From 99408d8a95e33d6257281d6a6a232a8714f9b630 Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Wed, 7 Sep 2016 15:21:31 +0800 Subject: [PATCH] cli: Include unreplicated data in `debug range-data` Add flag --replicated to limit the scan to replicated data. --- cli/cliflags/flags.go | 5 +++++ cli/context.go | 1 + cli/debug.go | 7 ++++--- cli/flags.go | 8 ++++++-- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/cli/cliflags/flags.go b/cli/cliflags/flags.go index c8272df4450a..6ddc3484f84c 100644 --- a/cli/cliflags/flags.go +++ b/cli/cliflags/flags.go @@ -349,4 +349,9 @@ defined in terms of multiples of this value.`, Name: "undo", Description: `Attempt to undo an earlier attempt to freeze the cluster.`, } + + Replicated = FlagInfo{ + Name: "replicated", + Description: "Restrict scan to replicated data.", + } ) diff --git a/cli/context.go b/cli/context.go index 945cb46f0f70..6bdde0be1868 100644 --- a/cli/context.go +++ b/cli/context.go @@ -144,4 +144,5 @@ type debugContext struct { startKey, endKey engine.MVCCKey values bool sizes bool + replicated bool } diff --git a/cli/debug.go b/cli/debug.go index 1357ed967323..a0f20334db49 100644 --- a/cli/debug.go +++ b/cli/debug.go @@ -152,8 +152,9 @@ var debugRangeDataCmd = &cobra.Command{ Use: "range-data [directory] range-id", Short: "dump all the data in a range", Long: ` -Pretty-prints all keys and values in a range. This includes all data covered -by the consistency checker. +Pretty-prints all keys and values in a range. By default, includes unreplicated +state like the raft HardState. With --replicated, only includes data covered by + the consistency checker. `, RunE: runDebugRangeData, } @@ -181,7 +182,7 @@ func runDebugRangeData(cmd *cobra.Command, args []string) error { return err } - iter := storage.NewReplicaDataIterator(&desc, db, true) + iter := storage.NewReplicaDataIterator(&desc, db, debugCtx.replicated) for ; iter.Valid(); iter.Next() { if _, err := printKeyValue(engine.MVCCKeyValue{ Key: iter.Key(), diff --git a/cli/flags.go b/cli/flags.go index a300312fd97d..56447d46ca56 100644 --- a/cli/flags.go +++ b/cli/flags.go @@ -51,8 +51,9 @@ var baseCtx = serverCtx.Context var cliCtx = cliContext{Context: baseCtx} var sqlCtx = sqlContext{cliContext: &cliCtx} var debugCtx = debugContext{ - startKey: engine.NilKey, - endKey: engine.MVCCKeyMax, + startKey: engine.NilKey, + endKey: engine.MVCCKeyMax, + replicated: false, } var cacheSize *bytesValue @@ -404,6 +405,9 @@ func init() { varFlag(f, (*mvccKey)(&debugCtx.endKey), cliflags.To) boolFlag(f, &debugCtx.values, cliflags.Values, false) boolFlag(f, &debugCtx.sizes, cliflags.Sizes, false) + + f = debugRangeDataCmd.Flags() + boolFlag(f, &debugCtx.replicated, cliflags.Replicated, false) } boolFlag(versionCmd.Flags(), &versionIncludesDeps, cliflags.Deps, false)