From b528a0c9ecd3e11135c9b3daf68bc1b67e2e2156 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 22 Nov 2026 08:42:32 -0800 Subject: [PATCH] fix(workspace): share detached proof and lease validity decisions --- .../cmd/blockvolume/workspace_lease.go | 6 +- .../cmd/blockvolume/workspace_proof_test.go | 58 +++++++++++++++++++ seaweed-block/core/authority/workspace.go | 5 +- .../core/authority/workspace_lease_view.go | 14 ++++- .../workspace_renewal_slowstore_test.go | 2 +- .../core/host/master/workspace_service.go | 26 ++------- .../core/host/master/workspace_skew_test.go | 5 +- seaweed-block/docs/design/invariants.md | 10 ++-- 8 files changed, 89 insertions(+), 37 deletions(-) create mode 100644 seaweed-block/cmd/blockvolume/workspace_proof_test.go diff --git a/seaweed-block/cmd/blockvolume/workspace_lease.go b/seaweed-block/cmd/blockvolume/workspace_lease.go index b0724b8288..4362b51e82 100644 --- a/seaweed-block/cmd/blockvolume/workspace_lease.go +++ b/seaweed-block/cmd/blockvolume/workspace_lease.go @@ -60,13 +60,9 @@ func workspaceDetachedGeneration(ctx context.Context, remoteFor func(string) (st if err != nil { return 0, err } - head, err := remote.GetHead(ctx) + head, err := storage.ReadDetachedChunkHead(ctx, remote, id.Epoch, holder) if err != nil { return 0, err } - proof := head.DetachedBy - if head.Gen == 0 || head.Epoch != id.Epoch || head.Holder != holder || head.State != storage.ChunkHeadDetached || proof == nil || proof.Gen != head.Gen || proof.Epoch != head.Epoch || proof.Holder != head.Holder { - return 0, fmt.Errorf("workspace shutdown has no matching stored detached HEAD") - } return head.Gen, nil } diff --git a/seaweed-block/cmd/blockvolume/workspace_proof_test.go b/seaweed-block/cmd/blockvolume/workspace_proof_test.go new file mode 100644 index 0000000000..6bbbf4e56d --- /dev/null +++ b/seaweed-block/cmd/blockvolume/workspace_proof_test.go @@ -0,0 +1,58 @@ +package main + +import ( + "context" + "errors" + control "github.com/seaweedfs/seaweed-block/core/rpc/control" + "github.com/seaweedfs/seaweed-block/core/storage" + "testing" +) + +type workspaceProofRemote struct { + storage.ChunkRemote + head storage.ChunkHead + err error + reads int +} + +func (r *workspaceProofRemote) GetHead(context.Context) (storage.ChunkHead, error) { + r.reads++ + return r.head, r.err +} + +func TestWorkspaceRevocationUsesExactStoredSeal(t *testing.T) { + for _, name := range []string{"valid", "zero-epoch", "empty-holder", "active", "proof-gen", "foreign-holder", "read-error"} { + t.Run(name, func(t *testing.T) { + h := storage.ChunkHead{Gen: 7, Epoch: 2, Holder: "s/r", State: storage.ChunkHeadDetached, DetachedBy: &storage.ChunkDetachedBy{Gen: 7, Epoch: 2, Holder: "s/r"}} + id := &control.WorkspaceIdentity{VolumeId: "v", ReplicaId: "r", Epoch: 2} + holder := "s/r" + r := &workspaceProofRemote{head: h} + switch name { + case "zero-epoch": + id.Epoch = 0 + r.head.Epoch = 0 + r.head.DetachedBy.Epoch = 0 + case "empty-holder": + holder = "" + r.head.Holder = "" + r.head.DetachedBy.Holder = "" + case "active": + r.head.State = storage.ChunkHeadActive + case "proof-gen": + r.head.DetachedBy.Gen = 6 + case "foreign-holder": + r.head.Holder = "other/r" + case "read-error": + r.err = errors.New("HEAD answer lost") + } + gen, err := workspaceDetachedGeneration(context.Background(), func(string) (storage.ChunkRemote, error) { return r, nil }, id, holder) + if name == "valid" { + if err != nil || gen != 7 || r.reads != 1 { + t.Fatalf("stored seal: gen%d reads%d err%v", gen, r.reads, err) + } + } else if err == nil || gen != 0 { + t.Fatalf("unproven ACK gen%d err%v", gen, err) + } + }) + } +} diff --git a/seaweed-block/core/authority/workspace.go b/seaweed-block/core/authority/workspace.go index adae4867fa..8382c23230 100644 --- a/seaweed-block/core/authority/workspace.go +++ b/seaweed-block/core/authority/workspace.go @@ -277,8 +277,9 @@ func (p *Publisher) AckWorkspaceRevocation(ctx context.Context, volume string, a if !ok || line.info.ReplicaID != ack.ReplicaID || line.info.Epoch != ack.Epoch || ack.HeadGen == 0 || s == nil || s.Lease == nil || !s.Lease.Revoking { return fmt.Errorf("workspace revoke ACK: stale or unsolicited") } - now := p.workspaceNow() - if now.UnixNano() >= s.Lease.ExpiresAtNS || !now.Before(p.leaseDeadlineLocked(volume)) { + lease := *s.Lease + lease.ExpiresAtNS = min(lease.ExpiresAtNS, p.leaseDeadlineLocked(volume).UnixNano()) + if p.WorkspaceLeaseValidity(lease) == 0 { return fmt.Errorf("workspace revoke ACK: lease expired; forced move required") } if s.Ack != nil && *s.Ack != ack { diff --git a/seaweed-block/core/authority/workspace_lease_view.go b/seaweed-block/core/authority/workspace_lease_view.go index 354aff74bd..b4c08095cf 100644 --- a/seaweed-block/core/authority/workspace_lease_view.go +++ b/seaweed-block/core/authority/workspace_lease_view.go @@ -144,6 +144,18 @@ func (p *Publisher) WorkspaceLeaseReply(volume string) (WorkspaceLease, bool) { return l, true } +// WorkspaceLeaseValidity reports host validity on the publisher clock, with +// the configured TTL and the larger configured/persisted skew bound. +// M2 grant/revoke ACK; INV-WS-FORCED-MOVE-HALF-SKEW-001. +func (p *Publisher) WorkspaceLeaseValidity(l WorkspaceLease) time.Duration { + return p.workspaceLeaseValidityAt(l, p.workspaceNow()) +} + +func (p *Publisher) workspaceLeaseValidityAt(l WorkspaceLease, now time.Time) time.Duration { + remaining := time.Unix(0, l.ExpiresAtNS).Add(-p.workspaceSkew(&l) / 2).Sub(now) + return max(0, min(remaining, p.workspaceTTL)) +} + // PublishedLine is a volume's committed authority line as the lease view // publishes it. type PublishedLine struct { @@ -261,7 +273,7 @@ func (p *Publisher) RenewWorkspaceLease(ctx context.Context, volume, holder stri // A grant without positive host validity (expiry minus half the skew // bound, leaseFact) would make the host fence on an invalid reply and lose // its remaining validity; refuse with an error instead. - if grant-lv.d.maxSkewNS/2 <= now.UnixNano() { + if p.workspaceLeaseValidityAt(WorkspaceLease{ExpiresAtNS: grant, MaxClockSkewNS: lv.d.maxSkewNS}, now) == 0 { horizon := lv.d.horizon // the view is leaseMu's: read it before the unlock (#242) summary := p.leaseStats.summaryDue(now) p.leaseMu.Unlock() diff --git a/seaweed-block/core/host/master/workspace_renewal_slowstore_test.go b/seaweed-block/core/host/master/workspace_renewal_slowstore_test.go index a9c488dbcb..c02ed5a927 100644 --- a/seaweed-block/core/host/master/workspace_renewal_slowstore_test.go +++ b/seaweed-block/core/host/master/workspace_renewal_slowstore_test.go @@ -112,7 +112,7 @@ func (c deadlineLeaseClient) RenewWorkspaceLease(ctx context.Context, id *contro done <- result{err: err} return } - done <- result{fact: leaseFact(id.VolumeId, l)} + done <- result{fact: leaseFact(c.p, id.VolumeId, l)} }() select { case r := <-done: diff --git a/seaweed-block/core/host/master/workspace_service.go b/seaweed-block/core/host/master/workspace_service.go index 2a84382c6a..04981c09fa 100644 --- a/seaweed-block/core/host/master/workspace_service.go +++ b/seaweed-block/core/host/master/workspace_service.go @@ -78,23 +78,9 @@ func workspaceError(err error) error { return status.Error(codes.FailedPrecondition, err.Error()) } -func leaseFact(volume string, l authority.WorkspaceLease) *control.WorkspaceLeaseFact { - // Client anchors this duration to its request START, not response arrival. - // The host fences half a skew bound before the stored master expiry. - // Never grant more than the server's configured 30s TTL after a restart. - skew := time.Duration(l.MaxClockSkewNS) - // Older persisted leases predate the bound; use the production default. - if skew <= 0 { - skew = 20 * time.Second - } - remaining := time.Until(time.Unix(0, l.ExpiresAtNS).Add(-skew / 2)) - if remaining > 30*time.Second { - remaining = 30 * time.Second - } - if remaining < 0 { - remaining = 0 - } - return &control.WorkspaceLeaseFact{VolumeId: volume, ReplicaId: l.ReplicaID, Epoch: l.Epoch, ExpiresAtNs: l.ExpiresAtNS, ValidForNs: int64(remaining), Revoking: l.Revoking} +func leaseFact(p *authority.Publisher, volume string, l authority.WorkspaceLease) *control.WorkspaceLeaseFact { + // The client anchors this duration to its request START, not response arrival. + return &control.WorkspaceLeaseFact{VolumeId: volume, ReplicaId: l.ReplicaID, Epoch: l.Epoch, ExpiresAtNs: l.ExpiresAtNS, ValidForNs: int64(p.WorkspaceLeaseValidity(l)), Revoking: l.Revoking} } // holderMatches implements INV-AUTH-HOLDER-IDENTITY-001 for both holder RPCs. @@ -125,7 +111,7 @@ func (s *services) RenewWorkspaceLease(ctx context.Context, q *control.Workspace if err != nil { return nil, workspaceError(err) } - return leaseFact(q.GetVolumeId(), l), nil + return leaseFact(s.host.Publisher(), q.GetVolumeId(), l), nil } func (s *services) RevokeWorkspace(ctx context.Context, q *control.WorkspaceIdentity) (*control.WorkspaceLeaseFact, error) { @@ -140,7 +126,7 @@ func (s *services) RevokeWorkspace(ctx context.Context, q *control.WorkspaceIden if !ok { return nil, status.Error(codes.FailedPrecondition, "workspace moved during revocation") } - return leaseFact(q.GetVolumeId(), lease), nil + return leaseFact(s.host.Publisher(), q.GetVolumeId(), lease), nil } func (s *services) AckWorkspaceRevoked(ctx context.Context, q *control.WorkspaceRevocationAck) (*control.WorkspaceEmpty, error) { @@ -416,7 +402,7 @@ func (s *services) QueryWorkspace(ctx context.Context, q *control.WorkspaceVolum return out, nil } if lease, ok := s.host.Publisher().WorkspaceLeaseReply(q.GetVolumeId()); ok { - out.Lease = leaseFact(q.GetVolumeId(), lease) // granted expiry, not the durable horizon + out.Lease = leaseFact(s.host.Publisher(), q.GetVolumeId(), lease) // granted expiry, not the durable horizon } if state.Ack != nil { out.RevocationAck = &control.WorkspaceRevocationAck{Identity: &control.WorkspaceIdentity{VolumeId: q.GetVolumeId(), ReplicaId: state.Ack.ReplicaID, Epoch: state.Ack.Epoch}, HeadGen: state.Ack.HeadGen} diff --git a/seaweed-block/core/host/master/workspace_skew_test.go b/seaweed-block/core/host/master/workspace_skew_test.go index a26ec75701..e6a3317d2d 100644 --- a/seaweed-block/core/host/master/workspace_skew_test.go +++ b/seaweed-block/core/host/master/workspace_skew_test.go @@ -19,7 +19,7 @@ func (c skewLeaseClient) RenewWorkspaceLease(ctx context.Context, id *control.Wo if err != nil { return nil, err } - return leaseFact(id.VolumeId, l), nil + return leaseFact(c.p, id.VolumeId, l), nil } func (skewLeaseClient) AckWorkspaceRevoked(context.Context, *control.WorkspaceRevocationAck, ...grpc.CallOption) (*control.WorkspaceEmpty, error) { panic("expiry must not ACK clean") @@ -151,7 +151,6 @@ func TestWorkspaceClockSkewConfigReachesLeaseReply(t *testing.T) { func TestWorkspaceLeaseFactUsesPublisherClockAndSkew(t *testing.T) { now := time.Unix(1000, 0) p := authority.NewPublisher(nil, authority.WithWorkspaceLeaseConfig(12*time.Second, func() time.Time { return now }), authority.WithWorkspaceMaxClockSkew(4*time.Second)) - _ = p for _, tc := range []struct { name string expiry time.Duration @@ -165,7 +164,7 @@ func TestWorkspaceLeaseFactUsesPublisherClockAndSkew(t *testing.T) { } { t.Run(tc.name, func(t *testing.T) { l := authority.WorkspaceLease{ReplicaID: "r", Epoch: 1, ExpiresAtNS: now.Add(tc.expiry).UnixNano(), MaxClockSkewNS: tc.skew} - fact := leaseFact("v", l) + fact := leaseFact(p, "v", l) if fact.ValidForNs != int64(tc.want) { t.Fatalf("validity=%s, want %s", time.Duration(fact.ValidForNs), tc.want) } diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index 19bb6ca18b..3d06edcae3 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -134,7 +134,7 @@ a pre-issued publication. | 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` | | Granted | Granted | current primary server/replica/epoch required by RPC holderMatches (registered server id, gRPC peer on its registered host: `refuseWorkspaceHolderHost`) (missing server refused); 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`; `core/host/master/workspace_service.go` `holderMatches` | `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`, `INV-AUTH-HOLDER-IDENTITY-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 primary server/replica at the current epoch, validated by the same RPC holderMatches (registered server id, gRPC peer on its registered host: `refuseWorkspaceHolderHost`) (missing/foreign server refused), a nonzero HEAD generation, the lease still valid; a different second acknowledgement is refused | `core/authority/workspace.go` `AckWorkspaceRevocation`; `core/host/master/workspace_service.go` `holderMatches` | `INV-WS-CLEAN-MOVE-001`, `INV-WS-REVOKE-ACK-001`, `INV-AUTH-HOLDER-IDENTITY-001` | +| Revoking | Acked | `AckWorkspaceRevocation` from the primary server/replica at the current epoch, validated by the same RPC holderMatches (registered server id, gRPC peer on its registered host: `refuseWorkspaceHolderHost`) (missing/foreign server refused), a nonzero HEAD generation, positive granted validity after half the configured/persisted skew on the publisher clock; a different second acknowledgement is refused | `core/authority/workspace.go` `AckWorkspaceRevocation`; `core/host/master/workspace_service.go` `holderMatches` | `INV-WS-CLEAN-MOVE-001`, `INV-WS-REVOKE-ACK-001`, `INV-AUTH-HOLDER-IDENTITY-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` | @@ -722,7 +722,7 @@ Notes: | `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 | -| `INV-WS-FORCED-MOVE-HALF-SKEW-001` | The validity the master gives a host with a lease ends half the clock-skew bound before the reported lease expiry. | M2 Granted → Granted (reply); M4 NoLease, Valid → Valid | `core/host/master/workspace_service.go` `leaseFact`; `core/host/volume/workspace_lease.go` `Refresh` | `TestWorkspaceSkewSeparatesOldServingFromForcedGrant` (`core/host/master/workspace_skew_test.go`) | — | ACTIVE | +| `INV-WS-FORCED-MOVE-HALF-SKEW-001` | The validity the master gives a host with a lease ends half the clock-skew bound before the reported lease expiry. | M2 Granted → Granted (reply); M4 NoLease, Valid → Valid | `core/authority/workspace_lease_view.go` `WorkspaceLeaseValidity`, `workspaceLeaseValidityAt`; `core/host/master/workspace_service.go` `leaseFact`; `core/authority/workspace.go` `AckWorkspaceRevocation`; `core/host/volume/workspace_lease.go` `Refresh` | `TestWorkspaceLeaseFactUsesPublisherClockAndSkew` (`core/host/master/workspace_skew_test.go`); `TestWorkspaceAckUsesGrantedHalfSkewBoundary` (`core/authority/workspace_validity_test.go`); `TestWorkspaceSkewSeparatesOldServingFromForcedGrant` (`core/host/master/workspace_skew_test.go`) | — | ACTIVE | | `INV-WS-LOST-RANGE-READOUT-001` | Every issued forced grant the master returns, also on a replay and after a restart, carries the lost range stored in the authority store before the issue, never a recomputed one: see M2 Moved → epoch issued. | M2 lease: Expired → Moved (forced); Moved → epoch issued | `core/authority/workspace_lost_range.go` `recordLostRangeLocked`, `WorkspaceLostRangeReadouts`, `encodeLostRangeEnvelope`; `core/authority/workspace.go` `prepareWorkspaceMoveLocked`; `core/host/master/workspace_head.go` `headFilerMtimeNS`; `core/host/master/workspace_service.go` `grantWithLostRange`, `issuedRecord`; `core/rpc/wsclient/wsclient.go` `Readout` | `TestWorkspaceForcedMoveRecordsTheLostRange`, `TestWorkspaceForcedMoveLostRangeOrdering`, `TestWorkspaceForcedReservationResumeNeedsItsRange` (`core/authority/workspace_lost_range_test.go`); `TestWorkspaceForcedMoveStoresHeadFilerTime` (`core/authority/workspace_lost_range_readout_test.go`); `TestWorkspaceForcedMoveLostRangeOverRPC`, `TestWorkspaceHEADReadsFilerMtime` (`core/host/master/workspace_lost_range_readout_test.go`); `TestReadoutWording` (`core/rpc/wsclient/wsclient_test.go`); `TestWorkspaceForceMove_Row3and4_SentAndGranted` (`cmd/sw-block/workspace_test.go`); `TestWorkspaceForceMoveAgainstRealMaster` (`cmd/sw-block/workspace_master_test.go`) | — | ACTIVE | | `INV-WS-LOST-RANGE-QUERY-001` | `QueryWorkspaceLostRange` returns the stored ranges unchanged: every issued forced move's range in issue order, or the single range of a given request id. | M2 lease: Moved → epoch issued (readout) | `core/authority/workspace_lost_range.go` `WorkspaceLostRangeReadouts`; `core/host/master/workspace_service.go` `QueryWorkspaceLostRange`; `core/rpc/wsclient/wsclient.go` `LostRanges`; `cmd/sw-block/workspace.go` `runWorkspaceLostRange` | `TestWorkspaceLostRangeAccumulatesInIssueOrder` (`core/authority/workspace_lost_range_readout_test.go`); `TestLostRangesBindsTheAnswer` (`core/rpc/wsclient/wsclient_test.go`); `TestWorkspaceLostRangeListsAllInOrder` (`cmd/sw-block/workspace_test.go`) | — | ACTIVE | | `INV-WS-LOST-RANGE-FAILCLOSED-001` | If an issued forced move's range record is missing or fails its range or HEAD-time checksum, the readout fails: the grant carries no range but the reason, the query returns `DataLoss`, the CLI exits 4; none reports the move as no loss. | M2 lease: Moved → epoch issued | `core/authority/workspace_lost_range.go` `LoadWorkspaceLostRanges`, `decodeLostRangeHeadTimes`, `WorkspaceLostRangeReadouts`; `core/host/master/workspace_service.go` `grantWithLostRange`, `QueryWorkspaceLostRange`; `core/rpc/wsclient/wsclient.go` `classify`, `checkRange`; `cmd/sw-block/workspace.go` `runWorkspaceForceMove`, `runWorkspaceLostRange` | `TestWorkspaceLostRangeReadoutFailsClosed`, `TestWorkspaceLostRangeHeadTimeTamperFailsClosed`, `TestWorkspaceLostRangeSkippedWriteIsDetected` (`core/authority/workspace_lost_range_readout_test.go`); `TestForceMoveGrantWithoutRangeIsUnproven` (`core/rpc/wsclient/wsclient_test.go`); `TestWorkspaceForceMove_Row7_ReadoutUnproven` (`cmd/sw-block/workspace_test.go`) | — | ACTIVE | @@ -755,7 +755,7 @@ Notes: - `INV-WS-FORCED-MOVE-001`: TLA+: `W4_drift` found the gap before #158; the skew margin itself is not in the model. Extended for a new holder that dies between its grant and its HEAD claim: the move issue starts its lease, admission uses that grant's lease, HEAD is read after admission, an older-epoch HEAD is accepted (its generation and remote LSN may have moved by an earlier holder's late claim), and a returning holder is refused by two fences, its lease-gated attach and the higher HEAD epoch. `WorkspaceTakeover` models one move from A to B and does not cover a second move away from an unclaimed grant; that model check is open and not claimed here. - `INV-WS-LOST-RANGE-READOUT-001`: The HEAD time is the HEAD filer entry's mtime from the filer's `Last-Modified` header on the same read as the HEAD content (1 s resolution). chunkstore writes that mtime from the clock of the host that wrote the entry (the cut); the readout labels it "(publishing host clock as recorded in the filer, 1 s resolution)", and it is not a master time; there is no HEAD format change. The HEAD times sit beside the v1 ranges in the lost-range file with their own checksum, so a binary that predates them still verifies the file; a record without one reads as unknown. The readout reads the ranges loaded at startup: damage after startup shows at the next load. The no-HEAD form ("no remote image exists") is defensive: the master refuses a forced move without a published HEAD. The header is checked against test HTTP servers only; the `chunkstore_integration` test does not assert it. Not in the TLA+ models. - `INV-WS-FORCED-CONFIRM-001`: A client-side rule: the master's own guards (explicit force, admission, expected epoch) are `INV-WS-FORCED-MOVE-001`. The holder's logical replica id is read from `QueryWorkspace` (the lease, or the journal on a rerun). The holder check (`INV-WS-FORCED-CONFIRM-HOLDER-001`) sends that one `QueryWorkspace` RPC; only the move is withheld. -- `INV-WS-FORCED-MOVE-001`, `INV-WS-FORCED-MOVE-REPLY-001`, `INV-WS-FORCED-MOVE-HALF-SKEW-001`: the persisted lease horizon is at least every grant (`INV-WS-LEASE-HORIZON-001`). blockmaster reads HEAD only after the forced admission holds; HEAD must be the expected holder's at the expected epoch, or any HEAD at an older epoch; the lost range starts at that HEAD's remote LSN: see M2 Expired → Moved (forced) (tests `TestWorkspaceUnclaimedGrantForcedReassignOverRPC`, `TestWorkspaceUnclaimedGrantHEADRule`, `TestWorkspaceForcedMoveRecordsTheLostRange`). The publisher checks the admission again when it issues the move. The host counts its validity from the start of its renewal request: see M4 NoLease, Valid → Valid. The validity is a duration computed on the master's wall clock (`time.Until`); `leaseFact` also caps it at 30 s and uses a 20 s bound when an older persisted lease carries none. +- `INV-WS-FORCED-MOVE-001`, `INV-WS-FORCED-MOVE-REPLY-001`, `INV-WS-FORCED-MOVE-HALF-SKEW-001`: the persisted lease horizon is at least every grant (`INV-WS-LEASE-HORIZON-001`). blockmaster reads HEAD only after the forced admission holds; HEAD must be the expected holder's at the expected epoch, or any HEAD at an older epoch; the lost range starts at that HEAD's remote LSN: see M2 Expired → Moved (forced) (tests `TestWorkspaceUnclaimedGrantForcedReassignOverRPC`, `TestWorkspaceUnclaimedGrantHEADRule`, `TestWorkspaceForcedMoveRecordsTheLostRange`). The publisher checks the admission again when it issues the move. The host counts its validity from the start of its renewal request: see M4 NoLease, Valid → Valid. The authority-owned `WorkspaceLeaseValidity` computes duration on the publisher clock with its configured TTL and the larger configured/persisted skew, including legacy leases with no stored bound. Renewal admission, RPC replies and revocation ACK admission share that calculation; ACK uses the granted deadline clamped to the durable horizon. `workspaceDetachedGeneration` reads its exact stored seal through `ReadDetachedChunkHead`; `TestWorkspaceRevocationUsesExactStoredSeal` (`cmd/blockvolume/workspace_proof_test.go`) covers valid and refused proofs without publishing. - `INV-WS-LOST-RANGE-READOUT-001`: a stored range holds the kept HEAD's remote LSN; the forced-move barrier as LostUntil, in master time; the kept HEAD's generation (via the move record); and the HEAD entry's filer mtime read with that HEAD, or "unknown". A missing or damaged record is `INV-WS-LOST-RANGE-FAILCLOSED-001`. A failure after the issue (for example the binding reconciliation) is answered `Internal` naming the move ISSUED, never as a refusal: see M2 Moved → epoch issued. `PreviewWorkspaceMove` runs the forced admission, reads HEAD only once admitted, and writes nothing: see M2 Expired → Moved (forced) (tests `TestWorkspaceForcedMovePreviewWritesNothing`, `TestWorkspaceForceMove_Row2_DryRunPreview`). - `INV-WS-LOST-RANGE-UNCERTAIN-001`, `INV-WS-LOST-RANGE-PRE-ISSUE-001`: on a volume already uncertain, every failed move, an admission refusal or a HEAD-read error included, is answered as an unknown outcome and logged as unknown; only the request's own cancellation or deadline stays typed, and an issued move's replay still returns its stored grant: see `INV-AUTH-UNCERTAIN-001` and M2 Uncertain → Uncertain (move answer). - Enforced by reading (no test asserts it): the publisher's second admission check when it issues a forced move (`prepareWorkspaceMoveLocked` calls `forcedMoveAdmissionLocked`). @@ -1060,13 +1060,13 @@ A row that names a function existing only on an open pull request says so ("on # | Term | Meaning | Field(s) | Deciding function (one per side) | Known second derivations to remove | Owner role | |---|---|---|---|---|---| | `TERM-HOLDER-001` Holder identity (the primary of a single-copy workspace volume only; supporting replicas are not holders) | The process that may act as primary of a single-copy workspace volume at an epoch is the pair (server id, replica id) at that epoch. A matching replica id or endpoint alone never names it, and a missing server id is refused. A local-root nonce joins the pair later (pending). | `AssignmentFact` `server_id`, `replica_id`, `epoch` (`core/rpc/proto/control.proto`; `server_id` on [#411](https://github.com/seaweedfs/seaweed-block/pull/411)); `WorkspaceIdentity` `server_id`, `replica_id`, `epoch` (`core/rpc/proto/workspace.proto`; `server_id` on #411); the published line's `PublishedLine.IssuedHost` (`core/authority/workspace_lease_view.go`) and the move journal's `WorkspaceMoveRecord.NewHost` (`core/authority/workspace.go`); the volume's `Config.ServerID`, `Config.ReplicaID` (`core/host/volume/host.go`, from `--server-id`, `--replica-id`); the HEAD `Holder`, written as `/` (`cmd/blockvolume/chunk_remote.go` `chunkHolder`) | Master: `core/host/master/workspace_service.go` `services.holderMatches(volume, replica, server, epoch)`, on #411; it gates `RenewWorkspaceLease` and `AckWorkspaceRevoked`, after the host check of #416, and takes the line's owner server from `core/host/master/workspace_binding.go` `Host.workspaceLineOwner`, on #423, the one owner decision for current and historical lines (through `PublishedLine.Owner`, which the snapshot builder's `expectOwnerForLine` also calls). The line's owner server is carried in the published line; a move's line names the move's new host; placement names the owner only for the initial line; an unknown owner is sent empty and never adopted. A volume that has seen an epoch owned by one server never adopts that epoch for another (this covers replays). The safety rule is the refusal to adopt a line naming another server; fencing on a foreign line is defence in depth, and only a process that has adopted a lineage fences, on a strictly newer foreign line. Volume: `core/host/volume/assignment_holder.go` `Host.assignmentNamesSelf`, on #411; called by `applyFact` and `IsSuperseded`. | `Host.applyFact` adopts a fact on the replica id alone. `Host.IsSuperseded` ignores a same-replica line from another server. `Host.recordOtherLine` lets an older line overwrite a newer one. Lease renewals and revocation ACKs carry no server id. All four are removed by #411. The master's status frontends and CSI publish target take the freshest same-replica heartbeat from any server (`ObservationStore.SlotFact` via `statusFrontendsForAssignedVolume`), and the operator's primary node is the placement slot (`serverForReplica`). Both are removed by [#416](https://github.com/seaweedfs/seaweed-block/pull/416), stacked on #411. The master computed the line's owner server twice; #423 makes it one function. | authority (master side); volume host (volume side) | -| `TERM-LEASE-NOW-001` Lease valid now | The holder may act on its workspace lease at this instant only while the guard has not fenced and host monotonic time is before the start of its last successful renewal plus the granted validity. The granted validity is the master expiry less half the clock-skew bound, at most 30 s. | `WorkspaceLease` `ExpiresAtNS`, `MaxClockSkewNS`, and the lease view's durable horizon and granted deadline (`core/authority/workspace_lease_view.go`); `WorkspaceLeaseFact` `valid_for_ns`, `expires_at_ns`, `revoking` (`core/rpc/proto/workspace.proto`); `WorkspaceLeaseGuard` `until`, `fenced` (`core/host/volume/workspace_lease.go`) | Holder: `core/host/volume/workspace_lease.go` `WorkspaceLeaseGuard.permits`. Master: `core/authority/workspace_lease_view.go` `Publisher.RenewWorkspaceLease`. `firstWorkspaceGrant` and `regrantWorkspaceLease` are reached only from it, and only it starts the extender `extendWorkspaceLease`. | `Publisher.AckWorkspaceRevocation` (`core/authority/workspace.go`) checks expiry again inline, without the skew term: open. `leaseFact` (`core/host/master/workspace_service.go`) recomputes the host validity with `time.Now` instead of the publisher's clock, with a 20 s skew fallback, while `RenewWorkspaceLease` refuses a grant on the same term inline: open (one helper for both). `WorkspaceLeaseGuard.drain` checks `now < until` again inline before the ACK, and `WorkspaceLeaseGuard.Refresh` repeats the expiry check of `permits`: open (both should call one predicate). The 30 s TTL is written three times: the publisher's default TTL (`core/authority/authority.go`), the cap in `leaseFact`, and the reply bound in `Refresh`: open. Not a duplicate: `Publisher.forcedMoveBarrierLocked` decides the opposite term, "the lease is over for the master" (the horizon and the deadline each plus the full skew bound), which a forced move and a re-grant need. | authority (grant); volume host (guard) | +| `TERM-LEASE-NOW-001` Lease valid now | The holder may act on its workspace lease at this instant only while the guard has not fenced and host monotonic time is before the start of its last successful renewal plus the granted validity. The granted validity is the master expiry less half the clock-skew bound, capped by the configured TTL. | `WorkspaceLease` `ExpiresAtNS`, `MaxClockSkewNS`, and the lease view's durable horizon and granted deadline (`core/authority/workspace_lease_view.go`); `WorkspaceLeaseFact` `valid_for_ns`, `expires_at_ns`, `revoking` (`core/rpc/proto/workspace.proto`); `WorkspaceLeaseGuard` `until`, `fenced` (`core/host/volume/workspace_lease.go`) | Holder: `core/host/volume/workspace_lease.go` `WorkspaceLeaseGuard.permits`. Master: `core/authority/workspace_lease_view.go` `Publisher.WorkspaceLeaseValidity` / `workspaceLeaseValidityAt` is shared by renewal admission, `leaseFact` and `AckWorkspaceRevocation`. `WorkspaceLeaseValidity` reads the publisher clock; its leaf calculation uses the larger configured/persisted skew and configured TTL. `Publisher.RenewWorkspaceLease`. `firstWorkspaceGrant` and `regrantWorkspaceLease` are reached only from it, and only it starts the extender `extendWorkspaceLease`. | `WorkspaceLeaseGuard.drain` checks `now < until` again inline before the ACK, and `WorkspaceLeaseGuard.Refresh` repeats the expiry check of `permits`: open (both should call one predicate). The host reply sanity bound in `Refresh` still repeats the publisher's default 30 s TTL: open. Not a duplicate: `Publisher.forcedMoveBarrierLocked` decides the opposite term, "the lease is over for the master" (the horizon and the deadline each plus the full skew bound), which a forced move and a re-grant need. | authority (grant); volume host (guard) | | `TERM-SERVING-001` Serving / ready | A workspace primary claims HEAD, listens, reports ready and admits I/O only while its lease guard permits now and its durable backend is operational. Without a granted lease it holds at the gate and exits 75 after the start-time wait. | `frontend.Projection.Healthy`; the `StorageBackend` operational flag and its evidence, reported as `VolumeStatus.Operational` (`core/frontend/durable`); `StatusProjection.FrontendPrimaryReady` (and `NotReadyReason`, on [#410](https://github.com/seaweedfs/seaweed-block/pull/410)); the ALUA and ANA state; `HeartbeatSlot.frontends` | Authority side: `core/host/volume/projection_bridge.go` `AdapterProjectionView.projectionWithSupersede`, which ANDs in `WorkspaceLeaseGuard.permits` for workspace volumes. Storage side: the `StorageBackend` operational flag (`core/frontend/durable/storage_adapter.go`), written only by `SetOperational` and read by `readyCheck`. The one decision of both sides together is `StorageBackend.AdmitsIO` (the guarded AND), read by the status, the frontend start gate and every I/O: on #410 (today `StorageBackend.gate` on `main`). | `StatusServer.authorityProjection` derives `FrontendPrimaryReady` from the authority view alone, and it repeats the supersede and supporting tests that `Healthy` already contains. #410 adds the backend half in `statusProjection`; the repeated tests remain open. The frontends listen whether or not the backend admits I/O: #410 holds them in `awaitBackendAdmitsIO` until it does. #410 replaces its earlier `backendAdmitsIO` (which read only `VolumeStatus.Operational`) with `StorageBackend.AdmitsIO`. A later lease fence ends the process on [#409](https://github.com/seaweedfs/seaweed-block/pull/409). `projectionALUAProvider.ALUAState` and `projectionANAProvider.ANAState` (`cmd/blockvolume`) follow the projection only: open. The start-time wait (`chunkAuthorityWait`; `ProviderConfig.ChunkAssignmentTimeout`, 30 s by default) ends once, and the process then stays up without serving: #409 makes it exit 75. iSCSI reports a not-ready or busy backend as a medium error, while NVMe retries the same error: [#415](https://github.com/seaweedfs/seaweed-block/pull/415) (`frontend.ClassifyBackendError`). The heartbeat `Frontends` are set when the listeners start and cleared only at shutdown: open. | volume host | | `TERM-STOP-SUPERSEDED-001` Superseded | A newer published line for this volume names another holder (another replica, or the same replica on another server) at or above this process's epoch and endpoint version. From then on the process is not healthy. | `Host.lastOther` (an `AssignmentFact`); the process's own epoch and endpoint version | Volume: `core/host/volume/host.go` `Host.IsSuperseded`. Its same-replica branch, and the ordered `recordOtherLine` it reads, are on #411. | The status repeat listed under `TERM-SERVING-001`. `Host.IsCurrentReplicaSuperseded` (on #409) and `Host.promotionReady` call `IsSuperseded` with other lineages. They are wrappers, not second derivations. | volume host | | `TERM-STOP-LEASE-FENCED-001` Lease fenced / revoked | The lease guard has latched: its deadline passed, a reply was invalid or late, the lease is revoking, or the process is stopping. A fenced guard never reopens. The host drains, and only when the lease was revoked does it acknowledge with the HEAD generation. | `WorkspaceLeaseGuard` `fenced`, `cause`, `revoked` (`core/host/volume/workspace_lease.go`) | Volume: `core/host/volume/workspace_lease.go` `WorkspaceLeaseGuard.fenceLocked`, the one writer of `fenced`; it is read through `permits`. | `Host.FenceWorkspaceLease` and `runWorkspaceLease` (`core/host/volume/workspace_runtime.go`) set `fenced` directly, with no cause, and keep a second latch, `Host.workspaceLeaseFenced`: open. On `main` a guard fence ends the process with status 0: #409 makes it exit 75. | volume host | | `TERM-STOP-HEAD-FENCED-001` HEAD fenced | HEAD shows a higher epoch, or another holder at this epoch. The chunk layer latches fenced and publishes nothing more, and the backend refuses I/O as stale. | HEAD `Epoch`, `Holder`, `Gen`; `chunkLayerImpl` `fenced` (`core/storage`) | Volume: `core/storage/chunk_layer.go` `chunkLayerImpl.supersededBy`. | `ClaimChunkHead` (`core/storage/chunk_restore.go`) repeats the comparison inline: open. Four cut and detach paths in `chunk_layer.go` set `fenced` directly, next to the setter `fencePublication`: open (one setter). A HEAD fence after startup ends the process with 78 (`head_fenced`): on #410. A refused startup claim exits with 78: on #409. | chunk layer | | `TERM-STOP-STALE-ROOT-001` Stale local root | An existing local root whose HEAD another holder has published is refused before the claim and never served. The process stays up without serving. | HEAD `Holder`; `ProviderConfig.ChunkHolder` | Volume: the `PrepareRestore` check inside `DurableProvider.newChunkLayer` (`core/frontend/durable/provider_chunk.go`). It is not a named function: open. | It compares the holder only, so a rolled-back root of the same holder passes: pending the local-root nonce. | volume host | -| `TERM-STOP-SEALED-001` Sealed | HEAD is detached by this holder at this epoch with a matching `DetachedBy` proof (generation, epoch, holder). The sealing process never reopens it, and only that proof licenses a clean move. | HEAD `State`, `DetachedBy` `Gen`, `Epoch`, `Holder` | Volume: `core/storage/chunk_seal_replay.go` `ReadDetachedChunkHead`. Master: `core/host/master/workspace_head.go` `NewWorkspaceHEADReader`, whose reader checks the proof before `workspaceHeadAdmits` sees the HEAD. | `workspaceDetachedGeneration` (`cmd/blockvolume/workspace_lease.go`) reimplements the proof check for the revocation ACK: open. The sealed-reopen test in `ClaimChunkHead` checks state, epoch and holder without the proof: open. | chunk layer (volume side); authority (master side) | +| `TERM-STOP-SEALED-001` Sealed | HEAD is detached by this holder at this epoch with a matching `DetachedBy` proof (generation, epoch, holder). The sealing process never reopens it, and only that proof licenses a clean move. | HEAD `State`, `DetachedBy` `Gen`, `Epoch`, `Holder` | Volume: `core/storage/chunk_seal_replay.go` `ReadDetachedChunkHead`. Master: `core/host/master/workspace_head.go` `NewWorkspaceHEADReader`, whose reader checks the proof before `workspaceHeadAdmits` sees the HEAD. | `workspaceDetachedGeneration` (`cmd/blockvolume/workspace_lease.go`) delegates revocation ACK proof to `ReadDetachedChunkHead`, with `TestWorkspaceRevocationUsesExactStoredSeal` coverage. The sealed-reopen test in `ClaimChunkHead` checks state, epoch and holder without the proof: open. | chunk layer (volume side); authority (master side) | | `TERM-STOP-EXIT-001` Exit class of a stopped workspace primary | A workspace primary that stops ends its process with one latched class. 75 means retry (start-time wait exhausted, lease fence, unconfirmed ACK). 78 means superseded (the line names another holder). 0 is used only after an ACKed revocation or a signal. | `workspaceExit` `code`, `reason`; the `processExit` decision (`cmd/blockvolume/process_exit.go`, on #409) | Volume: `cmd/blockvolume/process_exit.go` `workspaceRetryOutcome`, on #409. `processExit.choose` latches the first outcome. | `chooseChunkStartupExit` (on #409) turns 75 into 78 on a refused HEAD claim (`DurableProvider.ChunkStartupSuperseded`), outside `workspaceRetryOutcome`: open. On #409 alone, "superseded" means another replica; the same replica on another server counts only with #411's `IsSuperseded`: open until both merge. | volume host | | `TERM-ONE-PROCESS-001` One live process per holder | At most one blockvolume process serves a holder at a time. Today a second process is refused only when it opens the same store file. A local-root nonce in the holder identity is to close the other cases (pending). | The store file `<--durable-root>/.bin` (`cmd/blockvolume/main.go` `durableCreateGeometry`); its exclusive OS file lock; the HEAD `Holder` | Volume: `core/storage/volume_lock.go` `LockWALStoreFile`: an exclusive, non-blocking `flock` in `volume_lock_unix.go` and an exclusive, fail-immediately `LockFileEx` in `volume_lock_windows.go`. It is taken by v3 create and open and by the read-only open. | Not a second derivation but the lock's limit: it covers one file. A second process is not refused when it uses another `--durable-root`, runs on another host with the same server id, or runs on a copied root. Two such processes with one holder string both pass `ClaimChunkHead` and both renew. A failed CAS against the other process's same-epoch, same-holder HEAD is treated as a conflict, not a fence (`publicationOwnerChanged`): open, pending the local-root nonce. #416 refuses a server id that heartbeats from another host's address (`refuseServerIDFromOtherHost`), which covers part of this. The master's grants carry no per-process identity: open. | storage engine |