mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
fix: preserve terminal faults in WAL pressure waits and bind burst bytes to full LBA
This commit is contained in:
1 parent
1ae48b7939
commit
dffda03239
4 files changed
+32
-6
No files matched your search
@@ -72,9 +72,9 @@ func TestWALStoreChunkV3_SequentialBurstFlush(t *testing.T) {
|
||||
if n != transfer {
|
||||
t.Fatalf("short readback at%d: %d", off, n)
|
||||
}
|
||||
for i, b := range got {
|
||||
if want := byte(off/transfer) + byte(i); b != want {
|
||||
t.Fatalf("readback byte%d=%#x want%#x", off+i, b, want)
|
||||
for i := 0; i < len(got); i += 8 {
|
||||
if word := binary.LittleEndian.Uint64(got[i : i+8]); word != uint64(off+i) {
|
||||
t.Fatalf("readback word at byte%d=%d want%d", off+i, word, off+i)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,8 +82,8 @@ func TestWALStoreChunkV3_SequentialBurstFlush(t *testing.T) {
|
||||
}
|
||||
|
||||
func fillBurstTransfer(data []byte, off int) {
|
||||
for i := range data {
|
||||
data[i] = byte(off/len(data)) + byte(i)
|
||||
for i := 0; i < len(data); i += 8 {
|
||||
binary.LittleEndian.PutUint64(data[i:i+8], uint64(off+i))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ type walAdmission struct {
|
||||
softMark float64
|
||||
hardMark float64
|
||||
closedFn func() bool
|
||||
faultFn func() error // lock-free terminal fault lookup; nil for controllers without a store
|
||||
|
||||
sleepFn func(time.Duration) // replaceable for tests
|
||||
|
||||
@@ -48,6 +49,7 @@ type walAdmissionConfig struct {
|
||||
WALUsedFn func() float64
|
||||
NotifyFn func()
|
||||
ClosedFn func() bool
|
||||
FaultFn func() error
|
||||
}
|
||||
|
||||
// newWALAdmission constructs an admission controller. Caller must
|
||||
@@ -63,6 +65,7 @@ func newWALAdmission(cfg walAdmissionConfig) *walAdmission {
|
||||
softMark: cfg.SoftWatermark,
|
||||
hardMark: cfg.HardWatermark,
|
||||
closedFn: cfg.ClosedFn,
|
||||
faultFn: cfg.FaultFn,
|
||||
sleepFn: time.Sleep,
|
||||
}
|
||||
}
|
||||
@@ -99,6 +102,10 @@ func (a *walAdmission) Acquire(timeout time.Duration) error {
|
||||
a.notifyFn()
|
||||
hardStart := time.Now()
|
||||
for a.walUsed() >= a.hardMark {
|
||||
if err := a.terminalFault(); err != nil {
|
||||
a.hardPressureWaitNs.Add(time.Since(hardStart).Nanoseconds())
|
||||
return err
|
||||
}
|
||||
if a.closedFn() {
|
||||
a.hardPressureWaitNs.Add(time.Since(hardStart).Nanoseconds())
|
||||
return errVolumeClosed
|
||||
@@ -107,6 +114,9 @@ func (a *walAdmission) Acquire(timeout time.Duration) error {
|
||||
select {
|
||||
case <-deadline.C:
|
||||
a.hardPressureWaitNs.Add(time.Since(hardStart).Nanoseconds())
|
||||
if err := a.terminalFault(); err != nil {
|
||||
return err
|
||||
}
|
||||
return errWALFull
|
||||
default:
|
||||
}
|
||||
@@ -143,8 +153,14 @@ func (a *walAdmission) Acquire(timeout time.Duration) error {
|
||||
case a.sem <- struct{}{}:
|
||||
return nil
|
||||
case <-deadline.C:
|
||||
if err := a.terminalFault(); err != nil {
|
||||
return err
|
||||
}
|
||||
return errWALFull
|
||||
case <-closeTick.C:
|
||||
if err := a.terminalFault(); err != nil {
|
||||
return err
|
||||
}
|
||||
if a.closedFn() {
|
||||
return errVolumeClosed
|
||||
}
|
||||
@@ -154,3 +170,12 @@ func (a *walAdmission) Acquire(timeout time.Duration) error {
|
||||
|
||||
// Release returns a write slot to the semaphore.
|
||||
func (a *walAdmission) Release() { <-a.sem }
|
||||
|
||||
// terminalFault is sampled only on waiting paths. The store supplies its atomic
|
||||
// latch lookup; this does not acquire a store lock or perform persistence I/O.
|
||||
func (a *walAdmission) terminalFault() error {
|
||||
if a.faultFn != nil {
|
||||
return a.faultFn()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -384,6 +384,7 @@ func openInitializedInternal(path string, f *os.File, sb *superblock, metadata B
|
||||
SoftWatermark: 0.70,
|
||||
HardWatermark: 0.90,
|
||||
WALUsedFn: s.walUsedFraction,
|
||||
FaultFn: s.stickyIOFault,
|
||||
NotifyFn: func() {
|
||||
if s.flusher != nil {
|
||||
s.flusher.NotifyUrgent()
|
||||
|
||||
@@ -286,7 +286,7 @@ The "Machine / transition" column refers to Part A. Notes under a table record w
|
||||
| `INV-WAL-V3-DESCRIPTOR-001` | A v3 descriptor slot is used only if it is valid. It needs a matching CRC32C (Castagnoli), every reserved byte zero, an accepted impl, a nonzero slotGen at most 2^64-2 and a nonzero nonce. Its geometry must be consistent with checked arithmetic, its BASE fields must follow their per-state rules, and CheckpointLSN ≤ mapCoveredCheckpoint ≤ W must hold. Of the two slots, the valid selectable one with the higher slotGen wins. A prepared migration slot is never selected. Equal generations with different bytes, or slots that disagree on identity or geometry, are refused. | M1 Opened (v3 descriptor selection) | `core/storage/superblock_v3.go` `decodeSlotV3`, `selectSlotV3`, `nextSlotGenV3` | `TestSlotV3VectorsDecodeAsExpected`, `TestSlotV3Selection`, `TestSlotV3CounterExhaustion`, `TestSlotV3InstalledMayHaveCursorBelowTail` (`core/storage/superblock_v3_test.go`) | — | STUB |
|
||||
| `INV-WAL-V3-RECORD-001` | An impl-3 record codec uses the fixed 62-byte prefix and 70-byte overhead, CRC32C and an explicit EntrySize. It refuses unknown types/flags, a zero nonce, invalid per-type geometry, overflowing count/LSN/cursor or LBA spans, nonzero padding, bad CRC/footer and truncation before allocating a payload. Codec success alone is not nonce/cursor/lap replay admission. | M1 v3 record framing | `core/storage/wal_entry_v3.go` `payloadSizeV3`, `encodeWALEntryV3`, `decodeWALEntryV3` | `TestWALEntryV3_CanonicalBarrierBytes`, `TestWALEntryV3_TypeFootprints`, `TestWALEntryV3_RefusesInvalidEncode`, `TestWALEntryV3_RefusesMalformedWire`, `FuzzWALEntryV3_DecodeNeverPanics` | `WALRecovery` abstract record validity; physical byte rules are code-test obligations | 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 | STUB |
|
||||
| `INV-WAL-V3-ADMISSION-001` | Native v3 WAL pressure uses its physical writer head minus the both-slot reuse floor, never the inactive legacy writer. Existing soft/hard waits wake the flusher without holding store, descriptor or writer locks. No wait grants reuse or acknowledges writes. | M1 Serving (write admission) | `walstore.go` `walUsedFraction`, `openInitializedInternal`; `wal_admission.go` `Acquire` | `TestWALStoreV3AdmissionUsesNativeOccupancy`; `TestWALStoreChunkV3_SequentialBurstFlush` (public provider and NVMe handler, default 64 MiB WAL, 320 MiB literal readback) | Existing reuse/durability rules unchanged; pressure/liveness is not a new model claim | ACTIVE |
|
||||
| `INV-WAL-V3-ADMISSION-001` | Native v3 WAL pressure uses its physical writer head minus the both-slot reuse floor, never the inactive legacy writer. Existing soft/hard waits wake the flusher without holding store, descriptor or writer locks. A terminal I/O fault latched during a pressure or semaphore wait ends that wait with the original typed cause; timeout must not mask an already observed fault. No wait grants reuse or acknowledges writes. | M1 Serving (write admission) | `walstore.go` `walUsedFraction`, `openInitializedInternal`; `wal_admission.go` `Acquire` | `TestWALStoreV3AdmissionUsesNativeOccupancy`; `TestWALStoreV3AdmissionReturnsFaultLatchedDuringPressureWait` (Write and WriteBatch); `TestWALStoreChunkV3_SequentialBurstFlush`; `TestWALStoreChunkV3_BurstPatternBindsFullLBA` (public provider and NVMe handler, default 64 MiB WAL, 320 MiB literal readback) | Existing reuse/durability rules unchanged; pressure/liveness is not a new model claim | ACTIVE |
|
||||
| `INV-WAL-V3-RECLAIM-001` | A mapped v3 checkpoint releases only complete validated record ends covered by the checkpoint and outside the retention window; an installing BASE retains its install suffix. Physical recovery rebuilds the volatile boundary index only from the trusted kept scan, without restoring a disconnect cursor. Tail/head/map/checkpoint/W publish together, followed by metadata-only rollover; both slot tails still pin reuse. Failure grants no reuse and retains exact dirty retry identity. Checkpoint publication excludes writer admission through both-slot rollover and dirty-reference retirement. Idle, unchanged-checkpoint and admission settle pending rollover; catch-up revalidates tail/checkpoint before delivering its buffered scan. | M1 checkpoint / existing two-slot retirement | `wal_io_v3.go` `reclaimThroughV3`, `rememberReclaimScanV3`; `walstore_map_checkpoint_v3.go` `publishCheckpointV3`; `descriptor_v3.go` `rolloverIfPinned` | `TestWALStoreV3CheckpointReclaimsAcrossRingLaps`, `TestWALStoreV3ReclaimKeepsPartialBatchAndRetention`, `TestWALStoreV3ReclaimRebuildsIndexAfterPhysicalRecovery`, `TestWALStoreV3ReclaimAfterInstallingPhysicalReopen`, `TestWALStoreV3ReclaimSecondSlotFailureKeepsOldPin`, `TestWALStoreV3ReclaimRetiresReferencesBeforeReuse`, `TestWALStoreV3ReclaimRolloverProgressWithoutNewCheckpoint`, tagged `TestCatchUpV3AfterCheckpointRingReuse`, `TestCatchUpV3ScanOverlappingCheckpointReuseIsRecycled` | Existing dual-slot retirement and nonce/cursor contract; concrete index/recovery/caller wiring is a code-test obligation | STUB |
|
||||
| `INV-WAL-V3-OWNER-001` | v3 read/write open, offline readonly open and migrate-v3 acquire the same exclusive nonblocking OS file lock before reading slots or changing bytes. Contention refuses with volume locked; descriptor close releases it, allowing retry. | M1 open admission / offline migration precondition | `core/storage/volume_lock*.go`; `walstore_v3.go`; `walstore_readonly_v3.go`; `cmd/sw-block/migrate.go` | `TestMigrateV3RefusesAnOpenV3Volume`, `TestMigrateV3ExcludesOpenUntilCommitFinishes` (tag `swblock_format_v3_test`), `TestWALStoreV3CreatorKeepsOwnershipThroughPublication`, `TestWALStoreV3OwnerExcludesOpenAndReadOnly` | OS mutual exclusion is a caller obligation, outside the abstract crash model; existing open states unchanged | STUB |
|
||||
| `INV-WAL-V3-CATCHUP-001` | A dark v3 catch-up source refuses while installing, including an empty at-head request. Requests covered by an installed BASE require rebuild (typed WALRecycled); damage in retained WAL remains an integrity failure. Before emitting any entries the scan revalidates recovery generation, nonce, BASE state/ID and install epoch, so begin/complete/retire ABA cannot publish a superseded prefix. | M1 BASE lifecycle / M3 CatchingUp (dark callers) | `core/storage/walstore_recovery.go` `ScanLBAs`, `scanLBAsV3`, `v3CatchUpEntries` | `TestCatchUpV3InstallingAtHeadRefuses`, `TestCatchUpV3CompletedBASEUsesRebuild`, `TestCatchUpV3InstallRetireABARefusesOldScan`, `TestCatchUpV3CorruptFirstRecordFails`, `TestCatchUpV3CorruptMiddleRecordFails`, `TestCatchUpV3CompletedBASESuffix` (tag `swblock_format_v3_test`, actual catch-up sender) | Existing BASE and catch-up transitions unchanged; this physical scan/source-lifetime obligation is covered by deterministic caller tests | STUB |
|
||||
|
||||
Reference in new issue
Block a user