From 5a2fe0c657f9493a8ac9a67e7cdec38c44e4f665 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 21 Nov 2026 19:40:47 -0800 Subject: [PATCH 1/9] test: witness sealed same-host clean move and binding retirement --- .../workspace_same_host_clean_test.go | 57 ++++++++++++++++++ .../master/workspace_same_host_clean_test.go | 58 +++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 seaweed-block/core/authority/workspace_same_host_clean_test.go create mode 100644 seaweed-block/core/host/master/workspace_same_host_clean_test.go diff --git a/seaweed-block/core/authority/workspace_same_host_clean_test.go b/seaweed-block/core/authority/workspace_same_host_clean_test.go new file mode 100644 index 0000000000..de0052305c --- /dev/null +++ b/seaweed-block/core/authority/workspace_same_host_clean_test.go @@ -0,0 +1,57 @@ +package authority + +import ( + "context" + "testing" + "time" +) + +// INV-WS-SAME-HOST-CLEAN-MOVE-001: an unchanged sealed generation and its +// durable ACK remain a clean-move proof after the lease expires overnight. +func TestWorkspaceSameHostCleanMoveUsesOvernightSeal(t *testing.T) { + disk, _ := newTempStore(t) + clock := newTestClock() + p := newLeasePublisher(t, disk, time.Second, clock) + bindAndGrant(t, p, "v", "r") + ctx := context.Background() + if err := p.BeginWorkspaceRevocation(ctx, "v", "r", 1); err != nil { + t.Fatal(err) + } + if err := p.AckWorkspaceRevocation(ctx, "v", WorkspaceRevokeAck{ReplicaID: "r", Epoch: 1, HeadGen: 7}); err != nil { + t.Fatal(err) + } + clock.at(86400) + req := WorkspaceMoveRequest{RequestID: "return", VolumeID: "v", ExpectedReplicaID: "r", TargetReplicaID: "r", ExpectedHost: "host", TargetHost: "host", ExpectedEpoch: 1, TargetDataAddr: "d", TargetCtrlAddr: "c", Kind: "clean"} + head := WorkspaceHead{Gen: 7, Epoch: 1, Holder: "host/r", RemoteLSN: 42, Detached: true} + for _, bad := range []WorkspaceHead{ + {Gen: 7, Epoch: 1, Holder: "host/r", RemoteLSN: 42}, + {Gen: 8, Epoch: 1, Holder: "host/r", RemoteLSN: 42, Detached: true}, + } { + if _, err := p.MoveWorkspace(ctx, req, bad); err == nil { + t.Fatal("same-host move bypassed sealed-generation proof", bad) + } + } + forced := req + forced.Kind, forced.Force = "forced", true + if _, err := p.MoveWorkspace(ctx, forced, head); err == nil { + t.Fatal("same-host forced move accepted") + } + if line, _ := p.VolumeAuthorityLine("v"); line.Epoch != 1 || len(p.WorkspaceState("v").Moves) != 0 { + t.Fatal("refusal reserved or published authority", line) + } + grant, err := p.MoveWorkspace(ctx, req, head) + if err != nil { + t.Fatal("sealed same-host clean move refused", err) + } + if !grant.Issued || grant.NewEpoch != 2 || grant.OldHost != "host" || grant.NewHost != "host" || grant.HeadGen != 7 || grant.RemoteLSN != 42 { + t.Fatal("wrong journaled successor", grant) + } + again, err := p.MoveWorkspace(ctx, req, WorkspaceHead{}) + if err != nil || again != grant { + t.Fatal("same-ID replay changed the successor", again, err) + } + loaded := NewPublisher(nil, WithStore(disk)).WorkspaceState("v") + if loaded == nil || len(loaded.Moves) != 1 || loaded.Moves[0] != grant { + t.Fatal("same-host grant not durable", loaded) + } +} diff --git a/seaweed-block/core/host/master/workspace_same_host_clean_test.go b/seaweed-block/core/host/master/workspace_same_host_clean_test.go new file mode 100644 index 0000000000..d45ca68761 --- /dev/null +++ b/seaweed-block/core/host/master/workspace_same_host_clean_test.go @@ -0,0 +1,58 @@ +package master + +import ( + "testing" + + control "github.com/seaweedfs/seaweed-block/core/rpc/control" +) + +// INV-WS-SAME-HOST-CLEAN-MOVE-001: retirement belongs to an epoch, so the +// old epoch's replay cannot retire the re-prepared same-host binding. +func TestWorkspaceRPCSameHostCleanMoveKeepsRepreparedBinding(t *testing.T) { + h, conn, ctx := reviewBindingHost(t) + reviewCreate(t, conn, ctx, "v") + ws := control.NewWorkspaceServiceClient(conn) + b := &control.WorkspaceBinding{VolumeId: "v", ServerId: "node-a", DataAddr: "127.0.0.1:10000", CtrlAddr: "127.0.0.1:10001"} + if _, err := ws.RegisterWorkspaceBinding(ctx, b); err != nil { + t.Fatal(err) + } + if _, err := ws.PlaceWorkspace(ctx, &control.WorkspacePlacement{VolumeId: "v", ServerId: "node-a", ReplicaId: "r1"}); err != nil { + t.Fatal(err) + } + reviewHeartbeat(t, conn, ctx, "v", "node-a", b.DataAddr, b.CtrlAddr) + if _, err := h.RunLifecycleProductTick(); err != nil { + t.Fatal(err) + } + if line := waitAuthorityLine(t, h.Publisher(), "v"); line.Epoch != 1 { + t.Fatal(line) + } + id := &control.WorkspaceIdentity{VolumeId: "v", ReplicaId: "r1", Epoch: 1} + if _, err := ws.RenewWorkspaceLease(ctx, id); err != nil { + t.Fatal(err) + } + if _, err := ws.RevokeWorkspace(ctx, id); err != nil { + t.Fatal(err) + } + if _, err := ws.AckWorkspaceRevoked(ctx, &control.WorkspaceRevocationAck{Identity: id, HeadGen: 9}); err != nil { + t.Fatal(err) + } + if got, ok, err := h.Lifecycle().WorkspaceBindings.Get("v"); err != nil || !ok || !got.Retired { + t.Fatal("ACK did not retire the old binding", got, err) + } + if _, err := ws.RegisterWorkspaceBinding(ctx, b); err != nil { + t.Fatal("same-host re-prepare refused", err) + } + req := &control.WorkspaceMove{RequestId: "return", VolumeId: "v", ExpectedReplicaId: "r1", ExpectedEpoch: 1, TargetReplicaId: "r1", TargetServerId: "node-a", TargetDataAddr: b.DataAddr, TargetCtrlAddr: b.CtrlAddr, Kind: "clean"} + if _, err := ws.MoveWorkspace(ctx, req); err != nil { + t.Fatal("same-host clean move refused over RPC", err) + } + if _, err := ws.MoveWorkspace(ctx, req); err != nil { + t.Fatal("same-host move replay refused", err) + } + if line, _ := h.Publisher().VolumeAuthorityLine("v"); line.Epoch != 2 || line.DataAddr != b.DataAddr || line.CtrlAddr != b.CtrlAddr { + t.Fatal("same-host move did not publish exactly the next epoch", line) + } + if got, ok, err := h.Lifecycle().WorkspaceBindings.Get("v"); err != nil || !ok || got.Retired { + t.Fatal("old epoch retired the re-prepared binding", got, err) + } +} From 11079b620a7e6bfe24e8085eb08144a0b346e27c Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 21 Nov 2026 19:41:06 -0800 Subject: [PATCH 2/9] test: inspect the volume binding list explicitly --- .../core/host/master/workspace_same_host_clean_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/seaweed-block/core/host/master/workspace_same_host_clean_test.go b/seaweed-block/core/host/master/workspace_same_host_clean_test.go index d45ca68761..74df103b90 100644 --- a/seaweed-block/core/host/master/workspace_same_host_clean_test.go +++ b/seaweed-block/core/host/master/workspace_same_host_clean_test.go @@ -36,7 +36,7 @@ func TestWorkspaceRPCSameHostCleanMoveKeepsRepreparedBinding(t *testing.T) { if _, err := ws.AckWorkspaceRevoked(ctx, &control.WorkspaceRevocationAck{Identity: id, HeadGen: 9}); err != nil { t.Fatal(err) } - if got, ok, err := h.Lifecycle().WorkspaceBindings.Get("v"); err != nil || !ok || !got.Retired { + if got, ok, err := h.Lifecycle().WorkspaceBindings.Get("v"); err != nil || !ok || len(got) != 1 || !got[0].Retired { t.Fatal("ACK did not retire the old binding", got, err) } if _, err := ws.RegisterWorkspaceBinding(ctx, b); err != nil { @@ -52,7 +52,7 @@ func TestWorkspaceRPCSameHostCleanMoveKeepsRepreparedBinding(t *testing.T) { if line, _ := h.Publisher().VolumeAuthorityLine("v"); line.Epoch != 2 || line.DataAddr != b.DataAddr || line.CtrlAddr != b.CtrlAddr { t.Fatal("same-host move did not publish exactly the next epoch", line) } - if got, ok, err := h.Lifecycle().WorkspaceBindings.Get("v"); err != nil || !ok || got.Retired { + if got, ok, err := h.Lifecycle().WorkspaceBindings.Get("v"); err != nil || !ok || len(got) != 1 || got[0].Retired { t.Fatal("old epoch retired the re-prepared binding", got, err) } } From 26702a36aa7537292359ac5dd51f18b3ba448638 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 21 Nov 2026 20:00:07 -0800 Subject: [PATCH 3/9] fix: allow sealed clean moves to return to the same host --- seaweed-block/core/authority/workspace.go | 5 +++-- seaweed-block/core/host/master/workspace_service.go | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/seaweed-block/core/authority/workspace.go b/seaweed-block/core/authority/workspace.go index 9f3046cbb2..adae4867fa 100644 --- a/seaweed-block/core/authority/workspace.go +++ b/seaweed-block/core/authority/workspace.go @@ -153,12 +153,13 @@ func (p *Publisher) RecordWorkspaceDeletion(ctx context.Context, volume string, } func validateWorkspaceMoveRequest(req WorkspaceMoveRequest) error { - // v1 moves a replica between hosts without changing its logical slot. + // INV-WS-SAME-HOST-CLEAN-MOVE-001: clean moves may reuse the host, + // but every move preserves its logical replica slot. // Refuse before locking or persisting a reservation/authority epoch. if req.ExpectedReplicaID != req.TargetReplicaID { return fmt.Errorf("workspace move: v1 requires the same logical replica id") } - if req.RequestID == "" || req.VolumeID == "" || req.ExpectedHost == "" || req.TargetHost == "" || req.ExpectedHost == req.TargetHost || req.ExpectedReplicaID == "" || req.ExpectedEpoch == 0 || req.TargetReplicaID == "" || + if req.RequestID == "" || req.VolumeID == "" || req.ExpectedHost == "" || req.TargetHost == "" || (req.ExpectedHost == req.TargetHost && (req.Kind != "clean" || req.Force)) || req.ExpectedReplicaID == "" || req.ExpectedEpoch == 0 || req.TargetReplicaID == "" || req.TargetDataAddr == "" || req.TargetCtrlAddr == "" || (req.Kind != "clean" && req.Kind != "forced") || req.Force != (req.Kind == "forced") { return fmt.Errorf("workspace move: invalid request") } diff --git a/seaweed-block/core/host/master/workspace_service.go b/seaweed-block/core/host/master/workspace_service.go index fa363061f0..30ef4387bc 100644 --- a/seaweed-block/core/host/master/workspace_service.go +++ b/seaweed-block/core/host/master/workspace_service.go @@ -323,7 +323,9 @@ func (s *services) workspaceMoveCheckLocked(q *control.WorkspaceMove) (req autho refusal = fmt.Sprintf("move source unknown: no issued move or placement names replica %q at epoch %d", q.GetExpectedReplicaId(), q.GetExpectedEpoch()) case !ok: refusal = fmt.Sprintf("move target node %q is not registered", q.GetTargetServerId()) - case target.ServerID == oldHost: + // INV-WS-SAME-HOST-CLEAN-MOVE-001: the authority clean-proof + // checks still run after these endpoint and binding checks. + case target.ServerID == oldHost && (q.GetKind() != "clean" || q.GetForce()): refusal = fmt.Sprintf("move target %q is the current source host", target.ServerID) case !replay && s.host.colocatedTargetRefused(target.ServerID): refusal = fmt.Sprintf("move target node %q shares the authority store's file system (strict journal isolation)", target.ServerID) From 1f2bcd82bb21c9e624da0706336ff79c08aa1195 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 21 Nov 2026 20:01:49 -0800 Subject: [PATCH 4/9] test: preserve same-host clean proof and sealed image controls --- .../workspace_same_host_clean_test.go | 9 +++- .../master/workspace_move_refusal_test.go | 4 +- .../master/workspace_same_host_clean_test.go | 10 ++++- .../storage/chunk_same_host_clean_test.go | 41 +++++++++++++++++++ 4 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 seaweed-block/core/storage/chunk_same_host_clean_test.go diff --git a/seaweed-block/core/authority/workspace_same_host_clean_test.go b/seaweed-block/core/authority/workspace_same_host_clean_test.go index de0052305c..4473ebd22f 100644 --- a/seaweed-block/core/authority/workspace_same_host_clean_test.go +++ b/seaweed-block/core/authority/workspace_same_host_clean_test.go @@ -14,6 +14,11 @@ func TestWorkspaceSameHostCleanMoveUsesOvernightSeal(t *testing.T) { p := newLeasePublisher(t, disk, time.Second, clock) bindAndGrant(t, p, "v", "r") ctx := context.Background() + req := WorkspaceMoveRequest{RequestID: "return", VolumeID: "v", ExpectedReplicaID: "r", TargetReplicaID: "r", ExpectedHost: "host", TargetHost: "host", ExpectedEpoch: 1, TargetDataAddr: "d", TargetCtrlAddr: "c", Kind: "clean"} + head := WorkspaceHead{Gen: 7, Epoch: 1, Holder: "host/r", RemoteLSN: 42, Detached: true} + if _, err := p.MoveWorkspace(ctx, req, head); err == nil { + t.Fatal("same-host move accepted a seal without revocation ACK") + } if err := p.BeginWorkspaceRevocation(ctx, "v", "r", 1); err != nil { t.Fatal(err) } @@ -21,11 +26,11 @@ func TestWorkspaceSameHostCleanMoveUsesOvernightSeal(t *testing.T) { t.Fatal(err) } clock.at(86400) - req := WorkspaceMoveRequest{RequestID: "return", VolumeID: "v", ExpectedReplicaID: "r", TargetReplicaID: "r", ExpectedHost: "host", TargetHost: "host", ExpectedEpoch: 1, TargetDataAddr: "d", TargetCtrlAddr: "c", Kind: "clean"} - head := WorkspaceHead{Gen: 7, Epoch: 1, Holder: "host/r", RemoteLSN: 42, Detached: true} for _, bad := range []WorkspaceHead{ {Gen: 7, Epoch: 1, Holder: "host/r", RemoteLSN: 42}, {Gen: 8, Epoch: 1, Holder: "host/r", RemoteLSN: 42, Detached: true}, + {Gen: 7, Epoch: 1, Holder: "other/r", RemoteLSN: 42, Detached: true}, + {Gen: 7, Epoch: 2, Holder: "host/r", RemoteLSN: 42, Detached: true}, } { if _, err := p.MoveWorkspace(ctx, req, bad); err == nil { t.Fatal("same-host move bypassed sealed-generation proof", bad) diff --git a/seaweed-block/core/host/master/workspace_move_refusal_test.go b/seaweed-block/core/host/master/workspace_move_refusal_test.go index 9a7e113705..8c3196aa03 100644 --- a/seaweed-block/core/host/master/workspace_move_refusal_test.go +++ b/seaweed-block/core/host/master/workspace_move_refusal_test.go @@ -95,6 +95,8 @@ func TestWorkspaceMoveRefusalNamesTheMissingPrecondition(t *testing.T) { return &control.WorkspaceMove{RequestId: vol + "-" + server + "-" + data, VolumeId: vol, ExpectedReplicaId: "r1", ExpectedEpoch: 1, TargetReplicaId: "r1", TargetServerId: server, TargetDataAddr: data, TargetCtrlAddr: ctrl, Kind: "clean"} } + forcedSource := move("placed", "node-a", "127.0.0.1:19101", "127.0.0.1:19102") + forcedSource.Kind, forcedSource.Force = "forced", true for _, c := range []struct { name string q *control.WorkspaceMove @@ -102,7 +104,7 @@ func TestWorkspaceMoveRefusalNamesTheMissingPrecondition(t *testing.T) { }{ {"unknown source", move("unplaced", "node-b", "127.0.0.1:19301", "127.0.0.1:19302"), `move source unknown: no issued move or placement names replica "r1" at epoch 1`}, {"unknown target node", move("placed", "node-z", "127.0.0.1:19301", "127.0.0.1:19302"), `move target node "node-z" is not registered`}, - {"target is the source", move("placed", "node-a", "127.0.0.1:19101", "127.0.0.1:19102"), `move target "node-a" is the current source host`}, + {"forced target is the source", forcedSource, `move target "node-a" is the current source host`}, {"target on another host", move("placed", "node-b", "10.9.9.9:19311", "127.0.0.1:19312"), `move target endpoints 10.9.9.9:19311/127.0.0.1:19312 on "node-b" are not registered (not on the node's hosts: it registers 127.0.0.1:19301/127.0.0.1:19302; no per-volume binding is prepared)`}, {"explicit binding elsewhere", move("bound", "node-b", "127.0.0.1:19301", "127.0.0.1:19302"), diff --git a/seaweed-block/core/host/master/workspace_same_host_clean_test.go b/seaweed-block/core/host/master/workspace_same_host_clean_test.go index 74df103b90..e518160a4c 100644 --- a/seaweed-block/core/host/master/workspace_same_host_clean_test.go +++ b/seaweed-block/core/host/master/workspace_same_host_clean_test.go @@ -39,10 +39,18 @@ func TestWorkspaceRPCSameHostCleanMoveKeepsRepreparedBinding(t *testing.T) { if got, ok, err := h.Lifecycle().WorkspaceBindings.Get("v"); err != nil || !ok || len(got) != 1 || !got[0].Retired { t.Fatal("ACK did not retire the old binding", got, err) } + req := &control.WorkspaceMove{RequestId: "return", VolumeId: "v", ExpectedReplicaId: "r1", ExpectedEpoch: 1, TargetReplicaId: "r1", TargetServerId: "node-a", TargetDataAddr: b.DataAddr, TargetCtrlAddr: b.CtrlAddr, Kind: "clean"} + if _, err := ws.MoveWorkspace(ctx, req); err == nil { + t.Fatal("same-host move accepted an unprepared retired binding") + } if _, err := ws.RegisterWorkspaceBinding(ctx, b); err != nil { t.Fatal("same-host re-prepare refused", err) } - req := &control.WorkspaceMove{RequestId: "return", VolumeId: "v", ExpectedReplicaId: "r1", ExpectedEpoch: 1, TargetReplicaId: "r1", TargetServerId: "node-a", TargetDataAddr: b.DataAddr, TargetCtrlAddr: b.CtrlAddr, Kind: "clean"} + forced := *req + forced.Kind, forced.Force = "forced", true + if _, err := ws.MoveWorkspace(ctx, &forced); err == nil { + t.Fatal("same-host forced move accepted over RPC") + } if _, err := ws.MoveWorkspace(ctx, req); err != nil { t.Fatal("same-host clean move refused over RPC", err) } diff --git a/seaweed-block/core/storage/chunk_same_host_clean_test.go b/seaweed-block/core/storage/chunk_same_host_clean_test.go new file mode 100644 index 0000000000..1dfb88a699 --- /dev/null +++ b/seaweed-block/core/storage/chunk_same_host_clean_test.go @@ -0,0 +1,41 @@ +package storage + +import ( + "bytes" + "errors" + "testing" +) + +// INV-WS-SAME-HOST-CLEAN-MOVE-001: the returning host consumes its sealed +// image only with a newly issued epoch; same-epoch reopening stays sealed. +func TestClaimChunkHeadSameHostCleanMovePreservesSealedImage(t *testing.T) { + s, _ := newChunkTestStore(t) + r := newFakeChunkRemote() + layer := mustAttach(t, s, r, ctConfig(1)) + want := makeBlock(4096, 0x63) + if _, err := s.Write(0, want); err != nil { + t.Fatal(err) + } + if _, err := s.Sync(); err != nil { + t.Fatal(err) + } + if _, err := layer.Detach(ctTimeout(t)); err != nil { + t.Fatal(err) + } + sealed := copyHead(r.stats().head) + if _, err := ClaimChunkHead(ctTimeout(t), r, ctConfig(1)); !errors.Is(err, ErrChunkLayerDetached) || !sameHead(r.stats().head, sealed) { + t.Fatal("same-epoch reopen consumed the seal", err) + } + claimed, err := ClaimChunkHead(ctTimeout(t), r, ctConfig(2)) + if err != nil { + t.Fatal(err) + } + expected := copyHead(sealed) + expected.Gen++ + expected.Epoch = 2 + expected.State = ChunkHeadActive + expected.DetachedBy = nil + if !sameHead(claimed, expected) || !bytes.Equal(r.imageOf(t, claimed)[:4096], want) { + t.Fatalf("same-host claim changed sealed image/frontier: sealed=%+v claimed=%+v", sealed, claimed) + } +} From f9177aa249cf7f31750528b0ceb3690087d7a040 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 21 Nov 2026 20:02:31 -0800 Subject: [PATCH 5/9] docs: trace same-host clean return through the sealed HEAD claim --- .../core/host/master/workspace_move_refusal_test.go | 4 +--- seaweed-block/docs/design/agent-workspace-design.md | 4 +++- seaweed-block/docs/design/invariants.md | 11 ++++++----- seaweed-block/docs/workspace-lease.md | 13 +++++++++++++ 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/seaweed-block/core/host/master/workspace_move_refusal_test.go b/seaweed-block/core/host/master/workspace_move_refusal_test.go index 8c3196aa03..71d59787ee 100644 --- a/seaweed-block/core/host/master/workspace_move_refusal_test.go +++ b/seaweed-block/core/host/master/workspace_move_refusal_test.go @@ -95,8 +95,6 @@ func TestWorkspaceMoveRefusalNamesTheMissingPrecondition(t *testing.T) { return &control.WorkspaceMove{RequestId: vol + "-" + server + "-" + data, VolumeId: vol, ExpectedReplicaId: "r1", ExpectedEpoch: 1, TargetReplicaId: "r1", TargetServerId: server, TargetDataAddr: data, TargetCtrlAddr: ctrl, Kind: "clean"} } - forcedSource := move("placed", "node-a", "127.0.0.1:19101", "127.0.0.1:19102") - forcedSource.Kind, forcedSource.Force = "forced", true for _, c := range []struct { name string q *control.WorkspaceMove @@ -104,7 +102,7 @@ func TestWorkspaceMoveRefusalNamesTheMissingPrecondition(t *testing.T) { }{ {"unknown source", move("unplaced", "node-b", "127.0.0.1:19301", "127.0.0.1:19302"), `move source unknown: no issued move or placement names replica "r1" at epoch 1`}, {"unknown target node", move("placed", "node-z", "127.0.0.1:19301", "127.0.0.1:19302"), `move target node "node-z" is not registered`}, - {"forced target is the source", forcedSource, `move target "node-a" is the current source host`}, + {"same-host clean still needs authority", move("placed", "node-a", "127.0.0.1:19101", "127.0.0.1:19102"), `workspace move: missing or changed authority/lease`}, {"target on another host", move("placed", "node-b", "10.9.9.9:19311", "127.0.0.1:19312"), `move target endpoints 10.9.9.9:19311/127.0.0.1:19312 on "node-b" are not registered (not on the node's hosts: it registers 127.0.0.1:19301/127.0.0.1:19302; no per-volume binding is prepared)`}, {"explicit binding elsewhere", move("bound", "node-b", "127.0.0.1:19301", "127.0.0.1:19302"), diff --git a/seaweed-block/docs/design/agent-workspace-design.md b/seaweed-block/docs/design/agent-workspace-design.md index 5c81669a25..a2beb233de 100644 --- a/seaweed-block/docs/design/agent-workspace-design.md +++ b/seaweed-block/docs/design/agent-workspace-design.md @@ -359,12 +359,14 @@ stateDiagram-v2 Granted --> Granted: Renew before horizon and deadline (from memory) Granted --> Revoking: BeginWorkspaceRevocation Revoking --> Acked: host acks detached HEAD gen while the lease is valid - Acked --> Moved: CLEAN move + Acked --> Moved: CLEAN move, including same host, new epoch Granted --> Expired: horizon or deadline passes Expired --> Moved: FORCED move after expiry + skew bound, then HEAD read (an older-epoch HEAD is accepted) } ``` +**Same-host planned return.** A sealed volume can be moved cleanly back to its source host after the exact detached-generation ACK was recorded. The move issues a higher epoch even when the host and endpoints are unchanged. The returning process claims the sealed HEAD before serving; a same-epoch reopen remains detached. Forced moves to the source host remain refused. Re-preparing the binding preserves the old retired-epoch tag, so replaying that retirement cannot retire the new binding. + **Moving back to a host with a surviving local file.** A fresh volume claims HEAD before serving. A non-fresh attach reads HEAD first; if another holder published it, the attach fails closed with `ErrChunkStaleLocalRoot` (`core/frontend/durable/provider_chunk.go`): the volume is not served, and one log line and the status evidence name the local root to remove or quarantine, after which the next attach starts fresh from HEAD (#167). ## 8. Security model diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index d2f32d4b05..c36bbfb9e1 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -96,8 +96,8 @@ blockmaster's publisher is the only component that mints epochs. Diagrams: the a | Granted | Granted | renew from memory (the lease view, leaf lock only) before the durable horizon and the granted deadline; the grant is min(now + TTL, horizon), refused with an error when it would leave no host validity (grant − skew/2 ≤ now); an extender, an ordinary writer under the publisher lock, raises the horizon to trigger + 1.5·TTL | `core/authority/workspace_lease_view.go` `RenewWorkspaceLease`, `extendWorkspaceLease` | `INV-WS-LEASE-001`, `INV-WS-LEASE-HORIZON-001`, `INV-WS-LEASE-HORIZON-MONO-001`, `INV-WS-RENEW-NONBLOCKING-001`, `INV-LEASE-VIEW-001`, `INV-WS-FORCED-MOVE-REPLY-001`, `INV-WS-FORCED-MOVE-HALF-SKEW-001` | | Granted | Revoking | `BeginWorkspaceRevocation` for the matching lease; a renew now returns the revoking lease with the granted expiry, min(horizon, deadline), without extending it | `core/authority/workspace.go` `BeginWorkspaceRevocation`; `core/authority/workspace_lease_view.go` `RenewWorkspaceLease`, `WorkspaceLeaseReply` | `INV-WS-CLEAN-MOVE-001`, `INV-WS-FORCED-MOVE-REPLY-001` | | Revoking | Acked | `AckWorkspaceRevocation` from the holder at the current epoch, a nonzero HEAD generation, the lease still valid; a different second acknowledgement is refused | `core/authority/workspace.go` `AckWorkspaceRevocation` | `INV-WS-CLEAN-MOVE-001`, `INV-WS-REVOKE-ACK-001` | -| Acked | Moved (clean) | HEAD detached by the expected holder at the expected epoch, and the acknowledgement names that HEAD generation | `core/authority/workspace.go` `prepareWorkspaceMoveLocked` | `INV-WS-CLEAN-MOVE-001` | -| Acked or Expired | (move refused, nothing written) | blockmaster admits a move only with valid target endpoints (host:port, port 1..65535, data and ctrl distinct), a known source host, a registered target node other than the source, and target endpoints that either match a live per-volume binding or, for a volume without bindings, lie on the target node's registered hosts (any port) and are not owned by another assignment or binding, and, under strict journal isolation, a target node whose durable root does not share the authority store's file system (the retry of an issued move excepted); each refusal names its condition and is logged | `core/host/master/workspace_service.go` `MoveWorkspace`, `workspaceMoveCheckLocked`; `core/host/master/journal_isolation.go` `colocatedTargetRefused` | `INV-WS-CLEAN-MOVE-001`, `INV-WS-FORCED-MOVE-001`, `INV-MASTER-JOURNAL-ISOLATION-001` | +| Acked | Moved (clean) | HEAD detached by the expected holder at the expected epoch, and the acknowledgement names that HEAD generation; the target may be the same host, with a newly issued epoch and every binding/collision/isolation check retained | `core/authority/workspace.go` `prepareWorkspaceMoveLocked`, `validateWorkspaceMoveRequest`; `core/host/master/workspace_service.go` `workspaceMoveCheckLocked` | `INV-WS-CLEAN-MOVE-001`, `INV-WS-SAME-HOST-CLEAN-MOVE-001` | +| Acked or Expired | (move refused, nothing written) | blockmaster admits a move only with valid target endpoints (host:port, port 1..65535, data and ctrl distinct), a known source host, a registered target node (the source itself only for a clean, non-force move), and target endpoints that either match a live per-volume binding or, for a volume without bindings, lie on the target node's registered hosts (any port) and are not owned by another assignment or binding, and, under strict journal isolation, a target node whose durable root does not share the authority store's file system (the retry of an issued move excepted); each refusal names its condition and is logged | `core/host/master/workspace_service.go` `MoveWorkspace`, `workspaceMoveCheckLocked`; `core/host/master/journal_isolation.go` `colocatedTargetRefused` | `INV-WS-CLEAN-MOVE-001`, `INV-WS-FORCED-MOVE-001`, `INV-MASTER-JOURNAL-ISOLATION-001` | | Granted or Revoking | Expired | the durable horizon or the granted deadline passes | `core/authority/workspace_lease_view.go` `RenewWorkspaceLease`; `core/authority/workspace.go` `AckWorkspaceRevocation` | `INV-WS-FORCED-MOVE-001` | | Expired | Moved (forced) | explicit force; the persisted lease horizon (at least every grant) plus the clock-skew bound and the granted or restart deadline plus the bound have both passed, for the lease the last move issue started (never a predecessor's); blockmaster reads HEAD only after this admission; HEAD is the expected holder's at the expected epoch or any HEAD at an older epoch (the holder never claimed it, or an earlier holder's late claim landed; the lost range starts at that HEAD's remote LSN); a HEAD at the expected or a higher epoch that is not the expected holder's is refused; the lost range (the HEAD's remote LSN, the barrier as LostUntil, the HEAD's generation via the move record and the HEAD entry's filer mtime read with HEAD, or unknown) is written before the reservation. The OSS operator client sends the explicit force only with `--confirm-forced @`; `PreviewWorkspaceMove` runs this admission (HEAD read only once admitted) and writes nothing | `core/authority/workspace.go` `prepareWorkspaceMoveLocked`, `WorkspaceForcedMoveAdmitted`, `forcedMoveBarrierLocked`, `workspaceHeadAdmits`, `PreviewWorkspaceForcedMove`; `core/authority/workspace_lost_range.go` `recordLostRangeLocked`; `core/host/master/workspace_service.go` `MoveWorkspace`, `PreviewWorkspaceMove`; `core/rpc/wsclient/wsclient.go` `ForceMove` | `INV-WS-FORCED-MOVE-001`, `INV-WS-LEASE-HORIZON-001`, `INV-WS-LOST-RANGE-READOUT-001`, `INV-WS-FORCED-CONFIRM-001` | | Moved | epoch issued | the move journal record is durable first; a retried request id gets the same epoch; the issue write starts the new holder's lease (horizon issue + 1.5·TTL, granted deadline issue + TTL), published with the epoch in one lease-view section and never lowering a deadline a renewal raised; the new holder is then Granted, and one that dies before its first renewal still expires; the answer to an issued forced move (also a replay) carries its stored lost range, or no range and the reason when that record is missing or fails its checks; a failure after the issue is answered as issued-but-failed (`Internal`, rerun with the same request id), never as a refusal, and the issue is still logged; an issuing write whose durable outcome is unknown is answered as unknown (`Internal`, restart then rerun with the same request id) | `core/authority/workspace.go` `prepareWorkspaceMoveLocked`, `issueWorkspaceMove`, `MoveWorkspace`; `core/authority/workspace_lease_view.go` `publishIssuedLeaseLocked`; `core/host/master/workspace_service.go` `grantWithLostRange`, `postIssueError` | `INV-AUTH-MOVE-JOURNAL-001`, `INV-LEASE-VIEW-001`, `INV-WS-LOST-RANGE-READOUT-001`, `INV-WS-LOST-RANGE-FAILCLOSED-001`, `INV-WS-LOST-RANGE-AUDIT-001`, `INV-WS-LOST-RANGE-UNCERTAIN-001` | @@ -198,7 +198,8 @@ stateDiagram-v2 | Claiming | Detached (non-serving) | same epoch/holder HEAD is already detached: refuse with ErrChunkLayerDetached before restore preparation or CAS; a higher-epoch takeover still consumes the sealed image | `core/storage/chunk_restore.go` `ClaimChunkHead` | `INV-WS-SEALED-REOPEN-001` | | Claiming | Holder, or not installed | unknown CAS outcome: success only if a re-read shows the exact proposal; never a blind replay | `core/storage/chunk_restore.go` `ClaimChunkHead` | `INV-WS-CAS-UNKNOWN-001` | | Holder | Holder | every publish is a cut (M5) | `core/storage/chunk_layer.go` `captureLocked` | `INV-WS-HEAD-CAS-001`, `INV-WS-HEAD-MONOTONE-001` | -| Holder | Detached | `Detach` publishes the final cut with state `detached` in one CAS | `core/storage/chunk_layer.go` `chunkLayerImpl.Detach`, `captureLocked` | `INV-WS-CLEAN-MOVE-001` | +| Holder | Detached | `Detach` publishes the final cut with state `detached` in one CAS | `core/storage/chunk_layer.go` `chunkLayerImpl.Detach`, `captureLocked` | `INV-WS-SAME-HOST-CLEAN-MOVE-001` | Same-host move: CLEAN only, with HEAD detached by the current holder at its epoch and the matching revocation ACK; it issues a higher epoch to the same host, which claims that sealed HEAD and serves exactly its image. Forced same-host move stays refused; a same-epoch sealed reopen never serves. | M2 Acked → Moved (clean); M4 Claiming → Holder | `core/authority/workspace.go` `validateWorkspaceMoveRequest`, `prepareWorkspaceMoveLocked`; `core/host/master/workspace_service.go` `workspaceMoveCheckLocked`; `core/storage/chunk_restore.go` `ClaimChunkHead` | `TestWorkspaceSameHostCleanMoveUsesOvernightSeal` (`core/authority/workspace_same_host_clean_test.go`); `TestWorkspaceRPCSameHostCleanMoveKeepsRepreparedBinding` (`core/host/master/workspace_same_host_clean_test.go`); `TestClaimChunkHeadSameHostCleanMovePreservesSealedImage` (`core/storage/chunk_same_host_clean_test.go`) | `WorkspaceRegrant` `SameHostLoadsSealed` | ACTIVE | +| `INV-WS-CLEAN-MOVE-001` | | Holder | HolderFenced | a conflicting HEAD owner (including a regressed epoch) or a displaced publication is observed; local data and unresolved cut intents remain | `core/storage/chunk_layer.go` `supersededBy`; `core/frontend/chunkstore/chunk_remote.go` `CASHead` | `INV-WS-HEAD-CAS-001` | | Holder | (lazy read) | a block missing locally is fetched from HEAD and installed only if it does not overwrite a newer local extent version; a newer WAL-only write still wins on reads, and HEAD's value may be installed beneath it as the backing value, which is correct if a crash loses that unsynced write | `core/storage/chunk_layer.go` `OnReadMiss`, `installFetchedBlock` | `INV-CUT-READMISS-001` | | Holder | (hydration wait) | one request deadline covers all missing chunks; callers may detach, but bounded per-layer workers retain and join each shared fill; HEAD/generation/local-write checks still govern installation | `core/storage/chunk_hydration.go`; `core/frontend/durable/storage_adapter.go` `readStorageBlock` | `INV-CUT-HYDRATION-WAIT-001`, `INV-CUT-READMISS-001` | @@ -289,7 +290,7 @@ HEAD states, snapshots, forks, intents, key bindings, GC and volume delete in th | — | `active` (gen 1, epoch 0) | the first HEAD is an exclusive create (`CASHead` with expected gen 0); a fork or restore HEAD carries the parent's `RemoteLSN` and references | `core/frontend/chunkstore/chunk_remote.go` `CASHead`; `core/frontend/chunkstore/catalog.go` `EnsureVolume`, `Fork`, `Restore` | `INV-WS-HEAD-CAS-001` | | `active` | `active` | a holder's cut or a takeover CAS (M4, M5) | `core/frontend/chunkstore/chunk_remote.go` `CASHead` | `INV-WS-HEAD-CAS-001`, `INV-WS-HEAD-MONOTONE-001` | | `active` | `detached` | `Detach` final cut | `core/storage/chunk_layer.go` `chunkLayerImpl.Detach` | `INV-WS-CLEAN-MOVE-001` | -| `detached` | `active` | takeover CAS by a new holder at a higher epoch | `core/storage/chunk_restore.go` `ClaimChunkHead` | `INV-WS-CLAIM-BEFORE-SERVE-001` | +| `detached` | `active` | takeover CAS at a higher issued epoch, including a clean move to the same host | `core/storage/chunk_restore.go` `ClaimChunkHead` | `INV-WS-CLAIM-BEFORE-SERVE-001` | | `active`, `detached` | `deleting` | a blockmaster deletion reservation exists and HEAD is not held | `core/frontend/chunkstore/volume_delete.go` `DeleteVolume`, `markHeadDeleting` | `INV-VOLDEL-HELD-HEAD-001`, `INV-VOL-ID-NO-REUSE-001` | | `deleting` | previous state | a snapshot name record exists: the delete is refused and reverted | `core/frontend/chunkstore/volume_delete.go` `snapshotsBlock`, `revertHeadDeleting` | `INV-VOLDEL-COMMIT-001` | | `deleting` | `purging` | commit point, bound to the same delete incarnation | `core/frontend/chunkstore/volume_delete.go` `commitHeadPurging` | `INV-VOLDEL-COMMIT-001` | @@ -409,7 +410,7 @@ Tests: `TestSnapshotSchedule_SlotsAreOffsetPerVolume`, `_FailureIsTypedAndBacksO ## Part B. Invariant ledger -296 rows: 210 ACTIVE, 83 STUB, 3 ARCHIVED; 15 kept from the internal ledger, 281 new. +297 rows: 211 ACTIVE, 83 STUB, 3 ARCHIVED; 15 kept from the internal ledger, 282 new. The "Machine / transition" column refers to Part A. Notes under a table record what a row does not cover and, for kept rows, what was narrowed from the internal ledger. diff --git a/seaweed-block/docs/workspace-lease.md b/seaweed-block/docs/workspace-lease.md index bb089340fe..70e0b139c6 100644 --- a/seaweed-block/docs/workspace-lease.md +++ b/seaweed-block/docs/workspace-lease.md @@ -70,3 +70,16 @@ defaults). Beyond that, grants shrink and hosts fence: the design fails closed. Blockmaster logs one warning per failure streak, with the write's latency and the remaining horizon, when an extension fails, and one when grants start to be clamped to the horizon, and a line when either recovers. + + +## Planned return on the same host + +After plain detach seals HEAD and revocation records its exact generation, +a clean move may target the source host itself. Prepare the binding again +before requesting the move. The move journals a higher epoch even when its +endpoints are unchanged; start the returning blockvolume at that new epoch. +It claims the sealed HEAD before serving and preserves the sealed image and +remote frontier. The matching seal/ACK remains valid overnight while HEAD +is unchanged. A same-epoch reopen remains detached, and a forced move to the +same host is refused. Every ordinary binding, endpoint collision, journal +isolation and uncertain-outcome check still applies. From e6fcfd38b97e7acecac2927cf551a3c37216bd8e Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 21 Nov 2026 20:07:59 -0800 Subject: [PATCH 6/9] test: retain endpoint refusal evidence and place G3 row in ledger --- seaweed-block/core/host/master/workspace_move_refusal_test.go | 2 +- seaweed-block/docs/design/invariants.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/seaweed-block/core/host/master/workspace_move_refusal_test.go b/seaweed-block/core/host/master/workspace_move_refusal_test.go index 71d59787ee..3bcf314468 100644 --- a/seaweed-block/core/host/master/workspace_move_refusal_test.go +++ b/seaweed-block/core/host/master/workspace_move_refusal_test.go @@ -102,7 +102,7 @@ func TestWorkspaceMoveRefusalNamesTheMissingPrecondition(t *testing.T) { }{ {"unknown source", move("unplaced", "node-b", "127.0.0.1:19301", "127.0.0.1:19302"), `move source unknown: no issued move or placement names replica "r1" at epoch 1`}, {"unknown target node", move("placed", "node-z", "127.0.0.1:19301", "127.0.0.1:19302"), `move target node "node-z" is not registered`}, - {"same-host clean still needs authority", move("placed", "node-a", "127.0.0.1:19101", "127.0.0.1:19102"), `workspace move: missing or changed authority/lease`}, + {"same-host clean still needs prepared endpoints", move("bound", "node-a", "127.0.0.1:19101", "127.0.0.1:19102"), `move target endpoints 127.0.0.1:19101/127.0.0.1:19102 on "node-a" are not registered (live bindings on that node: 127.0.0.1:19121/127.0.0.1:19122)`}, {"target on another host", move("placed", "node-b", "10.9.9.9:19311", "127.0.0.1:19312"), `move target endpoints 10.9.9.9:19311/127.0.0.1:19312 on "node-b" are not registered (not on the node's hosts: it registers 127.0.0.1:19301/127.0.0.1:19302; no per-volume binding is prepared)`}, {"explicit binding elsewhere", move("bound", "node-b", "127.0.0.1:19301", "127.0.0.1:19302"), diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index c36bbfb9e1..6cad2c7132 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -198,8 +198,7 @@ stateDiagram-v2 | Claiming | Detached (non-serving) | same epoch/holder HEAD is already detached: refuse with ErrChunkLayerDetached before restore preparation or CAS; a higher-epoch takeover still consumes the sealed image | `core/storage/chunk_restore.go` `ClaimChunkHead` | `INV-WS-SEALED-REOPEN-001` | | Claiming | Holder, or not installed | unknown CAS outcome: success only if a re-read shows the exact proposal; never a blind replay | `core/storage/chunk_restore.go` `ClaimChunkHead` | `INV-WS-CAS-UNKNOWN-001` | | Holder | Holder | every publish is a cut (M5) | `core/storage/chunk_layer.go` `captureLocked` | `INV-WS-HEAD-CAS-001`, `INV-WS-HEAD-MONOTONE-001` | -| Holder | Detached | `Detach` publishes the final cut with state `detached` in one CAS | `core/storage/chunk_layer.go` `chunkLayerImpl.Detach`, `captureLocked` | `INV-WS-SAME-HOST-CLEAN-MOVE-001` | Same-host move: CLEAN only, with HEAD detached by the current holder at its epoch and the matching revocation ACK; it issues a higher epoch to the same host, which claims that sealed HEAD and serves exactly its image. Forced same-host move stays refused; a same-epoch sealed reopen never serves. | M2 Acked → Moved (clean); M4 Claiming → Holder | `core/authority/workspace.go` `validateWorkspaceMoveRequest`, `prepareWorkspaceMoveLocked`; `core/host/master/workspace_service.go` `workspaceMoveCheckLocked`; `core/storage/chunk_restore.go` `ClaimChunkHead` | `TestWorkspaceSameHostCleanMoveUsesOvernightSeal` (`core/authority/workspace_same_host_clean_test.go`); `TestWorkspaceRPCSameHostCleanMoveKeepsRepreparedBinding` (`core/host/master/workspace_same_host_clean_test.go`); `TestClaimChunkHeadSameHostCleanMovePreservesSealedImage` (`core/storage/chunk_same_host_clean_test.go`) | `WorkspaceRegrant` `SameHostLoadsSealed` | ACTIVE | -| `INV-WS-CLEAN-MOVE-001` | +| Holder | Detached | `Detach` publishes the final cut with state `detached` in one CAS | `core/storage/chunk_layer.go` `chunkLayerImpl.Detach`, `captureLocked` | `INV-WS-CLEAN-MOVE-001` | | Holder | HolderFenced | a conflicting HEAD owner (including a regressed epoch) or a displaced publication is observed; local data and unresolved cut intents remain | `core/storage/chunk_layer.go` `supersededBy`; `core/frontend/chunkstore/chunk_remote.go` `CASHead` | `INV-WS-HEAD-CAS-001` | | Holder | (lazy read) | a block missing locally is fetched from HEAD and installed only if it does not overwrite a newer local extent version; a newer WAL-only write still wins on reads, and HEAD's value may be installed beneath it as the backing value, which is correct if a crash loses that unsynced write | `core/storage/chunk_layer.go` `OnReadMiss`, `installFetchedBlock` | `INV-CUT-READMISS-001` | | Holder | (hydration wait) | one request deadline covers all missing chunks; callers may detach, but bounded per-layer workers retain and join each shared fill; HEAD/generation/local-write checks still govern installation | `core/storage/chunk_hydration.go`; `core/frontend/durable/storage_adapter.go` `readStorageBlock` | `INV-CUT-HYDRATION-WAIT-001`, `INV-CUT-READMISS-001` | @@ -651,6 +650,7 @@ Notes: | `INV-WS-LEASE-001` | A host admits frontend I/O and cuts only under an unexpired lease for its exact `{volume, replica, epoch}`; a fenced guard never reopens, even on a late renewal reply. | M4 lease guard: Valid → Fenced | `core/host/volume/workspace_lease.go` `permits`, `Refresh` | `TestWorkspaceLeaseExpiryFencesWithoutTimerAndCannotReopen`, `TestWorkspaceDelayedRenewalCannotUndoExpiry` (`core/host/volume/workspace_lease_test.go`); `TestWorkspaceHostRequiresLeaseBeforeFrontendAndCut` (`core/host/volume/workspace_runtime_test.go`); `TestWorkspacePausedGranteeRefusedAtAttach` (`core/host/master/workspace_paused_grantee_test.go`) | `WorkspaceTakeover` `NoDualServing` | ACTIVE | | `INV-WS-REVOKE-ACK-001` | A host acknowledges a revocation only after its frontend and cuts have stopped; a cancelled or expired drain sends no acknowledgement. | M4 lease guard: Revoking → Acked | `core/host/volume/workspace_lease.go` `drain` | `TestWorkspaceRevocationAckOnlyAfterFrontendAndCutsStop` (`core/host/volume/workspace_lease_test.go`); `TestWorkspaceHostCancelOrExpiryDuringRevokeDrainNeverACKs` (`core/host/volume/workspace_runtime_test.go`) | `WorkspaceTakeover` `CleanNoLoss` | ACTIVE | | `INV-WS-STOP-PENDING-001` | From when the detach hook of a chunk detach runs until the lease guard fences, or until that detach's resume clears stop-pending, each sleep of the guard after a completed renewal is at most 250 ms on the local monotonic clock. | M4 lease guard: Valid → StopPending → Valid \| Fenced | `core/host/volume/workspace_lease.go` `StopPending`, `ClearStopPending`, `renewDelay`, `Run`; `core/host/volume/workspace_runtime.go` `WorkspaceStopPending`, `WorkspaceStopResumed`; `core/frontend/durable/provider_chunk.go` `DetachVolume`, `detachVolume`, `resumeAfterDetach`; `cmd/blockvolume/main.go` `run` (wiring) | `TestWorkspaceLeaseStopPendingSchedule`, `TestWorkspaceHostStopResumedClearsOnlyTheLatestAttempt`, `TestWorkspaceHostFailedDetachStopPendingByOutcome`, `TestWorkspaceHostDetachHookFencesWithinPoll`, `TestWorkspaceLeaseStopPendingNeverBlocks` (`core/host/volume/workspace_lease_stop_pending_test.go`); `TestWALStoreChunk_DetachHookPrecedesDrain`, `TestWALStoreChunk_DetachResumeHookOnlyOnProvenAbort`, `TestWALStoreChunk_DetachCallsStopHook` (`core/frontend/durable/provider_chunk_detach_hook_test.go`) | — | ACTIVE | +| `INV-WS-SAME-HOST-CLEAN-MOVE-001` | Same-host move: CLEAN only, with HEAD detached by the current holder at its epoch and the matching revocation ACK; it issues a higher epoch to the same host, which claims that sealed HEAD and serves exactly its image. Forced same-host move stays refused; a same-epoch sealed reopen never serves. | M2 Acked → Moved (clean); M4 Claiming → Holder | `core/authority/workspace.go` `validateWorkspaceMoveRequest`, `prepareWorkspaceMoveLocked`; `core/host/master/workspace_service.go` `workspaceMoveCheckLocked`; `core/storage/chunk_restore.go` `ClaimChunkHead` | `TestWorkspaceSameHostCleanMoveUsesOvernightSeal` (`core/authority/workspace_same_host_clean_test.go`); `TestWorkspaceRPCSameHostCleanMoveKeepsRepreparedBinding` (`core/host/master/workspace_same_host_clean_test.go`); `TestClaimChunkHeadSameHostCleanMovePreservesSealedImage` (`core/storage/chunk_same_host_clean_test.go`) | `WorkspaceRegrant` `SameHostLoadsSealed` | ACTIVE | | `INV-WS-CLEAN-MOVE-001` | A clean move is granted only with a detached HEAD from the expected holder and a matching revocation acknowledgement at the current epoch. | M2 lease: Acked → Moved | `core/authority/workspace.go` `prepareWorkspaceMoveLocked`, `AckWorkspaceRevocation` | `TestWorkspaceCleanMoveNeedsDetachedHEADAndRevocationAck` (`core/authority/workspace_test.go`) | `WorkspaceTakeover` `CleanNoLoss` | ACTIVE | | `INV-WS-FORCED-MOVE-001` | A forced move is admitted only after the persisted lease horizon and the granted or restart deadline, each plus the clock-skew bound, have passed for the lease the last move issue started (never a predecessor's): see M2 Expired → Moved (forced). | M2 lease: Expired → Moved (forced) | `core/authority/workspace.go` `prepareWorkspaceMoveLocked`, `WorkspaceForcedMoveAdmitted`, `forcedMoveAdmissionLocked`, `forcedMoveBarrierLocked`, `workspaceHeadAdmits`; `core/host/master/workspace_service.go` `MoveWorkspace`, `workspaceMoveCheckLocked` | `TestWorkspaceSkewSeparatesOldServingFromForcedGrant` (`core/host/master/workspace_skew_test.go`); `TestWorkspaceClockSkewPersistsAndProtectsRestart` (`core/authority/workspace_skew_test.go`); `TestWorkspaceForcedMoveRequiresExplicitForceAndLeaseExpiry` (`core/authority/workspace_test.go`); `TestWorkspaceRestartForcedBarrierHonoursHorizon`, `TestWorkspaceAmbiguousExtensionLatchesUncertainty` (`core/authority/workspace_lease_horizon_test.go`); `TestWorkspaceRenewalRPCDuringHeldSameVolumeReservation` (`core/host/master/workspace_lease_horizon_test.go`); `TestWorkspaceUnclaimedGrantForcedReassignAfterExpiry`, `TestWorkspaceUnclaimedGrantHEADRule`, `TestWorkspaceLateClaimThenUnclaimedGrantForcedReassign` (`core/authority/workspace_unclaimed_grant_test.go`); `TestWorkspaceForcedMoveAdmittedMatchesMoveAdmission` (`core/authority/workspace_forced_admission_test.go`); `TestWorkspaceUnclaimedGrantForcedReassignOverRPC` (`core/host/master/workspace_unclaimed_grant_test.go`); `TestWorkspacePausedGranteeRefusedAtAttach` (`core/host/master/workspace_paused_grantee_test.go`) | — | ACTIVE | | `INV-WS-FORCED-MOVE-REPLY-001` | The lease expiry the master reports to a host is the granted expiry, never the persisted horizon. | M2 Granted → Granted; Granted → Revoking | `core/authority/workspace_lease_view.go` `RenewWorkspaceLease`, `WorkspaceLeaseReply`, `replyExpiryNS`; `core/host/master/workspace_service.go` `RevokeWorkspace` | `TestWorkspaceLeaseClampsToHorizonUnderStalledStore`, `TestWorkspaceSameVolumeRenewalDuringHeldWrite` (`core/authority/workspace_lease_horizon_test.go`); `TestWorkspaceUnclaimedGrantForcedReassignAfterExpiry` (`core/authority/workspace_unclaimed_grant_test.go`) | — | ACTIVE | From a489f4e1f58fec5e269ef7b4d48a507cf38eafab Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 21 Nov 2026 20:08:15 -0800 Subject: [PATCH 7/9] test: clone protobuf requests without copying lock state --- .../core/host/master/workspace_same_host_clean_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/seaweed-block/core/host/master/workspace_same_host_clean_test.go b/seaweed-block/core/host/master/workspace_same_host_clean_test.go index e518160a4c..6134a2c3d9 100644 --- a/seaweed-block/core/host/master/workspace_same_host_clean_test.go +++ b/seaweed-block/core/host/master/workspace_same_host_clean_test.go @@ -4,6 +4,7 @@ import ( "testing" control "github.com/seaweedfs/seaweed-block/core/rpc/control" + "google.golang.org/protobuf/proto" ) // INV-WS-SAME-HOST-CLEAN-MOVE-001: retirement belongs to an epoch, so the @@ -46,9 +47,9 @@ func TestWorkspaceRPCSameHostCleanMoveKeepsRepreparedBinding(t *testing.T) { if _, err := ws.RegisterWorkspaceBinding(ctx, b); err != nil { t.Fatal("same-host re-prepare refused", err) } - forced := *req + forced := proto.Clone(req).(*control.WorkspaceMove) forced.Kind, forced.Force = "forced", true - if _, err := ws.MoveWorkspace(ctx, &forced); err == nil { + if _, err := ws.MoveWorkspace(ctx, forced); err == nil { t.Fatal("same-host forced move accepted over RPC") } if _, err := ws.MoveWorkspace(ctx, req); err != nil { From 7ed752eb299ff6bf26ea8ce556e6170e3d900833 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 21 Nov 2026 20:09:42 -0800 Subject: [PATCH 8/9] docs: use the approved same-host clean move invariant text --- seaweed-block/docs/design/invariants.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index 6cad2c7132..8a1759e186 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -650,7 +650,7 @@ Notes: | `INV-WS-LEASE-001` | A host admits frontend I/O and cuts only under an unexpired lease for its exact `{volume, replica, epoch}`; a fenced guard never reopens, even on a late renewal reply. | M4 lease guard: Valid → Fenced | `core/host/volume/workspace_lease.go` `permits`, `Refresh` | `TestWorkspaceLeaseExpiryFencesWithoutTimerAndCannotReopen`, `TestWorkspaceDelayedRenewalCannotUndoExpiry` (`core/host/volume/workspace_lease_test.go`); `TestWorkspaceHostRequiresLeaseBeforeFrontendAndCut` (`core/host/volume/workspace_runtime_test.go`); `TestWorkspacePausedGranteeRefusedAtAttach` (`core/host/master/workspace_paused_grantee_test.go`) | `WorkspaceTakeover` `NoDualServing` | ACTIVE | | `INV-WS-REVOKE-ACK-001` | A host acknowledges a revocation only after its frontend and cuts have stopped; a cancelled or expired drain sends no acknowledgement. | M4 lease guard: Revoking → Acked | `core/host/volume/workspace_lease.go` `drain` | `TestWorkspaceRevocationAckOnlyAfterFrontendAndCutsStop` (`core/host/volume/workspace_lease_test.go`); `TestWorkspaceHostCancelOrExpiryDuringRevokeDrainNeverACKs` (`core/host/volume/workspace_runtime_test.go`) | `WorkspaceTakeover` `CleanNoLoss` | ACTIVE | | `INV-WS-STOP-PENDING-001` | From when the detach hook of a chunk detach runs until the lease guard fences, or until that detach's resume clears stop-pending, each sleep of the guard after a completed renewal is at most 250 ms on the local monotonic clock. | M4 lease guard: Valid → StopPending → Valid \| Fenced | `core/host/volume/workspace_lease.go` `StopPending`, `ClearStopPending`, `renewDelay`, `Run`; `core/host/volume/workspace_runtime.go` `WorkspaceStopPending`, `WorkspaceStopResumed`; `core/frontend/durable/provider_chunk.go` `DetachVolume`, `detachVolume`, `resumeAfterDetach`; `cmd/blockvolume/main.go` `run` (wiring) | `TestWorkspaceLeaseStopPendingSchedule`, `TestWorkspaceHostStopResumedClearsOnlyTheLatestAttempt`, `TestWorkspaceHostFailedDetachStopPendingByOutcome`, `TestWorkspaceHostDetachHookFencesWithinPoll`, `TestWorkspaceLeaseStopPendingNeverBlocks` (`core/host/volume/workspace_lease_stop_pending_test.go`); `TestWALStoreChunk_DetachHookPrecedesDrain`, `TestWALStoreChunk_DetachResumeHookOnlyOnProvenAbort`, `TestWALStoreChunk_DetachCallsStopHook` (`core/frontend/durable/provider_chunk_detach_hook_test.go`) | — | ACTIVE | -| `INV-WS-SAME-HOST-CLEAN-MOVE-001` | Same-host move: CLEAN only, with HEAD detached by the current holder at its epoch and the matching revocation ACK; it issues a higher epoch to the same host, which claims that sealed HEAD and serves exactly its image. Forced same-host move stays refused; a same-epoch sealed reopen never serves. | M2 Acked → Moved (clean); M4 Claiming → Holder | `core/authority/workspace.go` `validateWorkspaceMoveRequest`, `prepareWorkspaceMoveLocked`; `core/host/master/workspace_service.go` `workspaceMoveCheckLocked`; `core/storage/chunk_restore.go` `ClaimChunkHead` | `TestWorkspaceSameHostCleanMoveUsesOvernightSeal` (`core/authority/workspace_same_host_clean_test.go`); `TestWorkspaceRPCSameHostCleanMoveKeepsRepreparedBinding` (`core/host/master/workspace_same_host_clean_test.go`); `TestClaimChunkHeadSameHostCleanMovePreservesSealedImage` (`core/storage/chunk_same_host_clean_test.go`) | `WorkspaceRegrant` `SameHostLoadsSealed` | ACTIVE | +| `INV-WS-SAME-HOST-CLEAN-MOVE-001` | A clean move may name the source host as its target only when HEAD is sealed by the current holder and the revocation ACK is recorded for that HEAD generation; it issues a higher epoch. A forced move to the source host is refused. | M2 Acked → Moved (clean); M4 Claiming → Holder | `core/authority/workspace.go` `validateWorkspaceMoveRequest`, `prepareWorkspaceMoveLocked`; `core/host/master/workspace_service.go` `workspaceMoveCheckLocked`; `core/storage/chunk_restore.go` `ClaimChunkHead` | `TestWorkspaceSameHostCleanMoveUsesOvernightSeal` (`core/authority/workspace_same_host_clean_test.go`); `TestWorkspaceRPCSameHostCleanMoveKeepsRepreparedBinding` (`core/host/master/workspace_same_host_clean_test.go`); `TestClaimChunkHeadSameHostCleanMovePreservesSealedImage` (`core/storage/chunk_same_host_clean_test.go`) | `WorkspaceRegrant` `SameHostLoadsSealed` | ACTIVE | | `INV-WS-CLEAN-MOVE-001` | A clean move is granted only with a detached HEAD from the expected holder and a matching revocation acknowledgement at the current epoch. | M2 lease: Acked → Moved | `core/authority/workspace.go` `prepareWorkspaceMoveLocked`, `AckWorkspaceRevocation` | `TestWorkspaceCleanMoveNeedsDetachedHEADAndRevocationAck` (`core/authority/workspace_test.go`) | `WorkspaceTakeover` `CleanNoLoss` | ACTIVE | | `INV-WS-FORCED-MOVE-001` | A forced move is admitted only after the persisted lease horizon and the granted or restart deadline, each plus the clock-skew bound, have passed for the lease the last move issue started (never a predecessor's): see M2 Expired → Moved (forced). | M2 lease: Expired → Moved (forced) | `core/authority/workspace.go` `prepareWorkspaceMoveLocked`, `WorkspaceForcedMoveAdmitted`, `forcedMoveAdmissionLocked`, `forcedMoveBarrierLocked`, `workspaceHeadAdmits`; `core/host/master/workspace_service.go` `MoveWorkspace`, `workspaceMoveCheckLocked` | `TestWorkspaceSkewSeparatesOldServingFromForcedGrant` (`core/host/master/workspace_skew_test.go`); `TestWorkspaceClockSkewPersistsAndProtectsRestart` (`core/authority/workspace_skew_test.go`); `TestWorkspaceForcedMoveRequiresExplicitForceAndLeaseExpiry` (`core/authority/workspace_test.go`); `TestWorkspaceRestartForcedBarrierHonoursHorizon`, `TestWorkspaceAmbiguousExtensionLatchesUncertainty` (`core/authority/workspace_lease_horizon_test.go`); `TestWorkspaceRenewalRPCDuringHeldSameVolumeReservation` (`core/host/master/workspace_lease_horizon_test.go`); `TestWorkspaceUnclaimedGrantForcedReassignAfterExpiry`, `TestWorkspaceUnclaimedGrantHEADRule`, `TestWorkspaceLateClaimThenUnclaimedGrantForcedReassign` (`core/authority/workspace_unclaimed_grant_test.go`); `TestWorkspaceForcedMoveAdmittedMatchesMoveAdmission` (`core/authority/workspace_forced_admission_test.go`); `TestWorkspaceUnclaimedGrantForcedReassignOverRPC` (`core/host/master/workspace_unclaimed_grant_test.go`); `TestWorkspacePausedGranteeRefusedAtAttach` (`core/host/master/workspace_paused_grantee_test.go`) | — | ACTIVE | | `INV-WS-FORCED-MOVE-REPLY-001` | The lease expiry the master reports to a host is the granted expiry, never the persisted horizon. | M2 Granted → Granted; Granted → Revoking | `core/authority/workspace_lease_view.go` `RenewWorkspaceLease`, `WorkspaceLeaseReply`, `replyExpiryNS`; `core/host/master/workspace_service.go` `RevokeWorkspace` | `TestWorkspaceLeaseClampsToHorizonUnderStalledStore`, `TestWorkspaceSameVolumeRenewalDuringHeldWrite` (`core/authority/workspace_lease_horizon_test.go`); `TestWorkspaceUnclaimedGrantForcedReassignAfterExpiry` (`core/authority/workspace_unclaimed_grant_test.go`) | — | ACTIVE | From 612b3276c07b113b05ad40fdb317e42e1e9d54f9 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 21 Nov 2026 20:34:04 -0800 Subject: [PATCH 9/9] docs: recount invariant ledger after merging current main --- seaweed-block/docs/design/invariants.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index b0741f542f..f31d0df116 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -409,7 +409,7 @@ Tests: `TestSnapshotSchedule_SlotsAreOffsetPerVolume`, `_FailureIsTypedAndBacksO ## Part B. Invariant ledger -297 rows: 211 ACTIVE, 83 STUB, 3 ARCHIVED; 15 kept from the internal ledger, 282 new. +298 rows: 212 ACTIVE, 83 STUB, 3 ARCHIVED; 15 kept from the internal ledger, 283 new. The "Machine / transition" column refers to Part A. Notes under a table record what a row does not cover and, for kept rows, what was narrowed from the internal ledger.