Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: limit flag for debug range-data / debug keys #49290

Merged
merged 1 commit into from
Jun 1, 2020
Merged
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
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
4 changes: 2 additions & 2 deletions pkg/cli/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func initCLIDefaults() {
debugCtx.replicated = false
debugCtx.inputFile = ""
debugCtx.printSystemConfig = false
debugCtx.maxResults = 1000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep this line; it's needed. You can change the value to zero.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

debugCtx.maxResults = 0
debugCtx.ballastSize = base.SizeSpec{InBytes: 1000000000}

serverCfg.GoroutineDumpDirName = ""
Expand Down Expand Up @@ -306,7 +306,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
15 changes: 14 additions & 1 deletion 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,6 +300,7 @@ func runDebugRangeData(cmd *cobra.Command, args []string) error {

iter := rditer.NewReplicaDataIterator(&desc, db, debugCtx.replicated, false /* seekEnd */)
defer iter.Close()
results := 0
for ; ; iter.Next() {
if ok, err := iter.Valid(); err != nil {
return err
Expand All @@ -302,6 +311,10 @@ func runDebugRangeData(cmd *cobra.Command, args []string) error {
Key: iter.Key(),
Value: iter.Value(),
})
results++
if results == 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 @@ -686,12 +686,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, debugCtx.maxResults)
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, debugCtx.maxResults)
}
{
f := debugGossipValuesCmd.Flags()
Expand Down