Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/control/cmd/ddb/commands_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type DdbApi interface {
DtxStat(path string, details bool) error
ProvMem(db_path string, tmpfs_mount string, tmpfs_mount_size uint) error
DtxAggr(path string, cmt_time uint64, cmt_date string) error
CsumDump(path string, dst string, epoch uint64) error
}

// DdbContext structure for wrapping the C code context structure
Expand Down Expand Up @@ -381,3 +382,15 @@ func (ctx *DdbContext) DtxAggr(path string, cmt_time uint64, cmt_date string) er
/* Run the c code command */
return daosError(C.ddb_run_dtx_aggr(&ctx.ctx, &options))
}

func (ctx *DdbContext) CsumDump(path string, dst string, epoch uint64) error {
/* Set up the options */
options := C.struct_csum_dump_options{}
options.path = C.CString(path)
defer freeString(options.path)
options.dst = C.CString(dst)
defer freeString(options.dst)
options.epoch = C.uint64_t(epoch)
/* Run the c code command */
return daosError(C.ddb_run_csum_dump(&ctx.ctx, &options))
}
24 changes: 24 additions & 0 deletions src/control/cmd/ddb/ddb_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,4 +445,28 @@ the path must include the extent, otherwise, it must not.`,
},
Completer: nil,
})
// Command csum_dump
app.AddCommand(&grumble.Command{
Name: "csum_dump",
Aliases: nil,
Help: "Dump visible checksum(s)",
LongHelp: `Dump visible checksum(s) to the screen or in a file. The vos
path should be a complete path, including the akey and if the value is an array
value it should include the extent. If a path to a file was provided then the
value(s) will be written to the file, else it will be printed to the screen.
With array values it is possible to define the maximal epoch of the visible record
extent to select`,
HelpGroup: "vos",
Args: func(a *grumble.Args) {
a.String("path", "VOS tree path to dump.")
a.String("dst", "Optional, destination vos tree path to a value.", grumble.Default(""))
},
Flags: func(f *grumble.Flags) {
f.Uint64("e", "epoch", math.MaxUint64, "Maximal epoch of the visible array value to select (default EPOCH_MAX).")
},
Run: func(c *grumble.Context) error {
return api.CsumDump(c.Args.String("path"), c.Args.String("dst"), c.Flags.Uint64("epoch"))
},
Completer: nil,
})
}
85 changes: 85 additions & 0 deletions src/control/cmd/ddb/ddb_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"math"
"os"
"path"
"strings"
Expand Down Expand Up @@ -66,6 +67,10 @@ func TestHelpCmds(t *testing.T) {
cmdStr: "open",
helpSubStr: "Usage:\n open [flags] path\n",
},
"help for 'csum_dump' command": {
cmdStr: "csum_dump",
helpSubStr: "Usage:\n csum_dump [flags] path [dst]\n",
},
} {
t.Run(name, func(t *testing.T) {
runHelpCmd(t, tc.cmdStr, tc.helpSubStr)
Expand Down Expand Up @@ -179,6 +184,86 @@ func TestCmds(t *testing.T) {
},
expStdout: []string{"ls called"},
},
"csum_dump invalid options": {
args: []string{"csum_dump", "--bar"},
expErr: fmt.Errorf("invalid flag: --bar"),
},
"csum_dump default": {
args: []string{"csum_dump", "/[0]"},
expCalls: func(ctx *DdbContextStub) {
ctx.csumDump = func(path string, dst string, epoch uint64) error {
fmt.Println("csum_dump called")
if err := isArgEqual("/[0]", path, "path"); err != nil {
return err
}
if err := isArgEqual("", dst, "dst"); err != nil {
return err
}
if err := isArgEqual(uint64(math.MaxUint64), epoch, "epoch"); err != nil {
return err
}
return nil
}
},
expStdout: []string{"csum_dump called"},
},
"csum_dump epoch short": {
args: []string{"csum_dump", "-e", "999", "/[0]"},
expCalls: func(ctx *DdbContextStub) {
ctx.csumDump = func(path string, dst string, epoch uint64) error {
fmt.Println("csum_dump called")
if err := isArgEqual("/[0]", path, "path"); err != nil {
return err
}
if err := isArgEqual("", dst, "dst"); err != nil {
return err
}
if err := isArgEqual(uint64(999), epoch, "epoch"); err != nil {
return err
}
return nil
}
},
expStdout: []string{"csum_dump called"},
},
"csum_dump epoch long": {
args: []string{"csum_dump", "--epoch=666", "/[0]"},
expCalls: func(ctx *DdbContextStub) {
ctx.csumDump = func(path string, dst string, epoch uint64) error {
fmt.Println("csum_dump called")
if err := isArgEqual("/[0]", path, "path"); err != nil {
return err
}
if err := isArgEqual("", dst, "dst"); err != nil {
return err
}
if err := isArgEqual(uint64(666), epoch, "epoch"); err != nil {
return err
}
return nil
}
},
expStdout: []string{"csum_dump called"},
},
"csum_dump destination": {
args: []string{"csum_dump", "/[0]", "/tmp/csum_dump.out"},
expCalls: func(ctx *DdbContextStub) {
ctx.csumDump = func(path string, dst string, epoch uint64) error {
fmt.Println("csum_dump called")
if err := isArgEqual("/[0]", path, "path"); err != nil {
return err
}
if err := isArgEqual("/tmp/csum_dump.out", dst, "dst"); err != nil {
return err
}
if err := isArgEqual(uint64(math.MaxUint64), epoch, "epoch"); err != nil {
return err
}
return nil
}
},
expStdout: []string{"csum_dump called"},
},
} {
t.Run(name, func(t *testing.T) {
var opts cliOptions
Expand Down
8 changes: 8 additions & 0 deletions src/control/cmd/ddb/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type DdbContextStub struct {
dtxStat func(path string, details bool) error
provMem func(db_path string, tmpfs_mount string, tmpfs_mount_size uint) error
dtxAggr func(path string, cmt_time uint64, cmt_date string) error
csumDump func(path string, dst string, epoch uint64) error
}

func (ctx *DdbContextStub) Init(log *logging.LeveledLogger) (func(), error) {
Expand Down Expand Up @@ -248,6 +249,13 @@ func (ctx *DdbContextStub) DtxAggr(path string, cmt_time uint64, cmt_date string
return ctx.dtxAggr(path, cmt_time, cmt_date)
}

func (ctx *DdbContextStub) CsumDump(path string, dst string, epoch uint64) error {
if ctx.csumDump == nil {
return nil
}
return ctx.csumDump(path, dst, epoch)
}

func runCmdToStdout(log *logging.LeveledLogger, ctx *DdbContextStub, opts *cliOptions, args []string) (string, error) {
// replace os.Stdout so that we can verify the generated output
var result bytes.Buffer
Expand Down
Loading