diff --git a/seaweed-block/core/frontend/durable/provider.go b/seaweed-block/core/frontend/durable/provider.go index aa540cb07c..350bc56fae 100644 --- a/seaweed-block/core/frontend/durable/provider.go +++ b/seaweed-block/core/frontend/durable/provider.go @@ -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 diff --git a/seaweed-block/core/frontend/durable/provider_chunk.go b/seaweed-block/core/frontend/durable/provider_chunk.go index 7abd239466..8f93e4579f 100644 --- a/seaweed-block/core/frontend/durable/provider_chunk.go +++ b/seaweed-block/core/frontend/durable/provider_chunk.go @@ -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 diff --git a/seaweed-block/core/frontend/durable/provider_chunk_holder_test.go b/seaweed-block/core/frontend/durable/provider_chunk_holder_test.go index 88485d530d..dad763f914 100644 --- a/seaweed-block/core/frontend/durable/provider_chunk_holder_test.go +++ b/seaweed-block/core/frontend/durable/provider_chunk_holder_test.go @@ -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 (/): the second one is fenced and publishes -// nothing over the first one's HEAD. +// holders (/). 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) } }