Skip to content

[fix][ml] Confirm retried cursor metadata writes in ZooKeeper - #27652

Merged
poorbarcode merged 4 commits into
apache:masterfrom
poorbarcode:codex/confirm-cursor-metadata-writes
Nov 19, 2026
Merged

poorbarcode merged 4 commits into
apache:masterfrom
poorbarcode:codex/confirm-cursor-metadata-writes

Conversation

@poorbarcode

@poorbarcode poorbarcode commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Background

Following a ZooKeeper connectivity interruption, a broker repeatedly failed to open a durable subscription with BadVersion. The cursor znode already existed. Unloading the topic let the broker reload the persisted cursor, and the subscription recovered.

Motivation

ZooKeeper can commit a cursor write before the client loses the response. Replaying a create then returns NODEEXISTS, which Pulsar maps to BadVersion. Replaying an update with the original expected version also returns BadVersion. The broker needs to recognize its own committed write while continuing to report conflicts when another writer wins.

Modifications

  • Add an optional publication ID to ManagedCursorInfo. Assign a UUID on the first attempt and preserve it across retries of the same write. A new cursor property update clears the ID inherited from the previous record.
  • Let writers opt in through the existing put API with Option.VerifyPublication. Its documentation requires a unique publication ID in the serialized value and preservation of the ID, serialized bytes, and expected version across retries of the same write. Other metadata record types can use the same verification path.
  • Verify opted-in conditional writes to fixed, persistent ZooKeeper paths after a version conflict or an ambiguous write response. This includes individual creates and updates issued after another operation in a batch fails. Confirm success only if the stored version is the expected version plus one and the bytes, including the publication ID, match. A mismatch preserves the original write error.
  • Use an asynchronous single-node getData so verification also works for valid records larger than the server’s multiRead response limit. Return the observed Stat, including its session ownership information.
  • Keep the original write pending during transient verification read failures. Retry the read with exponential backoff and jitter so another open of the same cursor can join the pending create. Permanent read failures and store closure complete the pending operation exceptionally.
  • Document how to chain dependent operations when a retry or verification read delays write completion.
  • Add regression coverage for a committed write whose response is lost, caller retries, competing publications, cursor serialization with compression, and verification after transport or session changes.

Local verification passed the repository-wide sanityCheck and all 47 tests in ZKMetadataStoreTest, MetaStoreImplTest, ManagedCursorInfoMetadataTest, and ManagedCursorPropertiesTest.

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

The metadata-store API gains the optional VerifyPublication write option. The persisted managed cursor protobuf gains an optional string field. Brokers can still read older cursor records that omit it.

Comment thread managed-ledger/build.gradle.kts Resolved
@poorbarcode
poorbarcode requested a review from lhotari November 18, 2026 02:51

@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.

Please address the comment about removing the HasPublicationId.

@poorbarcode
poorbarcode requested a review from lhotari November 18, 2026 13:09

@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. Thanks for the quick follow-up: both requested simplifications are in. HasPublicationId and the LightProto doLast step are gone, and the VerifyPublication Javadoc now carries the contract.

@poorbarcode
poorbarcode merged commit 893259f into apache:master Nov 19, 2026
82 of 84 checks passed
poorbarcode added a commit that referenced this pull request Nov 19, 2026
codelipenghui added a commit to codelipenghui/incubator-pulsar that referenced this pull request Nov 24, 2026
Resolve the conflicts in ManagedCursorImpl and adapt the publication path to
the cursor changes on master:

- apache#27703 rebuilds the cursor properties in updateCursorLedgerStat, so drop
  adoptStoredCursorInfo and keep only the deletion of retained ledgers there.
  Sample the version and the properties as one pair in publishCursorLedger as
  well as in persistPositionMetaStore, and pass them to buildManagedCursorInfo.
- apache#27652 assigns a publication ID in MetaStoreImpl during the write. Assign it
  in publishCursorLedger before taking the attempted bytes, so that
  reconciliation still recognizes a committed publication.
- apache#27671 makes a closing cursor wait for an in-flight ledger switch, so allow
  that switch to publish while the cursor is Closing.
- apache#26817 closes the read-only cursor ledger in asyncDeleteCursorLedger; keep
  that next to the deletion of retained ledgers.

MetaStoreImpl now calls the put overload with options, so the fault-injection
stubs in ManagedCursorTest target that overload.

Assisted-by: Claude Code (Claude Opus 5.5)
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