diff --git a/seaweed-block/core/adapter/normalize.go b/seaweed-block/core/adapter/normalize.go index 082ab4e768..8871e7159c 100644 --- a/seaweed-block/core/adapter/normalize.go +++ b/seaweed-block/core/adapter/normalize.go @@ -23,6 +23,10 @@ import ( // AssignmentInfo is a raw assignment from the master heartbeat. type AssignmentInfo struct { + // ServerID is immutable for a moved authority line; an unknown moved + // owner remains empty instead of falling back to placement. + ServerID string + OwnerFromMove bool VolumeID string ReplicaID string Epoch uint64 diff --git a/seaweed-block/core/authority/assignment_owner.go b/seaweed-block/core/authority/assignment_owner.go new file mode 100644 index 0000000000..df7299423d --- /dev/null +++ b/seaweed-block/core/authority/assignment_owner.go @@ -0,0 +1,26 @@ +package authority + +import "github.com/seaweedfs/seaweed-block/core/adapter" + +// captureAssignmentOwner binds owner and line in one publication under p.mu +// (INV-AUTH-HOLDER-IDENTITY-001). Reload derives it from that same durable +// record's journal. A reserved/unissued move never permits placement fallback. +func (p *Publisher) captureAssignmentOwner(info *adapter.AssignmentInfo, issuing *WorkspaceState) { + state := issuing + if state == nil { + state = p.workspace[info.VolumeID] + } + if state == nil { + return + } + for _, move := range state.Moves { + if move.NewReplicaID == info.ReplicaID && move.NewEpoch == info.Epoch { + info.OwnerFromMove = true + info.ServerID = "" + if move.Issued { + info.ServerID = move.NewHost + } + return + } + } +} diff --git a/seaweed-block/core/authority/assignment_owner_test.go b/seaweed-block/core/authority/assignment_owner_test.go new file mode 100644 index 0000000000..a3cb7561e7 --- /dev/null +++ b/seaweed-block/core/authority/assignment_owner_test.go @@ -0,0 +1,25 @@ +package authority + +import ( + "github.com/seaweedfs/seaweed-block/core/adapter" + "testing" +) + +// INV-AUTH-HOLDER-IDENTITY-001: an unissued move cannot authorize a +// placement fallback, while a published move captures its own target. +func TestAssignmentOwnerReservedAndIssuedCapture(t *testing.T) { + p := NewPublisher(nil) + state := &WorkspaceState{Moves: []WorkspaceMoveRecord{{NewReplicaID: "r1", NewEpoch: 2, NewHost: "s2"}}} + for _, issued := range []bool{false, true} { + state.Moves[0].Issued = issued + info := adapter.AssignmentInfo{VolumeID: "v", ReplicaID: "r1", Epoch: 2, EndpointVersion: 1} + p.captureAssignmentOwner(&info, state) + want := "" + if issued { + want = "s2" + } + if !info.OwnerFromMove || info.ServerID != want { + t.Fatalf("issued=%t: captured %+v", issued, info) + } + } +} diff --git a/seaweed-block/core/authority/authority.go b/seaweed-block/core/authority/authority.go index c0fc650b39..cb28f1b74d 100644 --- a/seaweed-block/core/authority/authority.go +++ b/seaweed-block/core/authority/authority.go @@ -275,7 +275,7 @@ func (p *Publisher) reloadFromStore() { p.workspace[rec.VolumeID] = cloneWorkspace(rec.Workspace) } key := subKey{volumeID: rec.VolumeID, replicaID: rec.ReplicaID} - p.state[key] = assignmentState{ + loaded := assignmentState{ info: adapter.AssignmentInfo{ VolumeID: rec.VolumeID, ReplicaID: rec.ReplicaID, @@ -286,6 +286,8 @@ func (p *Publisher) reloadFromStore() { }, present: true, } + p.captureAssignmentOwner(&loaded.info, rec.Workspace) + p.state[key] = loaded if rec.WriteSeq > p.writeSeqByVolume[rec.VolumeID] { p.writeSeqByVolume[rec.VolumeID] = rec.WriteSeq } @@ -586,6 +588,8 @@ func (p *Publisher) applyWithWorkspaceMove(ask AssignmentAsk, grant *workspaceGr // sequenced after Put: on Put failure we simply return without // touching p.state / p.writeSeqByVolume, so no rollback is // needed. Subscribers never see a fact that isn't durable yet. + p.captureAssignmentOwner(&next, issuedWorkspace) + if p.store != nil { // Compute the per-volume WriteSeq for this mint. Starts // at the highest previously-persisted value for the diff --git a/seaweed-block/core/authority/workspace_lease_view.go b/seaweed-block/core/authority/workspace_lease_view.go index 49a0885727..05f7b84496 100644 --- a/seaweed-block/core/authority/workspace_lease_view.go +++ b/seaweed-block/core/authority/workspace_lease_view.go @@ -12,18 +12,19 @@ import ( // p.mu -> leaseMu at every point where an input changes, so that whenever // p.mu is released the view equals derive(published) (INV-LEASE-VIEW-001). type leaseDerived struct { - bound bool // an authority line exists for the volume - replica string - epoch uint64 - issuedHost string // NewHost of the issued move that minted the line; "" if none - leasePresent bool - revoking bool - movePending bool // the last workspace move is reserved, not issued - uncertain bool // a workspace write of the volume failed (INV-AUTH-UNCERTAIN-001) - storeless bool - horizon int64 // published Lease.ExpiresAtNS: durable upper bound of every grant - maxSkewNS int64 - lease WorkspaceLease // the published (durable) lease + bound bool // an authority line exists for the volume + replica string + epoch uint64 + ownerFromMove bool + issuedHost string // NewHost of the issued move that minted the line; "" if none + leasePresent bool + revoking bool + movePending bool // the last workspace move is reserved, not issued + uncertain bool // a workspace write of the volume failed (INV-AUTH-UNCERTAIN-001) + storeless bool + horizon int64 // published Lease.ExpiresAtNS: durable upper bound of every grant + maxSkewNS int64 + lease WorkspaceLease // the published (durable) lease } // leaseView is one volume's renewal state. Guarded by Publisher.leaseMu. @@ -43,14 +44,10 @@ func (p *Publisher) deriveLeaseLocked(volume string) leaseDerived { d := leaseDerived{uncertain: p.workspaceUncertain[volume], storeless: p.store == nil, maxSkewNS: int64(p.workspaceSkew(nil))} if _, line, ok := p.workspaceLineLocked(volume); ok { d.bound, d.replica, d.epoch = true, line.info.ReplicaID, line.info.Epoch + d.issuedHost, d.ownerFromMove = line.info.ServerID, line.info.OwnerFromMove } if s := p.workspace[volume]; s != nil { d.movePending = len(s.Moves) > 0 && !s.Moves[len(s.Moves)-1].Issued - for _, r := range s.Moves { - if d.bound && r.Issued && r.NewReplicaID == d.replica && r.NewEpoch == d.epoch { - d.issuedHost = r.NewHost - } - } if s.Lease != nil { d.leasePresent, d.revoking, d.horizon, d.lease = true, s.Lease.Revoking, s.Lease.ExpiresAtNS, *s.Lease d.maxSkewNS = int64(p.workspaceSkew(s.Lease)) @@ -154,7 +151,8 @@ type PublishedLine struct { Epoch uint64 // IssuedHost is the target host of the issued move that minted this line; // "" when no issued move did (a placement or static topology line). - IssuedHost string + IssuedHost string + OwnerFromMove bool } // PublishedAuthorityLine reads one committed line under leaf leaseMu. Identity @@ -167,7 +165,7 @@ func (p *Publisher) PublishedAuthorityLine(volume string) (PublishedLine, bool) if lv == nil || !lv.d.bound { return PublishedLine{}, false } - return PublishedLine{ReplicaID: lv.d.replica, Epoch: lv.d.epoch, IssuedHost: lv.d.issuedHost}, true + return PublishedLine{ReplicaID: lv.d.replica, Epoch: lv.d.epoch, IssuedHost: lv.d.issuedHost, OwnerFromMove: lv.d.ownerFromMove}, true } // PublishedAuthorityLines returns the committed authority line of every @@ -181,7 +179,7 @@ func (p *Publisher) PublishedAuthorityLines() map[string]PublishedLine { out := make(map[string]PublishedLine, len(p.leaseViews)) for volume, lv := range p.leaseViews { if lv.d.bound { - out[volume] = PublishedLine{ReplicaID: lv.d.replica, Epoch: lv.d.epoch, IssuedHost: lv.d.issuedHost} + out[volume] = PublishedLine{ReplicaID: lv.d.replica, Epoch: lv.d.epoch, IssuedHost: lv.d.issuedHost, OwnerFromMove: lv.d.ownerFromMove} } } return out diff --git a/seaweed-block/core/authority/workspace_test.go b/seaweed-block/core/authority/workspace_test.go index 39473fec1f..546ca03ae0 100644 --- a/seaweed-block/core/authority/workspace_test.go +++ b/seaweed-block/core/authority/workspace_test.go @@ -86,7 +86,18 @@ func TestWorkspaceCrashAfterJournalBeforeEpochResumesSameGrant(t *testing.T) { if err != nil || again != r { t.Fatal("grant replay changed", again, err) } - final := NewPublisher(nil, WithStore(disk)).WorkspaceState("v") + finalPublisher := NewPublisher(nil, WithStore(disk)) + for name, publisher := range map[string]*Publisher{"issued": loaded, "reloaded": finalPublisher} { + line, ok := publisher.LastPublished("v", "old") + if !ok || line.ServerID != "new-node" || !line.OwnerFromMove { + t.Fatalf("%s lost captured moved owner: %+v", name, line) + } + published, _ := publisher.PublishedAuthorityLine("v") + if published.IssuedHost != line.ServerID || !published.OwnerFromMove { + t.Fatalf("%s lease and stream owners differ: %+v / %+v", name, published, line) + } + } + final := finalPublisher.WorkspaceState("v") if final == nil || len(final.Moves) != 1 || !final.Moves[0].Issued { t.Fatal("issued epoch lost journal", final) } diff --git a/seaweed-block/core/host/master/assignment_fact_owner_test.go b/seaweed-block/core/host/master/assignment_fact_owner_test.go new file mode 100644 index 0000000000..44dae6679f --- /dev/null +++ b/seaweed-block/core/host/master/assignment_fact_owner_test.go @@ -0,0 +1,28 @@ +package master + +import ( + "github.com/seaweedfs/seaweed-block/core/adapter" + "github.com/seaweedfs/seaweed-block/core/authority" + "github.com/seaweedfs/seaweed-block/core/host/bootstrap" + "testing" +) + +// INV-AUTH-HOLDER-IDENTITY-001 / TERM-HOLDER-001: fault injection at the +// stream encoder, not a claim that publisher ordering can emit an unissued +// line. The captured E2 publication is available while its journal is not. +func TestAssignmentFactKeepsCapturedMoveOwnerWithoutReadableJournal(t *testing.T) { + h := &Host{boot: &bootstrap.DurableAuthorityBootstrap{Publisher: authority.NewPublisher(authority.NewStaticDirective(nil))}, topo: authority.AcceptedTopology{Volumes: []authority.VolumeExpected{{VolumeID: "v", Slots: []authority.ExpectedSlot{{ReplicaID: "r1", ServerID: "s1"}}}}}} + for _, owner := range []string{"s2", ""} { + t.Run("owner="+owner, func(t *testing.T) { + info := adapter.AssignmentInfo{VolumeID: "v", ReplicaID: "r1", Epoch: 2, EndpointVersion: 1, ServerID: owner, OwnerFromMove: true} + fact := (&services{host: h}).assignmentFact(info) + if fact.ServerId != owner { + t.Fatalf("captured owner %q relabelled %q from placement while journal unavailable", owner, fact.ServerId) + } + }) + } + initial := adapter.AssignmentInfo{VolumeID: "v", ReplicaID: "r1", Epoch: 1, EndpointVersion: 1} + if got := (&services{host: h}).assignmentFact(initial).ServerId; got != "s1" { + t.Fatalf("move-less initial placement owner: %q", got) + } +} diff --git a/seaweed-block/core/host/master/services.go b/seaweed-block/core/host/master/services.go index f8a191b61f..ae22453d36 100644 --- a/seaweed-block/core/host/master/services.go +++ b/seaweed-block/core/host/master/services.go @@ -472,25 +472,7 @@ func (s *services) SubscribeAssignments(req *control.SubscribeRequest, stream co lastEpoch = info.Epoch lastEV = info.EndpointVersion sentAny = true - fact := &control.AssignmentFact{ - VolumeId: info.VolumeID, - ReplicaId: info.ReplicaID, - ServerId: s.host.workspaceSourceHost(info.VolumeID, info.ReplicaID, info.Epoch), - Epoch: info.Epoch, - EndpointVersion: info.EndpointVersion, - DataAddr: info.DataAddr, - CtrlAddr: info.CtrlAddr, - } - // Populate the peer set from publisher LastPublished - // queries for every non-self replica slot in this volume's - // topology. peer_set_generation is derived - // from the authoritative line's (Epoch, EndpointVersion) - // packed into one uint64 as (epoch<<32 | ev). Assertion - // above guarantees each fits in uint32 so no aliasing. - // Monotonic across process lifetimes because Epoch/EV are - // durable authority facts preserved across master restart. - fact.Peers = s.collectPeers(req.VolumeId, info) - fact.PeerSetGeneration = (info.Epoch << 32) | info.EndpointVersion + fact := s.assignmentFact(info) if err := stream.Send(fact); err != nil { return err } @@ -968,3 +950,27 @@ func (h *Host) ingestHeartbeatRecordingHealth(msg authority.HeartbeatMessage) er } return nil } + +// assignmentFact encodes one captured publication at the stream boundary. +func (s *services) assignmentFact(info adapter.AssignmentInfo) *control.AssignmentFact { + fact := &control.AssignmentFact{ + VolumeId: info.VolumeID, + ReplicaId: info.ReplicaID, + ServerId: s.host.workspaceLineOwner(authority.PublishedLine{ReplicaID: info.ReplicaID, Epoch: info.Epoch, IssuedHost: info.ServerID, OwnerFromMove: info.OwnerFromMove}, info.VolumeID, info.ReplicaID, info.Epoch), + Epoch: info.Epoch, + EndpointVersion: info.EndpointVersion, + DataAddr: info.DataAddr, + CtrlAddr: info.CtrlAddr, + } + // Populate the peer set from publisher LastPublished + // queries for every non-self replica slot in this volume's + // topology. peer_set_generation is derived + // from the authoritative line's (Epoch, EndpointVersion) + // packed into one uint64 as (epoch<<32 | ev). Assertion + // above guarantees each fits in uint32 so no aliasing. + // Monotonic across process lifetimes because Epoch/EV are + // durable authority facts preserved across master restart. + fact.Peers = s.collectPeers(info.VolumeID, info) + fact.PeerSetGeneration = (info.Epoch << 32) | info.EndpointVersion + return fact +} diff --git a/seaweed-block/core/host/master/workspace_binding.go b/seaweed-block/core/host/master/workspace_binding.go index 5ef7f5356d..020c04d77a 100644 --- a/seaweed-block/core/host/master/workspace_binding.go +++ b/seaweed-block/core/host/master/workspace_binding.go @@ -68,6 +68,21 @@ func (h *Host) workspaceEndpointsAvailable(b lifecycle.WorkspaceBinding) error { // workspaceSourceHost resolves explicit holder membership for // INV-AUTH-HOLDER-IDENTITY-001; endpoints never select a server. func (h *Host) workspaceSourceHost(volume, replica string, epoch uint64) string { + current, _ := h.Publisher().PublishedAuthorityLine(volume) + return h.workspaceLineOwner(current, volume, replica, epoch) +} + +// workspaceLineOwner is TERM-HOLDER-001's single owner decision function +// (INV-AUTH-HOLDER-IDENTITY-001). A captured current line never takes the +// publisher's store-write lock (INV-WS-RENEW-NONBLOCKING-001); only historical +// lines need the move journal. Endpoints never identify a server. +func (h *Host) workspaceLineOwner(current authority.PublishedLine, volume, replica string, epoch uint64) string { + if current.ReplicaID == replica && current.Epoch == epoch { + if current.OwnerFromMove || current.IssuedHost != "" { + return current.IssuedHost + } + return h.placementSourceHost(volume, replica) + } if state := h.Publisher().WorkspaceState(volume); state != nil { for _, r := range state.Moves { if r.Issued && r.NewReplicaID == replica && r.NewEpoch == epoch { diff --git a/seaweed-block/core/host/master/workspace_lease_horizon_test.go b/seaweed-block/core/host/master/workspace_lease_horizon_test.go index 4882279711..5910a0371c 100644 --- a/seaweed-block/core/host/master/workspace_lease_horizon_test.go +++ b/seaweed-block/core/host/master/workspace_lease_horizon_test.go @@ -148,6 +148,9 @@ func TestWorkspaceRenewalRPCDuringHeldSameVolumeReservation(t *testing.T) { }() renewed := make(chan *control.WorkspaceLeaseFact, 1) renewErr := make(chan error, 1) + ownerResult := make(chan string, 1) + ownerJoined := make(chan struct{}) + ownerStarted := false renewStarted := false t.Cleanup(func() { // bounded: release, settle both workers, then clear the hook releaseHook() @@ -158,6 +161,14 @@ func TestWorkspaceRenewalRPCDuringHeldSameVolumeReservation(t *testing.T) { settled = false t.Error("held reservation write did not settle") } + if ownerStarted { + select { + case <-ownerJoined: + case <-time.After(5 * time.Second): + settled = false + t.Error("owner lookup did not settle") + } + } if renewStarted { select { case <-renewErr: @@ -175,6 +186,22 @@ func TestWorkspaceRenewalRPCDuringHeldSameVolumeReservation(t *testing.T) { case <-time.After(3 * time.Second): t.Fatal("reservation write of vol-b never reached the store") } + // TERM-HOLDER-001: current-line facts and lease admission resolve the + // same committed owner without entering the publisher's store-write lock. + ownerStarted = true + go func() { + defer close(ownerJoined) + ownerResult <- h.workspaceSourceHost("vol-b", line.ReplicaID, line.Epoch) + }() + select { + case owner := <-ownerResult: + matches, matchErr := svc.holderMatches(loopbackPeer(ctx), "vol-b", line.ReplicaID, owner, line.Epoch) + if owner != "node-a" || !matches || matchErr != nil { + t.Fatalf("fact and lease owner differ under held writer: %q", owner) + } + case <-time.After(time.Second): + t.Fatal("current owner lookup waited for publisher store write") + } renewStarted = true go func() { f, err := svc.RenewWorkspaceLease(loopbackPeer(ctx), id) diff --git a/seaweed-block/core/host/master/workspace_line_owner_test.go b/seaweed-block/core/host/master/workspace_line_owner_test.go new file mode 100644 index 0000000000..c99f7c4ab1 --- /dev/null +++ b/seaweed-block/core/host/master/workspace_line_owner_test.go @@ -0,0 +1,74 @@ +package master + +import ( + "github.com/seaweedfs/seaweed-block/core/lifecycle" + control "github.com/seaweedfs/seaweed-block/core/rpc/control" + "testing" +) + +// TERM-HOLDER-001 / INV-AUTH-HOLDER-IDENTITY-001: current facts, leases and +// move-source history share the owner rule; placement does not override a move. +func TestWorkspaceLineOwnerIssuedAndHistorical(t *testing.T) { + h, conn, ctx := reviewBindingHost(t) + reviewLegacyBind(t, h, conn, ctx, "v") + ws := control.NewWorkspaceServiceClient(conn) + id := leaseHolderIdentity(t, 1, "node-a") + 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) + } + target := &control.WorkspaceBinding{VolumeId: "v", ServerId: "node-b", DataAddr: "127.0.0.1:20000", CtrlAddr: "127.0.0.1:20001"} + if _, err := ws.RegisterWorkspaceBinding(ctx, target); err != nil { + t.Fatal(err) + } + grant, err := ws.MoveWorkspace(ctx, &control.WorkspaceMove{RequestId: "owner-move", VolumeId: "v", ExpectedReplicaId: "r1", ExpectedEpoch: 1, TargetReplicaId: "r1", TargetServerId: "node-b", TargetDataAddr: target.DataAddr, TargetCtrlAddr: target.CtrlAddr, Kind: "clean"}) + if err != nil { + t.Fatal(err) + } + if !grant.Issued || grant.NewEpoch != 2 { + t.Fatal("move did not issue", grant) + } + svc := &services{host: h} + matches := func(server string) bool { + t.Helper() + ok, err := svc.holderMatches(loopbackPeer(ctx), "v", "r1", server, 2) + if err != nil { + t.Fatal(err) + } + return ok + } + if got := h.placementSourceHost("v", "r1"); got != "node-a" { + t.Fatal("fixture placement no longer differs from issued owner", got) + } + // Both consumers must prefer the issued owner to the old placement. + if got := h.workspaceSourceHost("v", "r1", 2); got != "node-b" || !matches(got) || matches("node-a") { + t.Fatal("fact/lease issued owner mismatch", got) + } + stream, err := control.NewAssignmentServiceClient(conn).SubscribeAssignments(ctx, &control.SubscribeRequest{VolumeId: "v", ReplicaId: "r1", ServerId: "node-b"}) + if err != nil { + t.Fatal(err) + } + fact, err := stream.Recv() + if err != nil || fact.GetServerId() != "node-b" || fact.GetEpoch() != 2 { + t.Fatal("wrong produced fact", fact, err) + } + if _, err := ws.RenewWorkspaceLease(ctx, leaseHolderIdentity(t, 2, "node-b")); err != nil { + t.Fatal("issued owner lease refused", err) + } + // Change only desired-placement metadata. It must not rewrite the owner of + // the historical e1 line retained in the actual issued move journal. + if _, err := h.Lifecycle().Placements.ApplyPlan(lifecycle.PlacementPlan{VolumeID: "v", DesiredRF: 1, Candidates: []lifecycle.PlacementCandidate{{VolumeID: "v", ServerID: "node-c", ReplicaID: "r1", Source: lifecycle.PlacementSourceExistingReplica}}}); err != nil { + t.Fatal(err) + } + if got := h.workspaceSourceHost("v", "r1", 1); got != "node-a" { + t.Fatal("historical line guessed from current placement", got) + } + if got := h.workspaceSourceHost("v", "r1", 2); got != "node-b" || !matches(got) { + t.Fatal("issued owner changed with placement", got) + } +} diff --git a/seaweed-block/core/host/master/workspace_service.go b/seaweed-block/core/host/master/workspace_service.go index 53b6238d21..7c72a96438 100644 --- a/seaweed-block/core/host/master/workspace_service.go +++ b/seaweed-block/core/host/master/workspace_service.go @@ -109,11 +109,7 @@ func (s *services) holderMatches(ctx context.Context, volume, replica, server st if !ok || server == "" || line.ReplicaID != replica || line.Epoch != epoch { return false, nil } - owner := line.IssuedHost - if owner == "" { - owner = s.host.placementSourceHost(volume, line.ReplicaID) - } - return server == owner, nil + return server == s.host.workspaceLineOwner(line, volume, replica, epoch), nil } func (s *services) RenewWorkspaceLease(ctx context.Context, q *control.WorkspaceIdentity) (*control.WorkspaceLeaseFact, error) { diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index 2e0b5ed147..dde4d9cc7e 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -90,6 +90,38 @@ blockmaster's publisher is the only component that mints epochs. Diagrams: the a **Workspace lease and move, in blockmaster.** +TERM-HOLDER-001 uses one deciding function, `Host.workspaceLineOwner`. The +stream supplies the PublishedLine captured in its AssignmentInfo; lease/ACK +checks supply the captured leaf view; move source uses a leaf snapshot wrapper. +`Publisher.captureAssignmentOwner` captures the moved owner under the publication +lock and reloads it from that durable record's workspace journal. A moved line +with unknown owner sends an empty server id; only a move-less line falls back to +placement. Renewal never enters the publisher store-write lock for this lookup. +The stream regression injects an unavailable journal at encoding time; it does +not claim that a pre-issued publication is reachable in the current publisher. + + +```mermaid +flowchart LR + Reserved[Move reserved] --> Capture[Issue: capture line and moved owner under pub.mu] + Capture --> Durable[Persist line and issuing journal together] + Durable --> Published[Publish assignment and derived lease view] + Published --> Stream[Stream encodes captured line via workspaceLineOwner] + Published --> Lease[Lease and ACK use captured leaf owner] + Stream --> Known[Known moved owner: same server id] + Stream --> Unknown[Unknown moved owner: empty server id] + Stream --> Initial[Move-less epoch: placement owner] +``` + +Model trace: [WorkspaceRegrant round 4 pins and simulation results](../spec/WorkspaceRegrant-owner-label-results.md) +binds the owner-label switch, five configurations and reported results to exact +hashes. Captured labels use StreamLabelFromStore=FALSE; the mutant models a +lagging send-time owner store. Status is SIMULATION ONLY (3 seeds, 20,000 traces +each, depth 120); exhaustive combo10 is pending. No model proof is claimed. +The stream regression is an injected fault control; real P5 did not reproduce +a pre-issued publication. + + | From | To | Event and guard | Enforced in | Protects | |---|---|---|---|---| | none | Granted | `RenewWorkspaceLease` from the current primary (server id, replica id) at the current epoch; a missing/foreign server is refused by RPC holderMatches (registered server id, gRPC peer on its registered host: `refuseWorkspaceHolderHost`); no move pending; the first grant is written synchronously and persists the durable horizon now + 1.5·TTL (an epoch issued by a move already has its lease) | `core/authority/workspace_lease_view.go` `RenewWorkspaceLease`, `firstWorkspaceGrant`; `core/host/master/workspace_service.go` `holderMatches` | `INV-WS-LEASE-001`, `INV-WS-LEASE-HORIZON-001`, `INV-AUTH-HOLDER-IDENTITY-001` | @@ -101,7 +133,7 @@ blockmaster's publisher is the only component that mints epochs. Diagrams: the a | 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 | Granted | Same current primary server/replica/epoch, validated by RPC holderMatches (registered server id, gRPC peer on its registered host: `refuseWorkspaceHolderHost`) with missing server refused, no pending move or revocation/ACK, store certain; horizon and granted/restart deadline plus full skew both passed (the existing forced-move barrier); a busy authority writer refuses this attempt, otherwise persist the new horizon before its grant. A terminal guard stays terminal; a new process claims HEAD before I/O. | `core/authority/workspace_lease_view.go` `regrantWorkspaceLease`; `core/authority/workspace.go` `forcedMoveBarrierLocked`; `core/host/master/workspace_service.go` `holderMatches` | `INV-WS-LEASE-REGRANT-001`, `INV-WS-REOPEN-FENCE-001`, `INV-WS-CLAIM-BEFORE-SERVE-001`, `INV-AUTH-HOLDER-IDENTITY-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` | +| Moved | epoch issued | the moved owner is captured with the assignment under pub.mu and persisted with the issuing move journal before publication; the stream uses that captured owner, empty when unknown, with placement fallback only for a move-less epoch; 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/assignment_owner.go` `captureAssignmentOwner`; `core/host/master/services.go` `assignmentFact`; `core/host/master/workspace_binding.go` `workspaceLineOwner`; `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` | ### M3 Replica role and peer state @@ -575,7 +607,7 @@ Notes: | ID | Statement | Machine / transition | Enforced in | Test | TLA+ property | Status | |---|---|---|---|---|---|---| -| `INV-AUTH-HOLDER-IDENTITY-001` | A primary holder is the pair (server id, replica id): every site that decides holdership (adopting a fact, lease first grant, renew, re-grant, HEAD claim, superseded exit) compares both; a missing server id is refused, never guessed. | AUTHORITY: PRIMARY holdership (supporting replicas are not holders) | `core/host/volume/host.go` `applyFact`, `IsSuperseded`, `recordOtherLine`; `assignment_holder.go` `assignmentNamesSelf`, `observeForeignHolder`, `refusePrimaryAssignment`; `host.go` `IsSuperseded`; `core/host/master/services.go` `SubscribeAssignments`; `workspace_service.go` `holderMatches`, `RenewWorkspaceLease`, `AckWorkspaceRevoked`; `cmd/blockvolume/chunk_remote.go` `chunkHolder`; `core/storage/chunk_restore.go` `ClaimChunkHead`; superseded exit covered by #409; `core/host/master/server_host_identity.go` `refuseServerIDFromOtherHost` (from `ReportHeartbeat`), `refuseWorkspaceHolderHost` (from `holderMatches` and, for a workspace volume, `SubscribeAssignments`), `holderSlotFact` (from `QueryVolumeStatus` and `observationVolume`/`observationReplicas`); `core/csi/master_backend.go` `primaryOwnedFrontends` (a CSI target only from a usable primary frontend, iSCSI by IQN and LUN) | `TestAssignmentHolderIdentityRestartedOldProcess`, `TestAssignmentHolderIdentityMatchingServerStillAdopts`, `TestAssignmentHolderIdentityFencesPreviouslyHealthySameReplica`, `TestAssignmentHolderIdentityAdoptsAndWarnsCarriedEndpointMismatch`, `TestAssignmentHolderIdentityForeignStreamOrdering`, `TestAssignmentHolderIdentityForcedMoveRefusesEveryDeliveredVersion`, `TestAssignmentHolderIdentitySameEpochCannotChangeServer` (`core/host/volume/assignment_holder_test.go`); `TestWorkspaceLeaseGuardCarriesHolderServerIdentity` (`core/host/volume/workspace_holder_identity_test.go`); `TestWorkspaceLeaseRequiresHolderServerForGrantRenewAndRegrant`, `TestWorkspaceRevocationACKRequiresHolderServer` (`core/host/master/workspace_holder_identity_test.go`); `TestWorkspaceRPCCleanMovePreservesReplicaIdentity` (`core/host/master/workspace_service_test.go`); HEAD claim: `TestChunkHolderIsServerAndReplica` (`cmd/blockvolume/chunk_remote_test.go`), `TestWALStoreChunk_SameReplicaOnAnotherServerIsFenced` (`core/frontend/durable/provider_chunk_holder_test.go`); superseded exit: covered by #409 (server-id/replica-id pair, never replica alone); supporting replicas are not holders; descriptor identity not in this row; `TestServerIDRefusedFromAHostOtherThanItsRegisteredOne`, `TestWorkspaceHolderRefusedFromAnotherHostAtRenewAckAndStream`, `TestPortalAndPrimaryComeFromTheLineServerNotTheFreshestHeartbeat`, `TestDisplayedPrimaryIsTheIssuedHolderNotThePlacementSlot`, `TestStatusListsNoFrontendWhenThePrimaryEvidenceIsMissing`, `TestCSIPublishesNoTargetWhenThePrimaryFrontendIsMissingOrRejected`, `TestDeletionReservedWorkspaceVolumeKeepsTheStreamHostCheck` (`core/host/master/server_host_identity_test.go`); `TestPublishTargetIsPrimaryOwned` (`core/csi/primary_owned_frontend_test.go`). Host scope: registered advertised-host consistency, not process uniqueness; a workspace holder's server id must be registered (no first-seen binding: host addresses change); non-workspace heartbeats from an unregistered id are not checked. Limits: trusts the network peer address (no NAT or proxy between volume and master in OSS); not authentication | - (unit and RPC identity boundary) | ACTIVE | +| `INV-AUTH-HOLDER-IDENTITY-001` | A primary holder is the pair (server id, replica id): every site that decides holdership (adopting a fact, lease first grant, renew, re-grant, HEAD claim, superseded exit) compares both; a missing server id is refused, never guessed. | AUTHORITY: PRIMARY holdership (supporting replicas are not holders) | `core/host/volume/host.go` `applyFact`, `IsSuperseded`, `recordOtherLine`; `assignment_holder.go` `assignmentNamesSelf`, `observeForeignHolder`, `refusePrimaryAssignment`; `host.go` `IsSuperseded`; `core/host/master/services.go` `SubscribeAssignments`; `workspace_service.go` `holderMatches`, `RenewWorkspaceLease`, `AckWorkspaceRevoked`; `cmd/blockvolume/chunk_remote.go` `chunkHolder`; `core/storage/chunk_restore.go` `ClaimChunkHead`; superseded exit covered by #409; `core/host/master/workspace_binding.go` `workspaceLineOwner`, `workspaceSourceHost`; `core/authority/assignment_owner.go` `captureAssignmentOwner`; `core/host/master/services.go` `assignmentFact`; `core/host/master/server_host_identity.go` `refuseServerIDFromOtherHost` (from `ReportHeartbeat`), `refuseWorkspaceHolderHost` (from `holderMatches` and, for a workspace volume, `SubscribeAssignments`), `holderSlotFact` (from `QueryVolumeStatus` and `observationVolume`/`observationReplicas`); `core/csi/master_backend.go` `primaryOwnedFrontends` (a CSI target only from a usable primary frontend) | `TestAssignmentHolderIdentityRestartedOldProcess`, `TestAssignmentHolderIdentityMatchingServerStillAdopts`, `TestAssignmentHolderIdentityFencesPreviouslyHealthySameReplica`, `TestAssignmentHolderIdentityAdoptsAndWarnsCarriedEndpointMismatch`, `TestAssignmentHolderIdentityForeignStreamOrdering`, `TestAssignmentHolderIdentityForcedMoveRefusesEveryDeliveredVersion`, `TestAssignmentHolderIdentitySameEpochCannotChangeServer` (`core/host/volume/assignment_holder_test.go`); `TestWorkspaceLeaseGuardCarriesHolderServerIdentity` (`core/host/volume/workspace_holder_identity_test.go`); `TestWorkspaceLeaseRequiresHolderServerForGrantRenewAndRegrant`, `TestWorkspaceRevocationACKRequiresHolderServer` (`core/host/master/workspace_holder_identity_test.go`); `TestWorkspaceRPCCleanMovePreservesReplicaIdentity` (`core/host/master/workspace_service_test.go`); HEAD claim: `TestChunkHolderIsServerAndReplica` (`cmd/blockvolume/chunk_remote_test.go`), `TestWALStoreChunk_SameReplicaOnAnotherServerIsFenced` (`core/frontend/durable/provider_chunk_holder_test.go`); superseded exit: covered by #409 (server-id/replica-id pair, never replica alone); supporting replicas are not holders; descriptor identity not in this row; `TestWorkspaceLineOwnerIssuedAndHistorical` (`core/host/master/workspace_line_owner_test.go`), `TestWorkspaceRenewalRPCDuringHeldSameVolumeReservation` (`core/host/master/workspace_lease_horizon_test.go`); `TestAssignmentFactKeepsCapturedMoveOwnerWithoutReadableJournal` (`core/host/master/assignment_fact_owner_test.go`), `TestAssignmentOwnerReservedAndIssuedCapture` (`core/authority/assignment_owner_test.go`), `TestWorkspaceCrashAfterJournalBeforeEpochResumesSameGrant` (`core/authority/workspace_test.go`); `TestServerIDRefusedFromAHostOtherThanItsRegisteredOne`, `TestWorkspaceHolderRefusedFromAnotherHostAtRenewAckAndStream`, `TestPortalAndPrimaryComeFromTheLineServerNotTheFreshestHeartbeat`, `TestDisplayedPrimaryIsTheIssuedHolderNotThePlacementSlot`, `TestStatusListsNoFrontendWhenThePrimaryEvidenceIsMissing`, `TestCSIPublishesNoTargetWhenThePrimaryFrontendIsMissingOrRejected`, `TestDeletionReservedWorkspaceVolumeKeepsTheStreamHostCheck` (`core/host/master/server_host_identity_test.go`); `TestPublishTargetIsPrimaryOwned` (`core/csi/primary_owned_frontend_test.go`). Host scope: registered advertised-host consistency, not process uniqueness; a workspace holder's server id must be registered (no first-seen binding: host addresses change); non-workspace heartbeats from an unregistered id are not checked. Limits: trusts the network peer address (no NAT or proxy between volume and master in OSS); not authentication | `WorkspaceRegrant` `NoForeignAdoption`, `TargetNotFencedByOwnLine` (round 4 pinned simulations only; exhaustive combo10 pending) | ACTIVE | | `INV-AUTH-EPOCH-MINT-001` | Only the publisher mints epochs; a reassignment takes the per-volume maximum epoch plus one, also after a restart. | M2 Bound → Reassigned | `core/authority/authority.go` `applyWithWorkspaceMove`, `maxPublishedEpochForVolume` | `TestG8_0_Publisher_ReassignAdvancesPerVolumeEpochAcrossReplicaSlots` (`core/authority/g8_0_authority_failover_test.go`); `TestDurableAuthority_PublisherAdvancesFromReloaded` (`core/authority/authority_restart_test.go`); `TestG9F2_AssignmentRequestShapeHasNoEpochOrEndpointVersion` (`core/host/master/authority_request_bridge_test.go`) | `ControlPlane` `UniqueEpoch` | ACTIVE | | `INV-AUTH-PERSIST-BEFORE-PUBLISH-001` | With an authority store configured, an assignment is written to the store before memory or any subscriber sees it, and a failed write does not publish it: see M2 any → (store write first). | M2 any → (store write first) | `core/authority/authority.go` `applyWithWorkspaceMove` | `TestDurableAuthority_PutFailureRollsBackInMemoryState` (`core/authority/authority_restart_test.go`) | `ControlPlane` `UniqueEpoch` | ACTIVE | | `INV-AUTH-MOVE-JOURNAL-001` | A workspace move's epoch is issued only after its journal record is durable, and one move request id gets exactly one epoch, also across restarts. | M2 MoveReserved → MoveIssued | `core/authority/workspace.go` `prepareWorkspaceMoveLocked`, `MoveWorkspace`, `sameWorkspaceRequest` | `TestWorkspaceMoveCannotIssueEpochWithoutJournal`, `TestWorkspaceCrashAfterJournalBeforeEpochResumesSameGrant` (`core/authority/workspace_test.go`); `TestWorkspaceReplayedIssueStartsGranteeLease` (`core/authority/workspace_unclaimed_grant_test.go`) | `ControlPlane` `Idempotent`, `JournalComplete` | ACTIVE | diff --git a/seaweed-block/docs/spec/WorkspaceRegrant-owner-label-results.md b/seaweed-block/docs/spec/WorkspaceRegrant-owner-label-results.md new file mode 100644 index 0000000000..657c71b379 --- /dev/null +++ b/seaweed-block/docs/spec/WorkspaceRegrant-owner-label-results.md @@ -0,0 +1,48 @@ +# Workspace owner-label model: round 4 pins + +This is a citation of claude06's external model and its reported simulations, +not an exhaustive public-spec result. Source bundle: +`V:/share/rdma/claude06-sw-tla-regrant-r0-20261122/`. + +`WorkspaceRegrant.tla` round 4 maps `StreamLabelFromStore = FALSE` to +`Publisher.captureAssignmentOwner` -> immutable `AssignmentInfo` -> +`services.assignmentFact` -> `Host.workspaceLineOwner`. The lease view derives +the same owner metadata (`INV-LEASE-VIEW-001`). A moved unknown owner is empty; +only a move-less line falls back to placement (`INV-AUTH-HOLDER-IDENTITY-001`). +The TRUE switch injects a send-time owner store that can lag. This is a model +fault schedule, not evidence of a reachable pre-issued publication in current +Go code; the real P5 trace showed the old host refusing both foreign facts. + +## Results and limits + +Status: **SIMULATION ONLY**. `summary-r4.tsv` reports 3 seeds x 20,000 traces, +depth 120, with these exact configurations: + +| Configuration | Reported result | +|---|---| +| `WR_id4_fix_label.cfg` | No violation in the simulations | +| `WR_id4_fix_label_ownline.cfg` | No violation in the simulations | +| `WR_id4_RED_label.cfg` | `NoForeignAdoption` violated at traces 14, 17, 15 | +| `WR_id4_RED_label_safety.cfg` | No safety-invariant violation in the simulations; lease layer stops the adopter | +| `WR_id4_fix_label_volguard.cfg` | `NoForeignAdoption` still violated at traces 14, 17, 15; a fresh process has no recorded foreign line | + +The result interpretation is in `REGRANT-REPORT.md`, "Round 4: adoption fence". +A simulation finding is a counterexample; no sampled violation does not prove +an invariant. Exhaustive round 4 is **PENDING** in claude06's next Azure slot, +bundle `combo10`, results expected under +`V:/share/rdma/claude06-tlc-azure-results-20261120/tlc-combo10-*`. +Date depends on the open budget decision. No exhaustive state count or GO claim +is made here. This pending model is not added to the Exhausted bounds table. + +## Exact source pins + +| Artifact (relative to source bundle) | SHA-256 | +|---|---| +| `WorkspaceRegrant.tla` | `d92922331afa2bb127d4f29b9d6fc266354c30b8d11a9a0bd3931e67d2c27d1c` | +| `cfg/WR_id4_fix_label.cfg` | `d716ed5a9d4fce039e2dda084901c789f85f5a44e03d2db28d30a17312ad199f` | +| `cfg/WR_id4_fix_label_ownline.cfg` | `49188ae6776114c9c4358bac0e0dbf8187622feba25a69c1aaf97ed0da8bcdc1` | +| `cfg/WR_id4_RED_label.cfg` | `d22cf52f84bc6b2eed4f0696e4f84285daba2fe5ad0111bbae3358da7a3d1d50` | +| `cfg/WR_id4_RED_label_safety.cfg` | `ca1b0b66fdeb4fef31d43a5efb4e3bb5ef501270f1a6441c8250fb084d4f0e69` | +| `cfg/WR_id4_fix_label_volguard.cfg` | `86fad07c3a9e321ea5dd52a1e4b104c61bdc34a3ce08b4bc123d9b2d97e47f65` | +| `summary-r4.tsv` | `4ca8155ff7c3922d5ff6b0880c41ef59ef13169cc1af9cc630f7fd06256cdbd3` | +| `REGRANT-REPORT.md` | `eab94a6d2e5d81ad9318cb56a90b77958b1a73719258c9500cf71f9c95fc286a` |