test+docs: headroom tests clean up at once and fail on walk errors; M1 diagram edge CreateRefused

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-11-23 02:33:12 -08:00
1 parent 2129a73620
commit 05abcee55b
2 files changed
+30 -22

No files matched your search

@@ -4,7 +4,6 @@ import (
"bytes"
"io/fs"
"log"
"os"
"path/filepath"
"strings"
"testing"
@@ -36,12 +35,17 @@ func TestCreateRefusesWithoutLocalHeadroom(t *testing.T) {
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() {
if err := filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if !d.IsDir() {
left = append(left, path)
}
return nil
})
}); err != nil {
t.Fatalf("walk %s: %v", root, err)
}
if len(left) != 0 {
t.Fatalf("a refused create left %v", left)
}
@@ -65,24 +69,27 @@ func TestOpenWarnsWithoutLocalHeadroom(t *testing.T) {
}
p.Close()
for _, c := range []struct {
name string
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())
}
}{{"256MiB-free-warns", 256 << 20, true}, {"330MiB-free-quiet", 330 << 20, false}} {
t.Run(c.name, func(t *testing.T) {
var out bytes.Buffer
prior := log.Writer()
log.SetOutput(&out)
t.Cleanup(func() { log.SetOutput(prior) })
t.Cleanup(durable.SetRootFreeForTest(c.free))
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 with %d bytes free: %v", c.free, err)
}
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())
}
})
}
}
+2 -1
View File
@@ -45,6 +45,7 @@ The local storage engine and the durable backend in front of it. Diagrams in the
```mermaid
stateDiagram-v2
[*] --> Opened: OpenWALStore / CreateWALStore
[*] --> CreateRefused: CreateWALStore without local headroom (free < size + WAL)
Opened --> Recovering: RecoverVolume
Recovering --> Serving: Recover ok, backend operational; workspace primary: lease held, then HEAD claim, then frontends listen, then ready
Serving --> Closed: runtime HEAD fence, exit 78 head_fenced
@@ -60,7 +61,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` |
| — | CreateRefused | 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` |