diff --git a/seaweed-block/cmd/blockvolume/master_crash_integration_test.go b/seaweed-block/cmd/blockvolume/master_crash_integration_test.go index 4ed789162f..e38f77ea25 100644 --- a/seaweed-block/cmd/blockvolume/master_crash_integration_test.go +++ b/seaweed-block/cmd/blockvolume/master_crash_integration_test.go @@ -45,7 +45,7 @@ func TestProcedureMasterKilledAfterMoveBeforeTargetStarts(t *testing.T) { } } out, _ = env.h.command(t, env.chunkShow()...) - if got := mustU(sealedHeadLSN(out, e, g)); got != l { + if got := mustU(sealedLayoutHeadPosition(out, e, g)); got != l { t.Fatalf("sealed HEAD LSN %d; want %d", got, l) } nw := env.start(t, "blockvolume-s2", "s2") diff --git a/seaweed-block/cmd/blockvolume/planned_handoff_checks_test.go b/seaweed-block/cmd/blockvolume/planned_handoff_checks_test.go index 938d736167..59cdaafe6e 100644 --- a/seaweed-block/cmd/blockvolume/planned_handoff_checks_test.go +++ b/seaweed-block/cmd/blockvolume/planned_handoff_checks_test.go @@ -138,12 +138,16 @@ func sealedLayoutHeadPosition(out string, epoch, gen uint64) (uint64, error) { } func checkLayoutHeadReopened(out string, epoch, sealedGen, position uint64) error { + return checkLayoutHeadReopenedBy(out, epoch, sealedGen, position, "s1") +} + +func checkLayoutHeadReopenedBy(out string, epoch, sealedGen, position uint64, host string) error { h, err := parseLayoutHead(out) if err != nil { return err } - if h.Gen <= sealedGen || h.Epoch != epoch || h.Holder != "s1/r1" || h.ClaimID == "" || h.State != "" || h.Position != position || len(h.Current) == 0 || string(h.Current) == "null" { - return fmt.Errorf("layout HEAD after claim %+v; want live image above gen %d at epoch %d position %d holder s1/r1", h, sealedGen, epoch, position) + if h.Gen <= sealedGen || h.Epoch != epoch || h.Holder != host+"/r1" || h.ClaimID == "" || h.State != "" || h.Position != position || len(h.Current) == 0 || string(h.Current) == "null" { + return fmt.Errorf("layout HEAD after claim %+v; want live image above gen %d at epoch %d position %d holder %s/r1", h, sealedGen, epoch, position, host) } return nil } diff --git a/seaweed-block/cmd/blockvolume/procedure_crash_io_integration_test.go b/seaweed-block/cmd/blockvolume/procedure_crash_io_integration_test.go index 1d7e7eb38f..059ea0146d 100644 --- a/seaweed-block/cmd/blockvolume/procedure_crash_io_integration_test.go +++ b/seaweed-block/cmd/blockvolume/procedure_crash_io_integration_test.go @@ -386,7 +386,7 @@ func TestProcedureCrashDuringACut(t *testing.T) { verify := []string{"ops", "chunk", "verify", "--volume", "v1", "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath, "--depth", "data", "--timeout", "5m"} headGen := func() uint64 { out, _ := env.h.command(t, env.chunkShow()...) - h, err := parseHead(out) + h, err := parseLayoutHead(out) if err != nil { t.Fatal(err) } diff --git a/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go b/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go index 46e465b9ca..f901473a9e 100644 --- a/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go +++ b/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go @@ -76,7 +76,7 @@ func TestProcedureLocalDiskFull(t *testing.T) { verify := []string{"ops", "chunk", "verify", "--volume", "v1", "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath, "--depth", "data", "--timeout", "5m"} headGen := func() uint64 { out, _ := env.h.command(t, env.chunkShow()...) - hd, err := parseHead(out) + hd, err := parseLayoutHead(out) if err != nil { t.Fatal(err) } diff --git a/seaweed-block/cmd/blockvolume/procedure_gate_integration_test.go b/seaweed-block/cmd/blockvolume/procedure_gate_integration_test.go index 668e914ad0..6bca32185b 100644 --- a/seaweed-block/cmd/blockvolume/procedure_gate_integration_test.go +++ b/seaweed-block/cmd/blockvolume/procedure_gate_integration_test.go @@ -58,7 +58,7 @@ func TestProcedurePlannedHandoffToAnotherHost(t *testing.T) { must(wantLines(out, fmt.Sprintf("holder: r1@%d (logical replica)", e2), fmt.Sprintf("move: request=move-v1-1 kind=clean issued=true s1/r1@%d -> s2/r1@%d HEAD generation %d remote LSN %d", e, e2, g, l))) out, _ = h.command(t, env.chunkShow()...) - must(checkHeadReopenedBy(out, e2, g, l, "s2")) + must(checkLayoutHeadReopenedBy(out, e2, g, l, "s2")) if !bytes.Equal(env.readBlock(t, "s2", 0), block) { t.Fatal("the block written on s1 does not read back on s2") } @@ -387,12 +387,12 @@ func (env *handoffEnv) servingNow(id string) bool { func (env *handoffEnv) requireHeadHolder(t *testing.T, e uint64, host string) { t.Helper() out, _ := env.h.command(t, env.chunkShow()...) - head, err := parseHead(out) + head, err := parseLayoutHead(out) if err != nil { t.Fatal(err) } - if head.State != "active" || head.Epoch != e || head.Holder != host+"/r1" { - t.Fatalf("HEAD %+v; want active at epoch %d held by %s/r1", head, e, host) + if head.State != "" || head.ClaimID == "" || head.Epoch != e || head.Holder != host+"/r1" { + t.Fatalf("HEAD %+v; want live at epoch %d held by %s/r1", head, e, host) } } @@ -464,7 +464,7 @@ func (env *handoffEnv) sealedLSN(t *testing.T, e, g uint64) uint64 { t.Helper() _, mustU := fatalOn(t) out, _ := env.h.command(t, env.chunkShow()...) - return mustU(sealedHeadLSN(out, e, g)) + return mustU(sealedLayoutHeadPosition(out, e, g)) } func (env *handoffEnv) revoke(t *testing.T, e, g uint64) { diff --git a/seaweed-block/cmd/blockvolume/procedure_layout_head_checks_test.go b/seaweed-block/cmd/blockvolume/procedure_layout_head_checks_test.go new file mode 100644 index 0000000000..abb8110b1b --- /dev/null +++ b/seaweed-block/cmd/blockvolume/procedure_layout_head_checks_test.go @@ -0,0 +1,61 @@ +package main_test + +import ( + "encoding/json" + "testing" + + "github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/layout" +) + +// chunk show marshals layout.Head, not the on-store headDoc or the retired +// storage HEAD. Keep the procedure checks tied to that actual output type. +func TestProcedureLayoutHeadChecksReadProductShape(t *testing.T) { + show := func(h layout.Head) string { + t.Helper() + b, err := json.Marshal(struct { + Head layout.Head `json:"head"` + }{h}) + if err != nil { + t.Fatal(err) + } + return string(b) + } + sealed := layout.Head{Gen: 7, Epoch: 3, Holder: "s1/r1", ClaimID: "claim", + Position: 91, State: layout.StateDetached, Current: &layout.RootName{Hash: layout.Hash{1}}} + if got, err := sealedLayoutHeadPosition(show(sealed), 3, 7); err != nil || got != 91 { + t.Fatalf("detached layout image: position=%d err=%v", got, err) + } + live := sealed + live.Gen, live.Epoch, live.Holder, live.ClaimID, live.State = 8, 4, "s2/r1", "next-claim", layout.StateLive + if err := checkLayoutHeadReopenedBy(show(live), 4, 7, 91, "s2"); err != nil { + t.Fatal(err) + } + for _, tc := range []struct { + name string + mutate func(*layout.Head) + }{ + {"generation", func(h *layout.Head) { h.Gen = 6 }}, + {"epoch", func(h *layout.Head) { h.Epoch++ }}, + {"holder", func(h *layout.Head) { h.Holder = "foreign/r1" }}, + {"claim", func(h *layout.Head) { h.ClaimID = "" }}, + {"image", func(h *layout.Head) { h.Current = nil }}, + {"state", func(h *layout.Head) { h.State = layout.StateDeleting }}, + } { + t.Run(tc.name, func(t *testing.T) { + h := sealed + tc.mutate(&h) + if _, err := sealedLayoutHeadPosition(show(h), 3, 7); err == nil { + t.Fatal("invalid detached proof accepted") + } + h = live + tc.mutate(&h) + if err := checkLayoutHeadReopenedBy(show(h), 4, 7, 91, "s2"); err == nil { + t.Fatal("invalid successor accepted") + } + }) + } + live.Position++ + if err := checkLayoutHeadReopenedBy(show(live), 4, 7, 91, "s2"); err == nil { + t.Fatal("changed committed position accepted") + } +} diff --git a/seaweed-block/cmd/blockvolume/procedure_plain_detach_crash_integration_test.go b/seaweed-block/cmd/blockvolume/procedure_plain_detach_crash_integration_test.go index d4d681de15..85041eaa8a 100644 --- a/seaweed-block/cmd/blockvolume/procedure_plain_detach_crash_integration_test.go +++ b/seaweed-block/cmd/blockvolume/procedure_plain_detach_crash_integration_test.go @@ -26,8 +26,8 @@ func TestProcedureKillDuringPlainDetachThenCompleteHandoff(t *testing.T) { env.writeCutCrashImage(t, 'A') env.h.command(t, "ops", "chunk", "cut", "--volume", "v1", "--status-addr", env.hosts["s1"].status) out, _ := env.h.command(t, env.chunkShow()...) - before, err := parseHead(out) - if err != nil || before.State != "active" || before.Epoch != e { + before, err := parseLayoutHead(out) + if err != nil || before.State != "" || before.ClaimID == "" || before.Epoch != e { t.Fatalf("baseline HEAD: %+v: %v", before, err) } env.writeCutCrashImage(t, 'B') @@ -55,11 +55,11 @@ func TestProcedureKillDuringPlainDetachThenCompleteHandoff(t *testing.T) { t.Fatal(err) } out, _ = env.h.command(t, env.chunkShow()...) - atKill, err := parseHead(out) - if err != nil || atKill.Gen != before.Gen || atKill.State != "active" || atKill.RemoteLSN != before.RemoteLSN { + atKill, err := parseLayoutHead(out) + if err != nil || atKill.Gen != before.Gen || atKill.State != "" || atKill.ClaimID != before.ClaimID || atKill.Position != before.Position { t.Fatalf("missed mid-upload window: before=%+v stopped=%+v: %v", before, atKill, err) } - t.Logf("kill witness: immutable keys %d -> %d, HEAD gen=%d LSN=%d remains active", keys, plainDetachStoredKeys(t, env), atKill.Gen, atKill.RemoteLSN) + t.Logf("kill witness: immutable keys %d -> %d, HEAD gen=%d LSN=%d remains active", keys, plainDetachStoredKeys(t, env), atKill.Gen, atKill.Position) select { case <-cli.done: t.Fatal("detach completed or aborted before the verified kill window") @@ -91,8 +91,8 @@ func TestProcedureKillDuringPlainDetachThenCompleteHandoff(t *testing.T) { env.requireCutCrashImage(t, "s1", 'B') g := env.seal(t, "s1", e) l := env.sealedLSN(t, e, g) - if l <= before.RemoteLSN { - t.Fatalf("retry did not publish the acknowledged image: remote LSN %d <= baseline %d", l, before.RemoteLSN) + if l <= before.Position { + t.Fatalf("retry did not publish the acknowledged image: remote LSN %d <= baseline %d", l, before.Position) } if again := env.seal(t, "s1", e); again != g { t.Fatalf("plain seal replay changed generation %d -> %d", g, again) diff --git a/seaweed-block/cmd/blockvolume/procedure_powerloss_integration_test.go b/seaweed-block/cmd/blockvolume/procedure_powerloss_integration_test.go index 622d96c4a0..f31b5b2479 100644 --- a/seaweed-block/cmd/blockvolume/procedure_powerloss_integration_test.go +++ b/seaweed-block/cmd/blockvolume/procedure_powerloss_integration_test.go @@ -52,7 +52,7 @@ func TestPowerLossReplayChunkVolume(t *testing.T) { verify := []string{"ops", "chunk", "verify", "--volume", "v1", "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath, "--depth", "data", "--timeout", "5m"} headGen := func() uint64 { out, _ := env.h.command(t, env.chunkShow()...) - hd, err := parseHead(out) + hd, err := parseLayoutHead(out) if err != nil { t.Fatal(err) } diff --git a/seaweed-block/cmd/blockvolume/procedure_store_down_integration_test.go b/seaweed-block/cmd/blockvolume/procedure_store_down_integration_test.go index ffbde08a48..8c864c6c48 100644 --- a/seaweed-block/cmd/blockvolume/procedure_store_down_integration_test.go +++ b/seaweed-block/cmd/blockvolume/procedure_store_down_integration_test.go @@ -69,7 +69,7 @@ func storeDownDuringACut(t *testing.T, down string, cowBytes int64, cowWindow bo verify := []string{"ops", "chunk", "verify", "--volume", "v1", "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath, "--depth", "data", "--timeout", "5m"} headGen := func() uint64 { out, _ := env.h.command(t, env.chunkShow()...) - hd, err := parseHead(out) + hd, err := parseLayoutHead(out) if err != nil { t.Fatal(err) }