From 598e8f98992a56ea35a4bef7cd163f39caef9bfc Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 00:53:13 -0800 Subject: [PATCH 01/11] fix(hostlimit): an urgent cut on the static fallback is not rate-paced; a pacing error names the limiter On a full or unusable --host-limit-dir only urgent work (the seal at stop) runs, on the static fallback. Pacing it at BytesPerSecond/FallbackVolumes (320 KiB/s by default) made detach --plain time out, reported as 'chunk remote unavailable'. With no shared cap to protect it is not paced now, and an upload-pacing error says so. Issue 486. Co-Authored-By: Claude Opus 5.5 --- seaweed-block/cmd/blockvolume/host_limit.go | 2 +- .../core/frontend/durable/provider_chunk.go | 2 +- seaweed-block/core/hostlimit/limiter.go | 7 +++++-- seaweed-block/core/hostlimit/limiter_test.go | 21 +++++++++++++++++++ 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/host_limit.go b/seaweed-block/cmd/blockvolume/host_limit.go index 7eba88af39..f2d94d7aa0 100644 --- a/seaweed-block/cmd/blockvolume/host_limit.go +++ b/seaweed-block/cmd/blockvolume/host_limit.go @@ -15,6 +15,6 @@ func registerHostLimitFlags(fs *flag.FlagSet, c *hostlimit.Config) { fs.Int64Var(&c.PayloadBytes, "host-limit-payload-bytes", c.PayloadBytes, "maximum cut payload per slot") fs.Int64Var(&c.COWBytes, "host-limit-cow-bytes", c.COWBytes, "maximum saved COW bytes per slot") fs.Int64Var(&c.BytesPerSecond, "host-limit-upload-bytes-sec", c.BytesPerSecond, "pacing parameter divided per process by cut-slot count; not a host rate cap") - fs.IntVar(&c.FallbackVolumes, "host-limit-fallback-volumes", c.FallbackVolumes, "urgent-fallback per-process divisor; coordinated host cap is not enforced") + fs.IntVar(&c.FallbackVolumes, "host-limit-fallback-volumes", c.FallbackVolumes, "kept for configuration compatibility; the urgent fallback is not paced (no shared host cap to protect)") fs.DurationVar(&c.MaxHold, "host-limit-max-hold", c.MaxHold, "cut lease timeout; expiration aborts but waits for admitted I/O before release") } diff --git a/seaweed-block/core/frontend/durable/provider_chunk.go b/seaweed-block/core/frontend/durable/provider_chunk.go index e356da62a4..f4a2680e6f 100644 --- a/seaweed-block/core/frontend/durable/provider_chunk.go +++ b/seaweed-block/core/frontend/durable/provider_chunk.go @@ -584,7 +584,7 @@ func (r *closeBoundRemote) Put(ctx context.Context, key string, data []byte) err defer end() if r.waitUpload != nil { if err := r.waitUpload(c, len(data)); err != nil { - return err + return fmt.Errorf("hostlimit: upload pacing before put %s: %w", key, err) } } return r.ChunkRemote.Put(c, key, data) diff --git a/seaweed-block/core/hostlimit/limiter.go b/seaweed-block/core/hostlimit/limiter.go index d6486f6764..494d293d60 100644 --- a/seaweed-block/core/hostlimit/limiter.go +++ b/seaweed-block/core/hostlimit/limiter.go @@ -469,10 +469,13 @@ func (l *Limiter) WaitUpload(ctx context.Context, n int) error { l.mu.Unlock() return ErrRevoked } - div := l.cfg.NormalSlots + l.cfg.UrgentSlots if l.fallback { - div = l.cfg.FallbackVolumes + // Only an urgent cut runs on the fallback, and with the shared + // pool unusable there is no host cap to protect: not paced. + l.mu.Unlock() + return nil } + div := l.cfg.NormalSlots + l.cfg.UrgentSlots rate := l.cfg.BytesPerSecond / int64(div) if rate < 1 { rate = 1 diff --git a/seaweed-block/core/hostlimit/limiter_test.go b/seaweed-block/core/hostlimit/limiter_test.go index d0f35b0533..8e43876c9b 100644 --- a/seaweed-block/core/hostlimit/limiter_test.go +++ b/seaweed-block/core/hostlimit/limiter_test.go @@ -635,3 +635,24 @@ func TestAdmitClosedDuringPoolAcquisitionIsRevoked(t *testing.T) { t.Fatalf("admission racing Close: id=%d err=%v; want ErrRevoked", id, err) } } + +// An urgent cut on the static fallback (the shared pool is unusable) is not +// rate-paced: there is no shared cap to protect, and pacing it at +// BytesPerSecond/FallbackVolumes made a seal time out (issue 486). +func TestUrgentFallbackUploadIsNotPaced(t *testing.T) { + c := testConfig(t) + c.Directory += "-missing" + l := newTest(t, c) + id, err := l.Acquire(context.Background(), Urgent, nil) + if err != nil || !l.Snapshot().(Stats).FallbackActive { + t.Fatalf("urgent fallback: id=%d err=%v", id, err) + } + defer l.Release(id) + ctx, cancel := context.WithTimeout(context.Background(), time.Second) + defer cancel() + for i := 0; i < 4; i++ { + if err := l.WaitUpload(ctx, 16<<20); err != nil { + t.Fatalf("upload %d on the fallback was paced: %v", i, err) + } + } +} From 30dafdbb1e0bb2c10ade685a93a3e7ae60806676 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 00:54:57 -0800 Subject: [PATCH 02/11] docs: INV-HOST-CUT-BUDGET-FALLBACK-001: the urgent fallback does not pace uploads Co-Authored-By: Claude Opus 5.5 --- seaweed-block/docs/design/invariants.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index e903387775..d2da1bc5ef 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -839,7 +839,7 @@ Notes: | `INV-HOST-CUT-BUDGET-RESERVE-001` | Each admitted slot, urgent included, carries at most PayloadBytes of cut payload and at most COWBytes of COW side bytes; a reservation beyond COWBytes revokes the slot and aborts its cut. | M7 admitted | `core/hostlimit/limiter.go` `Admit`, `ReserveCOW`; `core/storage/chunk_cut_budget.go` | `TestHostCOWCapAbortsCutAndRetainsPermitUntilJoin` (`core/storage/chunk_host_budget_test.go`); `TestSlotsUrgentAndJoinedRelease` (`core/hostlimit/limiter_test.go`) | `HostBudget` PayloadBound/SpillBound | ACTIVE | | `INV-HOST-CUT-BUDGET-SETTLE-001` | A slot's OS lock is released only after its cut's workers settle and Release is called; cancellation, hold expiry and limiter Close abort the cut but keep the slot until then. | M7 draining → joined → released | `core/hostlimit/limiter.go` `Release`, `releaseLoop`, `revoke`, `Close`; `core/storage/chunk_layer.go` `captureLocked` | `TestCOWAbortHoldsSlotUntilWorkerSettlement`, `TestHoldExpiryAndCloseDoNotSteal`, `TestKilledProcessReleasesButLiveHolderDoesNot` (`core/hostlimit/limiter_test.go`); `TestHostCOWCapAbortsCutAndRetainsPermitUntilJoin` (`core/storage/chunk_host_budget_test.go`) | `HostBudget` HeldUntilJoined | ACTIVE | | `INV-HOST-CUT-BUDGET-CONFIG-001` | A busy configuration lock or a mismatched pool configuration refuses every class, urgent included, with no fallback. | M7 free → admitted (refused) | `core/hostlimit/limiter.go` `pool`, `Admit` | `TestConfigurationLockContentionRefusesAllClasses` (`core/hostlimit/limiter_test.go`) | — | ACTIVE | -| `INV-HOST-CUT-BUDGET-FALLBACK-001` | Only urgent admissions (urgent move-final cuts and named seals) proceed while the pool is unavailable, on per-process fallback limits that claim no host-wide bound and are reported as fallback while any such lease lives. | M7 free → admitted (pool unavailable) | `core/hostlimit/limiter.go` `Admit`, `releaseLoop`, `WaitUpload` | `TestUnusablePoolClassPolicy`, `TestLastFallbackReleaseClearsActiveStatus`, `TestConfigurationLockFailurePreservesPoolPolicy` (`core/hostlimit/limiter_test.go`); `TestChunkControl_NamedSnapshotUsesUrgentFallback` (`core/host/volume/chunk_control_adapter_test.go`) | `HostBudget` (fallback excluded) | ACTIVE | +| `INV-HOST-CUT-BUDGET-FALLBACK-001` | Only urgent admissions (urgent move-final cuts and named seals) proceed while the pool is unavailable, on a per-process fallback that claims no host-wide bound, does not pace their uploads (there is no shared cap to protect), and is reported as fallback while any such lease lives. | M7 free → admitted (pool unavailable) | `core/hostlimit/limiter.go` `Admit`, `releaseLoop`, `WaitUpload` | `TestUnusablePoolClassPolicy`, `TestLastFallbackReleaseClearsActiveStatus`, `TestUrgentFallbackUploadIsNotPaced`, `TestConfigurationLockFailurePreservesPoolPolicy` (`core/hostlimit/limiter_test.go`); `TestChunkControl_NamedSnapshotUsesUrgentFallback` (`core/host/volume/chunk_control_adapter_test.go`) | `HostBudget` (fallback excluded) | ACTIVE | | `INV-HOST-CUT-BUDGET-PACING-001` | A process's upload pacing debt carries across its own leases, and a new process starts with no debt. | M7 admitted (upload pacing) | `core/hostlimit/limiter.go` `WaitUpload` | `TestPacingDebtSurvivesOwnLeaseTurnover`, `TestPacingFreshProcessesDoNotShareDebt` (`core/hostlimit/limiter_test.go`) | — | ACTIVE | | `INV-HOST-POOL-CONFIG-001` | A pool configuration is invisible until its complete synced temporary file is atomically renamed under the OS configuration lock. A killed initializer cannot leave a partial visible configuration that strands successors. | M7 configuration preparation/publication | `core/hostlimit` `publishConfig` | `TestKilledInitializerDoesNotPublishPartialConfiguration` | `HostBudget` NoPartialConfig/ConfigBeforeAdmission (filesystem atomicity checked natively) | ACTIVE | | `INV-HOST-URGENT-PENDING-001` | While an urgent cut holds its slot, or a caller holds HoldUrgentPending, every Normal admission on the host is refused with ErrUrgentPending (a held-slot wait); urgent admissions still run. | M7 host cut admission (Normal before a slot) | `core/hostlimit/limiter.go` `pool`, `Admit`; `core/hostlimit/pending.go` `HoldUrgentPending` | `TestNormalWaitsWhileUrgentPendingIsHeld`, `TestUrgentLeaseHoldsThePendingSignal` (`core/hostlimit/pending_test.go`); `TestSlotsUrgentAndJoinedRelease` (`core/hostlimit/limiter_test.go`) | — | ACTIVE | From 64b541d7fb9ad027b9b406c49c52337cfe2ec213 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 00:58:32 -0800 Subject: [PATCH 03/11] fix(storage): the flusher logs a retried ENOSPC once per 30 s with a count On a full local disk every flusher cycle failed its extent write with ENOSPC and logged it, about 100 lines in 10 s. Terminal errors stay unlimited. Issue 484. Co-Authored-By: Claude Opus 5.5 --- .../core/storage/checkpoint_diagnostics.go | 15 +++++++++++- .../storage/checkpoint_diagnostics_test.go | 23 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/seaweed-block/core/storage/checkpoint_diagnostics.go b/seaweed-block/core/storage/checkpoint_diagnostics.go index 4a2ae329e2..3d7023aee3 100644 --- a/seaweed-block/core/storage/checkpoint_diagnostics.go +++ b/seaweed-block/core/storage/checkpoint_diagnostics.go @@ -3,6 +3,7 @@ package storage import ( "errors" "log" + "syscall" "time" ) @@ -63,13 +64,25 @@ func (r mapCoverageRefusal) Error() string { return ErrMapCoverageStale.Error() func (r mapCoverageRefusal) Unwrap() error { return ErrMapCoverageStale } // Owned exclusively by the flusher run loop; no storage lock or I/O ordering -// changes. Terminal errors are never rate limited. +// changes. Terminal errors are never rate limited; a retried ENOSPC is. type checkpointLogLimiter struct { last time.Time suppressed uint64 + // A full local disk fails every retry with ENOSPC; one line per 30 s. + noSpaceLast time.Time + noSpaceSuppressed uint64 } func (l *checkpointLogLimiter) report(err error, now time.Time) { + if errors.Is(err, syscall.ENOSPC) { + if !l.noSpaceLast.IsZero() && now.Sub(l.noSpaceLast) < 30*time.Second { + l.noSpaceSuppressed++ + return + } + log.Printf("storage: flusher: local disk full, retrying suppressed=%d: %v", l.noSpaceSuppressed, err) + l.noSpaceLast, l.noSpaceSuppressed = now, 0 + return + } if !errors.Is(err, ErrMapCoverageStale) { log.Printf("storage: flusher: %v", err) return diff --git a/seaweed-block/core/storage/checkpoint_diagnostics_test.go b/seaweed-block/core/storage/checkpoint_diagnostics_test.go index 3834cecd57..4bd2c0e2d0 100644 --- a/seaweed-block/core/storage/checkpoint_diagnostics_test.go +++ b/seaweed-block/core/storage/checkpoint_diagnostics_test.go @@ -6,7 +6,9 @@ import ( "errors" "fmt" "log" + "os" "strings" + "syscall" "testing" "time" ) @@ -191,3 +193,24 @@ func TestCheckpointDiagnostics_LastAdvanceFollowsOnlyAdvances(t *testing.T) { t.Fatalf("classification: s=%d r=%d f=%d", i.checkpointSuccesses.Load(), i.checkpointRefusals.Load(), i.checkpointFailures.Load()) } } + +// The flusher retries an extent write that failed with ENOSPC every cycle; on +// a full local disk that is one log line per cycle (issue 484). It is logged +// once per 30 s with the count of suppressed repeats. +func TestCheckpointDiagnostics_NoSpaceRetryLogRateLimit(t *testing.T) { + var out bytes.Buffer + old := log.Writer() + log.SetOutput(&out) + t.Cleanup(func() { log.SetOutput(old) }) + var limiter checkpointLogLimiter + now := time.Unix(100, 0) + full := fmt.Errorf("flusher: write extent LBA 653: %w", &os.PathError{Op: "write", Path: "v1.bin", Err: syscall.ENOSPC}) + for i := 0; i < 100; i++ { + limiter.report(full, now.Add(time.Duration(i)*100*time.Millisecond)) + } + limiter.report(full, now.Add(31*time.Second)) + got := out.String() + if n := strings.Count(got, "no space left on device"); n != 2 || !strings.Contains(got, "suppressed=99") { + t.Fatalf("want 2 lines, the second with suppressed=99; got %d:\n%s", n, got) + } +} From 88ee1b22b58fdd4acfd9bd58ea453a581199c64c Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 01:00:01 -0800 Subject: [PATCH 04/11] test(storage): ENOSPC on the WAL append itself is the latched permanent fault Co-Authored-By: Claude Opus 5.5 --- seaweed-block/core/storage/walstore_v3_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/seaweed-block/core/storage/walstore_v3_test.go b/seaweed-block/core/storage/walstore_v3_test.go index 298cd708c3..f28637d12e 100644 --- a/seaweed-block/core/storage/walstore_v3_test.go +++ b/seaweed-block/core/storage/walstore_v3_test.go @@ -7,6 +7,7 @@ import ( "path/filepath" "runtime" "sync" + "syscall" "testing" "time" ) @@ -984,3 +985,20 @@ func TestWALStoreV3FlusherCheckpointIsClampedToTheAcknowledgedW(t *testing.T) { } } } + +// ENOSPC on the WAL append itself (not behind it, in the flusher) is the +// permanent, latched store fault, as the disk-full ruling scopes it (issue +// 484): the error keeps ENOSPC and the latch is a SubstrateIO failure. +func TestWALStoreV3AppendNoSpaceIsTheLatchedPermanentFault(t *testing.T) { + s, _ := newStoreV3(t, WModeLagged) + defer s.Close() + writeSynced(t, s, 1, 1) + s.v3.w.writeAt = func([]byte, int64) (int, error) { return 0, syscall.ENOSPC } + if _, err := s.Write(2, blk(2)); !errors.Is(err, syscall.ENOSPC) { + t.Fatalf("append: err = %v, want ENOSPC", err) + } + var failure *RecoveryFailure + if f := s.stickyIOFault(); !errors.As(f, &failure) || failure.Kind != StorageRecoveryFailureSubstrateIO { + t.Fatalf("ENOSPC on the append latched %v, want a SubstrateIO failure", f) + } +} From 1a77477892bcdcdd12ea47e3e9c475bb89b36a4c Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 01:04:10 -0800 Subject: [PATCH 05/11] fix(hostlimit): uploads go unpaced only while every live lease is a fallback lease; wrapper test A healthy lease admitted beside an urgent fallback lease kept no pacing (review). The pacing error wrapper now has a test: prefix, cause, no put. Co-Authored-By: Claude Opus 5.5 --- .../durable/chunk_upload_pacing_error_test.go | 25 ++++++++++++++++ seaweed-block/core/hostlimit/limiter.go | 12 ++++++-- seaweed-block/core/hostlimit/limiter_test.go | 30 +++++++++++++++++++ seaweed-block/docs/design/invariants.md | 2 +- 4 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 seaweed-block/core/frontend/durable/chunk_upload_pacing_error_test.go diff --git a/seaweed-block/core/frontend/durable/chunk_upload_pacing_error_test.go b/seaweed-block/core/frontend/durable/chunk_upload_pacing_error_test.go new file mode 100644 index 0000000000..72f02b39bd --- /dev/null +++ b/seaweed-block/core/frontend/durable/chunk_upload_pacing_error_test.go @@ -0,0 +1,25 @@ +package durable + +import ( + "context" + "errors" + "strings" + "testing" + + "github.com/seaweedfs/seaweed-block/core/storage" +) + +// A pacing refusal before a chunk put names the host limiter, keeps its cause +// and sends no put (issue 486: it was reported as the chunk remote). +func TestChunkUploadPacingErrorNamesTheLimiter(t *testing.T) { + inner := storage.NewMemChunkRemote() + bound := &closeBoundRemote{ChunkRemote: inner, done: context.Background(), + waitUpload: func(context.Context, int) error { return context.DeadlineExceeded }} + err := bound.Put(context.Background(), "chunk-1", []byte("x")) + if !errors.Is(err, context.DeadlineExceeded) || !strings.HasPrefix(err.Error(), "hostlimit: upload pacing before put chunk-1: ") { + t.Fatalf("pacing error: %v", err) + } + if _, err := inner.Get(context.Background(), "chunk-1"); err == nil { + t.Fatal("a chunk was put although pacing refused it") + } +} diff --git a/seaweed-block/core/hostlimit/limiter.go b/seaweed-block/core/hostlimit/limiter.go index 494d293d60..1861fdb34b 100644 --- a/seaweed-block/core/hostlimit/limiter.go +++ b/seaweed-block/core/hostlimit/limiter.go @@ -469,9 +469,15 @@ func (l *Limiter) WaitUpload(ctx context.Context, n int) error { l.mu.Unlock() return ErrRevoked } - if l.fallback { - // Only an urgent cut runs on the fallback, and with the shared - // pool unusable there is no host cap to protect: not paced. + // Only urgent cuts run on the fallback, and with the shared pool + // unusable there is no host cap to protect: while every live lease + // is a fallback lease, uploads are not paced. A healthy lease beside + // one keeps its pacing. + onlyFallback := l.fallback && len(l.live) > 0 + for _, held := range l.live { + onlyFallback = onlyFallback && held.fallback + } + if onlyFallback { l.mu.Unlock() return nil } diff --git a/seaweed-block/core/hostlimit/limiter_test.go b/seaweed-block/core/hostlimit/limiter_test.go index 8e43876c9b..05b23eb02a 100644 --- a/seaweed-block/core/hostlimit/limiter_test.go +++ b/seaweed-block/core/hostlimit/limiter_test.go @@ -656,3 +656,33 @@ func TestUrgentFallbackUploadIsNotPaced(t *testing.T) { } } } + +// While an urgent cut is on the fallback, a healthy cut admitted after the +// pool came back is still paced: only fallback leases alone go unpaced. +func TestFallbackDoesNotUnpaceAHealthyLease(t *testing.T) { + c := testConfig(t) + c.BytesPerSecond = 16 << 20 + c.Directory += "-missing" + l := newTest(t, c) + urgent, err := l.Acquire(context.Background(), Urgent, nil) + if err != nil || !l.Snapshot().(Stats).FallbackActive { + t.Fatalf("urgent fallback: id=%d err=%v", urgent, err) + } + defer l.Release(urgent) + if err := os.Mkdir(c.Directory, 0o700); err != nil { + t.Fatal(err) + } + normal, err := l.Admit(context.Background(), 1, nil) + if err != nil { + t.Fatalf("healthy normal admission after the pool came back: %v", err) + } + defer l.Release(normal) + ctx, cancel := context.WithTimeout(context.Background(), time.Second) + defer cancel() + if err := l.WaitUpload(ctx, 16<<20); err != nil { + t.Fatal(err) + } + if err := l.WaitUpload(ctx, 16<<20); !errors.Is(err, context.DeadlineExceeded) { + t.Fatalf("a healthy lease's second 16 MiB upload was not paced beside a fallback lease: %v", err) + } +} diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index d2da1bc5ef..441f35e996 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -839,7 +839,7 @@ Notes: | `INV-HOST-CUT-BUDGET-RESERVE-001` | Each admitted slot, urgent included, carries at most PayloadBytes of cut payload and at most COWBytes of COW side bytes; a reservation beyond COWBytes revokes the slot and aborts its cut. | M7 admitted | `core/hostlimit/limiter.go` `Admit`, `ReserveCOW`; `core/storage/chunk_cut_budget.go` | `TestHostCOWCapAbortsCutAndRetainsPermitUntilJoin` (`core/storage/chunk_host_budget_test.go`); `TestSlotsUrgentAndJoinedRelease` (`core/hostlimit/limiter_test.go`) | `HostBudget` PayloadBound/SpillBound | ACTIVE | | `INV-HOST-CUT-BUDGET-SETTLE-001` | A slot's OS lock is released only after its cut's workers settle and Release is called; cancellation, hold expiry and limiter Close abort the cut but keep the slot until then. | M7 draining → joined → released | `core/hostlimit/limiter.go` `Release`, `releaseLoop`, `revoke`, `Close`; `core/storage/chunk_layer.go` `captureLocked` | `TestCOWAbortHoldsSlotUntilWorkerSettlement`, `TestHoldExpiryAndCloseDoNotSteal`, `TestKilledProcessReleasesButLiveHolderDoesNot` (`core/hostlimit/limiter_test.go`); `TestHostCOWCapAbortsCutAndRetainsPermitUntilJoin` (`core/storage/chunk_host_budget_test.go`) | `HostBudget` HeldUntilJoined | ACTIVE | | `INV-HOST-CUT-BUDGET-CONFIG-001` | A busy configuration lock or a mismatched pool configuration refuses every class, urgent included, with no fallback. | M7 free → admitted (refused) | `core/hostlimit/limiter.go` `pool`, `Admit` | `TestConfigurationLockContentionRefusesAllClasses` (`core/hostlimit/limiter_test.go`) | — | ACTIVE | -| `INV-HOST-CUT-BUDGET-FALLBACK-001` | Only urgent admissions (urgent move-final cuts and named seals) proceed while the pool is unavailable, on a per-process fallback that claims no host-wide bound, does not pace their uploads (there is no shared cap to protect), and is reported as fallback while any such lease lives. | M7 free → admitted (pool unavailable) | `core/hostlimit/limiter.go` `Admit`, `releaseLoop`, `WaitUpload` | `TestUnusablePoolClassPolicy`, `TestLastFallbackReleaseClearsActiveStatus`, `TestUrgentFallbackUploadIsNotPaced`, `TestConfigurationLockFailurePreservesPoolPolicy` (`core/hostlimit/limiter_test.go`); `TestChunkControl_NamedSnapshotUsesUrgentFallback` (`core/host/volume/chunk_control_adapter_test.go`) | `HostBudget` (fallback excluded) | ACTIVE | +| `INV-HOST-CUT-BUDGET-FALLBACK-001` | Only urgent admissions (urgent move-final cuts and named seals) proceed while the pool is unavailable, on a per-process fallback that claims no host-wide bound, does not pace their uploads while only fallback leases live (there is no shared cap to protect; a healthy lease beside one stays paced), and is reported as fallback while any such lease lives. | M7 free → admitted (pool unavailable) | `core/hostlimit/limiter.go` `Admit`, `releaseLoop`, `WaitUpload` | `TestUnusablePoolClassPolicy`, `TestLastFallbackReleaseClearsActiveStatus`, `TestUrgentFallbackUploadIsNotPaced`, `TestFallbackDoesNotUnpaceAHealthyLease`, `TestConfigurationLockFailurePreservesPoolPolicy` (`core/hostlimit/limiter_test.go`); `TestChunkControl_NamedSnapshotUsesUrgentFallback` (`core/host/volume/chunk_control_adapter_test.go`) | `HostBudget` (fallback excluded) | ACTIVE | | `INV-HOST-CUT-BUDGET-PACING-001` | A process's upload pacing debt carries across its own leases, and a new process starts with no debt. | M7 admitted (upload pacing) | `core/hostlimit/limiter.go` `WaitUpload` | `TestPacingDebtSurvivesOwnLeaseTurnover`, `TestPacingFreshProcessesDoNotShareDebt` (`core/hostlimit/limiter_test.go`) | — | ACTIVE | | `INV-HOST-POOL-CONFIG-001` | A pool configuration is invisible until its complete synced temporary file is atomically renamed under the OS configuration lock. A killed initializer cannot leave a partial visible configuration that strands successors. | M7 configuration preparation/publication | `core/hostlimit` `publishConfig` | `TestKilledInitializerDoesNotPublishPartialConfiguration` | `HostBudget` NoPartialConfig/ConfigBeforeAdmission (filesystem atomicity checked natively) | ACTIVE | | `INV-HOST-URGENT-PENDING-001` | While an urgent cut holds its slot, or a caller holds HoldUrgentPending, every Normal admission on the host is refused with ErrUrgentPending (a held-slot wait); urgent admissions still run. | M7 host cut admission (Normal before a slot) | `core/hostlimit/limiter.go` `pool`, `Admit`; `core/hostlimit/pending.go` `HoldUrgentPending` | `TestNormalWaitsWhileUrgentPendingIsHeld`, `TestUrgentLeaseHoldsThePendingSignal` (`core/hostlimit/pending_test.go`); `TestSlotsUrgentAndJoinedRelease` (`core/hostlimit/limiter_test.go`) | — | ACTIVE | From d8d1f3b4d25aaa8e9e7f26bdea614312edb7cbcd Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 01:23:06 -0800 Subject: [PATCH 06/11] fix(durable): refuse to create a volume without local room for its size and WAL; warn at open when the growth no longer fits A full local disk fails guest writes (a Linux guest sees EREMOTEIO after about 75 s), so the defence is headroom (V1-SPEC r2.60, issue 484): create needs free space >= volume size + the 64 MiB WAL, and the refusal names both numbers; an existing volume opens, with a loud warning, when its remaining sparse growth + WAL exceed the free space. No new state. Co-Authored-By: Claude Opus 5.5 --- .../core/frontend/durable/headroom.go | 43 +++++++++++++ .../frontend/durable/headroom_export_test.go | 9 +++ .../core/frontend/durable/headroom_test.go | 62 +++++++++++++++++++ .../core/frontend/durable/provider.go | 3 +- .../core/frontend/durable/spill_free_linux.go | 9 +++ .../core/frontend/durable/spill_free_other.go | 2 + seaweed-block/core/storage/walstore.go | 5 +- 7 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 seaweed-block/core/frontend/durable/headroom.go create mode 100644 seaweed-block/core/frontend/durable/headroom_export_test.go create mode 100644 seaweed-block/core/frontend/durable/headroom_test.go diff --git a/seaweed-block/core/frontend/durable/headroom.go b/seaweed-block/core/frontend/durable/headroom.go new file mode 100644 index 0000000000..ba0d13865d --- /dev/null +++ b/seaweed-block/core/frontend/durable/headroom.go @@ -0,0 +1,43 @@ +package durable + +import ( + "fmt" + "log" + + "github.com/seaweedfs/seaweed-block/core/storage" +) + +// rootFree probes the free bytes of the durable root's file system (nil where +// it cannot tell); tests replace it. +var rootFree = spillFree + +// Operator guide, Size a host: a full local disk fails guest writes, so a +// volume is created only with room for its full size and its WAL, and an +// existing volume opens with a loud warning when its remaining sparse growth +// and the WAL no longer fit. Neither adds state. +func (p *DurableProvider) refuseCreateWithoutHeadroom(volumeID string) error { + free := rootFree(p.cfg.StorageRoot) + if free == nil { + return nil + } + have, err := free() + size := int64(p.cfg.NumBlocks) * int64(p.cfg.BlockSize) + if need := size + storage.DefaultWALBytes; err == nil && have < need { + return fmt.Errorf("durable: %s has %d bytes free; volume %s needs %d (size %d + WAL %d): free space on it or use a larger file system", + p.cfg.StorageRoot, have, volumeID, need, size, storage.DefaultWALBytes) + } + return nil +} + +func (p *DurableProvider) warnLowHeadroom(volumeID, path string, size int64) { + free := rootFree(p.cfg.StorageRoot) + if free == nil { + return + } + have, err := free() + growth := max(size-allocatedBytes(path), 0) + if err == nil && have < growth+storage.DefaultWALBytes { + log.Printf("durable: WARNING volume %s: %s has %d bytes free, less than the volume's remaining growth %d + WAL %d; when the disk fills, guest writes fail: free space on it", + volumeID, p.cfg.StorageRoot, have, growth, storage.DefaultWALBytes) + } +} diff --git a/seaweed-block/core/frontend/durable/headroom_export_test.go b/seaweed-block/core/frontend/durable/headroom_export_test.go new file mode 100644 index 0000000000..9be29f63d7 --- /dev/null +++ b/seaweed-block/core/frontend/durable/headroom_export_test.go @@ -0,0 +1,9 @@ +package durable + +// SetRootFreeForTest replaces the durable root's free-space probe and returns +// the restore function. +func SetRootFreeForTest(free int64) func() { + old := rootFree + rootFree = func(string) func() (int64, error) { return func() (int64, error) { return free, nil } } + return func() { rootFree = old } +} diff --git a/seaweed-block/core/frontend/durable/headroom_test.go b/seaweed-block/core/frontend/durable/headroom_test.go new file mode 100644 index 0000000000..5463a8804a --- /dev/null +++ b/seaweed-block/core/frontend/durable/headroom_test.go @@ -0,0 +1,62 @@ +package durable_test + +import ( + "bytes" + "log" + "os" + "path/filepath" + "strings" + "testing" + + "github.com/seaweedfs/seaweed-block/core/frontend/durable" +) + +// A volume is not created on a durable root without room for its full size +// and its WAL (operator guide, Size a host; issue 484): a full local disk +// fails guest writes, so the cure comes before the first write. +func TestCreateRefusesWithoutLocalHeadroom(t *testing.T) { + defer durable.SetRootFreeForTest(8 << 20)() + root := t.TempDir() + p, err := durable.NewDurableProvider(durable.ProviderConfig{Impl: durable.ImplWALStore, StorageRoot: root, BlockSize: 4096, NumBlocks: 65536}, v1View()) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { p.Close() }) + _, err = p.EnsureStorage("v1") + if err == nil || !strings.Contains(err.Error(), "8388608 bytes free") || !strings.Contains(err.Error(), "needs 335544320") { + t.Fatalf("create on a root with 8 MiB free: %v", err) + } + if left, _ := filepath.Glob(filepath.Join(root, "*", "*.bin")); len(left) != 0 { + t.Fatalf("a refused create left %v", left) + } +} + +// An existing volume still opens on a root that is short of headroom, with a +// loud warning: refusing it would leave the acknowledged data unserved. +func TestOpenWarnsWithoutLocalHeadroom(t *testing.T) { + root := t.TempDir() + cfg := durable.ProviderConfig{Impl: durable.ImplWALStore, StorageRoot: root, BlockSize: 4096, NumBlocks: 64} + p, err := durable.NewDurableProvider(cfg, v1View()) + if err != nil { + t.Fatal(err) + } + if _, err := p.EnsureStorage("v1"); err != nil { + t.Fatal(err) + } + p.Close() + var out bytes.Buffer + log.SetOutput(&out) + t.Cleanup(func() { log.SetOutput(os.Stderr) }) + defer durable.SetRootFreeForTest(4096)() + p, err = durable.NewDurableProvider(cfg, v1View()) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { p.Close() }) + if _, err := p.EnsureStorage("v1"); err != nil { + t.Fatalf("an existing volume did not open on a short root: %v", err) + } + if !strings.Contains(out.String(), "WARNING") || !strings.Contains(out.String(), "4096 bytes free") { + t.Fatalf("no headroom warning:\n%s", out.String()) + } +} diff --git a/seaweed-block/core/frontend/durable/provider.go b/seaweed-block/core/frontend/durable/provider.go index 7dfc67abfc..c18becd6b4 100644 --- a/seaweed-block/core/frontend/durable/provider.go +++ b/seaweed-block/core/frontend/durable/provider.go @@ -938,6 +938,7 @@ func (p *DurableProvider) openExisting(volumeID, path string, impl ImplName) (*v if err != nil { return nil, fmt.Errorf("durable: OpenWALStore %s: %w", path, err) } + p.warnLowHeadroom(volumeID, path, int64(ws.NumBlocks())*int64(ws.BlockSize())) // G6 §1.A α: plumb operator-tunable retention into walstore. // Zero (pre-G6 default) preserves strict checkpoint-driven // recycle. @@ -988,7 +989,7 @@ func (p *DurableProvider) createFresh(volumeID, path string, impl ImplName) (*vo var err error if p.testWALStoreFactory != nil { ws, err = p.testWALStoreFactory(path, true) - } else { + } else if err = p.refuseCreateWithoutHeadroom(volumeID); err == nil { ws, err = storage.CreateWALStoreWithOptions(path, p.cfg.NumBlocks, p.cfg.BlockSize, storage.WALStoreOptions{ChunkBlocks: p.cfg.ChunkBlocks}) } if err != nil { diff --git a/seaweed-block/core/frontend/durable/spill_free_linux.go b/seaweed-block/core/frontend/durable/spill_free_linux.go index 92843c70ff..d3a3516804 100644 --- a/seaweed-block/core/frontend/durable/spill_free_linux.go +++ b/seaweed-block/core/frontend/durable/spill_free_linux.go @@ -15,3 +15,12 @@ func spillFree(dir string) func() (int64, error) { return int64(st.Bavail) * int64(st.Bsize), nil } } + +// allocatedBytes is the space path's file holds on disk (0 if unknown). +func allocatedBytes(path string) int64 { + var st syscall.Stat_t + if syscall.Stat(path, &st) != nil { + return 0 + } + return st.Blocks * 512 +} diff --git a/seaweed-block/core/frontend/durable/spill_free_other.go b/seaweed-block/core/frontend/durable/spill_free_other.go index 7ba44e278c..7c3a16135f 100644 --- a/seaweed-block/core/frontend/durable/spill_free_other.go +++ b/seaweed-block/core/frontend/durable/spill_free_other.go @@ -4,3 +4,5 @@ package durable // spillFree is nil off Linux: the COW spill cap is the configured one. func spillFree(string) func() (int64, error) { return nil } + +func allocatedBytes(string) int64 { return 0 } diff --git a/seaweed-block/core/storage/walstore.go b/seaweed-block/core/storage/walstore.go index 250a6bfa45..afccc9023f 100644 --- a/seaweed-block/core/storage/walstore.go +++ b/seaweed-block/core/storage/walstore.go @@ -171,6 +171,9 @@ type WALStore struct { // numBlocks defines the addressable block range; blockSize is the IO // unit (default 4096 if zero). The on-disk file is preallocated to // hold the superblock + WAL region + a fully addressable extent. +// DefaultWALBytes is the WAL region a created store reserves. +const DefaultWALBytes = 64 << 20 + func CreateWALStore(path string, numBlocks uint32, blockSize int) (*WALStore, error) { return CreateWALStoreWithOptions(path, numBlocks, blockSize, WALStoreOptions{}) } @@ -192,7 +195,7 @@ func CreateWALStoreWithOptions(path string, numBlocks uint32, blockSize int, opt if cb == 0 { cb = 1024 } - return createWALStoreV3Configured(path, numBlocks, uint32(blockSize), 64*1024*1024, opts.WMode, 0, uint64(cb), opts) + return createWALStoreV3Configured(path, numBlocks, uint32(blockSize), DefaultWALBytes, opts.WMode, 0, uint64(cb), opts) } // OpenWALStore opens an existing store file WITHOUT recovering it. From 2326e24707239f09e5cb48988b3b9af227fd1516 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 01:34:16 -0800 Subject: [PATCH 07/11] fix(storage): a latched store fault with ENOSPC as its cause is logged every time; only a retried ENOSPC is limited Co-Authored-By: Claude Opus 5.5 --- .../core/storage/checkpoint_diagnostics.go | 5 +++- .../storage/checkpoint_diagnostics_test.go | 27 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/seaweed-block/core/storage/checkpoint_diagnostics.go b/seaweed-block/core/storage/checkpoint_diagnostics.go index 3d7023aee3..468fa39d48 100644 --- a/seaweed-block/core/storage/checkpoint_diagnostics.go +++ b/seaweed-block/core/storage/checkpoint_diagnostics.go @@ -74,7 +74,10 @@ type checkpointLogLimiter struct { } func (l *checkpointLogLimiter) report(err error, now time.Time) { - if errors.Is(err, syscall.ENOSPC) { + // A latched store fault is terminal even when ENOSPC is its cause: it is + // logged every time. Only a retried ENOSPC (no RecoveryFailure) is limited. + var terminal *RecoveryFailure + if errors.Is(err, syscall.ENOSPC) && !errors.As(err, &terminal) { if !l.noSpaceLast.IsZero() && now.Sub(l.noSpaceLast) < 30*time.Second { l.noSpaceSuppressed++ return diff --git a/seaweed-block/core/storage/checkpoint_diagnostics_test.go b/seaweed-block/core/storage/checkpoint_diagnostics_test.go index 4bd2c0e2d0..4620636189 100644 --- a/seaweed-block/core/storage/checkpoint_diagnostics_test.go +++ b/seaweed-block/core/storage/checkpoint_diagnostics_test.go @@ -214,3 +214,30 @@ func TestCheckpointDiagnostics_NoSpaceRetryLogRateLimit(t *testing.T) { t.Fatalf("want 2 lines, the second with suppressed=99; got %d:\n%s", n, got) } } + +// A terminal fault with ENOSPC as its cause (the latched append or fsync +// failure the flusher returns each cycle) stays unlimited: only the retried +// ENOSPC is rate-limited. +func TestCheckpointDiagnostics_TerminalNoSpaceIsNotRateLimited(t *testing.T) { + var out bytes.Buffer + old := log.Writer() + log.SetOutput(&out) + t.Cleanup(func() { log.SetOutput(old) }) + var limiter checkpointLogLimiter + now := time.Unix(100, 0) + terminal := NewSubstrateIOFailure(fmt.Errorf("%w: %w", ErrAppendFailed, syscall.ENOSPC), "append failed") + limiter.report(terminal, now) + limiter.report(terminal, now.Add(time.Second)) + got := out.String() + if n := strings.Count(got, "no space left on device"); n != 2 || strings.Contains(got, "retrying") { + t.Fatalf("terminal ENOSPC faults were limited or relabelled (%d lines):\n%s", n, got) + } + // The window resets: a retried ENOSPC after 30 s is logged again with its count. + full := fmt.Errorf("write extent: %w", syscall.ENOSPC) + limiter.report(full, now) + limiter.report(full, now.Add(29*time.Second)) + limiter.report(full, now.Add(30*time.Second)) + if got := out.String(); strings.Count(got, "retrying") != 2 || !strings.Contains(got, "suppressed=1") { + t.Fatalf("30 s window:\n%s", got) + } +} From c1f1602d1df5c9312d42cb20e6a75038015f8bc2 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 01:35:29 -0800 Subject: [PATCH 08/11] docs: INV-LOCAL-HEADROOM-001 (create refused without local headroom; warning at start) Co-Authored-By: Claude Opus 5.5 --- seaweed-block/docs/design/invariants.md | 1 + 1 file changed, 1 insertion(+) diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index f1ac4c0122..184eb826dc 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -844,6 +844,7 @@ Notes: | `INV-HOST-POOL-CONFIG-001` | A pool configuration is invisible until its complete synced temporary file is atomically renamed under the OS configuration lock. A killed initializer cannot leave a partial visible configuration that strands successors. | M7 configuration preparation/publication | `core/hostlimit` `publishConfig` | `TestKilledInitializerDoesNotPublishPartialConfiguration` | `HostBudget` NoPartialConfig/ConfigBeforeAdmission (filesystem atomicity checked natively) | ACTIVE | | `INV-HOST-URGENT-PENDING-001` | While an urgent cut holds its slot, or a caller holds HoldUrgentPending, every Normal admission on the host is refused with ErrUrgentPending (a held-slot wait); urgent admissions still run. | M7 host cut admission (Normal before a slot) | `core/hostlimit/limiter.go` `pool`, `Admit`; `core/hostlimit/pending.go` `HoldUrgentPending` | `TestNormalWaitsWhileUrgentPendingIsHeld`, `TestUrgentLeaseHoldsThePendingSignal` (`core/hostlimit/pending_test.go`); `TestSlotsUrgentAndJoinedRelease` (`core/hostlimit/limiter_test.go`) | — | ACTIVE | | `INV-HOST-LAUNCH-CHECK-001` | blockvolume refuses to start with a --host-limit-dir that is missing or not a directory, under a temporary directory, on a network file system, or already in use with different host-limit flags. | M7 host cut admission (process start) | `core/hostlimit/launch.go` `CheckLaunch`; `core/hostlimit/remotefs_linux.go`; `cmd/blockvolume/main.go` | `TestCheckLaunch` (`core/hostlimit/pending_test.go`) | — | ACTIVE | +| `INV-LOCAL-HEADROOM-001` | blockvolume refuses to create a volume when the durable root's file system has less free space than the volume size plus its WAL, naming both numbers, and warns at start when an existing volume's remaining sparse growth plus the WAL exceed the free space; it adds no state. | M1 open/create (durable provider start) | `core/frontend/durable/headroom.go`; `core/frontend/durable/provider.go` `createFresh`, `openExisting` | `TestCreateRefusesWithoutLocalHeadroom`, `TestOpenWarnsWithoutLocalHeadroom` (`core/frontend/durable/headroom_test.go`) | — | ACTIVE | | `INV-HOST-SLOT-BUSY-CODE-001` | The chunk control API refuses a cut, snapshot or detach that host admission refused because every slot is held (or urgent work is pending) with 503 host_slot_busy, retryable; every other capture refusal keeps capture_refused. | M7 free → admitted (refused, wait) | `core/host/volume/chunk_control.go` `chunkErrorCode` | `TestHostSlotHeldHasItsOwnCode` (`core/host/volume/chunk_host_slot_code_test.go`) | — | ACTIVE | | `INV-CUT-INTENT-FIRST-001` | Before the first chunk or segment PUT of a cut or staging round, an intent naming every key of that kind the round preallocated is durable in the filer: one for all candidate chunks, however many upload waves the round uses, and one for all new segments. | M5 Intent → Upload → CAS | `core/storage/chunk_cut_payload.go` `streamCutPayloads`; `core/storage/chunk_layer.go` `captureLocked`, `stage`; `core/frontend/chunkstore/manifest.go` `PrepareManifest` | `TestChunkIntent_WrittenBeforeFirstUploadAndDeletedAfterCAS`, `TestChunkIntent_FailedPutIntentUploadsNothing` (`core/storage/chunk_layer_intent_test.go`); `TestCutPayloadIntentCountIndependentOfCandidates`, `TestCutPayloadReadsOverlapEarlierUploadsWithinBudget` (`core/storage/chunk_review271_test.go`); `TestChunkPrecopy_StagedUploadsAreCoveredByIntents` (`core/storage/chunk_layer_precopy_test.go`); `TestManifest_ReusesUnchangedRangeAndCrashKeepsOldRoot` (`core/frontend/chunkstore/manifest_test.go`) | `ChunkLifecycleFixed` `GCSafe`; `WorkspaceTakeover` `NoLiveIntentExpired` | ACTIVE | | `INV-CUT-INTENT-CLOSE-001` | Close deletes the intents of reusable uploads and leftover intents, but never an intent of a proposal whose CAS outcome is still unresolved. | M5 Close | `core/storage/chunk_layer.go` `Close`, `captureLocked`, `dropIntents` | `TestChunkCloseDropsReusableButKeepsUnknownCASRoots` (`core/storage/chunk_review271_test.go`); `TestHeadBeltOldCASUnconfirmedKeepsIntentsAndFrontier`, `TestHeadBeltLowerEpochConflictFencesWithoutCleanup`, `TestHeadBeltEmptyBaseForeignPublicationFences` (`core/storage/chunk_head_belt_test.go`) | — | ACTIVE | From 29c4c2ef834f127961fd7fecb8c650237eb96503 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 01:36:57 -0800 Subject: [PATCH 09/11] docs: invariants Part B count for INV-LOCAL-HEADROOM-001 Co-Authored-By: Claude Opus 5.5 --- seaweed-block/docs/design/invariants.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index 184eb826dc..020ad8ec8f 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -493,7 +493,7 @@ Tests: `TestSnapshotSchedule_SlotsAreOffsetPerVolume`, `_FailureIsTypedAndBacksO ## Part B. Invariant ledger -317 rows: 246 ACTIVE, 68 STUB, 3 ARCHIVED; 15 kept from the internal ledger, 302 new. +318 rows: 247 ACTIVE, 68 STUB, 3 ARCHIVED; 15 kept from the internal ledger, 303 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. From 98d87777aae5fa4e05b5dabfcf1327d164c7043f Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 01:41:58 -0800 Subject: [PATCH 10/11] fix(durable): headroom guard before any sidecar; the open warning counts data growth apart from the WAL; M1 trace row Review: a refused chunk create left its fresh marker; a fresh 256 MiB store (WAL only allocated) with 256 MiB free gave no warning. Co-Authored-By: Claude Opus 5.5 --- .../core/frontend/durable/headroom.go | 3 +- .../core/frontend/durable/headroom_test.go | 88 ++++++++++++------- .../core/frontend/durable/provider.go | 6 +- seaweed-block/docs/design/invariants.md | 1 + 4 files changed, 65 insertions(+), 33 deletions(-) diff --git a/seaweed-block/core/frontend/durable/headroom.go b/seaweed-block/core/frontend/durable/headroom.go index ba0d13865d..fcfd199003 100644 --- a/seaweed-block/core/frontend/durable/headroom.go +++ b/seaweed-block/core/frontend/durable/headroom.go @@ -35,7 +35,8 @@ func (p *DurableProvider) warnLowHeadroom(volumeID, path string, size int64) { return } have, err := free() - growth := max(size-allocatedBytes(path), 0) + // The store's allocation includes its WAL; only the rest is data. + growth := max(size-max(allocatedBytes(path)-storage.DefaultWALBytes, 0), 0) if err == nil && have < growth+storage.DefaultWALBytes { log.Printf("durable: WARNING volume %s: %s has %d bytes free, less than the volume's remaining growth %d + WAL %d; when the disk fills, guest writes fail: free space on it", volumeID, p.cfg.StorageRoot, have, growth, storage.DefaultWALBytes) diff --git a/seaweed-block/core/frontend/durable/headroom_test.go b/seaweed-block/core/frontend/durable/headroom_test.go index 5463a8804a..ff352c4eea 100644 --- a/seaweed-block/core/frontend/durable/headroom_test.go +++ b/seaweed-block/core/frontend/durable/headroom_test.go @@ -2,6 +2,7 @@ package durable_test import ( "bytes" + "io/fs" "log" "os" "path/filepath" @@ -9,33 +10,52 @@ import ( "testing" "github.com/seaweedfs/seaweed-block/core/frontend/durable" + "github.com/seaweedfs/seaweed-block/core/storage" ) // A volume is not created on a durable root without room for its full size -// and its WAL (operator guide, Size a host; issue 484): a full local disk -// fails guest writes, so the cure comes before the first write. +// and its WAL (operator guide, Size a host; issue 484), and a refused create +// leaves nothing behind: no store, no chunk fresh marker or other sidecar. func TestCreateRefusesWithoutLocalHeadroom(t *testing.T) { defer durable.SetRootFreeForTest(8 << 20)() - root := t.TempDir() - p, err := durable.NewDurableProvider(durable.ProviderConfig{Impl: durable.ImplWALStore, StorageRoot: root, BlockSize: 4096, NumBlocks: 65536}, v1View()) - if err != nil { - t.Fatal(err) - } - t.Cleanup(func() { p.Close() }) - _, err = p.EnsureStorage("v1") - if err == nil || !strings.Contains(err.Error(), "8388608 bytes free") || !strings.Contains(err.Error(), "needs 335544320") { - t.Fatalf("create on a root with 8 MiB free: %v", err) - } - if left, _ := filepath.Glob(filepath.Join(root, "*", "*.bin")); len(left) != 0 { - t.Fatalf("a refused create left %v", left) + for _, impl := range []durable.ImplName{durable.ImplWALStore, durable.ImplWALStoreChunk} { + t.Run(string(impl), func(t *testing.T) { + root := t.TempDir() + cfg := durable.ProviderConfig{Impl: impl, StorageRoot: root, BlockSize: 4096, NumBlocks: 65536} + if impl == durable.ImplWALStoreChunk { + remote := storage.NewMemChunkRemote() + cfg.ChunkRemoteFor = func(string) (storage.ChunkRemote, error) { return remote, nil } + } + p, err := durable.NewDurableProvider(cfg, v1View()) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { p.Close() }) + _, err = p.EnsureStorage("v1") + if err == nil || !strings.Contains(err.Error(), "8388608 bytes free") || !strings.Contains(err.Error(), "needs 335544320") { + t.Fatalf("create on a root with 8 MiB free: %v", err) + } + var left []string + _ = filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error { + if err == nil && !d.IsDir() { + left = append(left, path) + } + return nil + }) + if len(left) != 0 { + t.Fatalf("a refused create left %v", left) + } + }) } } -// An existing volume still opens on a root that is short of headroom, with a -// loud warning: refusing it would leave the acknowledged data unserved. +// An existing volume still opens on a root short of headroom, with a loud +// warning when its remaining data growth plus the WAL exceed the free space. +// A fresh 256 MiB volume holds only its WAL: 256 MiB free is short of the +// 256 MiB of data still to grow plus the 64 MiB WAL; 330 MiB free is not. func TestOpenWarnsWithoutLocalHeadroom(t *testing.T) { root := t.TempDir() - cfg := durable.ProviderConfig{Impl: durable.ImplWALStore, StorageRoot: root, BlockSize: 4096, NumBlocks: 64} + cfg := durable.ProviderConfig{Impl: durable.ImplWALStore, StorageRoot: root, BlockSize: 4096, NumBlocks: 65536} p, err := durable.NewDurableProvider(cfg, v1View()) if err != nil { t.Fatal(err) @@ -44,19 +64,25 @@ func TestOpenWarnsWithoutLocalHeadroom(t *testing.T) { t.Fatal(err) } p.Close() - var out bytes.Buffer - log.SetOutput(&out) - t.Cleanup(func() { log.SetOutput(os.Stderr) }) - defer durable.SetRootFreeForTest(4096)() - p, err = durable.NewDurableProvider(cfg, v1View()) - if err != nil { - t.Fatal(err) - } - t.Cleanup(func() { p.Close() }) - if _, err := p.EnsureStorage("v1"); err != nil { - t.Fatalf("an existing volume did not open on a short root: %v", err) - } - if !strings.Contains(out.String(), "WARNING") || !strings.Contains(out.String(), "4096 bytes free") { - t.Fatalf("no headroom warning:\n%s", out.String()) + for _, c := range []struct { + free int64 + warn bool + }{{256 << 20, true}, {330 << 20, false}} { + var out bytes.Buffer + log.SetOutput(&out) + restore := durable.SetRootFreeForTest(c.free) + p, err := durable.NewDurableProvider(cfg, v1View()) + if err != nil { + t.Fatal(err) + } + if _, err := p.EnsureStorage("v1"); err != nil { + t.Fatalf("an existing volume did not open with %d bytes free: %v", c.free, err) + } + p.Close() + restore() + log.SetOutput(os.Stderr) + if got := strings.Contains(out.String(), "WARNING volume v1"); got != c.warn { + t.Fatalf("free %d: warning=%v, want %v:\n%s", c.free, got, c.warn, out.String()) + } } } diff --git a/seaweed-block/core/frontend/durable/provider.go b/seaweed-block/core/frontend/durable/provider.go index c18becd6b4..a6af566c84 100644 --- a/seaweed-block/core/frontend/durable/provider.go +++ b/seaweed-block/core/frontend/durable/provider.go @@ -845,6 +845,10 @@ func (p *DurableProvider) openOrCreate(volumeID string) (*volHandle, error) { if err := geometry.ValidateBlockGeometry(uint64(p.cfg.NumBlocks), uint64(p.cfg.BlockSize)); err != nil { return nil, err } + // Headroom before any sidecar: a refused create leaves nothing behind. + if err := p.refuseCreateWithoutHeadroom(volumeID); err != nil { + return nil, err + } if p.cfg.Impl == ImplWALStoreChunk { // Durable before the volume file exists: a crash anywhere between // here and the first successful attach leaves a fresh volume. @@ -989,7 +993,7 @@ func (p *DurableProvider) createFresh(volumeID, path string, impl ImplName) (*vo var err error if p.testWALStoreFactory != nil { ws, err = p.testWALStoreFactory(path, true) - } else if err = p.refuseCreateWithoutHeadroom(volumeID); err == nil { + } else { ws, err = storage.CreateWALStoreWithOptions(path, p.cfg.NumBlocks, p.cfg.BlockSize, storage.WALStoreOptions{ChunkBlocks: p.cfg.ChunkBlocks}) } if err != nil { diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index 020ad8ec8f..cb11815e9f 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -60,6 +60,7 @@ stateDiagram-v2 | From | To | Guard | Enforced in | Protects | |---|---|---|---|---| | — | Opened | v3 A/B descriptors and owned-map dependencies valid, exclusive file ownership acquired; legacy formats refused; backend starts not operational | `core/storage/walstore.go` `OpenWALStoreWithOptions`; `core/frontend/durable/provider.go` `openOrCreate` | `INV-WAL-OPGATE-001`, `INV-WAL-V3-ACTIVATION-001`, `INV-WAL-V3-DESCRIPTOR-001`, `INV-WAL-V3-MAP-PUBLISH-001` | +| — | (create refused) | a new volume needs the durable root's free space >= its size + WAL, checked before any sidecar or marker; an existing volume opens and warns when its remaining data growth + WAL exceed the free space | `core/frontend/durable/headroom.go`; `core/frontend/durable/provider.go` `openOrCreate` | `INV-LOCAL-HEADROOM-001` | | Opened | Recovering | the volume is open in the provider | `core/frontend/durable/provider.go` `RecoverVolume` | `INV-WAL-OPGATE-001` | | Recovering | Serving | v3 nonce/cursor-bound physical prefix satisfies its W/BASE gate; rollback fence and rebuilt bounds publish before reuse; `Recover` aborts/drains an open COW window before lower locks, holds the capture barrier and invalidates proofs at start/end; the frontend targets start, and `FrontendPrimaryReady` is reported, only once the backend admits I/O (a chunk volume: after its storage claim; attach-pending or fenced reports not ready with the reason); a workspace primary claims HEAD, listens and reports ready only while its lease guard permits now (`WorkspaceLeaseGuard.Held`; without a grant: `NotReadyReason=lease_not_held`, exit 75 after the start-time wait) | `core/storage/walstore_v3.go` `recoverV3`; `core/storage/walstore.go` `WALStore.Recover`; `cmd/blockvolume/frontend_gate.go` `awaitFrontendStart`; `core/frontend/durable/storage_adapter.go` `FirstServing`; `core/host/volume/status_server.go` `statusProjection`; `core/host/volume/workspace_lease.go` `Held` | `INV-WAL-SYNCED-RECOVERED-001`, `INV-WAL-REPLAY-LWW-001`, `INV-WAL-FRONTIER-GAP-001`, `INV-CUT-RECOVER-BARRIER-001`, `INV-WAL-V3-W-RECOVERY-001`, `INV-WAL-V3-FENCE-001`, `INV-WAL-V3-MAP-PUBLISH-001`, `INV-FE-PRIMARY-READY-OPERATIONAL-001`, `INV-WS-SERVE-LEASE-HELD-001` | | Recovering | RecoveryFailed | a WAL integrity failure or an I/O error; the backend stays not operational and the host blocks local readiness with `wal_corrupt` or `io_error` | `cmd/blockvolume/durable_startup.go` `openAndRecoverDurable`; `core/host/volume/recovery_watchdog.go` `LocalRecoveryHealthReason` | `INV-WAL-TYPED-FAILCLOSED-001`, `INV-WAL-OPGATE-001`, `INV-WAL-V3-W-RECOVERY-001` | From 24b94325743d17d206f47f3f3dd82b06c9cf5dc2 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 01:48:18 -0800 Subject: [PATCH 11/11] docs: INV-HOST-CUT-BUDGET-FALLBACK-001 statement under 300 characters Co-Authored-By: Claude Opus 5.5 --- seaweed-block/docs/design/invariants.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index 441f35e996..53548faedb 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -839,7 +839,7 @@ Notes: | `INV-HOST-CUT-BUDGET-RESERVE-001` | Each admitted slot, urgent included, carries at most PayloadBytes of cut payload and at most COWBytes of COW side bytes; a reservation beyond COWBytes revokes the slot and aborts its cut. | M7 admitted | `core/hostlimit/limiter.go` `Admit`, `ReserveCOW`; `core/storage/chunk_cut_budget.go` | `TestHostCOWCapAbortsCutAndRetainsPermitUntilJoin` (`core/storage/chunk_host_budget_test.go`); `TestSlotsUrgentAndJoinedRelease` (`core/hostlimit/limiter_test.go`) | `HostBudget` PayloadBound/SpillBound | ACTIVE | | `INV-HOST-CUT-BUDGET-SETTLE-001` | A slot's OS lock is released only after its cut's workers settle and Release is called; cancellation, hold expiry and limiter Close abort the cut but keep the slot until then. | M7 draining → joined → released | `core/hostlimit/limiter.go` `Release`, `releaseLoop`, `revoke`, `Close`; `core/storage/chunk_layer.go` `captureLocked` | `TestCOWAbortHoldsSlotUntilWorkerSettlement`, `TestHoldExpiryAndCloseDoNotSteal`, `TestKilledProcessReleasesButLiveHolderDoesNot` (`core/hostlimit/limiter_test.go`); `TestHostCOWCapAbortsCutAndRetainsPermitUntilJoin` (`core/storage/chunk_host_budget_test.go`) | `HostBudget` HeldUntilJoined | ACTIVE | | `INV-HOST-CUT-BUDGET-CONFIG-001` | A busy configuration lock or a mismatched pool configuration refuses every class, urgent included, with no fallback. | M7 free → admitted (refused) | `core/hostlimit/limiter.go` `pool`, `Admit` | `TestConfigurationLockContentionRefusesAllClasses` (`core/hostlimit/limiter_test.go`) | — | ACTIVE | -| `INV-HOST-CUT-BUDGET-FALLBACK-001` | Only urgent admissions (urgent move-final cuts and named seals) proceed while the pool is unavailable, on a per-process fallback that claims no host-wide bound, does not pace their uploads while only fallback leases live (there is no shared cap to protect; a healthy lease beside one stays paced), and is reported as fallback while any such lease lives. | M7 free → admitted (pool unavailable) | `core/hostlimit/limiter.go` `Admit`, `releaseLoop`, `WaitUpload` | `TestUnusablePoolClassPolicy`, `TestLastFallbackReleaseClearsActiveStatus`, `TestUrgentFallbackUploadIsNotPaced`, `TestFallbackDoesNotUnpaceAHealthyLease`, `TestConfigurationLockFailurePreservesPoolPolicy` (`core/hostlimit/limiter_test.go`); `TestChunkControl_NamedSnapshotUsesUrgentFallback` (`core/host/volume/chunk_control_adapter_test.go`) | `HostBudget` (fallback excluded) | ACTIVE | +| `INV-HOST-CUT-BUDGET-FALLBACK-001` | Only urgent admissions (urgent move-final cuts and named seals) proceed while the pool is unavailable, on a per-process fallback that claims no host-wide bound, leaves uploads unpaced while only fallback leases live, and is reported as fallback while any such lease lives. | M7 free → admitted (pool unavailable) | `core/hostlimit/limiter.go` `Admit`, `releaseLoop`, `WaitUpload` | `TestUnusablePoolClassPolicy`, `TestLastFallbackReleaseClearsActiveStatus`, `TestUrgentFallbackUploadIsNotPaced`, `TestFallbackDoesNotUnpaceAHealthyLease`, `TestConfigurationLockFailurePreservesPoolPolicy` (`core/hostlimit/limiter_test.go`); `TestChunkControl_NamedSnapshotUsesUrgentFallback` (`core/host/volume/chunk_control_adapter_test.go`) | `HostBudget` (fallback excluded) | ACTIVE | | `INV-HOST-CUT-BUDGET-PACING-001` | A process's upload pacing debt carries across its own leases, and a new process starts with no debt. | M7 admitted (upload pacing) | `core/hostlimit/limiter.go` `WaitUpload` | `TestPacingDebtSurvivesOwnLeaseTurnover`, `TestPacingFreshProcessesDoNotShareDebt` (`core/hostlimit/limiter_test.go`) | — | ACTIVE | | `INV-HOST-POOL-CONFIG-001` | A pool configuration is invisible until its complete synced temporary file is atomically renamed under the OS configuration lock. A killed initializer cannot leave a partial visible configuration that strands successors. | M7 configuration preparation/publication | `core/hostlimit` `publishConfig` | `TestKilledInitializerDoesNotPublishPartialConfiguration` | `HostBudget` NoPartialConfig/ConfigBeforeAdmission (filesystem atomicity checked natively) | ACTIVE | | `INV-HOST-URGENT-PENDING-001` | While an urgent cut holds its slot, or a caller holds HoldUrgentPending, every Normal admission on the host is refused with ErrUrgentPending (a held-slot wait); urgent admissions still run. | M7 host cut admission (Normal before a slot) | `core/hostlimit/limiter.go` `pool`, `Admit`; `core/hostlimit/pending.go` `HoldUrgentPending` | `TestNormalWaitsWhileUrgentPendingIsHeld`, `TestUrgentLeaseHoldsThePendingSignal` (`core/hostlimit/pending_test.go`); `TestSlotsUrgentAndJoinedRelease` (`core/hostlimit/limiter_test.go`) | — | ACTIVE |