handleTablet will check if the given tablet is served by any group. If not the tablet will be added to the current group predicate list This function doesn't take any locks. It is the calling functions responsibility to manage the concurrency.
(tablet *pb.Tablet)
| 311 | // This function doesn't take any locks. |
| 312 | // It is the calling functions responsibility to manage the concurrency. |
| 313 | func (n *node) handleTablet(tablet *pb.Tablet) error { |
| 314 | state := n.server.state |
| 315 | if tablet.GroupId == 0 { |
| 316 | return errors.Errorf("Tablet group id is zero: %+v", tablet) |
| 317 | } |
| 318 | group := state.Groups[tablet.GroupId] |
| 319 | if tablet.Remove { |
| 320 | glog.Infof("Removing tablet for attr: [%v], gid: [%v]\n", tablet.Predicate, tablet.GroupId) |
| 321 | if group != nil { |
| 322 | delete(group.Tablets, tablet.Predicate) |
| 323 | } |
| 324 | return nil |
| 325 | } |
| 326 | if group == nil { |
| 327 | group = newGroup() |
| 328 | state.Groups[tablet.GroupId] = group |
| 329 | } |
| 330 | |
| 331 | // There's a edge case that we're handling. |
| 332 | // Two servers ask to serve the same tablet, then we need to ensure that |
| 333 | // only the first one succeeds. |
| 334 | if prev := n.server.servingTablet(tablet.Predicate); prev != nil { |
| 335 | if tablet.Force { |
| 336 | originalGroup := state.Groups[prev.GroupId] |
| 337 | delete(originalGroup.Tablets, tablet.Predicate) |
| 338 | } else if prev.GroupId != tablet.GroupId { |
| 339 | glog.Infof( |
| 340 | "Tablet for attr: [%s], gid: [%d] already served by group: [%d]\n", |
| 341 | prev.Predicate, tablet.GroupId, prev.GroupId) |
| 342 | return errTabletAlreadyServed |
| 343 | } |
| 344 | } |
| 345 | tablet.Force = false |
| 346 | group.Tablets[tablet.Predicate] = tablet |
| 347 | return nil |
| 348 | } |
| 349 | |
| 350 | func (n *node) handleTabletProposal(tablet *pb.Tablet) error { |
| 351 | n.server.AssertLock() |
no test coverage detected