You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.2 KiB

  1. package shell
  2. import (
  3. "context"
  4. "flag"
  5. "fmt"
  6. "github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
  7. "io"
  8. )
  9. func init() {
  10. Commands = append(Commands, &commandRaftServerRemove{})
  11. }
  12. type commandRaftServerRemove struct {
  13. }
  14. func (c *commandRaftServerRemove) Name() string {
  15. return "cluster.raft.remove"
  16. }
  17. func (c *commandRaftServerRemove) Help() string {
  18. return `remove a server from the raft cluster
  19. Example:
  20. cluster.raft.remove -id <server_name>
  21. `
  22. }
  23. func (c *commandRaftServerRemove) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  24. raftServerAddCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
  25. serverId := raftServerAddCommand.String("id", "", "server id")
  26. if err = raftServerAddCommand.Parse(args); err != nil {
  27. return nil
  28. }
  29. if *serverId == "" {
  30. return fmt.Errorf("empty server id")
  31. }
  32. err = commandEnv.MasterClient.WithClient(false, func(client master_pb.SeaweedClient) error {
  33. _, err := client.RaftRemoveServer(context.Background(), &master_pb.RaftRemoveServerRequest{
  34. Id: *serverId,
  35. Force: true,
  36. })
  37. if err != nil {
  38. return fmt.Errorf("raft remove server: %v", err)
  39. }
  40. println("removed server", *serverId)
  41. return nil
  42. })
  43. return err
  44. }