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

fix(debug): fix debug tool for schema keys #7939

Merged
merged 1 commit into from
Aug 21, 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
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