Repository navigation
[fix][ml] Make managed ledger properties updates atomic - #26569
Conversation
Assisted-by: Codex
lhotari
left a comment
There was a problem hiding this comment.
Thanks for working on making managed-ledger property updates atomic. One concurrent migration path can still lose the durable migration marker when it overlaps a pending property update.
Serialize the migration marker through the managed-ledger property update path before terminating the ledger, and add deterministic coverage for the overlapping update race. Assisted-by: Codex
Assisted-by: Codex
Coalesce concurrent migration attempts, avoid persisting an unfinished termination position, and isolate property failure callbacks. Cover marker and termination metadata retries. Assisted-by: Codex
lhotari
left a comment
There was a problem hiding this comment.
Thanks for the quick fix. The lost-marker race is closed. The two follow-up commits add retry handling for migration, and I found two cases there that still need a look (inline).
Share termination completion across migrations and independent terminate calls. Keep marker-write failures retryable and fail queued property updates when the ledger is fenced or closed. Release the metadata mutex when property writes fail synchronously and isolate completion callbacks without publishing failed property updates. Add deterministic coverage for concurrent termination, rollover fencing, retry behavior, and synchronous storage failures. Validation: quickCheck and 45 targeted managed-ledger tests passed. Assisted-by: Codex
…invariants Assisted-by: Codex
…ration order Assisted-by: Codex
Share cached read-handle cleanup between both close paths. Cover migration after the final ledger was offloaded and deleted from BookKeeper, durable migration recovery, and idempotent retries. Assisted-by: Codex
|
Updated this PR to
Targeted local verification passed: 55 managed-ledger test executions and 14 broker test executions ( The local jcstress tests, dependencies, and build configuration are not included in these pushed commits. |
lhotari
left a comment
There was a problem hiding this comment.
LGTM. Thanks for the quick follow-up: both retry-handling points are fixed in the code, and the new regression tests exercise exactly those scenarios. The marker-write failure now clears the cached migration independently of termination state, and queued property updates fail once the ledger is fenced or closed instead of retrying forever. I read the termination rewrite (shared terminationFuture), the merge resolution and the read-handle cleanup in the later commits and found nothing blocking.
Keep upstream termination recovery and read-handle cleanup. Publish the terminated position in ordinary metadata writes after the dedicated write succeeds, and cover migration retry, shadow ledger behavior, and broker migration readiness. Assisted-by: OpenAI Codex
Store a live migration marker with the terminated position. If ordinary termination submitted first, publish the marker independently after its success. Keep the final BookKeeper ledger recoverable until termination is durable and test ownership changes, offload, and queued property inputs. Assisted-by: OpenAI Codex
Assisted-by: OpenAI Codex
Assisted-by: OpenAI Codex
Assisted-by: OpenAI Codex
|
Updated this branch to
Local validation passed 306 managed-ledger tests, five broker test executions including the previously failing replication backlog case, and two transaction sequence ID recovery cases. Scoped Checkstyle reported the same Javadoc findings as the clean |
…roperties-review-26569
…ination Bind the migration marker to the termination attempt it joins so an ordinary retry cannot persist a failed migration. Reject fenced and closed migration handles, and repair a deleted marker when migration is requested again. Queue automatic offload after termination completion so a manual offload already waiting on its final ledger can proceed. Add coverage for each ordering and the existing disabled-threshold case. Assisted-by: OpenAI Codex
…d ledger An empty rollover ledger can disappear from the persisted list after a failed termination and a subsequent property update. Recover the retained offloaded ledger from its stored stats and read its last entry from tiered storage when an interceptor needs it. Assisted-by: OpenAI Codex
lhotari
left a comment
There was a problem hiding this comment.
LGTM. Thanks for the follow-up commits. Tying each migration attempt to its own termination future (ManagedLedgerImpl.java:1872 and the check in storeTerminatedPosition at ManagedLedgerImpl.java:2007) means a retried ordinary terminate() can no longer commit the marker of a migration that already failed, and testOrdinaryTerminationRetryDoesNotCommitFailedMigration reproduces that interleaving. Rejecting asyncMigrate() on a fenced or closed ledger is safe for the broker, which only calls it after isMigrated() returns false. testRepeatedMigrationRestoresDeletedMarker and testAlreadyMigratedLedgerRejectsMigrationAfterFencing cover the new isMigrated() semantics. Reopening a writable ledger whose last ledger was offloaded and deleted from BookKeeper now keeps its stored stats and reads the last entry through the offloaded handle for the interceptor (ManagedLedgerImpl.java:568-577), and testRecoverOffloadedTailAfterEmptyLedgerRolloverAndFailedTermination covers both the interceptor and the no-interceptor case.
Close the temporary BookKeeper handle after interceptor initialization and keep the offloaded tail handle managed by the ledger cache. Assisted-by: OpenAI Codex
lhotari
left a comment
There was a problem hiding this comment.
LGTM. The only change since my approval is the merge of master, and the conflict in ManagedLedgerImpl.java was resolved correctly: the last-ledger recovery path keeps master's handling of temporary read handles (the handle is closed after the interceptor completes when it is not retained, ManagedLedgerImpl.java:601-611), and both the BookKeeper and offloaded-tail paths still go through the shared initializeAfterInterceptor helper (ManagedLedgerImpl.java:663-671) with supplySafely and the unwrapped interceptor exception.
Change requests have been addressed.
(cherry picked from commit 67052c8)
Motivation
ManagedLedgerImplinitializespropertiesMapas aConcurrentHashMap, but replaces it with a plainHashMapwhen recovering persisted properties. In addition,getProperties()exposes the live internalmap, and property updates mutate the in-memory map before the metadata-store write succeeds.
As a result, callers can mutate managed-ledger state without using the property update APIs, readers can
observe a partially applied multi-property update, and a failed metadata-store update can leave memory
inconsistent with persisted metadata.
Modifications
getProperties()and property-update callbacks.snapshot only after the metadata-store write succeeds.
property-update completion path, including failures while building metadata locally.
it is serialized with other property snapshot updates.
future to each caller.
lastConfirmedEntry, so aconcurrent property update cannot persist a stale termination position.
without treating a BookKeeper close failure as a completed migration.
After merging the latest
master, the final termination metadata write is also serialized throughmetadataMutexbystoreTerminatedPosition()from #26680. Other managed-ledger metadata update flows areunchanged by this PR.
Verifying this change
This change added tests covering:
callback, including the persisted migration, property, and termination state after reopening;
Commands run locally:
./gradlew quickCheck:managed-ledger:testproperties, concurrency, migration, and termination testsManagedLedgerTerminationTest./gradlew :pulsar-broker:test --tests org.apache.pulsar.broker.intercept.ManagedLedgerInterceptorImplTest.testRecoveryIndexDoes this pull request potentially affect one of the following parts:
ManagedLedger.getProperties()now explicitly returns a detached snapshot rather than the live backingmap. The threading change is limited to atomic publication and serialization of managed-ledger property
and migration updates; no executors or thread pools are changed.