Files
seaweedfs/seaweed-block/cmd/blockvolume/existing_geometry_compat_test.go
T
pingqiuandClaude Opus 5.5 ab747bfa47 change: cut over to the content-named store and delete the legacy store
The runtime stores each volume in one content-named layout on the filer:
immutable chunks, segments and roots are ordinary filer files, and one
HEAD entry per volume carries every conditional commit. A holder claims
HEAD under its granted epoch and claim id, cuts in its own session,
commits by HEAD generation and position, and is fenced when its identity
moves. Catalog, restore, snapshot, retention, cleaning, verify and volume
delete run through the layout kernel; the master mints the layout
identity, reads HEAD proofs and holds the delete reservation and lease
barrier. The legacy store, its intents and its compatibility paths are
removed; existing stores are recreated, not converted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 14:59:23 -08:00

136 lines
4.1 KiB
Go

package main
import (
"bytes"
"context"
"errors"
"os"
"path/filepath"
"strconv"
"testing"
"time"
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/layout"
"github.com/seaweedfs/seaweed-block/core/frontend/durable"
"github.com/seaweedfs/seaweed-block/core/storage"
)
func TestExistingDurableVolumeIgnoresCreateGeometry(t *testing.T) {
root := t.TempDir()
s, err := storage.CreateWALStore(filepath.Join(root, "v1.bin"), 16, 4096)
if err != nil {
t.Fatal(err)
}
want := bytes.Repeat([]byte{0x73}, 4096)
if _, err = s.Write(0, want); err != nil {
s.Close()
t.Fatal(err)
}
if _, err = s.Sync(); err != nil {
s.Close()
t.Fatal(err)
}
if err = s.Close(); err != nil {
t.Fatal(err)
}
args := append(phase150RequiredBlockvolumeArgs(), "--volume-id=v1", "--durable-root="+root, "--durable-impl=walstore", "--durable-blocks=4294967295", "--durable-blocksize=8192")
f, err := parseFlags(args)
if err != nil {
t.Fatalf("existing storage must ignore create-only geometry: %v", err)
}
blocks, blockSize, err := durableCreateGeometry(f)
if err != nil {
t.Fatal(err)
}
if blocks != 0 {
t.Fatal("existing file must select open-only mode")
}
p, err := durable.NewDurableProvider(durable.ProviderConfig{Impl: durable.ImplName(f.durableImpl), StorageRoot: f.durableRoot, NumBlocks: blocks, BlockSize: blockSize}, healthyView{})
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { p.Close() })
result, _, err := openAndRecoverDurable(p, &spyHost{}, "v1", 5*time.Second)
if err != nil || result != durableStartupReady {
t.Fatalf("existing recovery: %v %v", result, err)
}
st, err := p.EnsureStorage("v1")
if err != nil {
t.Fatal(err)
}
if st.NumBlocks() != 16 || st.BlockSize() != 4096 {
t.Fatalf("existing geometry changed: %d x %d", st.NumBlocks(), st.BlockSize())
}
got := make([]byte, 4096)
b, err := p.Open(context.Background(), "v1")
if err != nil {
t.Fatal(err)
}
if _, err = b.Read(context.Background(), 0, got); err != nil {
t.Fatal(err)
}
if !bytes.Equal(got, want) {
t.Fatal("existing bytes changed")
}
}
func TestExistingDurableVolumeDisappearsDoesNotCreateFromIgnoredFlags(t *testing.T) {
if strconv.IntSize < 64 {
t.Skip("64-bit CLI uint overflow case")
}
for _, impl := range []durable.ImplName{durable.ImplWALStore, durable.ImplWALStoreChunk} {
t.Run(string(impl), func(t *testing.T) {
root := t.TempDir()
path := filepath.Join(root, "v1.bin")
s, err := storage.CreateWALStore(path, 16, 4096)
if err != nil {
t.Fatal(err)
}
if err = s.Close(); err != nil {
t.Fatal(err)
}
args := append(phase150RequiredBlockvolumeArgs(), "--volume-id=v1", "--durable-root="+root, "--durable-impl="+string(impl), "--durable-blocks=4294967297")
if impl == durable.ImplWALStoreChunk {
args = append(args, "--chunk-filer=127.0.0.1:18888")
}
f, err := parseFlags(args)
if err != nil {
t.Fatal(err)
}
blocks, bs, err := durableCreateGeometry(f)
if err != nil {
t.Fatal(err)
}
if blocks != 0 {
t.Fatal("not open-only")
}
if err = os.Remove(path); err != nil {
t.Fatal(err)
}
if _, _, err = durableCreateGeometry(f); err == nil {
t.Fatal("fresh recheck accepted original overflowing count")
}
cfg := durable.ProviderConfig{Impl: impl, StorageRoot: root, NumBlocks: blocks, BlockSize: bs}
if impl == durable.ImplWALStoreChunk {
unexpected := errors.New("unexpected layout access for missing open-only volume")
cfg.ChunkLayoutHeadFor = func(string) (layout.StartStore, error) { return nil, unexpected }
cfg.ChunkLayoutRemoteFor = func(string, layout.HolderID) (storage.ChunkRemote, error) { return nil, unexpected }
}
p, err := durable.NewDurableProvider(cfg, healthyView{})
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { p.Close() })
if _, err = p.EnsureStorage("v1"); err == nil {
t.Fatal("created replacement from ignored flags")
}
if _, err = os.Stat(path); !os.IsNotExist(err) {
t.Fatalf("replacement file exists: %v", err)
}
if _, err = os.Stat(path + ".chunkfresh"); !os.IsNotExist(err) {
t.Fatalf("open-only refusal left a fresh marker: %v", err)
}
})
}
}