mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
fix: retain sealed startup and atomically choose the current recovery exit
This commit is contained in:
1 parent
d638377ee6
commit
d060e9ab3f
5 files changed
+52
-2
No files matched your search
@@ -760,6 +760,7 @@ func runVolume(f flags, exits *processExit) int {
|
||||
// (wal_corrupt / io_error) faults fail-closed and is reported at
|
||||
// once by a primary assignment; see openAndRecoverDurable.
|
||||
outcome, evidence, sErr := openAndRecoverDurable(dp, h, f.volumeID, 10*time.Second)
|
||||
chooseChunkStartupExit(exits, f, h, dp)
|
||||
switch outcome {
|
||||
case durableStartupFatal:
|
||||
fmt.Fprintln(os.Stderr, "blockvolume: durable storage open:", sErr)
|
||||
|
||||
@@ -110,10 +110,10 @@ func watchChunkStartup(ctx context.Context, e *processExit, f flags, h *volume.H
|
||||
return
|
||||
}
|
||||
for {
|
||||
if _, failed := p.ChunkStartupOutcome(f.volumeID); failed {
|
||||
e.choose(workspaceRetryOutcome(f.volumeID, f.replicaID, "assignment_timeout", h.LastOtherLine()))
|
||||
if chooseChunkStartupExit(e, f, h, p) {
|
||||
return
|
||||
}
|
||||
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
@@ -164,3 +164,15 @@ func finishWorkspaceLease(e *processExit, f flags, h *volume.Host, done <-chan e
|
||||
}
|
||||
e.choose(workspaceRetryOutcome(f.volumeID, f.replicaID, "lease_expired", h.LastOtherLine()))
|
||||
}
|
||||
|
||||
func chooseChunkStartupExit(e *processExit, f flags, h *volume.Host, p *durable.DurableProvider) bool {
|
||||
if !f.workspaceLease || f.durableImpl != "walstore-chunk" {
|
||||
return false
|
||||
}
|
||||
gen, failed := p.ChunkStartupOutcome(f.volumeID)
|
||||
if !failed {
|
||||
return false
|
||||
}
|
||||
out := workspaceRetryOutcome(f.volumeID, f.replicaID, "assignment_timeout", h.LastOtherLine())
|
||||
return p.ChooseChunkStartupExit(f.volumeID, gen, func() { e.choose(out) })
|
||||
}
|
||||
@@ -232,6 +232,12 @@ func (p *DurableProvider) chunkAuthorityWait(volumeID string, h *volHandle, gen
|
||||
case errors.Is(err, errProviderClosed):
|
||||
ended = "provider closed"
|
||||
return
|
||||
case errors.Is(err, storage.ErrChunkLayerDetached):
|
||||
// INV-WS-STARTUP-RETRY-001: an assigned sealed incarnation stays
|
||||
// non-serving for exact seal replay; restarting cannot unseal it.
|
||||
ended = "sealed assignment, retained for replay"
|
||||
h.backend.SetOperational(false, "sealed assignment; replay only")
|
||||
return
|
||||
case errors.Is(err, storage.ErrChunkLayerFenced):
|
||||
ended = "fenced, not serving"
|
||||
log.Printf("durable: chunk layer for volume=%s: %v (not serving)", volumeID, err)
|
||||
|
||||
@@ -30,3 +30,18 @@ func (p *DurableProvider) endChunkStartup(h *volHandle, gen uint64) {
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
// ChooseChunkStartupExit validates and selects an outcome in one provider-lock
|
||||
// section, so recovery cannot change generation between observation and choice.
|
||||
// choose must only latch the process outcome; it must not block or call back
|
||||
// into the provider. No remote work or resource cleanup belongs in this call.
|
||||
func (p *DurableProvider) ChooseChunkStartupExit(volumeID string, gen uint64, choose func()) bool {
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
h := p.volumes[volumeID]
|
||||
if p.closed || h == nil || h.startupEnded != gen || gen == 0 || h.recoverGen != gen {
|
||||
return false
|
||||
}
|
||||
choose()
|
||||
return true
|
||||
}
|
||||
@@ -22,3 +22,19 @@ func TestChunkStartupOutcomeRejectsOldGenerationAndCoalescesWake(t *testing.T) {
|
||||
t.Fatal("late old completion overwrote the current result")
|
||||
}
|
||||
}
|
||||
|
||||
func TestChunkStartupExitRechecksGenerationBeforeChoice(t *testing.T) {
|
||||
h := &volHandle{recoverGen: 2, startupEnded: 2}
|
||||
p := &DurableProvider{volumes: map[string]*volHandle{"v": h}}
|
||||
calls := 0
|
||||
if p.ChooseChunkStartupExit("v", 1, func() { calls++ }) || calls != 0 {
|
||||
t.Fatal("stale observation selected process exit")
|
||||
}
|
||||
if !p.ChooseChunkStartupExit("v", 2, func() { calls++ }) || calls != 1 {
|
||||
t.Fatal("current result was not selectable")
|
||||
}
|
||||
p.closed = true
|
||||
if p.ChooseChunkStartupExit("v", 2, func() { calls++ }) || calls != 1 {
|
||||
t.Fatal("closed provider selected exit")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user