fix: one owner for the startup bound; a failing granted attach is bounded

The host owns the startup wait's one bound: it keeps the wait's start and
opens the window at the first reply at or after it; the run of replies
(and the window) ends on a transport, credentials or identity refusal;
/status shows the same bound. The provider asks the host for the bound
given its own start, and checks it on the attach retry path too: a
granted attach that keeps failing no longer holds the lease for ever
without serving. An identity refusal ends on an accepted identity-checked
call (the run of replies restarts there) or after 30 s of replies with no
new identity refusal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-11-24 00:52:11 -08:00
1 parent e04178d67b
commit 2a80101273
11 files changed
+341 -105

No files matched your search

+3 -3
View File
@@ -701,9 +701,9 @@ func runVolume(f flags, exits *processExit) int {
// reply; it ends 30 s after the first reply received after the
// local open and recovery (or the master's barrier time), or at
// once on a moved/deleted refusal.
cfg.ChunkMasterWait = func() durable.MasterContact {
streak, last, barrier, final := h.MasterWaitContact()
return durable.MasterContact{StreakStart: streak, LastReply: last, Barrier: barrier, Final: final != ""}
cfg.ChunkMasterWait = func(start time.Time) (time.Time, bool) {
deadline, final := h.MasterWaitBound(start)
return deadline, final != ""
}
}
if chunk.catalog != nil && f.chunk.snapshotSchedule.period > 0 {
@@ -24,6 +24,9 @@ type exitAssignmentStream struct {
control.UnimplementedWorkspaceServiceServer
revoke bool
refuse error // when set, every renewal is refused with it
// identityRefusals: the first this many stream calls are refused with
// the typed IDENTITY detail.
identityRefusals atomic.Int32
ackError error
acks atomic.Int32
facts chan *control.AssignmentFact
@@ -46,6 +49,11 @@ func (s *exitAssignmentStream) ReportHeartbeat(context.Context, *control.Heartbe
return &control.HeartbeatAck{}, nil
}
func (s *exitAssignmentStream) SubscribeAssignments(_ *control.SubscribeRequest, stream control.AssignmentService_SubscribeAssignmentsServer) error {
if s.identityRefusals.Add(-1) >= 0 {
st, _ := status.New(codes.FailedPrecondition, `assignment stream: server id "s" is not registered`).
WithDetails(&control.WorkspaceLeaseRefusal{Kind: control.WorkspaceLeaseRefusal_IDENTITY, Identity: "unregistered"})
return st.Err()
}
for {
select {
case <-stream.Context().Done():
@@ -565,3 +573,31 @@ func TestChunkStartupExitFinalGives78(t *testing.T) {
})
}
}
// An identity refusal on the assignment stream ends when the stream (which
// checks the holder's identity) delivers an assignment after the
// registration is fixed, not 30 s later by decay.
func TestIdentityRefusalEndsOnADeliveredAssignment(t *testing.T) {
h, assign := exitAuthorityHost(t, func(s *exitAssignmentStream) { s.identityRefusals.Store(1) })
deadline := time.Now().Add(10 * time.Second)
for {
if w := h.MasterWaitStatus(); w != nil && w.Reason == "identity refused: unregistered" {
break
}
if time.Now().After(deadline) {
t.Fatalf("the stream's identity refusal never showed: %+v", h.MasterWaitStatus())
}
time.Sleep(10 * time.Millisecond)
}
assign("r", 1) // the next stream is accepted and delivers
deadline = time.Now().Add(5 * time.Second)
for {
if w := h.MasterWaitStatus(); w == nil || w.Reason != "identity refused: unregistered" {
return
}
if time.Now().After(deadline) {
t.Fatal("a delivered assignment did not end the identity refusal")
}
time.Sleep(10 * time.Millisecond)
}
}
@@ -117,9 +117,11 @@ type ProviderConfig struct {
ChunkAssignmentTimeout time.Duration
// ChunkMasterWait, when set, replaces ChunkAssignmentTimeout's fixed
// deadline (a workspace primary) with the host's observed contact with
// the master. It is read on the wait's poll and must not block.
ChunkMasterWait func() MasterContact
// deadline (a workspace primary): given the wait's start, the host
// returns the wait's one bound (zero: none, the master gives no reply or
// refuses the node) and whether a permanent refusal (moved or deleted)
// ends it now. It is read on the wait's poll and must not block.
ChunkMasterWait func(start time.Time) (deadline time.Time, final bool)
// WALRetentionLSNs is the operator-tunable retention window past
// the substrate's checkpoint LSN (G6 §1.A α). Zero = pre-G6
@@ -1205,13 +1207,3 @@ func chunkSidecars(path string) ([]string, error) {
// Compile-time check.
var _ frontend.Provider = (*DurableProvider)(nil)
// MasterContact is the volume host's view of its calls to blockmaster, for
// the startup authority wait. StreakStart is the first reply of the current
// run of replies (zero while the master gives no reply, or refuses the
// node's credentials or identity: the wait then has no bound); LastReply is
// the latest reply; Barrier is the master's barrier time from its latest
// BARRIER refusal; Final is a permanent refusal (moved or deleted).
type MasterContact struct {
StreakStart, LastReply, Barrier time.Time
Final bool
}
@@ -182,38 +182,15 @@ func (p *DurableProvider) chunkAuthorityWait(volumeID string, h *volHandle, gen
waitCtx, endWait = context.WithCancel(p.closeCtx)
}
defer endWait()
// gaveUp: a permanent refusal, or limit has passed since the window
// opened. The window opens at the first reply from the master received
// after this wait started (local open and recovery count toward
// nothing), or at a later streak's start, and runs from the master's
// barrier time when that is later. No reply: no bound.
var window time.Time
// gaveUp: a permanent refusal, or the host's one bound for this wait has
// passed (the window opens at the first reply after this wait started;
// none while the master gives no reply or refuses the node).
gaveUp := func() bool {
if p.cfg.ChunkMasterWait == nil {
return false
}
c := p.cfg.ChunkMasterWait()
if c.Final {
return true
}
if c.StreakStart.IsZero() {
return false
}
if window.IsZero() || c.StreakStart.After(window) {
switch {
case !c.StreakStart.Before(start):
window = c.StreakStart
case !c.LastReply.Before(start):
window = c.LastReply
default:
return false // no reply since this wait started
}
}
from := window
if c.Barrier.After(from) {
from = c.Barrier
}
return !time.Now().Before(from.Add(limit))
deadline, final := p.cfg.ChunkMasterWait(start)
return final || (!deadline.IsZero() && !time.Now().Before(deadline))
}
defer func() {
if retained || !(expired || errors.Is(waitCtx.Err(), context.DeadlineExceeded)) {
@@ -318,6 +295,12 @@ func (p *DurableProvider) chunkAuthorityWait(volumeID string, h *volHandle, gen
continue
}
log.Printf("durable: chunk layer attach for volume=%s: %v (retrying)", volumeID, err)
// A granted attach that keeps failing stays inside the bound: it
// must not hold the lease while never serving.
if gaveUp() {
expired, ended = true, "master wait ended while the attach kept failing"
return
}
select {
case <-waitCtx.Done():
ended = "provider closed during the retry backoff"
@@ -2,6 +2,7 @@ package durable_test
import (
"context"
"errors"
"sync/atomic"
"testing"
"time"
@@ -28,11 +29,11 @@ func TestChunkAuthorityWaitFollowsTheMasterWait(t *testing.T) {
p, err := durable.NewDurableProvider(durable.ProviderConfig{
Impl: durable.ImplWALStoreChunk, StorageRoot: t.TempDir(), NumBlocks: 64,
BlockSize: 4096, ChunkBlocks: 4, ChunkAssignmentTimeout: time.Millisecond,
ChunkMasterWait: func() durable.MasterContact {
ChunkMasterWait: func(time.Time) (time.Time, bool) {
if b := bound.Load(); b != 0 {
return durable.MasterContact{StreakStart: time.Unix(0, b), LastReply: time.Unix(0, b), Final: final.Load()}
return time.Unix(0, b), final.Load()
}
return durable.MasterContact{Final: final.Load()}
return time.Time{}, final.Load()
},
ChunkRemoteFor: func(string) (storage.ChunkRemote, error) {
t.Error("remote reached without authority")
@@ -58,7 +59,7 @@ func TestChunkAuthorityWaitFollowsTheMasterWait(t *testing.T) {
if tc.final {
final.Store(true)
} else {
bound.Store(time.Now().UnixNano()) // the master answers now: the window opens
bound.Store(time.Now().Add(200 * time.Millisecond).UnixNano())
}
waitLog(t, logs, "assignment unavailable, not serving")
if gen, failed := outcomes.ChunkStartupOutcome("v1"); !failed || gen != 1 {
@@ -68,29 +69,65 @@ func TestChunkAuthorityWaitFollowsTheMasterWait(t *testing.T) {
}
}
// A slow open: the first answer from the master came long before the
// authority wait started, so the host's bound (contact + 30 s) is already in
// the past. The wait still gets its full limit from its own start (it cannot
// have learned the barrier time before the lease guard ran), or the start
// exits 75 every time and the unit loops to its start limit.
func TestChunkAuthorityWaitAfterASlowOpenGetsItsFullLimit(t *testing.T) {
// The provider hands the host the wait's own start, taken after the local
// open and recovery, so the host's window (the first reply at or after it)
// never counts the local work (the window rule itself:
// TestChunkAuthorityWaitAfterASlowOpenGetsItsFullLimit in core/host/volume).
func TestChunkAuthorityWaitPassesItsOwnStart(t *testing.T) {
v := &arrivingAssignment{seen: make(chan struct{}), assigned: make(chan struct{})}
var starts atomic.Int64
p, err := durable.NewDurableProvider(durable.ProviderConfig{
Impl: durable.ImplWALStoreChunk, StorageRoot: t.TempDir(), NumBlocks: 64,
BlockSize: 4096, ChunkBlocks: 4,
ChunkMasterWait: func(start time.Time) (time.Time, bool) {
starts.Store(start.UnixNano())
return time.Time{}, false
},
ChunkRemoteFor: func(string) (storage.ChunkRemote, error) { return storage.NewMemChunkRemote(), nil },
}, v)
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { _ = p.Close() })
if _, err := p.EnsureStorage("v1"); err != nil {
t.Fatal(err)
}
v.active.Store(true)
before := time.Now()
if _, err := p.RecoverVolume(context.Background(), "v1"); err != nil {
t.Fatal(err)
}
deadline := time.Now().Add(5 * time.Second)
for starts.Load() == 0 {
if time.Now().After(deadline) {
t.Fatal("the wait never asked the host")
}
time.Sleep(5 * time.Millisecond)
}
if s := time.Unix(0, starts.Load()); s.Before(before) {
t.Fatalf("start %v is before the recovery began (%v); want the wait's own start", s, before)
}
}
// A granted attach that keeps failing (the chunk store unreachable) stays
// inside the bound: the wait ends at it instead of retrying for ever while
// the lease is held and nothing serves (D1).
func TestChunkGrantedAttachThatKeepsFailingIsBounded(t *testing.T) {
logs := &lockedLog{}
captureWriteLogs(t, logs)
v := &arrivingAssignment{seen: make(chan struct{}), assigned: make(chan struct{})}
const limit = 400 * time.Millisecond
// The first reply came an hour before the wait started (a slow open and
// recovery); the master keeps answering. The window opens at the first
// reply received after the wait started, so the wait gets its full limit.
streak := time.Now().Add(-time.Hour)
var bound atomic.Int64
p, err := durable.NewDurableProvider(durable.ProviderConfig{
Impl: durable.ImplWALStoreChunk, StorageRoot: t.TempDir(), NumBlocks: 64,
BlockSize: 4096, ChunkBlocks: 4, ChunkAssignmentTimeout: limit,
ChunkMasterWait: func() durable.MasterContact {
return durable.MasterContact{StreakStart: streak, LastReply: time.Now()}
BlockSize: 4096, ChunkBlocks: 4,
ChunkMasterWait: func(time.Time) (time.Time, bool) {
if b := bound.Load(); b != 0 {
return time.Unix(0, b), false
}
return time.Time{}, false
},
ChunkRemoteFor: func(string) (storage.ChunkRemote, error) {
t.Error("remote reached without authority")
return storage.NewMemChunkRemote(), nil
return nil, errors.New("chunk store unreachable")
},
}, v)
if err != nil {
@@ -101,17 +138,58 @@ func TestChunkAuthorityWaitAfterASlowOpenGetsItsFullLimit(t *testing.T) {
t.Fatal(err)
}
v.active.Store(true)
started := time.Now()
if _, err := p.RecoverVolume(context.Background(), "v1"); err != nil {
t.Fatal(err)
}
outcomes := any(p).(interface{ ChunkStartupOutcome(string) (uint64, bool) })
time.Sleep(limit / 2)
if _, failed := outcomes.ChunkStartupOutcome("v1"); failed {
t.Fatalf("the wait ended %v after it started, on a bound that passed before it began", time.Since(started).Round(time.Millisecond))
}
<-v.seen
bound.Store(time.Now().Add(300 * time.Millisecond).UnixNano())
close(v.assigned) // granted: every attach attempt fails
waitLog(t, logs, "assignment unavailable, not serving")
if took := time.Since(started); took < limit {
t.Fatalf("the wait ended after %v; want at least its limit %v from its start", took, limit)
outcomes := any(p).(interface{ ChunkStartupOutcome(string) (uint64, bool) })
if _, failed := outcomes.ChunkStartupOutcome("v1"); !failed {
t.Fatal("the bounded wait ended without a startup outcome")
}
}
// A grant that arrives on the same poll as the end of the wait attaches: the
// wait checks the projection's authority before it asks whether to give up.
func TestChunkAuthorityWaitAttachesAGrantOnTheBoundsTick(t *testing.T) {
v := &arrivingAssignment{seen: make(chan struct{}), assigned: make(chan struct{})}
var ended atomic.Bool // the master wait reports its end together with the grant
p, err := durable.NewDurableProvider(durable.ProviderConfig{
Impl: durable.ImplWALStoreChunk, StorageRoot: t.TempDir(), NumBlocks: 64,
BlockSize: 4096, ChunkBlocks: 4, ChunkAssignmentTimeout: time.Millisecond,
ChunkMasterWait: func(time.Time) (time.Time, bool) {
return time.Time{}, ended.Load()
},
ChunkRemoteFor: func(string) (storage.ChunkRemote, error) { return storage.NewMemChunkRemote(), nil },
}, v)
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { _ = p.Close() })
if _, err := p.EnsureStorage("v1"); err != nil {
t.Fatal(err)
}
v.active.Store(true)
if _, err := p.RecoverVolume(context.Background(), "v1"); err != nil {
t.Fatal(err)
}
<-v.seen
ended.Store(true)
close(v.assigned) // the grant and the end of the wait, visible on the same poll
outcomes := any(p).(interface{ ChunkStartupOutcome(string) (uint64, bool) })
deadline := time.Now().Add(10 * time.Second)
for {
if st := p.DurableStatuses(); len(st) == 1 && st[0].Operational {
break
}
if _, failed := outcomes.ChunkStartupOutcome("v1"); failed {
t.Fatal("the wait gave up although the grant was there on the same poll")
}
if time.Now().After(deadline) {
t.Fatal("never attached")
}
time.Sleep(time.Millisecond)
}
}
+85 -27
View File
@@ -42,7 +42,10 @@ type masterWait struct {
down time.Time // first failure without a reply since the last contact
creds time.Time // first credentials refusal since the last accepted call
ident time.Time // first identity refusal since the last accepted call
identAt time.Time // the latest identity refusal
identOf string // its kind: unregistered or wrong_host
start time.Time // when the startup wait began (after the local open); zero before
window time.Time // the first reply at or after start in the current run of replies
barrier time.Time // T: request start + retry_after of the latest BARRIER refusal
final string // "moved" or "deleted": a permanent refusal
logged string // the reason last logged
@@ -84,8 +87,11 @@ func masterCallClass(err error) (contact, credentials bool) {
// IDENTITY detail: this server id is not registered, or calls from another
// host) is not contact: like refused credentials it has no bound, because a
// restart cannot fix a registration. It lasts until an identity-checked call
// (a lease renewal, an assignment delivered) is accepted: the heartbeat does
// not check identity, so its answers do not end it.
// (a lease renewal, an assignment delivered) is accepted, or until
// identityDecay passes with replies and no new identity refusal (the
// refused stream retries within seconds; a fixed registration may bring no
// assignment to accept). The heartbeat does not check identity, so its
// answers alone do not end it sooner.
func (w *masterWait) call(err error) {
contact, credentials := masterCallClass(err)
identity := ""
@@ -96,40 +102,75 @@ func (w *masterWait) call(err error) {
}
}
w.mu.Lock()
defer w.mu.Unlock()
now := w.now()
switch {
case identity != "":
w.endStreakLocked()
w.down, w.creds = time.Time{}, time.Time{}
if w.ident.IsZero() {
w.ident = now
}
w.identOf = identity
w.identAt, w.identOf = now, identity
case contact:
if w.contact.IsZero() {
w.contact = now
if !w.ident.IsZero() {
if now.Sub(w.identAt) < identityDecay {
return // still refused: a heartbeat answer does not end it
}
w.ident, w.identOf = time.Time{}, ""
}
w.last = now
w.replyLocked(now)
w.down, w.creds = time.Time{}, time.Time{}
case credentials:
w.contact, w.down, w.ident = time.Time{}, time.Time{}, time.Time{}
w.endStreakLocked()
w.down, w.ident = time.Time{}, time.Time{}
if w.creds.IsZero() {
w.creds = now
}
default:
w.contact, w.creds, w.ident = time.Time{}, time.Time{}, time.Time{}
w.endStreakLocked()
w.creds, w.ident = time.Time{}, time.Time{}
if w.down.IsZero() {
w.down = now
}
}
w.mu.Unlock()
}
// identityDecay ends an identity refusal that is not repeated: replies keep
// coming and no call was refused on identity for this long.
const identityDecay = 30 * time.Second
// replyLocked records an accepted reply at now: it starts a run of replies
// when none is running, and opens the wait's window at the first reply at
// or after the wait's start. Caller holds mu.
func (w *masterWait) replyLocked(now time.Time) {
if w.contact.IsZero() {
w.contact = now
}
w.last = now
if w.window.IsZero() && !w.start.IsZero() && !now.Before(w.start) {
w.window = now
}
}
// endStreakLocked ends the run of replies: the window closes with it, and the
// next reply opens a new one. Caller holds mu.
func (w *masterWait) endStreakLocked() {
w.contact, w.window = time.Time{}, time.Time{}
}
// identityAccepted ends an identity refusal: an identity-checked call (a
// lease renewal, an assignment delivered) was accepted.
// lease renewal, an assignment delivered) was accepted. The run of replies
// starts again there, as after any refusal that had no bound.
func (w *masterWait) identityAccepted() {
w.mu.Lock()
defer w.mu.Unlock()
if w.ident.IsZero() {
return
}
w.ident, w.identOf = time.Time{}, ""
w.mu.Unlock()
w.endStreakLocked()
w.replyLocked(w.now())
}
// renewal records a lease renewal started at start: the call itself, and
@@ -172,19 +213,37 @@ func leaseRefusalDetail(err error) *control.WorkspaceLeaseRefusal {
return nil
}
// deadlineLocked is max(contact streak start, barrier T) + MasterWaitLimit,
// or zero while there is no contact (no bound). Caller holds mu.
// deadlineLocked is the one bound of the startup wait: max(the window, the
// master's barrier time) + MasterWaitLimit, where the window is the first
// reply at or after the wait's start (local open and recovery count toward
// nothing). Zero (no bound) before the wait starts, while there is no window
// yet (no reply since the start, or the master gives no reply), and while
// the node's credentials or identity are refused. Caller holds mu.
func (w *masterWait) deadlineLocked() time.Time {
if w.contact.IsZero() || !w.ident.IsZero() {
if w.window.IsZero() || !w.ident.IsZero() || !w.creds.IsZero() {
return time.Time{}
}
from := w.contact
from := w.window
if w.barrier.After(from) {
from = w.barrier
}
return from.Add(MasterWaitLimit)
}
// begin records the startup wait's start (the latest wait's, for a later
// recovery): the window opens at the first reply at or after it.
func (w *masterWait) begin(start time.Time) {
w.mu.Lock()
defer w.mu.Unlock()
if start.Equal(w.start) {
return
}
w.start, w.window = start, time.Time{}
if !w.contact.IsZero() && !w.contact.Before(start) {
w.window = w.contact
}
}
// state returns the startup wait's bound (zero: none) and a permanent
// refusal ("" when none).
func (w *masterWait) state() (time.Time, string) {
@@ -213,6 +272,11 @@ func (w *masterWait) snapshot(assigned bool) MasterWait {
}
case w.barrier.After(now):
out = MasterWait{Reason: "barrier", Since: w.contact, Until: w.barrier}
case w.window.IsZero():
out = MasterWait{Reason: "no_assignment", Since: w.contact}
if assigned {
out.Reason = "refused"
}
case !assigned:
out = MasterWait{Reason: "no_assignment", Since: w.contact, Until: w.deadlineLocked()}
default:
@@ -260,16 +324,10 @@ func (w *masterWait) barrierTime() time.Time {
return w.barrier
}
// MasterWaitContact is the startup wait's input: the first reply of the
// current run of replies (zero while the master gives no reply or refuses
// the node's credentials or identity), the latest reply, the master's
// barrier time, and a permanent refusal ("moved" or "deleted"; "" if none).
func (h *Host) MasterWaitContact() (streakStart, lastReply, barrier time.Time, final string) {
w := h.mw
w.mu.Lock()
defer w.mu.Unlock()
if !w.ident.IsZero() {
return time.Time{}, w.last, w.barrier, w.final // no bound while identity is refused
}
return w.contact, w.last, w.barrier, w.final
// MasterWaitBound is the startup wait's one bound for a wait that started at
// start (zero: no bound) and a permanent refusal of the lease ("moved" or
// "deleted"; "" when none). /status shows the same bound.
func (h *Host) MasterWaitBound(start time.Time) (time.Time, string) {
h.mw.begin(start)
return h.mw.state()
}
@@ -35,6 +35,7 @@ func refusalWith(t *testing.T, text string, kind control.WorkspaceLeaseRefusal_K
func TestChunkAuthorityWaitStartsAtFirstContact(t *testing.T) {
now := time.Unix(1_800_000_000, 0)
w := newMasterWait(func() time.Time { return now }, func(string, ...any) {})
w.begin(now) // the wait starts (after the local open and recovery)
unreachable := status.Error(codes.Unavailable, "connection refused")
w.call(unreachable)
@@ -317,3 +318,74 @@ func TestIdentityRefusalWaitsVisibly(t *testing.T) {
t.Fatalf("status %+v after an accepted call; want the identity wait over", s)
}
}
// The window opens at the first reply received at or after the wait's start:
// a run of replies that began during a slow local open and recovery does not
// spend it (claude's red case: recovery slower than 30 s after first contact).
func TestChunkAuthorityWaitAfterASlowOpenGetsItsFullLimit(t *testing.T) {
now := time.Unix(1_800_000_000, 0)
w := newMasterWait(func() time.Time { return now }, func(string, ...any) {})
for i := 0; i < 30; i++ { // heartbeats answered for 60 s while the store opens
w.call(nil)
now = now.Add(2 * time.Second)
}
start := now // open and recovery done: the wait starts
w.begin(start)
if d, _ := w.state(); !d.IsZero() {
t.Fatalf("bound %v before any reply since the wait started; want none", d)
}
now = now.Add(1500 * time.Millisecond)
first := now
w.call(nil)
if d, _ := w.state(); !d.Equal(first.Add(MasterWaitLimit)) {
t.Fatalf("bound %v; want the first reply after the start + 30 s (%v)", d, first.Add(MasterWaitLimit))
}
w.renewal(now, refusalWith(t, "barrier", control.WorkspaceLeaseRefusal_BARRIER, 45*time.Second))
if d, _ := w.state(); !d.Equal(now.Add(45*time.Second + MasterWaitLimit)) {
t.Fatalf("bound %v; want T + 30 s", d)
}
}
// An identity refusal ends the run of replies (no bound, no window kept); an
// accepted identity-checked call starts a new one there (the window opens
// again), so a corrected registration gets a full 30 s (L1, a). A refusal
// that is not repeated for identityDecay while replies continue ends by
// itself, so a fixed registration with no assignment still reaches the
// bound (b).
func TestIdentityRefusalEndsAndDecays(t *testing.T) {
now := time.Unix(1_800_000_000, 0)
refused, err := status.New(codes.FailedPrecondition, "assignment stream: server id is not registered").
WithDetails(&control.WorkspaceLeaseRefusal{Kind: control.WorkspaceLeaseRefusal_IDENTITY, Identity: "unregistered"})
if err != nil {
t.Fatal(err)
}
w := newMasterWait(func() time.Time { return now }, func(string, ...any) {})
w.begin(now)
w.call(nil) // window opens
now = now.Add(10 * time.Second)
w.call(refused.Err())
if d, _ := w.state(); !d.IsZero() {
t.Fatalf("bound %v under an identity refusal; want none", d)
}
now = now.Add(10 * time.Minute)
w.identityAccepted() // a delivered assignment: registered now
if d, _ := w.state(); !d.Equal(now.Add(MasterWaitLimit)) {
t.Fatalf("bound %v after the identity was accepted; want a new window there + 30 s (%v)", d, now.Add(MasterWaitLimit))
}
w2 := newMasterWait(func() time.Time { return now }, func(string, ...any) {})
w2.begin(now)
w2.call(refused.Err())
for i := 0; i < 14; i++ { // 28 s of heartbeat answers: still refused
now = now.Add(2 * time.Second)
w2.call(nil)
}
if s := w2.snapshot(false); s.Reason != "identity refused: unregistered" {
t.Fatalf("status %+v at 28 s; want the identity refusal", s)
}
now = now.Add(4 * time.Second)
w2.call(nil) // 32 s without a new identity refusal: it decays
if s := w2.snapshot(false); s.Reason != "no_assignment" || s.Until.IsZero() {
t.Fatalf("status %+v after the decay; want no_assignment with the 30 s bound", s)
}
}
@@ -221,9 +221,10 @@ type StatusProjection struct {
Warnings []string `json:",omitempty"`
// MasterWait is why a workspace primary holds no granted lease, present
// only while NotReadyReason is lease_not_held: Reason (unreachable,
// credentials, barrier, no_assignment, refused, moved, deleted), since
// when, and the wait's bound or the master's barrier time (UntilMs,
// absent while there is no bound).
// credentials, "identity refused: <kind>" with kind unregistered or
// wrong_host, barrier, no_assignment, refused, moved, deleted), since
// when, and the startup wait's one bound or the master's barrier time
// (UntilMs, absent while there is no bound).
MasterWait *MasterWaitStatus `json:",omitempty"`
}
+2 -2
View File
@@ -775,10 +775,10 @@ Notes:
| `INV-WS-FORCED-CONFIRM-HOLDER-001` | A confirmation at an epoch the master reports no holder for, in its lease or its move journal, is refused without sending a move. | M2 lease: Expired → Moved (forced) (the explicit-force guard) | `core/rpc/wsclient/wsclient.go` `holderAt`, `request` | `TestForceMoveResolvesTheHolder` (`core/rpc/wsclient/wsclient_test.go`) | — | ACTIVE |
| `INV-WS-FORCED-CONFIRM-NO-BYPASS-001` | No force-move flag bypasses the confirmation, and `--dry-run` is never a confirmation: it sends only a preview, which needs the same confirmation. | M2 lease: Expired → Moved (forced) (the explicit-force guard) | `cmd/sw-block/workspace.go` `runWorkspaceForceMove`, `workspacePreview`; `core/rpc/wsclient/wsclient.go` `PreviewForcedMove` | `TestWorkspaceForceMove_Row2_DryRunPreview`, `TestWorkspaceHelpText` (`cmd/sw-block/workspace_test.go`) | — | ACTIVE |
| `INV-WS-STARTUP-RETRY-001` | A workspace primary exits 75 on assignment timeout or lease expiry after bounded cleanup. A master fact newer than nonzero observed-own, or an exact foreign HEAD at/above the assigned epoch, permits 78. ACK and signal keep normal exit; lease and claim gates never relax. | M2 restart | `cmd/blockvolume/process_exit.go` `superviseProcess`, `workspaceRetryOutcome`; `core/frontend/durable/provider_chunk.go` `claimHeadSupersedes`; `core/frontend/durable/provider_startup.go` `endChunkStartup` | `TestChunkAssignmentTimeoutExposesCurrentRecoveryOutcome` (`core/frontend/durable/provider_startup_outcome_test.go`); `TestChunkStartupOutcomeRejectsOldGenerationAndCoalescesWake` (`core/frontend/durable/provider_startup_internal_test.go`); `TestWorkspaceDisplacedClaimUsesAssignedEpoch`, `TestWorkspaceRetryUsesNewestOwnAssignment`, `TestWorkspaceForeignHeadClaimChoosesNoRetry`, `TestWorkspaceOldLocalHolderForeignHeadChoosesNoRetry` (`cmd/blockvolume/process_exit_authority_test.go`); `TestWorkspaceExitFirstOutcomeIsLatched`, `TestWorkspaceExitDoesNotWaitForBlockedFrontendClose`, `TestWorkspacePlannedStopKeepsSuccess` (`cmd/blockvolume/process_exit_test.go`) | Existing WorkspaceRegrant restart transition; no new grant rule | ACTIVE |
| `INV-WS-MASTER-WAIT-001` | A workspace primary's startup wait has no bound while blockmaster gives no reply or refuses its credentials or identity; it ends 30 s after max(the first reply after the local open and recovery, the master's barrier time), and a typed MOVED or DELETED lease refusal ends it at once with 78. | M2 Awaiting assignment → Process exited | `core/host/volume/master_wait.go` `masterWait` (contact from heartbeat, stream and renewal results; the refusal kind from the status detail only); `core/frontend/durable/provider_chunk.go` `chunkAuthorityWait` (`ChunkMasterWait`); `cmd/blockvolume/process_exit.go` `chooseChunkStartupExit`; `core/host/master/workspace_service.go` `leaseRefusal`, `renewalMoved`; `core/authority/workspace_lease_view.go` `LeaseBarrierError`; `core/host/volume/workspace_lease.go` `renewDelay` (sleeps until just past the barrier time, jittered, at most 2 min; then a 200 ms poll for 5 s); `core/rpc/link/link.go` `MasterReconnect` | `TestChunkAuthorityWaitStartsAtFirstContact`, `TestLeaseGuardSleepsUntilTheBarrier`, `TestStatusShowsTheMasterWait`, `TestCredentialsRefusedForAnHourWaitsAndLogs`, `TestHeartbeatLogsTheMasterWait`, `TestFlappingMasterNeverExpiresEarly` (`core/host/volume/master_wait_test.go`); `TestMasterLinkReconnectsWithinTwoSeconds` (`core/host/volume/master_reconnect_test.go`); `TestChunkAuthorityWaitFollowsTheMasterWait`, `TestChunkAuthorityWaitAfterASlowOpenGetsItsFullLimit` (`core/frontend/durable/provider_master_wait_test.go`); `TestIdentityRefusalWaitsVisibly` (`core/host/volume/master_wait_test.go`); `TestIdentityRefusalIsTyped` (`core/host/master/workspace_lease_refusal_kind_test.go`); `TestLeaseRefusalKinds`, `TestRenewalReplicaMismatchAtOlderLineEpochIsOther` (`core/host/master/workspace_lease_refusal_kind_test.go`); `TestChunkStartupExitFinalGives78` (`cmd/blockvolume/process_exit_authority_test.go`) | — | ACTIVE |
| `INV-WS-MASTER-WAIT-001` | A workspace primary's startup wait has no bound while blockmaster gives no reply or refuses its credentials or identity; it ends 30 s after max(the first reply after the local open and recovery, the master's barrier time), and a typed MOVED or DELETED lease refusal ends it at once with 78. | M2 Awaiting assignment → Process exited | `core/host/volume/master_wait.go` `masterWait` (contact from heartbeat, stream and renewal results; the refusal kind from the status detail only); `core/frontend/durable/provider_chunk.go` `chunkAuthorityWait` (`ChunkMasterWait`); `cmd/blockvolume/process_exit.go` `chooseChunkStartupExit`; `core/host/master/workspace_service.go` `leaseRefusal`, `renewalMoved`; `core/authority/workspace_lease_view.go` `LeaseBarrierError`; `core/host/volume/workspace_lease.go` `renewDelay` (sleeps until just past the barrier time, jittered, at most 2 min; then a 200 ms poll for 5 s); `core/rpc/link/link.go` `MasterReconnect` | `TestChunkAuthorityWaitStartsAtFirstContact`, `TestLeaseGuardSleepsUntilTheBarrier`, `TestStatusShowsTheMasterWait`, `TestCredentialsRefusedForAnHourWaitsAndLogs`, `TestHeartbeatLogsTheMasterWait`, `TestFlappingMasterNeverExpiresEarly` (`core/host/volume/master_wait_test.go`); `TestMasterLinkReconnectsWithinTwoSeconds` (`core/host/volume/master_reconnect_test.go`); `TestChunkAuthorityWaitFollowsTheMasterWait`, `TestChunkAuthorityWaitPassesItsOwnStart`, `TestChunkGrantedAttachThatKeepsFailingIsBounded`, `TestChunkAuthorityWaitAttachesAGrantOnTheBoundsTick` (`core/frontend/durable/provider_master_wait_test.go`); `TestIdentityRefusalWaitsVisibly`, `TestChunkAuthorityWaitAfterASlowOpenGetsItsFullLimit`, `TestIdentityRefusalEndsAndDecays` (`core/host/volume/master_wait_test.go`); `TestIdentityRefusalEndsOnADeliveredAssignment` (`cmd/blockvolume/process_exit_authority_test.go`); `TestIdentityRefusalIsTyped` (`core/host/master/workspace_lease_refusal_kind_test.go`); `TestLeaseRefusalKinds`, `TestRenewalReplicaMismatchAtOlderLineEpochIsOther` (`core/host/master/workspace_lease_refusal_kind_test.go`); `TestChunkStartupExitFinalGives78` (`cmd/blockvolume/process_exit_authority_test.go`) | — | ACTIVE |
- `INV-WS-STARTUP-RETRY-001`: exit 78 is permitted by a NEWER observed master fact for this volume naming another holder (compared with nonzero observed-own assignment; never-assigned zero retries75), or by the exact refused HEAD claim image proving another holder at or above the assigned epoch. The provider binds the latter proof to its recovery generation. Both existing-root checks and claim CAS readback use the same epoch-qualified supersede classifier. A lower-epoch foreign HEAD on an existing root retains the move-back diagnostic; a displaced lower-epoch claim on a fresh root retries 75 without serving. A same-holder higher-epoch HEAD fence retries 75. Unknown/no line, same replica at a higher epoch, and status codes alone mean retry 75. A wrong retry costs a bounded restart loop; a wrong 78 causes an outage until an explicit operator start. Sealed same-epoch recovery remains up for read-only replay after assignment; stale local roots, corrupt WAL and I/O faults retain diagnostic wait. The first chosen outcome wins. Process cleanup reuses `WorkspaceDrainTimeout` (5 s), including a blocked Close; only main exits the process.
- `INV-WS-MASTER-WAIT-001`: every reply produced by blockmaster's handler starts or continues a contact streak; a transport failure (`Unavailable`, `DeadlineExceeded`, `Canceled`) ends it. So a master that answers and drops in turn postpones the 30 s bound for as long as it flaps, also for an obsolete unit; it never ends the wait early (`TestFlappingMasterNeverExpiresEarly`). The barrier time travels as a duration the master computes from the same two predicates as admission, added by the volume to its own monotonic request start; the master re-checks the barrier on every re-grant, so a wrong duration only moves the 75 exit. The status codes alone still mean retry 75 (`INV-WS-STARTUP-RETRY-001`); only the typed `WorkspaceLeaseRefusal` detail (MOVED, DELETED) permits the early 78. Scale: after a master restart every lapsed volume has the same barrier time T and the master grants them one at a time, each grant one store write W under the publisher lock, so the last of N volumes is granted about T + 0.1 s + N x W; a volume whose grant comes 30 s past T exits 75 and is started again, so that starts at N >= 30 s / W. Measured: W p50 1.03 ms, p99 2.33 ms, max 14.5 ms (400 writes of the file authority store on an NVMe ext4 disk, `TestWorkspaceGrantStoreWriteTime`), so 200 volumes about T + 0.6 s and the 30 s point near 12,900 volumes (p99); 20 real volume processes served at most 0.81 s after T (`TestManyVolumesServeTogetherAfterMasterRestart`). The bound holds for that store device: on a device whose flushes stall (an fsync held for seconds), one stalled write puts every waiting volume behind it, so the blockmaster store's device is a deployment premise of serving within 2 s of the barrier.
- `INV-WS-MASTER-WAIT-001`: every reply produced by blockmaster's handler starts or continues a contact streak; a transport failure (`Unavailable`, `DeadlineExceeded`, `Canceled`) ends it. So a master that answers and drops in turn postpones the 30 s bound for as long as it flaps, also for an obsolete unit; it never ends the wait early (`TestFlappingMasterNeverExpiresEarly`). The barrier time travels as a duration the master computes from the same two predicates as admission, added by the volume to its own monotonic request start; the master re-checks the barrier on every re-grant, so a wrong duration only moves the 75 exit. The status codes alone still mean retry 75 (`INV-WS-STARTUP-RETRY-001`); only the typed `WorkspaceLeaseRefusal` detail (MOVED, DELETED) permits the early 78. Scale: after a master restart every lapsed volume has the same barrier time T and the master grants them one at a time, each grant one store write W under the publisher lock, so the last of N volumes is granted about T + 0.1 s + N x W; a volume whose grant comes 30 s past T exits 75 and is started again, so that starts at N >= 30 s / W. Measured: W p50 1.03 ms, p99 2.33 ms, max 14.5 ms (400 writes of the file authority store on an NVMe ext4 disk, `TestWorkspaceGrantStoreWriteTime`), so 200 volumes about T + 0.6 s and the 30 s point near 12,900 volumes (p99); 20 real volume processes served at most 0.81 s after T (`TestManyVolumesServeTogetherAfterMasterRestart`). The bound holds for that store device: on a device whose flushes stall (an fsync held for seconds), one stalled write puts every waiting volume behind it, so the blockmaster store's device is a deployment premise of serving within 2 s of the barrier. A granted process whose attach keeps failing (the chunk store unreachable) retries inside the same bound and then exits 75: it does not hold the lease while never serving. An identity refusal has no bound until an identity-checked call (a renewal, a delivered assignment) is accepted, or until 30 s of replies pass with no new identity refusal; the window then opens again. A serving holder that starts getting identity refusals is outside this row: its lease expires and it fences and exits 75 (`lease_expired`).
- Part T lineage evidence: `recordSelfAssignment` records the newest identity-validated observed-own assignment before local-readiness admission; `EngineProjection` is the adopted-own lineage. Exit compares the former; fencing compares the latter. Both use `IsSuperseded` with explicit lineage; zero lineage selects retry75 and no fence; neither fact grants I/O. `TestWorkspaceExitAndFenceUseNamedLineages`, `TestWorkspaceExitLineageIncludesBlockedOwnAssignment`, and `TestWorkspaceObservedLineageNeverTrailsAdoption` (`core/host/volume/workspace_startup_test.go`) keep the distinction causal.
- Part T evidence scope: `workspaceRetryOutcome` is the one retry/no-retry decision. Startup `chooseChunkStartupExit` supplies the recovery-generation-bound refused-claim HEAD proof; runtime lease-end supplies none. Both combine that input with a foreign master line newer than nonzero observed-own; absent proof means retry 75.
- Part T fence ownership: `Host.FenceWorkspaceLease` uses `WorkspaceLeaseGuard.fenceLocked`, including before runtime publication; the zero-validity terminal guard preserves the first cause through installation and can grant no I/O. No second host fence latch exists. `TestWorkspaceHostFencePublishesOneTerminalCause`, `TestWorkspaceInstalledHostFenceRecordsCause`, `TestWorkspaceFenceBeforeHeldInstallIsTerminal` (`core/host/volume/workspace_terminal_test.go`).
+16
View File
@@ -158,6 +158,8 @@ measured up to 15 s at 32 volumes with the default 3 slots.
- If it comes back after the move, its blockvolume gets no assignment, does not serve, and exits with status 75.
- The example unit starts it again about every 35 s (30 s of waiting, then `RestartSec=5s`), until its start
limit (10 starts in 600 s), and then shows it as failed (`start-limit-hit`).
- A process that was already waiting on its old assignment when the move was issued exits with status 78
(`reason=moved`) instead, and the unit does not start it again.
- Stop and disable that unit on the old host. Run `systemctl reset-failed` only after you have dealt with its
local root ([do not](volume-lifecycle.md#do-not)).
2. Run the forced move to another registered node: `--dry-run` first, then the move. See
@@ -168,6 +170,20 @@ measured up to 15 s at 32 volumes with the default 3 slots.
4. Start `blockvolume` on the new node, then reconnect the guest.
5. Optionally restore an older snapshot into a new volume and verify it with `ops chunk verify --depth data`.
## A volume waiting for blockmaster
A `blockvolume` that cannot get its lease from blockmaster waits inside its process: the unit stays **active**
and the volume does not serve. A monitor that only watches for failed units does not see it.
- `/status` shows `NotReadyReason=lease_not_held` and `MasterWait` with `Reason`, `SinceMs` and, when the wait has a
bound, `UntilMs`; the process logs `blockvolume: waiting for the master: <reason> ...` when the reason changes and
every 10 minutes.
- Alert when the reason is `unreachable`, `credentials` or `identity refused: ...` for more than 60 s, and on any
reason for more than 5 minutes.
- `identity refused: unregistered` or `wrong_host`: blockmaster does not know the unit's `--server-id`, or the
node calls from another address than the one registered for it in the cluster spec. The check compares the
address exactly: an address change, another outgoing interface, IPv4 against IPv6, or a host name in the cluster
spec all refuse the right host. Fix the cluster spec or the unit; the next call passes without a restart.
## Limits
- **One filer per chunk store.** It is a single point of availability for cuts, snapshots and moves.
+1 -1
View File
@@ -37,7 +37,7 @@ The volume's authority and health projection. Go type `volume.StatusProjection`.
| `CatchUp.ElapsedMs` | int64 | ElapsedMs is the time since this replica was admitted as a supporting replica at its current epoch. |
| `CatchUp.LagLSN` | uint64 | LagLSN is the engine's H-R (primary head minus this replica's durable frontier) as last observed; 0 when unknown or caught up. |
| `Warnings[]` | string | Warnings include routing disagreements and typed recovery warnings (e.g. wal_hole_suspected, issue #51). Visible, not an alert: they do not change Healthy or the frontend's readiness. (omitted when empty) |
| `MasterWait` | object | MasterWait is why a workspace primary holds no granted lease, present only while NotReadyReason is lease_not_held: Reason (unreachable, credentials, barrier, no_assignment, refused, moved, deleted), since when, and the wait's bound or the master's barrier time (UntilMs, absent while there is no bound). (omitted when empty) |
| `MasterWait` | object | MasterWait is why a workspace primary holds no granted lease, present only while NotReadyReason is lease_not_held: Reason (unreachable, credentials, "identity refused: <kind>" with kind unregistered or wrong_host, barrier, no_assignment, refused, moved, deleted), since when, and the startup wait's one bound or the master's barrier time (UntilMs, absent while there is no bound). (omitted when empty) |
| `MasterWait.Reason` | string | — |
| `MasterWait.SinceMs` | int64 | — |
| `MasterWait.UntilMs` | int64 | — (omitted when empty) |