phase147: document wal multiblock record design gate

This commit is contained in:
pingqiu committed 2026-07-06 15:54:09 -07:00
1 parent fa77e110a5
commit 7b5250ed66
8 files changed
+498 -42

No files matched your search

@@ -88,6 +88,7 @@ The supported-lab claim is intentionally narrow:
| 144 | 64KiB NVMe/TCP WAL encode/append pair profile | PASS |
| 145 | WAL record materialization allocation reduction | PASS |
| 146 | WAL materialization effectiveness profile | PASS |
| 147 | WAL multi-block record design gate | PASS |
Key QA sign-offs:
@@ -118,6 +119,7 @@ Key QA sign-offs:
- `internal/docs/qa-assignments/phase144-wal-encode-append-pair-profile-qa-signoff.md`
- `internal/docs/qa-assignments/phase145-wal-record-materialization-reduction-qa-signoff.md`
- `internal/docs/qa-assignments/phase146-wal-record-materialization-effectiveness-qa-signoff.md`
- `internal/docs/qa-assignments/phase147-wal-multiblock-record-design-qa-signoff.md`
## Performance Baseline
@@ -518,6 +520,26 @@ This keeps the Phase 145 allocation reduction, but it remains lab evidence and
not a throughput/SLO claim. The next backend gate should select a deeper WAL
design path, such as multi-block WAL records or vectored write-at.
Phase 147 selected that deeper path:
```text
phase147_wal_multiblock_record_design_status=ok
current_wal_format_unchanged=true
current_recovery_compatibility=pass
candidate_design=multi_block_record
candidate_reduces_record_count=true
candidate_reduces_write_calls=false
durability_invariant_documented=true
recovery_invariant_documented=true
phase147_decision=prototype_next
next_recommendation=phase148_wal_multiblock_record_local_prototype
cleanup_status=ok
```
The design gate keeps the current WAL format unchanged and documents the
required format-version, CRC, dirty-map, recovery, flusher, checkpoint, and
dirty-read invariants before any prototype writes a new record shape.
Phase 127 closes the source/component side of the ANA Change Notice gap:
```text
+3 -2
View File
@@ -113,8 +113,9 @@ Seaweed Block can already demonstrate a narrow Kubernetes block-storage loop:
Phase 145 removes one local batch-allocation seam without changing WAL format
or recovery semantics. Phase 146 measured that change as visible in the lab
profile, but it is still not a default or performance/SLO claim. The next
backend step is a WAL multi-block-record or vectored-write design gate, not a
public performance claim.
backend step selected by Phase 147 is a disabled-by-default multi-block WAL
record prototype. The current WAL format remains unchanged until local
encode/decode, dirty-read, recovery-split, and flusher-split tests pass.
- Kubernetes NVMe/TCP mounted reconnect is source-gated through changed
desired path-set evidence: CSI-node can connect a newly published desired
NVMe path, prune the stale old host path for the same NQN, preserve pod
+36 -40
View File
@@ -1,73 +1,69 @@
# Current Plan: Phase 147 WAL Multi-Block Record Design Gate
# Current Plan: Phase 148 WAL Multi-Block Record Local Prototype
Status: planning.
Phase 146 closed the WAL materialization effectiveness profile:
Phase 147 closed the WAL multi-block record design gate:
```text
phase146_wal_record_materialization_effectiveness_status=ok
wal_record_materialization_change=writebatch_value_entries
candidate_max_h2c_bytes=65536
target_write_request_max_bytes=65536
backend_write_request_max_bytes=65536
wal_encode_duration_ms=281
wal_append_duration_ms=280
phase146_pair_improvement_pct=5.24
phase146_effectiveness=visible
phase146_decision=keep_change
next_recommendation=phase147_wal_multiblock_record_design_gate
phase147_wal_multiblock_record_design_status=ok
current_wal_format_unchanged=true
current_recovery_compatibility=pass
candidate_design=multi_block_record
candidate_reduces_record_count=true
candidate_reduces_write_calls=false
durability_invariant_documented=true
recovery_invariant_documented=true
phase147_decision=prototype_next
next_recommendation=phase148_wal_multiblock_record_local_prototype
cleanup_status=ok
```
## Goal
Decide the next deeper WAL optimization path without changing durability
semantics by accident. The candidate designs are:
- multi-block WAL records: encode multiple contiguous block writes into one WAL
record;
- vectored write-at: keep the current record format but reduce materialization
or syscall/copy shape with a platform-gated write path.
Prototype a multi-block WAL record locally behind an explicit feature gate. The
prototype must prove encode/decode, dirty read, recovery split, and flusher split
semantics without changing the default WAL format or Kubernetes behavior.
## Required Evidence
```text
phase147_wal_multiblock_record_design_status=ok
phase148_wal_multiblock_record_local_prototype_status=ok
frontend_transport=tcp
roce_claim_allowed=false
nvme_rdma_claim_allowed=false
performance_slo_claim_allowed=false
current_wal_format_unchanged=true
default_wal_format_unchanged=true
feature_gate_default=false
multiblock_encode_decode=pass
multiblock_dirty_read=pass
multiblock_recovery_split=pass
multiblock_flusher_split=pass
single_block_compatibility=pass
current_recovery_compatibility=pass
candidate_design=<multi_block_record|vectored_writeat|defer>
candidate_reduces_record_count=<true|false>
candidate_reduces_write_calls=<true|false>
durability_invariant_documented=true
recovery_invariant_documented=true
phase147_decision=<prototype_next|defer|blocked>
phase148_decision=<profile_next|defer|blocked>
next_recommendation=<specific next phase>
cleanup_status=ok
```
## Boundaries
- Do not change the WAL on-disk format in Phase 147.
- Do not add Linux-specific writev/pwritev behavior without an explicit
fallback contract.
- Do not enable the new record shape by default.
- Do not use the new record shape from Kubernetes/blockvolume in this phase.
- Do not raise the default H2C size.
- Do not claim throughput/SLO from this design gate.
- Keep old single-block WAL recovery compatibility green.
## Candidate Work
1. Document the current WAL record/recovery invariants and the exact point where
contiguous writes could be grouped safely.
2. Add a local design gate that proves current WAL format/recovery tests still
pass unchanged.
3. Produce an explicit prototype recommendation:
`multi_block_record`, `vectored_writeat`, or `defer`.
1. Add a disabled-by-default local option for multi-block WAL records.
2. Encode/decode one batch record as `firstLSN + blockIndex` and
`firstLBA + blockIndex`.
3. Extend only the local test path enough to prove dirty reads, recovery split,
and flusher split.
4. Keep current single-block format as default and compatibility path.
## Exit Criteria
Phase 147 can close when the next WAL optimization is selected with durability
and recovery invariants written down, or when the work is explicitly deferred as
too risky for the current NVMe/TCP supported-lab track.
Phase 148 can close when the prototype proves correctness locally or is
explicitly deferred with a concrete blocker. A later phase must run the mounted
NVMe/TCP profile before any user-facing performance statement.
@@ -0,0 +1,45 @@
# Phase 147 Finished Plan: WAL Multi-Block Record Design Gate
Status: **closed 2026-07-06, local gate PASS**.
## Problem
Phase 146 showed the Phase 145 allocation reduction is visible, but further
small local materialization tweaks are unlikely to be the highest-leverage path.
The current append path already coalesces many encoded records into fewer
`WriteAt` calls. The remaining structural cost is per-record encode/checksum and
recovery work.
## Work
Phase 147 added:
- `internal/docs/protocol/phase147-wal-multiblock-record-design.md`;
- `scripts/run-phase147-wal-multiblock-record-design-gate.sh`.
The design gate pins the current WAL format as unchanged, runs current
storage/durable recovery tests, and documents the required invariants for a
future multi-block WAL record.
## Evidence
```text
phase147_wal_multiblock_record_design_status=ok
current_wal_format_unchanged=true
current_recovery_compatibility=pass
candidate_design=multi_block_record
candidate_reduces_record_count=true
candidate_reduces_write_calls=false
durability_invariant_documented=true
recovery_invariant_documented=true
phase147_decision=prototype_next
next_recommendation=phase148_wal_multiblock_record_local_prototype
cleanup_status=ok
```
## Conclusion
The next WAL optimization should be a local, feature-gated multi-block record
prototype. The prototype must not change defaults or live Kubernetes behavior
until encode/decode, dirty reads, recovery splitting, flusher splitting, and
compatibility tests pass.
@@ -478,6 +478,11 @@ rebuild, delete safety, or cleanup must start as a separate gated phase.
non-claim that this is not a throughput/SLO release statement. The next
backend gate should select a deeper WAL path: multi-block WAL records or
vectored write-at, with durability/recovery invariants documented first.
- Phase 147 is closed for that design gate. It selected `multi_block_record`
over vectored write-at because the current append path already coalesces
encoded records into fewer `WriteAt` calls, while record count remains the
structural encode/recovery cost. The current WAL format stays unchanged; the
next phase may prototype a disabled-by-default multi-block record locally.
- Later protocol candidates: complete a real NVMe/RDMA target, characterize
NVMe/TCP performance, or bridge to object/NIXL acceleration where the product
surface is object/storage rather than block PVC. Keep these separate so
@@ -0,0 +1,231 @@
# Phase 147 WAL Multi-Block Record Design Gate
Status: design gate, no on-disk format change in this phase.
## Why This Exists
The NVMe/TCP write path now has enough evidence to stop guessing:
- Phase 140 traced the old 32KiB write shape to the NVMe/TCP target
`MaxH2CDataLength`.
- Phase 141 added a 64KiB H2C opt-in and proved Linux host compatibility in the
lab.
- Phase 142 showed the remaining product-owned cost moved to WAL append/encode.
- Phase 143/144 showed append and encode are tied under the 64KiB shape.
- Phase 145 removed one safe per-record allocation seam.
- Phase 146 measured that local change as visible, but still not a public
performance/SLO claim.
The current WAL path already coalesces many independently encoded records into
one adjacent `WriteAt` through `walWriter.appendBatch`. That means the next
material improvement is unlikely to come from another small append wrapper. The
remaining high-leverage target is the number of WAL records and per-record
encode/checksum work.
## Current WAL Format
`core/storage/wal_entry.go` defines the current record layout:
```text
prefix:
LSN uint64
Reserved uint64
Type uint8
Flags uint8
LBA uint64
Length uint32
data:
Length bytes for walEntryWrite / walEntryPadding
trailer:
CRC32 uint32
EntrySize uint32
```
Current fixed overhead:
```text
walEntryPrefixSize = 30
walEntryHeaderSize = 38
```
Current write semantics:
- `walEntryWrite` represents exactly one block write.
- `LSN` is the LSN for that one block.
- `LBA` is the block address for that one block.
- `Length` must equal `BlockSize` for normal writes.
- `Data` is copied into the encoded WAL record.
- CRC covers prefix + data and the trailer stores CRC + total entry size.
Current batch execution:
- `WALStore.WriteBatch(startLBA, blocks)` allocates consecutive LSNs.
- It creates one `walEntry` per block.
- `walWriter.appendBatch` validates each record, serializes each record, and
appends adjacent encoded bytes into a pending buffer.
- The pending buffer is written with fewer `WriteAt` calls, but recovery still
sees independent single-block records.
Current recovery and flush assumptions:
- `recoverWAL` scans one record at a time.
- `dirtyMap` records one WAL offset per LBA.
- `readFromWAL` reads one record and returns one block.
- `flusher.flushOnce` reads each dirty entry's header, checks the on-disk LSN
matches the dirty-map LSN, reads one block, writes one extent slot, then
advances checkpoint to the highest verified flushed LSN.
## Design Choice
Candidate selected by this gate:
```text
candidate_design=multi_block_record
candidate_reduces_record_count=true
candidate_reduces_write_calls=false
```
Rationale:
- A vectored `pwritev` path could reduce some temporary buffer copying, but the
current append path already coalesces adjacent encoded records into one
`WriteAt` per pending region.
- A vectored path does not reduce `wal_encode_ops`, per-record CRC/trailer work,
recovery record count, or dirty-map entries.
- A multi-block WAL record can reduce record count and per-record encode/checksum
overhead for the common full-block contiguous WriteBatch path.
- A multi-block record changes WAL format semantics and therefore must be
versioned and gated separately.
## Proposed Multi-Block Record
Add a new WAL entry type in a future phase:
```text
walEntryWriteBatch = 0x04
```
Proposed encoded meaning:
```text
LSN = first LSN in the batch
Reserved = block count
Type = walEntryWriteBatch
Flags = 0 initially
LBA = first LBA in the batch
Length = blockCount * blockSize
Data = blockCount contiguous block payloads
CRC32 = checksum(prefix + full Data)
EntrySize = walEntryHeaderSize + Length
```
Per-block logical identity:
```text
block i:
lsn = firstLSN + i
lba = firstLBA + i
data = Data[i*blockSize : (i+1)*blockSize]
```
This design only applies to contiguous full-block `WriteBatch` calls. Single
`Write` calls, non-contiguous future writes, trim, barrier, padding, direct
extent writes, and recovery apply paths keep their current semantics until
explicitly redesigned.
## Required Invariants
`INV-WAL-BATCH-FORMAT-VERSION`
A multi-block record requires a WALStore format/version gate. Do not silently
write `walEntryWriteBatch` into a store that advertises the current
`WALStoreImplVersion=1`. A future prototype must either bump the implementation
version or add an explicit feature bit that old readers reject safely.
`INV-WAL-BATCH-CRC-ALL-OR-NOTHING`
The batch record CRC covers the entire batch. Recovery must not partially replay
a CRC-failed multi-block record. A torn or corrupted multi-block record is a
record-level failure, not a per-block best-effort replay.
`INV-WAL-BATCH-LSN-CONTIGUOUS`
The record's `LSN` is the first LSN. Per-block LSNs are contiguous
`firstLSN+i`. `WriteBatch` already allocates this shape today; a future
prototype must keep the same allocation before WAL append.
`INV-WAL-BATCH-LBA-CONTIGUOUS`
The record's `LBA` is the first LBA. Per-block LBAs are contiguous
`firstLBA+i`. The optimization must not be used for non-contiguous writes unless
the record format is extended to carry an explicit LBA table.
`INV-WAL-BATCH-DIRTYMAP-OFFSET`
The dirty map can no longer store only `(LBA -> WALOffset, LSN, Length)` if many
LBAs point to one WAL record. It must also know the in-record block index or
data offset, or `readFromWAL` must decode the batch and select the requested
block. Without this, reads of dirty data would return the first block for every
LBA in the batch.
`INV-WAL-BATCH-RECOVERY-SPLIT`
Recovery must split one batch record into per-LBA dirty-map entries and
per-block recovery entries:
```text
for i in [0, blockCount):
dirtyMap.put(firstLBA+i, walOffset, firstLSN+i, blockSize, dataOffset=i*blockSize)
```
The recovered frontier is the highest per-block LSN in the batch.
`INV-WAL-BATCH-FLUSH-SPLIT`
The flusher must write each block to its own extent slot and compare/delete
dirty-map entries by their per-block LSN. It must not treat one batch record as
one extent write.
`INV-WAL-BATCH-CHECKPOINT-HIGHEST-LSN`
Checkpoint advancement remains based on the highest verified per-block LSN that
was flushed. For a fully flushed batch, that is `firstLSN + blockCount - 1`.
`INV-WAL-BATCH-READ-ONE-BLOCK`
`Read(lba)` must continue returning exactly one block. If the dirty-map entry
points into a batch, `readFromWAL` must return only the selected block's slice.
`INV-WAL-BATCH-FALLBACK-CURRENT-FORMAT`
The current single-block `walEntryWrite` path must remain available as fallback.
The prototype must be disableable, and current format recovery tests must pass
with the feature disabled.
## Prototype Checklist
Before enabling any multi-block record in a live gate:
1. Add the version/feature gate and make unsupported readers fail closed.
2. Add encode/decode tests for a batch record, including CRC mismatch and torn
tail.
3. Extend dirty-map metadata to include in-record block offset.
4. Extend recovery scanning to split batch records.
5. Extend dirty read path to return the selected block from a batch.
6. Extend flusher to split batch records into extent writes and checkpoint by
highest per-block LSN.
7. Prove compatibility: existing single-block WAL stores still recover.
8. Prove fallback: feature disabled keeps current format and current tests pass.
9. Add instrumentation: record count, batch block count, batch bytes, and
fallback count.
10. Only then run a mounted NVMe/TCP profile gate.
## Decision
```text
phase147_decision=prototype_next
next_recommendation=phase148_wal_multiblock_record_local_prototype
```
The next phase should prototype the format behind an explicit local feature
gate, not turn it on in Kubernetes or change defaults.
@@ -0,0 +1,81 @@
# Phase 147 QA Sign-off: WAL Multi-Block Record Design Gate
Status: **PASS**.
Branch: `phase147-wal-multiblock-record-design-gate`.
## Scope
Phase 147 is a local executable design gate. It does not change WAL on-disk
format, Kubernetes behavior, H2C defaults, or public NVMe/TCP claims.
The gate selects the next deeper WAL optimization direction and documents the
durability/recovery invariants that must be satisfied before any prototype can
write a new WAL record shape.
## Checks
```text
bash -n scripts/run-phase147-wal-multiblock-record-design-gate.sh
bash scripts/run-phase147-wal-multiblock-record-design-gate.sh
```
The gate also runs:
```text
go test ./core/storage ./core/frontend/durable
```
Result:
```text
ok github.com/seaweedfs/seaweed-block/core/storage
ok github.com/seaweedfs/seaweed-block/core/frontend/durable
```
## Summary
```text
phase147_wal_multiblock_record_design_status=ok
frontend_transport=tcp
roce_claim_allowed=false
nvme_rdma_claim_allowed=false
performance_slo_claim_allowed=false
current_wal_format_unchanged=true
current_recovery_compatibility=pass
candidate_design=multi_block_record
candidate_reduces_record_count=true
candidate_reduces_write_calls=false
durability_invariant_documented=true
recovery_invariant_documented=true
phase147_decision=prototype_next
next_recommendation=phase148_wal_multiblock_record_local_prototype
cleanup_status=ok
```
## Decision
The selected prototype path is `multi_block_record`.
Reasoning:
- `walWriter.appendBatch` already coalesces adjacent encoded records into fewer
`WriteAt` calls.
- A vectored write path would mostly attack temporary materialization/copy, not
record count.
- A multi-block record can reduce per-record encode/checksum/recovery overhead,
but requires explicit WAL format/version, dirty-map, read, flusher, and
recovery changes.
The required invariants are documented in:
```text
internal/docs/protocol/phase147-wal-multiblock-record-design.md
```
## Verdict
Phase 147 passes. The current WAL format remains unchanged and recovery tests
still pass. Phase 148 may start a local, feature-gated multi-block WAL record
prototype. Do not enable it in Kubernetes or claim performance until a later
mounted NVMe/TCP profile gate passes.
@@ -0,0 +1,75 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT="${1:-$(pwd)}"
ARTIFACT_DIR="${SW_BLOCK_ARTIFACT_DIR:-${ROOT}/results/phase147-wal-multiblock-record-design-gate}"
SUMMARY="${ARTIFACT_DIR}/phase147-wal-multiblock-record-design-summary.txt"
DESIGN_DOC="${ROOT}/internal/docs/protocol/phase147-wal-multiblock-record-design.md"
if [[ -n "${SW_BLOCK_GO_BIN:-}" ]]; then
GO_BIN="${SW_BLOCK_GO_BIN}"
elif command -v go.exe >/dev/null 2>&1; then
GO_BIN="go.exe"
else
GO_BIN="go"
fi
mkdir -p "${ARTIFACT_DIR}"
: >"${SUMMARY}"
write_summary() {
echo "$*" | tee -a "${SUMMARY}" >/dev/null
}
require_text() {
local path="$1"
local pattern="$2"
local label="$3"
if ! grep -Fq "$pattern" "$path"; then
echo "missing ${label}: ${pattern}" >&2
exit 1
fi
}
require_source_text() {
local rel="$1"
local pattern="$2"
local label="$3"
require_text "${ROOT}/${rel}" "$pattern" "$label"
}
write_summary "phase147_wal_multiblock_record_design_status=running"
write_summary "frontend_transport=tcp"
write_summary "roce_claim_allowed=false"
write_summary "nvme_rdma_claim_allowed=false"
write_summary "performance_slo_claim_allowed=false"
require_source_text "core/storage/wal_entry.go" "walEntryHeaderSize = 38" "current WAL header size"
require_source_text "core/storage/wal_entry.go" "walEntryWrite = 0x01" "current write entry type"
require_source_text "core/storage/superblock.go" "const WALStoreImplVersion uint32 = 1" "current WALStore impl version"
write_summary "current_wal_format_unchanged=true"
cd "${ROOT}"
"${GO_BIN}" test ./core/storage ./core/frontend/durable \
>"${ARTIFACT_DIR}/go-test-recovery-compatibility.log" \
2>&1
write_summary "current_recovery_compatibility=pass"
require_text "${DESIGN_DOC}" "candidate_design=multi_block_record" "candidate design"
require_text "${DESIGN_DOC}" "candidate_reduces_record_count=true" "record-count decision"
require_text "${DESIGN_DOC}" "candidate_reduces_write_calls=false" "write-call decision"
require_text "${DESIGN_DOC}" "INV-WAL-BATCH-FORMAT-VERSION" "format version invariant"
require_text "${DESIGN_DOC}" "INV-WAL-BATCH-CRC-ALL-OR-NOTHING" "durability invariant"
require_text "${DESIGN_DOC}" "INV-WAL-BATCH-RECOVERY-SPLIT" "recovery split invariant"
require_text "${DESIGN_DOC}" "INV-WAL-BATCH-FLUSH-SPLIT" "flush split invariant"
require_text "${DESIGN_DOC}" "phase147_decision=prototype_next" "phase decision"
require_text "${DESIGN_DOC}" "next_recommendation=phase148_wal_multiblock_record_local_prototype" "next recommendation"
write_summary "candidate_design=multi_block_record"
write_summary "candidate_reduces_record_count=true"
write_summary "candidate_reduces_write_calls=false"
write_summary "durability_invariant_documented=true"
write_summary "recovery_invariant_documented=true"
write_summary "phase147_decision=prototype_next"
write_summary "next_recommendation=phase148_wal_multiblock_record_local_prototype"
write_summary "cleanup_status=ok"
write_summary "phase147_wal_multiblock_record_design_status=ok"