mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 19:17:28 +01:00
fix: terminate superseded local roots while retaining move-back diagnostics
This commit is contained in:
1 parent
4a3a66597a
commit
4814ce613c
4 files changed
+89
-61
No files matched your search
@@ -326,62 +326,79 @@ func TestWorkspaceForeignHeadClaimChoosesNoRetry(t *testing.T) {
|
||||
// Unlike a move BACK to an older foreign publication, this local root's
|
||||
// assignment is older than the foreign HEAD: another holder has superseded it.
|
||||
func TestWorkspaceOldLocalHolderForeignHeadChoosesNoRetry(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
h, _ := exitAuthorityHost(t)
|
||||
root := t.TempDir()
|
||||
remote := storage.NewMemChunkRemote()
|
||||
view := &claimExitView{}
|
||||
view.assigned.Store(true)
|
||||
open := func() *durable.DurableProvider {
|
||||
t.Helper()
|
||||
p, err := durable.NewDurableProvider(durable.ProviderConfig{Impl: durable.ImplWALStoreChunk, StorageRoot: root, NumBlocks: 64, BlockSize: 4096, ChunkBlocks: 4, ChunkRemoteFor: func(string) (storage.ChunkRemote, error) { return remote, nil }}, view)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _ = p.Close() })
|
||||
if _, err := p.EnsureStorage("v"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return p
|
||||
}
|
||||
first := open()
|
||||
if _, err := first.RecoverVolume(ctx, "v"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := bytes.Repeat([]byte{0x73}, 4096)
|
||||
if _, err := first.LogicalStorage("v").Write(0, want); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := first.LogicalStorage("v").Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := first.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
before, err := remote.GetHead(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := remote.CASHead(ctx, storage.ChunkHeadVersion{Gen: before.Gen, Epoch: before.Epoch}, storage.ChunkHead{Epoch: 2, Holder: "other", State: storage.ChunkHeadActive}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
second := open()
|
||||
if _, err := second.RecoverVolume(ctx, "v"); !errors.Is(err, storage.ErrChunkLayerFenced) {
|
||||
t.Fatalf("old root refusal=%v", err)
|
||||
}
|
||||
e := newProcessExit(ctx)
|
||||
if !chooseChunkStartupExit(e, flags{workspaceLease: true, durableImpl: "walstore-chunk", volumeID: "v"}, h, second) {
|
||||
t.Fatal("foreign HEAD attach refusal retained the superseded process")
|
||||
}
|
||||
if out := <-e.decision; out.code != 78 {
|
||||
t.Fatalf("old holder exit=%+v", out)
|
||||
}
|
||||
if got, err := second.LogicalStorage("v").Read(0); err != nil || !bytes.Equal(got, want) {
|
||||
t.Fatalf("refusal lost local acknowledged bytes: %v", err)
|
||||
}
|
||||
after, err := remote.GetHead(ctx)
|
||||
if err != nil || after.Gen != before.Gen+1 || after.Holder != "other" || remote.Puts() != 0 {
|
||||
t.Fatalf("refusal mutated HEAD/payload: %+v puts=%d err=%v", after, remote.Puts(), err)
|
||||
for _, deferred := range []bool{false, true} {
|
||||
t.Run(map[bool]string{false: "immediate", true: "waiting"}[deferred], func(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
h, _ := exitAuthorityHost(t)
|
||||
root := t.TempDir()
|
||||
remote := storage.NewMemChunkRemote()
|
||||
view := &claimExitView{}
|
||||
view.assigned.Store(true)
|
||||
open := func() *durable.DurableProvider {
|
||||
t.Helper()
|
||||
p, err := durable.NewDurableProvider(durable.ProviderConfig{Impl: durable.ImplWALStoreChunk, StorageRoot: root, NumBlocks: 64, BlockSize: 4096, ChunkBlocks: 4, ChunkRemoteFor: func(string) (storage.ChunkRemote, error) { return remote, nil }}, view)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _ = p.Close() })
|
||||
if _, err := p.EnsureStorage("v"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return p
|
||||
}
|
||||
first := open()
|
||||
if _, err := first.RecoverVolume(ctx, "v"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := bytes.Repeat([]byte{0x73}, 4096)
|
||||
if _, err := first.LogicalStorage("v").Write(0, want); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := first.LogicalStorage("v").Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := first.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
before, err := remote.GetHead(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := remote.CASHead(ctx, storage.ChunkHeadVersion{Gen: before.Gen, Epoch: before.Epoch}, storage.ChunkHead{Epoch: 2, Holder: "other", State: storage.ChunkHeadActive}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
view.assigned.Store(!deferred)
|
||||
second := open()
|
||||
_, err = second.RecoverVolume(ctx, "v")
|
||||
if deferred {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
view.assigned.Store(true)
|
||||
select {
|
||||
case <-second.ChunkStartupUpdates():
|
||||
case <-ctx.Done():
|
||||
t.Fatal(ctx.Err())
|
||||
}
|
||||
} else if !errors.Is(err, storage.ErrChunkLayerFenced) {
|
||||
t.Fatalf("old root refusal=%v", err)
|
||||
}
|
||||
e := newProcessExit(ctx)
|
||||
if !chooseChunkStartupExit(e, flags{workspaceLease: true, durableImpl: "walstore-chunk", volumeID: "v"}, h, second) {
|
||||
t.Fatal("foreign HEAD attach refusal retained the superseded process")
|
||||
}
|
||||
if out := <-e.decision; out.code != 78 {
|
||||
t.Fatalf("old holder exit=%+v", out)
|
||||
}
|
||||
if got, err := second.LogicalStorage("v").Read(0); err != nil || !bytes.Equal(got, want) {
|
||||
t.Fatalf("refusal lost local acknowledged bytes: %v", err)
|
||||
}
|
||||
after, err := remote.GetHead(ctx)
|
||||
if err != nil || after.Gen != before.Gen+1 || after.Holder != "other" || remote.Puts() != 0 {
|
||||
t.Fatalf("refusal mutated HEAD/payload: %+v puts=%d err=%v", after, remote.Puts(), err)
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -125,7 +125,7 @@ func (p *DurableProvider) recoverChunk(ctx context.Context, volumeID string, h *
|
||||
p.startChunkAuthorityWait(volumeID, h, gen)
|
||||
return false, nil
|
||||
}
|
||||
if errors.Is(err, storage.ErrChunkLayerFenced) && !errors.Is(err, ErrChunkStaleLocalRoot) {
|
||||
if errors.Is(err, storage.ErrChunkLayerFenced) && (!errors.Is(err, ErrChunkStaleLocalRoot) || errors.Is(err, errChunkForeignClaim)) {
|
||||
p.endChunkStartup(h, gen, err)
|
||||
}
|
||||
return err == nil, err
|
||||
@@ -244,7 +244,7 @@ func (p *DurableProvider) chunkAuthorityWait(volumeID string, h *volHandle, gen
|
||||
case errors.Is(err, storage.ErrChunkLayerFenced):
|
||||
ended = "fenced, not serving"
|
||||
log.Printf("durable: chunk layer for volume=%s: %v (not serving)", volumeID, err)
|
||||
if errors.Is(err, ErrChunkStaleLocalRoot) {
|
||||
if errors.Is(err, ErrChunkStaleLocalRoot) && !errors.Is(err, errChunkForeignClaim) {
|
||||
retained = true
|
||||
h.attachMu.Lock()
|
||||
if p.current(h, gen) && h.chunk == nil {
|
||||
@@ -450,6 +450,12 @@ func (p *DurableProvider) newChunkLayer(ctx context.Context, volumeID string, h
|
||||
if head.Gen != 0 && head.Holder != holder {
|
||||
err := fmt.Errorf("%w: %w: volume %s local root %s, HEAD holder %q gen %d epoch %d, local holder %q; remove or quarantine the local root to attach fresh from HEAD",
|
||||
ErrChunkStaleLocalRoot, storage.ErrChunkLayerFenced, volumeID, h.path, head.Holder, head.Gen, head.Epoch, holder)
|
||||
// INV-WS-STARTUP-RETRY-001: at or above this assignment,
|
||||
// the foreign holder is a supersede proof. A lower epoch is
|
||||
// the existing move-back/stale-root diagnostic, never 78.
|
||||
if head.Epoch >= cfg.Epoch {
|
||||
err = fmt.Errorf("%w: %w", err, errChunkForeignClaim)
|
||||
}
|
||||
log.Printf("durable: refusing to attach volume=%s root=%s: HEAD holder=%q gen=%d epoch=%d is not this holder %q (remove or quarantine the local root)",
|
||||
volumeID, h.path, head.Holder, head.Gen, head.Epoch, holder)
|
||||
return err
|
||||
|
||||
@@ -526,3 +526,8 @@ no-retry independently of the assignment stream. Higher epochs of the same
|
||||
holder and fences without that proof retain retry75. Provider generation checks
|
||||
and planned-stop arbitration still apply; no readiness or listen gate changes
|
||||
belong to this classification fix.
|
||||
|
||||
The existing-local-root precheck uses the same distinction: another holder at
|
||||
or above the assigned epoch is positive supersede evidence; an older foreign
|
||||
publication remains the existing move-back diagnostic. Neither path serves or
|
||||
publishes the local WAL, which remains on disk for diagnosis.
|
||||
@@ -671,9 +671,9 @@ Notes:
|
||||
| `INV-WS-FORCED-CONFIRM-LOCAL-001` | A missing or malformed `--confirm-forced` is refused before any connection or RPC, with exit 2. | M2 lease: Expired → Moved (forced) (the explicit-force guard) | `cmd/sw-block/workspace.go` `runWorkspaceForceMove`; `core/rpc/wsclient/wsclient.go` `ParseConfirmation`, `request` | `TestWorkspaceForceMove_Row1_ConfirmationRefusedLocally` (`cmd/sw-block/workspace_test.go`); `TestParseConfirmation` (`core/rpc/wsclient/wsclient_test.go`) | — | ACTIVE |
|
||||
| `INV-WS-FORCED-CONFIRM-HOLDER-001` | A confirmation at an epoch the master reports no holder for, in its lease or its move journal, is refused without sending a move. | M2 lease: Expired → Moved (forced) (the explicit-force guard) | `core/rpc/wsclient/wsclient.go` `holderAt`, `request` | `TestForceMoveResolvesTheHolder` (`core/rpc/wsclient/wsclient_test.go`) | — | ACTIVE |
|
||||
| `INV-WS-FORCED-CONFIRM-NO-BYPASS-001` | No force-move flag bypasses the confirmation, and `--dry-run` is never a confirmation: it sends only a preview, which needs the same confirmation. | M2 lease: Expired → Moved (forced) (the explicit-force guard) | `cmd/sw-block/workspace.go` `runWorkspaceForceMove`, `workspacePreview`; `core/rpc/wsclient/wsclient.go` `PreviewForcedMove` | `TestWorkspaceForceMove_Row2_DryRunPreview`, `TestWorkspaceHelpText` (`cmd/sw-block/workspace_test.go`) | — | ACTIVE |
|
||||
| `INV-WS-STARTUP-RETRY-001` | A workspace primary exits 75 on assignment timeout or lease expiry, with bounded cleanup; a newer other-replica master fact or a refused claim proving another HEAD holder permits 78. ACKed revocation and signal retain normal exit. Lease and claim gates never relax. | M2 restart | `cmd/blockvolume/process_exit.go` `superviseProcess`, `workspaceRetryOutcome`; `core/frontend/durable/provider_startup.go` `endChunkStartup` | `TestChunkAssignmentTimeoutExposesCurrentRecoveryOutcome` (`core/frontend/durable/provider_startup_outcome_test.go`); `TestChunkStartupOutcomeRejectsOldGenerationAndCoalescesWake` (`core/frontend/durable/provider_startup_internal_test.go`); `TestWorkspaceRetryUsesNewestOwnAssignment`, `TestWorkspaceForeignHeadClaimChoosesNoRetry` (`cmd/blockvolume/process_exit_authority_test.go`); `TestWorkspaceExitFirstOutcomeIsLatched`, `TestWorkspaceExitDoesNotWaitForBlockedFrontendClose`, `TestWorkspacePlannedStopKeepsSuccess` (`cmd/blockvolume/process_exit_test.go`) | Existing WorkspaceRegrant restart transition; no new grant rule | ACTIVE |
|
||||
| `INV-WS-STARTUP-RETRY-001` | A workspace primary exits 75 on assignment timeout or lease expiry, with bounded cleanup; a newer other-replica master fact or a refused claim proving another HEAD holder permits 78. ACKed revocation and signal retain normal exit. Lease and claim gates never relax. | M2 restart | `cmd/blockvolume/process_exit.go` `superviseProcess`, `workspaceRetryOutcome`; `core/frontend/durable/provider_startup.go` `endChunkStartup` | `TestChunkAssignmentTimeoutExposesCurrentRecoveryOutcome` (`core/frontend/durable/provider_startup_outcome_test.go`); `TestChunkStartupOutcomeRejectsOldGenerationAndCoalescesWake` (`core/frontend/durable/provider_startup_internal_test.go`); `TestWorkspaceRetryUsesNewestOwnAssignment`, `TestWorkspaceForeignHeadClaimChoosesNoRetry`, `TestWorkspaceOldLocalHolderForeignHeadChoosesNoRetry` (`cmd/blockvolume/process_exit_authority_test.go`); `TestWorkspaceExitFirstOutcomeIsLatched`, `TestWorkspaceExitDoesNotWaitForBlockedFrontendClose`, `TestWorkspacePlannedStopKeepsSuccess` (`cmd/blockvolume/process_exit_test.go`) | Existing WorkspaceRegrant restart transition; no new grant rule | ACTIVE |
|
||||
|
||||
- `INV-WS-STARTUP-RETRY-001`: exit 78 is permitted by a NEWER observed master fact for this volume naming another replica (compared with the latest own assignment, zero before any), or by the exact refused HEAD claim image proving another holder. The provider binds the latter proof to its recovery generation; stale-local-root diagnostics do not become no-retry. A same-holder higher-epoch HEAD fence retries 75. Unknown/no line, same replica at a higher epoch, and status codes alone mean retry 75. A wrong retry costs a bounded restart loop; a wrong 78 causes an outage until an explicit operator start. Sealed same-epoch recovery remains up for read-only replay after assignment; stale local roots, corrupt WAL and I/O faults retain diagnostic wait. The first chosen outcome wins. Process cleanup reuses `WorkspaceDrainTimeout` (5 s), including a blocked Close; only main exits the process.
|
||||
- `INV-WS-STARTUP-RETRY-001`: exit 78 is permitted by a NEWER observed master fact for this volume naming another replica (compared with the latest own assignment, zero before any), or by the exact refused HEAD claim image proving another holder. The provider binds the latter proof to its recovery generation. On an existing root, a foreign HEAD at or above the assigned epoch proves supersede; a lower-epoch foreign HEAD retains the move-back diagnostic. A same-holder higher-epoch HEAD fence retries 75. Unknown/no line, same replica at a higher epoch, and status codes alone mean retry 75. A wrong retry costs a bounded restart loop; a wrong 78 causes an outage until an explicit operator start. Sealed same-epoch recovery remains up for read-only replay after assignment; stale local roots, corrupt WAL and I/O faults retain diagnostic wait. The first chosen outcome wins. Process cleanup reuses `WorkspaceDrainTimeout` (5 s), including a blocked Close; only main exits the process.
|
||||
- Startup arbitration: sealed-replay/stale-local-root dispositions suppress the same wait's deadline defer (`TestChunkStartupRetainedDispositionWinsExpiredAttachContext`, `core/frontend/durable/provider_startup_outcome_test.go`). A stop request retires startup monitoring and its atomic-choice callback before resource cleanup; success is chosen only after the guard's ACK (`TestWorkspacePlannedDrainOwnsStartupExpiryUntilAck`, `cmd/blockvolume/process_exit_authority_test.go`). Provider-validated startup selection briefly takes the process startup mutex; cancellation takes only that mutex. No reverse provider-lock acquisition or remote call occurs.
|
||||
|
||||
- ACK closeout: the guard sets `revoked` under its mutex before calling `drain` and invoking the stop callback. After a drain reply, its ACK call is bounded by the original lease deadline and 2 s RPC timeout. The existing 3 s closeout wait therefore expires before a newly selected retry's 5 s supervisor bound starts; a prior nonzero decision remains immutable. A restart can ACK the sealed HEAD only while the original revoking lease is still valid. Once it expires, re-grant refuses revoking/ACKed leases: repeated 75 is not recovery of an unconfirmed ACK, and operator recovery is required; no lease or ACK gate is bypassed.
|
||||
|
||||
Reference in new issue
Block a user