[fix][broker] Run ResourceGroup tasks only when tenants/namespaces registered #24859
+390
−26
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Fixes #24693.
ResourceGroupService unconditionally schedules two periodic tasks (aggregating local usage and calculating quotas) during broker initialization, executing them every resourceUsageTransportPublishIntervalInSecs (default 60 seconds) regardless of whether any tenants or namespaces are registered to resource groups. This wastes resources on brokers where the resource group feature is unused.
This PR implements explicit lifecycle management: periodic tasks now start only when the first tenant or namespace is registered to any resource group, and stop when the last registration is removed. This eliminates unnecessary periodic task execution and resource consumption on brokers where the resource group feature is idle.
Modifications
Modified files
Verifying this change
This change is verified by unit tests. Tests are sleep free, run with per test isolation, and use 60s timeouts.
New unit tests (ResourceGroupServiceTest.java)
Updated unit tests (ResourceGroupServiceTest.java)
testClose(): start schedulers via an attachment, call close(), then assert scheduled task references are set to null and isSchedulersRunning() is false.
testResourceGroupOps(): The test now calls
calculateQuotaForAllResourceGroups()before unregistering all attachments, rather than after.Test utilities
Personal CI Results
Tested in Personal CI fork: vinkal-chudgar#1
Status:
Evidence: https://github.com/vinkal-chudgar/pulsar/pull/1/checks
Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes
Configuration note: Only the documentation string for
resourceUsageTransportPublishIntervalInSecswas updated. No default values were changed.Documentation
docdoc-requireddoc-not-neededdoc-completeNote: Inline configuration documentation was updated in ServiceConfiguration.java. No website docs need changes
Matching PR in forked repository
PR in forked repository: vinkal-chudgar#1