You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/01/19 13:54:34 UTC

[GitHub] [pulsar] Technoboy- opened a new pull request #13840: [Branch-2.9] Fix SystemTopicBasedTopicPoliciesService NPE issue.

Technoboy- opened a new pull request #13840:
URL: https://github.com/apache/pulsar/pull/13840


   ### Motivation
   When SystemTopicBasedTopicPoliciesService#getTopicPolicies is invoked before SystemTopicBasedTopicPoliciesService#addOwnedNamespaceBundleAsync, it will cause NPE:
   #### Stack trace
   ```
   java.lang.NullPointerException: null
   	at org.apache.pulsar.broker.service.SystemTopicBasedTopicPoliciesService.addOwnedNamespaceBundleAsync(SystemTopicBasedTopicPoliciesService.java:222) ~[classes/:?]
   	at org.apache.pulsar.broker.service.SystemTopicBasedTopicPoliciesService$1.onLoad(SystemTopicBasedTopicPoliciesService.java:301) ~[classes/:?]
   	at org.apache.pulsar.broker.namespace.NamespaceService.notifyNamespaceBundleOwnershipListener(NamespaceService.java:1052) ~[classes/:?]
   	at org.apache.pulsar.broker.namespace.NamespaceService.onNamespaceBundleOwned(NamespaceService.java:1020) ~[classes/:?]
   	at org.apache.pulsar.broker.namespace.OwnershipCache.lambda$tryAcquiringOwnership$1(OwnershipCache.java:200) ~[classes/:?]
   	at java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:642) ~[?:?]
   	at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:506) ~[?:?]
   	at java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:2073) ~[?:?]
   	at org.apache.pulsar.metadata.coordination.impl.LockManagerImpl.lambda$acquireLock$1(LockManagerImpl.java:105) ~[classes/:?]
   	at java.util.concurrent.CompletableFuture$UniRun.tryFire$$$capture(CompletableFuture.java:783) ~[?:?]
   	at java.util.concurrent.CompletableFuture$UniRun.tryFire(CompletableFuture.java) ~[?:?]
   	at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:506) ~[?:?]
   	at java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:2073) ~[?:?]
   	at org.apache.pulsar.metadata.coordination.impl.ResourceLockImpl.lambda$acquire$2(ResourceLockImpl.java:127) ~[classes/:?]
   	at java.util.concurrent.CompletableFuture$UniRun.tryFire$$$capture(CompletableFuture.java:783) ~[?:?]
   	at java.util.concurrent.CompletableFuture$UniRun.tryFire(CompletableFuture.java) ~[?:?]
   	at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:506) ~[?:?]
   	at java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:2073) ~[?:?]
   	at org.apache.pulsar.metadata.coordination.impl.ResourceLockImpl.lambda$acquireWithNoRevalidation$6(ResourceLockImpl.java:166) ~[classes/:?]
   	at java.util.concurrent.CompletableFuture$UniAccept.tryFire$$$capture(CompletableFuture.java:714) ~[?:?]
   	at java.util.concurrent.CompletableFuture$UniAccept.tryFire(CompletableFuture.java) ~[?:?]
   	at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:506) ~[?:?]
   	at java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:2073) ~[?:?]
   	at org.apache.pulsar.metadata.impl.ZKMetadataStore.handlePutResult(ZKMetadataStore.java:214) ~[classes/:?]
   	at org.apache.pulsar.metadata.impl.ZKMetadataStore.lambda$batchOperation$6(ZKMetadataStore.java:171) ~[classes/:?]
   	at org.apache.pulsar.metadata.impl.PulsarZooKeeperClient$3$1.processResult(PulsarZooKeeperClient.java:490) [classes/:?]
   	at org.apache.zookeeper.ClientCnxn$EventThread.processEvent(ClientCnxn.java:722) [zookeeper-3.6.3.jar:3.6.3]
   	at org.apache.zookeeper.ClientCnxn$EventThread.run(ClientCnxn.java:563) [zookeeper-3.6.3.jar:3.6.3]
   ```
   
   ### Modifications
   1. Move `ownedBundlesCountPerNamespace.putIfAbsent(namespace, new AtomicInteger(1))` in the prepareInitPoliciesCache method.
   
   ### Documentation
   
   
   - [x] `no-need-doc` 
   
   
   
   


-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] Technoboy- commented on a change in pull request #13840: [Branch-2.9] Fix SystemTopicBasedTopicPoliciesService NPE issue.

Posted by GitBox <gi...@apache.org>.
Technoboy- commented on a change in pull request #13840:
URL: https://github.com/apache/pulsar/pull/13840#discussion_r788280602



##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/SystemTopicBasedTopicPoliciesService.java
##########
@@ -234,6 +233,7 @@ private void prepareInitPoliciesCache(NamespaceName namespace, CompletableFuture
             CompletableFuture<SystemTopicClient.Reader<PulsarEvent>> readerCompletableFuture =
                     creatSystemTopicClientWithRetry(namespace);
             readerCaches.put(namespace, readerCompletableFuture);
+            ownedBundlesCountPerNamespace.putIfAbsent(namespace, new AtomicInteger(1));

Review comment:
       yes. This is only a init operation, we need to keep `readerCaches` and `ownedBundlesCountPerNamespace`  the data consistent.




-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] codelipenghui commented on a change in pull request #13840: [Branch-2.9] Fix SystemTopicBasedTopicPoliciesService NPE issue.

Posted by GitBox <gi...@apache.org>.
codelipenghui commented on a change in pull request #13840:
URL: https://github.com/apache/pulsar/pull/13840#discussion_r788342101



##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/SystemTopicBasedTopicPoliciesService.java
##########
@@ -234,6 +233,7 @@ private void prepareInitPoliciesCache(NamespaceName namespace, CompletableFuture
             CompletableFuture<SystemTopicClient.Reader<PulsarEvent>> readerCompletableFuture =
                     creatSystemTopicClientWithRetry(namespace);
             readerCaches.put(namespace, readerCompletableFuture);
+            ownedBundlesCountPerNamespace.putIfAbsent(namespace, new AtomicInteger(1));

Review comment:
       Oh, I see. My mistake.




-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] codelipenghui merged pull request #13840: [Branch-2.9] Fix SystemTopicBasedTopicPoliciesService NPE issue.

Posted by GitBox <gi...@apache.org>.
codelipenghui merged pull request #13840:
URL: https://github.com/apache/pulsar/pull/13840


   


-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] codelipenghui commented on a change in pull request #13840: [Branch-2.9] Fix SystemTopicBasedTopicPoliciesService NPE issue.

Posted by GitBox <gi...@apache.org>.
codelipenghui commented on a change in pull request #13840:
URL: https://github.com/apache/pulsar/pull/13840#discussion_r787795143



##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/SystemTopicBasedTopicPoliciesService.java
##########
@@ -234,6 +233,7 @@ private void prepareInitPoliciesCache(NamespaceName namespace, CompletableFuture
             CompletableFuture<SystemTopicClient.Reader<PulsarEvent>> readerCompletableFuture =
                     creatSystemTopicClientWithRetry(namespace);
             readerCaches.put(namespace, readerCompletableFuture);
+            ownedBundlesCountPerNamespace.putIfAbsent(namespace, new AtomicInteger(1));

Review comment:
       If we move this line here, can we ensure the `ownedBundlesCount` will decrease to 0 after all the bundles of the namespace are unloaded from this broker?




-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org