sw-block, test: delete diagnostics are best effort; a failed start is reported

- volume-delete: every progress line goes through a diagnostic writer whose
  one goroutine owns the stderr writes; a line that finds its queue full
  is dropped and printf never blocks, so a slow stderr delays neither a
  sweep, the retry window nor the answer. Once the answer is decided the
  command waits at most 200 ms for queued lines.
- process-test harness: a failed weed start (a server never listened, or
  every attempt failed) is reported with each server's state and the
  master's and the volume server's last lines, taken before the servers
  are stopped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-12-01 08:08:09 -08:00
1 parent 7ae15f06a7
commit b91bffb691
4 files changed
+67 -7

No files matched your search

@@ -63,9 +63,10 @@ func weedFailureReport(servers []weedServer) string {
return b.String()
}
// weedStartFailure is the message of a failed start attempt (seam).
// weedStartFailure is the message of a failed start attempt, with the
// cluster's evidence taken before its servers are stopped.
func weedStartFailure(attempt, starts int, err error, servers []weedServer) string {
return fmt.Sprintf("weed start %d of %d did not start: %v", attempt, starts, err)
return fmt.Sprintf("weed start %d of %d did not start: %v; %s", attempt, starts, err, weedFailureReport(servers))
}
// lastLogLines is the last n lines of the log at path (one line naming the
@@ -172,10 +172,11 @@ func startWorkspaceWeedWith(t *testing.T, dir string, o w4WeedOpts) *w4WeedClust
})
return c
}
// The evidence is taken now, before the servers are stopped.
if attempt >= starts {
t.Fatalf("cluster did not start (start %d of %d): %v", attempt, starts, err)
t.Fatal(weedStartFailure(attempt, starts, err, c.servers()))
}
t.Logf("weed start %d did not start (%v): master %s, filer %s; starting again on fresh ports", attempt, err, c.master, c.filerGRPC)
t.Logf("master %s, filer %s; starting again on fresh ports: %s", c.master, c.filerGRPC, weedStartFailure(attempt, starts, err, c.servers()))
c.discard(t)
}
}
+54
View File
@@ -0,0 +1,54 @@
package main
import (
"fmt"
"io"
"time"
)
// diagWriter writes a command's diagnostic lines best effort: one goroutine
// owns the writes, a line that finds the queue full is dropped, and printf
// never blocks. A slow or stuck stderr therefore never delays the work the
// lines describe, nor its answer.
type diagWriter struct {
lines chan string
done chan struct{}
}
// diagQueue is how many lines may wait for a slow stderr; diagDrain is how
// long close waits for them once the command's answer is decided.
const diagQueue = 64
var diagDrain = 200 * time.Millisecond
func newDiagWriter(w io.Writer) *diagWriter {
d := &diagWriter{lines: make(chan string, diagQueue), done: make(chan struct{})}
go func() {
defer close(d.done)
for l := range d.lines {
_, _ = io.WriteString(w, l)
}
}()
return d
}
// printf queues one line, or drops it when the queue is full.
func (d *diagWriter) printf(format string, args ...any) {
select {
case d.lines <- fmt.Sprintf(format, args...):
default:
}
}
// close takes no more lines and waits at most diagDrain for the queued ones.
// A writer still stuck after that finishes on its own; the stderr it writes
// to must then be safe for concurrent use (os.Stderr is).
func (d *diagWriter) close() {
close(d.lines)
t := time.NewTimer(diagDrain)
defer t.Stop()
select {
case <-d.done:
case <-t.C:
}
}
@@ -111,6 +111,10 @@ 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}
}
// Every progress line goes through diag, best effort: a slow stderr never
// delays a sweep, the retry window or the answer.
diag := newDiagWriter(stderr)
defer diag.close()
// 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,
@@ -130,7 +134,7 @@ func deleteVolumeWithProgress(ctx context.Context, cat *chunkstore.BCatalog, ref
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)
diag.printf("volume-delete: no progress for %s, waiting on %s (deleted %d of %d objects)\n", idle.Round(time.Millisecond), at, n, of)
}
}
}
@@ -170,8 +174,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)
<-reported // prompt: the reporter never blocks on stderr
diag.printf("volume-delete: deleted %d of %d objects\n", len(done), total)
for _, rn := range skipped {
skippedSet[rn] = true
}