durable: a layer fenced at attach fails recovery and never serves

Integration ruling F2: when the chunk layer attaches fenced (HEAD belongs
to a newer epoch or another holder, e.g. another server serving the same
replica), RecoverVolume fails with ErrChunkLayerFenced and the volume stays
non-operational, before anything can serve; the deferred authority attach
does not enable I/O either. HEAD is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-11-15 07:44:09 -08:00
1 parent fb939771f6
commit 122321b9e0
3 files changed
+39 -7

No files matched your search

@@ -742,6 +742,11 @@ func (p *DurableProvider) RecoverVolume(ctx context.Context, volumeID string) (R
h.backend.SetOperational(false, report.Evidence)
return report, nil
}
if err := chunkFenced(volumeID, h); err != nil {
h.backend.SetOperational(false, "chunk layer fenced: "+err.Error())
report.Err = err
return report, err
}
}
h.backend.SetOperational(true, report.Evidence)
return report, nil
@@ -142,6 +142,9 @@ func (p *DurableProvider) chunkAuthorityWait(volumeID string, h *volHandle, gen
ctx, cancel := context.WithTimeout(p.closeCtx, chunkAttachTimeout)
err := p.attachChunk(ctx, volumeID, h)
cancel()
if err == nil {
err = chunkFenced(volumeID, h)
}
if err == nil && !h.chunkDetach {
h.backend.SetOperational(true, "chunk layer attached under master authority")
}
@@ -149,6 +152,9 @@ func (p *DurableProvider) chunkAuthorityWait(volumeID string, h *volHandle, gen
switch {
case err == nil, errors.Is(err, errProviderClosed):
return
case errors.Is(err, storage.ErrChunkLayerFenced):
log.Printf("durable: chunk layer for volume=%s: %v (not serving)", volumeID, err)
return
case errors.Is(err, errChunkNoAuthority):
continue
}
@@ -463,6 +469,16 @@ func (p *DurableProvider) MakeVolumeRemoteDurable(ctx context.Context, volumeID
return layer.MakeRemoteDurable(ctx, lsn)
}
// chunkFenced refuses a volume whose layer attached fenced: HEAD belongs to
// a newer epoch or another holder (another server serving this replica),
// so this host must not serve it (integration ruling F2).
func chunkFenced(volumeID string, h *volHandle) error {
if h.chunk != nil && h.chunk.Fenced() {
return fmt.Errorf("durable: volume %s: HEAD belongs to a newer epoch or another holder: %w", volumeID, storage.ErrChunkLayerFenced)
}
return nil
}
// CutVolume takes one quiesced cut of volumeID and returns what it
// installed: the cut LSN, the HEAD (the current one when nothing changed)
// and the cut's statistics (B9 W2 §2.4, §3.1). With minLSN > 0 it is
@@ -5,13 +5,15 @@ import (
"errors"
"testing"
"github.com/seaweedfs/seaweed-block/core/frontend"
"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.
// holders (<server-id>/<replica-id>). The second one's RecoverVolume fails
// fenced before anything can serve, and HEAD is unchanged (integration
// ruling F2: the earlier surface is canonical).
func TestWALStoreChunk_SameReplicaOnAnotherServerIsFenced(t *testing.T) {
ctx := context.Background()
remote := storage.NewMemChunkRemote()
@@ -42,14 +44,23 @@ func TestWALStoreChunk_SameReplicaOnAnotherServerIsFenced(t *testing.T) {
head, _ := remote.GetHead(ctx)
b := newHost("s2/r1")
sb := openRecovered(t, b)
if _, err := sb.Write(2, block(2)); err != nil {
if _, err := b.EnsureStorage("v1"); 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 _, err := b.RecoverVolume(ctx, "v1"); !errors.Is(err, storage.ErrChunkLayerFenced) {
t.Fatalf("a second server with the same replica id at the same epoch: RecoverVolume %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)
t.Fatalf("HEAD after the second server's recovery: gen %d holder %q, want gen %d holder s1/r1", after.Gen, after.Holder, head.Gen)
}
be, err := b.Open(ctx, "v1")
if err != nil {
t.Fatal(err)
}
if _, err := be.Write(ctx, 4096, block(2)); !errors.Is(err, frontend.ErrNotReady) {
t.Fatalf("a write on the fenced second server: %v; want ErrNotReady", err)
}
if _, err := b.CaptureVolume(ctx, "v1"); !errors.Is(err, storage.ErrChunkLayerFenced) {
t.Fatalf("a cut on the fenced second server: %v; want fenced", err)
}
}