diff --git a/ctl/chksum.go b/ctl/chksum.go index 5d508dccc..28ae7b23c 100644 --- a/ctl/chksum.go +++ b/ctl/chksum.go @@ -92,7 +92,7 @@ func (cmd *ChkSumCommand) Run(ctx context.Context) (err error) { } for _, item := range res.Results { rowids := item.(*pilosa.RowIdentifiers) - //either rowids or keys + // either rowids or keys for _, row := range rowids.Keys { countPql := fmt.Sprintf(`Count(Row(%v="%v"))`, field.Name, row) qr := &pilosa.QueryRequest{Index: ii.Name, Query: countPql} @@ -121,7 +121,7 @@ func (cmd *ChkSumCommand) Run(ctx context.Context) (err error) { } } - fmt.Printf("hash:%x\n", h.Sum(nil)) + fmt.Fprintf(cmd.Stdout, "hash:%x\n", h.Sum(nil)) } return nil diff --git a/executor_test.go b/executor_test.go index 9c8aa595f..f73b93cc9 100644 --- a/executor_test.go +++ b/executor_test.go @@ -7040,6 +7040,35 @@ func backupTest(t *testing.T, c *test.Cluster) { // putting this here is to take advantage of already-existing // clusters and data. + sum := chkSumCluster(t, c) + + backupDir := backupCluster(t, c) + + cnew := test.MustRunCluster(t, 3) // this way we test 1->3 3->3 7->3 + defer cnew.Close() + + restoreCluster(t, backupDir, cnew) + + sumNew := chkSumCluster(t, cnew) + + if sum != sumNew { + t.Fatalf("old/new checksum mismatch, old:\n%s\nnew:\n:%s", sum, sumNew) + } +} + +func chkSumCluster(t *testing.T, c *test.Cluster) string { + buf := &bytes.Buffer{} + + chkSum := ctl.NewChkSumCommand(nil, buf, buf) + chkSum.Host = c.Nodes[len(c.Nodes)-1].URL() + if err := chkSum.Run(context.Background()); err != nil { + t.Fatalf("running checksum: %v", err) + } + + return buf.String() +} + +func backupCluster(t *testing.T, c *test.Cluster) (backupDir string) { td, err := testhook.TempDir(t, "backupTest") if err != nil { t.Fatalf("can't even get a temp dir, what a ripoff: %v", err) @@ -7056,6 +7085,18 @@ func backupTest(t *testing.T, c *test.Cluster) { t.Log(buf.String()) t.Fatalf("running backup: %v", err) } + return td +} + +func restoreCluster(t *testing.T, backupDir string, c *test.Cluster) { + buf := &bytes.Buffer{} + + restore := ctl.NewRestoreCommand(nil, buf, buf) + restore.Host = c.Nodes[len(c.Nodes)-1].URL() + restore.Path = backupDir + if err := restore.Run(context.Background()); err != nil { + t.Fatalf("restoring: %v", err) + } } // tests for abbreviating time values in queries