Skip to content

fix: count resync success by replication outcome, not target existence - #140

Merged
Vonng merged 2 commits into
mainfrom
fix/issue-139-resync-classification
Sep 6, 2026
Merged

Vonng merged 2 commits into
mainfrom
fix/issue-139-resync-classification

Conversation

@Vonng

@Vonng Vonng commented Sep 6, 2026

Copy link
Copy Markdown
Member

Description

Fixes #139. Stacked on #138 (fix/issue-136-resync-counter-flush) — review/merge #138 first; this PR's base retargets to main once #138 lands.

resyncBucket's worker classified a per-object resync as success whenever the target version merely existed (tgt.StatObject), ignoring the outcome of the replicateObject/replicateDelete it had just run. A quota-rejected update leaves the old version in place, so it was falsely recorded Completed / success (persisted across restart). #134's SSE-C internal HEAD marker made StatObject succeed for SSE-C objects too, exposing the same defect there; the delete path had the mirror flaw; and FailedSize was never incremented.

Fix (cmd/bucket-replication.go)

  • replicateObject and replicateDelete now return the per-target replicatedInfos they already build (early returns → replicatedInfos{}; the metadata-persistence side effects are unchanged). The non-resync callers are call statements that discard the value.
  • The resync worker classifies via pure helpers resyncResultFor / resyncTargetSucceeded, using the opts.arn target's own outcome:
    • object/delete-marker: success requires ReplicationStatus == Completed, tolerating only the benign duplicate PreconditionFailed (412) the destination returns for an exact ETag+version match;
    • version purge: success requires VersionPurgeStatus == VersionPurgeComplete (a purge leaves ReplicationStatus empty);
    • a failed/errored result, or opts.arn absent from the result, counts as a failure, and FailedSize is now recorded.
  • The StatObject-existence block (and its delete-marker/MethodNotAllowed heuristic, now subsumed) is removed. fix: retransmit and re-order Object Lock for SSE-C replicas (single erasure set) #134's SSE-C HEAD marker in replicateAll is untouched.

Scope / follow-ups

Counter timing is #138; cancellation robustness is #137; multi-pool is #133. Two items are deliberately out of scope: the compressed/encrypted byte-size approximation (pre-existing), and cross-ARN dispatch scoping (any-target mustResync can route a non-opts.arn object to a worker → conservatively counted a failure) — tracked as a follow-up.

Adversarial review

Codex Astra 6 (Max), 2 rounds → VERDICT PASS. Round 1 caught two over-strict misclassifications (successful version purge; benign 412); round 2 confirmed both fixes correct and that all other result shapes (Replica/pending/empty/arbitrary Completed+Err, quota rejection) classify correctly.

How to test

GOWORK=off go test -tags kqueue,dev ./cmd -count=1 -run '^TestResyncResultFor$'

Table-driven, 10 cases incl. the key regressions (failed update over an existing version → 1 failed / 196608 bytes / 0 replicated; version-purge complete/failed; benign 412). Red-on-revert confirmed for the existence heuristic and for both round-2 branches. gofmt/go vet/go build/-race clean; full -run 'Resync' -count=1 passes (incl. #138's finalize tests on the stack).

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • Commits signed off (git commit -s)
  • gofmt/go vet/go build/-race clean; Resync tests pass
  • Adversarial Codex review PASS (2 rounds)
  • Follow-ups tracked (dispatch scoping); no wire/API change

🤖 Generated with Claude Code

https://claude.ai/code/session_01L7qJqWwy8oFA6aCXWRzXQe

…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]>
@Vonng
Vonng changed the base branch from fix/issue-136-resync-counter-flush to main September 6, 2026 10:12
@Vonng

Vonng commented Sep 6, 2026

Copy link
Copy Markdown
Member Author

Note on base / merge order. CI only triggers on PRs targeting main, so I retargeted this PR's base from the #138 branch to main to get a CI run. It therefore now shows two commits — PR #138's counter-timing fix (f8ca4a865) and this classification fix (6c2d16454). They are a stack.

Merge either way:

No behavioral overlap between the two commits; #138 is finalization timing, #139 is result classification.

