Skip to content

Commit

Permalink
Fix: Change tablet size calculation to not depend on the right key. (#…
Browse files Browse the repository at this point in the history
…5656)

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 16, 2020
1 parent 5e89162 commit 785ee0c
Showing 1 changed file with 31 additions and 19 deletions.
50 changes: 31 additions & 19 deletions worker/draft.go
Original file line number Diff line number Diff line change
Expand Up @@ -1197,38 +1197,50 @@ func (n *node) calculateTabletSizes() {
}
var total int64
tablets := make(map[string]*pb.Tablet)
updateSize := func(pred string, size int64) {
if pred == "" {
return
}

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 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.
glog.V(2).Info("Skipping table not owned by one predicate")
continue
}
pred := left.Attr
if tablet, ok := tablets[pred]; ok {
tablet.Space += int64(tinfo.EstimatedSz)
updateSize(previousLeft, previousSize)
} else {
tablets[pred] = &pb.Tablet{
GroupId: n.gid,
Predicate: pred,
Space: int64(tinfo.EstimatedSz),
}
glog.V(3).Info("Skipping table not owned by one predicate")
}
total += int64(tinfo.EstimatedSz)
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 785ee0c

Please sign in to comment.