diff --git a/seaweed-block/cmd/sw-block/mini.go b/seaweed-block/cmd/sw-block/mini.go index c9bc5509cb..0b3a3f025b 100644 --- a/seaweed-block/cmd/sw-block/mini.go +++ b/seaweed-block/cmd/sw-block/mini.go @@ -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) +} diff --git a/seaweed-block/cmd/sw-block/mini_test.go b/seaweed-block/cmd/sw-block/mini_test.go index 091010d6f5..80543a4d9e 100644 --- a/seaweed-block/cmd/sw-block/mini_test.go +++ b/seaweed-block/cmd/sw-block/mini_test.go @@ -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") + } +} diff --git a/seaweed-block/docs/standalone-deployment.md b/seaweed-block/docs/standalone-deployment.md index f8bd07f645..8ee8675121 100644 --- a/seaweed-block/docs/standalone-deployment.md +++ b/seaweed-block/docs/standalone-deployment.md @@ -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 `