vinkal-chudgar commented on code in PR #24859:
URL: https://github.com/apache/pulsar/pull/24859#discussion_r2472298406


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/resourcegroup/ResourceGroupService.java:
##########
@@ -540,6 +558,12 @@ protected static Summary.Child.Value 
getRgQuotaCalculationTime() {
     // Periodically aggregate the usage from all topics known to the 
BrokerService.
     // Visibility for unit testing.
     protected void aggregateResourceGroupLocalUsages() {
+        if (!schedulersRunning.get() || resourceGroupsMap.isEmpty()) {
+            return;
+        }
+        if (tenantToRGsMap.isEmpty() && namespaceToRGsMap.isEmpty()) {

Review Comment:
   Thanks, good suggestion. Done in aeb35470be3b07fc68a3e0e73c972f9b14bc4294
   
   - I moved the duplicated early-return checks from both periodic methods into 
a single helper: `shouldRunPeriodicTasks`:
   
      ```
        /**
        * Whether the periodic ResourceGroupService tasks (aggregation & quota 
calculation) should run.
        * True only when:
        *  1. the scheduler flag is set,
        *  2. at least one Resource Group exists locally, and
        *  3. at least one tenant or namespace is registered to Resource Group.
        */
       private boolean shouldRunPeriodicTasks() {
           return schedulersRunning.get()
                   && !resourceGroupsMap.isEmpty()
                   && hasActiveResourceGroups();
       }
     ```
   
      Both aggregateResourceGroupLocalUsages() and 
calculateQuotaForAllResourceGroups() now start with:
        
      ```
        if (!shouldRunPeriodicTasks()) {
                return;
        }
      ```
   
   - I also renamed `hasActiveAttachments()` to `hasActiveResourceGroups()` and 
updated comments to use `registration` consistently.
   
   



-- 
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