// SetCoordinator makes a new Node the cluster coordinator.
SetCoordinator makes a new Node the cluster coordinator.
// SetCoordinator makes a new Node the cluster coordinator .
func (api *API) SetCoordinator(ctx context.Context, id string) (oldNode, newNode *Node, err error) {
	span, _ := tracing.StartSpanFromContext(ctx, "API.SetCoordinator")
	defer span.Finish()
	if err := api.validate(apiSetCoordinator); err != nil {
		return nil, nil, errors.Wrap(err, "validating api method")
	}
	oldNode = api.cluster.nodeByID(api.cluster.Coordinator)
	newNode = api.cluster.nodeByID(id)
	if newNode == nil {
		return nil, nil, errors.Wrap(ErrNodeIDNotExists, "getting new node")
	}
	if newNode.ID == api.Node().ID {
		return oldNode, newNode, api.cluster.setCoordinator(newNode)
	}
	err = api.server.SendTo(
		newNode,
		&SetCoordinatorMessage{
			New: newNode,
		})
	if err != nil {
		return nil, nil, fmt.Errorf("problem sending SetCoordinator message: %s", err)
	}
	return oldNode, newNode, nil
}
func ( api * API ) SetCoordinator ( ctx context . Context , id string ) ( oldNode , newNode * Node , err error ) { span , _ := tracing . StartSpanFromContext ( ctx , " " ) defer span . Finish ( ) if err := api . validate ( apiSetCoordinator ) ; err != nil { return nil , nil , errors . Wrap ( err , " " ) } oldNode = api . cluster . nodeByID ( api . cluster . Coordinator ) newNode = api . cluster . nodeByID ( id ) if newNode == nil { return nil , nil , errors . Wrap ( ErrNodeIDNotExists , " " ) } if newNode . ID == api . Node ( ) . ID { return oldNode , newNode , api . cluster . setCoordinator ( newNode ) } err = api . server . SendTo ( newNode , & SetCoordinatorMessage { New : newNode , } ) if err != nil { return nil , nil , fmt . Errorf ( " " , err ) } return oldNode , newNode , nil }
SetCoordinator makes a new Node the cluster coordinator.
SetCoordinator makes a new Node the cluster coordinator .
// If the new coordinator is this node, do the SetCoordinator directly. // Send the set-coordinator message to new node.