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


   Cherry-pick https://github.com/apache/pulsar/pull/14503
   
   ### Motivation
   
   The current exception handler does not clean all states, which will cause 
some wrong behaviour. 
   
   **E.g:**
   
   #### case 1:
   
   
https://github.com/apache/pulsar/blob/e20f34bd2a6b4bd7ce72390a593931a855f8e250/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/SystemTopicBasedTopicPoliciesService.java#L249-L264
   
   When line 259 closes the reader with an exception, it doesn't remove 
namespace from ``policyCacheInitMap``, so next time this method is called, they 
will do nothing because ``policyCacheInitMap.putIfAbsent(namespace, false)`` is 
not empty.
   This will cause `getTopicPolicies` throw TopicPoliciesCacheNotInitException.
   
   
https://github.com/apache/pulsar/blob/e20f34bd2a6b4bd7ce72390a593931a855f8e250/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/SystemTopicBasedTopicPoliciesService.java#L193-L205
   
   #### case 2:
   
   When line 384 gets ``AlreadyClosedException``, it doesn't remove namespace 
from ``policyCacheInitMap``, but the current namespace value in 
``policyCacheInitMap`` is true. Therefore, the next time 
``prepareInitPoliciesCache `` is called, a new reader is never created. This 
will cause `getTopicPolicies` get NULL value.
   
   
https://github.com/apache/pulsar/blob/e20f34bd2a6b4bd7ce72390a593931a855f8e250/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/SystemTopicBasedTopicPoliciesService.java#L376-L393
   
   ### Modifications
   
   - Clean state when the reader gets an error.
   - Don't clean ``ownedBundlesCountPerNamespace`` when reader get 
``AlreadyClosedException``.
   
   ### Verifying this change
   
   - [x] Make sure that the change passes the CI checks.
   
   ### 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: [email protected]

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


Reply via email to