MCPcopy
hub / github.com/dgraph-io/dgraph / calculateTabletSizes

Method calculateTabletSizes

worker/draft.go:1601–1669  ·  view source on GitHub ↗

calculateTabletSizes updates the tablet sizes for the keys.

()

Source from the content-addressed store, hash-verified

1599
1600// calculateTabletSizes updates the tablet sizes for the keys.
1601func (n *node) calculateTabletSizes() {
1602 if !n.AmLeader() {
1603 // Only leader sends the tablet size updates to Zero. No one else does.
1604 return
1605 }
1606 var total int64
1607 tablets := make(map[string]*pb.Tablet)
1608 updateSize := func(tinfo badger.TableInfo) {
1609 // The error has already been checked by caller.
1610 left, _ := x.Parse(tinfo.Left)
1611 pred := left.Attr
1612 if pred == "" {
1613 return
1614 }
1615 if tablet, ok := tablets[pred]; ok {
1616 tablet.OnDiskBytes += int64(tinfo.OnDiskSize)
1617 tablet.UncompressedBytes += int64(tinfo.UncompressedSize)
1618 } else {
1619 tablets[pred] = &pb.Tablet{
1620 GroupId: n.gid,
1621 Predicate: pred,
1622 OnDiskBytes: int64(tinfo.OnDiskSize),
1623 UncompressedBytes: int64(tinfo.UncompressedSize),
1624 }
1625 }
1626 total += int64(tinfo.OnDiskSize)
1627 }
1628
1629 tableInfos := pstore.Tables()
1630 glog.V(2).Infof("Calculating tablet sizes. Found %d tables\n", len(tableInfos))
1631 for _, tinfo := range tableInfos {
1632 left, err := x.Parse(tinfo.Left)
1633 if err != nil {
1634 glog.V(3).Infof("Unable to parse key: %v", err)
1635 continue
1636 }
1637 right, err := x.Parse(tinfo.Right)
1638 if err != nil {
1639 glog.V(3).Infof("Unable to parse key: %v", err)
1640 continue
1641 }
1642
1643 // Count the table only if it is occupied by a single predicate.
1644 if left.Attr == right.Attr {
1645 updateSize(tinfo)
1646 } else {
1647 glog.V(3).Info("Skipping table not owned by one predicate")
1648 }
1649 }
1650
1651 if len(tablets) == 0 {
1652 glog.V(2).Infof("No tablets found.")
1653 return
1654 }
1655 // Update Zero with the tablet sizes. If Zero sees a tablet which does not belong to
1656 // this group, it would send instruction to delete that tablet. There's an edge case
1657 // here if the followers are still running Rollup, and happen to read a key before and
1658 // write after the tablet deletion, causing that tablet key to resurface. Then, only the

Callers 1

processTabletSizesMethod · 0.95

Calls 7

AmLeaderMethod · 0.95
ParseFunction · 0.92
groupsFunction · 0.85
InfofMethod · 0.80
InfoMethod · 0.80
doSendMembershipMethod · 0.80
WarningfMethod · 0.80

Tested by

no test coverage detected