-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[fix][broker] Run ResourceGroup tasks only when tenants/namespaces registered #24859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[fix][broker] Run ResourceGroup tasks only when tenants/namespaces registered #24859
Conversation
…idle ResourceGroupService previously executed periodic tasks unconditionally every resourceUsageTransportPublishIntervalInSecs. This change starts both tasks only when at least one tenant or namespace is attached to any resource group, and stops them when no attachments remain. Each task reschedules itself if the interval changes at runtime. close() now cancels and clears both futures. Fixes apache#24693 Signed-off-by: Vinkal Chudgar <vinkal.chudgar@gmail.com>
Signed-off-by: Vinkal Chudgar <vinkal.chudgar@gmail.com>
Signed-off-by: Vinkal Chudgar <vinkal.chudgar@gmail.com>
|
@vinkal-chudgar Please add the following content to your PR description and select a checkbox: |
|
Thanks for the great contribution! I didn't do a full review yet. A few minor comments. |
Thanks for the quick look! I'll address the comments when available. |
|
@lhotari - When convenient, could you please review this PR? |
pulsar-broker/src/main/java/org/apache/pulsar/broker/resourcegroup/ResourceGroupService.java
Outdated
Show resolved
Hide resolved
pulsar-broker/src/main/java/org/apache/pulsar/broker/resourcegroup/ResourceGroupService.java
Outdated
Show resolved
Hide resolved
…ks; adopt 'registered' terminology - Moved the duplicated early-return checks from both periodic methods aggregateResourceGroupLocalUsages and calculateQuotaForAllResourceGroups into a single helper: shouldRunPeriodicTasks - Rename hasActiveAttachments() to hasActiveResourceGroups() - Update comments/logs to use 'registered' consistently. No functional change. Signed-off-by: Vinkal Chudgar <vinkal.chudgar@gmail.com>
|
@lhotari - Thanks for the review. I've addressed both comments. Could you please take a look when you have a moment? |
lhotari
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Good work @vinkal-chudgar
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces lazy initialization and lifecycle management for ResourceGroupService periodic schedulers. The schedulers now start only when the first tenant or namespace is attached to a resource group and stop automatically when all attachments are removed, reducing unnecessary overhead when resource groups exist but are not actively used.
- Adds lazy scheduler startup/shutdown triggered by tenant/namespace registrations
- Implements deterministic rescheduling when publish intervals change dynamically
- Ensures proper cleanup of scheduler state in close() method
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| ResourceGroupService.java | Implements lazy scheduler lifecycle with maybeStartSchedulers() and maybeStopSchedulersIfIdle() methods, adds guards to periodic tasks, and ensures proper cleanup with null-setting of futures |
| ResourceGroupServiceTest.java | Adds comprehensive tests for lazy scheduler lifecycle, rescheduling behavior, and close() cleanup; fixes test ordering issue in testResourceGroupOps() |
| ServiceConfiguration.java | Updates documentation for resourceUsageTransportPublishIntervalInSecs to explain the new lazy scheduler behavior |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
pulsar-broker/src/main/java/org/apache/pulsar/broker/resourcegroup/ResourceGroupService.java
Show resolved
Hide resolved
pulsar-broker/src/main/java/org/apache/pulsar/broker/resourcegroup/ResourceGroupService.java
Show resolved
Hide resolved
pulsar-broker/src/main/java/org/apache/pulsar/broker/resourcegroup/ResourceGroupService.java
Show resolved
Hide resolved
|
/pulsarbot rerun-failure-checks |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #24859 +/- ##
============================================
- Coverage 74.29% 74.28% -0.01%
- Complexity 33825 33855 +30
============================================
Files 1913 1913
Lines 149281 149365 +84
Branches 17325 17342 +17
============================================
+ Hits 110902 110961 +59
- Misses 29540 29546 +6
- Partials 8839 8858 +19
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
…gistered (apache#24859) Signed-off-by: Vinkal Chudgar <vinkal.chudgar@gmail.com> (cherry picked from commit 06f7142) (cherry picked from commit f535106)
…gistered (apache#24859) Signed-off-by: Vinkal Chudgar <vinkal.chudgar@gmail.com> (cherry picked from commit 06f7142) (cherry picked from commit aaabe70)
…gistered (apache#24859) Signed-off-by: Vinkal Chudgar <vinkal.chudgar@gmail.com> (cherry picked from commit 06f7142) (cherry picked from commit aaabe70)
…gistered (apache#24859) Signed-off-by: Vinkal Chudgar <vinkal.chudgar@gmail.com> (cherry picked from commit 06f7142) (cherry picked from commit f535106)
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