mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
change getMachines
This commit is contained in:
parent
64e6d54758
commit
49c160b50c
@ -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 {
|
||||
|
@ -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, ", ")))
|
||||
|
12
machines.go
12
machines.go
@ -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 {
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user