From f67564467439889c1fd7faf3e2b234bad4e282f4 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Tue, 1 Dec 2026 07:24:31 -0800 Subject: [PATCH] test, sw-block: a stalled delete and a dead test store are named - sw-block ops chunk volume-delete: while a sweep makes no progress, stderr says so every quarter of --timeout (at most every 5 s), with how long nothing has moved, the object it waits on and the count so far; the bound and the answer are unchanged. - process-test harness: each weed server keeps its own exit status per start; a failed test logs, as its own message, each server as running or exited with its status and the master's and the volume server's last lines (the volume server last, within what the CI summary keeps); the delete helper's kill and deadline failures name the store's state. Co-Authored-By: Claude Opus 5.5 --- ...olume_delete_procedure_integration_test.go | 5 +- .../blockvolume/weed_failure_report_test.go | 62 +++++++++++++++++-- .../workspace_weed_integration_test.go | 15 +++-- .../cmd/sw-block/chunk_volume_delete.go | 30 +++++++++ 4 files changed, 102 insertions(+), 10 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/volume_delete_procedure_integration_test.go b/seaweed-block/cmd/blockvolume/volume_delete_procedure_integration_test.go index dd3f0898a7..32f83a54ce 100644 --- a/seaweed-block/cmd/blockvolume/volume_delete_procedure_integration_test.go +++ b/seaweed-block/cmd/blockvolume/volume_delete_procedure_integration_test.go @@ -35,7 +35,8 @@ func (env *handoffEnv) deletePastPrintedHorizon(t *testing.T, volume, request st "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath, "--master", env.h.masterAddr, "--request-id", request) if err != nil { - t.Fatalf("volume-delete %s: %v", volume, err) + // a kill by the deadline below: name the store the delete waits on + t.Fatalf("volume-delete %s: %v (its object store: weed %s)", volume, err, weedState(env.cluster.servers())) } return out, errOut, code } @@ -59,7 +60,7 @@ func (env *handoffEnv) deletePastPrintedHorizon(t *testing.T, volume, request st for { select { case <-ctx.Done(): - t.Fatalf("delete did not resolve by original horizon + 5s: %s %s", out, errOut) + t.Fatalf("delete did not resolve by original horizon + 5s (its object store: weed %s): %s %s", weedState(env.cluster.servers()), out, errOut) case <-timer.C: } out, errOut, code = call(ctx) diff --git a/seaweed-block/cmd/blockvolume/weed_failure_report_test.go b/seaweed-block/cmd/blockvolume/weed_failure_report_test.go index 155341a1f6..5ba5b2fb22 100644 --- a/seaweed-block/cmd/blockvolume/weed_failure_report_test.go +++ b/seaweed-block/cmd/blockvolume/weed_failure_report_test.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "path/filepath" + "sort" "strings" "testing" ) @@ -17,11 +18,64 @@ type weedServer struct { err error } -// weedState names each server as running or exited with its status (seam). -func weedState(servers []weedServer) string { return "" } +// weedState names each server, by name, as running or exited with its status. +func weedState(servers []weedServer) string { + s := append([]weedServer(nil), servers...) + sort.Slice(s, func(i, j int) bool { return s[i].name < s[j].name }) + parts := make([]string, 0, len(s)) + for _, x := range s { + switch { + case !x.exited: + parts = append(parts, x.name+" running") + case x.err != nil: + parts = append(parts, fmt.Sprintf("%s exited (%v)", x.name, x.err)) + default: + parts = append(parts, x.name+" exited (status 0)") + } + } + return strings.Join(parts, ", ") +} -// weedFailureReport is a failed test's evidence of its cluster (seam). -func weedFailureReport(servers []weedServer) string { return "" } +// weedReportTails: the master's and the volume server's last lines a report +// carries, the volume server last. With a header each they are the 20 +// continuation lines the CI summary keeps of one message. +var weedReportTails = []struct { + name string + lines int +}{{"master", 8}, {"volume", 10}} + +// weedFailureReport is a failed test's evidence of its cluster: the state of +// each server, then the master's and the volume server's last log lines. +func weedFailureReport(servers []weedServer) string { + var b strings.Builder + fmt.Fprintf(&b, "weed cluster at the failure: %s\n", weedState(servers)) + for _, tail := range weedReportTails { + for _, s := range servers { + if s.name != tail.name { + continue + } + fmt.Fprintf(&b, "%s, last %d lines:\n", s.name, tail.lines) + for _, l := range lastLogLines(s.log, tail.lines) { + b.WriteString(l + "\n") + } + } + } + return b.String() +} + +// lastLogLines is the last n lines of the log at path (one line naming the +// error when it cannot be read). +func lastLogLines(path string, n int) []string { + data, err := os.ReadFile(path) + if err != nil { + return []string{fmt.Sprintf("(log not readable: %v)", err)} + } + lines := strings.Split(strings.TrimRight(string(data), "\n"), "\n") + if len(lines) > n { + lines = lines[len(lines)-n:] + } + return lines +} // fakeWeedLog writes a log of n numbered lines for name. func fakeWeedLog(t *testing.T, dir, name string, n int) string { diff --git a/seaweed-block/cmd/blockvolume/workspace_weed_integration_test.go b/seaweed-block/cmd/blockvolume/workspace_weed_integration_test.go index a7ffbb4a32..8be672c1a9 100644 --- a/seaweed-block/cmd/blockvolume/workspace_weed_integration_test.go +++ b/seaweed-block/cmd/blockvolume/workspace_weed_integration_test.go @@ -163,6 +163,13 @@ func startWorkspaceWeedWith(t *testing.T, dir string, o w4WeedOpts) *w4WeedClust } c, err := startWorkspaceWeedOnce(t, at, weed, o) if err == nil { + // Registered after the servers' own stop cleanups, so it runs + // first: a failed test names each server as it was at the end. + t.Cleanup(func() { + if t.Failed() { + t.Log(weedFailureReport(c.servers())) + } + }) return c } if attempt >= starts { @@ -278,7 +285,7 @@ type w4WeedProc struct { log *os.File cmd *exec.Cmd done chan struct{} - err error // the exit status, set before done closes + exit *error // this start's exit status, set before done closes (a fresh one per start) } func (c *w4WeedCluster) startProc(t *testing.T, name string, args ...string) { @@ -298,8 +305,8 @@ func (c *w4WeedCluster) startProc(t *testing.T, name string, args ...string) { if err := cmd.Start(); err != nil { t.Fatalf("start %s: %v", name, err) } - p.cmd, p.done = cmd, make(chan struct{}) - go func(done chan struct{}) { _ = cmd.Wait(); close(done) }(p.done) + p.cmd, p.done, p.exit = cmd, make(chan struct{}), new(error) + go func(done chan struct{}, exit *error) { *exit = cmd.Wait(); close(done) }(p.done, p.exit) } // servers is the cluster's servers for weedState and weedFailureReport. @@ -309,7 +316,7 @@ func (c *w4WeedCluster) servers() []weedServer { s := weedServer{name: name, log: p.log.Name()} select { case <-p.done: - s.exited, s.err = true, p.err + s.exited, s.err = true, *p.exit default: } out = append(out, s) diff --git a/seaweed-block/cmd/sw-block/chunk_volume_delete.go b/seaweed-block/cmd/sw-block/chunk_volume_delete.go index 0a45b64657..6f97742169 100644 --- a/seaweed-block/cmd/sw-block/chunk_volume_delete.go +++ b/seaweed-block/cmd/sw-block/chunk_volume_delete.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "io" + "sync" "time" "google.golang.org/grpc/codes" @@ -110,13 +111,40 @@ func deleteVolumeWithProgress(ctx context.Context, cat *chunkstore.BCatalog, ref stalled := func(err error) error { return &chunkstore.CatalogError{Code: "unavailable", Retryable: true, Message: fmt.Sprintf("deleted %d of %d objects; no progress at %s; retry with the same --request-id", len(done), total, object), Err: err} } + // A sweep stuck inside the store says so while it waits (every quarter of + // the bound, at most every 5 s): a stalled store is told apart from a slow + // delete before the bound ends the command. mu guards the sweep's counters, + // which the progress callback and the reporter share. + var mu sync.Mutex + stallEvery := min(5*time.Second, max(bound/4, 50*time.Millisecond)) + reportStalls := func(stop <-chan struct{}) { + tk := time.NewTicker(stallEvery) + defer tk.Stop() + for { + select { + case <-stop: + return + case <-tk.C: + } + mu.Lock() + idle, n, of, at := time.Since(lastProgress), len(done), total, object + mu.Unlock() + if idle >= stallEvery { + fmt.Fprintf(stderr, "volume-delete: no progress for %s, waiting on %s (deleted %d of %d objects)\n", idle.Round(time.Millisecond), at, n, of) + } + } + } for { if lastErr != nil && time.Since(lastProgress) >= bound { return nil, stalled(lastErr) } object = "listing or HEAD" batch, cancel := context.WithDeadline(ctx, minTime(time.Now().Add(bound), lastProgress.Add(bound))) + stop, reported := make(chan struct{}), make(chan struct{}) + go func() { defer close(reported); reportStalls(stop) }() skipped, err := cat.DeleteVolume(batch, ref, auth, func(p layout.DeleteProgress) { + mu.Lock() + defer mu.Unlock() if p.Object == "" { present := make(map[string]bool, len(p.Objects)) for _, rel := range p.Objects { @@ -141,6 +169,8 @@ func deleteVolumeWithProgress(ctx context.Context, cat *chunkstore.BCatalog, ref } }) cancel() + close(stop) + <-reported fmt.Fprintf(stderr, "volume-delete: deleted %d of %d objects\n", len(done), total) for _, rn := range skipped { skippedSet[rn] = true