mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
blockvolume: apply the VOLUME attach rules before the chunk layer attaches
walstore-chunk now dials one filer client for the per-volume remotes and a catalog under the same --chunk-path, and wires the provider's attach check to Catalog.EnsureVolume with the local geometry (B9 W2 §4.2, ruling of 2026-11-15): the first attach creates VOLUME, and an attach is refused with geometry_mismatch, or with fork_incomplete for a fork whose HEAD is not written yet. It runs before any HEAD read or CAS. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8b3e0cfbce
commit
985a825ac5
3 files changed
+78
-14
No files matched your search
@@ -6,6 +6,7 @@ package main
|
||||
// given by --chunk-filer; chunk bytes are needles on its volume servers.
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"path"
|
||||
@@ -13,6 +14,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore"
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/durable"
|
||||
"github.com/seaweedfs/seaweed-block/core/storage"
|
||||
)
|
||||
|
||||
@@ -49,9 +51,17 @@ func validateChunkFlags(f flags) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// newChunkRemoteFor dials the filer (lazily) and returns the provider's
|
||||
// ChunkRemoteFor plus the client's closer.
|
||||
func newChunkRemoteFor(c chunkFlags) (func(volumeID string) (storage.ChunkRemote, error), func() error, error) {
|
||||
// chunkWiring is what --durable-impl=walstore-chunk dials once: the
|
||||
// provider's per-volume remotes, the catalog under the same base (VOLUME
|
||||
// entries, snapshots) and the client's closer.
|
||||
type chunkWiring struct {
|
||||
remoteFor func(volumeID string) (storage.ChunkRemote, error)
|
||||
catalog *chunkstore.Catalog
|
||||
close func() error
|
||||
}
|
||||
|
||||
// newChunkWiring dials the filer (lazily).
|
||||
func newChunkWiring(c chunkFlags) (chunkWiring, error) {
|
||||
client, err := chunkstore.DialSWFS(chunkstore.SWFSConfig{
|
||||
FilerGRPC: c.filer,
|
||||
Collection: c.collection,
|
||||
@@ -59,15 +69,35 @@ func newChunkRemoteFor(c chunkFlags) (func(volumeID string) (storage.ChunkRemote
|
||||
AssignPath: c.path,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return chunkWiring{}, err
|
||||
}
|
||||
cat, err := chunkstore.NewCatalog(client, c.path)
|
||||
if err != nil {
|
||||
_ = client.Close()
|
||||
return chunkWiring{}, err
|
||||
}
|
||||
return chunkWiring{
|
||||
remoteFor: func(volumeID string) (storage.ChunkRemote, error) {
|
||||
root, err := chunkVolumeRoot(c.path, volumeID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return chunkstore.NewSWFSChunkRemote(client, root)
|
||||
},
|
||||
catalog: cat,
|
||||
close: client.Close,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// chunkAttachCheck applies the VOLUME entry's attach rules before the chunk
|
||||
// layer attaches (B9 W2 §4.2): create VOLUME from the local geometry when
|
||||
// it is missing, refuse geometry_mismatch, and refuse fork_incomplete for a
|
||||
// fork whose HEAD is not written yet.
|
||||
func chunkAttachCheck(cat *chunkstore.Catalog) func(context.Context, string, durable.ChunkGeometry) error {
|
||||
return func(ctx context.Context, volumeID string, g durable.ChunkGeometry) error {
|
||||
_, err := cat.EnsureVolume(ctx, volumeID, chunkstore.Geometry{NumBlocks: g.NumBlocks, BlockSize: g.BlockSize, ChunkBlocks: g.ChunkBlocks})
|
||||
return err
|
||||
}
|
||||
return func(volumeID string) (storage.ChunkRemote, error) {
|
||||
root, err := chunkVolumeRoot(c.path, volumeID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return chunkstore.NewSWFSChunkRemote(client, root)
|
||||
}, client.Close, nil
|
||||
}
|
||||
|
||||
// chunkVolumeRoot is <base>/<volumeID>; the volume ID must be one plain
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore"
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/durable"
|
||||
)
|
||||
|
||||
func TestWALStoreChunkFlags(t *testing.T) {
|
||||
@@ -47,3 +51,31 @@ func TestChunkVolumeRootStaysInsideBase(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The attach check is the VOLUME entry's attach rules (B9 W2 §4.2): the first
|
||||
// attach creates VOLUME from the local geometry, a later attach with the same
|
||||
// geometry passes, and another geometry is refused.
|
||||
func TestChunkAttachCheckAppliesVolumeRules(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
cat, err := chunkstore.NewCatalog(chunkstore.NewMemFiler(), defaultChunkPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
check := chunkAttachCheck(cat)
|
||||
g := durable.ChunkGeometry{NumBlocks: 64, BlockSize: 4096, ChunkBlocks: 8}
|
||||
if err := check(ctx, "v1", g); err != nil {
|
||||
t.Fatalf("first attach: %v", err)
|
||||
}
|
||||
v, ok, err := cat.ReadVolume(ctx, "v1")
|
||||
if err != nil || !ok || v.Origin != chunkstore.OriginCreate || v.Geometry != (chunkstore.Geometry{NumBlocks: 64, BlockSize: 4096, ChunkBlocks: 8}) {
|
||||
t.Fatalf("VOLUME after the first attach: %+v ok=%v %v", v, ok, err)
|
||||
}
|
||||
if err := check(ctx, "v1", g); err != nil {
|
||||
t.Fatalf("attach with the same geometry: %v", err)
|
||||
}
|
||||
other := g
|
||||
other.NumBlocks = 128
|
||||
if err := check(ctx, "v1", other); chunkstore.CodeOf(err) != chunkstore.CodeGeometryMismatch {
|
||||
t.Fatalf("attach with another geometry: %v, want geometry_mismatch", err)
|
||||
}
|
||||
}
|
||||
@@ -544,12 +544,14 @@ func run(f flags) int {
|
||||
WALRecoveryTestDisableFlusher: f.durableWALRecoveryTestDisableFlusher,
|
||||
}
|
||||
var chunkErr error
|
||||
var chunk chunkWiring
|
||||
if cfg.Impl == durable.ImplWALStoreChunk {
|
||||
var closeChunkClient func() error
|
||||
cfg.ChunkRemoteFor, closeChunkClient, chunkErr = newChunkRemoteFor(f.chunk)
|
||||
chunk, chunkErr = newChunkWiring(f.chunk)
|
||||
cfg.ChunkCaptureInterval = f.chunk.captureInterval
|
||||
if chunkErr == nil {
|
||||
defer closeChunkClient()
|
||||
cfg.ChunkRemoteFor = chunk.remoteFor
|
||||
cfg.ChunkAttachCheck = chunkAttachCheck(chunk.catalog)
|
||||
defer chunk.close()
|
||||
}
|
||||
}
|
||||
dp, err := durable.NewDurableProvider(cfg, h.ProjectionView())
|
||||
|
||||
Reference in new issue
Block a user