BewareMyPower commented on code in PR #25070:
URL: https://github.com/apache/pulsar/pull/25070#discussion_r2696620007


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/TopicListService.java:
##########
@@ -18,77 +18,171 @@
  */
 package org.apache.pulsar.broker.service;
 
+import com.google.common.annotations.VisibleForTesting;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.List;
+import java.util.Set;
+import java.util.concurrent.BlockingDeque;
 import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.Executor;
+import java.util.concurrent.LinkedBlockingDeque;
+import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicReference;
 import java.util.function.BiConsumer;
+import java.util.function.BooleanSupplier;
+import java.util.function.Function;
+import java.util.function.Supplier;
+import java.util.stream.Collectors;
 import org.apache.pulsar.broker.PulsarService;
 import org.apache.pulsar.broker.namespace.NamespaceService;
 import org.apache.pulsar.broker.resources.TopicResources;
+import org.apache.pulsar.broker.topiclistlimit.TopicListMemoryLimiter;
+import org.apache.pulsar.broker.topiclistlimit.TopicListSizeResultCache;
+import org.apache.pulsar.common.api.proto.CommandGetTopicsOfNamespace;
 import org.apache.pulsar.common.api.proto.CommandWatchTopicListClose;
 import org.apache.pulsar.common.api.proto.ServerError;
 import org.apache.pulsar.common.naming.NamespaceName;
 import org.apache.pulsar.common.naming.TopicName;
+import org.apache.pulsar.common.semaphore.AsyncDualMemoryLimiter;
+import org.apache.pulsar.common.semaphore.AsyncSemaphore;
 import org.apache.pulsar.common.topics.TopicList;
 import org.apache.pulsar.common.topics.TopicsPattern;
 import org.apache.pulsar.common.topics.TopicsPatternFactory;
+import org.apache.pulsar.common.util.Backoff;
+import org.apache.pulsar.common.util.FutureUtil;
 import org.apache.pulsar.common.util.collections.ConcurrentLongHashMap;
 import org.apache.pulsar.metadata.api.NotificationType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class TopicListService {
-
-
     public static class TopicListWatcher implements BiConsumer<String, 
NotificationType> {
-
+        // upper bound for buffered topic list updates
+        private static final int DEFAULT_TOPIC_LIST_UPDATE_MAX_QUEUE_SIZE = 
10000;
         /** Topic names which are matching, the topic name contains the 
partition suffix. **/
-        private final List<String> matchingTopics;
+        private final Set<String> matchingTopics;
         private final TopicListService topicListService;
         private final long id;
+        private final NamespaceName namespace;
         /** The regexp for the topic name(not contains partition suffix). **/
         private final TopicsPattern topicsPattern;
+        private final Executor executor;
+        private volatile boolean closed = false;
+        private boolean sendingInProgress;
+        private final BlockingDeque<Runnable> sendTopicListUpdateTasks;
+        private boolean updatingTopics;
+
+        public TopicListWatcher(TopicListService topicListService, long id,
+                                NamespaceName namespace, TopicsPattern 
topicsPattern, List<String> topics,
+                                Executor executor) {
+            this(topicListService, id, namespace, topicsPattern, topics, 
executor,
+                    DEFAULT_TOPIC_LIST_UPDATE_MAX_QUEUE_SIZE);
+        }
 
-        /***
-         * @param topicsPattern The regexp for the topic name(not contains 
partition suffix).
-         */
         public TopicListWatcher(TopicListService topicListService, long id,
-                                TopicsPattern topicsPattern, List<String> 
topics) {
+                                NamespaceName namespace, TopicsPattern 
topicsPattern, List<String> topics,
+                                Executor executor, int 
topicListUpdateMaxQueueSize) {
             this.topicListService = topicListService;
             this.id = id;
+            this.namespace = namespace;
             this.topicsPattern = topicsPattern;
-            this.matchingTopics = TopicList.filterTopics(topics, 
topicsPattern);
+            this.executor = executor;
+            this.matchingTopics =
+                    TopicList.filterTopics(topics, topicsPattern, 
Collectors.toCollection(LinkedHashSet::new));
+            // start with in progress state since topic list update will be 
sent first
+            this.sendingInProgress = true;
+            this.sendTopicListUpdateTasks =
+                    new LinkedBlockingDeque<>(topicListUpdateMaxQueueSize);
         }
 
-        public List<String> getMatchingTopics() {
+        public synchronized Collection<String> getMatchingTopics() {

Review Comment:
   Adding `synchronized` is useless without copying `matchingTopics`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to