diff --git a/seaweed-block/core/frontend/durable/device_write_scope_test.go b/seaweed-block/core/frontend/durable/device_write_scope_test.go index 5f6798bcde..5cb0e43c1e 100644 --- a/seaweed-block/core/frontend/durable/device_write_scope_test.go +++ b/seaweed-block/core/frontend/durable/device_write_scope_test.go @@ -2,6 +2,7 @@ package durable import ( "context" + "errors" "path/filepath" "testing" "testing/synctest" @@ -19,19 +20,15 @@ func TestDeviceLegacyBudgetDoesNotInstallARetryableWALHold(t *testing.T) { defer s.Close() b := NewStorageBackend(s, holdCommandView{}, frontend.Identity{VolumeID: "v1", ReplicaID: "r1", Epoch: 1, EndpointVersion: 1}) synctest.Test(t, func(t *testing.T) { - owner, cancelOwner := storage.WithWALWriteHold(context.Background(), s, time.Now(), time.Minute, false) - defer cancelOwner() - defer storage.FinishWALWriteHold(owner, nil) - if err := storage.BeginWALWriteHold(owner); err != nil { - t.Fatal(err) - } ctx, cancel := frontend.WithLegacyWriteBudget(context.Background(), time.Now()) defer cancel() ctx, cancelBackend := b.WriteCommandContext(ctx, time.Time{}) defer cancelBackend() defer storage.FinishWALWriteHold(ctx, nil) - if err := storage.BeginWALWriteHold(ctx); err != nil { - t.Fatalf("legacy device command installed a retryable hold behind the owner: %v", err) + time.Sleep(5 * time.Second) + _, err := s.WriteContext(ctx, 0, make([]byte, 4096)) + if !errors.Is(err, storage.ErrWALPressureTimeout) || errors.Is(err, storage.ErrWALHoldCap) { + t.Fatalf("legacy device budget became retryable hold: %v", err) } }) } diff --git a/seaweed-block/core/frontend/durable/storage_adapter.go b/seaweed-block/core/frontend/durable/storage_adapter.go index 115738e6be..60e4a46610 100644 --- a/seaweed-block/core/frontend/durable/storage_adapter.go +++ b/seaweed-block/core/frontend/durable/storage_adapter.go @@ -215,11 +215,12 @@ type StorageBackend struct { // seed) together with rebasing the observer, against installing an // observer together with its rebase: whichever runs second sees the // other's result. Lock order: observerMu, then mu. - observerMu sync.Mutex - observer WriteObserver // optional; nil = no replication fan-out - writeAck WriteAckPolicy - profile writeProfile - lbaWriteLocks [256]sync.Mutex + observerMu sync.Mutex + observer WriteObserver // optional; nil = no replication fan-out + writeAck WriteAckPolicy + profile writeProfile + lbaWriteLocks [256]sync.Mutex + testBeforeRMWRead func() } // NewStorageBackend constructs a backend. Starts NON-operational @@ -847,12 +848,6 @@ func (b *StorageBackend) Write(ctx context.Context, offset int64, p []byte) (wri if ctx.Err() != nil { return 0, b.attachReadyTimeout(ctx.Err()) } - if err := storage.BeginWALWriteHold(ctx); err != nil { - if errors.Is(err, storage.ErrWALPressureTimeout) { - return 0, fmt.Errorf("%w: %w", frontend.ErrBackendBusy, err) - } - return 0, err - } b.profile.recordBackendWriteRequest(len(p)) start := time.Now() n, err := b.writeBytes(ctx, offset, p) @@ -1129,6 +1124,9 @@ func (b *StorageBackend) writeBytes(ctx context.Context, offset int64, p []byte) block = buf[:chunkLen] } else { // Partial-block: RMW. + if b.testBeforeRMWRead != nil { + b.testBeforeRMWRead() + } existing, err := b.readStorageBlock(ctx, lba) if err != nil { writeLock.Unlock() diff --git a/seaweed-block/core/frontend/durable/wal_hold_command_test.go b/seaweed-block/core/frontend/durable/wal_hold_command_test.go index 45a2d07df8..d4a332718a 100644 --- a/seaweed-block/core/frontend/durable/wal_hold_command_test.go +++ b/seaweed-block/core/frontend/durable/wal_hold_command_test.go @@ -69,7 +69,7 @@ func TestWALHoldBudgetSurvivesNestedNVMeDispatch(t *testing.T) { }) } -func TestWALHoldTicketSpansBackendBatchesBeforeLBALocks(t *testing.T) { +func TestWALHoldReleasesAdmissionBeforeObserverAck(t *testing.T) { b := holdCommandBackend(t) synctest.Test(t, func(t *testing.T) { paused, resume := make(chan struct{}), make(chan struct{}) @@ -83,12 +83,15 @@ func TestWALHoldTicketSpansBackendBatchesBeforeLBALocks(t *testing.T) { doneA, doneB := make(chan error, 1), make(chan error, 1) go func() { _, err := b.Write(context.Background(), 0, bytes.Repeat([]byte{1}, 128*4096)); doneA <- err }() <-paused - go func() { _, err := b.Write(context.Background(), 64*4096, bytes.Repeat([]byte{2}, 4096)); doneB <- err }() + go func() { _, err := b.Write(context.Background(), 192*4096, bytes.Repeat([]byte{2}, 4096)); doneB <- err }() synctest.Wait() select { case err := <-doneB: - t.Fatalf("younger command crossed oldest batch lease: %v", err) + if err != nil { + t.Fatal(err) + } default: + t.Fatal("unrelated append blocked behind replica acknowledgement") } time.Sleep(6 * time.Second) // an observer delay is not WAL-pressure inactivity if st := b.storage.(*storage.WALStore).WALHoldStatus(); st.Degraded { @@ -99,12 +102,38 @@ func TestWALHoldTicketSpansBackendBatchesBeforeLBALocks(t *testing.T) { if err := <-doneA; err != nil { t.Fatal(err) } - if err := <-doneB; err != nil { - t.Fatal(err) - } got := make([]byte, 4096) - if _, err := b.Read(context.Background(), 64*4096, got); err != nil || !bytes.Equal(got, bytes.Repeat([]byte{2}, 4096)) { + if _, err := b.Read(context.Background(), 192*4096, got); err != nil || !bytes.Equal(got, bytes.Repeat([]byte{2}, 4096)) { t.Fatalf("younger bytes were overwritten: %v", err) } }) } + +func TestWALHoldDoesNotOwnAdmissionWhileWaitingForRMW(t *testing.T) { + b := holdCommandBackend(t) + synctest.Test(t, func(t *testing.T) { + paused, resume := make(chan struct{}), make(chan struct{}) + var once sync.Once + release := func() { once.Do(func() { close(resume) }) } + defer func() { release(); synctest.Wait() }() + b.testBeforeRMWRead = func() { close(paused); <-resume } + doneA, doneB := make(chan error, 1), make(chan error, 1) + go func() { _, err := b.Write(context.Background(), 1, []byte{7}); doneA <- err }() + <-paused + go func() { _, err := b.Write(context.Background(), 4096, bytes.Repeat([]byte{9}, 4096)); doneB <- err }() + synctest.Wait() + select { + case err := <-doneB: + if err != nil { + t.Fatal(err) + } + default: + t.Fatal("unrelated append blocked behind RMW read") + } + release() + synctest.Wait() + if err := <-doneA; err != nil { + t.Fatal(err) + } + }) +} diff --git a/seaweed-block/core/frontend/iscsi/legacy_write_budget_test.go b/seaweed-block/core/frontend/iscsi/legacy_write_budget_test.go new file mode 100644 index 0000000000..75a27803a9 --- /dev/null +++ b/seaweed-block/core/frontend/iscsi/legacy_write_budget_test.go @@ -0,0 +1,32 @@ +package iscsi + +import ( + "context" + "github.com/seaweedfs/seaweed-block/core/frontend" + "testing" + "time" +) + +type serialBudgetBackend struct { + frontend.Backend + legacy bool + deadline time.Time +} + +func (b *serialBudgetBackend) Write(ctx context.Context, _ int64, p []byte) (int, error) { + b.legacy = frontend.UsesLegacyWriteBudget(ctx) + b.deadline, _ = ctx.Deadline() + return len(p), nil +} +func (b *serialBudgetBackend) WriteCommandContext(ctx context.Context, _ time.Time) (context.Context, context.CancelFunc) { + return context.WithTimeout(ctx, 25*time.Second) +} +func TestSerialISCSIWriteKeepsLegacyBudget(t *testing.T) { + b := &serialBudgetBackend{} + h := &SCSIHandler{backend: b, blockSize: 4096, volumeSize: 4096} + start := time.Now() + r := h.doWrite(context.Background(), 0, 1, make([]byte, 4096)) + if r.Status != StatusGood || !b.legacy || b.deadline.IsZero() || b.deadline.After(start.Add(4*time.Second)) { + t.Fatalf("serial write status=%d legacy=%v deadline=%v", r.Status, b.legacy, b.deadline) + } +} diff --git a/seaweed-block/core/frontend/iscsi/scsi.go b/seaweed-block/core/frontend/iscsi/scsi.go index 7f31cbe3e8..61d34c23b2 100644 --- a/seaweed-block/core/frontend/iscsi/scsi.go +++ b/seaweed-block/core/frontend/iscsi/scsi.go @@ -278,7 +278,9 @@ func (h *SCSIHandler) doRead(ctx context.Context, lba uint64, transferLen uint32 } func (h *SCSIHandler) doWrite(ctx context.Context, lba uint64, transferLen uint32, dataOut []byte) SCSIResult { - ctx, cancel := frontend.WithBackendWriteBudget(ctx, time.Time{}, h.backend) + // The serial session must return to its reader before the initiator NOP window. + // Extended WAL holds require concurrent per-command session handling. + ctx, cancel := frontend.WithLegacyWriteBudget(ctx, time.Time{}) defer cancel() // G5-5 instrumentation: log every SCSI WRITE arrival at the // handler. If this line doesn't fire when the kernel initiator diff --git a/seaweed-block/core/storage/wal_admission.go b/seaweed-block/core/storage/wal_admission.go index 263fc1d056..e7ec800662 100644 --- a/seaweed-block/core/storage/wal_admission.go +++ b/seaweed-block/core/storage/wal_admission.go @@ -125,21 +125,15 @@ func (a *walAdmission) acquireContext(ctx context.Context, timeout time.Duration deadline = time.NewTimer(timeout) defer deadline.Stop() } - borrowed := hold != nil && hold.owned - var ticket *walAdmissionTicket - if !borrowed { - ticket = a.enqueueTicket() - } - granted := borrowed + ticket := a.enqueueTicket() + granted := false defer func() { - if !granted && ticket != nil { + if !granted { a.removeTicket(ticket) } }() - if !borrowed { - if err := a.waitForTicket(ctx, deadline, ticket, contextual); err != nil { - return err - } + if err := a.waitForTicket(ctx, deadline, ticket, contextual); err != nil { + return err } pressure, err := sample() @@ -214,16 +208,10 @@ func (a *walAdmission) acquireContext(ctx context.Context, timeout time.Duration } } - if borrowed { - return nil - } // Acquire semaphore slot using the same deadline. select { case a.sem <- struct{}{}: granted = true - if hold != nil { - hold.owned = true - } return nil default: } @@ -233,9 +221,6 @@ func (a *walAdmission) acquireContext(ctx context.Context, timeout time.Duration select { case a.sem <- struct{}{}: granted = true - if hold != nil { - hold.owned = true - } return nil case <-ctx.Done(): if err := a.terminalFault(); err != nil { diff --git a/seaweed-block/core/storage/wal_write_hold.go b/seaweed-block/core/storage/wal_write_hold.go index 23dd083fe4..239ec8934d 100644 --- a/seaweed-block/core/storage/wal_write_hold.go +++ b/seaweed-block/core/storage/wal_write_hold.go @@ -16,7 +16,7 @@ var ( type walWriteHoldKey struct{} // A command owns this state across its sequential store batches. Only the -// command's write goroutine observes progress or finishes the lease. +// command's write goroutine observes progress or finishes the observations. type walWriteHold struct { waiting bool waitStarted time.Time @@ -29,14 +29,13 @@ type walWriteHold struct { window walHoldWindow progress ReclaimProgress started bool - owned bool finished bool } // WithWALWriteHold preserves caller cancellation/deadlines and one command // identity across adapter batches. The caller must FinishWALWriteHold after -// its final store call, including an error return. Cancel never releases an -// in-flight append's ticket; finish happens only once that append has returned. +// the byte command, including an error return. Each store append owns and +// releases its own ticket synchronously; cancellation cannot release it early. func WithWALWriteHold(ctx context.Context, s *WALStore, arrival time.Time, maxHold time.Duration, final bool) (context.Context, context.CancelFunc) { if h, _ := ctx.Value(walWriteHoldKey{}).(*walWriteHold); h != nil { return ctx, func() {} @@ -72,31 +71,8 @@ func admissionHold(ctx context.Context, a *walAdmission) *walWriteHold { return nil } -// BeginWALWriteHold takes the command ticket before adapter LBA locks. This -// prevents a younger command waiting for the ticket from holding a block lock -// that the oldest command needs in a later batch. -func BeginWALWriteHold(ctx context.Context) error { - h, _ := ctx.Value(walWriteHoldKey{}).(*walWriteHold) - if h == nil || h.owned { - return nil - } - s := h.store - if s.v3 != nil && s.v3.layoutFresh.Load() { - return ErrLayoutFresh - } - if s.admission == nil { - return nil - } - deadline := s.writeAdmissionDeadline(ctx) - wait := time.Duration(0) - if !deadline.IsZero() { - wait = time.Until(deadline) - } - return s.admission.acquireContext(ctx, wait, s.writePressureSample(ctx, deadline)) -} - -// FinishWALWriteHold relinquishes capacity ownership after the complete byte -// command, not after each store batch or from an asynchronous cancellation. +// FinishWALWriteHold records a complete byte command's pressure observations. +// Each store call has already released its admission ticket before returning. func FinishWALWriteHold(ctx context.Context, outcome error) { h, _ := ctx.Value(walWriteHoldKey{}).(*walWriteHold) if h == nil || h.finished { @@ -132,10 +108,6 @@ func FinishWALWriteHold(ctx context.Context, outcome error) { p := h.store.ReclaimProgress() log.Printf("storage: WAL write hold reason=%q held_ns=%d reclaimed_bytes=%d extent_bytes=%d phase=%s error=%q", reason, h.waitNanos, p.ReclaimedBytes, p.ExtentBytes, p.Phase, detail) } - if h.owned { - h.store.admission.Release() - h.owned = false - } } func (h *walWriteHold) start() { @@ -194,10 +166,3 @@ func (h *walWriteHold) check() error { } return nil } - -func (s *WALStore) releaseWriteAdmission(ctx context.Context) { - if h := holdFor(ctx, s); h != nil { - return - } - s.admission.Release() -} diff --git a/seaweed-block/core/storage/walstore.go b/seaweed-block/core/storage/walstore.go index c270916c61..8ec4c03012 100644 --- a/seaweed-block/core/storage/walstore.go +++ b/seaweed-block/core/storage/walstore.go @@ -542,7 +542,7 @@ func (s *WALStore) WriteContext(ctx context.Context, lba uint32, data []byte) (u if err := s.admission.acquireContext(ctx, wait, s.writePressureSample(ctx, deadline)); err != nil { return 0, fmt.Errorf("storage: WAL admission: %w", err) } - defer s.releaseWriteAdmission(ctx) + defer s.admission.Release() } if h := s.testAfterAdmit; h != nil { h() @@ -646,7 +646,7 @@ func (s *WALStore) WriteBatchContext(ctx context.Context, startLBA uint32, block if err := s.admission.acquireContext(ctx, wait, s.writePressureSample(ctx, deadline)); err != nil { return nil, fmt.Errorf("storage: WAL admission: %w", err) } - defer s.releaseWriteAdmission(ctx) + defer s.admission.Release() } if h := s.testAfterAdmit; h != nil { h() diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index 8f40420026..5ccd2ae01a 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -480,11 +480,11 @@ snapshot lifetime; local persistence does not bypass it. ticket remains held through the append-capacity decision and is released by the existing post-write Release. A cancelled or refused invocation removes its ticket and wakes the next. No queue mutex is held while sampling pressure, - waiting, or appending. A WAL frontend command retains that ticket through - all adapter batches and releases it after the final store call returns. -- A WAL frontend command carries one arrival-based hold identity and FIFO - ticket through adapter batches. Only the head consumes append capacity; - the byte adapter acquires the lease before LBA locks and finishes it after + waiting, or appending. Each store call releases its ticket before returning + to the adapter; it never spans an RMW read or a replica acknowledgement. +- An NVMe WAL frontend command carries one arrival-based hold identity through + adapter batches. Each store call joins FIFO admission separately and only + its head consumes append capacity. Command observations finish after all its store calls return. Caller cancellation and an earlier deadline stay effective. Successful reclaim/extent counter increases renew the per-command inactivity window, never its absolute cap. Other backends keep @@ -680,14 +680,14 @@ The "Machine / transition" column refers to Part A. Notes under a table record w | `INV-WAL-V3-RECORD-REFUSE-001` | The impl-3 codec refuses unknown types or flags, a zero nonce, invalid per-type geometry, overflowing spans and truncation before allocating a payload; the scanner reads a record only after those checks bound its size, and refuses nonzero padding, a bad CRC or a bad footer before using its bytes. | M1 v3 record framing | `core/storage/wal_entry_v3.go` `payloadSizeV3`, `decodeWALEntryV3`; `core/storage/wal_io_v3.go` `scanWALV3Accepted` | `TestWALEntryV3_RefusesInvalidEncode`, `TestWALEntryV3_RefusesMalformedWire`, `FuzzWALEntryV3_DecodeNeverPanics` | — | STUB | | `INV-WAL-V3-LSN-ORDER-001` | A v3 writer accepts only a first LSN above its highest consumed LSN; a batch consumes its whole validated range. Equal/lower requests return ErrWALLSNOrder before any pwrite or cursor change. Constructor coverage and a recovered kept frontier count as consumed; a fenced-away suffix does not. | M1 v3 append | `core/storage/wal_io_v3.go` `append`, `newWALWriterV3`, `restoreScanV3` | `TestWALLSNOrderV3_RefusesDuplicateAndLower`, `TestWALLSNOrderV3_BatchConsumesFullRange`, `TestWALLSNOrderV3_RestoreUsesKeptNotDroppedFrontier`, `TestWALLSNOrderV3_DescriptorFloorIsAlreadyConsumed`, `TestWALIOV3_ValidatedFrontierIntervals`, `TestWALIOV3_ConcurrentAppendsHaveUniqueCursors` | Physical LSN-strict prefix is a contract constraint; r16 model correspondence is pending | ACTIVE | | `INV-WAL-V3-ADMISSION-001` | v3 write admission measures WAL pressure from the active v3 writer's physical head minus the both-slot reuse floor, as a fraction of WALSize. | M1 Serving (write admission) | `core/storage/walstore.go` `openInitializedV3`, `WALStore.walUsedFraction`; `core/storage/write_command_budget.go` `WALStore.writePressureSample` | `TestWALStoreV3AdmissionUsesNativeOccupancy` (`core/storage/walstore_admission_v3_test.go`); `TestWALStoreV3WritePressureSampleMatchesOccupancy` (`core/storage/write_command_budget_test.go`); liveness under pressure: `TestWALStoreChunkV3_SequentialBurstFlush` (public provider and NVMe handler, default 64 MiB WAL, 320 MiB literal readback), `TestWALStoreChunkV3_BurstPatternBindsFullLBA` (32/64/256 MiB alias controls) (`core/frontend/durable/provider_chunk_burst_test.go`) | Existing reuse/durability rules unchanged; pressure/liveness is not a new model claim | ACTIVE | -| `INV-WAL-V3-ADMISSION-FIFO-001` | Write admission retains the oldest ticket through append capacity consumption, including every batch of a retryable-protocol WAL frontend command; a cancelled waiter relinquishes its ticket without blocking later writes. | M1 Serving (write admission) | `core/storage/wal_admission.go` `acquireContext`, `Release`; `core/storage/wal_admission_fifo.go` | `TestWALAdmissionFIFOOwnsCapacityThroughAppend`, `TestWALAdmissionFIFOCancelledWaiterDoesNotBlockNext`, `TestWALStoreAdmissionFIFOOrdersRealAppends`, `TestWALHoldTicketSpansBackendBatchesBeforeLBALocks` | WALHold r2 rows 325-333, `AdmitInOrder` | ACTIVE | +| `INV-WAL-V3-ADMISSION-FIFO-001` | Write admission retains the oldest ticket through one store append, then releases it before RMW reads or replica acknowledgement waits. Cancelled waiters relinquish their ticket; command batches rejoin admission separately. | M1 Serving (write admission) | `core/storage/wal_admission.go` `acquireContext`, `Release`; `core/storage/wal_admission_fifo.go` | `TestWALAdmissionFIFOOwnsCapacityThroughAppend`, `TestWALAdmissionFIFOCancelledWaiterDoesNotBlockNext`, `TestWALStoreAdmissionFIFOOrdersRealAppends`, `TestWALHoldReleasesAdmissionBeforeObserverAck`, `TestWALHoldDoesNotOwnAdmissionWhileWaitingForRMW` | WALHold r2 rows 325-333, `AdmitInOrder` | ACTIVE | | `INV-WAL-HOLD-WINDOW-001` | A command's WAL-pressure inactivity window starts no earlier than its own hold; a host retry gets a fresh window. Successful same-store reclaim or extent-byte increments renew it. | M1 Serving (write admission) | `core/storage/wal_write_hold.go` `start`, `check`; `wal_hold_window.go` | `TestWALWriteHoldStallIsTypedAndFreshPerCommand`, `TestWALWriteHoldMovingReclaimOutlastsOldAdmissionBudget`, `TestWALHoldWindowRetryGetsOwnStallWindow` | WALHold r2 rows 325-333, StallHoldsOwnWindow, ErrorOnlyOnStall | ACTIVE | | `INV-WAL-HOLD-CAP-001` | Progress does not renew a command's arrival-based hold cap. Startup refuses a non-positive network cap or a cap leaving less than five seconds before the declared host timeout. | M1 Serving (write admission) | `core/storage/wal_hold_window.go`; `core/frontend/wal_hold_config.go` | `TestWALWriteHoldCapWhileProgressMoves`, `TestWALHoldConfigHostTimeoutMargin`, `TestParseFlagsWALHoldHostTimeout` | WALHold r2 rows 325-333, NoHostTimeout, RetryOnlyAtCap | ACTIVE | -| `INV-WAL-HOLD-DEGRADED-001` | Five seconds of WAL pressure without progress marks reclaim diagnostically degraded; it does not change authority or frontend readiness. | M1 Serving (diagnostics) | `core/storage/wal_write_hold.go` `check`; `wal_hold_status.go`; `core/host/volume/status_server.go` | `TestWALWriteHoldDegradedBeforeFinalStallAndCancellationJoins`, `TestWALHoldDegradedDoesNotChangeReadiness`, `TestWALHoldTicketSpansBackendBatchesBeforeLBALocks` | WALHold r2 window; diagnostic projection only | ACTIVE | +| `INV-WAL-HOLD-DEGRADED-001` | Five seconds of WAL pressure without progress marks reclaim diagnostically degraded; it does not change authority or frontend readiness. | M1 Serving (diagnostics) | `core/storage/wal_write_hold.go` `check`; `wal_hold_status.go`; `core/host/volume/status_server.go` | `TestWALWriteHoldDegradedBeforeFinalStallAndCancellationJoins`, `TestWALHoldDegradedDoesNotChangeReadiness`, `TestWALHoldReleasesAdmissionBeforeObserverAck`, `TestWALHoldDoesNotOwnAdmissionWhileWaitingForRMW` | WALHold r2 window; diagnostic projection only | ACTIVE | | `INV-WAL-HOLD-OBSERVE-001` | The hold status and metrics routes read atomic progress without requiring general frontier locks and preserve the status listener's access policy. | M1 Serving (diagnostics) | `core/host/volume/wal_hold_metrics.go`; `DurableProvider.WALHoldStatuses` | `TestWALHoldMetricsAtomicSourceAndAccess`, `TestWALHoldAtomicStatusDoesNotReadFrontiers` | NONE (read-only observation) | ACTIVE | -| `INV-WAL-HOLD-TRANSPORT-SCOPE-001` | ublk and NBD explicitly retain the legacy write budget and cannot install a retryable WAL hold; final-error extended holds remain deferred. | M1 Serving (write admission) | `core/frontend/write_budget.go` `WithLegacyWriteBudget`; `core/frontend/durable/storage_adapter.go` `WriteCommandContext`; ublk and NBD write dispatch | `TestDeviceWriteKeepsLegacyBudget` (`core/frontend/ublk/device_write_budget_test.go`, `core/frontend/nbd/device_write_budget_test.go`); `TestDeviceLegacyBudgetDoesNotInstallARetryableWALHold` (`core/frontend/durable/device_write_scope_test.go`) | WALHold r2 rows 325-333; final-error activation deferred | ACTIVE | +| `INV-WAL-HOLD-TRANSPORT-SCOPE-001` | ublk, NBD and serial iSCSI explicitly retain the legacy write budget and cannot install a retryable WAL hold; final-error extended holds remain deferred. | M1 Serving (write admission) | `core/frontend/write_budget.go` `WithLegacyWriteBudget`; `core/frontend/durable/storage_adapter.go` `WriteCommandContext`; ublk, NBD and serial iSCSI write dispatch | `TestDeviceWriteKeepsLegacyBudget` (`core/frontend/ublk/device_write_budget_test.go`, `core/frontend/nbd/device_write_budget_test.go`); `TestDeviceLegacyBudgetDoesNotInstallARetryableWALHold` (`core/frontend/durable/device_write_scope_test.go`); `TestSerialISCSIWriteKeepsLegacyBudget` | WALHold r2 rows 325-333; final-error activation deferred | ACTIVE | | `INV-WAL-V3-ADMISSION-FAULT-001` | A terminal I/O fault latched while a v3 write waits on WAL pressure or for an admission slot ends that wait with the fault's original typed cause, also when the deadline has expired at the same check. | M1 Serving (write admission) | `core/storage/wal_admission.go` `walAdmission.acquireContext`, `walAdmission.terminalFault`; `core/storage/write_command_budget.go` `WALStore.writeBudgetError` | `TestWALStoreV3AdmissionReturnsFaultLatchedDuringPressureWait` (Write and WriteBatch); `TestWALStoreV3WriteBudgetKeepsTerminalFault` (`core/storage/write_command_budget_test.go`); also in `core/storage/wal_admission_fault_v3_test.go` | — | ACTIVE | -| `INV-WAL-V3-ADMISSION-DEADLINE-001` | A command keeps any earlier caller deadline across adapter batches. Retryable WAL commands use their arrival-based cap; explicit legacy device transports and other backends keep WriteCommandBudget. An expired command starts no new append. | M1 Serving (write admission) | `core/frontend/write_budget.go` `WithWriteBudget`; `core/frontend/durable/storage_adapter.go` `StorageBackend.Write`, `writeBytes`; `core/storage/write_command_budget.go` `WALStore.writeAdmissionDeadline`, `WALStore.acquireWriteLock`; `core/storage/walstore.go` `WALStore.WriteContext`, `WALStore.WriteBatchContext`; `core/storage/wal_write_hold.go` | `TestStorageBackendWriteKeepsOneDeadlineAcrossBatches`, `TestWALStoreV3WriteContextDeadlineIncludesCaptureWait`, `TestWALStoreV3WriteBudgetIncludesPostAdmissionWait`, `TestSessionWriteBudgetIncludesDispatchQueue`, `TestWALHoldBudgetSurvivesNestedNVMeDispatch`, `TestWALHoldTicketSpansBackendBatchesBeforeLBALocks` | — | ACTIVE | +| `INV-WAL-V3-ADMISSION-DEADLINE-001` | A command keeps any earlier caller deadline across adapter batches. Retryable WAL commands use their arrival-based cap; explicit legacy device transports and other backends keep WriteCommandBudget. An expired command starts no new append. | M1 Serving (write admission) | `core/frontend/write_budget.go` `WithWriteBudget`; `core/frontend/durable/storage_adapter.go` `StorageBackend.Write`, `writeBytes`; `core/storage/write_command_budget.go` `WALStore.writeAdmissionDeadline`, `WALStore.acquireWriteLock`; `core/storage/walstore.go` `WALStore.WriteContext`, `WALStore.WriteBatchContext`; `core/storage/wal_write_hold.go` | `TestStorageBackendWriteKeepsOneDeadlineAcrossBatches`, `TestWALStoreV3WriteContextDeadlineIncludesCaptureWait`, `TestWALStoreV3WriteBudgetIncludesPostAdmissionWait`, `TestSessionWriteBudgetIncludesDispatchQueue`, `TestWALHoldBudgetSurvivesNestedNVMeDispatch`, `TestWALHoldReleasesAdmissionBeforeObserverAck`, `TestWALHoldDoesNotOwnAdmissionWhileWaitingForRMW` | — | ACTIVE | | `INV-WAL-V3-ADMISSION-SHORTLOCK-001` | A v3 write takes the store, descriptor and WAL writer locks blocking, never by polling, so RWMutex writer preference holds, and its command deadline is checked once they are held. | M1 Serving (write admission) | `core/storage/walstore.go` `WALStore.WriteContext`, `WALStore.WriteBatchContext`; `core/storage/write_command_budget.go` `WALStore.writePressureSample`; `core/storage/wal_io_v3.go` `walWriterV3.append` | `TestWALStoreV3ExpiredWriterRefusesAfterShortLockWait`, `TestWALStoreV3WriteKeepsWriterPreferenceUnderReaders`, `TestWALStoreV3WriteBudgetRefusesAfterDescriptorWaitBehindSync` | — | ACTIVE | | `INV-WAL-V3-ADMISSION-NOPAYLOAD-001` | A v3 write whose command deadline has passed starts no new payload WAL write: the deadline is checked again after a checkpoint rollover and inside the WAL writer after its descriptor snapshot, lock wait and encoding, before the first payload write. | M1 Serving (write admission) | `core/storage/walstore_v3.go` `WALStore.appendWriteV3`, `WALStore.writeBatchV3Locked`, `WALStore.v3BudgetAfterRollover`; `core/storage/wal_io_v3.go` `walWriterV3.append` | `TestWALStoreV3WriteBudgetRefusesNewPayloadAfterRollover`, `TestWALStoreV3WriteBudgetRechecksAfterRollover` | — | ACTIVE | | `INV-WAL-V3-ADMISSION-EXPIRY-STATE-001` | A v3 write refused for an expired deadline before its append leaves the WAL bytes, nextLSN and the dirty map unchanged. | M1 Serving (write admission) | `core/storage/walstore.go` `WALStore.WriteContext`, `WALStore.WriteBatchContext` | `TestStorageBackendExpiredWriteDoesNotAppend` | — | ACTIVE | @@ -1402,7 +1402,7 @@ The two STUB rows of the start path are measured by the 1 TiB row's kill-and-res | Offline seal | M5 PlainStop -> Quiesce; `INV-CUT-PLAIN-DETACH-001` | Caller context; positive HTTP timeoutMs. Completed uploads resume only within one blockvolume process and matching owner/HEAD/chunk versions; after restart the seal must fit seal_timeout_ms. | Provider owns drain, detached cut and settlement. Cancellation preserves unknown/fenced outcome safety; a closed frontend stays closed. | No admission lock held during store or remote I/O. | | Plain seal remote proof | M5 RemoteProof; `INV-WS-SEAL-REPLAY-001` | Earlier caller context or existing 2 s HEAD-operation bound for the filer read; attachment serialization retains its owner's cooperative caller bound | Provider registers with Close; closeBoundRemote cancels the read, and Close joins it. Failure keeps frontend admission closed. | Attachment mutex serializes against recover/detach; no backend/store/map lock spans the filer read. | | Frontend pre-copy admission | M5 tentative admission -> resume; `INV-CUT-PRECOPY-001` (not reachable in this release) | Earlier of caller deadline and this command arrival + 5 s; one bound across retries, no inherited pause clock | Owner `finishPrecopyLocked`: resume or terminal Close clears the pause and grants all waiters in FIFO arrival order under one `b.mu` hold; each rechecks the ordinary gate. Expiry removes only its waiter and refuses with typed `ErrBackendBusy` + deadline cause (guest-visible: yes). Only a typed pause refusal requeues a granted waiter under the original command deadline; already-observed stale-primary and other gate errors are returned unchanged. Grant versus queue expiry is decided under the same lock; timely grants survive later queue-timer expiry but never caller expiry or a terminal gate. No dependency on another command's completion. | No `ioMu`, store lock, or remote call while queued. Admitted I/O retains normal per-LBA serialization and lifecycle accounting. | -| v3 write WAL-pressure admission: `core/storage/wal_admission.go` `walAdmission.acquireContext`, called by `WALStore.WriteContext` and `WALStore.WriteBatchContext` | M1 Serving (write admission); `INV-WAL-V3-ADMISSION-001`, `INV-WAL-V3-ADMISSION-DEADLINE-001`, `INV-WAL-V3-ADMISSION-FAULT-001` | The write's store admission deadline, fixed once when the write enters the store: the earlier of the caller's deadline and entry + 4 s (`admissionTimeout`), less a reserve of min(1 s, a quarter of the time then left), so at most entry + 3 s, on the local clock. In the soft band (pressure at least 0.70 and below 0.90) the pressure wait is one sleep of at most 5 ms. | Owner: the flusher. The wait wakes it (`NotifyUrgent`) on entry and at every 2 ms recheck while pressure is at or above the 0.90 hard watermark, and ends once the flusher's progress brings pressure below 0.90; a wait for one of the 64 admission slots ends when another write releases its slot. On expiry the write is refused before its append, with no WAL byte, nextLSN or dirty entry changed: `ErrWALPressureTimeout` (retryable; `frontend.ErrBackendBusy` at the durable backend), or the original fault when a terminal fault has latched, or `context.Canceled` when the caller cancelled. The wait grants no reuse and acknowledges nothing. | Held while waiting: the `captureMu` and `lifecycleMu` read locks, so a capture barrier, a BASE begin or complete, and `Close` wait behind it for at most this bound. Not held while it sleeps: the store, descriptor and WAL writer locks (each pressure sample takes and releases them). Local wait: no remote call. | +| v3 write WAL-pressure admission: `core/storage/wal_admission.go` `walAdmission.acquireContext`, called by `WALStore.WriteContext` and `WALStore.WriteBatchContext` | M1 Serving (write admission); `INV-WAL-V3-ADMISSION-001`, `INV-WAL-V3-ADMISSION-DEADLINE-001`, `INV-WAL-V3-ADMISSION-FAULT-001` | NVMe WAL hold commands share their arrival-based cap (default 25 s) and a per-command five-second inactivity window, renewed only by reclaimed/extent bytes. Explicit legacy transports keep the earlier of caller deadline and store entry + 4 s, less a reserve of min(1 s, a quarter of the time left). In the soft band (pressure at least 0.70 and below 0.90) the pressure wait is one sleep of at most 5 ms. | Owner: the flusher. The wait wakes it (`NotifyUrgent`) on entry and at every 2 ms recheck while pressure is at or above the 0.90 hard watermark, and ends once pressure falls below 0.90; FIFO admission then retains its ticket through that store append, releasing before adapter RMW/replica waits. On expiry the write is refused before its append, with no WAL byte, nextLSN or dirty entry changed: `ErrWALPressureTimeout` (retryable; `frontend.ErrBackendBusy` at the durable backend), or the original fault when a terminal fault has latched, or `context.Canceled` when the caller cancelled. The wait grants no reuse and acknowledges nothing. | Held while waiting: the `captureMu` and `lifecycleMu` read locks, so a capture barrier, a BASE begin or complete, and `Close` join the command's bounded admission wait (default cap 25 s for NVMe holds; legacy admission at most about 3 s). Started I/O and short locks remain cooperative. Not held while it sleeps: the store, descriptor and WAL writer locks (each pressure sample takes and releases them). Local wait: no remote call. | The WAL-pressure admission wait is the one wait here held under store locks (the `captureMu` and `lifecycleMu` read locks). It is a local wait: pressure samples, a timer and the flusher's local progress. No remote call is made while those locks are held, so the rule that no remote call runs under a lock still holds. diff --git a/seaweed-block/docs/operator-guide.md b/seaweed-block/docs/operator-guide.md index 5f87387aa2..87c6a3d415 100644 --- a/seaweed-block/docs/operator-guide.md +++ b/seaweed-block/docs/operator-guide.md @@ -679,10 +679,10 @@ Every command on the pages above, and the test that runs it. The holder cannot discover an initiator's I/O timeout. Set `blockvolume --host-io-timeout` (`host_io_timeout`) to match the hosts using the volume; the default is `30s`. If you raise or lower the hosts' `io_timeout`, change this setting to match. For hosts with different timeouts, use the shortest timeout. -For NVMe and iSCSI, the per-command WAL-pressure hold limit, `--wal-hold-timeout`, defaults to `25s`. Startup refuses a non-positive hold or a hold that leaves less than five seconds before `--host-io-timeout`: `hold + 5s <= host_io_timeout`. Thus the default `25s` hold and `30s` host timeout are valid. For a `15s` host timeout, set the hold to at most `10s`. The five-second margin allows for network and queueing delay; it does not configure the host. +For NVMe/TCP, the per-command WAL-pressure hold limit, `--wal-hold-timeout`, defaults to `25s`. Startup refuses a non-positive hold or a hold that leaves less than five seconds before `--host-io-timeout`: `hold + 5s <= host_io_timeout`. Thus the default `25s` hold and `30s` host timeout are valid. For a `15s` host timeout, set the hold to at most `10s`. The five-second margin allows for network and queueing delay; it does not configure the host. -For NVMe/TCP and iSCSI, a command waiting on WAL capacity keeps its FIFO position across all backend batches. Reclaimed WAL bytes or successful extent writes renew that command's five-second inactivity window; identical samples and flusher phase changes do not. At the hold cap or a five-second reclaim stall, NVMe returns retryable SC `0x82` (CRD2 when ACRE is negotiated); iSCSI returns BUSY `0x08` without sense data. Permanent storage faults keep their original failure classification. +For NVMe/TCP, each store append waiting on WAL capacity keeps its FIFO position until that append returns. A command keeps its arrival cap across batches, but each batch rejoins admission separately. The ticket is released before read-modify-write reads and replica acknowledgement waits. Reclaimed WAL bytes or successful extent writes renew that command's five-second inactivity window; identical samples and flusher phase changes do not. At the hold cap or a five-second reclaim stall, NVMe returns retryable SC `0x82` (CRD2 when ACRE is negotiated). Permanent storage faults keep their original failure classification. A five-second reclaim stall also sets diagnostic `Degraded` in status. Read `GET /status/wal-hold?volume=` for atomic hold counters, reclaimed/extent bytes and flusher phase, or `GET /metrics?volume=` for numeric metrics. These endpoints share the status listener's access rules and avoid frontier locks. A degraded reclaim diagnostic does not remove authority or turn frontend readiness off. Successful reclaim/extent progress clears that diagnostic. Hold events name `wal_hold_cap`, `wal_reclaim_stalled`, completion, cancellation or a write failure, with accumulated admission-wait nanoseconds. -The extended WAL-pressure hold policy is currently limited to the retryable network paths. ublk and NBD retain an explicit four-second backend write budget and can return a final EIO under pressure. Their final-error 30-second stall policy and device-timeout-derived cap are deferred until actual device timeout configuration and native controls are wired; the network host timeout declaration does not configure those devices. Do not assume the extended slow-reclaim guarantee for ublk/NBD. +The extended WAL-pressure hold policy is currently limited to NVMe/TCP. The serial iSCSI session keeps its existing short write/admission budget (four seconds for a command, about three seconds for WAL admission), returning BUSY under transient pressure; it does not hold its reader for the extended window. Long iSCSI holds require concurrent session command handling and initiator qualification. ublk and NBD retain an explicit four-second backend write budget and can return a final EIO under pressure. Their final-error 30-second stall policy and device-timeout-derived cap are deferred until actual device timeout configuration and native controls are wired; the network host timeout declaration does not configure those devices. Do not assume the extended slow-reclaim guarantee for ublk/NBD.