codelipenghui commented on a change in pull request #12773:
URL: https://github.com/apache/pulsar/pull/12773#discussion_r748370933
##########
File path:
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/SystemTopicBasedTopicPoliciesService.java
##########
@@ -287,13 +275,34 @@ public boolean test(NamespaceBundle namespaceBundle) {
});
}
+ private synchronized void prepareInitPoliciesCache(NamespaceName
namespace, CompletableFuture<Void> result) {
+ if (readerCaches.get(namespace) == null) {
+ SystemTopicClient<PulsarEvent> systemTopicClient =
namespaceEventsSystemTopicFactory
+ .createTopicPoliciesSystemTopicClient(namespace);
+ CompletableFuture<SystemTopicClient.Reader<PulsarEvent>>
readerCompletableFuture =
+ systemTopicClient.newReaderAsync();
+ readerCaches.put(namespace, readerCompletableFuture);
+ readerCompletableFuture.whenComplete((reader, ex) -> {
+ if (ex != null) {
+ log.error("[{}] Failed to create reader on __change_events
topic", namespace, ex);
+ result.completeExceptionally(ex);
Review comment:
Should remove the failed reader future?
##########
File path:
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/SystemTopicBasedTopicPoliciesService.java
##########
@@ -287,13 +275,34 @@ public boolean test(NamespaceBundle namespaceBundle) {
});
}
+ private synchronized void prepareInitPoliciesCache(NamespaceName
namespace, CompletableFuture<Void> result) {
+ if (readerCaches.get(namespace) == null) {
+ SystemTopicClient<PulsarEvent> systemTopicClient =
namespaceEventsSystemTopicFactory
+ .createTopicPoliciesSystemTopicClient(namespace);
+ CompletableFuture<SystemTopicClient.Reader<PulsarEvent>>
readerCompletableFuture =
+ systemTopicClient.newReaderAsync();
+ readerCaches.put(namespace, readerCompletableFuture);
+ readerCompletableFuture.whenComplete((reader, ex) -> {
+ if (ex != null) {
+ log.error("[{}] Failed to create reader on __change_events
topic", namespace, ex);
+ result.completeExceptionally(ex);
+ } else {
+ initPolicesCache(reader, result);
+ result.thenRun(() -> readMorePolicies(reader));
+ }
+ });
+ }
+ }
+
private void initPolicesCache(SystemTopicClient.Reader<PulsarEvent>
reader, CompletableFuture<Void> future) {
reader.hasMoreEventsAsync().whenComplete((hasMore, ex) -> {
if (ex != null) {
log.error("[{}] Failed to check the move events for the system
topic",
reader.getSystemTopic().getTopicName(), ex);
future.completeExceptionally(ex);
readerCaches.remove(reader.getSystemTopic().getTopicName().getNamespaceObject());
+ reader.closeAsync();
Review comment:
Same as the above comment.
--
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]