Skip to content

Commit

Permalink
fix(debug): fix debug tool for schema keys
Browse files Browse the repository at this point in the history
  • Loading branch information
mangalaman93 committed Aug 21, 2023
1 parent 28ac6c2 commit c2937c0
Showing 1 changed file with 31 additions and 19 deletions.
50 changes: 31 additions & 19 deletions dgraph/cmd/debug/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,28 +514,40 @@ func lookup(db *badger.DB) {
return
}

item := itr.Item()
pl, err := posting.ReadPostingList(item.KeyCopy(nil), itr)
if err != nil {
log.Fatal(err)
}
var buf bytes.Buffer
fmt.Fprintf(&buf, " Key: %x", item.Key())
fmt.Fprintf(&buf, " Length: %d", pl.Length(math.MaxUint64, 0))
item := itr.Item()

splits := pl.PartSplits()
isMultiPart := len(splits) > 0
fmt.Fprintf(&buf, " Is multi-part list? %v", isMultiPart)
if isMultiPart {
fmt.Fprintf(&buf, " Start UID of parts: %v\n", splits)
}
fmt.Fprintf(&buf, "Key: %x\n", item.Key())
pk, err := x.Parse(item.Key())
x.Check(err)
fmt.Fprintf(&buf, "Parsed Key: %+v\n", pk)

err = pl.Iterate(math.MaxUint64, 0, func(o *pb.Posting) error {
appendPosting(&buf, o)
return nil
})
if err != nil {
log.Fatal(err)
// Schema is stored as pb.SchemaUpdate, we should not try to read it as a posting list.
if item.UserMeta()&posting.BitSchemaPosting > 0 {
schemaBytes, err := item.ValueCopy(nil)
x.Check(err)
fmt.Fprintf(&buf, "Value: %s\n", schemaBytes)
} else {
pl, err := posting.ReadPostingList(item.KeyCopy(nil), itr)
if err != nil {
log.Fatal(err)
}
fmt.Fprintf(&buf, " Length: %d", pl.Length(math.MaxUint64, 0))

splits := pl.PartSplits()
isMultiPart := len(splits) > 0
fmt.Fprintf(&buf, " Is multi-part list? %v", isMultiPart)
if isMultiPart {
fmt.Fprintf(&buf, " Start UID of parts: %v\n", splits)
}

err = pl.Iterate(math.MaxUint64, 0, func(o *pb.Posting) error {
appendPosting(&buf, o)
return nil
})
if err != nil {
log.Fatal(err)
}
}
fmt.Println(buf.String())
}
Expand Down

0 comments on commit c2937c0

Please sign in to comment.