Skip to content

[fix][broker] Preserve replicated subscription activity on activation - #26780

Merged
lhotari merged 1 commit into
apache:masterfrom
Denovo1998:replicated-subscription-activity
Oct 1, 2026
Merged

lhotari merged 1 commit into
apache:masterfrom
Denovo1998:replicated-subscription-activity

Conversation

@Denovo1998

Copy link
Copy Markdown
Contributor

Motivation

After #26655, messages published while the replicated subscriptions controller is inactive no longer update the snapshot activity timestamp. If those messages are consumed and their ledgers are trimmed before subscription replication is enabled, both activation seed checks see zero retained entries, leaving snapshots paused until another message is published.

The controller also schedules its first snapshot before initializing its statistics object, allowing the zero-delay task to encounter a null stats reference and leave the pending snapshot gauge incremented.

Modifications

  • Remember max-read-position activity for the lifetime of the topic instance and use it when seeding the snapshot timestamp, including after ledger trimming. Topics without a controller continue to avoid reading the wall clock on each publish.
  • Initialize controller statistics before scheduling the first snapshot task.
  • Add regression coverage in existing test classes for activation and reactivation after trimming, constructor scheduling, and transaction-buffer recovery with replicated subscriptions enabled.

Verifying this change

  • Make sure that the change passes the CI checks.

This change added tests and can be verified as follows:

  • ReplicatedSubscriptionTest: publish, consume, acknowledge and trim data through the real broker/client path, then enable subscription replication and verify that a cross-cluster snapshot completes without another publish. Covers initial activation, reactivation and keeping empty topics idle.
  • ReplicatedSubscriptionConfigTest: execute the first scheduler tick during controller construction using a real topic, marker publication and statistics object.
  • TopicTransactionBufferRecoveryTest: publish while the real snapshot processor is paused, then verify that recovery advances the snapshot activity timestamp. Covers recovery with and without a persisted snapshot.

Both bug-fix regressions failed before their corresponding fixes. Local validation passed 22 tests and quickCheck:

./gradlew :pulsar-broker:test \
  --tests 'ReplicatedSubscriptionTest.testEnableReplicatedSubscriptionAfterConsumedDataIsTrimmed' \
  --tests 'ReplicatedSubscriptionTest.testReplicationSnapshotStopWhenNoTraffic' \
  --tests 'ReplicatedSubscriptionsControllerTest' \
  --tests 'ReplicatedSubscriptionConfigTest' \
  --tests 'TopicTransactionBufferRecoveryTest' \
  quickCheck \
  -PtestRetryCount=0 -PtestMaxParallelForks=1 --max-workers=4

Does this pull request potentially affect one of the following parts:

  • 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

Initializing statistics before scheduling prevents the first snapshot task from failing after incrementing the pending snapshot gauge. Metric names and definitions are unchanged.

@merlimat
merlimat requested a review from lhotari September 30, 2026 23:32

@lhotari lhotari left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@lhotari lhotari added this to the 5.0.0 milestone Oct 1, 2026
@lhotari
lhotari merged commit 1f22326 into apache:master Oct 1, 2026
44 checks passed
@Denovo1998
Denovo1998 deleted the replicated-subscription-activity branch October 1, 2026 03:59
ascentstream-bot pushed a commit to ascentstream/pulsar that referenced this pull request Oct 1, 2026
ascentstream-bot pushed a commit to ascentstream/pulsar that referenced this pull request Oct 2, 2026
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.

2 participants