Repository navigation
[fix][ml] Check metadata versions for unchanged cursor property updates - #27746
Conversation
Assisted-by: Codex
nodece
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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).
Assisted-by: Codex
|
I updated the |
lhotari
left a comment
There was a problem hiding this comment.
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
…es (#27746) Co-authored-by: Lari Hotari <[email protected]> (cherry picked from commit 5adb229)
Motivation
Follow-up to apache/pulsar#27703. The first CI attempt and rerun for #78 both failed in
testUpdateCursorPropertiesConcurrentwithexpected [null] but found [3]. The failure also reproduced on the base revision.setCursorPropertiescan commitc=3before its callback refreshes the cursor's property snapshot. Aremove("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
BadVersionExceptionon 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 discussionBadVersionExceptionwhen 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:quickCheckpassed after refining the exception assertion.The previously failing
CI - Unit - Otherjob passed in personal CI.Does this pull request potentially affect one of the following parts: