Skip to content

Commit

Permalink
Merge pull request #7696 from petermattis/pmattis/debug-keys
Browse files Browse the repository at this point in the history
cli: add `debug keys --sizes`
  • Loading branch information
petermattis authored Jul 8, 2016
2 parents ffcdab5 + 2b204a2 commit 7e2eb5b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions cli/cliflags/names.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const (
FromName = "from"
ToName = "to"
ValuesName = "values"
SizesName = "sizes"
RaftTickIntervalName = "raft-tick-interval"
UndoFreezeClusterName = "undo"
)
1 change: 1 addition & 0 deletions cli/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,5 @@ func (k *mvccKey) Type() string {
type debugContext struct {
startKey, endKey engine.MVCCKey
values bool
sizes bool
}
14 changes: 10 additions & 4 deletions cli/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,22 @@ func openStore(cmd *cobra.Command, dir string, stopper *stop.Stopper) (*engine.R
}

func printKey(kv engine.MVCCKeyValue) (bool, error) {
fmt.Printf("%q\n", kv.Key)

fmt.Printf("%s", kv.Key)
if debugCtx.sizes {
fmt.Printf(" %d %d", len(kv.Key.Key), len(kv.Value))
}
fmt.Printf("\n")
return false, nil
}

func printKeyValue(kv engine.MVCCKeyValue) (bool, error) {
if kv.Key.Timestamp != hlc.ZeroTimestamp {
fmt.Printf("%s %q: ", kv.Key.Timestamp, kv.Key.Key)
fmt.Printf("%s %s: ", kv.Key.Timestamp, kv.Key.Key)
} else {
fmt.Printf("%q: ", kv.Key.Key)
fmt.Printf("%s: ", kv.Key.Key)
}
if debugCtx.sizes {
fmt.Printf("%d %d: ", len(kv.Key.Key), len(kv.Value))
}
decoders := []func(kv engine.MVCCKeyValue) (string, error){
tryRaftLogEntry,
Expand Down
4 changes: 4 additions & 0 deletions cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ Exclusive end key and format as [<format>:]<key>. Supported formats:
cliflags.ValuesName: wrapText(`
Print values along with their associated key.`),

cliflags.SizesName: wrapText(`
Print key and value sizes along with their associated key.`),

cliflags.RaftTickIntervalName: wrapText(`
The resolution of the Raft timer; other raft timeouts are
defined in terms of multiples of this value.`),
Expand Down Expand Up @@ -498,6 +501,7 @@ func init() {
f.Var((*mvccKey)(&debugCtx.startKey), cliflags.FromName, usageNoEnv(cliflags.FromName))
f.Var((*mvccKey)(&debugCtx.endKey), cliflags.ToName, usageNoEnv(cliflags.ToName))
f.BoolVar(&debugCtx.values, cliflags.ValuesName, false, usageNoEnv(cliflags.ValuesName))
f.BoolVar(&debugCtx.sizes, cliflags.SizesName, false, usageNoEnv(cliflags.SizesName))
}

{
Expand Down

0 comments on commit 7e2eb5b

Please sign in to comment.