seaweedfs/weed/shell/command_cluster_raft_remove.go

61 lines
1.3 KiB
Go
Raw Normal View History

2022-04-06 18:23:53 +08:00
package shell
import (
"context"
"flag"
"fmt"
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
2022-04-06 18:23:53 +08:00
"io"
)
func init() {
Commands = append(Commands, &commandRaftServerRemove{})
}
type commandRaftServerRemove struct {
}
func (c *commandRaftServerRemove) Name() string {
2022-04-11 13:50:01 +08:00
return "cluster.raft.remove"
2022-04-06 18:23:53 +08:00
}
func (c *commandRaftServerRemove) Help() string {
return `remove a server from the raft cluster
Example:
2022-04-11 13:50:01 +08:00
cluster.raft.remove -id <server_name>
2022-04-06 18:23:53 +08:00
`
}
func (c *commandRaftServerRemove) IsResourceHeavy() bool {
return false
}
2022-04-06 18:23:53 +08:00
func (c *commandRaftServerRemove) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
raftServerAddCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
serverId := raftServerAddCommand.String("id", "", "server id")
if err = raftServerAddCommand.Parse(args); err != nil {
return nil
}
if *serverId == "" {
return fmt.Errorf("empty server id")
}
err = commandEnv.MasterClient.WithClient(false, func(client master_pb.SeaweedClient) error {
_, err := client.RaftRemoveServer(context.Background(), &master_pb.RaftRemoveServerRequest{
2022-04-07 18:31:37 +08:00
Id: *serverId,
Force: true,
2022-04-06 18:23:53 +08:00
})
if err != nil {
return fmt.Errorf("raft remove server: %v", err)
}
println("removed server", *serverId)
return nil
})
return err
}