mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
86ac412577
commit
d8d1f3b4d2
7 files changed
+131
-2
No files matched your search
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -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 }
|
||||
}
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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 }
|
||||
@@ -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.
|
||||
|
||||
Reference in new issue
Block a user