Skip to content

Commit

Permalink
Return nil instead of emptyTablet in groupi.Tablet() (#5469)
Browse files Browse the repository at this point in the history
groupi.Tablet returns error and empty Tablet when error is returned while querying zero for
Tablet serving info. Allocation of space by empty Tablet shows up in alloc_space profile.

         .          .    463:func (g *groupi) Tablet(key string) (*pb.Tablet, error) {
   16.22GB    16.22GB    464:	emptyTablet := pb.Tablet{}
         .          .    465:
         .          .    466:	// TODO: Remove all this later, create a membership state and apply it
         .          .    467:	g.RLock()
         .          .    468:	tablet, ok := g.tablets[key]
         .          .    469:	g.RUnlock()
         .          .    470:	if ok {
         .          .    471:		return tablet, nil
         .          .    472:	}
         .          .    473:
         .          .    474:	// We don't know about this tablet.
         .          .    475:	// Check with dgraphzero if we can serve it.
         .          .    476:	pl := g.connToZeroLeader()
         .          .    477:	zc := pb.NewZeroClient(pl.Get())
         .          .    478:
         .          .    479:	tablet = &pb.Tablet{GroupId: g.groupId(), Predicate: key}
         .     1.07MB    480:	out, err := zc.ShouldServe(context.Background(), tablet)
         .          .    481:	if err != nil {
         .          .    482:		glog.Errorf("Error while ShouldServe grpc call %v", err)
         .          .    483:		return &emptyTablet, err
         .          .    484:	}

This can be avoided. We can return nil instead of emptyTablet and save allocations here. Caller
function always checks for error first before accessing tablet information.
  • Loading branch information
ashish-goswami authored May 21, 2020
1 parent d1c9dfa commit 428f3bd
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions worker/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,6 @@ func (g *groupi) ServesTablet(key string) (bool, error) {

// Do not modify the returned Tablet
func (g *groupi) Tablet(key string) (*pb.Tablet, error) {
emptyTablet := pb.Tablet{}

// TODO: Remove all this later, create a membership state and apply it
g.RLock()
tablet, ok := g.tablets[key]
Expand All @@ -480,7 +478,7 @@ func (g *groupi) Tablet(key string) (*pb.Tablet, error) {
out, err := zc.ShouldServe(context.Background(), tablet)
if err != nil {
glog.Errorf("Error while ShouldServe grpc call %v", err)
return &emptyTablet, err
return nil, err
}

// Do not store tablets with group ID 0, as they are just dummy tablets for
Expand Down

0 comments on commit 428f3bd

Please sign in to comment.