Repository navigation
fix: persist an honest resync terminal status about object counts - #138
Conversation
…unts resyncBucket could publish and persist a Completed resync status that did not actually cover every object, in two ways: 1. It joined only the producer workers before the deferred markStatus ran, not the goroutine that folds each worker result into the status, so a Completed status could omit the last object (or a failed object) until the periodic ~1m flush (issue #136). The same finalization also closed the result channel on early-return paths while workers were still in flight, risking a send-on-closed-channel panic and a lost result. 2. markStatus persists under its own background context, so if the parent context was cancelled during the drain - workers then return without sending their computed result - or a worker dropped a result on the resync-cancel signal, a bare Completed was still recorded with counts that no longer matched the objects seen. Fixes (count integrity only; the inherited cancellation deadlock, walker leak, and single-token routing are tracked as separate follow-ups): - Centralize shutdown in a resyncResults helper whose finish() stops the workers (closes inputs, waits for them to exit) before closing the result channel and waiting for the consumer to drain, then lets the deferred markStatus persist the final counts. finish() now runs on every exit path. - Record a dropped result via sendResyncResult (a worker consuming the resync-cancel token returns without sending), and in the finalizer downgrade a Completed status to Failed via finalResyncStatus when the parent context was cancelled or a worker aborted - so a persisted Completed never misrepresents an incomplete resync. Deterministic tests: an on-disk round-trip of the terminal status (complete counts stay Completed; parent-cancel-during-drain and worker-abort each downgrade to Failed), and testing/synctest drain/worker-order assertions that fail deterministically if a finish() wait is removed. The inherited cancellation structure (inline Walk, the dispatch send, the worker cancel branches) is left unchanged for the follow-ups. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01L7qJqWwy8oFA6aCXWRzXQe Signed-off-by: Feng Ruohang <[email protected]>
35d9f18 to
f8ca4a8
Compare
|
Independent round-2 verification: the #136 drain-before-persist fix passes; complete resync outcome correctness still needs #139. Tested
P2 found in the actual producer: when those versions already exist at the destination, the same quota-rejected updates yield Completed / 2 successes / 0 failures, while source status is FAILED and destination tags remain old. Restart preserves the false result. Clearing only the quota makes the same updates converge. Full reproduction, source path and bounded acceptance are in #139. The current sink tests inject already-classified outcomes, so they cannot catch that defect. Keep the minimal drain fix; make the real worker use the outcome for the selected target ARN and retain an existing-version failure regression. There is no need to absorb #137's cancellation architecture or #133's multi-pool work into this fix. #136's original four acceptance checks are now marked verified, with #139 explicitly linked as the remaining release-accounting condition. |
Description
resyncBucketcould persist a resync terminal status that misrepresents the work actually accounted for. Fixes #136 — scoped to counter integrity only by maintainer ruling; the inherited resync cancellation defects (dispatch deadlock, walker leak, one-token-vs-N-buckets routing, blocking-phase cancellation) are tracked separately in #137.Two counter-integrity problems:
incStatswas not joined before the deferredmarkStatuspersisted, soCompletedcould be persisted with an under-count (objects and failed objects) until the periodic ~1m flush; the status API reads from disk.Completedeven when work was dropped: the parent context cancelled mid-drain (workers return without sending their result), or a worker consumed the resync-cancel token and returned without submitting its computed result.Fix (minimal;
cmd/bucket-replication.go, +100/-18)resyncResultshelper centralises finalization ordering: close worker inputs → join workers → close the result channel → join the consumer, then persist. Registered asdefer results.finish(workers, &wg)after themarkStatusfinalizer, so LIFO runs the drain first. This also runs on early-return paths (no send-on-closed), replacing the trailing inline close+wait.finalResyncStatus(status, ctxErr, workerAborted)downgrades a tentativeCompletedtoFailedwhen the parent context was cancelled or a worker aborted; called in the finalizer (after the drain, beforemarkStatus, which persists under its own background context).sendResyncResultrecordsworkerAbortedwhen a worker drops its result on the resync-cancel token; actx.Done()return is covered by the parent-context check.Deliberately unchanged (→ #137):
Walk(ctx)inline, thedefault:blocking dispatch send, the workerresyncCancelChbranches, andcmd/site-replication.go. This change does not depend on those for its own correctness.Adversarial review
Codex Astra 6 (Max) recommended exactly this minimal set for the narrowed scope and then reviewed the implementation: VERDICT PASS. It confirmed the ordering, the parent-context recheck, the worker-abort safeguard, behavior-preserving helper extractions, and that #137's mechanisms are byte-identical with no refactor residue.
How to test
TestResyncBucketFinalizedrives a real erasureObjectLayerand asserts the on-disk terminal status: complete counts stayCompleted(2 replicated + 1 failed); parent-cancel-during-drain →Failed; worker-abort →Failed. The finish-order tests usetesting/synctest. Red-on-revert confirmed for each wait and each downgrade term.gofmt/go vet/go buildclean;-raceclean; full-run 'Resync' -count=1passes.Compatibility impact
No wire or API change. A resync that lost work now reports
Failedinstead of a misleadingCompleted, and the persisted counts are complete at the momentCompletedis written. There is one intentional conservative downgrade: a fully-processed run whose parent is cancelled between finishing and the final check is recordedFailed.Types of changes
Checklist
git commit -s) per the DCOgofmt/go vet/go buildclean;-raceclean; package Resync tests pass🤖 Generated with Claude Code
https://claude.ai/code/session_01L7qJqWwy8oFA6aCXWRzXQe