ShouldServe returns the tablet serving the predicate passed in the request.
( ctx context.Context, tablet *pb.Tablet)
| 678 | |
| 679 | // ShouldServe returns the tablet serving the predicate passed in the request. |
| 680 | func (s *Server) ShouldServe( |
| 681 | ctx context.Context, tablet *pb.Tablet) (resp *pb.Tablet, err error) { |
| 682 | ctx, span := otel.Tracer("").Start(ctx, "Zero.ShouldServe") |
| 683 | defer span.End() |
| 684 | |
| 685 | if tablet.Predicate == "" { |
| 686 | return resp, errors.Errorf("Tablet predicate is empty in %+v", tablet) |
| 687 | } |
| 688 | if tablet.GroupId == 0 && !tablet.ReadOnly { |
| 689 | return resp, errors.Errorf("Group ID is Zero in %+v", tablet) |
| 690 | } |
| 691 | |
| 692 | // Check who is serving this tablet. |
| 693 | tab := s.ServingTablet(tablet.Predicate) |
| 694 | span.SetAttributes(attribute.String("tablet_predicate", tablet.Predicate)) |
| 695 | if tab != nil && !tablet.Force { |
| 696 | // Someone is serving this tablet. Could be the caller as well. |
| 697 | // The caller should compare the returned group against the group it holds to check who's |
| 698 | // serving. |
| 699 | return tab, nil |
| 700 | } |
| 701 | |
| 702 | // Read-only requests should return an empty tablet instead of asking zero |
| 703 | // to serve the predicate. |
| 704 | if tablet.ReadOnly { |
| 705 | return &pb.Tablet{}, nil |
| 706 | } |
| 707 | |
| 708 | // Set the tablet to be served by this server's group. |
| 709 | var proposal pb.ZeroProposal |
| 710 | |
| 711 | if x.IsReservedPredicate(tablet.Predicate) { |
| 712 | // Force all the reserved predicates to be allocated to group 1. |
| 713 | // This is to make it easier to stream ACL updates to all alpha servers |
| 714 | // since they only need to open one pipeline to receive updates for all |
| 715 | // ACL predicates. |
| 716 | // This will also make it easier to restore the reserved predicates after |
| 717 | // a DropAll operation. |
| 718 | tablet.GroupId = 1 |
| 719 | } |
| 720 | proposal.Tablet = tablet |
| 721 | if err := s.Node.proposeAndWait(ctx, &proposal); err != nil && err != errTabletAlreadyServed { |
| 722 | span.AddEvent(fmt.Sprintf("Error proposing tablet: %+v. Error: %v", &proposal, err)) |
| 723 | return tablet, err |
| 724 | } |
| 725 | tab = s.ServingTablet(tablet.Predicate) |
| 726 | x.AssertTrue(tab != nil) |
| 727 | span.SetAttributes(attribute.String("tablet_predicate_served", tablet.Predicate)) |
| 728 | return tab, nil |
| 729 | } |
| 730 | |
| 731 | // UpdateMembership updates the membership of the given group. |
| 732 | func (s *Server) UpdateMembership(ctx context.Context, group *pb.Group) (*api.Payload, error) { |
nothing calls this directly
no test coverage detected