[fix][broker] Prevent subscribe rate limit from stalling compaction and blocking forced deletion - #26015
Merged
Conversation
The subscribe rate limiter was enforced for every subscription, including the broker-internal __compaction subscription. The compactor's reader re-subscribes after the phase-two seek, and the per-consumer token bucket denies that re-subscribe once the initial subscribe has consumed the budget. The compaction then stalls in a reconnect backoff loop, and forced topic/namespace deletion blocks waiting on the in-flight compaction. Exempt the compaction subscription and system topics from the subscribe rate limit, consistent with the existing system-topic exemptions for the publish and dispatch rate limiters. Assisted-by: Claude Code (claude-fable-5)
void-ptr974
approved these changes
Jun 13, 2026
void-ptr974
left a comment
Contributor
There was a problem hiding this comment.
LGTM. Nice fix: the root cause is well analyzed, and the change is kept narrowly scoped to broker-internal compaction/system-topic subscriptions while preserving normal consumer subscribe-rate throttling. The regression test directly exercises the stall scenario and makes the behavior easy to verify.
lhotari
added a commit
to lhotari/pulsar
that referenced
this pull request
Jun 13, 2026
…d conflicting with PR apache#26015 Assisted-by: Claude Code (claude-fable-5)
merlimat
approved these changes
Jun 13, 2026
sandeep-ctds
pushed a commit
to datastax/pulsar
that referenced
this pull request
Jul 31, 2026
…nd blocking forced deletion (apache#26015) (cherry picked from commit a1b5a0d)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Main Issue: #22736
Related: #24148
Motivation
MockedPulsarServiceBaseTest.deleteNamespaceWithRetrytimes out sporadically in CI (#22736). Investigation of a recent occurrence (TopicPoliciesTest.setupTestTopic in this run) showed the following chain in the test-report logs:SubscribeRate(1 subscribe per consumer per period).__change_eventstopic starts. Phase two of the compaction seeks the__compactionsubscription, which disconnects and re-subscribes the compactor's reader.Subscribe limited by subscribe rate limit per consumer.— the limiter's token bucket is per consumer identifier, and the reader's initial subscribe already consumed the only token. The reader retries in an exponential-backoff loop and the compaction stalls.PersistentTopic.asyncDeleteCursorWithCleanCompactionLedger(), which waits for the in-flight compaction to complete (the mechanism described in [Bug] Compaction of __change_events topic is blocking forceful namespace/topic deletion #24148), until the test times out.This is not only a test problem: a user-configured subscribe rate (namespace, topic, or broker level) can stall compaction on any topic in production and consequently block forced topic/namespace deletion. Throttling broker-internal readers on system topics such as
__change_eventscan also stall topic policy updates.Note that this addresses one root cause of #22736 only; the underlying deletion-vs-compaction deadlock analyzed in #24148 (which can also be reached without any subscribe rate) is a separate issue and is not changed here.
Modifications
PersistentTopic#internalSubscribe: skip the subscribe rate limit check for the broker-internal__compactionsubscription and for system topics. This is consistent with the existing system-topic exemptions for the publish and dispatch rate limiters (SystemTopic#getBrokerPublishRateLimiter,AbstractTopic#updateTopicPolicyByNamespacePolicy).CompactionTest.testCompactionNotBlockedBySubscribeRateLimit, which sets aSubscribeRate(1, 3600)on the namespace and verifies that a compaction completes.Verifying this change
This change added tests and can be verified as follows:
CompactionTest.testCompactionNotBlockedBySubscribeRateLimitreproduces the stall: without the fix, the compaction does not complete within 30 seconds (timed out deterministically); with the fix it completes immediately (verified locally withinvocationCount = 10, 10/10 passes).TopicPoliciesTestsubscribe-rate tests (testGetSetSubscribeRate,testDisableSubscribeRate,testRemoveSubscribeRate) still pass, confirming regular consumers remain throttled.Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes