diff --git a/seaweed-block/core/replication/phase174_fixed_work_test.go b/seaweed-block/core/replication/phase174_fixed_work_test.go index 5e67dd90e6..6f69985adb 100644 --- a/seaweed-block/core/replication/phase174_fixed_work_test.go +++ b/seaweed-block/core/replication/phase174_fixed_work_test.go @@ -91,6 +91,9 @@ type phase174FixedWorkResult struct { ReplicationAckWaitNanos uint64 `json:"replication_ack_wait_ns,omitempty"` PeerQueueMaxDepth uint64 `json:"peer_queue_max_depth,omitempty"` PeerQueueSaturated uint64 `json:"peer_queue_saturated,omitempty"` + PostMeasurementDrain bool `json:"post_measurement_sync_all"` + PostMeasurementDrainNS int64 `json:"post_measurement_sync_all_ns,omitempty"` + RemoteReplicaEvidence bool `json:"remote_replica_evidence_required"` ReplicaCount int `json:"replica_count"` ReplicaDurableCount int `json:"replica_durable_count"` ReplicaFrontiersEqual bool `json:"replica_frontiers_equal"` @@ -108,15 +111,17 @@ func (v *phase174HealthyView) Projection() frontend.Projection { } type phase174Pipeline struct { - layer phase174Layer - primaryPath string - replicaPaths []string - primary *storage.WALStore - replicas []*storage.WALStore - backend *durable.StorageBackend - replication *ReplicationVolume - listeners []*transport.ReplicaListener - closed bool + layer phase174Layer + primaryPath string + replicaPaths []string + primary *storage.WALStore + replicas []*storage.WALStore + backend *durable.StorageBackend + replication *ReplicationVolume + listeners []*transport.ReplicaListener + configuredReplicas int + remoteReplicas bool + closed bool } func TestPhase174FixedWorkContract(t *testing.T) { @@ -179,7 +184,7 @@ func TestPhase174FixedWorkPipeline(t *testing.T) { groupDir := filepath.Join(storeRoot, fmt.Sprintf("set%d-%s-writers%d", set, layer, writers)) create := run == 0 - if layer == phase174RF3TCP { + if layer == phase174RF3TCP && os.Getenv(phase174RemoteReplicasEnv) == "" { // Same-host durable RF3 is diagnostic: sync-quorum may let one peer // lag, so every sample needs independent stores rather than inheriting // an intentionally incomplete replica from the previous sample. @@ -249,23 +254,32 @@ func newPhase174Pipeline(t *testing.T, layer phase174Layer, dir string, create b if layer == phase174RF3TCP { p.replication = NewReplicationVolume("phase174", p.primary) p.replication.SetDurabilityMode(DurabilitySyncQuorum) - targets := make([]ReplicaTarget, 0, 2) - for replica := 1; replica <= 2; replica++ { - path := filepath.Join(dir, fmt.Sprintf("replica-%d.store", replica)) - store := phase174OpenWALStore(t, path, create) - listener, err := transport.NewReplicaListener("127.0.0.1:0", store) - if err != nil { - t.Fatal(err) - } - listener.Serve() - p.replicaPaths = append(p.replicaPaths, path) - p.replicas = append(p.replicas, store) - p.listeners = append(p.listeners, listener) - targets = append(targets, ReplicaTarget{ - ReplicaID: fmt.Sprintf("r%d", replica), DataAddr: listener.Addr(), - ControlAddr: listener.Addr(), Epoch: 1, EndpointVersion: 1, - }) + targets, err := phase174RemoteReplicaTargets() + if err != nil { + t.Fatal(err) } + if len(targets) > 0 { + p.remoteReplicas = true + } else { + targets = make([]ReplicaTarget, 0, 2) + for replica := 1; replica <= 2; replica++ { + path := filepath.Join(dir, fmt.Sprintf("replica-%d.store", replica)) + store := phase174OpenWALStore(t, path, create) + listener, err := transport.NewReplicaListener("127.0.0.1:0", store) + if err != nil { + t.Fatal(err) + } + listener.Serve() + p.replicaPaths = append(p.replicaPaths, path) + p.replicas = append(p.replicas, store) + p.listeners = append(p.listeners, listener) + targets = append(targets, ReplicaTarget{ + ReplicaID: fmt.Sprintf("r%d", replica), DataAddr: listener.Addr(), + ControlAddr: listener.Addr(), Epoch: 1, EndpointVersion: 1, + }) + } + } + p.configuredReplicas = len(targets) if err := p.replication.UpdateReplicaSet(1, targets); err != nil { t.Fatal(err) } @@ -338,6 +352,15 @@ func runPhase174FixedWork(t *testing.T, p *phase174Pipeline, set, run, writers i if reached := p.waitForReplicaFrontier(2 * time.Second); len(p.replicas) > 0 && reached < 1 { t.Fatalf("no replica reached final frontier") } + var postMeasurementDrain time.Duration + if p.remoteReplicas { + p.replication.SetDurabilityMode(DurabilitySyncAll) + drainStart := time.Now() + if err := p.sync(context.Background()); err != nil { + t.Fatalf("post-measurement sync-all: %v", err) + } + postMeasurementDrain = time.Since(drainStart) + } writeAfter := p.primary.WriteInstrumentation() replicationAfter := p.replicationStats() if got := writeAfter.WALEncodeOps - writeBefore.WALEncodeOps; got != phase174APIOperations { @@ -395,7 +418,9 @@ func runPhase174FixedWork(t *testing.T, p *phase174Pipeline, set, run, writers i FlusherExtentSyncOps: flusherForeground.ExtentSyncOps - flusherBefore.ExtentSyncOps, FlusherExtentSyncNanos: flusherForeground.ExtentSyncDurationNanos - flusherBefore.ExtentSyncDurationNanos, PrimaryStableLSN: primaryR, PrimaryHeadLSN: primaryH, - ReplicaCount: len(p.replicaPaths), ReplicaDurableCount: durableReplicas, + PostMeasurementDrain: p.remoteReplicas, PostMeasurementDrainNS: postMeasurementDrain.Nanoseconds(), + RemoteReplicaEvidence: p.remoteReplicas, + ReplicaCount: p.configuredReplicas, ReplicaDurableCount: durableReplicas, ReplicaFrontiersEqual: replicasEqual, FlusherPhaseReset: flusherPhaseReset, CloseRecoverComplete: true, CorrectnessSamples: correctness, diff --git a/seaweed-block/core/replication/phase174_remote_replica_test.go b/seaweed-block/core/replication/phase174_remote_replica_test.go new file mode 100644 index 0000000000..da21c8936b --- /dev/null +++ b/seaweed-block/core/replication/phase174_remote_replica_test.go @@ -0,0 +1,211 @@ +package replication + +import ( + "bytes" + "encoding/json" + "fmt" + "net" + "os" + "path/filepath" + "strconv" + "strings" + "testing" + "time" + + "github.com/seaweedfs/seaweed-block/core/storage" + "github.com/seaweedfs/seaweed-block/core/transport" +) + +const ( + phase174RemoteReplicasEnv = "SW_BLOCK_PHASE174_REMOTE_REPLICAS" + phase174ReplicaStoreEnv = "SW_BLOCK_PHASE174_REPLICA_STORE" + phase174ReplicaListenEnv = "SW_BLOCK_PHASE174_REPLICA_LISTEN" + phase174ReplicaReadyFileEnv = "SW_BLOCK_PHASE174_REPLICA_READY_FILE" + phase174ReplicaStopFileEnv = "SW_BLOCK_PHASE174_REPLICA_STOP_FILE" + phase174ReplicaResultEnv = "SW_BLOCK_PHASE174_REPLICA_RESULT_FILE" + phase174ReplicaFinalSetEnv = "SW_BLOCK_PHASE174_REPLICA_FINAL_SET" + phase174ReplicaFinalRunEnv = "SW_BLOCK_PHASE174_REPLICA_FINAL_RUN" +) + +type phase174RemoteReplicaResult struct { + Status string `json:"status"` + ListenAddress string `json:"listen_address"` + StableLSN uint64 `json:"stable_lsn"` + HeadLSN uint64 `json:"head_lsn"` + ExpectedHeadLSN uint64 `json:"expected_head_lsn"` + CorrectnessSamples int `json:"correctness_samples"` +} + +func phase174RemoteReplicaTargets() ([]ReplicaTarget, error) { + raw := strings.TrimSpace(os.Getenv(phase174RemoteReplicasEnv)) + if raw == "" { + return nil, nil + } + addresses := strings.Split(raw, ",") + if len(addresses) != 2 { + return nil, fmt.Errorf("phase174: %s must contain exactly two addresses", phase174RemoteReplicasEnv) + } + targets := make([]ReplicaTarget, 0, len(addresses)) + hosts := make(map[string]struct{}, len(addresses)) + for index, value := range addresses { + address := strings.TrimSpace(value) + host, port, err := net.SplitHostPort(address) + if err != nil { + return nil, fmt.Errorf("phase174: remote replica address %q: %w", address, err) + } + ip := net.ParseIP(host) + if ip == nil || ip.IsLoopback() || ip.IsUnspecified() { + return nil, fmt.Errorf("phase174: remote replica host %q must be a non-loopback IP", host) + } + if _, err := strconv.ParseUint(port, 10, 16); err != nil { + return nil, fmt.Errorf("phase174: remote replica port %q: %w", port, err) + } + if _, exists := hosts[ip.String()]; exists { + return nil, fmt.Errorf("phase174: remote replicas must use distinct hosts") + } + hosts[ip.String()] = struct{}{} + targets = append(targets, ReplicaTarget{ + ReplicaID: fmt.Sprintf("remote-r%d", index+1), DataAddr: address, + ControlAddr: address, Epoch: 1, EndpointVersion: 1, + }) + } + return targets, nil +} + +func TestPhase174RemoteReplicaTargetContract(t *testing.T) { + t.Setenv(phase174RemoteReplicasEnv, "192.0.2.1:17411,192.0.2.2:17412") + targets, err := phase174RemoteReplicaTargets() + if err != nil { + t.Fatal(err) + } + if len(targets) != 2 || targets[0].DataAddr != "192.0.2.1:17411" || targets[1].DataAddr != "192.0.2.2:17412" { + t.Fatalf("targets=%+v", targets) + } + + for _, invalid := range []string{ + "192.0.2.1:17411", + "127.0.0.1:17411,192.0.2.2:17412", + "192.0.2.1:17411,192.0.2.1:17412", + } { + t.Setenv(phase174RemoteReplicasEnv, invalid) + if _, err := phase174RemoteReplicaTargets(); err == nil { + t.Fatalf("accepted remote replica addresses %q", invalid) + } + } +} + +func TestPhase174RemoteReplicaProcess(t *testing.T) { + storePath := os.Getenv(phase174ReplicaStoreEnv) + if storePath == "" { + t.Skip("remote replica process requires " + phase174ReplicaStoreEnv) + } + listenAddress := os.Getenv(phase174ReplicaListenEnv) + readyFile := os.Getenv(phase174ReplicaReadyFileEnv) + stopFile := os.Getenv(phase174ReplicaStopFileEnv) + resultFile := os.Getenv(phase174ReplicaResultEnv) + if listenAddress == "" || readyFile == "" || stopFile == "" || resultFile == "" { + t.Fatal("remote replica process requires listen, ready, stop, and result paths") + } + finalSet := phase174RequiredPositiveInt(t, phase174ReplicaFinalSetEnv) + finalRun := phase174RequiredPositiveInt(t, phase174ReplicaFinalRunEnv) + + if err := os.MkdirAll(filepath.Dir(storePath), 0o755); err != nil { + t.Fatal(err) + } + store, err := storage.CreateWALStore(storePath, phase174NumBlocks, phase174BlockSize) + if err != nil { + t.Fatal(err) + } + storeOpen := true + defer func() { + if storeOpen { + _ = store.Close() + } + }() + + listener, err := transport.NewReplicaListener(listenAddress, store) + if err != nil { + t.Fatal(err) + } + listenerRunning := true + defer func() { + if listenerRunning { + listener.Stop() + } + }() + listener.Serve() + if err := os.WriteFile(readyFile, []byte(listener.Addr()+"\n"), 0o644); err != nil { + t.Fatal(err) + } + + deadline := time.Now().Add(15 * time.Minute) + for { + if _, err := os.Stat(stopFile); err == nil { + break + } else if !os.IsNotExist(err) { + t.Fatal(err) + } + if time.Now().After(deadline) { + t.Fatal("timed out waiting for remote replica stop file") + } + time.Sleep(100 * time.Millisecond) + } + + listener.Stop() + listenerRunning = false + if _, err := store.Sync(); err != nil { + t.Fatal(err) + } + if err := store.Close(); err != nil { + t.Fatal(err) + } + storeOpen = false + + reopened, err := storage.OpenWALStore(storePath) + if err != nil { + t.Fatal(err) + } + defer reopened.Close() + if _, err := reopened.Recover(); err != nil { + t.Fatal(err) + } + stable, _, head := reopened.Boundaries() + expectedHead := uint64((phase174Runs + 1) * (phase174WarmupOperations + phase174APIOperations)) + if stable != head || head != expectedHead { + t.Fatalf("remote replica frontier stable=%d head=%d want=%d", stable, head, expectedHead) + } + + payloads := phase174Payloads(phase174APIOperations, finalSet, finalRun, 0x1741) + samples := 0 + for _, operation := range phase174SampleOperations(len(payloads)) { + got, err := reopened.Read(phase174OperationLBA(operation, 0)) + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(got, payloads[operation]) { + t.Fatalf("operation=%d data mismatch", operation) + } + samples++ + } + result := phase174RemoteReplicaResult{ + Status: "ok", ListenAddress: listener.Addr(), StableLSN: stable, + HeadLSN: head, ExpectedHeadLSN: expectedHead, CorrectnessSamples: samples, + } + encoded, err := json.Marshal(result) + if err != nil { + t.Fatal(err) + } + if err := os.WriteFile(resultFile, append(encoded, '\n'), 0o644); err != nil { + t.Fatal(err) + } + fmt.Printf("phase174_remote_replica_result=%s\n", encoded) +} + +func phase174RequiredPositiveInt(t *testing.T, name string) int { + t.Helper() + value, err := strconv.Atoi(os.Getenv(name)) + if err != nil || value <= 0 { + t.Fatalf("%s must be a positive integer", name) + } + return value +} diff --git a/seaweed-block/internal/docs/qa-assignments/phase174-d2-distinct-node-rf3-qa.md b/seaweed-block/internal/docs/qa-assignments/phase174-d2-distinct-node-rf3-qa.md new file mode 100644 index 0000000000..da62500537 --- /dev/null +++ b/seaweed-block/internal/docs/qa-assignments/phase174-d2-distinct-node-rf3-qa.md @@ -0,0 +1,41 @@ +# Phase 174 D2 Distinct-Node RF3 QA + +Run this gate from Windows Git Bash. It cross-compiles one test-only binary, +uses m02 as primary, and runs persistent replica listeners on m01 and tp01. +Each replica writes to its own host's NVMe filesystem. The transport is the +shared `192.168.1.x` management LAN because tp01 has no RoCE interface; this is +not a 100 GbE performance claim. + +```bash +cd /c/work/seaweed_block +SW_BLOCK_PHASE174_SSH_KEY=/c/work/dev_server/testdev_key \ + bash scripts/run-phase174-distinct-node-rf3-gate.sh "$PWD" +``` + +## Contract + +- 16,384 deterministic 4 KiB writes and 64 MiB per measured run; +- 1, 4, and 8 writers, five runs each, after a persistent precondition run; +- foreground ACK remains `sync_quorum_rf3`; +- after the measured Sync, an explicitly excluded SyncAll drain makes both + external replicas inspectable without weakening or relabeling foreground + semantics; +- each remote process stops, reopens WALStore, recovers the exact expected + frontier, and verifies final payload bytes independently; +- the primary also closes, reopens, recovers, and verifies bytes every run. + +## Required Evidence + +- `phase174_distinct_node_rf3_status=ok`; +- 15 primary result rows and six independently recovered remote results; +- `foreground_sync_quorum_preserved=true`; +- `post_measurement_sync_all_verified=true`; +- `remote_replica_frontiers_and_bytes_equal=true`; +- `rf3_distinct_node_healthy=true`; +- peer queue saturation is reported, not hidden; +- no cross-ACK-profile throughput ratio, candidate selection, or product + mutation; +- remote process/store cleanup leaves no gate residue. + +This is D2 attribution/correctness evidence. It does not override the D1 local +HOLD and cannot authorize D4/D5 implementation. diff --git a/seaweed-block/scripts/run-phase174-distinct-node-rf3-gate.sh b/seaweed-block/scripts/run-phase174-distinct-node-rf3-gate.sh new file mode 100644 index 0000000000..347f48c1b9 --- /dev/null +++ b/seaweed-block/scripts/run-phase174-distinct-node-rf3-gate.sh @@ -0,0 +1,223 @@ +#!/usr/bin/env bash +set -euo pipefail + +ROOT="${1:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}" +M01_HOST="${SW_BLOCK_PHASE174_M01_HOST:-testdev@192.168.1.181}" +M02_HOST="${SW_BLOCK_PHASE174_M02_HOST:-testdev@192.168.1.184}" +TP01_HOST="${SW_BLOCK_PHASE174_TP01_HOST:-testdev@192.168.1.188}" +M01_DATA_IP="${SW_BLOCK_PHASE174_M01_DATA_IP:-192.168.1.181}" +TP01_DATA_IP="${SW_BLOCK_PHASE174_TP01_DATA_IP:-192.168.1.188}" +SSH_KEY="${SW_BLOCK_PHASE174_SSH_KEY:-/c/work/dev_server/testdev_key}" +PUBLISH_ROOT="${SW_BLOCK_PHASE174_PUBLISH_ROOT:-/mnt/smb/work/share/g15d-k8s}" +RUN_ID="${SW_BLOCK_PHASE174_RUN_ID:-$(date -u +%Y%m%dT%H%M%SZ)-phase174-d2-rf3-distinct}" +ARTIFACT_DIR="${SW_BLOCK_ARTIFACT_DIR:-/tmp/${RUN_ID}}" +LOCAL_BINARY="/tmp/${RUN_ID}-replication.test" +REMOTE_ROOT="/tmp/${RUN_ID}" +REMOTE_BINARY="${REMOTE_ROOT}/replication.test" +M02_STORE_ROOT="/data/nvme/block/${RUN_ID}-stores" +RESULTS="${ARTIFACT_DIR}/phase174-distinct-node-rf3-results.jsonl" +SUMMARY="${ARTIFACT_DIR}/phase174-distinct-node-rf3-summary.txt" +M01_ADDR="${M01_DATA_IP}:17411" +TP01_ADDR="${TP01_DATA_IP}:17412" +RUNS=5 +WRITERS=(1 4 8) + +SSH=(ssh -T -i "${SSH_KEY}" -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o BatchMode=yes) +SCP=(scp -q -i "${SSH_KEY}" -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o BatchMode=yes) + +remote() { + local host="$1" + shift + "${SSH[@]}" "${host}" "$@" +} + +write_summary() { + echo "$*" | tee -a "${SUMMARY}" >/dev/null +} + +cleanup() { + rm -f "${LOCAL_BINARY}" + for host in "${M01_HOST}" "${TP01_HOST}"; do + remote "${host}" "test '${REMOTE_ROOT}' = '/tmp/${RUN_ID}'; rm -rf -- '${REMOTE_ROOT}'" >/dev/null 2>&1 || true + done + remote "${M02_HOST}" "test '${REMOTE_ROOT}' = '/tmp/${RUN_ID}'; test '${M02_STORE_ROOT}' = '/data/nvme/block/${RUN_ID}-stores'; rm -rf -- '${REMOTE_ROOT}' '${M02_STORE_ROOT}'" >/dev/null 2>&1 || true +} +trap cleanup EXIT + +wait_remote_file() { + local host="$1" path="$2" label="$3" + for _ in $(seq 1 150); do + if remote "${host}" "test -s '${path}'"; then + return 0 + fi + sleep 0.2 + done + echo "timed out waiting for ${label}: ${host}:${path}" >&2 + return 1 +} + +start_replica() { + local host="$1" address="$2" writers="$3" node="$4" + local dir="${REMOTE_ROOT}/w${writers}-${node}" + remote "${host}" "set -e; mkdir -p '${dir}'; setsid nohup env \ +SW_BLOCK_PHASE174_REPLICA_STORE='${dir}/replica.store' \ +SW_BLOCK_PHASE174_REPLICA_LISTEN='${address}' \ +SW_BLOCK_PHASE174_REPLICA_READY_FILE='${dir}/ready' \ +SW_BLOCK_PHASE174_REPLICA_STOP_FILE='${dir}/stop' \ +SW_BLOCK_PHASE174_REPLICA_RESULT_FILE='${dir}/result.json' \ +SW_BLOCK_PHASE174_REPLICA_FINAL_SET=1 \ +SW_BLOCK_PHASE174_REPLICA_FINAL_RUN=${RUNS} \ +'${REMOTE_BINARY}' -test.run '^TestPhase174RemoteReplicaProcess$' -test.v -test.timeout=20m \ +>'${dir}/replica.log' 2>&1 '${dir}/pid'" + wait_remote_file "${host}" "${dir}/ready" "${node} replica readiness" +} + +stop_replica() { + local host="$1" writers="$2" node="$3" + local dir="${REMOTE_ROOT}/w${writers}-${node}" + remote "${host}" "touch '${dir}/stop'" + wait_remote_file "${host}" "${dir}/result.json" "${node} replica result" + "${SCP[@]}" "${host}:${dir}/result.json" "${ARTIFACT_DIR}/remote/w${writers}-${node}-result.json" + "${SCP[@]}" "${host}:${dir}/replica.log" "${ARTIFACT_DIR}/remote/w${writers}-${node}.log" +} + +mkdir -p "${ARTIFACT_DIR}/environment" "${ARTIFACT_DIR}/logs" "${ARTIFACT_DIR}/remote" +: >"${SUMMARY}" +: >"${RESULTS}" + +for command in go ssh scp python3 tar; do + command -v "${command}" >/dev/null 2>&1 || { + echo "missing required command: ${command}" >&2 + exit 2 + } +done + +write_summary "phase174_distinct_node_rf3_status=running" +write_summary "contract=phase174-distinct-node-rf3-v1" +write_summary "source_commit=$(git -C "${ROOT}" rev-parse HEAD)" +write_summary "foreground_ack_profile=sync_quorum_rf3" +write_summary "post_measurement_drain=sync_all" +write_summary "transport=tcp" +write_summary "network_class=management_lan" +write_summary "primary_node=m02" +write_summary "replica_nodes=m01,tp01" +write_summary "primary_management_ip=192.168.1.184" +write_summary "replica_addresses=${M01_ADDR},${TP01_ADDR}" +write_summary "tp01_roce_capable=false" +write_summary "cross_ack_profile_throughput_ratio_allowed=false" + +for spec in "m01:${M01_HOST}" "m02:${M02_HOST}" "tp01:${TP01_HOST}"; do + name="${spec%%:*}" + host="${spec#*:}" + remote "${host}" 'hostname; uname -a; uptime; lsblk -o NAME,TYPE,SIZE,ROTA,MODEL,FSTYPE,MOUNTPOINTS; ip -brief address' \ + >"${ARTIFACT_DIR}/environment/${name}.txt" +done +remote "${M02_HOST}" "test \"\$(findmnt -n -T /data/nvme/block -o SOURCE)\" = /dev/nvme0n1p1" +remote "${M01_HOST}" "findmnt -n -T /tmp -o SOURCE,FSTYPE" >"${ARTIFACT_DIR}/environment/m01-store.txt" +remote "${TP01_HOST}" "findmnt -n -T /tmp -o SOURCE,FSTYPE" >"${ARTIFACT_DIR}/environment/tp01-store.txt" +remote "${M01_HOST}" "! ss -ltnH | grep -q ':17411 '" +remote "${TP01_HOST}" "! ss -ltnH | grep -q ':17412 '" + +cd "${ROOT}" +CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go test -tags swblock_testtools -c \ + -o "${LOCAL_BINARY}" ./core/replication +for host in "${M01_HOST}" "${M02_HOST}" "${TP01_HOST}"; do + remote "${host}" "test '${REMOTE_ROOT}' = '/tmp/${RUN_ID}'; rm -rf -- '${REMOTE_ROOT}'; mkdir -p '${REMOTE_ROOT}'" + "${SCP[@]}" "${LOCAL_BINARY}" "${host}:${REMOTE_BINARY}" + remote "${host}" "chmod 0755 '${REMOTE_BINARY}'" +done +remote "${M02_HOST}" "test '${M02_STORE_ROOT}' = '/data/nvme/block/${RUN_ID}-stores'; rm -rf -- '${M02_STORE_ROOT}'; mkdir -p '${M02_STORE_ROOT}'" + +for writers in "${WRITERS[@]}"; do + start_replica "${M01_HOST}" "${M01_ADDR}" "${writers}" m01 + start_replica "${TP01_HOST}" "${TP01_ADDR}" "${writers}" tp01 + + for run in $(seq 0 "${RUNS}"); do + log="${ARTIFACT_DIR}/logs/w${writers}-run${run}.log" + remote "${M02_HOST}" "env \ +SW_BLOCK_PHASE174_STORE_DIR='${M02_STORE_ROOT}/w${writers}' \ +SW_BLOCK_PHASE174_LAYER=rf3_tcp \ +SW_BLOCK_PHASE174_WRITERS=${writers} \ +SW_BLOCK_PHASE174_SET=1 \ +SW_BLOCK_PHASE174_RUN=${run} \ +SW_BLOCK_PHASE174_REMOTE_REPLICAS='${M01_ADDR},${TP01_ADDR}' \ +GOMAXPROCS=4 taskset -c 0,2,4,6 \ +'${REMOTE_BINARY}' -test.run '^TestPhase174FixedWorkPipeline$' -test.v -test.count=1 -test.timeout=10m" \ + >"${log}" 2>&1 + if [[ "${run}" != "0" ]]; then + sed -n 's/^phase174_fixed_work_result=//p' "${log}" >>"${RESULTS}" + fi + done + + stop_replica "${M01_HOST}" "${writers}" m01 + stop_replica "${TP01_HOST}" "${writers}" tp01 +done + +python3 - "${RESULTS}" "${ARTIFACT_DIR}/remote" "${SUMMARY}" "${RUNS}" <<'PY' +import glob +import json +import statistics +import sys + +results_path, remote_dir, summary_path, runs_text = sys.argv[1:] +runs = int(runs_text) +rows = [json.loads(line) for line in open(results_path, encoding="utf-8") if line.strip()] +if len(rows) != 3 * runs: + raise SystemExit(f"primary rows={len(rows)} want {3 * runs}") + +queue_saturation_rows = 0 +for row in rows: + if row["contract"] != "phase174-fixed-work-v1" or row["ack_profile"] != "sync_quorum_rf3": + raise SystemExit(f"bad primary contract: {row}") + if row["replica_count"] != 2 or not row["remote_replica_evidence_required"]: + raise SystemExit(f"bad external replica contract: {row}") + if not row["post_measurement_sync_all"] or row["post_measurement_sync_all_ns"] <= 0: + raise SystemExit(f"missing post-measurement drain: {row}") + if row["api_operations"] != 16384 or row["logical_bytes"] != 67108864: + raise SystemExit(f"bad fixed work: {row}") + if row["primary_wal_write_ops"] != 16384 or row["replication_write_ops"] != 16384: + raise SystemExit(f"write counter mismatch: {row}") + if not row["close_recover_complete"] or row["primary_stable_lsn"] != row["primary_head_lsn"]: + raise SystemExit(f"primary recovery mismatch: {row}") + if row.get("peer_queue_saturated", 0) > 0: + queue_saturation_rows += 1 + +remote_paths = sorted(glob.glob(f"{remote_dir}/w*-*-result.json")) +if len(remote_paths) != 6: + raise SystemExit(f"remote results={len(remote_paths)} want 6") +for path in remote_paths: + row = json.load(open(path, encoding="utf-8")) + if row["status"] != "ok" or row["stable_lsn"] != row["head_lsn"]: + raise SystemExit(f"bad remote recovery {path}: {row}") + if row["head_lsn"] != row["expected_head_lsn"] or row["correctness_samples"] < 5: + raise SystemExit(f"bad remote frontier/data {path}: {row}") + +with open(summary_path, "a", encoding="utf-8") as out: + for writers in (1, 4, 8): + rates = [row["mib_per_second"] for row in rows if int(row["writers"]) == writers] + out.write(f"writers_{writers}_median_mibps={statistics.median(rates):.3f}\n") + out.write(f"writers_{writers}_max_min_ratio={max(rates) / min(rates):.3f}\n") + out.write(f"primary_result_count={len(rows)}\n") + out.write(f"remote_recovered_replica_count={len(remote_paths)}\n") + out.write(f"peer_queue_saturation_row_count={queue_saturation_rows}\n") + out.write("remote_replica_frontiers_and_bytes_equal=true\n") + out.write("foreground_sync_quorum_preserved=true\n") + out.write("post_measurement_sync_all_verified=true\n") + out.write("rf3_distinct_node_healthy=true\n") + out.write("architecture_candidate_selected=false\n") + out.write("product_mutation_present=false\n") + out.write("phase174_distinct_node_rf3_status=ok\n") +PY + +cleanup +trap - EXIT +for host in "${M01_HOST}" "${M02_HOST}" "${TP01_HOST}"; do + remote "${host}" "test ! -e '${REMOTE_ROOT}'" +done +remote "${M02_HOST}" "test ! -e '${M02_STORE_ROOT}'" +write_summary "remote_process_and_store_residue_count=0" +write_summary "published_artifact=${PUBLISH_ROOT}/${RUN_ID}.tar.gz" +tar -C "$(dirname "${ARTIFACT_DIR}")" -czf "${ARTIFACT_DIR}.tar.gz" "$(basename "${ARTIFACT_DIR}")" +"${SCP[@]}" "${ARTIFACT_DIR}.tar.gz" "${M02_HOST}:${PUBLISH_ROOT}/${RUN_ID}.tar.gz" +sha256sum "${ARTIFACT_DIR}.tar.gz" | tee "${ARTIFACT_DIR}.tar.gz.sha256" +cat "${SUMMARY}"