@Vonng
Vonng force-pushed the fix/issue-139-resync-classification branch from 6c2d164 to 069a5ce Compare September 6, 2026 10:35
The resync worker classified each object by whether the target version
merely existed (a tgt.StatObject HEAD), ignoring the outcome of the
replicateObject/replicateDelete call it had just made. A quota-rejected
update leaves the old version in place, so StatObject succeeded and the
resync recorded a false success - reported as Completed / N success /
0 failed and persisted across restart (issue #139). #134's SSE-C HEAD
marker made StatObject succeed for SSE-C too, exposing it there. The delete
path had the mirror flaw (a failed delete leaves the object, so the HEAD
succeeded), and FailedSize was never incremented (a failed 196,608-byte
object counted as 1 failed / 0 bytes).

replicateObject and replicateDelete already build the per-target
replicatedInfos (each replicatedTargetInfo carries Arn, ReplicationStatus
and Err) but discarded it. Return it (callers that only trigger replication
ignore the value - a Go call statement discards it, so the queue paths are
unchanged) and classify the resync from the target whose Arn == opts.arn via
a small pure helper:

- Completed without error -> replicated (+ that target's size, falling back
  to the object size).
- Failed or errored -> failed (+ the object size, fixing FailedSize).
- opts.arn absent from the result (not attempted) -> failed; a resync that
  cannot confirm the object reached the target is not a success.

The StatObject-existence block (including the delete-marker/MethodNotAllowed
special case, now subsumed by the delete outcome) is removed. #134's SSE-C
HEAD marker is left intact - it is needed for genuine SSE-C success.

Adds a table-driven regression for the classifier covering a completed
update, a failed update over an existing version, an errored-but-Completed
result, a delete failure, a delete-marker success (zero bytes) and an
un-attempted ARN. Classifying by existence makes the failed cases count
success and fails the test.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01L7qJqWwy8oFA6aCXWRzXQe
Signed-off-by: Feng Ruohang <[email protected]>
@Vonng
Vonng force-pushed the fix/issue-139-resync-classification branch from 069a5ce to 46e82eb Compare September 6, 2026 10:48
@Vonng

Vonng commented Sep 6, 2026

Copy link
Copy Markdown
Member Author

Independent functional verification, 2026-09-06, against #140 head 46e82eb54df3e8e420ebe421335f613e5b0de681.

The original #139 failure now behaves correctly. I built an isolated integration of main e7d0e62f1 plus #131, #132, #134, #138 and #140, and ran two disposable SILO servers over loopback TLS with the maintained mcli client bec94e4e:

  1. Created and replicated an SSE-C single PUT and a multipart object. Verified plaintext at both ends.
  2. Applied a 100 KiB destination quota, then changed source tags. Both replication attempts failed while the old destination versions still existed and remained readable.
  3. Resync's first terminal record reported 0 successful / 2 failed, with failedReplicationSize=8917248. Source status remained FAILED and destination tags remained stale, matching the actual transfer outcome.
  4. Restarted the source: the same completed record and failure counters were retained.
  5. Cleared the quota and resynced: 2 successful / 0 failed, completedReplicationSize=8917248; both tags converged, source status became COMPLETED, and plaintext SHA-256/VersionID checks passed.
  6. A healthy repeat resync also reported 2/0 on its first terminal record and retained that record across another restart.

The targeted Go test run passed all 161 tests/subtests covering resync, replication action selection, retention removal, replica lock reconciliation, SSE-C PUT/MPU and quota behavior. The eight hosted checks attached to this PR head are green. The prior full integration suite predates #140; this new evidence is targeted tests plus the real transfer/restart matrix, not a claim that a new full suite or published image was tested.

Returning the existing per-target result addresses the root cause and removes the unreliable post-transfer existence inference. Keeping the established benign-412 interpretation is necessary for an already matching replica. No blocking functional finding in this bounded change.

Merge #138 before #140. When integrating #134, the resync-only target HEAD block is superseded by the outcome classifier; retain #134's sender-side SSE-C repair logic. #141 remains a separate dispatch-scoping fix, and #137/#133 remain separate cancellation/multi-pool work. #139 should close when this fix reaches main, not merely because candidate tests pass.

@Vonng
Vonng merged commit 58b0ee3 into main Sep 6, 2026
8 checks passed
@Vonng
Vonng deleted the fix/issue-139-resync-classification branch September 6, 2026 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[P2] Resync counts an existing replica as successful even when its update failed

1 participant