change getMachines

release-0.4
Xiang Li 2013-08-19 13:42:00 -07:00
parent 64e6d54758
commit 49c160b50c
4 changed files with 6 additions and 14 deletions

View File

@ -212,7 +212,7 @@ func (c *RemoveCommand) Apply(raftServer *raft.Server) (interface{}, error) {
if c.Name == raftServer.Name() {
// the removed node is this node
// if the node is not replying the previous logs
// if the node is not replaying the previous logs
// and the node has sent out a join request in this
// start. It is sure that this node received a new remove
// command and need to be removed
@ -220,7 +220,7 @@ func (c *RemoveCommand) Apply(raftServer *raft.Server) (interface{}, error) {
debugf("server [%s] is removed", raftServer.Name())
os.Exit(0)
} else {
// the node is replying previous logs and there is a join command
// the node is replaying previous logs and there is a join command
// afterwards, we should not exit
if r.joinIndex == 0 {

View File

@ -189,7 +189,7 @@ func LeaderHttpHandler(w http.ResponseWriter, req *http.Request) error {
// Handler to return all the known machines in the current cluster
func MachinesHttpHandler(w http.ResponseWriter, req *http.Request) error {
machines := getMachines(true)
machines := getMachines(nameToEtcdURL)
w.WriteHeader(http.StatusOK)
w.Write([]byte(strings.Join(machines, ", ")))

View File

@ -8,22 +8,14 @@ func machineNum() int {
}
// getMachines gets the current machines in the cluster
func getMachines(etcd bool) []string {
func getMachines(toURL func(string) (string, bool)) []string {
peers := r.Peers()
machines := make([]string, len(peers)+1)
var toURL func(string) (string, bool)
if etcd {
toURL = nameToEtcdURL
} else {
toURL = nameToRaftURL
}
leader, ok := toURL(r.Leader())
self := e.url
self, _ := toURL(r.Name())
i := 1
if ok {

View File

@ -82,7 +82,7 @@ func (r *raftServer) ListenAndServe() {
} else {
if r.pendingJoin {
cluster = getMachines(false)
cluster = getMachines(nameToRaftURL)
for i := 0; i < len(cluster); i++ {
u, err := url.Parse(cluster[i])
if err != nil {