Explorar o código

allow pervious machine to rejoin to the cluster without pervious log

Xiang Li %!s(int64=12) %!d(string=hai) anos
pai
achega
9b8c5b0527
Modificáronse 1 ficheiros con 7 adicións e 0 borrados
  1. 7 0
      command.go

+ 7 - 0
command.go

@@ -120,6 +120,13 @@ func (c *JoinCommand) CommandName() string {
 // Join a server to the cluster
 func (c *JoinCommand) Apply(raftServer *raft.Server) (interface{}, error) {
 
+	// check if the join command is from a previous machine, who lost all its previous log.
+	response, _ := etcdStore.RawGet(path.Join("_etcd/machines", c.Name))
+
+	if response != nil {
+		return []byte("join success"), nil
+	}
+
 	// check machine number in the cluster
 	num := machineNum()
 	if num == maxClusterSize {