mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
durable: auto refuses a chunk-managed root instead of opening it as walstore
walstore-chunk volumes share walstore's on-disk format (SWBK), and on a fresh host their published bytes may exist only in the remote HEAD. Opened by auto as plain walstore, such a root would skip chunk recovery, install no read-miss or fencing hooks and serve the local, absent extent. Auto now refuses any volume whose root carries chunk metadata (<volume>.chunk*: fresh marker, dirty bitmap and deltas, presence map), on both the open and the create path, with ErrImplKindMismatch naming the files and asking for --durable-impl=walstore-chunk with its remote configuration. Nothing is deleted or converted. Tests: a lazy fresh-host chunk root (block published on host A, host B attached and closed before fetching it) is refused by auto and read exactly by the explicit walstore-chunk selector; any chunk root is refused; a stray fresh marker without a volume file is refused and left in place. autoProvider registers its cleanup (review P3). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1f10755b0e
commit
d65471908f
3 files changed
+139
No files matched your search
@@ -33,6 +33,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -557,6 +558,19 @@ 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 {
|
||||
impl, err := p.verifyImplOnDisk(path)
|
||||
@@ -858,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)
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@ func autoProvider(t *testing.T, root string, impl durable.ImplName) *durable.Dur
|
||||
if err != nil {
|
||||
t.Fatalf("NewDurableProvider(%q): %v", impl, err)
|
||||
}
|
||||
t.Cleanup(func() { _ = p.Close() })
|
||||
return p
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user