Skip to content

Commit

Permalink
Fix badger.info: prefix should be parsed as hex before using.
Browse files Browse the repository at this point in the history
  • Loading branch information
manishrjain committed May 29, 2019
1 parent 1725096 commit d9620c8
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions badger/cmd/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,16 @@ func handleInfo(cmd *cobra.Command, args []string) error {
tableInfo(sstDir, vlogDir, db)
}

prefix, err := hex.DecodeString(opt.withPrefix)
if err != nil {
return errors.Wrapf(err, "failed to decode hex prefix: %s", opt.withPrefix)
}
if opt.showHistogram {
db.PrintHistogram([]byte(opt.withPrefix))
db.PrintHistogram(prefix)
}

if opt.showKeys {
if err := showKeys(db, opt.withPrefix); err != nil {
if err := showKeys(db, prefix); err != nil {
return err
}
}
Expand All @@ -117,9 +121,9 @@ func handleInfo(cmd *cobra.Command, args []string) error {
return nil
}

func showKeys(db *badger.DB, prefix string) error {
func showKeys(db *badger.DB, prefix []byte) error {
if len(prefix) > 0 {
fmt.Printf("Only choosing keys with prefix: \n%s", hex.Dump([]byte(prefix)))
fmt.Printf("Only choosing keys with prefix: \n%s", hex.Dump(prefix))
}
txn := db.NewTransaction(false)
defer txn.Discard()
Expand Down

0 comments on commit d9620c8

Please sign in to comment.