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

feat(debug): add parse_key to debug tool #7640

Merged
merged 1 commit into from
Aug 24, 2023
Merged
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
31 changes: 31 additions & 0 deletions dgraph/cmd/debug/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type flagOptions struct {
noKeys bool
key x.Sensitive
onlySummary bool
parseKey string

// Options related to the WAL.
wdir string
Expand Down Expand Up @@ -114,6 +115,7 @@ func init() {
flag.StringVarP(&opt.wsetSnapshot, "snap", "s", "",
"Set snapshot term,index,readts to this. Value must be comma-separated list containing"+
" the value for these vars in that order.")
flag.StringVar(&opt.parseKey, "parse_key", "", "Parse hex key.")
ee.RegisterEncFlag(flag)
}

Expand Down Expand Up @@ -949,6 +951,35 @@ func run() {
}
}()

if opt.parseKey != "" {
k, err := hex.DecodeString(opt.parseKey)
if err != nil {
log.Fatalf("error while decoding hex key: %v\n", err)
}
pk, err := x.Parse(k)
if err != nil {
log.Fatalf("error while parsing key: %v\n", err)
}
if pk.IsData() {
fmt.Printf("{d}")
}
if pk.IsIndex() {
fmt.Printf("{i}")
}
if pk.IsCountOrCountRev() {
fmt.Printf("{c}")
}
if pk.IsSchema() {
fmt.Printf("{s}")
}
if pk.IsReverse() {
fmt.Printf("{r}")
}
fmt.Printf(" Key: %+v\n", pk)
return
}

var err error
dir := opt.pdir
isWal := false
if len(dir) == 0 {
Expand Down