Jason918 opened a new pull request #12658:
URL: https://github.com/apache/pulsar/pull/12658


   <!--
   ### Contribution Checklist
     
     - Name the pull request in the form "[Issue XYZ][component] Title of the 
pull request", where *XYZ* should be replaced by the actual issue number.
       Skip *Issue XYZ* if there is no associated github issue for this pull 
request.
       Skip *component* if you are unsure about which is the best component. 
E.g. `[docs] Fix typo in produce method`.
   
     - Fill out the template below to describe the changes contributed by the 
pull request. That will give reviewers the context they need to do the review.
     
     - Each pull request should address only one issue, not mix up code from 
multiple issues.
     
     - Each commit in the pull request has a meaningful commit message
   
     - Once all items of the checklist are addressed, remove the above text and 
this checklist, leaving only the filled out template below.
   
   **(The sections below can be removed for hotfixes of typos)**
   -->
   
   ### Motivation
   
   Currently, `AbstractTopic#maxSubscriptionsPerTopic` stores the value of 
namespace level policy, but we have broker level setting in 
`org.apache.pulsar.broker.ServiceConfiguration#maxSubscriptionsPerTopic` and 
topic level setting in 
`org.apache.pulsar.common.policies.data.TopicPolicies#maxSubscriptionsPerTopic`.
   And the real value we used of `maxSubscriptionsPerTopic` is calculated every 
time in 
`org.apache.pulsar.broker.service.persistent.PersistentTopic#checkMaxSubscriptionsPerTopicExceed`.
 It can be avoided by cache maxSubscriptionsPerTopic result locally.
   
   As we have already registered listeners to namespace policy and topic policy 
updates, so we can cache the value locally in AbstractTopic to avoid the 
recalculation.
   
   Finally, as some of other policies value have similar issues, I am 
introducing `PolicyHierarchyValue` to solve the hierarchy value storage and 
calculation.
   
   ### Modifications
   
   Introduce `PolicyHierarchyValue` to store policy value in broker, namespace 
and topic level.
   It provides corresponding `updateXX` methods, and recalculate real value in 
it.  And the `get()` method returns the policy value we should use directly.
   
   ### Verifying this change
   
   - [ ] Make sure that the change passes the CI checks.
   
   
   
   This change is already covered by existing tests, such as 
`org.apache.pulsar.broker.admin.TopicPoliciesTest#testMaxSubscriptionsPerTopic`
   
   And added PolicyHierarchyValueTest  for new class.
   
   ### Does this pull request potentially affect one of the following parts:
   
   *If `yes` was chosen, please highlight the changes*
   
     - Dependencies (does it add or upgrade a dependency): (no)
     - The public API: (no)
     - The schema: (no)
     - The default values of configurations: (no)
     - The wire protocol: (no)
     - The rest endpoints: (no)
     - The admin cli options: (no)
     - Anything that affects deployment: (no)
   
   ### Documentation
   
   Check the box below and label this PR (if you have committer privilege).
   
   Need to update docs? 
   
   - [x] `doc` 
     
   New class PolicyHierarchyValue comes with docs.
   The rest is internal optimization, no user behavior changed.
   
   
   


-- 
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-unsubscr...@pulsar.apache.org

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


Reply via email to