Skip to content

Commit

Permalink
Change tablet size calculation to not depend on the right key.
Browse files Browse the repository at this point in the history
In badger, the right key might be a badger specific key that Dgraph
cannot understand. To deal with these keys, a table is included in
the size calculation if the next table starts with the same key.

Related to DGRAPH-1358 and #5408.
  • Loading branch information
martinmr committed Jun 15, 2020
1 parent 43330d9 commit e7832bf
Showing 1 changed file with 34 additions and 18 deletions.
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

0 comments on commit e7832bf

Please sign in to comment.