mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
fix: the startup window opens at the first reply after the local open
The 30 s window opens at the first reply from blockmaster received after the store is opened and recovered (or at a later streak's start), and runs from the master's barrier time when that is later; local open and recovery count toward nothing. The host hands the provider its contact facts (streak start, latest reply, barrier time, final refusal). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
199b13b254
commit
04c07de5ac
5 files changed
+67
-27
No files matched your search
@@ -698,11 +698,12 @@ func runVolume(f flags, exits *processExit) int {
|
||||
cfg.ChunkMaintenance = chunk.maintenance
|
||||
if f.workspaceLease {
|
||||
// The startup wait does not run out while the master gives no
|
||||
// reply; it ends 30 s after answered contact (or the master's
|
||||
// barrier), or at once on a moved/deleted refusal.
|
||||
cfg.ChunkMasterWait = func() (time.Time, bool) {
|
||||
deadline, final := h.MasterWaitState()
|
||||
return deadline, final != ""
|
||||
// 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 != ""}
|
||||
}
|
||||
}
|
||||
if chunk.catalog != nil && f.chunk.snapshotSchedule.period > 0 {
|
||||
|
||||
@@ -117,11 +117,9 @@ type ProviderConfig struct {
|
||||
ChunkAssignmentTimeout time.Duration
|
||||
|
||||
// ChunkMasterWait, when set, replaces ChunkAssignmentTimeout's fixed
|
||||
// deadline (a workspace primary): it returns the wait's bound (zero: no
|
||||
// bound, the master gives no reply) and whether a permanent refusal
|
||||
// (moved or deleted) ends the wait now. It is read on the wait's poll
|
||||
// and must not block.
|
||||
ChunkMasterWait func() (deadline time.Time, final bool)
|
||||
// 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
|
||||
|
||||
// WALRetentionLSNs is the operator-tunable retention window past
|
||||
// the substrate's checkpoint LSN (G6 §1.A α). Zero = pre-G6
|
||||
@@ -1206,3 +1204,14 @@ 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,26 +182,38 @@ func (p *DurableProvider) chunkAuthorityWait(volumeID string, h *volHandle, gen
|
||||
waitCtx, endWait = context.WithCancel(p.closeCtx)
|
||||
}
|
||||
defer endWait()
|
||||
// gaveUp: a permanent refusal, or the host's bound passed. The bound
|
||||
// counts from max(contact, the barrier time) on the host, but never
|
||||
// ends before limit from this wait's own start: the lease guard, the
|
||||
// only source of the barrier time, starts after the local open and
|
||||
// recovery, so a slow open must not find the bound already spent.
|
||||
// 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 := func() bool {
|
||||
if p.cfg.ChunkMasterWait == nil {
|
||||
return false
|
||||
}
|
||||
deadline, final := p.cfg.ChunkMasterWait()
|
||||
if final {
|
||||
c := p.cfg.ChunkMasterWait()
|
||||
if c.Final {
|
||||
return true
|
||||
}
|
||||
if deadline.IsZero() {
|
||||
if c.StreakStart.IsZero() {
|
||||
return false
|
||||
}
|
||||
if floor := start.Add(limit); deadline.Before(floor) {
|
||||
deadline = floor
|
||||
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
|
||||
}
|
||||
}
|
||||
return !time.Now().Before(deadline)
|
||||
from := window
|
||||
if c.Barrier.After(from) {
|
||||
from = c.Barrier
|
||||
}
|
||||
return !time.Now().Before(from.Add(limit))
|
||||
}
|
||||
defer func() {
|
||||
if retained || !(expired || errors.Is(waitCtx.Err(), context.DeadlineExceeded)) {
|
||||
|
||||
@@ -28,11 +28,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() (time.Time, bool) {
|
||||
ChunkMasterWait: func() durable.MasterContact {
|
||||
if b := bound.Load(); b != 0 {
|
||||
return time.Unix(0, b), final.Load()
|
||||
return durable.MasterContact{StreakStart: time.Unix(0, b), LastReply: time.Unix(0, b), Final: final.Load()}
|
||||
}
|
||||
return time.Time{}, final.Load()
|
||||
return durable.MasterContact{Final: final.Load()}
|
||||
},
|
||||
ChunkRemoteFor: func(string) (storage.ChunkRemote, error) {
|
||||
t.Error("remote reached without authority")
|
||||
@@ -58,7 +58,7 @@ func TestChunkAuthorityWaitFollowsTheMasterWait(t *testing.T) {
|
||||
if tc.final {
|
||||
final.Store(true)
|
||||
} else {
|
||||
bound.Store(time.Now().Add(200 * time.Millisecond).UnixNano())
|
||||
bound.Store(time.Now().UnixNano()) // the master answers now: the window opens
|
||||
}
|
||||
waitLog(t, logs, "assignment unavailable, not serving")
|
||||
if gen, failed := outcomes.ChunkStartupOutcome("v1"); !failed || gen != 1 {
|
||||
@@ -78,11 +78,16 @@ func TestChunkAuthorityWaitAfterASlowOpenGetsItsFullLimit(t *testing.T) {
|
||||
captureWriteLogs(t, logs)
|
||||
v := &arrivingAssignment{seen: make(chan struct{}), assigned: make(chan struct{})}
|
||||
const limit = 400 * time.Millisecond
|
||||
past := time.Now().Add(-time.Hour) // contact + 30 s, long gone
|
||||
// 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)
|
||||
p, err := durable.NewDurableProvider(durable.ProviderConfig{
|
||||
Impl: durable.ImplWALStoreChunk, StorageRoot: t.TempDir(), NumBlocks: 64,
|
||||
BlockSize: 4096, ChunkBlocks: 4, ChunkAssignmentTimeout: limit,
|
||||
ChunkMasterWait: func() (time.Time, bool) { return past, false },
|
||||
ChunkMasterWait: func() durable.MasterContact {
|
||||
return durable.MasterContact{StreakStart: streak, LastReply: time.Now()}
|
||||
},
|
||||
ChunkRemoteFor: func(string) (storage.ChunkRemote, error) {
|
||||
t.Error("remote reached without authority")
|
||||
return storage.NewMemChunkRemote(), nil
|
||||
|
||||
@@ -38,6 +38,7 @@ type masterWait struct {
|
||||
mu sync.Mutex
|
||||
now func() time.Time
|
||||
contact time.Time // start of the current contact streak; zero while none
|
||||
last time.Time // the latest reply
|
||||
down time.Time // first failure without a reply since the last contact
|
||||
creds time.Time // first credentials refusal since the last accepted call
|
||||
barrier time.Time // T: request start + retry_after of the latest BARRIER refusal
|
||||
@@ -87,6 +88,7 @@ func (w *masterWait) call(err error) {
|
||||
if w.contact.IsZero() {
|
||||
w.contact = now
|
||||
}
|
||||
w.last = now
|
||||
w.down, w.creds = time.Time{}, time.Time{}
|
||||
case credentials:
|
||||
w.contact, w.down = time.Time{}, time.Time{}
|
||||
@@ -224,3 +226,14 @@ func (w *masterWait) barrierTime() time.Time {
|
||||
defer w.mu.Unlock()
|
||||
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()
|
||||
return w.contact, w.last, w.barrier, w.final
|
||||
}
|
||||
Reference in new issue
Block a user