mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 18:47:20 +01:00
test: triage of the tagged run: --master, exit 78, the cleaning pass
- ops chunk show and snapshots built as argument slices get --master;
the guard now also checks []string{"ops", ...} literals.
- A returning old host after a forced move exits 78 with reason=moved
(the master's typed MOVED refusal), as the product documents.
- TestProcedureStartTooEarlyExitsAndARestartServes is retired: a start
before the barrier now waits through it and is re-granted, which
TestProcedureStartInsideTheBarrierWaitIsReGranted covers.
- ops chunk gc is gone: D4 deletes through the holder, whose cleaning
pass removes exactly the deleted snapshot's chunks from the pool; the
headroom test asserts the source snapshot of a waiting restore target
cannot be deleted and keeps its chunks.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1e1d1f3628
commit
cbe25d20f9
5 files changed
+127
-378
No files matched your search
@@ -3,6 +3,7 @@
|
||||
package main_test
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -82,17 +83,16 @@ func TestHeadroomRefusedTargetBlastRadiusAndAnotherRoot(t *testing.T) {
|
||||
requireDeleteCompleted(t, out, errOut, code, false)
|
||||
}
|
||||
|
||||
// TestHeadroomRefusedRestoreTargetSurvivesItsSourceDeleteAndGC: a restore
|
||||
// target (v2) refused for local headroom has never hydrated, so its HEAD
|
||||
// names its source's chunks. While it waits, the source's snapshot is
|
||||
// deleted and then the source volume (seal, revoke, ACK, volume-delete), and
|
||||
// the collector runs two applying passes a grace apart (its shortest grace;
|
||||
// about 25 minutes). Then space is freed and v2 starts: it must read back
|
||||
// the snapshot exactly, at once and again after its restore reaches
|
||||
// independence. A read that differs or reads zero is a data-loss path and
|
||||
// fails the test as such; a target that refuses to start fails with its
|
||||
// reason.
|
||||
func TestHeadroomRefusedRestoreTargetSurvivesItsSourceDeleteAndGC(t *testing.T) {
|
||||
// TestHeadroomRefusedRestoreTargetKeepsItsSourceSnapshot: a restore target
|
||||
// (v2) refused for local headroom has never read a chunk, so its HEAD names
|
||||
// its source's chunks. While it waits, its source snapshot cannot go: the
|
||||
// delete through the source's holder (whose cleaning pass would collect the
|
||||
// snapshot's chunks) is refused because v2 depends on it, and the source's
|
||||
// pool keeps every chunk. Then space is freed and v2 starts: it must read
|
||||
// back the snapshot exactly, at once and again after every chunk is made
|
||||
// local. A read that differs or reads zero is a data-loss path and fails the
|
||||
// test as such; a target that refuses to start fails with its reason.
|
||||
func TestHeadroomRefusedRestoreTargetKeepsItsSourceSnapshot(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")
|
||||
@@ -101,13 +101,12 @@ func TestHeadroomRefusedRestoreTargetSurvivesItsSourceDeleteAndGC(t *testing.T)
|
||||
if free := freeBytes(t, small); free >= need {
|
||||
t.Fatalf("the small file system has %d bytes free, not less than the %d a volume needs: fix the runner", free, need)
|
||||
}
|
||||
requireBudget(t, 2*ladderGCWait+10*time.Minute)
|
||||
t.Cleanup(func() { _ = os.RemoveAll(filepath.Join(small, t.Name())) })
|
||||
|
||||
env := startHandoffEnvWith(t, 1, []string{"v2"})
|
||||
env.volExtra = []string{"--chunk-capture-interval", "0", "--chunk-snapshot-schedule", "off"}
|
||||
src := env.start(t, "blockvolume-v1", "s1")
|
||||
e := env.adopt(t, src, "s1")
|
||||
env.adopt(t, src, "s1")
|
||||
b2 := env.hosts["n-v2"]
|
||||
b2.root = filepath.Join(small, t.Name(), "vol-n-v2")
|
||||
env.hosts["n-v2"] = b2
|
||||
@@ -121,30 +120,17 @@ func TestHeadroomRefusedRestoreTargetSurvivesItsSourceDeleteAndGC(t *testing.T)
|
||||
"--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath)
|
||||
env.refusedForHeadroom(t, "v2", "blockvolume-v2-no-room")
|
||||
|
||||
// The source goes: its snapshot, then the volume, by the documented steps.
|
||||
env.deleteSnapshot(t, "v1", "base")
|
||||
g := env.seal(t, "s1", e)
|
||||
env.revoke(t, e, g)
|
||||
if err := src.wait(30 * time.Second); err != nil {
|
||||
t.Fatalf("s1 after the revocation: %v; want a clean exit by itself", err)
|
||||
// The source snapshot stays while v2 depends on it.
|
||||
stored := env.poolObjects(t, "v1")
|
||||
code, out := env.holderDeleteSnapshot(t, "s1", "v1", "base")
|
||||
if code == http.StatusOK || !strings.Contains(out, "dependents") {
|
||||
t.Fatalf("holder delete of the snapshot v2 depends on: status %d %s; want it refused (dependents)", code, out)
|
||||
}
|
||||
env.waitAck(t, e, g)
|
||||
out, errOut, code := env.volumeDelete(t, "del-v1")
|
||||
requireDeleteCompleted(t, out, errOut, code, false)
|
||||
deleted := time.Now()
|
||||
|
||||
// Two collector passes a grace apart.
|
||||
requireBudget(t, time.Until(deleted.Add(ladderGCWait))+ladderGCWait+5*time.Minute)
|
||||
time.Sleep(time.Until(deleted.Add(ladderGCWait)))
|
||||
objs1, n1 := env.gc(t, true)
|
||||
first := time.Now()
|
||||
requireBudget(t, ladderGCWait+5*time.Minute)
|
||||
time.Sleep(time.Until(first.Add(ladderGCWait)))
|
||||
objs2, n2 := env.gc(t, true)
|
||||
for _, o := range append(objs1, objs2...) {
|
||||
t.Logf("GC reclaimed %s %s (fid %s)", o.Volume, o.Key, o.FID)
|
||||
env.requireSnapshotNames(t, "v1", "base")
|
||||
time.Sleep(5 * time.Second) // a cleaning pass, had one run, ends well inside this
|
||||
if got := env.poolObjects(t, "v1"); got != stored {
|
||||
t.Fatalf("the source pool held %d chunk objects before the refused delete and %d after; want them all kept", stored, got)
|
||||
}
|
||||
t.Logf("GC: first pass reclaimed %d, second %d", n1, n2)
|
||||
|
||||
// The refused target, now with room, must read the snapshot exactly.
|
||||
if err := os.Remove(filler); err != nil {
|
||||
@@ -155,16 +141,16 @@ func TestHeadroomRefusedRestoreTargetSurvivesItsSourceDeleteAndGC(t *testing.T)
|
||||
for end := time.Now().Add(60 * time.Second); time.Now().Before(end) && !adopted; time.Sleep(200 * time.Millisecond) {
|
||||
select {
|
||||
case <-d2.done:
|
||||
t.Fatalf("v2 refused to start after its source was deleted and collected: %v; %q", d2.err, strings.TrimSpace(d2.line("blockvolume:")))
|
||||
t.Fatalf("v2 refused to start: %v; %q", d2.err, strings.TrimSpace(d2.line("blockvolume:")))
|
||||
default:
|
||||
}
|
||||
adopted = d2.has("blockvolume: volume v2 adopted as PRIMARY at r1@")
|
||||
}
|
||||
if !adopted {
|
||||
t.Fatal("v2 never adopted after its source was deleted and collected")
|
||||
t.Fatal("v2 never adopted once it had room")
|
||||
}
|
||||
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")
|
||||
requireImageExact(t, env, "n-v2", img, "after the refused delete of its source snapshot")
|
||||
env.hydrate(t, "v2")
|
||||
requireImageExact(t, env, "n-v2", img, "after it was read in full (hydrated)")
|
||||
}
|
||||
|
||||
@@ -195,19 +195,21 @@ func TestProcedureForcedMoveWithTheOldHostReturning(t *testing.T) {
|
||||
t.Fatal("the block written after the last cut reads back on s2; the page says it is lost")
|
||||
}
|
||||
|
||||
// The old host returns with its old local root, and the example unit
|
||||
// (Restart=on-failure, RestartSec=5s) starts it again after it exits,
|
||||
// until its start limit. Each time it must not take s2's line as its own
|
||||
// (a holder is server and replica), report its frontend ready or listen
|
||||
// for I/O; it logs a refusal and exits with status 75.
|
||||
back := env.oldHostRefuses(t, "blockvolume-s1-back", env.hosts["s1"], e2, 75)
|
||||
time.Sleep(5 * time.Second) // RestartSec of the example unit
|
||||
again := env.oldHostRefuses(t, "blockvolume-s1-restarted", env.hosts["s1"], e2, 75)
|
||||
// Control: on a fresh local root there is no stale root, so its refusal
|
||||
// is the identity check alone; it also exits 75.
|
||||
// The old host returns with its old local root. blockmaster refuses its
|
||||
// lease with a typed MOVED (the volume moved to s2 at a newer epoch), so
|
||||
// it exits 78, which the example unit does not restart
|
||||
// (RestartPreventExitStatus=78); an operator's start again ends the same
|
||||
// way. Each time it must not take s2's line as its own (a holder is server
|
||||
// and replica), report its frontend ready or listen for I/O; it logs
|
||||
// `exiting status=78 reason=moved`.
|
||||
back := env.oldHostRefuses(t, "blockvolume-s1-back", env.hosts["s1"], e2, 78)
|
||||
time.Sleep(5 * time.Second)
|
||||
again := env.oldHostRefuses(t, "blockvolume-s1-restarted", env.hosts["s1"], e2, 78)
|
||||
// Control: on a fresh local root there is no stale root; the master's
|
||||
// MOVED refusal alone ends it, also with status 78.
|
||||
fresh := env.hosts["s1"]
|
||||
fresh.root = fresh.root + "-fresh"
|
||||
freshRoot := env.oldHostRefuses(t, "blockvolume-s1-fresh-root", fresh, e2, 75)
|
||||
freshRoot := env.oldHostRefuses(t, "blockvolume-s1-fresh-root", fresh, e2, 78)
|
||||
// A line carries its owner and that owner's endpoints: every line
|
||||
// delivered at the forced epoch, to the new owner and to each returning
|
||||
// old host alike, carries s2's own endpoints, never another host's.
|
||||
@@ -308,65 +310,6 @@ func TestProcedureStartInsideTheBarrierWaitIsReGranted(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestProcedureStartTooEarlyExitsAndARestartServes: with
|
||||
// --workspace-max-clock-skew 50s the barrier is at most 95 s after the stop.
|
||||
// A holder started 31 s after the stop ends its 30 s authority wait before
|
||||
// the barrier: it does not serve and exits with status 75, so a supervisor
|
||||
// (Restart=on-failure, RestartSec=5s) starts it again; a start that waits
|
||||
// past the barrier is re-granted and serves at the same epoch.
|
||||
func TestProcedureStartTooEarlyExitsAndARestartServes(t *testing.T) {
|
||||
env := startHandoffEnv(t, 1, "--workspace-max-clock-skew", "50s")
|
||||
first := env.start(t, "blockvolume-s1", "s1")
|
||||
e := env.adopt(t, first, "s1")
|
||||
block := pattern("start-too-early!")
|
||||
env.writeBlock(t, "s1", 0, block)
|
||||
first.kill(t)
|
||||
time.Sleep(31 * time.Second)
|
||||
|
||||
// Attempt 2 starts about 66 s after the stop and its wait ends about
|
||||
// 96 s after it, against a barrier of at most 95 s, so attempt 2 normally
|
||||
// serves; up to 4 attempts allow for scheduling on a loaded host.
|
||||
for attempt := 1; ; attempt++ {
|
||||
d := env.start(t, fmt.Sprintf("blockvolume-s1-try%d", attempt), "s1")
|
||||
served := false
|
||||
end := time.Now().Add(45 * time.Second)
|
||||
for time.Now().Before(end) {
|
||||
if env.servingNow("s1") {
|
||||
served = true
|
||||
break
|
||||
}
|
||||
select {
|
||||
case <-d.done:
|
||||
end = time.Now()
|
||||
default:
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
if served {
|
||||
if attempt == 1 {
|
||||
t.Fatal("started before the barrier with its wait ending first, the holder served")
|
||||
}
|
||||
if got := env.adopt(t, d, "s1"); got != e {
|
||||
t.Fatalf("attempt %d adopted epoch %d; want the same epoch %d", attempt, got, e)
|
||||
}
|
||||
break
|
||||
}
|
||||
if err := d.wait(5 * time.Second); exitCode(err) != 75 {
|
||||
t.Fatalf("attempt %d did not serve and did not exit 75: %v", attempt, err)
|
||||
}
|
||||
if !d.has("blockvolume: exiting status=75 reason=assignment_timeout") {
|
||||
t.Fatalf("attempt %d exited 75 without the reason assignment_timeout", attempt)
|
||||
}
|
||||
if attempt == 4 {
|
||||
t.Fatal("four supervised starts never served")
|
||||
}
|
||||
time.Sleep(5 * time.Second)
|
||||
}
|
||||
if !bytes.Equal(env.readBlock(t, "s1", 0), block) {
|
||||
t.Fatal("the block written before the stop does not read back")
|
||||
}
|
||||
}
|
||||
|
||||
// lastLogTime is the time of the last log line containing s (second
|
||||
// resolution, the log's local time), or zero.
|
||||
func lastLogTime(d *daemon, s string) time.Time {
|
||||
@@ -422,7 +365,10 @@ func (env *handoffEnv) oldHostRefuses(t *testing.T, name string, b bvHost, e2 ui
|
||||
if err := d.wait(5 * time.Second); exitCode(err) != wantExit {
|
||||
failures = append(failures, fmt.Sprintf("it did not exit with status %d: %v", wantExit, err))
|
||||
}
|
||||
if !d.has("refusing to attach volume=v1") && !d.has("workspace lease: stale authority") && !d.has("foreign assignment") {
|
||||
if wantExit == 78 && !d.has("exiting status=78 reason=moved") {
|
||||
failures = append(failures, "it did not log `exiting status=78 reason=moved`")
|
||||
}
|
||||
if wantExit != 78 && !d.has("refusing to attach volume=v1") && !d.has("workspace lease: stale authority") && !d.has("foreign assignment") {
|
||||
failures = append(failures, "it logged no refusal (stale root, stale authority, or another server's assignment)")
|
||||
}
|
||||
if len(failures) > 0 {
|
||||
@@ -511,7 +457,7 @@ func (env *handoffEnv) seal(t *testing.T, id string, e uint64) uint64 {
|
||||
}
|
||||
|
||||
func (env *handoffEnv) chunkShow() []string {
|
||||
return []string{"ops", "chunk", "show", "--volume", "v1", "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath}
|
||||
return []string{"ops", "chunk", "show", "--master", env.h.masterAddr, "--volume", "v1", "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath}
|
||||
}
|
||||
|
||||
func (env *handoffEnv) sealedLSN(t *testing.T, e, g uint64) uint64 {
|
||||
|
||||
@@ -7,11 +7,12 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/layout"
|
||||
)
|
||||
|
||||
// Rung D of the snapshot ladder: deletes. D1-D3 are the logical delete: a
|
||||
@@ -21,19 +22,6 @@ import (
|
||||
// name), so they prove nothing about reclamation. D4 runs the collector and
|
||||
// measures what it reclaims.
|
||||
//
|
||||
// The collector's grace may not be shorter than the operation deadline plus
|
||||
// the clock skew plus the CAS apply bound (11 minutes with the defaults), and
|
||||
// an unreferenced chunk is reclaimed only by a second mark at least the grace
|
||||
// after the first, on a chunk older than the grace: D4 runs for about 25
|
||||
// minutes.
|
||||
|
||||
const (
|
||||
ladderGCGrace = 11 * time.Minute
|
||||
// ladderGCWait is the grace plus the collector's clock skew allowance
|
||||
// and its one-second timestamp resolution, with a margin.
|
||||
ladderGCWait = ladderGCGrace + time.Minute + 15*time.Second
|
||||
)
|
||||
|
||||
// deleteSnapshot deletes vol's snapshot name and checks the answer names it.
|
||||
func (env *handoffEnv) deleteSnapshot(t *testing.T, vol, name string) {
|
||||
t.Helper()
|
||||
@@ -48,6 +36,39 @@ func (env *handoffEnv) deleteSnapshot(t *testing.T, vol, name string) {
|
||||
}
|
||||
}
|
||||
|
||||
// holderDeleteSnapshot deletes vol's snapshot name through its holder's
|
||||
// control route (POST /chunk/snapshot/delete on hostID's status listener),
|
||||
// which runs the holder's cleaning pass right after the delete. It returns
|
||||
// the HTTP status and body.
|
||||
func (env *handoffEnv) holderDeleteSnapshot(t *testing.T, hostID, vol, name string) (int, string) {
|
||||
t.Helper()
|
||||
body, _ := json.Marshal(map[string]string{"volumeID": vol, "name": name})
|
||||
c := &http.Client{Timeout: 2 * time.Minute}
|
||||
resp, err := c.Post("http://"+env.hosts[hostID].status+"/chunk/snapshot/delete", "application/json", strings.NewReader(string(body)))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
out, _ := io.ReadAll(io.LimitReader(resp.Body, 1<<20))
|
||||
return resp.StatusCode, string(out)
|
||||
}
|
||||
|
||||
// poolObjects counts the chunk objects in vol's pool (every shard
|
||||
// directory): what the volume stores, whatever names it.
|
||||
func (env *handoffEnv) poolObjects(t *testing.T, vol string) int {
|
||||
t.Helper()
|
||||
id, err := layout.ParseVolumeID(env.layoutID(vol))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
pool := path.Join(env.chunkPath, layout.VolumeDir(vol, id), layout.PoolDir)
|
||||
n := 0
|
||||
for shard := range env.filerNames(t, pool) {
|
||||
n += len(env.filerNames(t, path.Join(pool, shard)))
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
// requireSnapshotNames checks vol's snapshot list is exactly names, in order.
|
||||
func (env *handoffEnv) requireSnapshotNames(t *testing.T, vol string, names ...string) {
|
||||
t.Helper()
|
||||
@@ -130,261 +151,44 @@ func TestSnapshotLadderD3DeleteWhenContentRecurs(t *testing.T) {
|
||||
env.restoreChecked(t, "s2", "v3", map[uint64][]byte{7: b})
|
||||
}
|
||||
|
||||
// gcObject is one chunk object a collector pass names as eligible.
|
||||
type gcObject struct {
|
||||
Volume string `json:"volume"`
|
||||
Key string `json:"key"`
|
||||
FID string `json:"fid"`
|
||||
}
|
||||
|
||||
// chunkKeys lists the names (unescaped) of v1's chunk-key bindings, read
|
||||
// straight from the filer's directory listing, not through the collector.
|
||||
func (env *handoffEnv) chunkKeys(t *testing.T, vol string) map[string]bool {
|
||||
t.Helper()
|
||||
c := &http.Client{Timeout: 10 * time.Second}
|
||||
dir := path.Join(env.chunkPath, vol, "keys") + "/"
|
||||
keys := map[string]bool{}
|
||||
for last := ""; ; {
|
||||
req, _ := http.NewRequest("GET", "http://"+env.cluster.filerHTTP+dir+"?limit=1000&lastFileName="+url.QueryEscape(last), nil)
|
||||
req.Header.Set("Accept", "application/json")
|
||||
resp, err := c.Do(req)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var page struct {
|
||||
Entries []struct {
|
||||
FullPath string `json:"FullPath"`
|
||||
} `json:"Entries"`
|
||||
LastFileName string `json:"LastFileName"`
|
||||
ShouldDisplayLoadMore bool `json:"ShouldDisplayLoadMore"`
|
||||
}
|
||||
err = json.NewDecoder(resp.Body).Decode(&page)
|
||||
resp.Body.Close()
|
||||
if err != nil || resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("filer listing of %s: status %d %v", dir, resp.StatusCode, err)
|
||||
}
|
||||
for _, e := range page.Entries {
|
||||
name, err := url.PathUnescape(path.Base(e.FullPath))
|
||||
if err != nil {
|
||||
t.Fatalf("chunk key %q: %v", e.FullPath, err)
|
||||
}
|
||||
keys[name] = true
|
||||
}
|
||||
if !page.ShouldDisplayLoadMore || page.LastFileName == "" || page.LastFileName == last {
|
||||
return keys
|
||||
}
|
||||
last = page.LastFileName
|
||||
}
|
||||
}
|
||||
|
||||
// objectsByKey indexes collector objects by key and counts the records that
|
||||
// are not distinct v1 chunk objects (another volume, an empty field, or a
|
||||
// key or fid named again).
|
||||
func objectsByKey(objs []gcObject) (map[string]gcObject, int) {
|
||||
byKey, fids, odd := map[string]gcObject{}, map[string]bool{}, 0
|
||||
for _, o := range objs {
|
||||
_, dup := byKey[o.Key]
|
||||
if o.Volume != "v1" || o.Key == "" || o.FID == "" || fids[o.FID] || dup {
|
||||
odd++
|
||||
continue
|
||||
}
|
||||
byKey[o.Key], fids[o.FID] = o, true
|
||||
}
|
||||
return byKey, odd
|
||||
}
|
||||
|
||||
// requireBudget fails the test before it starts anything when the test
|
||||
// binary's deadline leaves less than need: a wait cut short by the package
|
||||
// timeout would skip the harness's cleanup.
|
||||
func requireBudget(t *testing.T, need time.Duration) {
|
||||
t.Helper()
|
||||
if dl, ok := t.Deadline(); ok && time.Until(dl) < need {
|
||||
t.Fatalf("this test needs %v; the test deadline leaves %v (run with -timeout 45m)", need, time.Until(dl).Round(time.Second))
|
||||
}
|
||||
}
|
||||
|
||||
// gc runs one collector pass (applying or a preview) and returns the chunk
|
||||
// objects it found eligible and how many it reclaimed.
|
||||
func (env *handoffEnv) gc(t *testing.T, apply bool) ([]gcObject, int) {
|
||||
t.Helper()
|
||||
args := []string{"ops", "chunk", "gc", "--master", env.h.masterAddr, "--grace", ladderGCGrace.String(),
|
||||
"--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath}
|
||||
if apply {
|
||||
args = append(args, "--apply")
|
||||
}
|
||||
out, _ := env.h.command(t, args...)
|
||||
var body struct {
|
||||
MarkSaved bool `json:"mark_saved"`
|
||||
UnknownOutcomes []string `json:"unknown_outcomes"`
|
||||
FailedDeletes []any `json:"failed_deletes"`
|
||||
WouldDelete []gcObject `json:"would_delete"`
|
||||
Candidates int
|
||||
Reclaimed int
|
||||
}
|
||||
if err := json.Unmarshal([]byte(out), &body); err != nil || (apply && !body.MarkSaved) || len(body.UnknownOutcomes) != 0 || len(body.FailedDeletes) != 0 {
|
||||
t.Fatalf("gc pass (apply %v): %v\n%s", apply, err, out)
|
||||
}
|
||||
t.Logf("gc pass (apply %v): %d candidates, %d eligible, %d reclaimed", apply, body.Candidates, len(body.WouldDelete), body.Reclaimed)
|
||||
return body.WouldDelete, body.Reclaimed
|
||||
}
|
||||
|
||||
// exclusiveBytes is what the usage command says deleting snapshot name of vol
|
||||
// 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", "--master", env.h.masterAddr, "--volume", vol,
|
||||
"--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath)
|
||||
var u struct {
|
||||
Snapshots []struct {
|
||||
Name string `json:"name"`
|
||||
ExclusiveBytes uint64 `json:"exclusiveBytes"`
|
||||
} `json:"snapshots"`
|
||||
}
|
||||
if err := json.Unmarshal([]byte(out), &u); err != nil {
|
||||
t.Fatalf("usage of %s: %v\n%s", vol, err, out)
|
||||
}
|
||||
for _, s := range u.Snapshots {
|
||||
if s.Name == name {
|
||||
return s.ExclusiveBytes
|
||||
}
|
||||
}
|
||||
t.Fatalf("usage of %s has no snapshot %s\n%s", vol, name, out)
|
||||
return 0
|
||||
}
|
||||
|
||||
// blobStored reports whether the weed store still holds the chunk data of
|
||||
// fid (a volume server answers 200 for it, 404 once it is deleted).
|
||||
func (env *handoffEnv) blobStored(t *testing.T, fid string) bool {
|
||||
t.Helper()
|
||||
c := &http.Client{Timeout: 10 * time.Second}
|
||||
vid, _, ok := strings.Cut(fid, ",")
|
||||
if !ok {
|
||||
t.Fatalf("chunk object fid %q has no volume id", fid)
|
||||
}
|
||||
resp, err := c.Get("http://" + env.cluster.master + "/dir/lookup?volumeId=" + vid)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var lookup struct {
|
||||
Locations []struct {
|
||||
URL string `json:"url"`
|
||||
} `json:"locations"`
|
||||
}
|
||||
err = json.NewDecoder(resp.Body).Decode(&lookup)
|
||||
resp.Body.Close()
|
||||
if err != nil || len(lookup.Locations) == 0 {
|
||||
t.Fatalf("weed lookup of volume %s: %v %+v", vid, err, lookup)
|
||||
}
|
||||
resp, err = c.Get("http://" + lookup.Locations[0].URL + "/" + fid)
|
||||
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("weed read of %s: status %d", fid, resp.StatusCode)
|
||||
return false
|
||||
}
|
||||
|
||||
// TestSnapshotLadderD4DeleteAllButOneThenCollect is a MEASUREMENT, not a
|
||||
// pass/fail rung: what the collector reclaims after deletes, against an
|
||||
// expected set taken independently of it. Three snapshots, each overwriting
|
||||
// the same four chunks; the third and then the second are deleted. The
|
||||
// third's chunks are still HEAD's, so the bindings the second's cut created
|
||||
// (those that appear in the filer between the first and the second
|
||||
// snapshot) are referenced by nothing. Two collector passes the grace apart
|
||||
// run; the test reports, in one MEASUREMENT line, how many of the expected
|
||||
// bindings a preview names and the applying pass reclaims, how many of
|
||||
// those are gone from the weed store, what else either pass named, and the
|
||||
// surplus left. It fails only when the harness cannot measure (the setup
|
||||
// did not create the expected bindings, a command failed) or when data is
|
||||
// lost: HEAD must still read the newest content and the remaining snapshot
|
||||
// restore as it was.
|
||||
//
|
||||
// What is measured is chunk data in the weed store for the bindings the
|
||||
// deleted snapshot alone created, not filer entries and not the whole store.
|
||||
// The known surplus of today's format, not measured:
|
||||
// - a reclaimed binding's filer entry is kept for ever (marked reclaimed),
|
||||
// so filer entry counts and usage's stored bindings and stored bytes do
|
||||
// not fall after collection;
|
||||
// - a needle uploaded before its binding was written (a retried upload)
|
||||
// cannot be enumerated and is never reclaimed;
|
||||
// - disk space returns only when weed compacts its volume.
|
||||
// TestSnapshotLadderD4DeleteAllButOneThenCollect: three snapshots, each
|
||||
// overwriting the same four chunks; the third and then the second are
|
||||
// deleted through the holder, whose cleaning pass runs right after each
|
||||
// delete. The third's chunks are still HEAD's, so deleting it frees nothing;
|
||||
// the second's four chunks are named by nothing after its delete, and the
|
||||
// cleaning removes exactly those from the pool. No data is lost: HEAD reads
|
||||
// the newest content and the remaining snapshot restores as it was.
|
||||
func TestSnapshotLadderD4DeleteAllButOneThenCollect(t *testing.T) {
|
||||
requireBudget(t, 2*ladderGCWait+10*time.Minute)
|
||||
env := startLadderEnv(t, "v2")
|
||||
chunks := []uint64{0, 1, 2, 3}
|
||||
imgs := []map[uint64][]byte{ladderImage("d4one", chunks, 4), ladderImage("d4two", chunks, 4), ladderImage("d4three", chunks, 4)}
|
||||
uploads := make([]int, len(imgs))
|
||||
keysAfter := make([]map[string]bool, len(imgs))
|
||||
for i, img := range imgs {
|
||||
env.writeImage(t, "s1", img)
|
||||
env.snapshot(t, "s1", "v1", fmt.Sprintf("s%d", i+1))
|
||||
uploads[i] = env.lastCutUploads(t, "s1", "v1")
|
||||
keysAfter[i] = env.chunkKeys(t, "v1")
|
||||
}
|
||||
expected := map[string]bool{} // the bindings the second snapshot's cut created
|
||||
for k := range keysAfter[1] {
|
||||
if !keysAfter[0][k] {
|
||||
expected[k] = true
|
||||
stored := env.poolObjects(t, "v1")
|
||||
t.Logf("after three snapshots the pool holds %d chunk objects", stored)
|
||||
|
||||
collect := func(name string, freed int) {
|
||||
t.Helper()
|
||||
if code, out := env.holderDeleteSnapshot(t, "s1", "v1", name); code != http.StatusOK {
|
||||
t.Fatalf("holder delete of %s: status %d: %s", name, code, out)
|
||||
}
|
||||
want := stored - freed
|
||||
end := time.Now().Add(60 * time.Second)
|
||||
got := env.poolObjects(t, "v1")
|
||||
for got != want && time.Now().Before(end) {
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
got = env.poolObjects(t, "v1")
|
||||
}
|
||||
if got != want {
|
||||
t.Fatalf("after deleting %s the pool holds %d chunk objects; want %d (%d freed)", name, got, want, freed)
|
||||
}
|
||||
stored = got
|
||||
}
|
||||
t.Logf("the second snapshot's cut uploaded %d chunks and created %d bindings", uploads[1], len(expected))
|
||||
if len(expected) < len(chunks) {
|
||||
t.Fatalf("the second snapshot's cut created %d bindings; want at least one per overwritten chunk (%d)", len(expected), len(chunks))
|
||||
}
|
||||
if uploads[1] != len(chunks) {
|
||||
t.Fatalf("the second snapshot's cut uploaded %d chunks; want the %d it overwrote", uploads[1], len(chunks))
|
||||
}
|
||||
env.deleteSnapshot(t, "v1", "s3")
|
||||
exclusive := env.exclusiveBytes(t, "v1", "s2")
|
||||
env.deleteSnapshot(t, "v1", "s2")
|
||||
collect("s3", 0) // its chunks are HEAD's
|
||||
collect("s2", len(chunks)) // named by nothing now
|
||||
env.requireSnapshotNames(t, "v1", "s1")
|
||||
deleted := time.Now()
|
||||
|
||||
requireBudget(t, time.Until(deleted.Add(ladderGCWait))+ladderGCWait+5*time.Minute)
|
||||
time.Sleep(time.Until(deleted.Add(ladderGCWait))) // the chunks are older than the grace
|
||||
_, firstReclaimed := env.gc(t, true)
|
||||
first := time.Now()
|
||||
requireBudget(t, ladderGCWait+5*time.Minute)
|
||||
time.Sleep(time.Until(first.Add(ladderGCWait))) // a second mark the grace after the first
|
||||
|
||||
eligible, _ := env.gc(t, false)
|
||||
named, oddPreview := objectsByKey(eligible)
|
||||
namedExpected, namedOther, storedBefore := 0, 0, 0
|
||||
for k, o := range named {
|
||||
if !expected[k] {
|
||||
namedOther++
|
||||
continue
|
||||
}
|
||||
namedExpected++
|
||||
if env.blobStored(t, o.FID) {
|
||||
storedBefore++
|
||||
}
|
||||
}
|
||||
reclaimedObjs, n := env.gc(t, true)
|
||||
reclaimed, oddApply := objectsByKey(reclaimedObjs)
|
||||
reclaimedExpected, reclaimedOther, goneAfter := 0, 0, 0
|
||||
for k, o := range reclaimed {
|
||||
if !expected[k] {
|
||||
reclaimedOther++
|
||||
continue
|
||||
}
|
||||
reclaimedExpected++
|
||||
if !env.blobStored(t, o.FID) {
|
||||
goneAfter++
|
||||
}
|
||||
}
|
||||
t.Logf("D4 MEASUREMENT: expected %d bindings (s2's cut uploaded %d chunks; usage: deleting s2 frees %d bytes); "+
|
||||
"first mark reclaimed %d; preview named %d of them (%d still in the store), %d others, %d malformed; "+
|
||||
"apply reclaimed %d (%d of them, %d now gone from the store), %d others, %d malformed; surplus left: %d of the expected",
|
||||
len(expected), uploads[1], exclusive, firstReclaimed, namedExpected, storedBefore, namedOther, oddPreview,
|
||||
n, reclaimedExpected, goneAfter, reclaimedOther, oddApply, len(expected)-goneAfter)
|
||||
env.requireImage(t, "s1", imgs[2])
|
||||
env.restoreChecked(t, "s1", "v2", imgs[0], imgs[1], imgs[2])
|
||||
}
|
||||
@@ -208,7 +208,7 @@ func (env *handoffEnv) snapshot(t *testing.T, hostID, vol, name string) snapshot
|
||||
// listSnapshots lists vol's snapshots (with a name prefix when given) under
|
||||
// ctx, without failing the test.
|
||||
func (env *handoffEnv) listSnapshots(ctx context.Context, vol, prefix string) ([]snapshotInfo, error) {
|
||||
args := []string{"ops", "chunk", "snapshots", "--volume", vol, "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath}
|
||||
args := []string{"ops", "chunk", "snapshots", "--master", env.h.masterAddr, "--volume", vol, "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath}
|
||||
if prefix != "" {
|
||||
args = append(args, "--prefix", prefix)
|
||||
}
|
||||
@@ -228,7 +228,7 @@ func (env *handoffEnv) listSnapshots(ctx context.Context, vol, prefix string) ([
|
||||
// snapshots lists vol's snapshots (with a name prefix when given).
|
||||
func (env *handoffEnv) snapshots(t *testing.T, vol, prefix string) []snapshotInfo {
|
||||
t.Helper()
|
||||
args := []string{"ops", "chunk", "snapshots", "--volume", vol, "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath}
|
||||
args := []string{"ops", "chunk", "snapshots", "--master", env.h.masterAddr, "--volume", vol, "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath}
|
||||
if prefix != "" {
|
||||
args = append(args, "--prefix", prefix)
|
||||
}
|
||||
|
||||
@@ -84,23 +84,36 @@ func literalOpsInvocations(t *testing.T, dir string) []opsInvocation {
|
||||
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 {
|
||||
var elems []ast.Expr
|
||||
switch x := n.(type) {
|
||||
case *ast.CallExpr:
|
||||
if x.Ellipsis != token.NoPos || len(x.Args) < 2 {
|
||||
return true
|
||||
}
|
||||
from := opsArg(x)
|
||||
if from < 0 {
|
||||
return true
|
||||
}
|
||||
elems = x.Args[from:]
|
||||
case *ast.CompositeLit:
|
||||
// a prepared argument list, []string{"ops", ...}, that a
|
||||
// harness call spreads
|
||||
if len(x.Elts) < 2 || literal(x.Elts[0]) != "ops" {
|
||||
return true
|
||||
}
|
||||
elems = x.Elts
|
||||
default:
|
||||
return true
|
||||
}
|
||||
var args []string
|
||||
for _, a := range call.Args[from:] {
|
||||
for _, a := range elems {
|
||||
if v := literal(a); v != "" || isStringLit(a) {
|
||||
args = append(args, v)
|
||||
continue
|
||||
}
|
||||
args = append(args, placeholder(args, len(args)))
|
||||
}
|
||||
pos := fset.Position(call.Pos())
|
||||
pos := fset.Position(n.Pos())
|
||||
out = append(out, opsInvocation{where: filepath.Base(pos.Filename) + ":" + strconv.Itoa(pos.Line), args: args})
|
||||
return true
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user