MoveTablet can be used to move a tablet to a specific group. It takes in tablet and destination group as argument. It returns a *pb.Status to be used by the `/moveTablet` HTTP handler in Zero.
(ctx context.Context, req *pb.MoveTabletRequest)
| 67 | // It takes in tablet and destination group as argument. |
| 68 | // It returns a *pb.Status to be used by the `/moveTablet` HTTP handler in Zero. |
| 69 | func (s *Server) MoveTablet(ctx context.Context, req *pb.MoveTabletRequest) (*pb.Status, error) { |
| 70 | if !s.Node.AmLeader() { |
| 71 | return &pb.Status{Code: 1, Msg: x.Error}, errNotLeader |
| 72 | } |
| 73 | |
| 74 | knownGroups := s.KnownGroups() |
| 75 | var isKnown bool |
| 76 | for _, grp := range knownGroups { |
| 77 | if grp == req.DstGroup { |
| 78 | isKnown = true |
| 79 | break |
| 80 | } |
| 81 | } |
| 82 | if !isKnown { |
| 83 | return &pb.Status{Code: 1, Msg: x.ErrorInvalidRequest}, |
| 84 | fmt.Errorf("group: [%d] is not a known group", req.DstGroup) |
| 85 | } |
| 86 | |
| 87 | tablet := x.NamespaceAttr(req.Namespace, req.Tablet) |
| 88 | tab := s.ServingTablet(tablet) |
| 89 | if tab == nil { |
| 90 | return &pb.Status{Code: 1, Msg: x.ErrorInvalidRequest}, |
| 91 | fmt.Errorf("namespace: %d. No tablet found for: %s", req.Namespace, req.Tablet) |
| 92 | } |
| 93 | |
| 94 | srcGroup := tab.GroupId |
| 95 | if srcGroup == req.DstGroup { |
| 96 | return &pb.Status{Code: 1, Msg: x.ErrorInvalidRequest}, |
| 97 | fmt.Errorf("namespace: %d. Tablet: [%s] is already being served by group: [%d]", |
| 98 | req.Namespace, req.Tablet, srcGroup) |
| 99 | } |
| 100 | |
| 101 | if err := s.movePredicate(tablet, srcGroup, req.DstGroup); err != nil { |
| 102 | glog.Errorf("namespace: %d. While moving predicate %s from %d -> %d. Error: %v", |
| 103 | req.Namespace, req.Tablet, srcGroup, req.DstGroup, err) |
| 104 | return &pb.Status{Code: 1, Msg: x.Error}, err |
| 105 | } |
| 106 | |
| 107 | return &pb.Status{Code: 0, Msg: fmt.Sprintf("namespace: %d. "+ |
| 108 | "Predicate: [%s] moved from group [%d] to [%d]", req.Namespace, req.Tablet, srcGroup, |
| 109 | req.DstGroup)}, nil |
| 110 | } |
| 111 | |
| 112 | // movePredicate is the main entry point for move predicate logic. This Zero must remain the leader |
| 113 | // for the entire duration of predicate move. If this Zero stops being the leader, the final |
nothing calls this directly
no test coverage detected