mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 18:47:20 +01:00
Merge pull request #174 from seaweedfs/feat/walstore-default-smartwal-experimental
blockvolume: walstore is the default for new volumes; smartwal is experimental
This commit is contained in:
commit
72eefdbe28
6 files changed
+354
-43
No files matched your search
@@ -143,6 +143,14 @@ default, a release claim or a production path.
|
||||
control broker, which is not done.
|
||||
- Crash-restart recovery of a ublk server. A crashed server fails closed.
|
||||
- Multi-replica workspaces combined with chunk snapshots.
|
||||
- The `smartwal` storage engine. It is experimental: in-place overwrites
|
||||
have no rollback on a torn write, blocks lose their per-block CRC once
|
||||
their ring records recycle, the handling of a corrupted committed record
|
||||
is still open, and it has no chunk-snapshot support. New volumes use
|
||||
`walstore`; `blockvolume --durable-impl` defaults to auto, which creates
|
||||
new volumes as `walstore` and opens an existing volume with its on-disk
|
||||
format. A `walstore-chunk` volume is refused under auto and needs
|
||||
`--durable-impl=walstore-chunk` with its remote configuration.
|
||||
|
||||
## Kubernetes block storage (alpha)
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
// --durable-impl defaults to empty (auto): new volumes are walstore, and an
|
||||
// existing volume opens with its on-disk format. smartwal is experimental
|
||||
// and only used when chosen explicitly or found on disk.
|
||||
func TestBlockvolumeDurableImplDefaultIsAuto(t *testing.T) {
|
||||
f, err := parseFlags(phase150RequiredBlockvolumeArgs())
|
||||
if err != nil {
|
||||
t.Fatalf("parseFlags: %v", err)
|
||||
}
|
||||
if f.durableImpl != "" {
|
||||
t.Fatalf("durableImpl default=%q, want empty (auto)", f.durableImpl)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBlockvolumeDurableImplExplicitValues(t *testing.T) {
|
||||
for _, impl := range []string{"walstore", "smartwal", "parallel-walstore"} {
|
||||
args := append(phase150RequiredBlockvolumeArgs(), "--durable-root=/tmp/sw-block", "--durable-impl="+impl)
|
||||
f, err := parseFlags(args)
|
||||
if err != nil {
|
||||
t.Fatalf("--durable-impl=%s: %v", impl, err)
|
||||
}
|
||||
if f.durableImpl != impl {
|
||||
t.Fatalf("durableImpl=%q, want %q", f.durableImpl, impl)
|
||||
}
|
||||
}
|
||||
args := append(phase150RequiredBlockvolumeArgs(), "--durable-impl=bogus")
|
||||
if _, err := parseFlags(args); err == nil {
|
||||
t.Fatal("--durable-impl=bogus accepted")
|
||||
}
|
||||
}
|
||||
@@ -103,12 +103,13 @@ type flags struct {
|
||||
|
||||
// Durable-backend flags. When --durable-root is set, the iSCSI
|
||||
// and NVMe providers use DurableProvider instead of memback.
|
||||
// --durable-impl selects smartwal, walstore, or the explicit
|
||||
// parallel-walstore candidate (default smartwal).
|
||||
// --durable-impl selects walstore, smartwal (experimental), or the
|
||||
// explicit parallel-walstore candidate. Empty (default) = auto: an
|
||||
// existing volume opens with its on-disk format, a new one is walstore.
|
||||
// --durable-blocks + --durable-blocksize are used on first-time
|
||||
// storage create.
|
||||
durableRoot string
|
||||
durableImpl string // "smartwal" | "walstore" | "parallel-walstore" | "walstore-chunk"
|
||||
durableImpl string // "" (auto) | "walstore" | "smartwal" | "parallel-walstore" | "walstore-chunk"
|
||||
// --chunk-*: the SeaweedFS remote of --durable-impl=walstore-chunk.
|
||||
chunk chunkFlags
|
||||
durableBlocks uint
|
||||
@@ -185,7 +186,7 @@ func parseFlags(args []string) (flags, error) {
|
||||
fs.IntVar(&f.ublkQueues, "ublk-queues", 0, "ublk hardware queues (one server thread each); 0 = default 1. Requires --ublk-device")
|
||||
fs.IntVar(&f.ublkQueueDepth, "ublk-queue-depth", 0, "ublk in-flight requests per queue; 0 = default 64. Requires --ublk-device")
|
||||
fs.StringVar(&f.durableRoot, "durable-root", "", "directory for persistent storage files; empty = memback (non-durable)")
|
||||
fs.StringVar(&f.durableImpl, "durable-impl", "smartwal", "LogicalStorage impl: smartwal (default), walstore, opt-in parallel-walstore, or opt-in walstore-chunk (walstore published to SeaweedFS; proof of concept); ignored unless --durable-root is set")
|
||||
fs.StringVar(&f.durableImpl, "durable-impl", "", "LogicalStorage impl: empty (default) = auto: an existing volume opens with its on-disk format (a walstore-chunk root needs the explicit walstore-chunk selector), a new volume is created as walstore; or walstore, smartwal (experimental), opt-in parallel-walstore, or opt-in walstore-chunk (walstore published to SeaweedFS; proof of concept); ignored unless --durable-root is set")
|
||||
fs.StringVar(&f.chunk.filer, "chunk-filer", "", "walstore-chunk: SeaweedFS filer gRPC address host:port")
|
||||
fs.StringVar(&f.chunk.path, "chunk-path", defaultChunkPath, "walstore-chunk: filer directory holding one directory per volume (HEAD and chunk key bindings)")
|
||||
fs.StringVar(&f.chunk.collection, "chunk-collection", "", "walstore-chunk: collection for chunk needles (empty = filer default / storage rule)")
|
||||
@@ -243,9 +244,9 @@ func parseFlags(args []string) (flags, error) {
|
||||
return flags{}, err
|
||||
}
|
||||
switch f.durableImpl {
|
||||
case "smartwal", "walstore", "parallel-walstore", "walstore-chunk":
|
||||
case "", "walstore", "smartwal", "parallel-walstore", "walstore-chunk":
|
||||
default:
|
||||
return flags{}, fmt.Errorf("--durable-impl=%q invalid; want smartwal, walstore, parallel-walstore, or walstore-chunk", f.durableImpl)
|
||||
return flags{}, fmt.Errorf("--durable-impl=%q invalid; want empty (auto), walstore, smartwal, parallel-walstore, or walstore-chunk", f.durableImpl)
|
||||
}
|
||||
if f.workspaceLease && (f.durableRoot == "" || f.durableImpl != "walstore-chunk") {
|
||||
return flags{}, fmt.Errorf("--workspace-lease requires --durable-root and --durable-impl=walstore-chunk")
|
||||
|
||||
@@ -33,6 +33,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -48,7 +49,15 @@ import (
|
||||
type ImplName string
|
||||
|
||||
const (
|
||||
ImplSmartWAL ImplName = "smartwal" // production default per PM direction
|
||||
// ImplAuto (the zero value) opens an existing volume with the
|
||||
// implementation its on-disk superblock names, and creates a new
|
||||
// volume as ImplWALStore.
|
||||
ImplAuto ImplName = ""
|
||||
// ImplSmartWAL is experimental: in-place overwrites have no rollback
|
||||
// on a torn write, blocks lose their per-block CRC once their ring
|
||||
// records recycle, and it has no chunk-snapshot support. Selected only
|
||||
// explicitly, or by auto for an existing smartwal volume.
|
||||
ImplSmartWAL ImplName = "smartwal"
|
||||
ImplWALStore ImplName = "walstore"
|
||||
// ImplParallelWALStore is the explicit Phase 167 candidate. It remains
|
||||
// opt-in until the full recovery, replication, and mounted close gates pass.
|
||||
@@ -75,7 +84,8 @@ var ErrVolumeNotOpen = errors.New("durable: volume not opened")
|
||||
// ProviderConfig configures a DurableProvider.
|
||||
type ProviderConfig struct {
|
||||
// Impl selects which LogicalStorage implementation to open or
|
||||
// create. Zero value (""): ImplSmartWAL (production default).
|
||||
// create. Zero value (ImplAuto): an existing volume opens with its
|
||||
// on-disk implementation, and a new volume is created as walstore.
|
||||
Impl ImplName
|
||||
|
||||
// StorageRoot is the directory under which per-volume files
|
||||
@@ -182,6 +192,7 @@ type volHandle struct {
|
||||
storage storage.LogicalStorage
|
||||
backend *StorageBackend
|
||||
path string
|
||||
impl ImplName // the resolved implementation, never ImplAuto
|
||||
|
||||
// ImplWALStoreChunk. fresh: the local volume is new and starts from
|
||||
// the remote HEAD. It mirrors the durable fresh marker beside the
|
||||
@@ -253,11 +264,8 @@ func NewDurableProvider(cfg ProviderConfig, view frontend.ProjectionView) (*Dura
|
||||
if cfg.StorageRoot == "" {
|
||||
return nil, fmt.Errorf("durable: ProviderConfig.StorageRoot required")
|
||||
}
|
||||
if cfg.Impl == "" {
|
||||
cfg.Impl = ImplSmartWAL
|
||||
}
|
||||
if cfg.Impl != ImplSmartWAL && cfg.Impl != ImplWALStore && cfg.Impl != ImplParallelWALStore && cfg.Impl != ImplWALStoreChunk {
|
||||
return nil, fmt.Errorf("durable: unknown impl %q (want %q, %q, %q, or %q)",
|
||||
if cfg.Impl != ImplAuto && cfg.Impl != ImplSmartWAL && cfg.Impl != ImplWALStore && cfg.Impl != ImplParallelWALStore && cfg.Impl != ImplWALStoreChunk {
|
||||
return nil, fmt.Errorf("durable: unknown impl %q (want auto (empty), %q, %q, %q, or %q)",
|
||||
cfg.Impl, ImplSmartWAL, ImplWALStore, ImplParallelWALStore, ImplWALStoreChunk)
|
||||
}
|
||||
if cfg.Impl == ImplWALStoreChunk && cfg.ChunkRemoteFor == nil {
|
||||
@@ -503,12 +511,11 @@ func (p *DurableProvider) DurableStatuses() []VolumeStatus {
|
||||
chunks[volumeID] = chunkView{layer: h.chunk, awaiting: h.waitGen != 0}
|
||||
}
|
||||
}
|
||||
impl := string(p.cfg.Impl)
|
||||
p.mu.Unlock()
|
||||
|
||||
out := make([]VolumeStatus, 0, len(handles))
|
||||
for volumeID, h := range handles {
|
||||
st := h.backend.durableStatus(volumeID, h.path, impl)
|
||||
st := h.backend.durableStatus(volumeID, h.path, string(h.impl))
|
||||
if cv, ok := chunks[volumeID]; ok {
|
||||
cs := &ChunkStatus{AwaitingAuthority: cv.awaiting}
|
||||
if cv.layer != nil {
|
||||
@@ -551,12 +558,26 @@ func (p *DurableProvider) openOrCreate(volumeID string) (*volHandle, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("durable: stat %s: %w", path, err)
|
||||
}
|
||||
if p.cfg.Impl == ImplAuto {
|
||||
// A walstore-chunk volume shares walstore's on-disk format, and its
|
||||
// authoritative bytes may live only in the remote HEAD. Opened as
|
||||
// plain walstore it would serve local (possibly absent) extents, so
|
||||
// auto refuses any root carrying chunk metadata; it never deletes
|
||||
// or converts it.
|
||||
if side, err := chunkSidecars(path); err != nil {
|
||||
return nil, err
|
||||
} else if len(side) > 0 {
|
||||
return nil, fmt.Errorf("%w: %s is a chunk-managed volume (%s present); auto cannot open it: set --durable-impl=walstore-chunk with its remote configuration",
|
||||
ErrImplKindMismatch, path, strings.Join(side, ", "))
|
||||
}
|
||||
}
|
||||
|
||||
if exists {
|
||||
if err := p.verifyImplOnDisk(path); err != nil {
|
||||
impl, err := p.verifyImplOnDisk(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
h, err := p.openExisting(volumeID, path)
|
||||
h, err := p.openExisting(volumeID, path, impl)
|
||||
if err != nil || p.cfg.Impl != ImplWALStoreChunk {
|
||||
return h, err
|
||||
}
|
||||
@@ -573,26 +594,31 @@ func (p *DurableProvider) openOrCreate(volumeID string) (*volHandle, error) {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
h, err := p.createFresh(volumeID, path)
|
||||
impl := p.cfg.Impl
|
||||
if impl == ImplAuto {
|
||||
impl = ImplWALStore
|
||||
}
|
||||
h, err := p.createFresh(volumeID, path, impl)
|
||||
if err == nil && p.cfg.Impl == ImplWALStoreChunk {
|
||||
h.fresh = true
|
||||
}
|
||||
return h, err
|
||||
}
|
||||
|
||||
// verifyImplOnDisk peeks the 4-byte magic at offset 0 and returns
|
||||
// ErrImplKindMismatch if it doesn't match the configured selector.
|
||||
// Runs BEFORE the storage-level Open so the error message is
|
||||
// selector-aware instead of cryptic magic-mismatch.
|
||||
func (p *DurableProvider) verifyImplOnDisk(path string) error {
|
||||
// verifyImplOnDisk peeks the 4-byte magic at offset 0 and returns the
|
||||
// implementation to open the volume with: the on-disk one under
|
||||
// ImplAuto, else the configured selector, with ErrImplKindMismatch if
|
||||
// the two differ. Runs BEFORE the storage-level Open so the error
|
||||
// message is selector-aware instead of cryptic magic-mismatch.
|
||||
func (p *DurableProvider) verifyImplOnDisk(path string) (ImplName, error) {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("durable: open for magic peek: %w", err)
|
||||
return "", fmt.Errorf("durable: open for magic peek: %w", err)
|
||||
}
|
||||
defer f.Close()
|
||||
magic := make([]byte, 4)
|
||||
if _, err := io.ReadFull(f, magic); err != nil {
|
||||
return fmt.Errorf("durable: read magic: %w", err)
|
||||
return "", fmt.Errorf("durable: read magic: %w", err)
|
||||
}
|
||||
diskImpl, ok := magicToImpl(string(magic))
|
||||
if !ok {
|
||||
@@ -604,17 +630,20 @@ func (p *DurableProvider) verifyImplOnDisk(path string) error {
|
||||
}
|
||||
}
|
||||
if !ok {
|
||||
return fmt.Errorf("%w: unrecognized magic %q at %s",
|
||||
return "", fmt.Errorf("%w: unrecognized magic %q at %s",
|
||||
ErrImplKindMismatch, string(magic), path)
|
||||
}
|
||||
if p.cfg.Impl == ImplAuto {
|
||||
return diskImpl, nil
|
||||
}
|
||||
if diskImpl == ImplWALStore && p.cfg.Impl == ImplWALStoreChunk {
|
||||
return nil // a chunk volume is a walstore file
|
||||
return ImplWALStoreChunk, nil // a chunk volume is a walstore file
|
||||
}
|
||||
if diskImpl != p.cfg.Impl {
|
||||
return fmt.Errorf("%w: selector=%s on-disk=%s at %s",
|
||||
return "", fmt.Errorf("%w: selector=%s on-disk=%s at %s",
|
||||
ErrImplKindMismatch, p.cfg.Impl, diskImpl, path)
|
||||
}
|
||||
return nil
|
||||
return diskImpl, nil
|
||||
}
|
||||
|
||||
// magicToImpl maps a 4-byte magic to ImplName. Hardcoded per
|
||||
@@ -633,10 +662,11 @@ func magicToImpl(magic string) (ImplName, bool) {
|
||||
}
|
||||
}
|
||||
|
||||
// openExisting dispatches to the selector-matching Open function.
|
||||
func (p *DurableProvider) openExisting(volumeID, path string) (*volHandle, error) {
|
||||
// openExisting dispatches to the Open function of impl, the volume's
|
||||
// resolved implementation.
|
||||
func (p *DurableProvider) openExisting(volumeID, path string, impl ImplName) (*volHandle, error) {
|
||||
var s storage.LogicalStorage
|
||||
switch p.cfg.Impl {
|
||||
switch impl {
|
||||
case ImplWALStore, ImplWALStoreChunk:
|
||||
ws, err := storage.OpenWALStore(path)
|
||||
if err != nil {
|
||||
@@ -668,21 +698,21 @@ func (p *DurableProvider) openExisting(volumeID, path string) (*volHandle, error
|
||||
}
|
||||
s = pw
|
||||
default:
|
||||
return nil, fmt.Errorf("durable: unknown impl %q", p.cfg.Impl)
|
||||
return nil, fmt.Errorf("durable: unknown impl %q", impl)
|
||||
}
|
||||
return p.wrap(volumeID, path, s)
|
||||
return p.wrap(volumeID, path, impl, s)
|
||||
}
|
||||
|
||||
// createFresh dispatches to the selector-matching Create function.
|
||||
// Requires cfg.NumBlocks to be non-zero (can't create without
|
||||
// knowing geometry).
|
||||
func (p *DurableProvider) createFresh(volumeID, path string) (*volHandle, error) {
|
||||
// createFresh dispatches to the Create function of impl, the volume's
|
||||
// resolved implementation. Requires cfg.NumBlocks to be non-zero
|
||||
// (can't create without knowing geometry).
|
||||
func (p *DurableProvider) createFresh(volumeID, path string, impl ImplName) (*volHandle, error) {
|
||||
if p.cfg.NumBlocks == 0 {
|
||||
return nil, fmt.Errorf("durable: NumBlocks=0; cannot create storage for %s (use open-existing mode)",
|
||||
volumeID)
|
||||
}
|
||||
var s storage.LogicalStorage
|
||||
switch p.cfg.Impl {
|
||||
switch impl {
|
||||
case ImplWALStore, ImplWALStoreChunk:
|
||||
ws, err := storage.CreateWALStore(path, p.cfg.NumBlocks, p.cfg.BlockSize)
|
||||
if err != nil {
|
||||
@@ -712,15 +742,15 @@ func (p *DurableProvider) createFresh(volumeID, path string) (*volHandle, error)
|
||||
}
|
||||
s = pw
|
||||
default:
|
||||
return nil, fmt.Errorf("durable: unknown impl %q", p.cfg.Impl)
|
||||
return nil, fmt.Errorf("durable: unknown impl %q", impl)
|
||||
}
|
||||
return p.wrap(volumeID, path, s)
|
||||
return p.wrap(volumeID, path, impl, s)
|
||||
}
|
||||
|
||||
// wrap builds a StorageBackend around an opened LogicalStorage
|
||||
// using the current projection's Identity. Backend starts
|
||||
// operational=false; the caller flips via RecoverVolume.
|
||||
func (p *DurableProvider) wrap(volumeID, path string, s storage.LogicalStorage) (*volHandle, error) {
|
||||
func (p *DurableProvider) wrap(volumeID, path string, impl ImplName, s storage.LogicalStorage) (*volHandle, error) {
|
||||
proj := p.view.Projection()
|
||||
id := frontend.Identity{
|
||||
VolumeID: proj.VolumeID,
|
||||
@@ -729,7 +759,7 @@ func (p *DurableProvider) wrap(volumeID, path string, s storage.LogicalStorage)
|
||||
EndpointVersion: proj.EndpointVersion,
|
||||
}
|
||||
b := NewStorageBackend(s, p.view, id)
|
||||
return &volHandle{storage: s, backend: b, path: path}, nil
|
||||
return &volHandle{storage: s, backend: b, path: path, impl: impl}, nil
|
||||
}
|
||||
|
||||
// RecoverVolume runs LogicalStorage.Recover for an open volume
|
||||
@@ -842,5 +872,29 @@ func fileExists(path string) (bool, error) {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// chunkSidecars lists the walstore-chunk metadata files beside a volume
|
||||
// file: everything named <volume file>.chunk* (the fresh marker, the dirty
|
||||
// bitmap and its deltas, the presence map). Directories are ignored.
|
||||
func chunkSidecars(path string) ([]string, error) {
|
||||
dir, base := filepath.Split(path)
|
||||
if dir == "" {
|
||||
dir = "."
|
||||
}
|
||||
entries, err := os.ReadDir(dir)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, fmt.Errorf("durable: list %s for chunk metadata: %w", dir, err)
|
||||
}
|
||||
var out []string
|
||||
for _, e := range entries {
|
||||
if !e.IsDir() && strings.HasPrefix(e.Name(), base+".chunk") {
|
||||
out = append(out, e.Name())
|
||||
}
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Compile-time check.
|
||||
var _ frontend.Provider = (*DurableProvider)(nil)
|
||||
@@ -0,0 +1,100 @@
|
||||
package durable_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/durable"
|
||||
"github.com/seaweedfs/seaweed-block/core/storage"
|
||||
)
|
||||
|
||||
// A walstore-chunk volume has walstore's on-disk format, and on a fresh host
|
||||
// its published bytes may exist only in the remote HEAD. Auto must not open
|
||||
// such a root as plain walstore (no read-miss or fencing hooks: it would
|
||||
// serve the local, absent extent). It refuses, and the explicit
|
||||
// walstore-chunk selector with the remote still reads the exact bytes.
|
||||
func TestDurableProvider_AutoRefusesLazyChunkRoot(t *testing.T) {
|
||||
remote := storage.NewMemChunkRemote()
|
||||
view := v1View()
|
||||
|
||||
// Host A publishes a nonzero block.
|
||||
hostA := chunkProvider(t, t.TempDir(), remote, view, 0)
|
||||
sA := openRecovered(t, hostA)
|
||||
if _, err := sA.Write(33, block(0x33)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := hostA.MakeVolumeRemoteDurable(context.Background(), "v1", 1); err != nil {
|
||||
t.Fatalf("MakeVolumeRemoteDurable: %v", err)
|
||||
}
|
||||
|
||||
// Host B attaches lazily from HEAD and closes before LBA 33 is fetched.
|
||||
rootB := t.TempDir()
|
||||
hostB := chunkProvider(t, rootB, remote, view, 0)
|
||||
openRecovered(t, hostB)
|
||||
if err := hostB.Close(); err != nil {
|
||||
t.Fatalf("close host B: %v", err)
|
||||
}
|
||||
|
||||
// Restart host B with no selector: auto must refuse before any I/O.
|
||||
auto := autoProvider(t, rootB, durable.ImplAuto)
|
||||
if _, err := auto.EnsureStorage("v1"); err == nil {
|
||||
got := []byte("not read")
|
||||
if _, rerr := auto.RecoverVolume(context.Background(), "v1"); rerr == nil {
|
||||
if s, serr := auto.EnsureStorage("v1"); serr == nil {
|
||||
got, _ = s.Read(33)
|
||||
}
|
||||
}
|
||||
t.Fatalf("auto opened a chunk-managed root as plain walstore; LBA 33 reads %x... (want HEAD byte 33)", got[:4])
|
||||
} else if !errors.Is(err, durable.ErrImplKindMismatch) {
|
||||
t.Fatalf("auto on a chunk root: %v, want ErrImplKindMismatch", err)
|
||||
}
|
||||
_ = auto.Close()
|
||||
|
||||
// The explicit selector with the remote reopens and reads HEAD's bytes.
|
||||
explicit := chunkProvider(t, rootB, remote, view, 0)
|
||||
s := openRecovered(t, explicit)
|
||||
if got, err := s.Read(33); err != nil || !bytes.Equal(got, block(0x33)) {
|
||||
t.Fatalf("explicit walstore-chunk reopen read: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Any root with chunk metadata is refused under auto, not only a lazy one:
|
||||
// a chunk volume created and attached on this host.
|
||||
func TestDurableProvider_AutoRefusesAnyChunkRoot(t *testing.T) {
|
||||
remote := storage.NewMemChunkRemote()
|
||||
root := t.TempDir()
|
||||
p := chunkProvider(t, root, remote, v1View(), 0)
|
||||
openRecovered(t, p)
|
||||
if err := p.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
auto := autoProvider(t, root, durable.ImplAuto)
|
||||
if _, err := auto.EnsureStorage("v1"); !errors.Is(err, durable.ErrImplKindMismatch) {
|
||||
t.Fatalf("auto on a root with chunk metadata: %v, want ErrImplKindMismatch", err)
|
||||
}
|
||||
}
|
||||
|
||||
// A chunk fresh marker without a volume file (a chunk create interrupted
|
||||
// before the file existed) is refused rather than turned into a new plain
|
||||
// walstore volume, and the marker is left in place.
|
||||
func TestDurableProvider_AutoRefusesStrayChunkFreshMarker(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
marker := filepath.Join(root, "v1.bin.chunkfresh")
|
||||
if err := os.WriteFile(marker, nil, 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
auto := autoProvider(t, root, durable.ImplAuto)
|
||||
if _, err := auto.EnsureStorage("v1"); !errors.Is(err, durable.ErrImplKindMismatch) {
|
||||
t.Fatalf("auto with a stray chunk fresh marker: %v, want ErrImplKindMismatch", err)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(root, "v1.bin")); !os.IsNotExist(err) {
|
||||
t.Fatalf("auto created a volume file beside a chunk marker: %v", err)
|
||||
}
|
||||
if _, err := os.Stat(marker); err != nil {
|
||||
t.Fatalf("chunk fresh marker removed: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
package durable_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend"
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/durable"
|
||||
)
|
||||
|
||||
// The empty selector (ImplAuto) creates new volumes as walstore and opens an
|
||||
// existing volume with the implementation its on-disk superblock names, so
|
||||
// volumes created under the old smartwal default keep opening. An explicit
|
||||
// selector still refuses a different on-disk format
|
||||
// (TestT3b_DurableProvider_Open_ImplKindMismatch_FailsFast).
|
||||
|
||||
func autoProvider(t *testing.T, root string, impl durable.ImplName) *durable.DurableProvider {
|
||||
t.Helper()
|
||||
id := frontend.Identity{VolumeID: "v1", ReplicaID: "r1", Epoch: 1, EndpointVersion: 1}
|
||||
p, err := durable.NewDurableProvider(durable.ProviderConfig{
|
||||
Impl: impl,
|
||||
StorageRoot: root,
|
||||
BlockSize: 4096,
|
||||
NumBlocks: 16,
|
||||
}, newStubView(healthyProj(id)))
|
||||
if err != nil {
|
||||
t.Fatalf("NewDurableProvider(%q): %v", impl, err)
|
||||
}
|
||||
t.Cleanup(func() { _ = p.Close() })
|
||||
return p
|
||||
}
|
||||
|
||||
func onDiskMagic(t *testing.T, path string) string {
|
||||
t.Helper()
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer f.Close()
|
||||
magic := make([]byte, 4)
|
||||
if _, err := io.ReadFull(f, magic); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return string(magic)
|
||||
}
|
||||
|
||||
func statusImpl(t *testing.T, p *durable.DurableProvider) string {
|
||||
t.Helper()
|
||||
st := p.DurableStatuses()
|
||||
if len(st) != 1 {
|
||||
t.Fatalf("DurableStatuses: %d entries, want 1", len(st))
|
||||
}
|
||||
return st[0].Impl
|
||||
}
|
||||
|
||||
func TestDurableProvider_AutoCreatesWALStore(t *testing.T) {
|
||||
if durable.ImplAuto != "" {
|
||||
t.Fatalf("ImplAuto=%q; the zero value must be auto", durable.ImplAuto)
|
||||
}
|
||||
root := t.TempDir()
|
||||
p := autoProvider(t, root, durable.ImplAuto)
|
||||
defer p.Close()
|
||||
if _, err := p.Open(context.Background(), "v1"); err != nil {
|
||||
t.Fatalf("Open: %v", err)
|
||||
}
|
||||
if got := statusImpl(t, p); got != string(durable.ImplWALStore) {
|
||||
t.Fatalf("status impl=%q, want walstore", got)
|
||||
}
|
||||
if got := onDiskMagic(t, filepath.Join(root, "v1.bin")); got != "SWBK" {
|
||||
t.Fatalf("on-disk magic=%q, want SWBK (walstore)", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDurableProvider_AutoOpensExistingVolumeByOnDiskFormat(t *testing.T) {
|
||||
for _, impl := range []durable.ImplName{durable.ImplSmartWAL, durable.ImplWALStore, durable.ImplParallelWALStore} {
|
||||
t.Run(string(impl), func(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
created := autoProvider(t, root, impl)
|
||||
if _, err := created.Open(context.Background(), "v1"); err != nil {
|
||||
t.Fatalf("create %s: %v", impl, err)
|
||||
}
|
||||
if err := created.Close(); err != nil {
|
||||
t.Fatalf("close %s: %v", impl, err)
|
||||
}
|
||||
|
||||
p := autoProvider(t, root, durable.ImplAuto)
|
||||
defer p.Close()
|
||||
if _, err := p.Open(context.Background(), "v1"); err != nil {
|
||||
if errors.Is(err, durable.ErrImplKindMismatch) {
|
||||
t.Fatalf("auto refused an existing %s volume: %v", impl, err)
|
||||
}
|
||||
t.Fatalf("auto Open of an existing %s volume: %v", impl, err)
|
||||
}
|
||||
if got := statusImpl(t, p); got != string(impl) {
|
||||
t.Fatalf("status impl=%q, want the on-disk %q", got, impl)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDurableProvider_AutoRefusesUnknownOnDiskFormat(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
if err := os.WriteFile(filepath.Join(root, "v1.bin"), make([]byte, 8192), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p := autoProvider(t, root, durable.ImplAuto)
|
||||
defer p.Close()
|
||||
if _, err := p.Open(context.Background(), "v1"); !errors.Is(err, durable.ErrImplKindMismatch) {
|
||||
t.Fatalf("auto Open of an unrecognized file: %v, want ErrImplKindMismatch", err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user