Skip to content

[fix][ml] Check metadata versions for unchanged cursor property updates - #27746

Merged
nodece merged 3 commits into
apache:masterfrom
oneby-wang:fix/cursor-property-version-check
Nov 26, 2026
Merged

nodece merged 3 commits into
apache:masterfrom
oneby-wang:fix/cursor-property-version-check

Conversation

@oneby-wang

Copy link
Copy Markdown
Contributor

Motivation

Follow-up to apache/pulsar#27703. The first CI attempt and rerun for #78 both failed in testUpdateCursorPropertiesConcurrent with expected [null] but found [3]. The failure also reproduced on the base revision.

setCursorProperties can commit c=3 before its callback refreshes the cursor's property snapshot. A remove("c") using that stale snapshot sees no change and returns success before checking the metadata version, so the retry never runs. Submitting calls in order still allows overlap. Dependent operations need to await the previous future or use a sequencer so removal observes the preceding write.

Modifications

  • Remove the equality shortcut for durable cursor property updates. The existing version check now surfaces BadVersionException on a stale snapshot so callers can retry. Update the Javadoc to reflect that unchanged results may write and advance the version. The original shortcut was introduced to avoid redundant writes and conflicts during conditional cleanup. Original review discussion
  • Add a two-cursor regression that expects BadVersionException when removing a key missing from a stale local snapshot and verifies the persisted value is preserved.

Verifying this change

  • Make sure that the change passes the CI checks.

  • The new regression failed with early success before the fix and passed afterward. Local validation passed 50 Managed Ledger tests, 81 Broker tests, and 100 repetitions of the original failing test. Both cursor property suites and :managed-ledger:quickCheck passed after refining the exception assertion.

  • The previously failing CI - Unit - Other job passed in personal CI.

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

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

Confirmed — the equality shortcut was a real lost-update hole, and the analysis is exactly right: the skip decided from the in-memory property snapshot, which can lag the store while a committed write's callback has not refreshed it yet, so a remove computed from the pre-write snapshot returned success without ever consulting the metadata version. Two confessions from my side: I implemented that shortcut, and when testUpdateCursorPropertiesConcurrent failed on #27673's CI run I misdiagnosed it as commit-order probability — I had enumerated this interleaving and discarded it with wrong reasoning, instead of recognizing the shortcut made the false success deterministic through that window. Good catch.

Verified on this PR's head: the property suites pass including the previously failing concurrency test (3 green repeats), and restoring the shortcut makes testRemoveMissingPropertyRejectsStaleMetadataVersion fail with early success — the regression pins the hole.

Downstream, this also holds together with the conditional cleanup in #27673: the original rationale for the shortcut (an unchanged result colliding with a concurrent putBucketKeyId) is covered by the executeWithRetry wrapper the cleanup already carries, and I cherry-picked this fix onto that branch and ran its full delayed-delivery suites (96 tests, all green). Nothing there depends on the skip's no-write behavior.

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

Thanks for tracking down the root cause of the testUpdateCursorPropertiesConcurrent flake and for the clear write-up.

The diagnosis looks right to me: a remove("c") computed from a snapshot that setCursorProperties's callback has not refreshed yet sees no change and, with the equality shortcut, completes without ever checking the version. Without the shortcut, the stale version fails the CAS, the callback on the same ordered executor publishes the refreshed snapshot first, and the retry then succeeds. The new two-cursor test is deterministic and fails on the base revision.

One trade-off is worth deciding on before merging: every no-op property update on a durable cursor now advances the metadata version, which brings back the collision the shortcut was added for in #27703 (details inline).

@oneby-wang
oneby-wang requested a review from lhotari November 26, 2026 08:13
@oneby-wang

Copy link
Copy Markdown
Contributor Author

I updated the updateCursorProperties Javadoc in 445af51d46 to clarify that even an unchanged update on a durable cursor can advance the metadata version or fail with BadVersionException. Callers should be prepared to retry on a version conflict.

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

Thanks for the Javadoc update, and thanks @nodece for the detailed reasoning on the trade-off.

Keeping the version-checked write for unchanged updates and documenting it works for me: the stale-snapshot case is detected, and the admin endpoint not retrying BadVersionException can be fixed separately, as @nodece offered.

One small point on the new Javadoc: the rewrite dropped the contract that the update function must be side-effect free and must not retain the passed map (details inline). Once that sentence is back, this looks good to me.

…t be side-effect free

Assisted-by: Claude Code
@nodece
nodece merged commit 5adb229 into apache:master Nov 26, 2026
43 checks passed
lhotari added a commit that referenced this pull request Nov 28, 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.

3 participants