mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
G5-5 implementation: instrumentation + verifier + m01 orchestration
Per architect-ratified mini-plan v0.3 §1 file map. Three additions
(no engine/adapter behavior changes per architect §6 binding):
1. /status/recovery endpoint (opt-in, loopback-only, default off)
- core/host/volume/status_server.go: handler + EnableRecoveryEndpoint()
- core/host/volume/projection_bridge.go: AdapterProjectionView.EngineProjection()
accessor returns the underlying engine.ReplicaProjection (Mode/R/S/H/
RecoveryDecision/Reason). Surfaces existing engine state via HTTP;
no engine code change.
- cmd/blockvolume/main.go: --status-recovery CLI flag (default off);
calls status.EnableRecoveryEndpoint() when set
- core/host/volume/status_server_test.go: 3 new tests
(Disabled→404, Enabled→200+fields, WrongVolume→404)
2. core/storage.OpenReadOnly + WALStoreReader
- Read-only walstore opener for hardware byte-equal verification.
Opens O_RDONLY, runs Recover() to populate dirty map, exposes
Read(lba) only (no Write/Sync surface). Caller must ensure no
concurrent writer.
- core/storage/walstore_readonly.go + walstore_readonly_test.go
(round-trip write→close→OpenReadOnly→Read passes; missing-file
fence)
3. cmd/m01verify standalone helper (build-tag m01verify)
- Separate cmd subpackage so it doesn't collide with blockvolume's
main(). Builds only with `go build -tags m01verify`.
- Opens replica's walstore via storage.OpenReadOnly, calls Read(lba)
per LBA in target range, SHA-256 vs --expected-pattern (single hex
byte) or --expected-file (binary payload). Prints OK / MISMATCH +
exit 0/1.
- Architect REVISE round 51: NO raw .extent peek; storage abstraction
is the only authoritative read path.
4. scripts/iterate-m01-replicated-write.sh — full G5-5 orchestration
- Replaces v0.1 skeleton's TODO scenario bodies with real verify
steps matching mini-plan v0.3 §2 acceptance criteria #1-#6.
- 6 verify functions: cluster_ready, byte_equal (kernel iSCSI write
+ m01verify storage-aware compare), network_catchup (iptables
drop + /status/recovery R/H polling), restart_catchup (SIGTERM
replica + restart same --durable-root + R/H polling), race_stress
(TestG54_BinaryWiring x10 -race on m01), full_suite (go test ./...).
- Build phase compiles all 3 binaries on m01 (master + volume + verify)
and scp blockvolume + m01verify to M02. SMB share path used in
prior smoke is replaced by direct scp for simpler dependency.
Acceptance gates per mini-plan v0.3 §2:
#1-#6 covered by script verify steps; m01 hardware run is QA's
responsibility per `v3-batch-process.md §14` (sw drafts, QA verifies).
#7 (v3-dev-roadmap.md update at gate-close) deferred to §close.
Full V3 regression: 23/23 packages green from local Windows run
(includes G5-4 binary integration test still passing at 16.4s; new
status_server tests pass; new walstore_readonly tests pass; m01verify
builds clean under -tags m01verify).
Hard binding preserved: zero engine/adapter behavior changes. The
/status/recovery endpoint surfaces an already-computed projection;
walstore.OpenReadOnly is a new read-only wrapper around existing Recover
+ Read; no semantic changes to either.
Refs: sw-block/design/v3-phase-15-g5-5-mini-plan.md v0.3
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
be9823b872
commit
702c661f87
8 files changed
+773
-189
No files matched your search
@@ -46,6 +46,11 @@ type flags struct {
|
||||
// addr on the ready line so the test harness can discover it.
|
||||
enableT1Readiness bool
|
||||
statusAddr string
|
||||
// statusRecovery — G5-5 opt-in: enable /status/recovery?volume=v1
|
||||
// endpoint exposing engine.ReplicaProjection (Mode/R/S/H/Decision).
|
||||
// Default off; production binaries do NOT enable. Used by the m01
|
||||
// orchestration script for catch-up verification (R/H polling).
|
||||
statusRecovery bool
|
||||
|
||||
// T2 iSCSI frontend flags. iscsiListen is the TCP address
|
||||
// the iSCSI target binds on; empty disables the frontend.
|
||||
@@ -88,6 +93,7 @@ func parseFlags(args []string) (flags, error) {
|
||||
fs.BoolVar(&f.printReadyLine, "t0-print-ready", false, "internal test-only: emit one structured JSON line on stdout on first assignment")
|
||||
fs.BoolVar(&f.enableT1Readiness, "t1-readiness", false, "enable T1 readiness bridge (HealthyPathExecutor) so adapter projection reaches Healthy")
|
||||
fs.StringVar(&f.statusAddr, "status-addr", "", "address for the status HTTP endpoint (e.g. 127.0.0.1:0); empty disables")
|
||||
fs.BoolVar(&f.statusRecovery, "status-recovery", false, "G5-5 opt-in: expose /status/recovery?volume=<id> with engine.ReplicaProjection (Mode/R/S/H/RecoveryDecision); off by default; loopback-only; intended for hardware test orchestration")
|
||||
fs.StringVar(&f.iscsiListen, "iscsi-listen", "", "iSCSI target bind address (e.g. 127.0.0.1:0); empty disables. Loopback-only in T2 scope (no auth)")
|
||||
fs.StringVar(&f.iscsiIQN, "iscsi-iqn", "", "iSCSI target IQN (required if --iscsi-listen is set)")
|
||||
fs.UintVar(&f.iscsiLUN, "iscsi-lun", 0, "iSCSI LUN id (default 0)")
|
||||
@@ -236,6 +242,9 @@ func run(f flags) int {
|
||||
var status *volume.StatusServer
|
||||
if f.statusAddr != "" {
|
||||
status = volume.NewStatusServer(h.ProjectionView())
|
||||
if f.statusRecovery {
|
||||
status.EnableRecoveryEndpoint()
|
||||
}
|
||||
bound, err := status.Start(f.statusAddr)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "blockvolume: status server:", err)
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
//go:build m01verify
|
||||
|
||||
// G5-5 hardware-test byte-equal verifier — built only under
|
||||
// `m01verify` build tag; never compiled into the production
|
||||
// blockvolume binary.
|
||||
//
|
||||
// Build:
|
||||
//
|
||||
// go build -tags m01verify -o m01verify ./cmd/blockvolume/
|
||||
//
|
||||
// Usage (inside iterate-m01-replicated-write.sh):
|
||||
//
|
||||
// m01verify --walstore /tmp/g5sm/replica-store/v1.walstore \
|
||||
// --lba-start 0 --lba-count 256 --block-size 4096 \
|
||||
// --expected-pattern <hex-byte> | --expected-file payload.bin
|
||||
//
|
||||
// Per architect REVISE binding round 51: opens the replica's
|
||||
// walstore through `core/storage.OpenReadOnly` (NOT raw extent
|
||||
// peek), invokes Read(lba) over the target LBA range, SHA-256-
|
||||
// compares against the known primary write payload. Prints OK on
|
||||
// equality, MISMATCH lba=N exp=... got=... + exit 1 on diff.
|
||||
//
|
||||
// Caller (script) MUST ensure the daemon owning the walstore is
|
||||
// stopped or quiesced before invocation; OpenReadOnly opens the
|
||||
// file O_RDONLY but the underlying WAL replay assumes no
|
||||
// concurrent writer.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/storage"
|
||||
)
|
||||
|
||||
type verifyFlags struct {
|
||||
walstorePath string
|
||||
lbaStart uint
|
||||
lbaCount uint
|
||||
blockSize uint
|
||||
expectedPattern string // single hex byte (e.g. "ab")
|
||||
expectedFile string // path to a binary file with the expected per-LBA bytes
|
||||
}
|
||||
|
||||
func parseVerifyFlags() (verifyFlags, error) {
|
||||
var f verifyFlags
|
||||
fs := flag.NewFlagSet("m01verify", flag.ContinueOnError)
|
||||
fs.StringVar(&f.walstorePath, "walstore", "", "path to replica's walstore file (required)")
|
||||
fs.UintVar(&f.lbaStart, "lba-start", 0, "first LBA to verify")
|
||||
fs.UintVar(&f.lbaCount, "lba-count", 1, "number of consecutive LBAs to verify")
|
||||
fs.UintVar(&f.blockSize, "block-size", 4096, "block size in bytes")
|
||||
fs.StringVar(&f.expectedPattern, "expected-pattern", "", "expected per-byte pattern as a single hex byte (e.g. 'ab'); each LBA filled with this byte")
|
||||
fs.StringVar(&f.expectedFile, "expected-file", "", "expected payload file (lba_count * block_size bytes); read concatenated per-LBA")
|
||||
if err := fs.Parse(os.Args[1:]); err != nil {
|
||||
return f, err
|
||||
}
|
||||
if f.walstorePath == "" {
|
||||
return f, fmt.Errorf("--walstore required")
|
||||
}
|
||||
if f.lbaCount == 0 {
|
||||
return f, fmt.Errorf("--lba-count must be > 0")
|
||||
}
|
||||
if f.expectedPattern == "" && f.expectedFile == "" {
|
||||
return f, fmt.Errorf("one of --expected-pattern or --expected-file required")
|
||||
}
|
||||
if f.expectedPattern != "" && f.expectedFile != "" {
|
||||
return f, fmt.Errorf("--expected-pattern and --expected-file are mutually exclusive")
|
||||
}
|
||||
return f, nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
f, err := parseVerifyFlags()
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "m01verify:", err)
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
expected, err := buildExpected(f)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "m01verify: build expected:", err)
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
r, err := storage.OpenReadOnly(f.walstorePath)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "m01verify: OpenReadOnly:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer func() { _ = r.Close() }()
|
||||
|
||||
mismatches := 0
|
||||
for i := uint(0); i < f.lbaCount; i++ {
|
||||
lba := uint32(f.lbaStart + i)
|
||||
got, rerr := r.Read(lba)
|
||||
if rerr != nil {
|
||||
fmt.Fprintf(os.Stderr, "m01verify: Read lba=%d: %v\n", lba, rerr)
|
||||
os.Exit(1)
|
||||
}
|
||||
want := expected[i]
|
||||
if !bytesEqual(got, want) {
|
||||
gotSum := sha256.Sum256(got)
|
||||
wantSum := sha256.Sum256(want)
|
||||
fmt.Printf("MISMATCH lba=%d exp_sha256=%s got_sha256=%s\n",
|
||||
lba, hex.EncodeToString(wantSum[:8]), hex.EncodeToString(gotSum[:8]))
|
||||
mismatches++
|
||||
}
|
||||
}
|
||||
if mismatches > 0 {
|
||||
fmt.Printf("FAIL %d mismatch(es) over %d LBA(s)\n", mismatches, f.lbaCount)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Printf("OK %d LBA(s) byte-equal\n", f.lbaCount)
|
||||
}
|
||||
|
||||
// buildExpected returns the expected bytes for each verified LBA.
|
||||
// Either every LBA is filled with --expected-pattern, or the bytes
|
||||
// come from --expected-file split into block-size chunks.
|
||||
func buildExpected(f verifyFlags) ([][]byte, error) {
|
||||
out := make([][]byte, f.lbaCount)
|
||||
if f.expectedPattern != "" {
|
||||
raw, err := hex.DecodeString(f.expectedPattern)
|
||||
if err != nil || len(raw) != 1 {
|
||||
return nil, fmt.Errorf("--expected-pattern must be a single hex byte (e.g. 'ab'); got %q", f.expectedPattern)
|
||||
}
|
||||
b := raw[0]
|
||||
for i := range out {
|
||||
block := make([]byte, f.blockSize)
|
||||
for j := range block {
|
||||
block[j] = b
|
||||
}
|
||||
out[i] = block
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
data, err := os.ReadFile(f.expectedFile)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("read expected file: %w", err)
|
||||
}
|
||||
want := int(f.lbaCount * f.blockSize)
|
||||
if len(data) < want {
|
||||
return nil, fmt.Errorf("expected file too short: got %d bytes, want >= %d", len(data), want)
|
||||
}
|
||||
for i := uint(0); i < f.lbaCount; i++ {
|
||||
out[i] = data[i*f.blockSize : (i+1)*f.blockSize]
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func bytesEqual(a, b []byte) bool {
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
}
|
||||
for i := range a {
|
||||
if a[i] != b[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -90,3 +90,16 @@ func (v *AdapterProjectionView) Projection() frontend.Projection {
|
||||
Healthy: healthy,
|
||||
}
|
||||
}
|
||||
|
||||
// EngineProjection returns the underlying engine.ReplicaProjection
|
||||
// (Mode, R/S/H, RecoveryDecision, SessionKind/Phase, Reason). Used
|
||||
// by the G5-5 opt-in `/status/recovery` endpoint to surface recovery
|
||||
// boundaries for hardware-test catch-up verification. NOT consumed
|
||||
// by the frontend (which uses Projection() above for Healthy gating).
|
||||
//
|
||||
// This accessor reads engine state without modifying it; supersede
|
||||
// is NOT applied here (callers needing the same fail-closed semantic
|
||||
// the frontend gets should also call Projection()).
|
||||
func (v *AdapterProjectionView) EngineProjection() engine.ReplicaProjection {
|
||||
return v.projector.Projection()
|
||||
}
|
||||
@@ -41,10 +41,11 @@ import (
|
||||
type StatusServer struct {
|
||||
view *AdapterProjectionView
|
||||
|
||||
mu sync.Mutex
|
||||
ln net.Listener
|
||||
srv *http.Server
|
||||
addr string
|
||||
mu sync.Mutex
|
||||
ln net.Listener
|
||||
srv *http.Server
|
||||
addr string
|
||||
recoveryEnabled bool // G5-5: gates /status/recovery; off by default
|
||||
}
|
||||
|
||||
// NewStatusServer wires a server to one volume host's view.
|
||||
@@ -52,6 +53,26 @@ func NewStatusServer(view *AdapterProjectionView) *StatusServer {
|
||||
return &StatusServer{view: view}
|
||||
}
|
||||
|
||||
// EnableRecoveryEndpoint opts in the test/operator-only
|
||||
// `/status/recovery?volume=v1` endpoint, which surfaces the
|
||||
// engine.ReplicaProjection (Mode, R/S/H, RecoveryDecision,
|
||||
// SessionKind/Phase, Reason) over HTTP. The endpoint is
|
||||
// loopback-only (same guard as `/status`).
|
||||
//
|
||||
// G5-5 uses this for hardware-test catch-up verification: the
|
||||
// orchestration script polls primary's H and replica's R to assert
|
||||
// catch-up convergence. Production binaries do NOT enable it
|
||||
// (default off; opt-in via --status-recovery flag). The endpoint
|
||||
// surfaces existing engine projection — no engine/adapter
|
||||
// behavior change.
|
||||
//
|
||||
// Must be called BEFORE Start.
|
||||
func (s *StatusServer) EnableRecoveryEndpoint() {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.recoveryEnabled = true
|
||||
}
|
||||
|
||||
// Start binds on addr and spawns the HTTP serve goroutine.
|
||||
// addr MUST be a loopback host (empty-host is rejected; any
|
||||
// non-loopback IP returns an error). Returns the bound addr
|
||||
@@ -75,6 +96,9 @@ func (s *StatusServer) Start(addr string) (string, error) {
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/status", s.handleStatus)
|
||||
if s.recoveryEnabled {
|
||||
mux.HandleFunc("/status/recovery", s.handleStatusRecovery)
|
||||
}
|
||||
s.srv = &http.Server{Handler: mux, ReadHeaderTimeout: 5 * time.Second}
|
||||
|
||||
go func() { _ = s.srv.Serve(ln) }()
|
||||
@@ -120,6 +144,42 @@ func (s *StatusServer) handleStatus(w http.ResponseWriter, r *http.Request) {
|
||||
_ = json.NewEncoder(w).Encode(p)
|
||||
}
|
||||
|
||||
// handleStatusRecovery returns engine.ReplicaProjection for the
|
||||
// targeted volume. Loopback-only; same guards as /status. Surfaced
|
||||
// fields cover the recovery boundaries (R/S/H), recovery decision,
|
||||
// session kind/phase, and reason — used by G5-5 hardware-test
|
||||
// catch-up verification (R/H polling).
|
||||
//
|
||||
// This endpoint is OPT-IN (off by default). Production binaries do
|
||||
// not enable it; m01 orchestration script + tests do via
|
||||
// --status-recovery / EnableRecoveryEndpoint.
|
||||
//
|
||||
// The response shape is the engine projection struct — JSON field
|
||||
// names follow Go default capitalization. Schema-stable across
|
||||
// G5-5 close (per `v3-batch-process.md` no engine/adapter behavior
|
||||
// change rule); future field additions are append-only.
|
||||
func (s *StatusServer) handleStatusRecovery(w http.ResponseWriter, r *http.Request) {
|
||||
if !isLoopbackRemote(r.RemoteAddr) {
|
||||
http.Error(w, "status endpoint restricted to loopback", http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
vol := r.URL.Query().Get("volume")
|
||||
if vol == "" {
|
||||
http.Error(w, "missing volume query param", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
// Frontend projection is the cheap volume-id check; if this
|
||||
// host doesn't serve `vol`, fail-fast with 404 (same as /status).
|
||||
fp := s.view.Projection()
|
||||
if fp.VolumeID != vol {
|
||||
http.Error(w, fmt.Sprintf("volume %q not served by this host (serves %q)", vol, fp.VolumeID), http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
ep := s.view.EngineProjection()
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_ = json.NewEncoder(w).Encode(ep)
|
||||
}
|
||||
|
||||
// enforceLoopbackBind refuses to bind on anything other than
|
||||
// 127.0.0.1 / ::1. Empty-host binds (":port") would listen on
|
||||
// ALL interfaces and are rejected. The guard runs before the
|
||||
|
||||
@@ -5,6 +5,7 @@ package volume
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -102,3 +103,91 @@ func TestIsLoopbackRemote(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestStatusServer_RecoveryEndpoint_Disabled_Returns404 — G5-5
|
||||
// regression: /status/recovery is OPT-IN. Default config (no
|
||||
// EnableRecoveryEndpoint call) must NOT route the path.
|
||||
func TestStatusServer_RecoveryEndpoint_Disabled_Returns404(t *testing.T) {
|
||||
s := NewStatusServer(NewAdapterProjectionView(
|
||||
stubProjector{p: engine.ReplicaProjection{Mode: engine.ModeHealthy}},
|
||||
"v1", "r1", nil))
|
||||
addr, err := s.Start("127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatalf("start: %v", err)
|
||||
}
|
||||
defer func() { _ = s.Close(context.Background()) }()
|
||||
resp, err := http.Get("http://" + addr + "/status/recovery?volume=v1")
|
||||
if err != nil {
|
||||
t.Fatalf("get: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != 404 {
|
||||
t.Fatalf("disabled recovery endpoint: got %d want 404 (mux must not route)", resp.StatusCode)
|
||||
}
|
||||
}
|
||||
|
||||
// TestStatusServer_RecoveryEndpoint_Enabled_ReturnsEngineProjection
|
||||
// — pins that EnableRecoveryEndpoint exposes the engine projection
|
||||
// over HTTP with R/S/H + Mode + RecoveryDecision visible (the fields
|
||||
// G5-5 hardware-test catch-up verification reads).
|
||||
func TestStatusServer_RecoveryEndpoint_Enabled_ReturnsEngineProjection(t *testing.T) {
|
||||
p := stubProjector{p: engine.ReplicaProjection{
|
||||
Mode: engine.ModeRecovering,
|
||||
RecoveryDecision: "catch_up",
|
||||
R: 42,
|
||||
S: 10,
|
||||
H: 100,
|
||||
Epoch: 7,
|
||||
EndpointVersion: 3,
|
||||
}}
|
||||
s := NewStatusServer(NewAdapterProjectionView(p, "v1", "r1", nil))
|
||||
s.EnableRecoveryEndpoint()
|
||||
addr, err := s.Start("127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatalf("start: %v", err)
|
||||
}
|
||||
defer func() { _ = s.Close(context.Background()) }()
|
||||
resp, err := http.Get("http://" + addr + "/status/recovery?volume=v1")
|
||||
if err != nil {
|
||||
t.Fatalf("get: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != 200 {
|
||||
t.Fatalf("enabled recovery: got %d want 200", resp.StatusCode)
|
||||
}
|
||||
var body map[string]any
|
||||
if err := json.NewDecoder(resp.Body).Decode(&body); err != nil {
|
||||
t.Fatalf("decode: %v", err)
|
||||
}
|
||||
for _, want := range []string{"R", "S", "H", "Mode", "RecoveryDecision", "Epoch", "EndpointVersion"} {
|
||||
if _, ok := body[want]; !ok {
|
||||
t.Errorf("recovery body missing field %q (need for G5-5 catch-up verifier); body=%v", want, body)
|
||||
}
|
||||
}
|
||||
if got, _ := body["R"].(float64); got != 42 {
|
||||
t.Errorf("R: got %v want 42", body["R"])
|
||||
}
|
||||
if got, _ := body["H"].(float64); got != 100 {
|
||||
t.Errorf("H: got %v want 100", body["H"])
|
||||
}
|
||||
}
|
||||
|
||||
// TestStatusServer_RecoveryEndpoint_WrongVolume_Returns404 — pins
|
||||
// that the wrong-volume guard fires the same way as /status.
|
||||
func TestStatusServer_RecoveryEndpoint_WrongVolume_Returns404(t *testing.T) {
|
||||
s := NewStatusServer(NewAdapterProjectionView(stubProjector{}, "v1", "r1", nil))
|
||||
s.EnableRecoveryEndpoint()
|
||||
addr, err := s.Start("127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatalf("start: %v", err)
|
||||
}
|
||||
defer func() { _ = s.Close(context.Background()) }()
|
||||
resp, err := http.Get("http://" + addr + "/status/recovery?volume=other")
|
||||
if err != nil {
|
||||
t.Fatalf("get: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != 404 {
|
||||
t.Fatalf("wrong volume: got %d want 404", resp.StatusCode)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
// G5-5: read-only walstore opener for hardware-test byte-equal
|
||||
// verification. Provides Read(lba) only — no Write, no Sync, no
|
||||
// Recover, no checkpoint advance. Safe to invoke against a walstore
|
||||
// path while the daemon owning it is stopped (file is opened
|
||||
// O_RDONLY; the daemon must NOT be writing concurrently).
|
||||
//
|
||||
// Used by `cmd/blockvolume/m01_verify_helper.go` (build-tag
|
||||
// `m01verify`) to read the replica's stored bytes for a target LBA
|
||||
// range and compare against the primary's known write payload.
|
||||
//
|
||||
// NOT a substrate semantic change — exposes the same Read(lba)
|
||||
// merge logic the daemon uses (WAL-replay then extent fallback)
|
||||
// through a read-only file handle.
|
||||
|
||||
package storage
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
// WALStoreReader is the read-only handle returned by OpenReadOnly.
|
||||
// Surface is intentionally narrow: Read(lba), Close. No mutating
|
||||
// methods (Write, Sync, Recover, Trim) are exposed; callers that
|
||||
// need them must use OpenWALStore + Recover.
|
||||
type WALStoreReader struct {
|
||||
inner *WALStore
|
||||
}
|
||||
|
||||
// OpenReadOnly opens an existing walstore file for read-only access
|
||||
// and replays the WAL into an in-memory dirty map so subsequent
|
||||
// Read(lba) calls return the most-recent value (per-LBA WAL-then-
|
||||
// extent merge — same semantic as the daemon's Read).
|
||||
//
|
||||
// Caller MUST ensure no writer (i.e., no daemon) is currently open
|
||||
// against the same path; concurrent writes from another process
|
||||
// would race the dirty-map snapshot. Typical use: stop the daemon
|
||||
// (or pause writes) before invoking OpenReadOnly.
|
||||
//
|
||||
// The returned reader holds an open file descriptor; caller MUST
|
||||
// call Close. Forward-carry: if mid-test we discover a need for
|
||||
// shared-read semantics under concurrent writes (advisory locks,
|
||||
// reader-snapshot variant), that is a separate scope expansion
|
||||
// flagged at G5-5 close.
|
||||
func OpenReadOnly(path string) (*WALStoreReader, error) {
|
||||
f, err := os.OpenFile(path, os.O_RDONLY, 0)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("storage: OpenReadOnly %s: %w", path, err)
|
||||
}
|
||||
if _, err := f.Seek(0, 0); err != nil {
|
||||
_ = f.Close()
|
||||
return nil, fmt.Errorf("storage: seek superblock: %w", err)
|
||||
}
|
||||
sb, err := readSuperblock(f)
|
||||
if err != nil {
|
||||
_ = f.Close()
|
||||
return nil, err
|
||||
}
|
||||
if err := sb.validate(); err != nil {
|
||||
_ = f.Close()
|
||||
return nil, err
|
||||
}
|
||||
// Reuse openInitialized so the WAL writer + dirty map are
|
||||
// constructed identically to the R/W path. We never CALL the
|
||||
// writer (no Write surface exposed); the dirty map gets populated
|
||||
// by Recover below.
|
||||
inner, err := openInitialized(path, f, &sb)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Replay WAL into dirty map so Read merges WAL-recent writes
|
||||
// over the extent. Recover scans the WAL — it does NOT issue
|
||||
// writes against the file (the recover path's writes happen
|
||||
// only when promoting WAL entries to the extent at flush time,
|
||||
// which our caller never triggers).
|
||||
if _, err := inner.Recover(); err != nil {
|
||||
_ = inner.Close()
|
||||
return nil, fmt.Errorf("storage: OpenReadOnly recover: %w", err)
|
||||
}
|
||||
return &WALStoreReader{inner: inner}, nil
|
||||
}
|
||||
|
||||
// Read returns the current bytes at lba — same merge logic the
|
||||
// daemon uses (WAL-recent over extent).
|
||||
func (r *WALStoreReader) Read(lba uint32) ([]byte, error) {
|
||||
if r.inner == nil {
|
||||
return nil, errors.New("storage: WALStoreReader.Read after Close")
|
||||
}
|
||||
return r.inner.Read(lba)
|
||||
}
|
||||
|
||||
// Close releases the file descriptor.
|
||||
func (r *WALStoreReader) Close() error {
|
||||
if r.inner == nil {
|
||||
return nil
|
||||
}
|
||||
err := r.inner.Close()
|
||||
r.inner = nil
|
||||
return err
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestOpenReadOnly_RoundTripWriteThenRead — pin G5-5: a value
|
||||
// written through the R/W path is observable via OpenReadOnly+Read.
|
||||
// Closes #2 acceptance criterion's "storage abstraction is the only
|
||||
// authoritative read path" claim by exercising the same merge logic.
|
||||
func TestOpenReadOnly_RoundTripWriteThenRead(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
path := filepath.Join(dir, "vol.walstore")
|
||||
|
||||
// Write phase: open R/W, write LBAs 0/1/2 with distinct payloads.
|
||||
{
|
||||
w, err := CreateWALStore(path, 8 /*blocks*/, 4096 /*bs*/)
|
||||
if err != nil {
|
||||
t.Fatalf("create: %v", err)
|
||||
}
|
||||
for i := 0; i < 3; i++ {
|
||||
data := bytes.Repeat([]byte{byte(0x10 + i)}, 4096)
|
||||
if _, err := w.Write(uint32(i), data); err != nil {
|
||||
t.Fatalf("write lba=%d: %v", i, err)
|
||||
}
|
||||
}
|
||||
if _, err := w.Sync(); err != nil {
|
||||
t.Fatalf("sync: %v", err)
|
||||
}
|
||||
if err := w.Close(); err != nil {
|
||||
t.Fatalf("close R/W: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Read phase: open read-only, verify each LBA's bytes.
|
||||
r, err := OpenReadOnly(path)
|
||||
if err != nil {
|
||||
t.Fatalf("OpenReadOnly: %v", err)
|
||||
}
|
||||
defer func() { _ = r.Close() }()
|
||||
for i := 0; i < 3; i++ {
|
||||
got, err := r.Read(uint32(i))
|
||||
if err != nil {
|
||||
t.Fatalf("read lba=%d: %v", i, err)
|
||||
}
|
||||
want := bytes.Repeat([]byte{byte(0x10 + i)}, 4096)
|
||||
if !bytes.Equal(got, want) {
|
||||
t.Fatalf("lba=%d bytes mismatch: got[0]=%02x want[0]=%02x", i, got[0], want[0])
|
||||
}
|
||||
}
|
||||
|
||||
// Close idempotency.
|
||||
if err := r.Close(); err != nil {
|
||||
t.Fatalf("first close: %v", err)
|
||||
}
|
||||
if err := r.Close(); err != nil {
|
||||
t.Fatalf("idempotent close: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestOpenReadOnly_FailsOnMissingFile — cheap fence.
|
||||
func TestOpenReadOnly_FailsOnMissingFile(t *testing.T) {
|
||||
r, err := OpenReadOnly(filepath.Join(t.TempDir(), "does-not-exist"))
|
||||
if err == nil {
|
||||
_ = r.Close()
|
||||
t.Fatal("OpenReadOnly on missing file: want error")
|
||||
}
|
||||
if _, ok := err.(*os.PathError); ok {
|
||||
// fine — wrapped os error
|
||||
}
|
||||
}
|
||||
@@ -1,272 +1,346 @@
|
||||
#!/usr/bin/env bash
|
||||
# iterate-m01-replicated-write.sh — G5-4 m01 hardware first-light harness
|
||||
# iterate-m01-replicated-write.sh — G5-5 m01 hardware first-light orchestration
|
||||
#
|
||||
# DRAFT v0.1 SKELETON — awaiting G5 kickoff §3 batch ratification.
|
||||
# Scenario bodies marked TODO(G5-arch-ratify) depend on G5 mini-plan.
|
||||
# Per v3-phase-15-g5-5-mini-plan.md v0.3 §2 acceptance criteria:
|
||||
# #1 verify_cluster_ready — blockmaster + 2x blockvolume, role-appropriate ready
|
||||
# #2 verify_byte_equal — kernel iSCSI write → m01verify storage-aware compare
|
||||
# #3 verify_network_catchup — iptables disconnect + /status/recovery R/H polling
|
||||
# #4 verify_restart_catchup — SIGTERM replica + restart same --durable-root
|
||||
# #5 verify_race_stress — TestG54_BinaryWiring x10 -race
|
||||
# #6 verify_full_suite — go test ./... clean
|
||||
#
|
||||
# Runs on local workstation, drives a 2-node cluster:
|
||||
# - m01 (192.168.1.181) — primary blockvolume
|
||||
# - M02 (192.168.1.184) — replica blockvolume
|
||||
# Both nodes share a blockmaster (running on m01).
|
||||
#
|
||||
# Mirrors structure of T2 iterate-m01-nvme.sh; key differences:
|
||||
# - 2-node cross-host wire (vs T2's single-node 3-volume)
|
||||
# - Replicated write path under test (vs T2's NVMe-oF target)
|
||||
# - iptables-based mid-stream disconnect injection
|
||||
# - Byte-exact convergence verification on both replicas
|
||||
#
|
||||
# Ownership: QA. Part of G5 batch G5-4 per
|
||||
# sw-block/design/v3-phase-15-g5-kickoff.md §3 (PROPOSAL — awaiting
|
||||
# architect ratification).
|
||||
# Two-node cluster:
|
||||
# m01 (192.168.1.181) — primary blockvolume + iSCSI target + blockmaster
|
||||
# M02 (192.168.1.184) — replica blockvolume
|
||||
#
|
||||
# Run from local workstation (Windows / Git Bash); SSH drives both nodes.
|
||||
# Exit 0 on all-green; non-zero + diagnostic artifacts on any failure.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# --- Config (env-overridable) ---
|
||||
M01_HOST="${M01_HOST:-testdev@192.168.1.181}" # primary node
|
||||
M02_HOST="${M02_HOST:-testdev@192.168.1.184}" # replica node
|
||||
M01_HOST="${M01_HOST:-testdev@192.168.1.181}"
|
||||
M02_HOST="${M02_HOST:-testdev@192.168.1.184}"
|
||||
SSH_KEY="${SSH_KEY:-/c/work/dev_server/testdev_key}"
|
||||
SRC_DIR="${SRC_DIR:-/c/work/seaweed_block}"
|
||||
REMOTE_BUILD_DIR="${REMOTE_BUILD_DIR:-/tmp/g5_sb_build}"
|
||||
REMOTE_RUN_DIR="${REMOTE_RUN_DIR:-/tmp/g5_sb_run}"
|
||||
DURABLE_IMPL="${DURABLE_IMPL:-walstore}" # walstore | smartwal — per-scenario matrix
|
||||
DURABLE_BLOCKS="${DURABLE_BLOCKS:-262144}" # 1 GiB at 4 KiB blocks
|
||||
DURABLE_IMPL="${DURABLE_IMPL:-walstore}"
|
||||
DURABLE_BLOCKS="${DURABLE_BLOCKS:-256}" # 1 MiB at 4 KiB blocks (small for fast tests)
|
||||
DURABLE_BLOCKSIZE="${DURABLE_BLOCKSIZE:-4096}"
|
||||
WORKLOAD_DURATION_SEC="${WORKLOAD_DURATION_SEC:-30}"
|
||||
ARTIFACT_DIR="${ARTIFACT_DIR:-${SRC_DIR%/*}/seaweedfs/sw-block/design/g5-artifacts}"
|
||||
|
||||
# Network ports (m01 primary)
|
||||
# Network ports (m01 primary side)
|
||||
M01_MASTER_PORT=9180
|
||||
M01_PRIMARY_CTRL_PORT=9210
|
||||
M01_PRIMARY_DATA_PORT=9220
|
||||
M01_PRIMARY_STATUS_PORT=9290
|
||||
M01_ISCSI_PORT=3260
|
||||
|
||||
# Network ports (M02 replica)
|
||||
# Network ports (M02 replica side)
|
||||
M02_REPLICA_CTRL_PORT=9211
|
||||
M02_REPLICA_DATA_PORT=9221
|
||||
M02_REPLICA_STATUS_PORT=9291
|
||||
|
||||
SSH_M01="ssh -i ${SSH_KEY} -o ConnectTimeout=10 ${M01_HOST}"
|
||||
SSH_M02="ssh -i ${SSH_KEY} -o ConnectTimeout=10 ${M02_HOST}"
|
||||
# iSCSI target identity (primary serves a single LUN)
|
||||
ISCSI_IQN="iqn.2026-04.io.seaweed.block:v1"
|
||||
|
||||
# Catch-up deadline (s) for #3 + #4
|
||||
CATCHUP_DEADLINE=30
|
||||
|
||||
SSH_M01="ssh -i ${SSH_KEY} -o ConnectTimeout=10 -o StrictHostKeyChecking=no ${M01_HOST}"
|
||||
SSH_M02="ssh -i ${SSH_KEY} -o ConnectTimeout=10 -o StrictHostKeyChecking=no ${M02_HOST}"
|
||||
|
||||
# --- Helpers ---
|
||||
|
||||
log() { printf '\033[1;36m[g5-replwrite]\033[0m %s\n' "$*" >&2; }
|
||||
die() { printf '\033[1;31m[g5-replwrite FAIL]\033[0m %s\n' "$*" >&2; exit 1; }
|
||||
log() { printf '\033[1;36m[g5-5]\033[0m %s\n' "$*" >&2; }
|
||||
die() { printf '\033[1;31m[g5-5 FAIL]\033[0m %s\n' "$*" >&2; collect_diagnostics fail; exit 1; }
|
||||
|
||||
mkdir -p "${ARTIFACT_DIR}"
|
||||
|
||||
collect_diagnostics() {
|
||||
local label="$1"
|
||||
log "collecting diagnostics [${label}]..."
|
||||
$SSH_M01 "cat ${REMOTE_RUN_DIR}/logs/master.log 2>/dev/null" > "${ARTIFACT_DIR}/master-${label}.log" || true
|
||||
$SSH_M01 "cat ${REMOTE_RUN_DIR}/logs/master.log 2>/dev/null" > "${ARTIFACT_DIR}/master-${label}.log" || true
|
||||
$SSH_M01 "cat ${REMOTE_RUN_DIR}/logs/primary.log 2>/dev/null" > "${ARTIFACT_DIR}/primary-${label}.log" || true
|
||||
$SSH_M02 "cat ${REMOTE_RUN_DIR}/logs/replica.log 2>/dev/null" > "${ARTIFACT_DIR}/replica-${label}.log" || true
|
||||
$SSH_M01 "sudo dmesg -T | tail -50" > "${ARTIFACT_DIR}/m01-dmesg-${label}.txt" 2>/dev/null || true
|
||||
$SSH_M02 "sudo dmesg -T | tail -50" > "${ARTIFACT_DIR}/m02-dmesg-${label}.txt" 2>/dev/null || true
|
||||
log " → ${ARTIFACT_DIR}/{master,primary,replica}-${label}.log + {m01,m02}-dmesg-${label}.txt"
|
||||
}
|
||||
|
||||
# --- Phase 1: sync + rebuild ---
|
||||
# poll_status — fetch /status/recovery from a given node + status port,
|
||||
# extract a JSON field via a tiny python one-liner. Returns the field
|
||||
# value on stdout or empty on failure.
|
||||
poll_status_field() {
|
||||
local ssh_cmd="$1" status_port="$2" field="$3"
|
||||
$ssh_cmd "curl -s --max-time 2 'http://127.0.0.1:${status_port}/status/recovery?volume=v1' | python3 -c 'import json,sys; d=json.load(sys.stdin); print(d.get(\"${field}\",\"\"))' 2>/dev/null" || true
|
||||
}
|
||||
|
||||
# wait_until — polls a check command until it returns 0 or deadline.
|
||||
wait_until() {
|
||||
local desc="$1" deadline_s="$2" check_cmd="$3"
|
||||
local end=$(( $(date +%s) + deadline_s ))
|
||||
while [ "$(date +%s)" -lt "${end}" ]; do
|
||||
if eval "${check_cmd}" >/dev/null 2>&1; then
|
||||
return 0
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
log "wait_until(${desc}) TIMEOUT after ${deadline_s}s"
|
||||
return 1
|
||||
}
|
||||
|
||||
# --- Phase 1: sync + build ---
|
||||
|
||||
sync_and_build() {
|
||||
log "phase 1: sync source + build binaries"
|
||||
|
||||
# Build on m01 (Go installed there); scp binaries to M02 (no Go on M02 per D-finding)
|
||||
log " syncing source to m01..."
|
||||
log "phase 1: sync source + build binaries on m01"
|
||||
cd "${SRC_DIR}"
|
||||
tar --exclude='.git' --exclude='*.exe' --exclude='*.test' -czf /tmp/g5-src.tgz .
|
||||
scp -i "${SSH_KEY}" /tmp/g5-src.tgz "${M01_HOST}:/tmp/" >/dev/null
|
||||
scp -i "${SSH_KEY}" -o StrictHostKeyChecking=no /tmp/g5-src.tgz "${M01_HOST}:/tmp/" >/dev/null
|
||||
$SSH_M01 "rm -rf ${REMOTE_BUILD_DIR} && mkdir -p ${REMOTE_BUILD_DIR} && cd ${REMOTE_BUILD_DIR} && tar xzf /tmp/g5-src.tgz"
|
||||
|
||||
log " building blockmaster + blockvolume on m01..."
|
||||
$SSH_M01 "cd ${REMOTE_BUILD_DIR} && go build -o /tmp/g5-blockmaster ./cmd/blockmaster/ && go build -o /tmp/g5-blockvolume ./cmd/blockvolume/" || die "build failed on m01"
|
||||
$SSH_M01 "
|
||||
cd ${REMOTE_BUILD_DIR} && \
|
||||
go build -o /tmp/g5-blockmaster ./cmd/blockmaster/ && \
|
||||
go build -o /tmp/g5-blockvolume ./cmd/blockvolume/ && \
|
||||
go build -tags m01verify -o /tmp/g5-m01verify ./cmd/m01verify/
|
||||
" || die "build failed on m01"
|
||||
|
||||
log " scp blockvolume binary to M02 (Go not installed there)..."
|
||||
$SSH_M01 "scp -o StrictHostKeyChecking=no /tmp/g5-blockvolume testdev@192.168.1.184:/tmp/" >/dev/null \
|
||||
|| $SSH_M02 "exit" \
|
||||
|| die "scp m01→M02 failed (verify SSH key on m01:~/.ssh/ has access to M02)"
|
||||
log " scp blockvolume + m01verify to M02..."
|
||||
$SSH_M01 "scp -o StrictHostKeyChecking=no /tmp/g5-blockvolume /tmp/g5-m01verify ${M02_HOST}:/tmp/" >/dev/null \
|
||||
|| die "scp m01→M02 failed"
|
||||
}
|
||||
|
||||
# --- Phase 2: start cluster ---
|
||||
# --- Phase 2: cluster lifecycle ---
|
||||
|
||||
start_cluster() {
|
||||
log "phase 2: start blockmaster (m01) + primary (m01) + replica (M02)"
|
||||
write_topology() {
|
||||
$SSH_M01 "cat > ${REMOTE_RUN_DIR}/topology.yaml <<EOF
|
||||
volumes:
|
||||
- volume_id: v1
|
||||
slots:
|
||||
- replica_id: r1
|
||||
server_id: m01-primary
|
||||
- replica_id: r2
|
||||
server_id: m02-replica
|
||||
EOF"
|
||||
}
|
||||
|
||||
# Pre-cleanup
|
||||
$SSH_M01 "sudo pkill -9 -f g5-blockvolume 2>/dev/null || true; sudo pkill -9 -f g5-blockmaster 2>/dev/null || true; rm -rf ${REMOTE_RUN_DIR} && mkdir -p ${REMOTE_RUN_DIR}/{logs,store,durable-primary}" >/dev/null
|
||||
$SSH_M02 "sudo pkill -9 -f g5-blockvolume 2>/dev/null || true; rm -rf ${REMOTE_RUN_DIR} && mkdir -p ${REMOTE_RUN_DIR}/{logs,durable-replica}" >/dev/null
|
||||
|
||||
# blockmaster on m01
|
||||
log " starting blockmaster on m01..."
|
||||
start_master() {
|
||||
log " start blockmaster on m01..."
|
||||
$SSH_M01 "
|
||||
nohup /tmp/g5-blockmaster --authority-store ${REMOTE_RUN_DIR}/store --listen 0.0.0.0:${M01_MASTER_PORT} \
|
||||
--topology ${REMOTE_RUN_DIR}/topology.yaml --t0-print-ready \
|
||||
nohup /tmp/g5-blockmaster \
|
||||
--authority-store ${REMOTE_RUN_DIR}/master-store \
|
||||
--listen 0.0.0.0:${M01_MASTER_PORT} \
|
||||
--topology ${REMOTE_RUN_DIR}/topology.yaml \
|
||||
--expected-slots-per-volume 2 \
|
||||
--t0-print-ready \
|
||||
> ${REMOTE_RUN_DIR}/logs/master.log 2>&1 </dev/null & disown
|
||||
sleep 2
|
||||
pgrep -f g5-blockmaster >/dev/null || (cat ${REMOTE_RUN_DIR}/logs/master.log; exit 1)
|
||||
" || die "blockmaster failed to start"
|
||||
sleep 1"
|
||||
}
|
||||
|
||||
# primary blockvolume on m01
|
||||
log " starting primary blockvolume on m01..."
|
||||
start_primary() {
|
||||
log " start primary blockvolume on m01..."
|
||||
$SSH_M01 "
|
||||
nohup /tmp/g5-blockvolume \
|
||||
--master 127.0.0.1:${M01_MASTER_PORT} \
|
||||
--server-id m01-primary --volume-id v1 --replica-id r1 \
|
||||
--ctrl-addr 0.0.0.0:${M01_PRIMARY_CTRL_PORT} --data-addr 0.0.0.0:${M01_PRIMARY_DATA_PORT} \
|
||||
--durable-root ${REMOTE_RUN_DIR}/durable-primary --durable-impl ${DURABLE_IMPL} \
|
||||
--ctrl-addr 0.0.0.0:${M01_PRIMARY_CTRL_PORT} \
|
||||
--data-addr 0.0.0.0:${M01_PRIMARY_DATA_PORT} \
|
||||
--status-addr 127.0.0.1:${M01_PRIMARY_STATUS_PORT} \
|
||||
--status-recovery \
|
||||
--durable-root ${REMOTE_RUN_DIR}/primary-store \
|
||||
--durable-impl ${DURABLE_IMPL} \
|
||||
--durable-blocks ${DURABLE_BLOCKS} --durable-blocksize ${DURABLE_BLOCKSIZE} \
|
||||
--t0-print-ready --t1-readiness \
|
||||
> ${REMOTE_RUN_DIR}/logs/primary.log 2>&1 </dev/null & disown
|
||||
sleep 3
|
||||
pgrep -f 'g5-blockvolume.*server-id m01-primary' >/dev/null || (cat ${REMOTE_RUN_DIR}/logs/primary.log; exit 1)
|
||||
" || die "primary blockvolume failed to start"
|
||||
--iscsi-listen 0.0.0.0:${M01_ISCSI_PORT} \
|
||||
--iscsi-iqn ${ISCSI_IQN} \
|
||||
--t1-readiness \
|
||||
> ${REMOTE_RUN_DIR}/logs/primary.log 2>&1 </dev/null & disown"
|
||||
}
|
||||
|
||||
# replica blockvolume on M02
|
||||
log " starting replica blockvolume on M02..."
|
||||
$SSH_M02 "
|
||||
start_replica() {
|
||||
log " start replica blockvolume on M02..."
|
||||
$SSH_M02 "mkdir -p ${REMOTE_RUN_DIR}/{logs,replica-store} && \
|
||||
nohup /tmp/g5-blockvolume \
|
||||
--master 192.168.1.181:${M01_MASTER_PORT} \
|
||||
--server-id m02-replica --volume-id v1 --replica-id r2 \
|
||||
--ctrl-addr 0.0.0.0:${M02_REPLICA_CTRL_PORT} --data-addr 0.0.0.0:${M02_REPLICA_DATA_PORT} \
|
||||
--durable-root ${REMOTE_RUN_DIR}/durable-replica --durable-impl ${DURABLE_IMPL} \
|
||||
--ctrl-addr 0.0.0.0:${M02_REPLICA_CTRL_PORT} \
|
||||
--data-addr 0.0.0.0:${M02_REPLICA_DATA_PORT} \
|
||||
--status-addr 127.0.0.1:${M02_REPLICA_STATUS_PORT} \
|
||||
--status-recovery \
|
||||
--durable-root ${REMOTE_RUN_DIR}/replica-store \
|
||||
--durable-impl ${DURABLE_IMPL} \
|
||||
--durable-blocks ${DURABLE_BLOCKS} --durable-blocksize ${DURABLE_BLOCKSIZE} \
|
||||
--t0-print-ready --t1-readiness \
|
||||
> ${REMOTE_RUN_DIR}/logs/replica.log 2>&1 </dev/null & disown
|
||||
sleep 3
|
||||
pgrep -f 'g5-blockvolume.*server-id m02-replica' >/dev/null || (cat ${REMOTE_RUN_DIR}/logs/replica.log; exit 1)
|
||||
" || die "replica blockvolume failed to start"
|
||||
--t1-readiness \
|
||||
> ${REMOTE_RUN_DIR}/logs/replica.log 2>&1 </dev/null & disown"
|
||||
}
|
||||
|
||||
log " cluster up: master+primary on m01, replica on M02"
|
||||
start_cluster() {
|
||||
log "phase 2: start cluster"
|
||||
$SSH_M01 "sudo pkill -9 -f g5-blockvolume 2>/dev/null || true; sudo pkill -9 -f g5-blockmaster 2>/dev/null || true; rm -rf ${REMOTE_RUN_DIR} && mkdir -p ${REMOTE_RUN_DIR}/{logs,master-store,primary-store}"
|
||||
$SSH_M02 "sudo pkill -9 -f g5-blockvolume 2>/dev/null || true; rm -rf ${REMOTE_RUN_DIR} && mkdir -p ${REMOTE_RUN_DIR}/{logs,replica-store}"
|
||||
write_topology
|
||||
start_master
|
||||
start_primary
|
||||
start_replica
|
||||
}
|
||||
|
||||
stop_cluster() {
|
||||
log "stopping cluster..."
|
||||
$SSH_M01 "sudo pkill -9 -f g5-blockvolume 2>/dev/null || true; sudo pkill -9 -f g5-blockmaster 2>/dev/null || true; sleep 1" >/dev/null 2>&1 || true
|
||||
$SSH_M02 "sudo pkill -9 -f g5-blockvolume 2>/dev/null || true; sleep 1" >/dev/null 2>&1 || true
|
||||
log "stop cluster"
|
||||
$SSH_M01 "sudo pkill -9 -f g5-blockvolume 2>/dev/null || true; sudo pkill -9 -f g5-blockmaster 2>/dev/null || true" || true
|
||||
$SSH_M02 "sudo pkill -9 -f g5-blockvolume 2>/dev/null || true" || true
|
||||
}
|
||||
|
||||
# --- Phase 3: scenarios (TODO bodies await G5 mini-plan ratification) ---
|
||||
# --- Phase 3: verify steps (per mini-plan v0.3 §2) ---
|
||||
|
||||
# TODO(G5-arch-ratify): the architect-ratified scenario list per G5
|
||||
# mini-plan §3 batch G5-4 acceptance criteria #3. Suggested set
|
||||
# (subject to architect ratification, see g5-kickoff.md §4 #1):
|
||||
#
|
||||
# ShortDisconnect_DeltaCatchUp × {smartwal, walstore}
|
||||
# LongDisconnect_RebuildEscalation × {smartwal, walstore}
|
||||
# MidStreamDisconnect_Recovery × {smartwal, walstore}
|
||||
# SteadyStateLiveShip_Throughput × {smartwal, walstore}
|
||||
#
|
||||
# Each scenario body needs:
|
||||
# 1. workload driver (iSCSI? gRPC admin? direct primary-write?)
|
||||
# 2. fault injection (iptables block on data-addr? or ctrl-addr?)
|
||||
# 3. wait-for-event (SessionClosed, RebuildSessionClosed, etc.)
|
||||
# 4. byte-exact convergence verification (compare AllBlocks() on
|
||||
# primary vs replica)
|
||||
#
|
||||
# Need framework support:
|
||||
# - workload driver — sw decision: iSCSI target binding to primary
|
||||
# vs gRPC admin endpoint vs new test-only RPC
|
||||
# - replica state inspector — gRPC status endpoint (--status-addr
|
||||
# already on blockvolume) reports R/S/H/Decision
|
||||
# - byte-exact verifier — read-back across both nodes via status
|
||||
# endpoint or separate diagnostic tool
|
||||
|
||||
scenario_short_disconnect_delta_catchup() {
|
||||
local impl="$1"
|
||||
log " scenario: ShortDisconnect_DeltaCatchUp (${impl}) — TODO(G5-arch-ratify)"
|
||||
# 1. Drive primary writes for 5s (TODO: workload driver)
|
||||
# 2. iptables -I INPUT -p tcp --dport ${M02_REPLICA_DATA_PORT} -j DROP
|
||||
# 3. Drive primary writes for 5s more
|
||||
# 4. iptables -D INPUT -p tcp --dport ${M02_REPLICA_DATA_PORT} -j DROP
|
||||
# 5. Wait for engine-driven catch-up to complete (poll status endpoint)
|
||||
# 6. Verify replica converges byte-exact (delta only — most data was already shipped)
|
||||
# 7. Assert: ScanLBAs metric shows reduced emit count vs full-window
|
||||
return 0
|
||||
# §2 #1 — cluster reaches role-appropriate ready state
|
||||
verify_cluster_ready() {
|
||||
log "verify_cluster_ready: primary should reach Healthy=true; replica Healthy=false"
|
||||
wait_until "primary Healthy=true" 15 \
|
||||
"[ \"\$($SSH_M01 \"curl -s --max-time 2 'http://127.0.0.1:${M01_PRIMARY_STATUS_PORT}/status?volume=v1' | grep -o '\\\"Healthy\\\":true'\")\" = '\"Healthy\":true' ]" \
|
||||
|| die "primary did not reach Healthy=true within 15s"
|
||||
# Replica must respond to /status with Healthy=false (NOT Healthy=true; role split).
|
||||
local rh
|
||||
rh=$($SSH_M02 "curl -s --max-time 2 'http://127.0.0.1:${M02_REPLICA_STATUS_PORT}/status?volume=v1' | grep -o '\"Healthy\":[a-z]*'")
|
||||
[ "${rh}" = '"Healthy":false' ] || die "replica reported ${rh}; expected Healthy=false (architect role-split binding)"
|
||||
log " ✓ cluster ready"
|
||||
}
|
||||
|
||||
scenario_long_disconnect_rebuild_escalation() {
|
||||
local impl="$1"
|
||||
log " scenario: LongDisconnect_RebuildEscalation (${impl}) — TODO(G5-arch-ratify)"
|
||||
# 1. Drive primary writes for long enough to fill replica's WAL retention window
|
||||
# 2. iptables block replica
|
||||
# 3. Drive primary writes past retention
|
||||
# 4. iptables unblock
|
||||
# 5. Catch-up should fail with WAL recycled → engine emits StartRebuild
|
||||
# 6. Rebuild completes → replica converges byte-exact
|
||||
# 7. Assert: rebuild session was actually emitted (not just Decision=Rebuild state)
|
||||
return 0
|
||||
# §2 #2 — kernel iSCSI write + m01verify storage-aware compare
|
||||
verify_byte_equal() {
|
||||
log "verify_byte_equal: iSCSI write 1 LBA + m01verify SHA-256"
|
||||
# Prereq: open-iscsi initiator on m01.
|
||||
$SSH_M01 "command -v iscsiadm >/dev/null" || die "iscsiadm not installed on m01 (apt install open-iscsi)"
|
||||
# Discover + login
|
||||
$SSH_M01 "
|
||||
sudo iscsiadm -m discovery -t st -p 127.0.0.1:${M01_ISCSI_PORT} >/dev/null
|
||||
sudo iscsiadm -m node -T ${ISCSI_IQN} -p 127.0.0.1:${M01_ISCSI_PORT} --login >/dev/null
|
||||
" || die "iscsi login failed"
|
||||
sleep 2
|
||||
# Find the device (most-recently attached scsi disk)
|
||||
local dev
|
||||
dev=$($SSH_M01 "ls -t /dev/disk/by-path/*${ISCSI_IQN}*-lun-0 2>/dev/null | head -1")
|
||||
[ -n "${dev}" ] || die "iscsi device not found under /dev/disk/by-path"
|
||||
log " iscsi device: ${dev}"
|
||||
# Write a known pattern (0xab) into LBA 0 (4096 bytes) via dd
|
||||
$SSH_M01 "
|
||||
sudo dd if=/dev/zero bs=4096 count=1 2>/dev/null | tr '\\0' '\\xab' | sudo dd of=${dev} bs=4096 count=1 conv=fsync,nocreat 2>/dev/null
|
||||
sync
|
||||
" || die "iscsi write failed"
|
||||
sleep 1 # let replication fan-out complete
|
||||
# Logout iscsi (release the device handle so we can stop replica cleanly later)
|
||||
$SSH_M01 "sudo iscsiadm -m node -T ${ISCSI_IQN} -p 127.0.0.1:${M01_ISCSI_PORT} --logout >/dev/null" || true
|
||||
# Stop replica daemon so m01verify can OpenReadOnly
|
||||
$SSH_M02 "sudo pkill -TERM -f 'g5-blockvolume.*server-id m02-replica' && sleep 2"
|
||||
# m01verify reads replica's walstore
|
||||
local out
|
||||
out=$($SSH_M02 "/tmp/g5-m01verify --walstore ${REMOTE_RUN_DIR}/replica-store/v1.walstore --lba-start 0 --lba-count 1 --block-size 4096 --expected-pattern ab 2>&1")
|
||||
log " m01verify output: ${out}"
|
||||
echo "${out}" | grep -q '^OK ' || die "byte-equal verify failed: ${out}"
|
||||
# Restart replica for subsequent steps
|
||||
start_replica
|
||||
sleep 3
|
||||
log " ✓ byte-equal"
|
||||
}
|
||||
|
||||
scenario_mid_stream_disconnect_recovery() {
|
||||
local impl="$1"
|
||||
log " scenario: MidStreamDisconnect_Recovery (${impl}) — TODO(G5-arch-ratify)"
|
||||
# 1. Drive primary writes
|
||||
# 2. Cause primary↔replica disconnect mid-catch-up (iptables block + unblock quickly)
|
||||
# 3. Verify engine retry budget consumes attempts
|
||||
# 4. Verify final convergence within budget OR escalation observed
|
||||
return 0
|
||||
# §2 #3 — network disconnect catch-up via /status/recovery R/H polling
|
||||
verify_network_catchup() {
|
||||
log "verify_network_catchup: iptables drop primary→replica WAL port + observe catch-up"
|
||||
# Block primary→replica data port at M02
|
||||
$SSH_M02 "sudo iptables -I INPUT -p tcp --dport ${M02_REPLICA_DATA_PORT} -j DROP"
|
||||
# Trigger primary write while disconnected (login + write + logout)
|
||||
$SSH_M01 "
|
||||
sudo iscsiadm -m node -T ${ISCSI_IQN} -p 127.0.0.1:${M01_ISCSI_PORT} --login >/dev/null
|
||||
sleep 2
|
||||
DEV=\$(ls -t /dev/disk/by-path/*${ISCSI_IQN}*-lun-0 2>/dev/null | head -1)
|
||||
sudo dd if=/dev/urandom of=\${DEV} bs=4096 count=2 conv=fsync,nocreat 2>/dev/null
|
||||
sync
|
||||
sudo iscsiadm -m node -T ${ISCSI_IQN} -p 127.0.0.1:${M01_ISCSI_PORT} --logout >/dev/null
|
||||
" || die "iscsi write during disconnect failed"
|
||||
# Verify replica is behind: R != H
|
||||
local prim_h rep_r
|
||||
prim_h=$(poll_status_field "$SSH_M01" "${M01_PRIMARY_STATUS_PORT}" H)
|
||||
rep_r=$(poll_status_field "$SSH_M02" "${M02_REPLICA_STATUS_PORT}" R)
|
||||
log " pre-restore: primary.H=${prim_h}, replica.R=${rep_r}"
|
||||
# Restore network
|
||||
$SSH_M02 "sudo iptables -D INPUT -p tcp --dport ${M02_REPLICA_DATA_PORT} -j DROP"
|
||||
# Poll until replica catches up
|
||||
wait_until "replica catches up to primary.H=${prim_h}" "${CATCHUP_DEADLINE}" \
|
||||
"[ \"\$(poll_status_field '$SSH_M02' '${M02_REPLICA_STATUS_PORT}' R)\" -ge \"${prim_h}\" ]" \
|
||||
|| die "replica did not catch up to H=${prim_h} within ${CATCHUP_DEADLINE}s"
|
||||
# Assert RecoveryDecision was catch_up (not rebuild)
|
||||
local decision
|
||||
decision=$(poll_status_field "$SSH_M02" "${M02_REPLICA_STATUS_PORT}" RecoveryDecision)
|
||||
case "${decision}" in
|
||||
catch_up|"") ;; # empty = already converged before observation; acceptable
|
||||
rebuild) die "expected RecoveryDecision=catch_up; got rebuild (gap exceeded retention?)" ;;
|
||||
*) log " RecoveryDecision=${decision}" ;;
|
||||
esac
|
||||
log " ✓ network catch-up converged"
|
||||
}
|
||||
|
||||
scenario_steady_state_live_ship_throughput() {
|
||||
local impl="$1"
|
||||
log " scenario: SteadyStateLiveShip_Throughput (${impl}) — TODO(G5-arch-ratify)"
|
||||
# 1. No fault injection
|
||||
# 2. Drive sustained writes for ${WORKLOAD_DURATION_SEC}s
|
||||
# 3. Measure throughput, latency, replica lag
|
||||
# 4. Verify walstore flusher cadence under sustained load
|
||||
# (relevant to G5-2 walstore tuning policy)
|
||||
return 0
|
||||
# §2 #4 — replica process stop/restart catch-up
|
||||
verify_restart_catchup() {
|
||||
log "verify_restart_catchup: SIGTERM replica + restart same --durable-root"
|
||||
# Trigger primary write while replica is down
|
||||
$SSH_M02 "sudo pkill -TERM -f 'g5-blockvolume.*server-id m02-replica'"
|
||||
sleep 2
|
||||
$SSH_M01 "
|
||||
sudo iscsiadm -m node -T ${ISCSI_IQN} -p 127.0.0.1:${M01_ISCSI_PORT} --login >/dev/null
|
||||
sleep 2
|
||||
DEV=\$(ls -t /dev/disk/by-path/*${ISCSI_IQN}*-lun-0 2>/dev/null | head -1)
|
||||
sudo dd if=/dev/urandom of=\${DEV} bs=4096 count=2 seek=4 conv=fsync,nocreat 2>/dev/null
|
||||
sync
|
||||
sudo iscsiadm -m node -T ${ISCSI_IQN} -p 127.0.0.1:${M01_ISCSI_PORT} --logout >/dev/null
|
||||
" || die "iscsi write during replica-down failed"
|
||||
local prim_h
|
||||
prim_h=$(poll_status_field "$SSH_M01" "${M01_PRIMARY_STATUS_PORT}" H)
|
||||
log " primary.H after offline write: ${prim_h}"
|
||||
# Restart replica (same binary, same --durable-root)
|
||||
start_replica
|
||||
sleep 3
|
||||
# Poll until replica catches up
|
||||
wait_until "replica catches up post-restart to H=${prim_h}" "${CATCHUP_DEADLINE}" \
|
||||
"[ \"\$(poll_status_field '$SSH_M02' '${M02_REPLICA_STATUS_PORT}' R)\" -ge \"${prim_h}\" ]" \
|
||||
|| die "replica did not catch up post-restart within ${CATCHUP_DEADLINE}s"
|
||||
log " ✓ restart catch-up converged"
|
||||
}
|
||||
|
||||
# --- Phase 4: run scenario matrix ---
|
||||
# §2 #5 — race ×10 stress on G5-4 integration test
|
||||
verify_race_stress() {
|
||||
log "verify_race_stress: TestG54_BinaryWiring x10 -race on m01"
|
||||
$SSH_M01 "command -v gcc >/dev/null" || die "gcc not installed on m01 (needed for CGO -race)"
|
||||
$SSH_M01 "cd ${REMOTE_BUILD_DIR} && CGO_ENABLED=1 go test -race -count=10 -run TestG54_BinaryWiring ./cmd/blockvolume/ 2>&1" > "${ARTIFACT_DIR}/race-stress.log" \
|
||||
|| die "race stress failed; see ${ARTIFACT_DIR}/race-stress.log"
|
||||
log " ✓ race ×10"
|
||||
}
|
||||
|
||||
run_matrix() {
|
||||
local scenarios=(
|
||||
scenario_short_disconnect_delta_catchup
|
||||
scenario_long_disconnect_rebuild_escalation
|
||||
scenario_mid_stream_disconnect_recovery
|
||||
scenario_steady_state_live_ship_throughput
|
||||
)
|
||||
local impls=(walstore smartwal)
|
||||
local total=0 passed=0 failed=0
|
||||
|
||||
for impl in "${impls[@]}"; do
|
||||
DURABLE_IMPL="${impl}"
|
||||
for fn in "${scenarios[@]}"; do
|
||||
total=$((total+1))
|
||||
log "scenario ${total}: ${fn} on ${impl}"
|
||||
start_cluster
|
||||
if "${fn}" "${impl}"; then
|
||||
passed=$((passed+1))
|
||||
log " ✓ pass"
|
||||
else
|
||||
failed=$((failed+1))
|
||||
log " ✗ FAIL"
|
||||
collect_diagnostics "${fn}-${impl}"
|
||||
fi
|
||||
stop_cluster
|
||||
done
|
||||
done
|
||||
|
||||
log "matrix: ${passed}/${total} passed (${failed} failed)"
|
||||
[ "${failed}" -eq 0 ] || die "matrix had ${failed} failures; see ${ARTIFACT_DIR}/"
|
||||
# §2 #6 — full V3 suite green from m01
|
||||
verify_full_suite() {
|
||||
log "verify_full_suite: go test ./... clean from m01"
|
||||
$SSH_M01 "cd ${REMOTE_BUILD_DIR} && go test ./... -count=1 -timeout 600s 2>&1" > "${ARTIFACT_DIR}/full-suite.log" \
|
||||
|| die "full suite has failures; see ${ARTIFACT_DIR}/full-suite.log"
|
||||
log " ✓ full suite green"
|
||||
}
|
||||
|
||||
# --- Main ---
|
||||
|
||||
main() {
|
||||
log "=== G5-4 m01 hardware first-light harness (DRAFT v0.1 skeleton) ==="
|
||||
log "primary node: ${M01_HOST}"
|
||||
log "replica node: ${M02_HOST}"
|
||||
log "substrate impl matrix: walstore + smartwal"
|
||||
log "extent size: ${DURABLE_BLOCKS} blocks × ${DURABLE_BLOCKSIZE} bytes = $((DURABLE_BLOCKS*DURABLE_BLOCKSIZE/1024/1024)) MiB"
|
||||
log "workload duration: ${WORKLOAD_DURATION_SEC}s per scenario"
|
||||
log "artifact dir: ${ARTIFACT_DIR}"
|
||||
log "=== G5-5 m01 hardware first-light ==="
|
||||
log "primary: ${M01_HOST} ; replica: ${M02_HOST}"
|
||||
log "substrate: ${DURABLE_IMPL} ; ${DURABLE_BLOCKS} blocks × ${DURABLE_BLOCKSIZE} B"
|
||||
log "artifacts: ${ARTIFACT_DIR}"
|
||||
|
||||
sync_and_build
|
||||
run_matrix
|
||||
start_cluster
|
||||
sleep 3
|
||||
|
||||
log "=== ALL SCENARIOS PASSED ==="
|
||||
verify_cluster_ready
|
||||
verify_byte_equal
|
||||
verify_network_catchup
|
||||
verify_restart_catchup
|
||||
verify_race_stress
|
||||
verify_full_suite
|
||||
|
||||
stop_cluster
|
||||
log "=== G5-5 ALL VERIFY STEPS PASS ==="
|
||||
}
|
||||
|
||||
main "$@"
|
||||
Reference in new issue
Block a user