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: Change tablet size calculation to not depend on the right key. #5656

Merged
merged 2 commits into from
Jun 16, 2020
Merged
Changes from 1 commit
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: 34 additions & 18 deletions worker/draft.go
Original file line number Diff line number Diff line change
Expand Up @@ -1240,38 +1240,54 @@ func (n *node) calculateTabletSizes() {
}
var total int64
tablets := make(map[string]*pb.Tablet)
updateSize := func(pred string, size int64) {
if pred == "" {
return
}

glog.Infof("Adding %v to table %v", size, pred)
if tablet, ok := tablets[pred]; ok {
tablet.Space += size
} else {
tablets[pred] = &pb.Tablet{
GroupId: n.gid,
Predicate: pred,
Space: size,
}
}
total += size
}

tableInfos := pstore.Tables(false)
previousLeft := ""
var previousSize int64
glog.V(2).Infof("Calculating tablet sizes. Found %d tables\n", len(tableInfos))
for _, tinfo := range tableInfos {
left, err := x.Parse(tinfo.Left)
if err != nil {
glog.V(3).Infof("Unable to parse key: %v", err)
continue
}
right, err := x.Parse(tinfo.Right)
if err != nil {
glog.V(3).Infof("Unable to parse key: %v", err)
continue
}
if left.Attr != right.Attr {
// Skip all tables not fully owned by one predicate.

if previousLeft != "" && left.Attr != previousLeft {
// Dgraph cannot depend on the right end of the table to know if the table belongs
// to a single predicate because there might be Badger-specific keys.
// Instead, Dgraph only counts the previous table if the current one belongs to the
// same predicate.
// We could later specifically iterate over these tables to get their estimated sizes.
previousLeft = left.Attr
previousSize = int64(tinfo.EstimatedSz)
glog.V(3).Info("Skipping table not owned by one predicate")
continue
}
pred := left.Attr
if tablet, ok := tablets[pred]; ok {
tablet.Space += int64(tinfo.EstimatedSz)
} else {
tablets[pred] = &pb.Tablet{
GroupId: n.gid,
Predicate: pred,
Space: int64(tinfo.EstimatedSz),
}
}
total += int64(tinfo.EstimatedSz)

updateSize(previousLeft, previousSize)
previousLeft = left.Attr
previousSize = int64(tinfo.EstimatedSz)
}
// The last table has not been counted. Assign it to the predicate at the left of the table.
updateSize(previousLeft, previousSize)

if len(tablets) == 0 {
glog.V(2).Infof("No tablets found.")
return
Expand Down