diff --git a/seaweed-block/cmd/blockvolume/geometry_flag_record_integration_test.go b/seaweed-block/cmd/blockvolume/geometry_flag_record_integration_test.go index bdd1616177..28ac228ffe 100644 --- a/seaweed-block/cmd/blockvolume/geometry_flag_record_integration_test.go +++ b/seaweed-block/cmd/blockvolume/geometry_flag_record_integration_test.go @@ -21,7 +21,7 @@ import ( // a right-flag start on the same root then fails on the leftover store. func TestWrongGeometryFlagIsRefusedBeforeTheStoreIsCreated(t *testing.T) { env := startSourceWithSnapshot(t, "v2") - env.h.command(t, "ops", "chunk", "restore", "--source", "v1", "--snapshot", "s1", "--target", "v2", + env.h.command(t, "ops", "chunk", "restore", "--master", env.h.masterAddr, "--source", "v1", "--snapshot", "s1", "--target", "v2", "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) b := env.hosts["n-v2"] args := append([]string{}, env.volArgsFor(b)...) @@ -70,7 +70,7 @@ func TestWrongGeometryFlagIsRefusedBeforeTheStoreIsCreated(t *testing.T) { // cannot deliver the record is the retryable case, 75: the unit test.) func TestCorruptRecordIsRefusedBeforeTheStoreIsCreated(t *testing.T) { env := startSourceWithSnapshot(t, "v2") - env.h.command(t, "ops", "chunk", "restore", "--source", "v1", "--snapshot", "s1", "--target", "v2", + env.h.command(t, "ops", "chunk", "restore", "--master", env.h.masterAddr, "--source", "v1", "--snapshot", "s1", "--target", "v2", "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) b := env.hosts["n-v2"] right := append([]string{}, env.volArgsFor(b)...) @@ -121,7 +121,7 @@ func TestCorruptRecordIsRefusedBeforeTheStoreIsCreated(t *testing.T) { // check (exit 1) before the record check and before any store exists. func TestFirstStartWithTheFilerDownCreatesNoStore(t *testing.T) { env := startSourceWithSnapshot(t, "v2") - env.h.command(t, "ops", "chunk", "restore", "--source", "v1", "--snapshot", "s1", "--target", "v2", + env.h.command(t, "ops", "chunk", "restore", "--master", env.h.masterAddr, "--source", "v1", "--snapshot", "s1", "--target", "v2", "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) b := env.hosts["n-v2"] env.cluster.stopProc(t, "filer") diff --git a/seaweed-block/cmd/blockvolume/headroom_blast_radius_integration_test.go b/seaweed-block/cmd/blockvolume/headroom_blast_radius_integration_test.go index 01d5f1db74..01dfde9421 100644 --- a/seaweed-block/cmd/blockvolume/headroom_blast_radius_integration_test.go +++ b/seaweed-block/cmd/blockvolume/headroom_blast_radius_integration_test.go @@ -12,7 +12,7 @@ import ( // TestHeadroomRefusedTargetBlastRadiusAndAnotherRoot: two restore targets of // a snapshot of v1 (v2, v3) are refused for local headroom on the small file -// system (as in TestHeadroomRefusesARestoreAndAForkTargetThenServesThem; run +// system (as in TestHeadroomRefusesRestoreTargetsThenServesThem; run // it with testdata/headroom-small-fs.sh). Then: // // - another root on the same host is a way out: v3's blockvolume, started @@ -50,7 +50,7 @@ func TestHeadroomRefusedTargetBlastRadiusAndAnotherRoot(t *testing.T) { env.writeImage(t, "s1", img) env.snapshot(t, "s1", "v1", "base") for _, v := range []string{"v2", "v3"} { - env.h.command(t, "ops", "chunk", "restore", "--source", "v1", "--snapshot", "base", "--target", v, + env.h.command(t, "ops", "chunk", "restore", "--master", env.h.masterAddr, "--source", "v1", "--snapshot", "base", "--target", v, "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) env.refusedForHeadroom(t, v, "blockvolume-"+v+"-no-room") } @@ -117,7 +117,7 @@ func TestHeadroomRefusedRestoreTargetSurvivesItsSourceDeleteAndGC(t *testing.T) img := ladderImage("srcgone", []uint64{0, 3, 9}, 4) env.writeImage(t, "s1", img) env.snapshot(t, "s1", "v1", "base") - env.h.command(t, "ops", "chunk", "restore", "--source", "v1", "--snapshot", "base", "--target", "v2", + env.h.command(t, "ops", "chunk", "restore", "--master", env.h.masterAddr, "--source", "v1", "--snapshot", "base", "--target", "v2", "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) env.refusedForHeadroom(t, "v2", "blockvolume-v2-no-room") @@ -165,9 +165,8 @@ func TestHeadroomRefusedRestoreTargetSurvivesItsSourceDeleteAndGC(t *testing.T) } poll(t, 60*time.Second, "v2 never reported its frontend ready", func() bool { return volumeFrontendReady(b2.status, "v2") }) requireImageExact(t, env, "n-v2", img, "after its source was deleted and collected") - env.h.command(t, "ops", "chunk", "restore", "--volume", "v2", "--status-addr", b2.status) - env.waitIndependent(t, "v2") - requireImageExact(t, env, "n-v2", img, "after its restore reached independence") + env.waitHydrated(t, "v2") + requireImageExact(t, env, "n-v2", img, "after it hydrated") } // requireImageExact reads every block of img on the host and fails, marked diff --git a/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go b/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go index f94e200850..865a291353 100644 --- a/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go +++ b/seaweed-block/cmd/blockvolume/headroom_restore_fork_integration_test.go @@ -15,7 +15,7 @@ import ( "time" ) -// Local headroom for a restore and a fork target. The durable root of each +// Local headroom for restore targets. The durable root of each // target is on a small file system (CHUNKSTORE_SMALL_ROOT, a directory on it) // that a filler file (CHUNKSTORE_SMALL_FILLER, on the same file system) keeps // below the volume size + WAL. testdata/headroom-small-fs.sh prepares both on @@ -158,8 +158,8 @@ func (env *handoffEnv) deleteServingTarget(t *testing.T, vol string, b bvHost, d } } -// TestHeadroomRefusesARestoreAndAForkTargetThenServesThem: a snapshot of v1 -// is restored into v2, v4 and v6 and forked into v3, each target's durable +// TestHeadroomRefusesRestoreTargetsThenServesThem: a snapshot of v1 is +// restored into v2, v4 and v6 (fork is not in v1), each target's durable // root on a small file system with less free space than the volume size + // WAL. // Each target's blockvolume refuses the create, naming both numbers, exits @@ -172,9 +172,9 @@ func (env *handoffEnv) deleteServingTarget(t *testing.T, vol string, b bvHost, d // of 1.0): a volume-delete wants a clean revocation ACK its holder cannot // send, and a forced move to a host with room (n-v7) is refused because the // master knows no holder of it. The one way out is run: once space is freed, -// v2 and v3 start and serve the snapshot, and v4 and v6 start, serve, and are +// v2 starts and serves the snapshot, and v4 and v6 start, serve, and are // sealed, revoked, acknowledged and deleted. -func TestHeadroomRefusesARestoreAndAForkTargetThenServesThem(t *testing.T) { +func TestHeadroomRefusesRestoreTargetsThenServesThem(t *testing.T) { small, filler := os.Getenv("CHUNKSTORE_SMALL_ROOT"), os.Getenv("CHUNKSTORE_SMALL_FILLER") if small == "" || filler == "" { t.Skip("CHUNKSTORE_SMALL_ROOT and CHUNKSTORE_SMALL_FILLER name a small file system and its filler file") @@ -185,8 +185,8 @@ func TestHeadroomRefusesARestoreAndAForkTargetThenServesThem(t *testing.T) { } t.Cleanup(func() { _ = os.RemoveAll(filepath.Join(small, t.Name())) }) - env := startLadderEnv(t, "v2", "v3", "v4", "v5", "v6", "v7") - for _, v := range []string{"v2", "v3", "v4", "v6"} { + env := startLadderEnv(t, "v2", "v4", "v5", "v6", "v7") + for _, v := range []string{"v2", "v4", "v6"} { b := env.hosts["n-"+v] b.root = filepath.Join(small, t.Name(), "vol-n-"+v) env.hosts["n-"+v] = b @@ -198,16 +198,14 @@ func TestHeadroomRefusesARestoreAndAForkTargetThenServesThem(t *testing.T) { env.writeImage(t, "s1", img) env.snapshot(t, "s1", "v1", "base") - env.h.command(t, "ops", "chunk", "restore", "--source", "v1", "--snapshot", "base", "--target", "v2", - "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) - env.h.command(t, "ops", "chunk", "fork", "--source", "v1", "--snapshot", "base", "--target", "v3", + env.h.command(t, "ops", "chunk", "restore", "--master", env.h.masterAddr, "--source", "v1", "--snapshot", "base", "--target", "v2", "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) for _, v := range []string{"v4", "v6"} { - env.h.command(t, "ops", "chunk", "restore", "--source", "v1", "--snapshot", "base", "--target", v, + env.h.command(t, "ops", "chunk", "restore", "--master", env.h.masterAddr, "--source", "v1", "--snapshot", "base", "--target", v, "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) } refused := map[string]*daemon{} - for _, v := range []string{"v2", "v3", "v4", "v6"} { + for _, v := range []string{"v2", "v4", "v6"} { refused[v] = env.refusedForHeadroom(t, v, "blockvolume-"+v+"-no-room") } @@ -235,7 +233,7 @@ func TestHeadroomRefusesARestoreAndAForkTargetThenServesThem(t *testing.T) { if free := freeBytes(t, small); free < need { t.Fatalf("after removing the filler the small file system has %d bytes free; the %d a volume needs does not fit: fix the runner", free, need) } - for _, v := range []string{"v2", "v3"} { + for _, v := range []string{"v2"} { env.startTarget(t, v, "blockvolume-"+v+"-with-room") env.requireImage(t, "n-"+v, img) } diff --git a/seaweed-block/cmd/blockvolume/known_zero_acceptance_integration_test.go b/seaweed-block/cmd/blockvolume/known_zero_acceptance_integration_test.go index 0bc8dcef1f..7b5006ce5e 100644 --- a/seaweed-block/cmd/blockvolume/known_zero_acceptance_integration_test.go +++ b/seaweed-block/cmd/blockvolume/known_zero_acceptance_integration_test.go @@ -52,7 +52,7 @@ func TestKnownZeroAcceptance(t *testing.T) { run = fmt.Sprintf("local-%d", time.Now().Unix()) } // KZ_ROLE: "" = every step in this process (the smoke); "source" = steps - // 1, 2 and 5 here, the restore and fork targets on KZ_TARGET_HOST (the + // 1, 2 and 5 here, the restore target on KZ_TARGET_HOST (the // second host), handed over through KZ_HANDOFF; "target" = steps // 3 and 4 on this host against the source's cluster named in KZ_HANDOFF. role := os.Getenv("KZ_ROLE") @@ -70,13 +70,12 @@ func TestKnownZeroAcceptance(t *testing.T) { } else if role != "" { t.Fatalf("KZ_ROLE %q: want source, target or unset", role) } - // per file system: the source and two targets of its S1, each target on - // its own server node (on KZ_TARGET_HOST in the source role) + // per file system: the source and a restore target of its S1 on its own + // server node (on KZ_TARGET_HOST in the source role); fork is not in v1 var vols []headSzVol for _, fs := range fss { vols = append(vols, headSzVol{id: "kz" + fs, bytes: bytes}, - headSzVol{id: "kz" + fs + "r", bytes: bytes, server: "t-" + fs + "r", host: targetHost}, - headSzVol{id: "kz" + fs + "f", bytes: bytes, server: "t-" + fs + "f", host: targetHost}) + headSzVol{id: "kz" + fs + "r", bytes: bytes, server: "t-" + fs + "r", host: targetHost}) } // step 5: up to kzCrashTries fresh volumes (a try whose stop lands after the // attach commit has committed that store, so a retry needs a new one) @@ -93,7 +92,7 @@ func TestKnownZeroAcceptance(t *testing.T) { if !v.S1.Completed { continue } - for _, kind := range []string{"restore", "fork"} { + for _, kind := range []string{"restore"} { tb := env.hosts["kz"+fs+kind[:1]] if role == "source" { ho.Targets = append(ho.Targets, kzHandoffTarget{Kind: kind, Volume: tb.volume, Server: tb.server, Data: tb.data, Ctrl: tb.ctrl, @@ -111,7 +110,7 @@ func TestKnownZeroAcceptance(t *testing.T) { } // kzHandoff is what the source role hands to the target role (KZ_HANDOFF): -// the cluster to use and, per target, the S1 to restore or fork and what the +// the cluster to use and, per target, the S1 to restore and what the // source wrote into it. type kzHandoff struct { Run string `json:"run"` @@ -278,7 +277,7 @@ type kzTargetRecord struct { FirstCut kzCutRecord `json:"first_snapshot"` } -// kzTarget restores or forks the source's S1 into tb, then runs step 4 (read +// kzTarget restores the source's S1 into tb, then runs step 4 (read // the S1-named blocks BEFORE hydration: data, never zeros; the read itself // waits for its chunk) and step 3 (all contents equal the source; the target's // first snapshot completes without a full scan). @@ -286,8 +285,8 @@ func kzTarget(t *testing.T, env *handoffEnv, rep *kzReport, src kzVolume, kind s t.Helper() r := kzTargetRecord{Volume: tb.volume, Kind: kind, Source: src.Volume, Snapshot: src.S1Name, NQN: fmt.Sprintf("nqn.2026-11.io.seaweedfs:kz-%s-%s", run, tb.volume)} - env.h.command(t, "ops", "chunk", kind, "--source", src.Volume, "--snapshot", src.S1Name, "--target", tb.volume, - "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath, "--request-id", "kz-"+kind+"-"+tb.volume) + env.h.command(t, "ops", "chunk", "restore", "--source", src.Volume, "--snapshot", src.S1Name, "--target", tb.volume, + "--master", env.h.masterAddr, "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath, "--request-id", "kz-"+kind+"-"+tb.volume) d, refusal := headSzStartVolume(t, env, tb, bytes, "--nvme-subsysnqn", r.NQN) if d == nil { rep.step(t, 3, tb.volume, false, kind+" target refused: "+refusal) @@ -318,10 +317,9 @@ func kzTarget(t *testing.T, env *handoffEnv, rep *kzReport, src kzVolume, kind s kind, r.Reads, r.ReadsEqual, r.ReadsZero, r.Before.AbsentChunks, r.After.AbsentChunks, waited, r.After.Hydration.Fetches-r.Before.Hydration.Fetches)) - // (3) contents equal + first snapshot without a full scan - if kind == "restore" { - env.h.command(t, "ops", "chunk", "restore", "--volume", tb.volume, "--status-addr", tb.status) - } + // (3) contents equal + first snapshot without a full scan (a restore + // target hydrates in the background; the reads below wait for any chunk + // still absent) if device { r.Identity, r.FilesEqual = kzDeviceVerify(t, tb, r.NQN, src, run) } else { diff --git a/seaweed-block/cmd/blockvolume/neverstarted_delete_integration_test.go b/seaweed-block/cmd/blockvolume/neverstarted_delete_integration_test.go index 0ee99aef8b..112aabac5d 100644 --- a/seaweed-block/cmd/blockvolume/neverstarted_delete_integration_test.go +++ b/seaweed-block/cmd/blockvolume/neverstarted_delete_integration_test.go @@ -29,7 +29,7 @@ func TestNeverAttachedRestoreTargetIsDeletable(t *testing.T) { env.snapshot(t, "s1", "v1", "s1") // The target exists in the catalog; its blockvolume never starts. - env.h.command(t, "ops", "chunk", "restore", "--source", "v1", "--snapshot", "s1", "--target", "v2", + env.h.command(t, "ops", "chunk", "restore", "--master", env.h.masterAddr, "--source", "v1", "--snapshot", "s1", "--target", "v2", "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) out, errOut, code := env.h.run(t, "ops", "chunk", "volume-delete", "--volume", "v2", "--chunk-filer", env.cluster.filerGRPC, @@ -62,7 +62,7 @@ func TestNeverStartedDeleteFencesALateStart(t *testing.T) { env.adopt(t, holder, "s1") env.writeBlock(t, "s1", 0, cutCrashBlock('L', 0)) env.snapshot(t, "s1", "v1", "s1") - env.h.command(t, "ops", "chunk", "restore", "--source", "v1", "--snapshot", "s1", "--target", "v2", + env.h.command(t, "ops", "chunk", "restore", "--master", env.h.masterAddr, "--source", "v1", "--snapshot", "s1", "--target", "v2", "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) out, errOut, code := env.h.run(t, "ops", "chunk", "volume-delete", "--volume", "v2", "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath, "--master", env.h.masterAddr, "--request-id", "del-v2-late") @@ -93,7 +93,7 @@ func TestNeverStartedDeleteRacesAStart(t *testing.T) { env.writeBlock(t, "s1", 0, cutCrashBlock('R', 0)) env.snapshot(t, "s1", "v1", "s1") for _, v := range targets { - env.h.command(t, "ops", "chunk", "restore", "--source", "v1", "--snapshot", "s1", "--target", v, + env.h.command(t, "ops", "chunk", "restore", "--master", env.h.masterAddr, "--source", "v1", "--snapshot", "s1", "--target", v, "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) b := env.hosts["n-"+v] type delResult struct { @@ -185,7 +185,7 @@ func (env *handoffEnv) requireNeverStarted(t *testing.T, v string, e, headEpoch // and the process exits. The filer comes back. Line at 1, no lease, HEAD 0. func (env *handoffEnv) strandStoreDown(t *testing.T, v string) { t.Helper() - env.h.command(t, "ops", "chunk", "restore", "--source", "v1", "--snapshot", "s1", "--target", v, + env.h.command(t, "ops", "chunk", "restore", "--master", env.h.masterAddr, "--source", "v1", "--snapshot", "s1", "--target", v, "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) env.cluster.stopProc(t, "filer") d := env.h.start(t, "blockvolume-"+v+"-store-down", env.h.volume, env.volArgsFor(env.hosts["n-"+v])...) @@ -206,7 +206,7 @@ func (env *handoffEnv) strandStoreDown(t *testing.T, v string) { func (env *handoffEnv) strandAtGrant(t *testing.T, candidates ...string) string { t.Helper() for _, v := range candidates { - env.h.command(t, "ops", "chunk", "restore", "--source", "v1", "--snapshot", "s1", "--target", v, + env.h.command(t, "ops", "chunk", "restore", "--master", env.h.masterAddr, "--source", "v1", "--snapshot", "s1", "--target", v, "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) d := env.h.start(t, "blockvolume-"+v+"-stopped-at-grant", env.h.volume, env.volArgsFor(env.hosts["n-"+v])...) deadline := time.Now().Add(60 * time.Second) @@ -412,7 +412,7 @@ func TestNeverStartedDeleteAfterAMasterRestart(t *testing.T) { // without a revoke and an ACK is refused and the HEAD is not tombstoned. func TestClaimedTargetAfterAMasterRestartIsNotNeverStarted(t *testing.T) { env := startSourceWithSnapshot(t, "v2") - env.h.command(t, "ops", "chunk", "restore", "--source", "v1", "--snapshot", "s1", "--target", "v2", + env.h.command(t, "ops", "chunk", "restore", "--master", env.h.masterAddr, "--source", "v1", "--snapshot", "s1", "--target", "v2", "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) d := env.startTarget(t, "v2", "blockvolume-v2") if head := env.headOf(t, "v2"); strings.Contains(head, `"holder":""`) { diff --git a/seaweed-block/cmd/blockvolume/snapshot_ladder_c3kill_integration_test.go b/seaweed-block/cmd/blockvolume/snapshot_ladder_c3kill_integration_test.go index 113bdad1a3..ae41b9da6b 100644 --- a/seaweed-block/cmd/blockvolume/snapshot_ladder_c3kill_integration_test.go +++ b/seaweed-block/cmd/blockvolume/snapshot_ladder_c3kill_integration_test.go @@ -3,85 +3,36 @@ package main_test import ( - "encoding/json" "fmt" - "io" "math/rand" - "net/http" - "path" "testing" "time" ) -// restoreProgress is the restore driver's status of a target. -type restoreProgress struct { - Phase string `json:"phase"` - Running bool `json:"running"` - Filled int `json:"filled"` - Owned int `json:"owned"` - Foreign int `json:"foreign"` - Batches int `json:"batches"` -} - -// restoreStatus reads target's restore status straight from its status -// server (a GET answers the status without starting a run). -func (env *handoffEnv) restoreStatus(c *http.Client, target string) (restoreProgress, string, bool) { - resp, err := c.Get("http://" + env.hosts["n-"+target].status + "/chunk/restore?volume=" + target) - if err != nil { - return restoreProgress{}, "", false - } - b, _ := io.ReadAll(io.LimitReader(resp.Body, 1<<20)) - resp.Body.Close() - var st restoreProgress - if resp.StatusCode != http.StatusOK || json.Unmarshal(b, &st) != nil { - return restoreProgress{}, string(b), false - } - return st, string(b), true -} - -// awaitRestorePhase polls target's restore status every 10 ms until ok -// holds and returns that status, logging each change with when it was seen -// (the record of where a kill landed). It fails the test if the restore -// failed, became independent first (the moment was missed), or bound passed. -// The driver's counters (filled, owned, foreign) are written when a step -// ends, not while it runs: a moment inside a step is chosen by the phase and -// the time spent in it, not by a counter. -func (env *handoffEnv) awaitRestorePhase(t *testing.T, target, what string, bound time.Duration, ok func(restoreProgress) bool) restoreProgress { +// awaitAbsent polls target's chunk status every 10 ms until ok holds for its +// count of chunks not yet local, and returns that count. A volume that was +// already fully local before ok held fails the test: the moment was missed. +func (env *handoffEnv) awaitAbsent(t *testing.T, target, what string, bound time.Duration, ok func(absent int) bool) int { t.Helper() - c := &http.Client{Timeout: 2 * time.Second} + b := env.hosts["n-"+target] began := time.Now() - last := restoreProgress{Phase: "-"} + last := -1 for time.Since(began) < bound { - if st, raw, good := env.restoreStatus(c, target); good { - if st != last { - t.Logf("restore of %s at +%v (waiting for %s): %+v", target, time.Since(began).Round(time.Millisecond), what, st) - last = st - } - switch { - case ok(st): - return st - case st.Phase == "failed": - t.Fatalf("restore of %s failed waiting for %s: %s", target, what, raw) - case st.Phase == "independent": - t.Fatalf("restore of %s became independent before %s was seen (the restore is too small to catch it): %s", target, what, raw) - } + absent := kzReadStats(t, b).AbsentChunks + if absent != last { + t.Logf("%s at +%v (waiting for %s): %d chunks absent", target, time.Since(began).Round(time.Millisecond), what, absent) + last = absent + } + if ok(absent) { + return absent + } + if absent == 0 { + t.Fatalf("%s hydrated before %s was seen (the restore is too small to catch it)", target, what) } time.Sleep(10 * time.Millisecond) } - t.Fatalf("restore of %s: %s not seen within %v", target, what, bound) - return restoreProgress{} -} - -// requireRestoreState reads target's restore status once and fails the test -// unless the run is still going and ok holds: the check, right before a -// kill, that the kill lands where the test says. -func (env *handoffEnv) requireRestoreState(t *testing.T, target, what string, ok func(restoreProgress) bool) restoreProgress { - t.Helper() - st, raw, good := env.restoreStatus(&http.Client{Timeout: 2 * time.Second}, target) - if !good || !st.Running || !ok(st) { - t.Fatalf("restore of %s is no longer %s before the kill: %s", target, what, raw) - } - return st + t.Fatalf("%s: %s not seen within %v (last %d chunks absent)", target, what, bound, last) + return -1 } // requireBlocksOf reads every block of img on the host and requires each to @@ -117,29 +68,6 @@ func denseImage(tag string, chunks []uint64) map[uint64][]byte { return img } -// independent reports whether target's independence marker exists, read -// from the filer (not through the product's status, which reports only a -// run of this process). -func (env *handoffEnv) independent(t *testing.T, target string) bool { - t.Helper() - c := &http.Client{Timeout: 10 * time.Second} - p := path.Join(env.chunkPath, target, "RESTORE-INDEPENDENT") - resp, err := c.Get("http://" + env.cluster.filerHTTP + p + "?metadata=true") - if err != nil { - t.Fatal(err) - } - io.Copy(io.Discard, resp.Body) - resp.Body.Close() - switch resp.StatusCode { - case http.StatusOK: - return true - case http.StatusNotFound: - return false - } - t.Fatalf("filer lookup of %s: status %d", p, resp.StatusCode) - return false -} - // subsetOf returns the blocks of img in the given chunks. func subsetOf(img map[uint64][]byte, chunks []uint64) map[uint64][]byte { in := map[uint64]bool{} @@ -167,31 +95,21 @@ func (env *handoffEnv) startTarget(t *testing.T, target, name string) *daemon { return d } -// TestSnapshotLadderC3KilledHydratingAndBeforeIndependence: a restore of a -// snapshot of 32 full chunks of incompressible data into v2 (128 MiB to make -// local at the driver's 64 MiB/s: about 2 s of hydrating). +// TestSnapshotLadderC3KilledHydrating: a restore of a snapshot of 32 full +// chunks of incompressible data into v2 (128 MiB its background fill makes +// local), its blockvolume killed (SIGKILL) while the fill is under way. // -// 1. Its blockvolume is killed (SIGKILL) one second into hydrating and -// started again. Every other chunk is read back (a partly filled chunk -// must never be served), which makes those chunks local and leaves the -// rest to the driver, and the driver is started again. -// 2. The resumed run must report, when its hydrating step ends, that it -// filled some chunks and not all (0 < filled < 32: it resumed from a -// partly local volume). Then, the run still going and not independent, -// the guest writes to v2 (acknowledged); checked still running and not -// independent, the blockvolume is killed again and restarted. Before the -// driver is started again the independence marker must be absent (the -// kill landed before independence); every acknowledged write reads back. -// 3. The driver is started again, the guest writes once more, and the run -// reaches independence (per its status and the marker). Then v2 holds -// the snapshot with every acknowledged write over it, read back in full, -// and the source's snapshot, restored again into v3, is unchanged (none -// of v2's writes in it). -// -// Not covered: guest writes while the driver reports Owning. The status -// shows owning only once the single batch (32 chunks, under the 64-chunk -// batch) has ended, a few ms before independent. -func TestSnapshotLadderC3KilledHydratingAndBeforeIndependence(t *testing.T) { +// 1. Killed with some chunks local and some not, then started again. Every +// other chunk is read back: each is the snapshot's (a partly filled +// chunk is never served), and reading makes it local. +// 2. The fill resumes from what is local: still some chunks absent, then +// fewer. The guest writes (acknowledged); killed again before the fill +// ends and restarted, every acknowledged write reads back. +// 3. The guest writes once more and the fill completes (no chunk absent). +// v2 holds the snapshot with every acknowledged write over it, read back +// in full, and the source's snapshot, restored again into v3, is +// unchanged (none of v2's writes in it). +func TestSnapshotLadderC3KilledHydrating(t *testing.T) { env := startLadderEnv(t, "v2", "v3") var chunks []uint64 for c := uint64(0); c < 32; c++ { @@ -201,56 +119,38 @@ func TestSnapshotLadderC3KilledHydratingAndBeforeIndependence(t *testing.T) { env.writeImage(t, "s1", src) env.snapshot(t, "s1", "v1", "base") - env.h.command(t, "ops", "chunk", "restore", "--source", "v1", "--snapshot", "base", "--target", "v2", + env.h.command(t, "ops", "chunk", "restore", "--master", env.h.masterAddr, "--source", "v1", "--snapshot", "base", "--target", "v2", "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) target := env.startTarget(t, "v2", "blockvolume-v2") - drive := func() { - t.Helper() - env.h.command(t, "ops", "chunk", "restore", "--volume", "v2", "--status-addr", env.hosts["n-v2"].status) - } - drive() - // Killed one second into hydrating. - env.awaitRestorePhase(t, "v2", "hydrating", 120*time.Second, func(s restoreProgress) bool { return s.Phase == "hydrating" }) - time.Sleep(time.Second) - st := env.requireRestoreState(t, "v2", "hydrating", func(s restoreProgress) bool { return s.Phase == "hydrating" }) + // (1) killed mid-fill + partly := func(absent int) bool { return absent > 0 && absent < len(chunks) } + absent := env.awaitAbsent(t, "v2", "a partly filled volume", 120*time.Second, partly) target.kill(t) - t.Logf("killed 1 s into hydrating: %+v", st) - target = env.startTarget(t, "v2", "blockvolume-v2-after-hydrate-kill") + t.Logf("killed with %d of %d chunks absent", absent, len(chunks)) + target = env.startTarget(t, "v2", "blockvolume-v2-after-fill-kill") var even []uint64 for c := uint64(0); c < 32; c += 2 { even = append(even, c) } env.requireBlocksOf(t, "n-v2", subsetOf(src, even)) // no partly filled chunk is served - drive() - // The resumed run: it fills what is not local yet; then, before - // independence, written and killed. - notDone := func(s restoreProgress) bool { return s.Phase != "independent" } - st = env.awaitRestorePhase(t, "v2", "the resumed run's hydrating step ended", 60*time.Second, func(s restoreProgress) bool { - return s.Running && s.Filled > 0 && notDone(s) - }) - if st.Filled >= len(chunks) { - t.Fatalf("the resumed run filled %d chunks: it did not resume from a partly local volume (%d read back before it)", st.Filled, len(even)) + // (2) the fill resumes; written and killed again before it ends + resumed := env.awaitAbsent(t, "v2", "the resumed fill", 60*time.Second, func(a int) bool { return a > 0 }) + if resumed >= len(chunks) { + t.Fatalf("after the restart %d of %d chunks are absent: nothing local survived the kill", resumed, len(chunks)) } w1 := ladderImage("c3kw1", []uint64{3, 17, 50}, 3) env.writeImage(t, "n-v2", w1) - st = env.requireRestoreState(t, "v2", "running and not independent", notDone) + env.awaitAbsent(t, "v2", "the fill still running after the write", time.Second, func(a int) bool { return a > 0 }) target.kill(t) - t.Logf("killed in the resumed run after it filled %d of %d chunks, after the write: %+v", st.Filled, len(chunks), st) - target = env.startTarget(t, "v2", "blockvolume-v2-after-batch-kill") - if env.independent(t, "v2") { - t.Fatal("the independence marker exists after the second kill: the kill did not land before independence") - } + target = env.startTarget(t, "v2", "blockvolume-v2-after-write-kill") env.requireBlocksOf(t, "n-v2", w1) // every acknowledged write survived the kill - drive() + + // (3) completes w2 := ladderImage("c3kw2", []uint64{17, 44, 60}, 2) // not chunk 40: requireEdges keeps it untouched env.writeImage(t, "n-v2", w2) - - env.waitIndependent(t, "v2") - if !env.independent(t, "v2") { - t.Fatal("the restore status says independent but the marker is absent") - } + env.waitHydrated(t, "v2") env.requireImage(t, "n-v2", mergeImages(src, w1, w2)) env.restoreChecked(t, "base", "v3", src, w1, w2) } diff --git a/seaweed-block/cmd/blockvolume/snapshot_ladder_d_integration_test.go b/seaweed-block/cmd/blockvolume/snapshot_ladder_d_integration_test.go index f746773426..2738384ab8 100644 --- a/seaweed-block/cmd/blockvolume/snapshot_ladder_d_integration_test.go +++ b/seaweed-block/cmd/blockvolume/snapshot_ladder_d_integration_test.go @@ -37,7 +37,7 @@ const ( // deleteSnapshot deletes vol's snapshot name and checks the answer names it. func (env *handoffEnv) deleteSnapshot(t *testing.T, vol, name string) { t.Helper() - out, _ := env.h.command(t, "ops", "chunk", "snapshot-delete", "--volume", vol, "--name", name, + out, _ := env.h.command(t, "ops", "chunk", "snapshot-delete", "--master", env.h.masterAddr, "--volume", vol, "--name", name, "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) var body struct { VolumeID string `json:"volumeID"` @@ -67,7 +67,7 @@ func (env *handoffEnv) requireSnapshotNames(t *testing.T, vol string, names ...s func (env *handoffEnv) restoreChecked(t *testing.T, snap, target string, img map[uint64][]byte, later ...map[uint64][]byte) { t.Helper() env.restoreInto(t, "v1", snap, target) - env.waitIndependent(t, target) + env.waitHydrated(t, target) env.requireImage(t, "n-"+target, img, later...) } @@ -232,7 +232,7 @@ func (env *handoffEnv) gc(t *testing.T, apply bool) ([]gcObject, int) { // makes eligible for collection: the chunk bytes no other holder references. func (env *handoffEnv) exclusiveBytes(t *testing.T, vol, name string) uint64 { t.Helper() - out, _ := env.h.command(t, "ops", "chunk", "usage", "--volume", vol, + out, _ := env.h.command(t, "ops", "chunk", "usage", "--master", env.h.masterAddr, "--volume", vol, "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) var u struct { Snapshots []struct { diff --git a/seaweed-block/cmd/blockvolume/snapshot_ladder_f1_integration_test.go b/seaweed-block/cmd/blockvolume/snapshot_ladder_f1_integration_test.go index 09705b39e1..d2bfde4232 100644 --- a/seaweed-block/cmd/blockvolume/snapshot_ladder_f1_integration_test.go +++ b/seaweed-block/cmd/blockvolume/snapshot_ladder_f1_integration_test.go @@ -266,15 +266,13 @@ func f1StartSources(t *testing.T, env *handoffEnv, n int) []f1Volume { } // f1Restore restores snapshot snap of src into target (a new volume on the -// same server) and drives the restore; the target's blockvolume is stopped -// once verified (f1RunRound), so restores do not pile up processes. +// same server), which hydrates in the background; the target's blockvolume +// is stopped once verified (f1RunRound), so restores do not pile up processes. func f1Restore(t *testing.T, env *handoffEnv, src, snap, target string) *daemon { t.Helper() - b := env.hosts[target] - env.h.command(t, "ops", "chunk", "restore", "--source", src, "--snapshot", snap, "--target", target, + env.h.command(t, "ops", "chunk", "restore", "--master", env.h.masterAddr, "--source", src, "--snapshot", snap, "--target", target, "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) d := f1Up(t, env, target) - env.h.command(t, "ops", "chunk", "restore", "--volume", target, "--status-addr", b.status) return d } diff --git a/seaweed-block/cmd/blockvolume/snapshot_ladder_integration_test.go b/seaweed-block/cmd/blockvolume/snapshot_ladder_integration_test.go index 3354bd49fc..ca912b8e44 100644 --- a/seaweed-block/cmd/blockvolume/snapshot_ladder_integration_test.go +++ b/seaweed-block/cmd/blockvolume/snapshot_ladder_integration_test.go @@ -248,7 +248,7 @@ func (env *handoffEnv) snapshots(t *testing.T, vol, prefix string) []snapshotInf func (env *handoffEnv) restoreAttached(t *testing.T, src, snap, target string) { t.Helper() b := env.hosts["n-"+target] - env.h.command(t, "ops", "chunk", "restore", "--source", src, "--snapshot", snap, "--target", target, + env.h.command(t, "ops", "chunk", "restore", "--master", env.h.masterAddr, "--source", src, "--snapshot", snap, "--target", target, "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) d := env.h.start(t, "blockvolume-"+target, env.h.volume, env.volArgsFor(b)...) d.waitLog(t, 60*time.Second, fmt.Sprintf("blockvolume: volume %s adopted as PRIMARY at r1@", target)) @@ -418,14 +418,13 @@ func (env *handoffEnv) lastCutUploads(t *testing.T, hostID, vol string) int { func (env *handoffEnv) restoreInto(t *testing.T, src, snap, target string) { t.Helper() b := env.hosts["n-"+target] - env.h.command(t, "ops", "chunk", "restore", "--source", src, "--snapshot", snap, "--target", target, + env.h.command(t, "ops", "chunk", "restore", "--master", env.h.masterAddr, "--source", src, "--snapshot", snap, "--target", target, "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) d := env.h.start(t, "blockvolume-"+target, env.h.volume, env.volArgsFor(b)...) d.waitLog(t, 60*time.Second, fmt.Sprintf("blockvolume: volume %s adopted as PRIMARY at r1@", target)) poll(t, 60*time.Second, fmt.Sprintf("%s never reported its frontend ready", target), func() bool { return volumeFrontendReady(b.status, target) }) - env.h.command(t, "ops", "chunk", "restore", "--volume", target, "--status-addr", b.status) } // requireEdges reads, through the host, a block in a chunk no test writes and @@ -495,36 +494,23 @@ func volumeFrontendReady(statusAddr, vol string) bool { return frontendReady(b) } -// waitIndependent polls the restore status of target until the restore -// driver reports its phase independent (what the status says; it is not a -// separate measurement of which keys hold the chunks). 120 s bounds the -// observation: every query runs within what is left of it, and a success -// seen after it does not count. A query cancelled at the bound may take up -// to runCLI's 5 s WaitDelay more to clean up. -func (env *handoffEnv) waitIndependent(t *testing.T, target string) { +// waitHydrated waits until target holds every chunk its HEAD names locally +// (its chunk status shows none absent). A restored volume keeps its +// references to the source's snapshot; hydration only makes it read them +// locally. +func (env *handoffEnv) waitHydrated(t *testing.T, target string) { t.Helper() const bound = 120 * time.Second + b := env.hosts["n-"+target] end := time.Now().Add(bound) - ctx, cancel := context.WithDeadline(context.Background(), end) - defer cancel() - last := "" + last := -1 for time.Now().Before(end) { - out, errOut, code, err := runCLI(ctx, env.h, "ops", "chunk", "restore", "--volume", target, "--status-addr", env.hosts["n-"+target].status, "--status") - var st struct { - Phase string `json:"phase"` + if last = kzReadStats(t, b).AbsentChunks; last == 0 { + return } - if err == nil && code == 0 && json.Unmarshal([]byte(out), &st) == nil { - if st.Phase == "failed" { - t.Fatalf("restore of %s failed: %s", target, out) - } - if st.Phase == "independent" && time.Now().Before(end) { - return - } - } - last = out + errOut time.Sleep(200 * time.Millisecond) } - t.Fatalf("%s never became independent within %v; last status: %s", target, bound, last) + t.Fatalf("%s never hydrated within %v: %d chunks still absent", target, bound, last) } // runCLI runs sw-block under ctx and returns its output and exit status. It @@ -625,7 +611,7 @@ func TestSnapshotLadderC1FullRestore(t *testing.T) { later := mergeImages(ladderImage("c1later", []uint64{1, 20}, 8), ladderImage("c1new", []uint64{9, 33}, 3)) env.writeImage(t, "s1", later) env.restoreInto(t, "v1", "full", "v2") - env.waitIndependent(t, "v2") + env.waitHydrated(t, "v2") env.requireImage(t, "n-v2", img, later) } @@ -645,10 +631,10 @@ func TestSnapshotLadderC2IncrementalRestore(t *testing.T) { env.snapshot(t, "s1", "v1", "s3") env.restoreInto(t, "v1", "s2", "v2") - env.waitIndependent(t, "v2") + env.waitHydrated(t, "v2") env.requireImage(t, "n-v2", mergeImages(img1, img2), img3) // nothing written after s2, chunk 30 included env.restoreInto(t, "v1", "s3", "v3") - env.waitIndependent(t, "v3") + env.waitHydrated(t, "v3") env.requireImage(t, "n-v3", mergeImages(img1, img2, img3)) } @@ -667,7 +653,7 @@ func TestSnapshotLadderC3RestoreThenWriteThenSnapshotIt(t *testing.T) { env.writeImage(t, "s1", srcLater) env.restoreInto(t, "v1", "base", "v2") - env.waitIndependent(t, "v2") + env.waitHydrated(t, "v2") own := ladderImage("c3own", []uint64{3, 11}, 3) env.writeImage(t, "n-v2", own) env.snapshot(t, "n-v2", "v2", "mine") @@ -675,9 +661,9 @@ func TestSnapshotLadderC3RestoreThenWriteThenSnapshotIt(t *testing.T) { env.writeImage(t, "n-v2", ownLater) env.restoreInto(t, "v2", "mine", "v3") - env.waitIndependent(t, "v3") + env.waitHydrated(t, "v3") env.requireImage(t, "n-v3", mergeImages(src, own), ownLater, srcLater) env.restoreInto(t, "v1", "base", "v4") // the source's snapshot is unchanged - env.waitIndependent(t, "v4") + env.waitHydrated(t, "v4") env.requireImage(t, "n-v4", src, srcLater, own, ownLater) } diff --git a/seaweed-block/cmd/blockvolume/startup_systemd_filer_down_integration_test.go b/seaweed-block/cmd/blockvolume/startup_systemd_filer_down_integration_test.go index 28570b441d..20939e7f47 100644 --- a/seaweed-block/cmd/blockvolume/startup_systemd_filer_down_integration_test.go +++ b/seaweed-block/cmd/blockvolume/startup_systemd_filer_down_integration_test.go @@ -31,7 +31,7 @@ func TestSystemdFirstStartDuringAFilerOutageThenResetFailedServes(t *testing.T) t.Fatal("systemd qualification needs root") } env := startSourceWithSnapshot(t, "v2") - env.h.command(t, "ops", "chunk", "restore", "--source", "v1", "--snapshot", "s1", "--target", "v2", + env.h.command(t, "ops", "chunk", "restore", "--master", env.h.masterAddr, "--source", "v1", "--snapshot", "s1", "--target", "v2", "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) b := env.hosts["n-v2"] diff --git a/seaweed-block/cmd/blockvolume/template_retirement_integration_test.go b/seaweed-block/cmd/blockvolume/template_retirement_integration_test.go deleted file mode 100644 index c4da02ffb6..0000000000 --- a/seaweed-block/cmd/blockvolume/template_retirement_integration_test.go +++ /dev/null @@ -1,61 +0,0 @@ -//go:build subprocess && chunkstore_integration - -package main_test - -import ( - "testing" - "time" -) - -// TestProcedureRetireTemplateSource runs the template-holder procedure: -// fork the seed, publish the template on the holder, fork a consumer, then -// seal/revoke/ACK and delete the original source. No GC grace is advanced; -// the final ordinary pass proves its command and reads, not reclamation. -func TestProcedureRetireTemplateSource(t *testing.T) { - env := startHandoffEnvWith(t, 1, []string{"template-holder", "consumer"}) - env.volExtra = []string{"--chunk-capture-interval", "0", "--chunk-snapshot-schedule", "off"} - source := env.start(t, "blockvolume-source", "s1") - e := env.adopt(t, source, "s1") - const template = "template-holder" - want := map[uint64][]byte{5: pattern("template-seed!!!")} - env.writeBlock(t, "s1", 5, want[5]) - env.snapshot(t, "s1", "v1", "seed") - for _, step := range []struct{ source, snapshot, target string }{ - {"v1", "seed", template}, {template, "template-v1", "consumer"}, - } { - env.h.command(t, "ops", "chunk", "fork", "--source", step.source, "--snapshot", step.snapshot, - "--target", step.target, "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath, - "--request-id", "fork-"+step.target) - env.startTarget(t, step.target, "blockvolume-"+step.target) - env.requireBlocks(t, "n-"+step.target, 0, 16, want) - env.requireEdges(t, "n-"+step.target) - if step.target == template { - env.snapshot(t, "n-"+template, template, "template-v1") - } - } - g := env.seal(t, "s1", e) - env.revoke(t, e, g) - // The process must ACK and exit naturally; a signal would skip the ACK. - if err := source.wait(30 * time.Second); err != nil { - t.Fatalf("source did not exit naturally after revocation: %v", err) - } - env.waitAck(t, e, g) - env.deleteSnapshot(t, "v1", "seed") - out, stderr, code := env.volumeDelete(t, "delete-template-source") - requireDeleteCompleted(t, out, stderr, code, false) - env.requireDeletedForGood(t, "delete-template-source") - check := func() { - for _, vol := range []string{template, "consumer"} { - env.h.command(t, "ops", "chunk", "verify", "--volume", vol, "--all-snapshots", "--depth", "data", "--timeout", "2m", - "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) - env.requireBlocks(t, "n-"+vol, 0, 16, want) - env.requireEdges(t, "n-"+vol) - } - env.requireSnapshotNames(t, template, "template-v1") - } - check() - env.h.command(t, "ops", "chunk", "gc", "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath, - "--master", env.h.masterAddr, "--apply") - check() - t.Logf("template source retired; %s/template-v1 and consumer read unchanged after a default-grace GC pass", template) -} diff --git a/seaweed-block/cmd/blockvolume/testdata/headroom-small-fs.sh b/seaweed-block/cmd/blockvolume/testdata/headroom-small-fs.sh index 96553abf9f..75469bf5a9 100755 --- a/seaweed-block/cmd/blockvolume/testdata/headroom-small-fs.sh +++ b/seaweed-block/cmd/blockvolume/testdata/headroom-small-fs.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Small-file-system harness for TestHeadroomRefusesARestoreAndAForkTargetThenServesThem. +# Small-file-system harness for TestHeadroomRefusesRestoreTargetsThenServesThem. # Root only, on a disposable host; it formats only a loop device over a private # sparse file under WORKDIR. # @@ -16,7 +16,7 @@ # Example (from the repository root, as root): # mkdir /tmp/headroom && cmd/blockvolume/testdata/headroom-small-fs.sh /tmp/headroom -- \ # env CHUNKSTORE_WEED=/path/to/weed go test -count=1 -tags 'subprocess chunkstore_integration' \ -# -run '^TestHeadroomRefusesARestoreAndAForkTargetThenServesThem$' -timeout 15m ./cmd/blockvolume/ +# -run '^TestHeadroomRefusesRestoreTargetsThenServesThem$' -timeout 15m ./cmd/blockvolume/ set -euo pipefail [ "$(id -u)" = 0 ] || { echo "root required" >&2; exit 2; } work=$(realpath "${1:?existing empty work dir}") diff --git a/seaweed-block/cmd/blockvolume/wrong_geometry_cure_integration_test.go b/seaweed-block/cmd/blockvolume/wrong_geometry_cure_integration_test.go index 5e56b5656f..18a2bc5a1e 100644 --- a/seaweed-block/cmd/blockvolume/wrong_geometry_cure_integration_test.go +++ b/seaweed-block/cmd/blockvolume/wrong_geometry_cure_integration_test.go @@ -30,7 +30,7 @@ import ( // forbids removing those files. func TestWrongGeometryCureAsWritten(t *testing.T) { env := startSourceWithSnapshot(t, "v2") - env.h.command(t, "ops", "chunk", "restore", "--source", "v1", "--snapshot", "s1", "--target", "v2", + env.h.command(t, "ops", "chunk", "restore", "--master", env.h.masterAddr, "--source", "v1", "--snapshot", "s1", "--target", "v2", "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) plantStore(t, filepath.Join("testdata", "onezero-wrong-geometry-store.txt"), env.hosts["n-v2"].root) // The planted files are byte for byte the captured ones. diff --git a/seaweed-block/cmd/sw-block/integration_invocations_test.go b/seaweed-block/cmd/sw-block/integration_invocations_test.go new file mode 100644 index 0000000000..3ebd8239d6 --- /dev/null +++ b/seaweed-block/cmd/sw-block/integration_invocations_test.go @@ -0,0 +1,169 @@ +package main + +import ( + "bytes" + "go/ast" + "go/parser" + "go/token" + "os" + "path/filepath" + "strconv" + "strings" + "testing" + "time" +) + +// The process-level integration tests (cmd/blockvolume, behind build tags) +// call this command by argument list: they compile without these tags in +// CI, so an invocation the CLI no longer accepts (a removed subcommand, a +// renamed or newly required flag) would pass compile and fail only on a +// lab run. Every literal `ops ...` invocation in them is run through this +// CLI's own argument handling here. Variable values become placeholders and +// addresses point at nothing, so a call that gets past its arguments fails +// on the network or is still waiting at the deadline; only a refusal of the +// arguments themselves fails this test. +func TestIntegrationTestInvocationsParse(t *testing.T) { + invocations := literalOpsInvocations(t, filepath.Join("..", "blockvolume")) + if len(invocations) == 0 { + t.Fatal("no ops invocations found in the integration tests") + } + for _, inv := range invocations { + inv := inv + if len(inv.args) < 2 { + t.Fatalf("%s: an ops invocation without a subcommand", inv.where) + } + t.Run(inv.where, func(t *testing.T) { + var stdout, stderr bytes.Buffer + done := make(chan int, 1) + go func() { done <- run(inv.args, &stdout, &stderr) }() + select { + case <-done: + case <-time.After(3 * time.Second): + return // past its arguments: waiting on the network + } + out := stdout.String() + stderr.String() + if strings.Contains(out, "rpc error") || strings.Contains(out, "dial tcp") { + return // past its arguments: the placeholder address refused the call + } + for _, refusal := range []string{`"code":"bad_request"`, "unknown subcommand", "unknown command", "flag provided but not defined"} { + if strings.Contains(out, refusal) { + t.Fatalf("sw-block %s\nrefused its arguments: %s", strings.Join(inv.args, " "), firstLine(out, refusal)) + } + } + }) + } +} + +type opsInvocation struct { + where string + args []string +} + +// literalOpsInvocations returns every `.command(t, "ops", ...)` and +// `runCLI(ctx, h, "ops", ...)` call in +// dir's test files whose arguments are listed (not spread from a slice), +// with each non-literal argument replaced by a placeholder for its flag. +func literalOpsInvocations(t *testing.T, dir string) []opsInvocation { + t.Helper() + files, err := filepath.Glob(filepath.Join(dir, "*_test.go")) + if err != nil { + t.Fatal(err) + } + var out []opsInvocation + fset := token.NewFileSet() + for _, f := range files { + src, err := os.ReadFile(f) + if err != nil { + t.Fatal(err) + } + file, err := parser.ParseFile(fset, f, src, 0) + if err != nil { + t.Fatal(err) + } + ast.Inspect(file, func(n ast.Node) bool { + call, ok := n.(*ast.CallExpr) + if !ok || call.Ellipsis != token.NoPos || len(call.Args) < 2 { + return true + } + from := opsArg(call) + if from < 0 { + return true + } + var args []string + for _, a := range call.Args[from:] { + if v := literal(a); v != "" || isStringLit(a) { + args = append(args, v) + continue + } + args = append(args, placeholder(args, len(args))) + } + pos := fset.Position(call.Pos()) + out = append(out, opsInvocation{where: filepath.Base(pos.Filename) + ":" + strconv.Itoa(pos.Line), args: args}) + return true + }) + } + return out +} + +// opsArg is the index of the literal "ops" that starts the CLI argument +// list of a harness call: x.command(t, "ops", ...) or runCLI(ctx, h, "ops", +// ...); -1 for any other call. +func opsArg(call *ast.CallExpr) int { + name := "" + switch f := call.Fun.(type) { + case *ast.SelectorExpr: + name = f.Sel.Name + case *ast.Ident: + name = f.Name + } + at := map[string]int{"command": 1, "runCLI": 2}[name] + if at == 0 || len(call.Args) <= at || literal(call.Args[at]) != "ops" { + return -1 + } + return at +} + +func isStringLit(e ast.Expr) bool { + b, ok := e.(*ast.BasicLit) + return ok && b.Kind == token.STRING +} + +func literal(e ast.Expr) string { + b, ok := e.(*ast.BasicLit) + if !ok || b.Kind != token.STRING { + return "" + } + v, err := strconv.Unquote(b.Value) + if err != nil { + return "" + } + return v +} + +// placeholder is a value of the kind the preceding flag takes: an address +// nothing listens on, a number, a duration, or a name. +func placeholder(prev []string, at int) string { + name := "x" + strconv.Itoa(at) // distinct, so two variables never compare equal + if len(prev) == 0 { + return name + } + flag := strings.TrimLeft(prev[len(prev)-1], "-") + switch { + case strings.Contains(flag, "timeout") || strings.Contains(flag, "interval") || strings.Contains(flag, "wait"): + return "1s" + case strings.Contains(flag, "lsn") || strings.Contains(flag, "epoch") || strings.Contains(flag, "count") || strings.Contains(flag, "bytes") || strings.Contains(flag, "size"): + return "1" + case strings.Contains(flag, "master") || strings.Contains(flag, "addr") || strings.Contains(flag, "filer") || strings.Contains(flag, "data") || strings.Contains(flag, "ctrl") || strings.Contains(flag, "endpoint"): + return "127.0.0.1:1" + } + return name +} + +func firstLine(out, near string) string { + for _, l := range strings.Split(out, "\n") { + if strings.Contains(l, near) { + return l + } + } + return out +} diff --git a/seaweed-block/docs/operator-guide.md b/seaweed-block/docs/operator-guide.md index 6689fed28e..8be9ead7d3 100644 --- a/seaweed-block/docs/operator-guide.md +++ b/seaweed-block/docs/operator-guide.md @@ -290,7 +290,7 @@ Every command on the pages above, and the test that runs it. | `blockvolume` under systemd: exit 75 after an expired start, restart, re-grant | `TestSystemdExpiredStartupExits75ThenRegrantServes` (`cmd/blockvolume`, a real systemd manager, tag `systemd_integration`) | binary | | The shipped units' start limits (`StartLimitIntervalSec=600`, `StartLimitBurst=10`, `RestartPreventExitStatus=78`) | `TestBlockvolumeUnitsBoundStartupRetries` (`internal/testops`, reads the unit files) | unit files | | `systemctl enable`, `stop`, `disable`, `reset-failed`, `systemd-tmpfiles --create` as written on these pages | not run: the tests above start transient units, not the installed ones | not run | -| Headroom refusal at create, and both ways out (free space; `--durable-root` on a file system with room) | `TestHeadroomRefusesARestoreAndAForkTargetThenServesThem`, `TestHeadroomRefusedTargetBlastRadiusAndAnotherRoot`, `TestHeadroomRefusedRestoreTargetSurvivesItsSourceDeleteAndGC` (`cmd/blockvolume`, root, loop-mounted file systems) | binary | +| Headroom refusal at create, and both ways out (free space; `--durable-root` on a file system with room) | `TestHeadroomRefusesRestoreTargetsThenServesThem`, `TestHeadroomRefusedTargetBlastRadiusAndAnotherRoot`, `TestHeadroomRefusedRestoreTargetSurvivesItsSourceDeleteAndGC` (`cmd/blockvolume`, root, loop-mounted file systems) | binary | | A snapshot refused with `host_slot_busy` / `no background slot` while every host slot is held, retried with the same request id | `TestSnapshotLadderF1VolumesOneHost` (`cmd/blockvolume`, `F1_RUN=1`, `F1_HOST_LIMIT_DIR` set, 3 slots; `F1_SLOT_RETRY_SECONDS=0` is its negative control) | binary | | Full local disk; full `--host-limit-dir` | `TestProcedureLocalDiskFull` (`cmd/blockvolume`, root, `testdata/diskfull.sh`); what a Linux guest sees: `TestProcedureLocalDiskFullKernelInitiator` (kernel NVMe/TCP host) | binary | | A first start with the wrong `--durable-blocks`: refused before any local store is created (exit 78) | `TestWrongGeometryFlagIsRefusedBeforeTheStoreIsCreated` (`cmd/blockvolume`) | binary |