You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
package cluster
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/rqlite/rqlite/command"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Control is an interface for interacting with a cluster.
|
|
|
|
type Control interface {
|
|
|
|
WaitForLeader(time.Duration) (string, error)
|
|
|
|
WaitForRemoval(string, time.Duration) error
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remover executes a node-removal operation.
|
|
|
|
type Remover struct {
|
|
|
|
timeout time.Duration
|
|
|
|
control Control
|
|
|
|
client *Client
|
|
|
|
}
|
|
|
|
|
|
|
|
// / NewRemover returns an instantiated Remover.
|
|
|
|
func NewRemover(client *Client, timeout time.Duration, control Control) *Remover {
|
|
|
|
return &Remover{
|
|
|
|
client: client,
|
|
|
|
timeout: timeout,
|
|
|
|
control: control,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do executes the node-removal operation.
|
|
|
|
func (r *Remover) Do(id string, confirm bool) error {
|
|
|
|
laddr, err := r.control.WaitForLeader(r.timeout)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
rn := &command.RemoveNodeRequest{
|
|
|
|
Id: id,
|
|
|
|
}
|
|
|
|
if err := r.client.RemoveNode(rn, laddr, nil, r.timeout); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if confirm {
|
|
|
|
if err := r.control.WaitForRemoval(id, r.timeout); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|