aboutsummaryrefslogtreecommitdiff
path: root/weed/shell/command_cluster_raft_add.go
diff options
context:
space:
mode:
authorKonstantin Lebedev <9497591+kmlebedev@users.noreply.github.com>2022-04-11 10:50:01 +0500
committerKonstantin Lebedev <9497591+kmlebedev@users.noreply.github.com>2022-04-11 10:50:01 +0500
commit931cb9e5818b202c3855321c9b12a6149d121ffa (patch)
treed3ef08ee15dd8fe05e6ce8f008dd2f6e472a6167 /weed/shell/command_cluster_raft_add.go
parentd2fe0fae33f66e356cadd6096daa24d37e87df6d (diff)
downloadseaweedfs-931cb9e5818b202c3855321c9b12a6149d121ffa.tar.xz
seaweedfs-931cb9e5818b202c3855321c9b12a6149d121ffa.zip
use "cluster.raft.{ps,add,remove}"
Diffstat (limited to 'weed/shell/command_cluster_raft_add.go')
-rw-r--r--weed/shell/command_cluster_raft_add.go59
1 files changed, 59 insertions, 0 deletions
diff --git a/weed/shell/command_cluster_raft_add.go b/weed/shell/command_cluster_raft_add.go
new file mode 100644
index 000000000..e5f3c41c9
--- /dev/null
+++ b/weed/shell/command_cluster_raft_add.go
@@ -0,0 +1,59 @@
+package shell
+
+import (
+ "context"
+ "flag"
+ "fmt"
+ "github.com/chrislusf/seaweedfs/weed/pb/master_pb"
+ "io"
+)
+
+func init() {
+ Commands = append(Commands, &commandRaftServerAdd{})
+}
+
+type commandRaftServerAdd struct {
+}
+
+func (c *commandRaftServerAdd) Name() string {
+ return "cluster.raft.add"
+}
+
+func (c *commandRaftServerAdd) Help() string {
+ return `add a server to the raft cluster
+
+ Example:
+ cluster.raft.add -id <server_name> -address <server_host:port> -voter
+`
+}
+
+func (c *commandRaftServerAdd) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
+
+ raftServerAddCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
+ serverId := raftServerAddCommand.String("id", "", "server id")
+ serverAddress := raftServerAddCommand.String("address", "", "server grpc address")
+ serverVoter := raftServerAddCommand.Bool("voter", true, "assign it a vote")
+ if err = raftServerAddCommand.Parse(args); err != nil {
+ return nil
+ }
+
+ if *serverId == "" || *serverAddress == "" {
+ return fmt.Errorf("empty server id or address")
+ }
+
+ err = commandEnv.MasterClient.WithClient(false, func(client master_pb.SeaweedClient) error {
+ _, err := client.RaftAddServer(context.Background(), &master_pb.RaftAddServerRequest{
+ Id: *serverId,
+ Address: *serverAddress,
+ Voter: *serverVoter,
+ })
+ if err != nil {
+ return fmt.Errorf("raft add server: %v", err)
+ }
+ println("added server", *serverId)
+ return nil
+ })
+
+ return err
+
+}