mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
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>
165 lines
4.9 KiB
Go
165 lines
4.9 KiB
Go
//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
|
|
}
|