Skip to content

[fix][broker] Prevent subscribe rate limit from stalling compaction and blocking forced deletion - #26015

Merged
merlimat merged 1 commit into
apache:masterfrom
lhotari:lh-fix-subscribe-rate-compaction
Jun 13, 2026
Merged

[fix][broker] Prevent subscribe rate limit from stalling compaction and blocking forced deletion#26015
merlimat merged 1 commit into
apache:masterfrom
lhotari:lh-fix-subscribe-rate-compaction

Conversation

@lhotari

@lhotari lhotari commented Jun 13, 2026

Copy link
Copy Markdown
Member

Main Issue: #22736

Related: #24148

Motivation

MockedPulsarServiceBaseTest.deleteNamespaceWithRetry times out sporadically in CI (#22736). Investigation of a recent occurrence (TopicPoliciesTest.setupTestTopic in this run) showed the following chain in the test-report logs:

  1. A test sets a namespace-level SubscribeRate (1 subscribe per consumer per period).
  2. A compaction of the namespace's __change_events topic starts. Phase two of the compaction seeks the __compaction subscription, which disconnects and re-subscribes the compactor's reader.
  3. The re-subscribe is denied with 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.
  4. A subsequent forced namespace deletion blocks in 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_events can 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 __compaction subscription and for system topics. This is consistent with the existing system-topic exemptions for the publish and dispatch rate limiters (SystemTopic#getBrokerPublishRateLimiter, AbstractTopic#updateTopicPolicyByNamespacePolicy).
  • Added CompactionTest.testCompactionNotBlockedBySubscribeRateLimit, which sets a SubscribeRate(1, 3600) on the namespace and verifies that a compaction completes.

Verifying this change

  • Make sure that the change passes the CI checks.

This change added tests and can be verified as follows:

  • CompactionTest.testCompactionNotBlockedBySubscribeRateLimit reproduces the stall: without the fix, the compaction does not complete within 30 seconds (timed out deterministically); with the fix it completes immediately (verified locally with invocationCount = 10, 10/10 passes).
  • TopicPoliciesTest subscribe-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

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

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 void-ptr974 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
merlimat merged commit a1b5a0d into apache:master Jun 13, 2026
44 checks passed
@lhotari lhotari added this to the 5.0.0-M1 milestone Jun 13, 2026
lhotari added a commit that referenced this pull request Jun 22, 2026
…nd blocking forced deletion (#26015)

(cherry picked from commit a1b5a0d)
lhotari added a commit that referenced this pull request Jun 22, 2026
…nd blocking forced deletion (#26015)

(cherry picked from commit a1b5a0d)
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants