fix: replay plain seal during deferred authority startup

This commit is contained in:
pingqiu committed 2026-11-21 14:14:31 -08:00
1 parent 17c1204fbd
commit 84b39f379b
4 files changed
+70 -4

No files matched your search

@@ -1096,11 +1096,12 @@ var ErrPlainDetachBusy = errors.New("durable: plain detach requires idle fronten
// only the caller context, not the live-serving freeze timer.
func (p *DurableProvider) DetachVolumePlain(ctx context.Context, volumeID string) (storage.ChunkCutResult, uint64, error) {
result, last, err := p.detachVolume(ctx, volumeID, true)
if err != nil && !errors.Is(err, ErrNotChunkVolume) {
if err != nil && !errors.Is(err, ErrNotChunkVolume) && !errors.Is(err, ErrChunkAwaitingAuthority) {
return result, last, err
}
// INV-WS-SEAL-REPLAY-001: success is always a fresh remote proof, also
// after restart when no layer exists. A cached result is not sufficient.
// after restart when no layer exists, including deferred authority startup.
// A cached result is not sufficient.
return p.replayPlainSeal(ctx, volumeID, result)
}
@@ -167,3 +167,63 @@ func TestPlainSealReplayNeverUsesProcessMemory(t *testing.T) {
t.Fatal("re-sent plain seal answered from process memory despite unreadable filer")
}
}
// INV-WS-SEAL-REPLAY-001: deferred healthy startup must not hide a filer seal.
func TestPlainSealReplayDuringDeferredAuthorityStartup(t *testing.T) {
ctx := hangGuard(t)
r := &plainSealReplayRemote{MemChunkRemote: storage.NewMemChunkRemote()}
root := t.TempDir()
first := chunkProvider(t, root, r, v1View(), 0)
s := openRecovered(t, first)
writeSync(t, s, 1, 0x64)
r.mu.Lock()
r.loseSeal = true
r.mu.Unlock()
if _, _, err := first.DetachVolumePlain(ctx, "v1"); !errors.Is(err, durable.ErrDetachOutcomeUnknown) {
t.Fatal("seal did not lose its committed answer", err)
}
sealed := headHolder(t, r.MemChunkRemote)
if err := first.Close(); err != nil {
t.Fatal(err)
}
r.mu.Lock()
r.loseSeal, r.unreadable = false, false
r.mu.Unlock()
view := v1View()
assigned := view.Projection()
assigned.Healthy = false
view.set(assigned)
second := chunkProvider(t, root, r, view, 0)
if _, err := second.EnsureStorage("v1"); err != nil {
t.Fatal(err)
}
if _, err := second.RecoverVolume(ctx, "v1"); err != nil {
t.Fatal(err)
}
// This is the actual awaiting/no-layer schedule, before any healthy attach.
if _, err := second.CaptureVolume(ctx, "v1"); !errors.Is(err, durable.ErrChunkAwaitingAuthority) {
t.Fatal("recovery did not enter deferred authority startup", err)
}
r.mu.Lock()
reads, cas := r.reads, r.cas
r.mu.Unlock()
result, last, err := second.DetachVolumePlain(ctx, "v1")
if err != nil || !reflect.DeepEqual(result.Head, sealed) || result.H != sealed.RemoteLSN || last != sealed.RemoteLSN {
t.Fatalf("awaiting restart did not replay exact filer proof: result=%+v last=%d err=%v", result, last, err)
}
r.mu.Lock()
gotReads, gotCAS := r.reads, r.cas
r.mu.Unlock()
if gotReads <= reads || gotCAS != cas || !reflect.DeepEqual(headHolder(t, r.MemChunkRemote), sealed) {
t.Fatal("replay skipped filer proof or changed sealed HEAD")
}
if view.Projection().Healthy {
t.Fatal("replay made the projection healthy")
}
if _, err := second.CaptureVolume(ctx, "v1"); !errors.Is(err, durable.ErrChunkAwaitingAuthority) {
t.Fatal("replay enabled unhealthy cuts", err)
}
if err := second.Close(); err != nil {
t.Fatal(err)
}
}
+2 -2
View File
@@ -253,7 +253,7 @@ stateDiagram-v2
| Settle pending | an earlier unknown CAS is resolved by re-reading HEAD before any new proposal | `core/storage/chunk_layer.go` `resolvePending` | `INV-WS-CAS-UNKNOWN-001` |
| Stage | native remaining bytes above half the COW side cap trigger logical-read pre-copy straight to remote; repeat only while the remainder shrinks; legacy fixtures retain the chunk-count bound; each new key is intent-rooted first | `core/storage/chunk_layer.go` `stage` | `INV-CUT-INTENT-FIRST-001`, `INV-CUT-STAGED-REUSE-001`, `INV-CUT-PAYLOAD-BOUNDED-001`, `INV-CUT-READ-LOGICAL-001` |
| Plain detach | plain=true acquires exclusive idle frontend admission (closed handles allowed), then StopIO and caller-bounded seal. Busy requests mutate nothing; publication and settlement retain authority/HEAD checks. | `provider_chunk.go` `DetachVolumePlain`; `storage_adapter.go` `stopPlainDetachIfIdle`; `chunk_control.go` `handleChunkDetach` | `INV-CUT-PLAIN-DETACH-001`, `INV-WS-HEAD-BELT-001` |
| Plain seal replay | a fresh filer HEAD must be detached with exact epoch/holder and matching detachedBy generation/epoch/holder; idle admission remains closed, authority is checked across the read, and no CAS occurs. Missing process state is allowed; cache alone never answers success. | `provider_seal_replay.go` `replayPlainSeal`; `chunk_seal_replay.go` `ReadDetachedChunkHead` | `INV-WS-SEAL-REPLAY-001` |
| Plain seal replay | a fresh filer HEAD must be detached with exact epoch/holder and matching detachedBy generation/epoch/holder; idle admission remains closed, authority is checked across the read, and no CAS occurs. Missing process state, including deferred authority startup, is allowed; cache alone never answers success. | `provider_seal_replay.go` `replayPlainSeal`; `chunk_seal_replay.go` `ReadDetachedChunkHead` | `INV-WS-SEAL-REPLAY-001` |
| Pre-copy admission | opt-in: close frontend admission and drain registered operations for at most 100 ms before taking the store barrier; rejected attempts clear the pause and grant every waiter FIFO admission under one lock hold before ordinary uploads; each waiter rechecks the ordinary gate without waiting for another I/O to finish | `precopy_admission.go` `BeginPrecopyPause`; `chunk_precopy.go` `PrecopyDetachWithAdmission` | `INV-CUT-PRECOPY-001` |
| Quiesce | the capture barrier (`captureMu`) is held exclusively, then `Sync` fixes H; `Recover` and writes hold the barrier shared | `core/storage/chunk_layer.go` `captureLocked`; `core/storage/walstore.go` `WALStore.Recover`, `WALStore.Write` | `INV-CUT-QUIESCED-001`, `INV-CUT-RECOVER-BARRIER-001` |
| Pre-copy detach | at most five rolling attempts within a cooperative 60 s context; authoritative candidates and measured costs admit the final cut after the bounded drain; a known estimate may use the declared five-second freeze ceiling when it is at least 90% of the previous comparable known estimate or on the final physical round; frozen commands wait up to the five-second cutover budget and receive FIFO admission grants together after a safe abort, without serializing on I/O completion; each queue bound starts at the command arrival | `chunk_precopy.go`; `precopy_admission.go`; `DurableProvider.DetachVolume` | `INV-CUT-PRECOPY-001` |
@@ -530,7 +530,7 @@ Notes:
| `INV-WS-HEAD-KEY-PROVENANCE-001` | Every key a HEAD names is named by its predecessor HEAD or was uploaded by this owner under an intent that rooted it until the CAS settled; a key that left every root is never named again. | M5 Manifest → CAS | `core/storage/chunk_layer.go` `captureLocked`; `core/frontend/chunkstore/manifest.go` `PrepareManifest` | — | — | STUB |
| `INV-WS-REOPEN-FENCE-001` | Before I/O, an active reopened holder replaces the observed HEAD generation, including the same epoch/holder and an empty HEAD. A previous incarnation's delayed CAS cannot publish afterward. Local acknowledged WAL is retained. | M4 Claiming -> Holder | `core/storage/chunk_restore.go` `ClaimChunkHead`; `core/frontend/durable/provider_chunk.go` `newChunkLayer` | `TestClaimChunkHeadSameOwnerReopenRejectsKilledProcessCAS`, `TestHeadBeltSameOwnerReopenPreservesAcknowledgedWrites` (`core/storage/chunk_reopen_belt_test.go`); `TestLocalReopenClaimsBeforeServing` (`core/frontend/durable/provider_reopen_belt_test.go`) | `HeadReopenBelt` `OldCASCannotLandAfterReopen` | ACTIVE |
| `INV-WS-SEALED-REOPEN-001` | A same-epoch/holder reopen cannot reactivate a detached HEAD. It refuses before preparation, CAS or serving, retaining the exact generation, owner, frontier, image and detachedBy proof for the planned new holder. | M4 Claiming -> Detached | `core/storage/chunk_restore.go` `ClaimChunkHead` | `TestClaimChunkHeadSameOwnerReopenPreservesSeal` (`core/storage/chunk_reopen_belt_test.go`); `TestRestoreEqualOwnerDetachedHEADStaysSealed` (`core/frontend/durable/provider_seed_order_test.go`) | `SealedReopen` `SealedReopenPreservesProof` | ACTIVE |
| `INV-WS-SEAL-REPLAY-001` | A repeated plain seal, also after restart, succeeds only from a fresh filer HEAD with exact owner/epoch and detachedBy proof. It returns that original HEAD/frontier without a CAS or new generation. An unreadable or mismatched proof cannot be answered from process memory. | M5 PlainStop -> RemoteProof -> SealedReply | `core/frontend/durable/provider_seal_replay.go` `replayPlainSeal`; `core/storage/chunk_seal_replay.go` `ReadDetachedChunkHead` | `TestPlainSealLostAnswerRestartReplaysFilerProof`, `TestPlainSealReplayNeverUsesProcessMemory` (`core/frontend/durable/provider_plain_seal_replay_test.go`) | `PlainSealReplay` `SuccessNeedsFreshExactProof`, `ValidProofDoesNotNeedProcessMemory` | ACTIVE |
| `INV-WS-SEAL-REPLAY-001` | A repeated plain seal, also after restart, succeeds only from a fresh filer HEAD with exact owner/epoch and detachedBy proof. It returns that original HEAD/frontier without a CAS or new generation. An unreadable or mismatched proof cannot be answered from process memory. | M5 PlainStop -> RemoteProof -> SealedReply | `core/frontend/durable/provider_seal_replay.go` `replayPlainSeal`; `core/storage/chunk_seal_replay.go` `ReadDetachedChunkHead` | `TestPlainSealLostAnswerRestartReplaysFilerProof`, `TestPlainSealReplayNeverUsesProcessMemory`, `TestPlainSealReplayDuringDeferredAuthorityStartup` (`core/frontend/durable/provider_plain_seal_replay_test.go`) | `PlainSealReplay` `SuccessNeedsFreshExactProof`, `ValidProofDoesNotNeedProcessMemory` | ACTIVE |
| `INV-WS-CAS-UNKNOWN-001` | An unknown HEAD CAS outcome is settled by re-reading HEAD, never by a blind retry; until it is settled the proposal stays pending and its intents stay. | M5 CAS → Pending | `core/storage/chunk_layer.go` `captureLocked`, `resolvePending`; `core/storage/chunk_restore.go` `ClaimChunkHead` | `TestChunkRemote_UncertainCASIsNotPrecondition` (`core/frontend/chunkstore/chunk_remote_test.go`); `TestChunkLayer_C6_UnknownNotAppliedNeverClaimsSuccess` (`core/storage/chunk_layer_contract_test.go`); `TestClaimChunkHeadSettlesUnknownWithoutReplay` (`core/storage/chunk_restore_test.go`); `TestChunkIntent_UncertainCASKeepsIntentUntilSettled` (`core/storage/chunk_layer_intent_test.go`) | — | ACTIVE |
| `INV-WS-CLAIM-BEFORE-SERVE-001` | A new holder claims HEAD at its master-issued epoch before I/O opens; a HEAD with a higher epoch, or another holder at the same epoch, fences the claim. | M4 Claiming → Holder \| Fenced | `core/storage/chunk_restore.go` `ClaimChunkHead`; `core/frontend/durable/provider_chunk.go` `newChunkLayer` | `TestClaimChunkHeadRefusesStaleAuthorityAndAdmissionDrift` (`core/storage/chunk_restore_test.go`); `TestRestoreSeedPrecedesTakeoverCAS` (`core/frontend/durable/provider_seed_order_test.go`); `TestWorkspaceMoveRestoresLazilyAndFencesOldHost` (`core/host/master/workspace_restore_test.go`) | `WorkspaceTakeover` `SeedMatchesTakeover` | ACTIVE |
| `INV-WS-STALE-LOCAL-ROOT-001` | An existing local root whose HEAD another holder has published is not served or cut; the attach fails closed with `ErrChunkStaleLocalRoot`. | M4 Claiming → Refused | `core/frontend/durable/provider_chunk.go` `newChunkLayer` | `TestWALStoreChunk_MoveBackOntoAnOldRootIsRefused`, `TestWALStoreChunk_MoveBackRefusedOnDeferredAttach` (`core/frontend/durable/provider_chunk_moveback_test.go`); `TestLocalReopenRejectsForeignClaimImage` (`core/frontend/durable/provider_reopen_belt_test.go`) | — | ACTIVE |
+5
View File
@@ -636,3 +636,8 @@ that test's lost committed answer -> storage restart -> successful re-send.
Native controls additionally require the original full HEAD and no CAS/new
generation. CAS atomicity, local WAL recovery and remote-call cancellation
remain native/existing-spec obligations rather than claims of this small model.
The provider dispatch control `TestPlainSealReplayDuringDeferredAuthorityStartup`
sets Healthy=false before RecoverVolume, witnesses the no-layer authority wait,
and checks fresh proof replay without CAS or enabling cuts. This is native
integration coverage of the existing RemoteProof transition; the model is unchanged.