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 697eb71
Showing 1 changed file with 32 additions and 20 deletions.
52 changes: 32 additions & 20 deletions dgraph/cmd/debug/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,28 +514,39 @@ 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()
if item.UserMeta()&posting.BitSchemaPosting > 0 {
// Schema is stored as pb.SchemaUpdate, we should not try to read it as a posting list
fmt.Fprintf(&buf, "Key: %x\n", item.Key())
schemaBytes, err := item.ValueCopy(nil)
x.Check(err)

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)
}
var s pb.SchemaUpdate
x.Check(s.Unmarshal(schemaBytes))
fmt.Fprintf(&buf, "Value: %+v\n", s)
} else {
fmt.Fprintf(&buf, "Key: %x", item.Key())
pl, err := posting.ReadPostingList(item.KeyCopy(nil), itr)
if err != nil {
log.Fatal(err)
}
fmt.Fprintf(&buf, " Length: %d", pl.Length(math.MaxUint64, 0))

err = pl.Iterate(math.MaxUint64, 0, func(o *pb.Posting) error {
appendPosting(&buf, o)
return nil
})
if err != nil {
log.Fatal(err)
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 All @@ -560,6 +571,7 @@ func printKeys(db *badger.DB) {
item := itr.Item()
pk, err := x.Parse(key)
x.Check(err)

var buf bytes.Buffer
// Don't use a switch case here. Because multiple of these can be true. In particular,
// IsSchema can be true alongside IsData.
Expand All @@ -582,7 +594,7 @@ func printKeys(db *badger.DB) {
x.Check2(buf.WriteString(fmt.Sprintf(" ns: %#x ", ns)))
x.Check2(buf.WriteString(" attr: " + attr))
if len(pk.Term) > 0 {
fmt.Fprintf(&buf, " term: [%d] %s ", pk.Term[0], pk.Term[1:])
fmt.Fprintf(&buf, " term: [%d] [%v] ", pk.Term[0], pk.Term[1:])
}
if pk.Uid > 0 {
fmt.Fprintf(&buf, " uid: %d ", pk.Uid)
Expand Down

0 comments on commit 697eb71

Please sign in to comment.