Skip to content

Commit

Permalink
cli: limit flag for debug range-data / debug keys
Browse files Browse the repository at this point in the history
There was a teasing maxResults field already, completely unused.

Release note: None
  • Loading branch information
andreimatei committed May 19, 2020
1 parent 41e568c commit 1e4c5c8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
5 changes: 5 additions & 0 deletions pkg/cli/cliflags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,11 @@ Exclusive end key and format as [<format>:]<key>. Supported formats: raw, hex,
human, rangeID. The raw format supports escaped text. For example, "raw:\x01k"
is the prefix for range local keys. The hex format takes an encoded MVCCKey.`}

Limit = FlagInfo{
Name: "limit",
Description: `Maximum number of keys to return.`,
}

Values = FlagInfo{
Name: "values",
Description: `Print values along with their associated key.`,
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ var debugCtx struct {
inputFile string
ballastSize base.SizeSpec
printSystemConfig bool
maxResults int64
maxResults int
}

// startCtx captures the command-line arguments for the `start` command.
Expand Down
16 changes: 14 additions & 2 deletions pkg/cli/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,15 @@ func runDebugKeys(cmd *cobra.Command, args []string) error {
}
}

return db.Iterate(debugCtx.startKey.Key, debugCtx.endKey.Key, printer)
results := 0
return db.Iterate(debugCtx.startKey.Key, debugCtx.endKey.Key, func(kv storage.MVCCKeyValue) (bool, error) {
done, err := printer(kv)
if done || err != nil {
return done, err
}
results++
return results == debugCtx.maxResults, nil
})
}

func runDebugBallast(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -292,7 +300,8 @@ func runDebugRangeData(cmd *cobra.Command, args []string) error {

iter := rditer.NewReplicaDataIterator(&desc, db, debugCtx.replicated, false /* seekEnd */)
defer iter.Close()
for ; ; iter.Next() {
for i := 0; ; iter.Next() {
i++
if ok, err := iter.Valid(); err != nil {
return err
} else if !ok {
Expand All @@ -302,6 +311,9 @@ func runDebugRangeData(cmd *cobra.Command, args []string) error {
Key: iter.Key(),
Value: iter.Value(),
})
if i == debugCtx.maxResults {
break
}
}
return nil
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -697,12 +697,14 @@ func init() {
f := debugKeysCmd.Flags()
VarFlag(f, (*mvccKey)(&debugCtx.startKey), cliflags.From)
VarFlag(f, (*mvccKey)(&debugCtx.endKey), cliflags.To)
IntFlag(f, &debugCtx.maxResults, cliflags.Limit, 0)
BoolFlag(f, &debugCtx.values, cliflags.Values, debugCtx.values)
BoolFlag(f, &debugCtx.sizes, cliflags.Sizes, debugCtx.sizes)
}
{
f := debugRangeDataCmd.Flags()
BoolFlag(f, &debugCtx.replicated, cliflags.Replicated, debugCtx.replicated)
IntFlag(f, &debugCtx.maxResults, cliflags.Limit, 0)
}
{
f := debugGossipValuesCmd.Flags()
Expand Down

0 comments on commit 1e4c5c8

Please sign in to comment.