From 8b9cbfd0469f1f91fa80d63842ff6f7eb15bf34a Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 1 Aug 2026 02:45:55 -0700 Subject: [PATCH] test: attribute phase174 RF1 write boundaries --- .../core/frontend/durable/storage_adapter.go | 7 ++ .../frontend/durable/storage_adapter_test.go | 19 ++++ .../replication/phase174_fixed_work_test.go | 56 +++++++++++- .../phase174-d2-rf1-attribution-qa.md | 57 ++++++++++++ .../run-phase174-fixed-work-pipeline-gate.sh | 86 +++++++++++++++++++ 5 files changed, 223 insertions(+), 2 deletions(-) create mode 100644 seaweed-block/internal/docs/qa-assignments/phase174-d2-rf1-attribution-qa.md diff --git a/seaweed-block/core/frontend/durable/storage_adapter.go b/seaweed-block/core/frontend/durable/storage_adapter.go index 49ec959a8a..821fb830a1 100644 --- a/seaweed-block/core/frontend/durable/storage_adapter.go +++ b/seaweed-block/core/frontend/durable/storage_adapter.go @@ -327,6 +327,13 @@ func (b *StorageBackend) SetWriteAckPolicy(policy WriteAckPolicy) { b.mu.Unlock() } +// WriteProfile returns a read-only snapshot of the adapter's existing +// cumulative write counters. It does not enable instrumentation or alter the +// write path. +func (b *StorageBackend) WriteProfile() WriteProfileStatus { + return b.profile.snapshot() +} + // SetOperational flips the readiness gate. evidence is surfaced // in error strings and diagnostic logs — pass a short reason like // "recovered LSN=123 epoch=4" or "superblock ahead of assignment". diff --git a/seaweed-block/core/frontend/durable/storage_adapter_test.go b/seaweed-block/core/frontend/durable/storage_adapter_test.go index 8e91569e28..f682e95172 100644 --- a/seaweed-block/core/frontend/durable/storage_adapter_test.go +++ b/seaweed-block/core/frontend/durable/storage_adapter_test.go @@ -60,6 +60,25 @@ type partialBatchStorage struct { err error } +func TestStorageBackend_WriteProfileReturnsCurrentSnapshot(t *testing.T) { + b, _, _ := newTestBackend(t, logicalStorageFactories()[0], 16, 4096) + payload := make([]byte, 4096) + if _, err := b.Write(context.Background(), 0, payload); err != nil { + t.Fatal(err) + } + + profile := b.WriteProfile() + if profile.BackendWriteRequestOps != 1 || profile.BackendWriteRequestBytes != uint64(len(payload)) { + t.Fatalf("request profile=%+v", profile) + } + if profile.BackendWriteOps != 1 || profile.BackendWriteBytes != uint64(len(payload)) { + t.Fatalf("write profile=%+v", profile) + } + if profile.BackendStorageWriteCalls != 1 || profile.BackendStorageWriteBlocks != 1 { + t.Fatalf("storage profile=%+v", profile) + } +} + func (s partialBatchStorage) WriteBatch(_ uint32, _ [][]byte) ([]uint64, error) { return []uint64{1}, s.err } diff --git a/seaweed-block/core/replication/phase174_fixed_work_test.go b/seaweed-block/core/replication/phase174_fixed_work_test.go index 8a974738f6..5e67dd90e6 100644 --- a/seaweed-block/core/replication/phase174_fixed_work_test.go +++ b/seaweed-block/core/replication/phase174_fixed_work_test.go @@ -64,6 +64,26 @@ type phase174FixedWorkResult struct { FinalSyncNanos int64 `json:"final_sync_ns"` CloseRecoverNanos int64 `json:"close_recover_ns"` PrimaryWALWrites uint64 `json:"primary_wal_write_ops"` + PrimaryWALCopyNanos uint64 `json:"primary_wal_copy_ns"` + PrimaryWALEncodeNanos uint64 `json:"primary_wal_encode_ns"` + PrimaryWALChecksumNanos uint64 `json:"primary_wal_checksum_ns"` + PrimaryWALAppendNanos uint64 `json:"primary_wal_append_ns"` + PrimaryAppendWaitNanos uint64 `json:"primary_wal_append_lock_wait_ns"` + PrimaryCommitWaitNanos uint64 `json:"primary_commit_lock_wait_ns"` + PrimaryDirtyMapNanos uint64 `json:"primary_dirty_map_ns"` + AdapterRequestOps uint64 `json:"adapter_request_ops,omitempty"` + AdapterRequestBytes uint64 `json:"adapter_request_bytes,omitempty"` + AdapterWriteOps uint64 `json:"adapter_write_ops,omitempty"` + AdapterWriteBytes uint64 `json:"adapter_write_bytes,omitempty"` + AdapterWriteNanos uint64 `json:"adapter_write_ns,omitempty"` + AdapterStorageCalls uint64 `json:"adapter_storage_write_calls,omitempty"` + AdapterStorageBlocks uint64 `json:"adapter_storage_write_blocks,omitempty"` + FlusherCycles uint64 `json:"foreground_flusher_cycles"` + FlusherCycleNanos uint64 `json:"foreground_flusher_cycle_ns"` + FlusherExtentWriteOps uint64 `json:"foreground_flusher_extent_write_ops"` + FlusherExtentWriteNanos uint64 `json:"foreground_flusher_extent_write_ns"` + FlusherExtentSyncOps uint64 `json:"foreground_flusher_extent_sync_ops"` + FlusherExtentSyncNanos uint64 `json:"foreground_flusher_extent_sync_ns"` PrimaryStableLSN uint64 `json:"primary_stable_lsn"` PrimaryHeadLSN uint64 `json:"primary_head_lsn"` ReplicationWrites uint64 `json:"replication_write_ops,omitempty"` @@ -299,12 +319,17 @@ func runPhase174FixedWork(t *testing.T, p *phase174Pipeline, set, run, writers i } writeBefore := p.primary.WriteInstrumentation() + flusherBefore := p.primary.FlusherInstrumentation() + adapterBefore := p.adapterProfile() replicationBefore := p.replicationStats() payloads := phase174Payloads(phase174APIOperations, set, run, 0x1741) foreground, latencies, err := phase174RunWrites(p, writers, 0, payloads, true) if err != nil { t.Fatalf("measured writes: %v", err) } + writeForeground := p.primary.WriteInstrumentation() + flusherForeground := p.primary.FlusherInstrumentation() + adapterForeground := p.adapterProfile() syncStart := time.Now() if err := p.sync(context.Background()); err != nil { t.Fatalf("final sync: %v", err) @@ -348,8 +373,28 @@ func runPhase174FixedWork(t *testing.T, p *phase174Pipeline, set, run, writers i MiBPerSecond: (float64(logicalBytes) / (1024 * 1024)) / foreground.Seconds(), P50Nanos: p50, P95Nanos: p95, P99Nanos: p99, FinalSyncNanos: finalSync.Nanoseconds(), CloseRecoverNanos: closeRecover.Nanoseconds(), - PrimaryWALWrites: writeAfter.WALEncodeOps - writeBefore.WALEncodeOps, - PrimaryStableLSN: primaryR, PrimaryHeadLSN: primaryH, + PrimaryWALWrites: writeAfter.WALEncodeOps - writeBefore.WALEncodeOps, + PrimaryWALCopyNanos: writeForeground.WALCopyDurationNanos - writeBefore.WALCopyDurationNanos, + PrimaryWALEncodeNanos: writeForeground.WALEncodeDurationNanos - writeBefore.WALEncodeDurationNanos, + PrimaryWALChecksumNanos: writeForeground.WALChecksumDurationNanos - writeBefore.WALChecksumDurationNanos, + PrimaryWALAppendNanos: writeForeground.WALAppendDurationNanos - writeBefore.WALAppendDurationNanos, + PrimaryAppendWaitNanos: writeForeground.WALAppendLockWaitNanos - writeBefore.WALAppendLockWaitNanos, + PrimaryCommitWaitNanos: writeForeground.WriteCommitLockWaitNanos - writeBefore.WriteCommitLockWaitNanos, + PrimaryDirtyMapNanos: writeForeground.DirtyMapUpdateDurationNanos - writeBefore.DirtyMapUpdateDurationNanos, + AdapterRequestOps: adapterForeground.BackendWriteRequestOps - adapterBefore.BackendWriteRequestOps, + AdapterRequestBytes: adapterForeground.BackendWriteRequestBytes - adapterBefore.BackendWriteRequestBytes, + AdapterWriteOps: adapterForeground.BackendWriteOps - adapterBefore.BackendWriteOps, + AdapterWriteBytes: adapterForeground.BackendWriteBytes - adapterBefore.BackendWriteBytes, + AdapterWriteNanos: adapterForeground.BackendWriteDurationNanos - adapterBefore.BackendWriteDurationNanos, + AdapterStorageCalls: adapterForeground.BackendStorageWriteCalls - adapterBefore.BackendStorageWriteCalls, + AdapterStorageBlocks: adapterForeground.BackendStorageWriteBlocks - adapterBefore.BackendStorageWriteBlocks, + FlusherCycles: flusherForeground.CyclesStarted - flusherBefore.CyclesStarted, + FlusherCycleNanos: flusherForeground.CycleDurationNanos - flusherBefore.CycleDurationNanos, + FlusherExtentWriteOps: flusherForeground.ExtentWriteOps - flusherBefore.ExtentWriteOps, + FlusherExtentWriteNanos: flusherForeground.ExtentWriteDurationNanos - flusherBefore.ExtentWriteDurationNanos, + FlusherExtentSyncOps: flusherForeground.ExtentSyncOps - flusherBefore.ExtentSyncOps, + FlusherExtentSyncNanos: flusherForeground.ExtentSyncDurationNanos - flusherBefore.ExtentSyncDurationNanos, + PrimaryStableLSN: primaryR, PrimaryHeadLSN: primaryH, ReplicaCount: len(p.replicaPaths), ReplicaDurableCount: durableReplicas, ReplicaFrontiersEqual: replicasEqual, FlusherPhaseReset: flusherPhaseReset, @@ -424,6 +469,13 @@ func (p *phase174Pipeline) replicationStats() VolumeStats { return p.replication.Stats() } +func (p *phase174Pipeline) adapterProfile() durable.WriteProfileStatus { + if p.backend == nil { + return durable.WriteProfileStatus{} + } + return p.backend.WriteProfile() +} + type phase174FlusherResetter interface { ResetFlusherForMeasurement() error } diff --git a/seaweed-block/internal/docs/qa-assignments/phase174-d2-rf1-attribution-qa.md b/seaweed-block/internal/docs/qa-assignments/phase174-d2-rf1-attribution-qa.md new file mode 100644 index 0000000000..14db0533c7 --- /dev/null +++ b/seaweed-block/internal/docs/qa-assignments/phase174-d2-rf1-attribution-qa.md @@ -0,0 +1,57 @@ +# Phase 174 D2 RF1 Boundary Attribution QA + +Run the Phase 174 fixed-work pipeline gate from the assignment commit. D2 +extends the D1 matrix with existing WALStore, flusher, and durable-adapter +counter deltas; it does not add hot-path instrumentation or change product +behavior. + +## Purpose + +Explain the unstable `adapter_rf1` four-writer baseline before any architecture +candidate is allowed. The same 16,384-operation, 64 MiB, `local_durable` work +must reconcile through: + +- durable adapter requests, successful writes, bytes, storage calls, and + blocks; +- WAL encode, append, dirty-map, and global commit-lock wait; +- foreground flusher cycles, extent writes, and extent syncs; +- merged CPU, block, and mutex profiles from five direct and five adapter + diagnostic repeats. + +Durations are accumulated concurrent work, not wall time. The gate reports +per-operation medians and correlation with foreground wall time; it must not +sum overlapping measurements into a throughput claim. + +## Run + +```bash +export SW_BLOCK_ARTIFACT_DIR=/path/to/results/phase174-d2-rf1-attribution +export SW_BLOCK_PHASE174_STORE_DIR=/path/on/dedicated/nvme/phase174-d2-stores +export SW_BLOCK_PHASE174_CPUSET=0,2,4,6 +bash scripts/run-phase174-fixed-work-pipeline-gate.sh /path/to/seaweed_block +``` + +## Required Evidence + +- all 90 D1 rows retain their ACK, recovery, correctness, and cleanup checks; +- every adapter four-writer row has exactly 16,384 requests, writes, storage + calls, and blocks, plus 64 MiB at both adapter byte counters; +- `rf1_attribution_counter_reconciliation=true`; +- `rf1_attribution_status=ok` even if the unchanged D1 stability verdict is + `hold`; +- per-operation medians and foreground correlations exist for adapter total, + accounted storage, commit wait, encode, append, dirty map, unattributed + adapter work, and foreground flusher work; +- merged CPU, block, and mutex tops exist for direct and adapter; +- `architecture_candidate_selected=false` and no product mutation is present; +- store residue is zero. + +## Verdict + +- `PASS`: attribution counters reconcile and identify the measured boundary; + this does not override a D1 HOLD or authorize implementation. +- `FAIL`: any operation/byte count, profile, correctness, or cleanup evidence + is missing. + +D2 remains open for RF3 distinct-node and frontend attribution after this RF1 +slice. diff --git a/seaweed-block/scripts/run-phase174-fixed-work-pipeline-gate.sh b/seaweed-block/scripts/run-phase174-fixed-work-pipeline-gate.sh index b90c38dfc7..1f4106d79b 100644 --- a/seaweed-block/scripts/run-phase174-fixed-work-pipeline-gate.sh +++ b/seaweed-block/scripts/run-phase174-fixed-work-pipeline-gate.sh @@ -124,8 +124,39 @@ for set_id in 1 2; do done done +for layer in direct_walstore adapter_rf1; do + cpu_profiles=() + block_profiles=() + mutex_profiles=() + for profile_run in $(seq 1 "${RUNS}"); do + prefix="${ARTIFACT_DIR}/profiles/${layer}-run${profile_run}" + mkdir -p "${ARTIFACT_DIR}/profiles" + SW_BLOCK_PHASE174_STORE_DIR="${STORE_DIR}" \ + SW_BLOCK_PHASE174_LAYER="${layer}" \ + SW_BLOCK_PHASE174_WRITERS=4 \ + SW_BLOCK_PHASE174_SET=1 \ + SW_BLOCK_PHASE174_RUN="${profile_run}" \ + GOMAXPROCS="${GOMAXPROCS_VALUE}" taskset -c "${CPUSET}" \ + "${TEST_BINARY}" -test.run '^TestPhase174FixedWorkPipeline$' -test.count=1 \ + -test.cpuprofile="${prefix}-cpu.pprof" \ + -test.blockprofile="${prefix}-block.pprof" -test.blockprofilerate=1 \ + -test.mutexprofile="${prefix}-mutex.pprof" -test.mutexprofilefraction=1 \ + >"${prefix}.log" 2>&1 + cpu_profiles+=("${prefix}-cpu.pprof") + block_profiles+=("${prefix}-block.pprof") + mutex_profiles+=("${prefix}-mutex.pprof") + done + go tool pprof -top -nodecount=30 "${TEST_BINARY}" "${cpu_profiles[@]}" \ + >"${ARTIFACT_DIR}/profiles/${layer}-cpu-top.txt" 2>&1 + go tool pprof -top -nodecount=30 "${TEST_BINARY}" "${block_profiles[@]}" \ + >"${ARTIFACT_DIR}/profiles/${layer}-block-top.txt" 2>&1 + go tool pprof -top -nodecount=30 "${TEST_BINARY}" "${mutex_profiles[@]}" \ + >"${ARTIFACT_DIR}/profiles/${layer}-mutex-top.txt" 2>&1 +done + python3 - "${RESULTS}" "${SUMMARY}" "${RUNS}" "${MAX_RANGE}" <<'PY' import json +import math import statistics import sys from collections import defaultdict @@ -183,6 +214,21 @@ def set_rate_range(layer, writers, set_id): raise SystemExit(f"group {(layer, writers)} set={set_id} rows={len(values)} want {runs}") return max(values) / min(values) +def median_per_op(rows, field): + return statistics.median(row[field] / row["api_operations"] for row in rows) + +def correlation(rows, field): + xs = [float(row["foreground_ns"]) for row in rows] + ys = [float(row[field]) for row in rows] + x_mean = statistics.mean(xs) + y_mean = statistics.mean(ys) + numerator = sum((x - x_mean) * (y - y_mean) for x, y in zip(xs, ys)) + x_norm = math.sqrt(sum((x - x_mean) ** 2 for x in xs)) + y_norm = math.sqrt(sum((y - y_mean) ** 2 for y in ys)) + if x_norm == 0 or y_norm == 0: + return 0.0 + return numerator / (x_norm * y_norm) + with open(summary_path, "a", encoding="utf-8") as out: for layer in ("direct_walstore", "adapter_rf1", "rf3_tcp"): for writers in (1, 4, 8): @@ -207,11 +253,51 @@ with open(summary_path, "a", encoding="utf-8") as out: for row in rf3_rows ) queue_saturation_rows = sum(row.get("peer_queue_saturated", 0) > 0 for row in rf3_rows) + adapter_rows = groups[("adapter_rf1", 4)] + for row in adapter_rows: + if row["adapter_request_ops"] != row["api_operations"]: + raise SystemExit(f"adapter request count mismatch: {row}") + if row["adapter_write_ops"] != row["api_operations"]: + raise SystemExit(f"adapter write count mismatch: {row}") + if row["adapter_request_bytes"] != row["logical_bytes"] or row["adapter_write_bytes"] != row["logical_bytes"]: + raise SystemExit(f"adapter byte count mismatch: {row}") + if row["adapter_storage_write_calls"] != row["api_operations"]: + raise SystemExit(f"adapter storage call count mismatch: {row}") + if row["adapter_storage_write_blocks"] != row["api_operations"]: + raise SystemExit(f"adapter storage block count mismatch: {row}") + row["storage_attributed_ns"] = ( + row["primary_commit_lock_wait_ns"] + + row["primary_wal_encode_ns"] + + row["primary_wal_append_lock_wait_ns"] + + row["primary_wal_append_ns"] + + row["primary_dirty_map_ns"] + ) + row["adapter_unattributed_ns"] = max(0, row["adapter_write_ns"] - row["storage_attributed_ns"]) + attribution_fields = ( + "adapter_write_ns", + "storage_attributed_ns", + "primary_commit_lock_wait_ns", + "primary_wal_encode_ns", + "primary_wal_append_ns", + "primary_dirty_map_ns", + "adapter_unattributed_ns", + "foreground_flusher_cycle_ns", + ) + dominant = max( + ("storage_attributed", "adapter_unattributed"), + key=lambda name: median_per_op(adapter_rows, f"{name}_ns"), + ) out.write(f"direct_walstore_writers_4_set1_max_min_ratio={direct_set_ranges[0]:.3f}\n") out.write(f"direct_walstore_writers_4_set2_max_min_ratio={direct_set_ranges[1]:.3f}\n") out.write(f"adapter_rf1_writers_4_set1_max_min_ratio={adapter_set_ranges[0]:.3f}\n") out.write(f"adapter_rf1_writers_4_set2_max_min_ratio={adapter_set_ranges[1]:.3f}\n") out.write(f"rf1_direct_adapter_four_writer_ratio={adapter_four / direct_four:.3f}\n") + for field in attribution_fields: + out.write(f"adapter_rf1_writers_4_{field}_per_op={median_per_op(adapter_rows, field):.3f}\n") + out.write(f"adapter_rf1_writers_4_{field}_foreground_correlation={correlation(adapter_rows, field):.3f}\n") + out.write(f"adapter_rf1_dominant_accounted_boundary={dominant}\n") + out.write("rf1_attribution_counter_reconciliation=true\n") + out.write("rf1_attribution_status=ok\n") out.write(f"rf1_local_stability_gate={'pass' if rf1_stable else 'hold'}\n") out.write(f"rf3_same_host_healthy_baseline={str(rf3_healthy).lower()}\n") out.write(f"rf3_queue_saturation_row_count={queue_saturation_rows}\n")