mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
blockvolume: HEAD holder is <server-id>/<replica-id>
The replica id alone made two hosts that both serve replica r1 look like the same holder returning, so the later one was not fenced (B9 W2 appendix, 2026-11-15 14:30Z). blockvolume now passes <server-id>/<replica-id> as the provider's ChunkHolder. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b06bf7dc45
commit
e483d45728
5 files changed
+77
-1
No files matched your search
@@ -105,6 +105,12 @@ func chunkAttachCheck(cat *chunkstore.Catalog) func(context.Context, string, dur
|
||||
}
|
||||
}
|
||||
|
||||
// chunkHolder is how this host names itself in HEAD: <server-id>/<replica-id>
|
||||
// (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 <base>/<volumeID>; 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) {
|
||||
|
||||
@@ -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 <server-id>/<replica-id>: 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)
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
// <server-id>/<replica-id>. Zero: the replica ID (tests).
|
||||
ChunkHolder string
|
||||
// ChunkReadMissTimeout bounds one remote fetch of an absent block.
|
||||
// Zero: the storage default.
|
||||
|
||||
@@ -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 (<server-id>/<replica-id>): 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)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user