diff --git a/seaweed-block/cmd/blockvolume/chunk_remote.go b/seaweed-block/cmd/blockvolume/chunk_remote.go index 0a938918a1..d1d2cde3ff 100644 --- a/seaweed-block/cmd/blockvolume/chunk_remote.go +++ b/seaweed-block/cmd/blockvolume/chunk_remote.go @@ -105,6 +105,12 @@ func chunkAttachCheck(cat *chunkstore.Catalog) func(context.Context, string, dur } } +// chunkHolder is how this host names itself in HEAD: / +// (B9 W2 appendix, 2026-11-15 14:30Z). The replica id alone is not enough: +// two hosts that both serve replica r1 would look like the same holder +// returning, and the later one would not be fenced. +func chunkHolder(f flags) string { return f.serverID + "/" + f.replicaID } + // chunkVolumeRoot is /; the volume ID must be one plain // path element so no volume can reach another volume's directory. func chunkVolumeRoot(base, volumeID string) (string, error) { diff --git a/seaweed-block/cmd/blockvolume/chunk_remote_test.go b/seaweed-block/cmd/blockvolume/chunk_remote_test.go index 36eed75a36..e560dbc215 100644 --- a/seaweed-block/cmd/blockvolume/chunk_remote_test.go +++ b/seaweed-block/cmd/blockvolume/chunk_remote_test.go @@ -88,3 +88,16 @@ func TestChunkAttachCheckAppliesVolumeRules(t *testing.T) { t.Fatalf("attach with another geometry: %v, want geometry_mismatch", err) } } + +// HEAD names a host as /: two servers serving the same +// replica id are different holders (B9 W2 appendix, 2026-11-15 14:30Z). +func TestChunkHolderIsServerAndReplica(t *testing.T) { + f, err := parseFlags(append(phase150RequiredBlockvolumeArgs(), "--durable-root=/tmp/sw-block", + "--durable-impl=walstore-chunk", "--chunk-filer=x:1")) + if err != nil { + t.Fatal(err) + } + if got := chunkHolder(f); got != "m02/r1" { + t.Fatalf("chunk holder %q, want m02/r1", got) + } +} diff --git a/seaweed-block/cmd/blockvolume/main.go b/seaweed-block/cmd/blockvolume/main.go index 6eb0e8d2c2..77fd116515 100644 --- a/seaweed-block/cmd/blockvolume/main.go +++ b/seaweed-block/cmd/blockvolume/main.go @@ -552,6 +552,7 @@ func run(f flags) int { if cfg.Impl == durable.ImplWALStoreChunk { chunk, chunkErr = newChunkWiring(f.chunk) cfg.ChunkCaptureInterval = f.chunk.captureInterval + cfg.ChunkHolder = chunkHolder(f) if chunkErr == nil { cfg.ChunkRemoteFor = chunk.remoteFor cfg.ChunkAttachCheck = chunkAttachCheck(chunk.catalog) diff --git a/seaweed-block/core/frontend/durable/provider.go b/seaweed-block/core/frontend/durable/provider.go index 60a9c9daa9..aa540cb07c 100644 --- a/seaweed-block/core/frontend/durable/provider.go +++ b/seaweed-block/core/frontend/durable/provider.go @@ -132,7 +132,8 @@ type ProviderConfig struct { // entry's attach rules (B9 W2 ยง4.2): create VOLUME when missing, refuse // a geometry mismatch and a fork whose HEAD is not written yet. ChunkAttachCheck func(ctx context.Context, volumeID string, g ChunkGeometry) error - // ChunkHolder names this node in HEAD. Zero: the replica ID. + // ChunkHolder names this node in HEAD; blockvolume sets + // /. Zero: the replica ID (tests). ChunkHolder string // ChunkReadMissTimeout bounds one remote fetch of an absent block. // Zero: the storage default. diff --git a/seaweed-block/core/frontend/durable/provider_chunk_holder_test.go b/seaweed-block/core/frontend/durable/provider_chunk_holder_test.go new file mode 100644 index 0000000000..88485d530d --- /dev/null +++ b/seaweed-block/core/frontend/durable/provider_chunk_holder_test.go @@ -0,0 +1,55 @@ +package durable_test + +import ( + "context" + "errors" + "testing" + + "github.com/seaweedfs/seaweed-block/core/frontend/durable" + "github.com/seaweedfs/seaweed-block/core/storage" +) + +// Two servers serving the same replica id at the same epoch are different +// holders (/): the second one is fenced and publishes +// nothing over the first one's HEAD. +func TestWALStoreChunk_SameReplicaOnAnotherServerIsFenced(t *testing.T) { + ctx := context.Background() + remote := storage.NewMemChunkRemote() + newHost := func(holder string) *durable.DurableProvider { + p, err := durable.NewDurableProvider(durable.ProviderConfig{ + Impl: durable.ImplWALStoreChunk, + StorageRoot: t.TempDir(), + BlockSize: 4096, + NumBlocks: pcBlocks, + ChunkBlocks: pcChunkBlocks, + ChunkHolder: holder, + ChunkRemoteFor: func(string) (storage.ChunkRemote, error) { return remote, nil }, + }, v1View()) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { _ = p.Close() }) + return p + } + a := newHost("s1/r1") + sa := openRecovered(t, a) + if _, err := sa.Write(1, block(1)); err != nil { + t.Fatal(err) + } + if _, err := a.CaptureVolume(ctx, "v1"); err != nil { + t.Fatal(err) + } + head, _ := remote.GetHead(ctx) + + b := newHost("s2/r1") + sb := openRecovered(t, b) + if _, err := sb.Write(2, block(2)); err != nil { + t.Fatal(err) + } + if _, err := b.CaptureVolume(ctx, "v1"); !errors.Is(err, storage.ErrChunkLayerFenced) { + t.Fatalf("a second server with the same replica id at the same epoch: %v; want fenced", err) + } + if after, _ := remote.GetHead(ctx); after.Gen != head.Gen || after.Holder != "s1/r1" { + t.Fatalf("HEAD after the second server's cut: gen %d holder %q, want gen %d holder s1/r1", after.Gen, after.Holder, head.Gen) + } +}