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

Return nil instead of emptyTablet in groupi.Tablet() #5469

Merged
merged 1 commit into from
May 21, 2020

Conversation

ashish-goswami
Copy link
Contributor

@ashish-goswami ashish-goswami commented May 19, 2020

groupi.Tablet() returns error and empty Tablet when error is returned while querying zero for Tablet
serving info. This results in allocation of space by empty Tablet and it 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.


This change is Reviewable

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.
Copy link
Contributor

@harshil-goel harshil-goel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewable status: 0 of 1 files reviewed, all discussions resolved (waiting on @manishrjain and @vvbalaji-dgraph)

Copy link
Contributor

@jarifibrahim jarifibrahim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm: The change looks fine to me but please get it approved by @manishrjain as well.

Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @ashish-goswami, @manishrjain, and @vvbalaji-dgraph)


worker/groups.go, line 462 at r1 (raw file):

}

// Do not modify the returned Tablet

We should check why this comment was added. Maybe this comment is no longer valid.

Copy link
Contributor

@manishrjain manishrjain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 1 of 1 files at r1.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @ashish-goswami and @vvbalaji-dgraph)

@ashish-goswami ashish-goswami merged commit 428f3bd into master May 21, 2020
@ashish-goswami ashish-goswami deleted the ashish/tablet branch May 21, 2020 04:15
ashish-goswami added a commit that referenced this pull request May 26, 2020
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.

(cherry picked from commit 428f3bd)
ashish-goswami added a commit that referenced this pull request May 26, 2020
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.

(cherry picked from commit 428f3bd)
dna2github pushed a commit to dna2fork/dgraph that referenced this pull request Jul 18, 2020
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants