Browse Source

Merge pull request #33 from xiangli-cmu/master

simplify start func
Xiang Li 12 years ago
parent
commit
fac8d66244
2 changed files with 11 additions and 9 deletions
  1. 9 5
      command.go
  2. 2 4
      etcd.go

+ 9 - 5
command.go

@@ -23,7 +23,7 @@ type SetCommand struct {
 
 
 // The name of the set command in the log
 // The name of the set command in the log
 func (c *SetCommand) CommandName() string {
 func (c *SetCommand) CommandName() string {
-	return "set"
+	return "etcd:set"
 }
 }
 
 
 // Set the key-value pair
 // Set the key-value pair
@@ -56,7 +56,7 @@ type GetCommand struct {
 
 
 // The name of the get command in the log
 // The name of the get command in the log
 func (c *GetCommand) CommandName() string {
 func (c *GetCommand) CommandName() string {
-	return "get"
+	return "etcd:get"
 }
 }
 
 
 // Get the value of key
 // Get the value of key
@@ -71,7 +71,7 @@ type DeleteCommand struct {
 
 
 // The name of the delete command in the log
 // The name of the delete command in the log
 func (c *DeleteCommand) CommandName() string {
 func (c *DeleteCommand) CommandName() string {
-	return "delete"
+	return "etcd:delete"
 }
 }
 
 
 // Delete the key
 // Delete the key
@@ -87,7 +87,7 @@ type WatchCommand struct {
 
 
 // The name of the watch command in the log
 // The name of the watch command in the log
 func (c *WatchCommand) CommandName() string {
 func (c *WatchCommand) CommandName() string {
-	return "watch"
+	return "etcd:watch"
 }
 }
 
 
 func (c *WatchCommand) Apply(server *raft.Server) (interface{}, error) {
 func (c *WatchCommand) Apply(server *raft.Server) (interface{}, error) {
@@ -113,7 +113,7 @@ type JoinCommand struct {
 
 
 // The name of the join command in the log
 // The name of the join command in the log
 func (c *JoinCommand) CommandName() string {
 func (c *JoinCommand) CommandName() string {
-	return "join"
+	return "etcd:join"
 }
 }
 
 
 // Join a server to the cluster
 // Join a server to the cluster
@@ -122,3 +122,7 @@ func (c *JoinCommand) Apply(raftServer *raft.Server) (interface{}, error) {
 	addMachine(c.Name, c.Hostname, c.RaftPort, c.ClientPort)
 	addMachine(c.Name, c.Hostname, c.RaftPort, c.ClientPort)
 	return []byte("join success"), err
 	return []byte("join success"), err
 }
 }
+
+func (c *JoinCommand) NodeName() string {
+	return c.Name
+}

+ 2 - 4
etcd.go

@@ -226,10 +226,11 @@ func startRaft(securityType int) {
 		}
 		}
 	}
 	}
 
 
-	raftServer.Initialize()
 	raftServer.SetElectionTimeout(ELECTIONTIMTOUT)
 	raftServer.SetElectionTimeout(ELECTIONTIMTOUT)
 	raftServer.SetHeartbeatTimeout(HEARTBEATTIMEOUT)
 	raftServer.SetHeartbeatTimeout(HEARTBEATTIMEOUT)
 
 
+	raftServer.Start()
+
 	// start to response to raft requests
 	// start to response to raft requests
 	go startRaftTransport(info.RaftPort, securityType)
 	go startRaftTransport(info.RaftPort, securityType)
 
 
@@ -237,7 +238,6 @@ func startRaft(securityType int) {
 
 
 		// start as a leader in a new cluster
 		// start as a leader in a new cluster
 		if len(cluster) == 0 {
 		if len(cluster) == 0 {
-			raftServer.StartLeader()
 
 
 			time.Sleep(time.Millisecond * 20)
 			time.Sleep(time.Millisecond * 20)
 
 
@@ -257,7 +257,6 @@ func startRaft(securityType int) {
 
 
 			// start as a follower in a existing cluster
 			// start as a follower in a existing cluster
 		} else {
 		} else {
-			raftServer.StartFollower(false)
 
 
 			time.Sleep(time.Millisecond * 20)
 			time.Sleep(time.Millisecond * 20)
 
 
@@ -292,7 +291,6 @@ func startRaft(securityType int) {
 
 
 	} else {
 	} else {
 		// rejoin the previous cluster
 		// rejoin the previous cluster
-		raftServer.StartFollower(true)
 		debug("%s restart as a follower", raftServer.Name())
 		debug("%s restart as a follower", raftServer.Name())
 	}
 	}