mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
fix(storage): retain takeover cooling across retries and hydration fencing
This commit is contained in:
1 parent
dd38de086c
commit
9759dc02d6
4 files changed
+30
-9
No files matched your search
@@ -95,14 +95,15 @@ func TestWALStoreChunk_TakeoverReadBeforeAttachIsRetryable(t *testing.T) {
|
||||
command := nvme.IOCommand{Opcode: 0x02, NSID: 1, SLBA: 33, NLB: 1}
|
||||
start := time.Now()
|
||||
for attempt := 0; attempt <= 5; attempt++ {
|
||||
commandStart := time.Now()
|
||||
result := handler.Handle(context.Background(), command)
|
||||
if elapsed := time.Since(commandStart); elapsed >= 5*time.Second {
|
||||
t.Fatalf("guest command took %s", elapsed)
|
||||
}
|
||||
if result.AsError() == nil {
|
||||
if !bytes.Equal(result.Data, block(0x33)) {
|
||||
t.Fatal("guest read returned incorrect HEAD bytes")
|
||||
}
|
||||
if elapsed := time.Since(start); elapsed >= 5*time.Second {
|
||||
t.Fatalf("guest read took %s", elapsed)
|
||||
}
|
||||
t.Logf("guest read succeeded on attempt%d after%s (max5 immediate retries)", attempt+1, time.Since(start))
|
||||
return
|
||||
}
|
||||
@@ -142,14 +143,24 @@ func TestWALStoreChunk_PendingReadHonoursEarlierDeadline(t *testing.T) {
|
||||
|
||||
func TestWALStoreChunk_TakeoverWriteWaitsForAttach(t *testing.T) {
|
||||
_, backend, _ := pendingTakeoverRead(t, 2500*time.Millisecond)
|
||||
start := time.Now()
|
||||
n, err := backend.Write(context.Background(), 33*4096, block(0x74))
|
||||
var n int
|
||||
var err error
|
||||
for attempt := 0; attempt <= 5; attempt++ {
|
||||
start := time.Now()
|
||||
n, err = backend.Write(context.Background(), 33*4096, block(0x74))
|
||||
if elapsed := time.Since(start); elapsed >= 5*time.Second {
|
||||
t.Fatalf("write command waited %s", elapsed)
|
||||
}
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
if n != 0 || !errors.Is(err, frontend.ErrBackendBusy) {
|
||||
t.Fatalf("pending write lost retryability: n=%d err=%v", n, err)
|
||||
}
|
||||
}
|
||||
if err != nil || n != 4096 {
|
||||
t.Fatalf("pending write: n=%d err=%v", n, err)
|
||||
}
|
||||
if elapsed := time.Since(start); elapsed >= 5*time.Second {
|
||||
t.Fatalf("write waited %s", elapsed)
|
||||
}
|
||||
got := make([]byte, 4096)
|
||||
if n, err := backend.Read(context.Background(), 33*4096, got); err != nil || n != 4096 || !bytes.Equal(got, block(0x74)) {
|
||||
t.Fatalf("attached write readback: n=%d err=%v", n, err)
|
||||
|
||||
@@ -69,6 +69,11 @@ func (l *chunkLayerImpl) publicationOwnerChanged(cur chunkHead) bool {
|
||||
func (l *chunkLayerImpl) fencePublication(cur chunkHead) {
|
||||
l.stMu.Lock()
|
||||
l.fenced = true
|
||||
if cur.Gen != 0 {
|
||||
// Preserve the existing hydration identity invalidation. This is not
|
||||
// settlement of our cut: remoteLSN and captured-map dirt stay unchanged.
|
||||
l.head = copyHead(cur)
|
||||
}
|
||||
l.stMu.Unlock()
|
||||
log.Printf("ALARM: chunk publisher fenced: local epoch=%d holder=%q, observed gen=%d epoch=%d holder=%q; keeping local data and intents", l.cfg.Epoch, l.cfg.Holder, cur.Gen, cur.Epoch, cur.Holder)
|
||||
l.abortCOW(errChunkLayerFenced)
|
||||
|
||||
@@ -1175,7 +1175,7 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch
|
||||
keepPending()
|
||||
return chunkCutResult{}, fmt.Errorf("storage: capture CAS outcome unresolved (%v): %w: %w", casErr, errChunkCASOutcomeUnknown, gerr)
|
||||
}
|
||||
if errors.Is(casErr, errChunkLayerFenced) || (!sameProposal(cur, next) && l.publicationOwnerChanged(cur)) {
|
||||
if !sameProposal(cur, next) && l.publicationOwnerChanged(cur) {
|
||||
keepPending() // Close must keep these roots as well.
|
||||
l.fencePublication(cur)
|
||||
return chunkCutResult{}, errors.Join(errChunkLayerFenced, casErr)
|
||||
|
||||
@@ -50,6 +50,11 @@ func ClaimChunkHead(ctx context.Context, remote ChunkRemote, cfg ChunkLayerConfi
|
||||
return head, nil
|
||||
}
|
||||
if head.Gen != 0 && head.Epoch == cfg.Epoch && head.Holder == cfg.Holder && !chunkHeadIsDetached(head) && head.DetachedBy == nil {
|
||||
// A previous claim may have committed but timed out during cooling.
|
||||
// An identical root alone does not prove that wait completed.
|
||||
if err := confirmChunkTakeover(ctx, remote, head); err != nil {
|
||||
return ChunkHead{}, err
|
||||
}
|
||||
return head, allowed() // idempotent restart or settled prior claim
|
||||
}
|
||||
next := copyHead(head)
|
||||
|
||||
Reference in new issue
Block a user