|
37 | 37 | import java.util.Optional;
|
38 | 38 | import java.util.Set;
|
39 | 39 | import java.util.concurrent.CompletableFuture;
|
| 40 | +import java.util.concurrent.ConcurrentHashMap; |
40 | 41 | import java.util.concurrent.CopyOnWriteArrayList;
|
41 | 42 | import java.util.concurrent.ExecutionException;
|
42 | 43 | import java.util.concurrent.TimeUnit;
|
|
52 | 53 | import org.apache.commons.collections4.CollectionUtils;
|
53 | 54 | import org.apache.commons.collections4.ListUtils;
|
54 | 55 | import org.apache.commons.lang3.StringUtils;
|
| 56 | +import org.apache.commons.lang3.mutable.MutableBoolean; |
55 | 57 | import org.apache.commons.lang3.tuple.Pair;
|
56 | 58 | import org.apache.pulsar.broker.PulsarServerException;
|
57 | 59 | import org.apache.pulsar.broker.PulsarService;
|
|
100 | 102 | import org.apache.pulsar.common.policies.data.Policies;
|
101 | 103 | import org.apache.pulsar.common.policies.data.stats.TopicStatsImpl;
|
102 | 104 | import org.apache.pulsar.common.policies.impl.NamespaceIsolationPolicies;
|
| 105 | +import org.apache.pulsar.common.topics.TopicList; |
103 | 106 | import org.apache.pulsar.common.util.FutureUtil;
|
104 | 107 | import org.apache.pulsar.common.util.collections.ConcurrentOpenHashMap;
|
105 | 108 | import org.apache.pulsar.metadata.api.MetadataCache;
|
@@ -159,6 +162,9 @@ public class NamespaceService implements AutoCloseable {
|
159 | 162 | .register();
|
160 | 163 |
|
161 | 164 |
|
| 165 | + private ConcurrentHashMap<String, CompletableFuture<List<String>>> inProgressQueryUserTopics = |
| 166 | + new ConcurrentHashMap<>(); |
| 167 | + |
162 | 168 | /**
|
163 | 169 | * Default constructor.
|
164 | 170 | */
|
@@ -1452,6 +1458,23 @@ public CompletableFuture<List<String>> getListOfTopics(NamespaceName namespaceNa
|
1452 | 1458 | }
|
1453 | 1459 | }
|
1454 | 1460 |
|
| 1461 | + public CompletableFuture<List<String>> getListOfUserTopics(NamespaceName namespaceName, Mode mode) { |
| 1462 | + String key = String.format("%s://%s", mode, namespaceName); |
| 1463 | + final MutableBoolean initializedByCurrentThread = new MutableBoolean(); |
| 1464 | + CompletableFuture<List<String>> queryRes = inProgressQueryUserTopics.computeIfAbsent(key, k -> { |
| 1465 | + initializedByCurrentThread.setTrue(); |
| 1466 | + return getListOfTopics(namespaceName, mode).thenApplyAsync(list -> { |
| 1467 | + return TopicList.filterSystemTopic(list); |
| 1468 | + }, pulsar.getExecutor()); |
| 1469 | + }); |
| 1470 | + if (initializedByCurrentThread.getValue()) { |
| 1471 | + queryRes.whenComplete((ignore, ex) -> { |
| 1472 | + inProgressQueryUserTopics.remove(key, queryRes); |
| 1473 | + }); |
| 1474 | + } |
| 1475 | + return queryRes; |
| 1476 | + } |
| 1477 | + |
1455 | 1478 | public CompletableFuture<List<String>> getAllPartitions(NamespaceName namespaceName) {
|
1456 | 1479 | return getPartitions(namespaceName, TopicDomain.persistent)
|
1457 | 1480 | .thenCombine(getPartitions(namespaceName, TopicDomain.non_persistent),
|
|
0 commit comments