Skip to content

Commit

Permalink
Merge pull request xcat2#40 from chenglch/etcdbug
Browse files Browse the repository at this point in the history
List all of the nodes even though the goconserver host is down
  • Loading branch information
chenglch authored May 30, 2018
2 parents a081955 + 1232f51 commit 6f05add
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
5 changes: 4 additions & 1 deletion console/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,22 +146,24 @@ func serverHandshake(conn net.Conn) (*Node, error) {
}
b, err := common.Network.ReceiveBytesTimeout(conn, n, clientTimeout)
if err != nil {
conn.Close()
plog.Error(err)
return nil, err
}
plog.Debug(fmt.Sprintf("Receive connection from client: %s", string(b)))
if err := json.Unmarshal(b, &m); err != nil {
defer conn.Close()
tempErr := err
plog.Error(err)
err = sendProtoMessage(conn, err.Error(), ACTION_SESSION_ERROR, clientTimeout)
if err != nil {
plog.ErrorNode(name, err)
return nil, err
}
conn.Close()
return nil, tempErr
}
if m.Action != ACTION_SESSION_START || m.Node == "" {
conn.Close()
return nil, common.ErrConnection
}
name = m.Node
Expand All @@ -179,6 +181,7 @@ func serverHandshake(conn net.Conn) (*Node, error) {
}
err = redirect(conn, name)
if err != nil {
conn.Close()
return nil, err
}
return nil, nil
Expand Down
18 changes: 5 additions & 13 deletions storage/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ func (self *EtcdStorage) keepalive(ready chan<- struct{}) {
}

func (self *EtcdStorage) GetEndpoint(vhost string) (*EndpointConfig, error) {
fmt.Println(EtcdKeyJoin(ENDPOINT_PREFIX, vhost))
b, err := self.client.Get(EtcdKeyJoin(ENDPOINT_PREFIX, vhost))
if err != nil {
return nil, err
Expand Down Expand Up @@ -155,21 +154,14 @@ func (self *EtcdStorage) GetNodeCountEachHost() (map[string]int, error) {
}

func (self *EtcdStorage) ListNodeWithHost() (map[string]string, error) {
hosts, err := self.GetVhosts()
nodeToHost := make(map[string]string)
resp, err := self.client.Keys(EtcdKeyJoin(NODE_PREFIX))
if err != nil {
plog.Error(err)
return nil, err
}
nodeToHost := make(map[string]string)
for host, _ := range hosts {
resp, err := self.client.Keys(EtcdKeyJoin(NODE_PREFIX, host))
if err != nil {
return nil, err
}
for _, k := range resp {
temp := strings.Split(string(k), "/")
nodeToHost[temp[len(temp)-1]] = host
}
for _, k := range resp {
temp := strings.Split(string(k), "/")
nodeToHost[temp[len(temp)-1]] = temp[len(temp)-2]
}
return nodeToHost, nil
}
Expand Down

0 comments on commit 6f05add

Please sign in to comment.