mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 18:47:20 +01:00
Merge pull request #400 from seaweedfs/train/20261122-18
train 18: same-holder re-grant after lease expiry
This commit is contained in:
commit
7f4f61d9ce
6 files changed
+508
-10
No files matched your search
@@ -177,8 +177,8 @@ func (p *Publisher) PublishedAuthorityLines() map[string]PublishedLine {
|
||||
// RenewWorkspaceLease answers a live holder from memory: it takes only the
|
||||
// leaf leaseMu, does no I/O and never waits on p.mu or the store. The grant
|
||||
// is min(now+TTL, durable horizon); a background extender (an ordinary p.mu
|
||||
// writer) pushes the horizon ahead. Only the first grant of a lease writes
|
||||
// synchronously (firstWorkspaceGrant).
|
||||
// writer) pushes the horizon ahead. A first grant and an expired re-grant
|
||||
// after the shared move barrier write synchronously.
|
||||
func (p *Publisher) RenewWorkspaceLease(ctx context.Context, volume, holder string, epoch uint64) (WorkspaceLease, error) {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return WorkspaceLease{}, err
|
||||
@@ -214,7 +214,7 @@ func (p *Publisher) RenewWorkspaceLease(ctx context.Context, volume, holder stri
|
||||
}
|
||||
if now.UnixNano() >= lv.d.horizon || !now.Before(lv.deadline) {
|
||||
unlock()
|
||||
return WorkspaceLease{}, fmt.Errorf("workspace lease expired or revoking")
|
||||
return p.regrantWorkspaceLease(ctx, volume, holder, epoch)
|
||||
}
|
||||
// Where the synchronous write used to refuse (persistWorkspaceLocked):
|
||||
// a renewal never bypasses uncertainty (INV-AUTH-UNCERTAIN-001).
|
||||
@@ -310,9 +310,49 @@ func (p *Publisher) firstWorkspaceGrant(ctx context.Context, volume, holder stri
|
||||
return WorkspaceLease{ReplicaID: holder, Epoch: epoch, ExpiresAtNS: grant.UnixNano(), MaxClockSkewNS: lease.MaxClockSkewNS}, nil
|
||||
}
|
||||
|
||||
// INV-WS-LEASE-REGRANT-001: serialize an expired re-grant with move issue,
|
||||
// reusing the forced-move barrier so the old process's validity is past.
|
||||
// The live renewal path releases leaseMu before entering this writer.
|
||||
func (p *Publisher) regrantWorkspaceLease(ctx context.Context, volume, holder string, epoch uint64) (WorkspaceLease, error) {
|
||||
// INV-WS-RENEW-NONBLOCKING-001: a held writer refuses this attempt;
|
||||
// a returning process can retry after that writer has settled.
|
||||
if !p.mu.TryLock() {
|
||||
return WorkspaceLease{}, fmt.Errorf("workspace lease: authority writer busy; retry")
|
||||
}
|
||||
defer p.mu.Unlock()
|
||||
if err := ctx.Err(); err != nil {
|
||||
return WorkspaceLease{}, err
|
||||
}
|
||||
_, line, ok := p.workspaceLineLocked(volume)
|
||||
s := cloneWorkspace(p.workspace[volume])
|
||||
if !ok || line.info.ReplicaID != holder || line.info.Epoch != epoch || s == nil || s.Lease == nil ||
|
||||
s.Lease.ReplicaID != holder || s.Lease.Epoch != epoch {
|
||||
return WorkspaceLease{}, fmt.Errorf("workspace lease: stale authority")
|
||||
}
|
||||
if s.Lease.Revoking || s.Ack != nil || (len(s.Moves) > 0 && !s.Moves[len(s.Moves)-1].Issued) {
|
||||
return WorkspaceLease{}, fmt.Errorf("workspace lease: revocation or move pending")
|
||||
}
|
||||
if p.store == nil || p.workspaceUncertain[volume] {
|
||||
return WorkspaceLease{}, fmt.Errorf("workspace durable store unavailable or uncertain")
|
||||
}
|
||||
_, now, err := p.forcedMoveBarrierLocked(volume, s.Lease)
|
||||
if err != nil {
|
||||
return WorkspaceLease{}, err
|
||||
}
|
||||
lease, grant := p.newWorkspaceLease(holder, epoch, now)
|
||||
lease.ExpiresAtNS = max(lease.ExpiresAtNS, s.Lease.ExpiresAtNS)
|
||||
lease.MaxClockSkewNS = int64(p.workspaceSkew(s.Lease))
|
||||
s.Lease = lease
|
||||
if err := p.persistWorkspaceLocked(volume, s); err != nil {
|
||||
return WorkspaceLease{}, err
|
||||
}
|
||||
p.setLeaseDeadlineLocked(volume, grant, true)
|
||||
return WorkspaceLease{ReplicaID: holder, Epoch: epoch, ExpiresAtNS: grant.UnixNano(), MaxClockSkewNS: lease.MaxClockSkewNS}, nil
|
||||
}
|
||||
|
||||
// newWorkspaceLease starts a lease at now: the durable horizon is
|
||||
// now+1.5*TTL and the grant (the deadline) now+TTL. Both a first grant and a
|
||||
// move issue start a lease this way.
|
||||
// now+1.5*TTL and the grant (the deadline) now+TTL. A first grant, expired
|
||||
// re-grant and move issue start a lease this way.
|
||||
func (p *Publisher) newWorkspaceLease(holder string, epoch uint64, now time.Time) (*WorkspaceLease, time.Time) {
|
||||
return &WorkspaceLease{ReplicaID: holder, Epoch: epoch, ExpiresAtNS: now.Add(p.workspaceTTL + p.workspaceTTL/2).UnixNano(), MaxClockSkewNS: int64(p.workspaceSkew(nil))}, now.Add(p.workspaceTTL)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
package authority
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend"
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/durable"
|
||||
"github.com/seaweedfs/seaweed-block/core/storage"
|
||||
)
|
||||
|
||||
type regrantStorageView struct{}
|
||||
|
||||
func (regrantStorageView) Projection() frontend.Projection {
|
||||
return frontend.Projection{VolumeID: "v", ReplicaID: "r", Epoch: 1, Healthy: true}
|
||||
}
|
||||
|
||||
// These component controls obtain the real authority re-grant before opening
|
||||
// the returning file-backed provider. They do not model a second live process.
|
||||
func TestWorkspaceLeaseRegrantPreservesLocalLogThroughFirstCut(t *testing.T) {
|
||||
testWorkspaceRegrantStorage(t, false, false)
|
||||
}
|
||||
|
||||
func TestWorkspaceLeaseRegrantCannotUnsealSameEpoch(t *testing.T) {
|
||||
testWorkspaceRegrantStorage(t, true, false)
|
||||
}
|
||||
|
||||
func TestWorkspaceLeaseRegrantEmptyRootClaimsOnlyHEAD(t *testing.T) {
|
||||
testWorkspaceRegrantStorage(t, false, true)
|
||||
}
|
||||
|
||||
func testWorkspaceRegrantStorage(t *testing.T, sealed, fresh bool) {
|
||||
t.Helper()
|
||||
ctx := context.Background()
|
||||
disk, _ := newTempStore(t)
|
||||
clock := newTestClock()
|
||||
p := newLeasePublisher(t, disk, time.Second, clock)
|
||||
bindAndGrant(t, p, "v", "r")
|
||||
remote := storage.NewMemChunkRemote()
|
||||
root := t.TempDir()
|
||||
open := func() *durable.DurableProvider {
|
||||
t.Helper()
|
||||
provider, err := durable.NewDurableProvider(durable.ProviderConfig{
|
||||
Impl: durable.ImplWALStoreChunk, StorageRoot: root, NumBlocks: 64,
|
||||
BlockSize: 4096, ChunkBlocks: 4,
|
||||
ChunkRemoteFor: func(string) (storage.ChunkRemote, error) { return remote, nil },
|
||||
}, regrantStorageView{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _ = provider.Close() })
|
||||
if _, err := provider.EnsureStorage("v"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return provider
|
||||
}
|
||||
first := open()
|
||||
if _, err := first.RecoverVolume(ctx, "v"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
backend, err := first.Open(ctx, "v")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
a, b := bytes.Repeat([]byte{0x31}, 4096), bytes.Repeat([]byte{0x42}, 4096)
|
||||
write := func(offset int64, data []byte) {
|
||||
t.Helper()
|
||||
if n, err := backend.Write(ctx, offset, data); err != nil || n != len(data) {
|
||||
t.Fatal(n, err)
|
||||
}
|
||||
if err := backend.Sync(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
write(0, a)
|
||||
if _, err := first.CaptureVolume(ctx, "v"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
write(4096, b) // completed Sync, deliberately absent from the last HEAD
|
||||
if sealed {
|
||||
if _, _, err := first.DetachVolumePlain(ctx, "v"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
before, err := remote.GetHead(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := first.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
clock.at(3) // beyond both original expiry/skew endpoints
|
||||
if _, err := p.RenewWorkspaceLease(ctx, "v", "r", 1); err != nil {
|
||||
t.Fatal("returning process could not obtain the authority re-grant", err)
|
||||
}
|
||||
if fresh {
|
||||
root = t.TempDir()
|
||||
b = make([]byte, 4096) // the absent local log cannot be claimed as present
|
||||
}
|
||||
second := open()
|
||||
_, err = second.RecoverVolume(ctx, "v")
|
||||
if sealed {
|
||||
after, readErr := remote.GetHead(ctx)
|
||||
if !errors.Is(err, storage.ErrChunkLayerDetached) || readErr != nil || !reflect.DeepEqual(after, before) {
|
||||
t.Fatal("same-epoch re-grant reactivated the seal", after, err, readErr)
|
||||
}
|
||||
blocked, openErr := second.Open(ctx, "v")
|
||||
if openErr != nil {
|
||||
t.Fatal(openErr)
|
||||
}
|
||||
if _, readErr := blocked.Read(ctx, 0, make([]byte, 4096)); !errors.Is(readErr, frontend.ErrNotReady) {
|
||||
t.Fatal("sealed re-granted process exposed guest I/O", readErr)
|
||||
}
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
returning, err := second.Open(ctx, "v")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for i, want := range [][]byte{a, b} {
|
||||
got := make([]byte, 4096)
|
||||
if _, err := returning.Read(ctx, int64(i*4096), got); err != nil || !bytes.Equal(got, want) {
|
||||
t.Fatal("return lost locally acknowledged bytes", i, err)
|
||||
}
|
||||
}
|
||||
claimed, err := remote.GetHead(ctx)
|
||||
if err != nil || claimed.Gen <= before.Gen || claimed.Epoch != 1 || claimed.Holder != before.Holder || claimed.RemoteLSN != before.RemoteLSN {
|
||||
t.Fatal("return served without the new generation fence", claimed, err)
|
||||
}
|
||||
if _, err := second.CaptureVolume(ctx, "v"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
final, err := remote.GetHead(ctx)
|
||||
if fresh {
|
||||
if err != nil || !reflect.DeepEqual(final, claimed) {
|
||||
t.Fatal("empty-root return published bytes/frontier absent from HEAD", final, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
if err != nil || final.RemoteLSN <= before.RemoteLSN {
|
||||
t.Fatal("first returning cut did not cover the local log", final, err)
|
||||
}
|
||||
payload, err := remote.Get(ctx, final.Chunks[0].Key)
|
||||
if err != nil || len(payload) < 8192 || !bytes.Equal(payload[:4096], a) || !bytes.Equal(payload[4096:8192], b) {
|
||||
t.Fatal("first cut did not publish the full acknowledged image", err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,276 @@
|
||||
package authority
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// INV-WS-LEASE-REGRANT-001: expiry alone does not abandon an unchanged owner.
|
||||
// A new guard may use a durable re-grant; existing fenced guards stay terminal.
|
||||
func TestWorkspaceLeaseExpiredSameHolderRegrantIsDurable(t *testing.T) {
|
||||
disk, _ := newTempStore(t)
|
||||
clock := newTestClock()
|
||||
store := &hookStore{AuthorityStore: disk}
|
||||
p := newLeasePublisher(t, store, time.Second, clock)
|
||||
original := bindAndGrant(t, p, "v", "r")
|
||||
before := p.WorkspaceState("v").Lease
|
||||
clock.at(3)
|
||||
writes := 0
|
||||
store.setBefore(func(r DurableRecord) error { writes++; return nil })
|
||||
renewed, err := p.RenewWorkspaceLease(context.Background(), "v", "r", 1)
|
||||
if err != nil {
|
||||
t.Fatalf("unchanged expired holder cannot obtain a durable re-grant: %v", err)
|
||||
}
|
||||
if renewed.ReplicaID != "r" || renewed.Epoch != 1 || renewed.Revoking || renewed.ExpiresAtNS <= clock.now().UnixNano() || renewed.ExpiresAtNS <= original.ExpiresAtNS || writes != 1 {
|
||||
t.Fatalf("bad re-grant %+v writes%d", renewed, writes)
|
||||
}
|
||||
records, err := disk.Load()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
found := false
|
||||
for _, r := range records {
|
||||
if r.VolumeID == "v" && r.Workspace != nil && r.Workspace.Lease != nil {
|
||||
l := r.Workspace.Lease
|
||||
found = true
|
||||
if l.ExpiresAtNS < renewed.ExpiresAtNS || l.ExpiresAtNS < before.ExpiresAtNS || l.MaxClockSkewNS < before.MaxClockSkewNS {
|
||||
t.Fatalf("grant ahead of durable horizon/skew: disk%+v reply%+v", l, renewed)
|
||||
}
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatal("re-grant used without durable lease")
|
||||
}
|
||||
line, _ := p.VolumeAuthorityLine("v")
|
||||
if line.Epoch != 1 || line.ReplicaID != "r" {
|
||||
t.Fatal("re-grant minted authority", line)
|
||||
}
|
||||
// Immediate flapping/repeated requests take the memory path: one durable
|
||||
// re-grant, no extra writes while its positive grant is outstanding.
|
||||
for i := 0; i < 10; i++ {
|
||||
if _, err := p.RenewWorkspaceLease(context.Background(), "v", "r", 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if writes != 1 {
|
||||
t.Fatalf("repeat requests amplified durable writes: %d", writes)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWorkspaceLeaseRegrantWaitsForDurabilityAndLatchesFailure(t *testing.T) {
|
||||
for _, fail := range []bool{false, true} {
|
||||
t.Run(map[bool]string{false: "durable", true: "uncertain"}[fail], func(t *testing.T) {
|
||||
disk, _ := newTempStore(t)
|
||||
clock := newTestClock()
|
||||
store := &hookStore{AuthorityStore: disk}
|
||||
p := newLeasePublisher(t, store, time.Second, clock)
|
||||
before := bindAndGrant(t, p, "v", "r")
|
||||
clock.at(3)
|
||||
entered, release := make(chan struct{}), make(chan struct{})
|
||||
var releaseOnce sync.Once
|
||||
releaseWriter := func() { releaseOnce.Do(func() { close(release) }) }
|
||||
store.setBefore(func(DurableRecord) error {
|
||||
close(entered)
|
||||
<-release
|
||||
return nil
|
||||
})
|
||||
store.setAfter(func(DurableRecord) error {
|
||||
if fail {
|
||||
return errors.New("write landed but reply lost")
|
||||
}
|
||||
return nil
|
||||
})
|
||||
type answer struct {
|
||||
lease WorkspaceLease
|
||||
err error
|
||||
}
|
||||
done := make(chan answer, 1)
|
||||
finished := make(chan struct{})
|
||||
// Registered last: release and join before publisher/store cleanup.
|
||||
t.Cleanup(func() {
|
||||
releaseWriter()
|
||||
select {
|
||||
case <-finished:
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Error("re-grant worker did not finish during cleanup")
|
||||
}
|
||||
})
|
||||
go func() {
|
||||
defer close(finished)
|
||||
l, err := p.RenewWorkspaceLease(context.Background(), "v", "r", 1)
|
||||
done <- answer{l, err}
|
||||
}()
|
||||
select {
|
||||
case <-entered:
|
||||
case got := <-done:
|
||||
t.Fatal("re-grant returned before the durable write witness", got)
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("re-grant did not enter the durable write")
|
||||
}
|
||||
if visible, ok := p.WorkspaceLeaseReply("v"); !ok || visible.ExpiresAtNS != before.ExpiresAtNS {
|
||||
t.Error("grant published ahead of durable store", visible)
|
||||
}
|
||||
// Events decide success; timers only bound failed handshakes.
|
||||
releaseWriter()
|
||||
var got answer
|
||||
select {
|
||||
case got = <-done:
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("released re-grant did not return")
|
||||
}
|
||||
if fail {
|
||||
if got.err == nil || got.lease.ExpiresAtNS != 0 {
|
||||
t.Fatal("uncertain write produced a usable grant", got)
|
||||
}
|
||||
if _, err := p.RenewWorkspaceLease(context.Background(), "v", "r", 1); err == nil {
|
||||
t.Fatal("renewal bypassed uncertain re-grant")
|
||||
}
|
||||
} else if got.err != nil || got.lease.ExpiresAtNS != clock.sec(4).UnixNano() {
|
||||
t.Fatal("durable re-grant not returned", got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestWorkspaceLeaseForcedIssueDefeatsOldHolderRegrant(t *testing.T) {
|
||||
disk, _ := newTempStore(t)
|
||||
clock := newTestClock()
|
||||
p := newLeasePublisher(t, disk, time.Second, clock)
|
||||
bindAndGrant(t, p, "v", "r")
|
||||
clock.at(3)
|
||||
req := WorkspaceMoveRequest{RequestID: "force", VolumeID: "v", ExpectedReplicaID: "r", TargetReplicaID: "r", ExpectedHost: "old", TargetHost: "new", ExpectedEpoch: 1, TargetDataAddr: "nd", TargetCtrlAddr: "nc", Kind: "forced", Force: true}
|
||||
grant, err := p.MoveWorkspace(context.Background(), req, WorkspaceHead{Gen: 7, Epoch: 1, Holder: "old/r", RemoteLSN: 42})
|
||||
if err != nil || !grant.Issued || grant.NewEpoch != 2 {
|
||||
t.Fatal("fixture did not issue forced successor", grant, err)
|
||||
}
|
||||
clock.at(7)
|
||||
if got, err := p.RenewWorkspaceLease(context.Background(), "v", "r", 1); err == nil {
|
||||
t.Fatal("old epoch re-granted after forced issue", got)
|
||||
}
|
||||
line, _ := p.VolumeAuthorityLine("v")
|
||||
if line.Epoch != 2 || p.WorkspaceState("v").Lease.Epoch != 2 {
|
||||
t.Fatal("re-grant undid forced issue", line)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWorkspaceLeaseRegrantDefeatsAlreadyPassedForcedPreflight(t *testing.T) {
|
||||
disk, _ := newTempStore(t)
|
||||
clock := newTestClock()
|
||||
p := newLeasePublisher(t, disk, time.Second, clock)
|
||||
bindAndGrant(t, p, "v", "r")
|
||||
clock.at(3)
|
||||
req := WorkspaceMoveRequest{RequestID: "force", VolumeID: "v", ExpectedReplicaID: "r", TargetReplicaID: "r", ExpectedHost: "old", TargetHost: "new", ExpectedEpoch: 1, TargetDataAddr: "nd", TargetCtrlAddr: "nc", Kind: "forced", Force: true}
|
||||
if err := p.WorkspaceForcedMoveAdmitted(context.Background(), "v", req.RequestID, "r", 1); err != nil {
|
||||
t.Fatal("forced preflight was not actually admitted", err)
|
||||
}
|
||||
if _, err := p.RenewWorkspaceLease(context.Background(), "v", "r", 1); err != nil {
|
||||
t.Fatal("same-owner re-grant failed", err)
|
||||
}
|
||||
if _, err := p.MoveWorkspace(context.Background(), req, WorkspaceHead{Gen: 7, Epoch: 1, Holder: "old/r", RemoteLSN: 42}); err == nil {
|
||||
t.Fatal("force ignored the grant committed after its HEAD preflight")
|
||||
}
|
||||
line, _ := p.VolumeAuthorityLine("v")
|
||||
if line.Epoch != 1 {
|
||||
t.Fatal("two winning successors", line)
|
||||
}
|
||||
if len(p.WorkspaceState("v").Moves) != 0 {
|
||||
t.Fatal("refused forced move reserved an epoch")
|
||||
}
|
||||
}
|
||||
|
||||
func TestWorkspaceLeaseSealedAckNeverRegrants(t *testing.T) {
|
||||
disk, _ := newTempStore(t)
|
||||
clock := newTestClock()
|
||||
store := &hookStore{AuthorityStore: disk}
|
||||
p := newLeasePublisher(t, store, 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)
|
||||
}
|
||||
// ACK is the master's durable evidence for this holder's sealed generation.
|
||||
clock.at(10)
|
||||
writes := 0
|
||||
store.setBefore(func(DurableRecord) error { writes++; return nil })
|
||||
got, err := p.RenewWorkspaceLease(ctx, "v", "r", 1)
|
||||
if err == nil && (!got.Revoking || got.ExpiresAtNS > clock.now().UnixNano()) {
|
||||
t.Fatalf("sealed/ACKed owner got usable re-grant: %+v", got)
|
||||
}
|
||||
if writes != 0 || p.WorkspaceState("v").Ack.HeadGen != 7 {
|
||||
t.Fatal("sealed proof mutated by re-grant")
|
||||
}
|
||||
}
|
||||
|
||||
// INV-WS-LEASE-REGRANT-001: expiry alone cannot fence a previous process
|
||||
// whose own clock may lag. The full skew bound must pass before re-grant.
|
||||
func TestWorkspaceLeaseRegrantWaitsForFullSkew(t *testing.T) {
|
||||
disk, _ := newTempStore(t)
|
||||
clock := newTestClock()
|
||||
store := &hookStore{AuthorityStore: disk}
|
||||
p := NewPublisher(nil, WithStore(store), WithWorkspaceLeaseConfig(10*time.Second, clock.now), WithWorkspaceMaxClockSkew(4*time.Second))
|
||||
t.Cleanup(p.CloseWorkspaceExtenders)
|
||||
grant := bindAndGrant(t, p, "v", "r")
|
||||
if grant.ExpiresAtNS != clock.sec(10).UnixNano() || p.WorkspaceState("v").Lease.ExpiresAtNS != clock.sec(15).UnixNano() {
|
||||
t.Fatal("fixture did not create the declared grant/horizon", grant)
|
||||
}
|
||||
writes := 0
|
||||
store.setBefore(func(DurableRecord) error { writes++; return nil })
|
||||
// The deadline+skew boundary is 14 s; horizon+skew is 19 s.
|
||||
// Re-grant uses the same MAX barrier as a forced move, including the
|
||||
// interval after the shorter deadline has passed and its final ns.
|
||||
for _, now := range []time.Time{clock.sec(13), clock.sec(14), clock.sec(19).Add(-time.Nanosecond)} {
|
||||
clock.ns.Store(now.UnixNano())
|
||||
if got, err := p.RenewWorkspaceLease(context.Background(), "v", "r", 1); err == nil {
|
||||
t.Fatal("re-grant crossed the later expiry/skew boundary early", now, got)
|
||||
}
|
||||
if err := p.WorkspaceForcedMoveAdmitted(context.Background(), "v", "force", "r", 1); err == nil {
|
||||
t.Fatal("forced move crossed the shared boundary early", now)
|
||||
}
|
||||
if writes != 0 {
|
||||
t.Fatal("unsafe early re-grant attempted persistence", writes)
|
||||
}
|
||||
}
|
||||
clock.at(19)
|
||||
if err := p.WorkspaceForcedMoveAdmitted(context.Background(), "v", "force", "r", 1); err != nil {
|
||||
t.Fatal("fixture did not reach the shared forced-move barrier", err)
|
||||
}
|
||||
got, err := p.RenewWorkspaceLease(context.Background(), "v", "r", 1)
|
||||
if err != nil || got.ExpiresAtNS <= clock.now().UnixNano() || writes != 1 {
|
||||
t.Fatalf("safe unchanged owner cannot return: grant=%+v writes=%d err=%v", got, writes, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWorkspaceLeaseRegrantRetainsPersistedSkewAfterRestart(t *testing.T) {
|
||||
disk, _ := newTempStore(t)
|
||||
clock := newTestClock()
|
||||
first := newLeasePublisher(t, disk, time.Second, clock)
|
||||
before := bindAndGrant(t, first, "v", "r")
|
||||
first.CloseWorkspaceExtenders()
|
||||
clock.at(3)
|
||||
returned := NewPublisher(nil, WithStore(disk), WithWorkspaceLeaseConfig(time.Second, clock.now), WithWorkspaceMaxClockSkew(time.Millisecond))
|
||||
t.Cleanup(returned.CloseWorkspaceExtenders)
|
||||
// Restart deadline is 4 s. The newly configured 1 ms bound has passed,
|
||||
// but the original persisted bound still protects the previous process.
|
||||
clock.at(4.5)
|
||||
if got, err := returned.RenewWorkspaceLease(context.Background(), "v", "r", 1); err == nil {
|
||||
t.Fatal("smaller restart setting shortened the old barrier", got)
|
||||
}
|
||||
clock.at(6)
|
||||
got, err := returned.RenewWorkspaceLease(context.Background(), "v", "r", 1)
|
||||
if err != nil || got.MaxClockSkewNS != before.MaxClockSkewNS {
|
||||
t.Fatal("re-grant lowered the persisted skew", got, err)
|
||||
}
|
||||
records, err := disk.Load()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(records) != 1 || records[0].Workspace.Lease.MaxClockSkewNS != before.MaxClockSkewNS || records[0].Workspace.Lease.ExpiresAtNS < got.ExpiresAtNS {
|
||||
t.Fatal("preserved re-grant bound was not durable", records)
|
||||
}
|
||||
}
|
||||
@@ -361,10 +361,13 @@ stateDiagram-v2
|
||||
Revoking --> Acked: host acks detached HEAD gen while the lease is valid
|
||||
Acked --> Moved: CLEAN move, including same host, new epoch
|
||||
Granted --> Expired: horizon or deadline passes
|
||||
Expired --> Granted: unchanged holder, no move/revocation, MAX expiry + skew passed; durable re-grant
|
||||
Expired --> Moved: FORCED move after expiry + skew bound, then HEAD read (an older-epoch HEAD is accepted)
|
||||
}
|
||||
```
|
||||
|
||||
**Return after lease expiry.** A new process of the unchanged holder and epoch may obtain one durable re-grant after the existing forced-move barrier: both the persisted horizon and granted/restart deadline plus full skew have passed. Re-grant and forced issue serialize under the publisher lock; the winner prevents the competing operation. Revocation, a pending move or uncertain persistence refuses a usable grant. Existing fenced guards remain terminal. The returning process claims a new HEAD generation before I/O, keeps its local acknowledged WAL, and publishes it on the first cut. An empty local root restores only HEAD; a same-epoch sealed HEAD remains detached.
|
||||
|
||||
**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).
|
||||
|
||||
@@ -99,6 +99,7 @@ blockmaster's publisher is the only component that mints epochs. Diagrams: the a
|
||||
| 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 | Granted | Same current holder/epoch, 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` | `INV-WS-LEASE-REGRANT-001`, `INV-WS-REOPEN-FENCE-001`, `INV-WS-CLAIM-BEFORE-SERVE-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 <volume>@<expected epoch>`; `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` |
|
||||
|
||||
@@ -409,7 +410,7 @@ Tests: `TestSnapshotSchedule_SlotsAreOffsetPerVolume`, `_FailureIsTypedAndBacksO
|
||||
|
||||
## Part B. Invariant ledger
|
||||
|
||||
302 rows: 216 ACTIVE, 83 STUB, 3 ARCHIVED; 15 kept from the internal ledger, 287 new.
|
||||
303 rows: 217 ACTIVE, 83 STUB, 3 ARCHIVED; 15 kept from the internal ledger, 288 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.
|
||||
|
||||
@@ -581,7 +582,7 @@ Notes:
|
||||
| `INV-LEASE-VIEW-OWNED-001` | The granted deadline and the extender flag exist only in the lease view; refreshing the view from its derive inputs never changes either of them. | M2 every workspace transition | `core/authority/workspace_lease_view.go` `refreshLeaseViewLocked`, `setLeaseDeadlineLocked`, `extendWorkspaceLease` | — | — | STUB |
|
||||
| `INV-WS-LEASE-HORIZON-001` | For the active lease of the current authority epoch, the `Lease.ExpiresAtNS` persisted in the authority store is at least the published horizon, and the published horizon is at least every grant issued since the last reload. | M2 Granted → Granted | `core/authority/workspace_lease_view.go` `RenewWorkspaceLease`, `firstWorkspaceGrant`, `newWorkspaceLease`, `extendWorkspaceLease`; `core/authority/workspace.go` `persistWorkspaceLocked`, `issueWorkspaceMove` | `TestWorkspaceLeaseClampsToHorizonUnderStalledStore`, `TestWorkspaceRestartForcedBarrierHonoursHorizon`, `TestWorkspaceAmbiguousExtensionLatchesUncertainty`, `TestWorkspaceLeaseConcurrentRenewalsWritersExtendersClose` (`core/authority/workspace_lease_horizon_test.go`); `TestWorkspaceLeaseGuardFencesByHorizonUnderStalledStore` (`core/host/master/workspace_lease_horizon_test.go`) | — | ACTIVE |
|
||||
| `INV-WS-LEASE-HORIZON-MONO-001` | Within one lease the published horizon never decreases: an extension writes a new horizon only when it is greater than the current one. | M2 Granted → Granted | `core/authority/workspace_lease_view.go` `extendWorkspaceLease`; `core/authority/workspace.go` `persistWorkspaceLocked` | `TestWorkspaceExtenderHeldOrdersSameVolumeWriters`, `TestWorkspaceLeaseConcurrentRenewalsWritersExtendersClose` (`core/authority/workspace_lease_horizon_test.go`) | — | ACTIVE |
|
||||
| `INV-WS-RENEW-NONBLOCKING-001` | A renewal of an established lease takes only the leaf lease lock and lock-free lifecycle snapshots: it never waits on the publisher lock, an authority store write or a lifecycle store mutex. Only the first grant of a lease writes synchronously. | M2 Granted → Granted | `core/authority/workspace_lease_view.go` `RenewWorkspaceLease`; `core/host/master/workspace_service.go` `workspaceVolumeForRenewal` | `TestWorkspaceRenewalDoesNotWaitForSlowStore`, `TestWorkspaceConcurrentRenewalsDoNotSerializeOnStore`, `TestWorkspaceRenewalDoesNotWaitForUnrelatedHeldWrite` (`core/authority/workspace_renewal_slowstore_test.go`); `TestWorkspaceExtenderAdmittedBeforeCloseDoesNotWrite` (`core/authority/workspace_lease_horizon_test.go`); `TestWorkspaceLeaseGuardSurvivesSlowAuthorityStore`, `TestWorkspaceRenewalRPCDoesNotWaitForHeldReservationWrite` (`core/host/master/workspace_renewal_slowstore_test.go`) | — | ACTIVE |
|
||||
| `INV-WS-RENEW-NONBLOCKING-001` | Live renewals take only the leaf lease lock and lock-free lifecycle snapshots; they never wait on publisher/store locks. First grants and expired re-grants persist synchronously; an expired re-grant refuses immediately if the publisher lock is busy. | M2 Granted → Granted | `core/authority/workspace_lease_view.go` `RenewWorkspaceLease`; `core/host/master/workspace_service.go` `workspaceVolumeForRenewal` | `TestWorkspaceRenewalDoesNotWaitForSlowStore`, `TestWorkspaceConcurrentRenewalsDoNotSerializeOnStore`, `TestWorkspaceRenewalDoesNotWaitForUnrelatedHeldWrite` (`core/authority/workspace_renewal_slowstore_test.go`); `TestWorkspaceExtenderAdmittedBeforeCloseDoesNotWrite` (`core/authority/workspace_lease_horizon_test.go`); `TestWorkspaceLeaseGuardSurvivesSlowAuthorityStore`, `TestWorkspaceRenewalRPCDoesNotWaitForHeldReservationWrite` (`core/host/master/workspace_renewal_slowstore_test.go`) | — | ACTIVE |
|
||||
| `INV-LIFECYCLE-SNAPSHOT-001` | The Volumes and deletion-reservation snapshots read by the renewal path equal the store records after every change of the records, including load, delete and a protective reservation kept in memory on an unknown write outcome; a published snapshot is never mutated. | M2 Bound → Deleting (renewal reads) | `core/lifecycle/store.go` `publishLocked`, `GetVolumeSnapshot`; `core/lifecycle/deletion_reservations.go` `publishLocked`, `ReservedSnapshot` | `TestDeletionReservationSnapshotFollowsRecords`, `TestFileStoreSnapshotFollowsRecords`, `TestLifecycleSnapshotReadsDoNotTakeStoreMutex`, `TestLifecycleSnapshotConcurrentWriters` (`core/lifecycle/renewal_snapshot_test.go`); `TestWorkspaceRenewalRPCDuringHeldSameVolumeReservation` (`core/host/master/workspace_lease_horizon_test.go`) | — | ACTIVE |
|
||||
| `INV-VOL-ID-NO-REUSE-001` | A deleted volume id is never created or attached again. | M2 Deleting; M6 purging → deleted | `core/host/master/services.go` `MarkVolumeDeleting`; `core/frontend/chunkstore/catalog.go` `EnsureVolume` | `TestMarkVolumeDeleting_ReservesUnknownIdsAndSurvivesDeleteAndRestart` (`core/host/master/volume_deleting_test.go`); `TestCatalog_DeleteVolumeTombstonesAndRefusesReuse` (`core/frontend/chunkstore/volume_delete_test.go`) | `ChunkLifecycleFixed` `NoIdReuse` | ACTIVE |
|
||||
| `INV-MASTER-JOURNAL-ISOLATION-001` | Under strict journal isolation, blockmaster gives no new work to a node whose durable root shares the authority store's file system: it refuses that node's heartbeat while it serves no volume, a new placement on it and a move onto it; work the node already has is kept. | M2 workspace move: Acked or Expired → (move refused, nothing written); workspace placement admission; node heartbeat | `core/host/master/journal_isolation.go` `refuseColocatedHeartbeat`, `colocatedTargetRefused`, `reconcilePlacements`, `nodeServesVolumes`; `core/host/master/workspace_service.go` `workspaceMoveCheckLocked`; `core/host/master/workspace_binding.go` `PlaceWorkspace` | `TestColocatedNodeIsAlarmedButAcceptedByDefault`, `TestStrictRefusesColocatedNodeWithoutVolumes`, `TestStrictAcceptsColocatedNodeThatAlreadyServes`, `TestStrictRefusesPlacementAndMoveOntoColocatedNode`, `TestStrictProductLoopSkipsColocatedNodeForNewPlacement` (`core/host/master/journal_isolation_test.go`); `TestStrictReplaysAnIssuedMoveToANowColocatedTarget`, `TestStrictKeepsAnIdempotentPlacementOnANowColocatedNode` (`core/host/master/journal_isolation_fold_test.go`) | — | ACTIVE |
|
||||
@@ -593,9 +594,9 @@ Notes:
|
||||
- `INV-AUTH-UNCERTAIN-001`: The cited test asserts the refusal after an unknown-outcome lease extension (rename landed, directory sync failed): the next renewal, a revocation and an endpoint change are all refused. The TLA+ configuration `S5_red_noUncertain` violates `UniqueEpoch` without it. A Revoking lease still gets its bounded drain reply, min(horizon, deadline), never extended: see M2 any (workspace) → Uncertain. A failed move on an uncertain volume is answered as an unknown outcome before any admission refusal, the request's own cancellation or deadline stays typed, and an issued move's replay still returns its stored grant: see M2 Uncertain → Uncertain (move answer). The renewal path reads uncertainty from the lease view (`INV-LEASE-VIEW-001`), not from `persistWorkspaceLocked`.
|
||||
- `INV-WS-LEASE-HORIZON-001`: The forced-barrier argument (a renewal that reads its clock after the barrier has read the deadline is refused) assumes nondecreasing master time. That is an assumption of the current `WorkspaceTakeover` model, whose `Tick` and `SlowTick` actions only advance `now`; it is not a consequence of `time.Now` carrying a monotonic reading, because persisted `UnixNano` deadlines are compared as wall-clock values. The existing deadline check stays alongside the horizon. The model still renews with `exp = deadline = now + TTL`; the horizon/grant split is a pending specification update (Part C rule 2).
|
||||
- `INV-WS-LEASE-HORIZON-001`, `INV-WS-LEASE-HORIZON-MONO-001`: a move issue that replaces the lease with the new holder's (a clean handoff, or a forced move past the barrier) is its ordered successor and ends the scope of these rows. If that issue write is persisted ambiguously (it may have landed while memory has not published it), the volume is uncertain and no further grant at the old epoch is issued (`INV-AUTH-UNCERTAIN-001`), so no disk expiry is claimed for it.
|
||||
- `INV-LEASE-VIEW-001`, `INV-LEASE-VIEW-OWNED-001`: writers refresh the view under the publisher lock, then the lease lock, at every change of a derive input; the renewal path takes only the lease lock (`INV-WS-RENEW-NONBLOCKING-001`). A move issue publishes the derived view and the new holder's initial deadline in one lease-lock section, never lowering a deadline a renewal raised: see M2 Moved → epoch issued (test `TestWorkspaceIssuePublishNeverLowersARenewedDeadline`, `core/authority/workspace_issue_publish_test.go`).
|
||||
- `INV-LEASE-VIEW-001`, `INV-LEASE-VIEW-OWNED-001`: writers refresh the view under the publisher lock, then the lease lock, at every change of a derive input; the live renewal path takes only the lease lock (`INV-WS-RENEW-NONBLOCKING-001`). A move issue publishes the derived view and the new holder's initial deadline in one lease-lock section, never lowering a deadline a renewal raised: see M2 Moved → epoch issued (test `TestWorkspaceIssuePublishNeverLowersARenewedDeadline`, `core/authority/workspace_issue_publish_test.go`).
|
||||
- Enforced by reading (no test asserts it): `INV-AUTH-PERSIST-BEFORE-PUBLISH-001`, that no subscriber sees a failed write (`applyWithWorkspaceMove` writes the store before it changes memory and snapshots the subscribers); `INV-AUTH-UNCERTAIN-001`, the drain reply on an uncertain volume (`RenewWorkspaceLease` answers a Revoking lease before it checks uncertainty); `INV-LEASE-VIEW-OWNED-001` (`refreshLeaseViewLocked` assigns only the derived part); the one-section issue publish (`publishIssuedLeaseLocked`); `INV-WS-LEASE-HORIZON-MONO-001`, that an extension writes only a greater horizon (`extendWorkspaceLease`); and the note above on `INV-WS-LEASE-HORIZON-001`, that no old-epoch grant follows an issue write with an unknown outcome (the latch, then the uncertainty check in `RenewWorkspaceLease`).
|
||||
- `INV-WS-RENEW-NONBLOCKING-001`: The cited tests inject delays or holds before or inside the store write; they show sensitivity to a slow store, not a measured disk trace.
|
||||
- `INV-WS-RENEW-NONBLOCKING-001`: First grants and expired re-grants are synchronous exceptions (M2 Expired → Granted, `INV-WS-LEASE-REGRANT-001`); the expired path uses TryLock and refuses a busy publisher. The cited live-renewal tests inject delays or holds before or inside the store write; they show sensitivity to a slow store, not a measured disk trace.
|
||||
- `INV-MASTER-JOURNAL-ISOLATION-001`: a refused heartbeat gets FailedPrecondition. A new placement is either a workspace placement or one the product loop plans. Work the node already has means: the node serves by durable state (a placement slot or a current authority line that names it), a repeated identical placement, or the retry of an issued move. Without strict mode, co-location only raises an alarm.
|
||||
|
||||
### B.3 Core: replication and replica roles
|
||||
@@ -647,6 +648,7 @@ Notes:
|
||||
| `INV-WS-CLAIM-BEFORE-SERVE-001` | A new holder claims HEAD at its master-issued epoch before I/O opens; a HEAD with a higher epoch, or another holder at the same epoch, fences the claim. | M4 Claiming → Holder \| Fenced | `core/storage/chunk_restore.go` `ClaimChunkHead`; `core/frontend/durable/provider_chunk.go` `newChunkLayer` | `TestClaimChunkHeadRefusesStaleAuthorityAndAdmissionDrift` (`core/storage/chunk_restore_test.go`); `TestRestoreSeedPrecedesTakeoverCAS` (`core/frontend/durable/provider_seed_order_test.go`); `TestWorkspaceMoveRestoresLazilyAndFencesOldHost` (`core/host/master/workspace_restore_test.go`) | `WorkspaceTakeover` `SeedMatchesTakeover` | ACTIVE |
|
||||
| `INV-WS-STALE-LOCAL-ROOT-001` | An existing local root whose HEAD another holder has published is not served or cut; the attach fails closed with `ErrChunkStaleLocalRoot`. | M4 Claiming → Refused | `core/frontend/durable/provider_chunk.go` `newChunkLayer` | `TestWALStoreChunk_MoveBackOntoAnOldRootIsRefused`, `TestWALStoreChunk_MoveBackRefusedOnDeferredAttach` (`core/frontend/durable/provider_chunk_moveback_test.go`); `TestLocalReopenRejectsForeignClaimImage` (`core/frontend/durable/provider_reopen_belt_test.go`) | — | ACTIVE |
|
||||
| `INV-WS-SINGLE-FILER-001` | A chunk volume starts only when `--chunk-filer` is the only filer of its group: a master listing another filer or several refuses at once, whichever master answers first; a filer no master lists within 60 s is refused. A startup census, not a fence: a filer added to the group later is not detected. | M4 (startup) → Refused | `core/frontend/chunkstore/single_filer.go` `CheckSingleFiler`; `cmd/blockvolume/chunk_remote.go` `newChunkWiring`; `cmd/sw-block/chunk.go` `refuseUnlessSingleFiler` | `TestCheckSingleFilerRefusesAnotherOrSeveralFilers`, `TestCheckSingleFilerFailsClosed`, `TestCheckSingleFilerFavourableThenStalledRefuses`, `TestIsTargetComparesScopedAddresses`, `TestCheckSingleFilerPasses` (`core/frontend/chunkstore/single_filer_test.go`), `TestChunkWiringRefusesAMultiFilerGroup` (`cmd/blockvolume/single_filer_test.go`), `TestOpsChunk_WritingCommandsRunTheSingleFilerCheck` (`cmd/sw-block/chunk_start_check_test.go`), `TestOpsChunk_VerifyRunsTheSingleFilerCheck` (`cmd/sw-block/chunk_verify_test.go`) | — | ACTIVE |
|
||||
| `INV-WS-LEASE-REGRANT-001` | Re-grant after expiry: same holder and epoch only, no move pending or issued, not revoking, store certain, one durable write, and only once max(horizon, deadline) + skew bound has passed; the new process claims HEAD with a new generation before any I/O, so no older incarnation writes or CASes after. | M2 lease: Expired → Granted | `core/authority/workspace_lease_view.go` `regrantWorkspaceLease`; `core/authority/workspace.go` `forcedMoveBarrierLocked`; `core/storage/chunk_restore.go` `ClaimChunkHead` | `TestWorkspaceLeaseExpiredSameHolderRegrantIsDurable`, `TestWorkspaceLeaseRegrantWaitsForFullSkew`, `TestWorkspaceLeaseRegrantDefeatsAlreadyPassedForcedPreflight`, `TestWorkspaceLeaseForcedIssueDefeatsOldHolderRegrant`, `TestWorkspaceLeaseRegrantWaitsForDurabilityAndLatchesFailure` (`core/authority/workspace_regrant_test.go`); `TestWorkspaceLeaseRegrantPreservesLocalLogThroughFirstCut`, `TestWorkspaceLeaseRegrantCannotUnsealSameEpoch`, `TestWorkspaceLeaseRegrantEmptyRootClaimsOnlyHEAD` (`core/authority/workspace_regrant_storage_test.go`) | `WorkspaceRegrant` `NoDualServingInc`, `RegrantNoLoss`, `DiskCoversMemory` | ACTIVE |
|
||||
| `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 |
|
||||
|
||||
@@ -17,7 +17,9 @@ the assignment. Blockvolume closes frontend admission, drains and closes the
|
||||
frontend, replication, and provider, reads the stored detached HEAD, and only
|
||||
then ACKs its exact generation. The authority refuses an expired lease's ACK.
|
||||
Revocation does not perform a final cut. Lease expiry or cancellation closes
|
||||
the host without a CLEAN ACK or cut; recovery uses a FORCED move.
|
||||
the host without a CLEAN ACK or cut. A new process of the unchanged holder
|
||||
and epoch may return through a durable re-grant as described below; a move
|
||||
to a different holder still requires the move protocol.
|
||||
|
||||
The shared projection loads the guard atomically. Guard operations serialize
|
||||
renewal, drain, and ACK with the operation mutex; the state mutex is held only
|
||||
@@ -72,6 +74,27 @@ 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.
|
||||
|
||||
|
||||
## Returning after an expired lease
|
||||
|
||||
Restarting the same holder at the same epoch can retain its acknowledged
|
||||
local WAL after a long outage. Re-grant waits for the existing forced-move
|
||||
barrier: both the durable horizon and the granted or conservative restart
|
||||
deadline, each plus the full configured/persisted skew bound, must have
|
||||
passed. The master then persists one new horizon before returning the grant;
|
||||
neither horizon nor skew is reduced. Immediate repeated renewals use memory,
|
||||
so they do not add durable re-grant writes while that grant is live.
|
||||
|
||||
The authority record must still name this holder and epoch. A pending move,
|
||||
revocation/ACK or uncertain store prevents a usable re-grant. Re-grant and
|
||||
forced issue serialize; whichever commits first makes the other refuse.
|
||||
If an authority writer holds the lock, this renewal attempt refuses
|
||||
immediately; a returning process may retry after the writer settles.
|
||||
An already fenced guard never reopens: start a new process, which claims a
|
||||
new HEAD generation before serving and retains its local WAL. Its first cut
|
||||
covers those acknowledged bytes. If the local root is absent, recovery
|
||||
restores only the sealed/published HEAD image and never claims missing local
|
||||
bytes. A same-epoch detached HEAD stays detached even after a lease re-grant.
|
||||
|
||||
## Planned return on the same host
|
||||
|
||||
After plain detach seals HEAD and revocation records its exact generation,
|
||||
|
||||
Reference in new issue
Block a user