diff --git a/seaweed-block/core/storage/chunk_layer.go b/seaweed-block/core/storage/chunk_layer.go index f9af9446e1..346d0227f8 100644 --- a/seaweed-block/core/storage/chunk_layer.go +++ b/seaweed-block/core/storage/chunk_layer.go @@ -889,6 +889,17 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch // Do not sample the owned map after COW writers are admitted again. births := l.captureBirths(candidates, h) + if h < baseHead.RemoteLSN && !l.supersededBy(baseHead) { + l.s.captureMu.Unlock() + st.BarrierPauseNs = time.Since(pauseStart).Nanoseconds() + // HEAD holds the image of a later LSN than this host's log has + // reached: publishing would move remote_lsn backwards. Refused + // before any upload. (A HEAD of a newer holder fences below.) + l.abortCut(all) + l.dropIntents(ctx, intents) + return chunkCutResult{}, fmt.Errorf("%w: %w: cut LSN %d, HEAD remote_lsn %d", errChunkCaptureRefused, errChunkLSNBehind, h, baseHead.RemoteLSN) + } + st.CandidateChunks = len(candidates) var copyErr error copyStart := time.Now() @@ -943,14 +954,6 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch if b := l.cfg.BarrierBound; b > 0 && st.BarrierCopyChunks > b { st.BarrierOverBound = true } - if h < baseHead.RemoteLSN && !l.supersededBy(baseHead) { - // HEAD holds the image of a later LSN than this host's log has - // reached: publishing would move remote_lsn backwards. Refused - // before any upload. (A HEAD of a newer holder fences below.) - l.abortCut(all) - l.dropIntents(ctx, intents) - return chunkCutResult{}, fmt.Errorf("%w: %w: cut LSN %d, HEAD remote_lsn %d", errChunkCaptureRefused, errChunkLSNBehind, h, baseHead.RemoteLSN) - } // Upload only what changed against HEAD. next := copyHead(baseHead) diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index 720392619c..722e21405d 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -191,12 +191,14 @@ stateDiagram-v2 Stage --> Quiesce: at most 3 pre-copy rounds Quiesce --> OpenWindow: Sync H and D fixed under barrier OpenWindow --> Copy: release barrier - Copy --> Closed: all candidates done + Copy --> Upload: local entry released, intent durable first + Upload --> Copy: next unsent candidate + Upload --> Closed: all workers settled Copy --> Aborted: error, cancellation, observed fence, recovery or close + Upload --> Aborted: error, cancellation, observed fence, recovery or close Aborted --> Refused: drain owners, cleanup, merge candidates Copy --> Refused: H below HEAD RemoteLSN - Closed --> Upload: drain and cleanup; intent durable first - Upload --> Manifest + Closed --> Manifest: drain owners and cleanup Manifest --> Readmit Readmit --> Fenced: superseding HEAD Readmit --> CAS