ProposeConfChange proposes a Raft configuration change (add, remove, or update a node) and blocks until it is committed or the context expires. It is used by both the conn package internally and by the zero package (for address reconciliation via ConfChangeUpdateNode).
(ctx context.Context, conf raftpb.ConfChange)
| 562 | // It is used by both the conn package internally and by the zero package |
| 563 | // (for address reconciliation via ConfChangeUpdateNode). |
| 564 | func (n *Node) ProposeConfChange(ctx context.Context, conf raftpb.ConfChange) error { |
| 565 | cctx, cancel := context.WithTimeout(ctx, 3*time.Second) |
| 566 | defer cancel() |
| 567 | |
| 568 | ch := make(chan error, 1) |
| 569 | id := n.storeConfChange(ch) |
| 570 | // TODO: Delete id from the map. |
| 571 | conf.ID = id |
| 572 | if err := n.Raft().ProposeConfChange(cctx, conf); err != nil { |
| 573 | if cctx.Err() != nil { |
| 574 | return errInternalRetry |
| 575 | } |
| 576 | glog.Warningf("Error while proposing conf change: %v", err) |
| 577 | return err |
| 578 | } |
| 579 | select { |
| 580 | case err := <-ch: |
| 581 | return err |
| 582 | case <-ctx.Done(): |
| 583 | return ctx.Err() |
| 584 | case <-cctx.Done(): |
| 585 | return errInternalRetry |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | func (n *Node) addToCluster(ctx context.Context, rc *pb.RaftContext) error { |
| 590 | pid := rc.Id |
no test coverage detected