mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
fix(sw-block): mini prints only commands it has, and says to disconnect before stopping
Review follow-up. The next steps name only commands this binary runs (the workspace show and chunk snapshots checks, a snapshot), each parsed by a test; no shell line until the shell exists. Without weed, the missing chunk store is mini's own sentence, not a check that did not run. With the connect command and again at stop, mini says to unmount and nvme disconnect first; at stop it says the data stays in --dir and --reuse resumes it; one line names it a trial setup (one host, loopback, no authentication). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
33474e882d
commit
9613086d50
3 files changed
+82
-8
No files matched your search
@@ -409,33 +409,67 @@ func mini(ctx context.Context, cfg miniConfig, stdout, stderr io.Writer) (int, e
|
||||
for {
|
||||
for _, c := range r.children {
|
||||
if c.exited() {
|
||||
miniBeforeStop(stdout, cfg)
|
||||
r.stop()
|
||||
miniAfterStop(stdout, cfg)
|
||||
return fail(fmt.Errorf("%s exited: %v; stopped the others", c.name, c.err))
|
||||
}
|
||||
}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
fmt.Fprintln(stdout, "sw-block mini: interrupted: stopping")
|
||||
miniBeforeStop(stdout, cfg)
|
||||
r.stop()
|
||||
miniAfterStop(stdout, cfg)
|
||||
return 0, nil
|
||||
case <-time.After(500 * time.Millisecond):
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// miniCommands are the sw-block commands mini prints for the user to run
|
||||
// next (without the leading "sw-block"): only commands this binary has.
|
||||
func miniCommands(c miniConfig, chunk bool) [][]string {
|
||||
if !chunk {
|
||||
return nil
|
||||
}
|
||||
m, f := loopback(c.Ports.Master), loopback(c.Ports.WeedFG)
|
||||
return [][]string{
|
||||
{"ops", "workspace", "show", "--master", m, "--volume", miniVolume},
|
||||
{"ops", "chunk", "snapshots", "--master", m, "--volume", miniVolume, "--chunk-filer", f},
|
||||
{"ops", "chunk", "snapshot", "--volume", miniVolume, "--name", "first", "--status-addr", loopback(c.Ports.Status)},
|
||||
}
|
||||
}
|
||||
|
||||
func miniDisconnect(c miniConfig) string {
|
||||
return "sudo nvme disconnect -n " + c.NQN
|
||||
}
|
||||
|
||||
// miniNextSteps prints what to run next; mini runs none of it.
|
||||
func miniNextSteps(w io.Writer, c miniConfig, chunk bool) {
|
||||
m := loopback(c.Ports.Master)
|
||||
fmt.Fprintf(w, "\nsw-block mini: running (%s). Ctrl-C stops everything it started. Logs: %s/*.log\n", map[bool]string{true: "walstore-chunk on weed mini", false: "walstore, no snapshots"}[chunk], c.Dir)
|
||||
mode := map[bool]string{true: "walstore-chunk on weed mini", false: "walstore, no snapshots"}[chunk]
|
||||
fmt.Fprintf(w, "\nsw-block mini: running (%s). Ctrl-C stops everything it started. Logs: %s/*.log\n", mode, c.Dir)
|
||||
fmt.Fprintln(w, "sw-block mini: trial setup: one host, loopback, no authentication.")
|
||||
fmt.Fprintf(w, "\nAttach v1 (mini does not do this for you):\n sudo nvme connect -t tcp -a 127.0.0.1 -s %d -n %s --ctrl-loss-tmo=180 --reconnect-delay=2\n", c.Ports.NVMe, c.NQN)
|
||||
fmt.Fprintf(w, "Before stopping mini: unmount anything on v1, then\n %s\n(else a mounted filesystem sits on a stopped target while the kernel retries for 3 minutes)\n", miniDisconnect(c))
|
||||
fmt.Fprintf(w, "\nStatus:\n curl -s 'http://%s/status?volume=%s'\n", loopback(c.Ports.Status), miniVolume)
|
||||
if !chunk {
|
||||
fmt.Fprintln(w, "\ncluster.check: no chunk store: snapshots unavailable")
|
||||
fmt.Fprintln(w, "\nsw-block mini: no chunk store: snapshots unavailable (run with weed for snapshots and restore)")
|
||||
return
|
||||
}
|
||||
f := loopback(c.Ports.WeedFG)
|
||||
fmt.Fprintf(w, "\nCheck the cluster:\n sw-block shell -master %s -filer %s\n > cluster.check\n", m, f)
|
||||
fmt.Fprintf(w, " (until the shell lands, the same checks: sw-block ops workspace show --master %s --volume %s\n and sw-block ops chunk snapshots --master %s --volume %s --chunk-filer %s)\n", m, miniVolume, m, miniVolume, f)
|
||||
fmt.Fprintf(w, "\nSnapshot:\n sw-block ops chunk snapshot --volume %s --name first --status-addr %s\n", miniVolume, loopback(c.Ports.Status))
|
||||
cmds := miniCommands(c, chunk)
|
||||
fmt.Fprintf(w, "\nCheck the volume:\n sw-block %s\n sw-block %s\n", strings.Join(cmds[0], " "), strings.Join(cmds[1], " "))
|
||||
fmt.Fprintf(w, "\nSnapshot:\n sw-block %s\n", strings.Join(cmds[2], " "))
|
||||
fmt.Fprintf(w, "\nSeaweedFS itself: weed shell -master=%s\n", loopback(c.Ports.WeedMaster))
|
||||
}
|
||||
|
||||
// miniBeforeStop reminds the user, before the target goes away, to have
|
||||
// disconnected v1.
|
||||
func miniBeforeStop(w io.Writer, c miniConfig) {
|
||||
fmt.Fprintf(w, "sw-block mini: if v1 is connected: unmount it, then %s\n", miniDisconnect(c))
|
||||
}
|
||||
|
||||
// miniAfterStop says where the data is and how to resume it.
|
||||
func miniAfterStop(w io.Writer, c miniConfig) {
|
||||
fmt.Fprintf(w, "sw-block mini: stopped. The data stays in %s; sw-block mini --dir %s --reuse starts it again.\n", c.Dir, c.Dir)
|
||||
}
|
||||
@@ -307,7 +307,8 @@ func TestMiniInterruptStopsEveryChild(t *testing.T) {
|
||||
done := make(chan int, 1)
|
||||
go func() { code, _ := mini(ctx, c, out, io.Discard); done <- code }()
|
||||
waitOutput(t, out, "sw-block mini: running")
|
||||
for _, want := range []string{"+ " + filepath.Join(c.Bin, "blockmaster") + " ", "+ " + filepath.Join(c.Bin, "blockvolume") + " ", "sudo nvme connect -t tcp -a 127.0.0.1 -s " + strconv.Itoa(c.Ports.NVMe) + " -n nqn.test:v1", "no chunk store: snapshots unavailable"} {
|
||||
for _, want := range []string{"+ " + filepath.Join(c.Bin, "blockmaster") + " ", "+ " + filepath.Join(c.Bin, "blockvolume") + " ", "sudo nvme connect -t tcp -a 127.0.0.1 -s " + strconv.Itoa(c.Ports.NVMe) + " -n nqn.test:v1", "sudo nvme disconnect -n nqn.test:v1",
|
||||
"sw-block mini: no chunk store: snapshots unavailable", "trial setup: one host, loopback, no authentication"} {
|
||||
if !strings.Contains(out.String(), want) {
|
||||
t.Fatalf("output lacks %q:\n%s", want, out.String())
|
||||
}
|
||||
@@ -321,6 +322,14 @@ func TestMiniInterruptStopsEveryChild(t *testing.T) {
|
||||
case <-time.After(30 * time.Second):
|
||||
t.Fatal("mini did not stop")
|
||||
}
|
||||
for _, want := range []string{"if v1 is connected: unmount it, then sudo nvme disconnect -n nqn.test:v1", "The data stays in " + c.Dir, "--reuse starts it again"} {
|
||||
if !strings.Contains(out.String(), want) {
|
||||
t.Fatalf("at stop, output lacks %q:\n%s", want, out.String())
|
||||
}
|
||||
}
|
||||
if strings.Contains(out.String(), "cluster.check") || strings.Contains(out.String(), "sw-block shell") {
|
||||
t.Fatal("mini prints a check or a shell this binary does not have")
|
||||
}
|
||||
stops := stoppedRE.FindAllStringSubmatch(out.String(), -1)
|
||||
if len(stops) != 2 || stops[0][1] != "blockvolume" || stops[1][1] != "blockmaster" {
|
||||
t.Fatalf("stop order %v; want blockvolume then blockmaster", stops)
|
||||
@@ -364,3 +373,31 @@ func processAlive(pid int) bool {
|
||||
}
|
||||
return p.Signal(syscall.Signal(0)) == nil
|
||||
}
|
||||
|
||||
// Every sw-block command mini prints is one this binary parses: run against
|
||||
// ports where nothing listens, it may fail to connect, never on its flags.
|
||||
// A control with an unknown flag shows the check sees a flag error.
|
||||
func TestMiniPrintedCommandsParse(t *testing.T) {
|
||||
c := miniConfig{Dir: t.TempDir(), NQN: "n", SizeBytes: 1 << 20, Ports: freePorts(t)}
|
||||
cmds := miniCommands(c, true)
|
||||
if len(cmds) == 0 {
|
||||
t.Fatal("no commands")
|
||||
}
|
||||
flagError := func(args []string) (bool, string) {
|
||||
var errb bytes.Buffer
|
||||
run(args, io.Discard, &errb)
|
||||
e := errb.String()
|
||||
return strings.Contains(e, "flag provided but not defined") || strings.Contains(e, "usage:"), e
|
||||
}
|
||||
for _, args := range cmds {
|
||||
if bad, e := flagError(args); bad {
|
||||
t.Errorf("sw-block %s: refused its own flags: %s", strings.Join(args, " "), e)
|
||||
}
|
||||
}
|
||||
if bad, _ := flagError(append(append([]string{}, cmds[0]...), "--no-such-flag")); !bad {
|
||||
t.Fatal("control: an unknown flag was not reported as a flag error")
|
||||
}
|
||||
if miniCommands(c, false) != nil {
|
||||
t.Fatal("without weed mini prints sw-block commands that need a chunk store")
|
||||
}
|
||||
}
|
||||
@@ -423,6 +423,9 @@ sw-block mini --dir ./swb-mini # blockmaster and blockvolume next to sw
|
||||
- **Visibility:** it prints every command before it runs it, and each process logs to `<dir>/<name>.log`.
|
||||
- **It does not connect the volume.** It never runs `sudo` or `nvme connect`; it prints the connect command, the status URL and the next commands (snapshot, checks).
|
||||
- **Stopping:** Ctrl-C stops everything it started, the last started first. So does any of its processes exiting.
|
||||
- If you connected v1, unmount it and run `sudo nvme disconnect -n <nqn>` **before** stopping mini. Otherwise a mounted filesystem sits on a stopped target while the kernel retries for 3 minutes. mini prints this with the connect command and again when it stops.
|
||||
- The data stays in `--dir`; `sw-block mini --dir <dir> --reuse` starts it again.
|
||||
- **It is a trial setup:** one host, loopback, no authentication.
|
||||
- **Refusals:** it refuses a `--dir` that already exists, unless you pass `--reuse` to start again on it, and refuses a port that is already in use. `--port-shift N` moves every port by N, for a host where a default port is taken.
|
||||
- **Size:** `--size` sets v1's size (default `256MiB`). Volumes above the release maximum are refused by blockmaster as usual.
|
||||
|
||||
|
||||
Reference in new issue
Block a user