Use TCPHost when checking for existence of data node

Host is the http endpoint and is not really needed.
pull/5879/head
Jason Wilder 2016-03-01 12:25:53 -07:00
parent e3fef5593c
commit cd4ef1856b
2 changed files with 14 additions and 2 deletions

View File

@ -256,7 +256,7 @@ func (c *Client) CreateDataNode(httpAddr, tcpAddr string) (*NodeInfo, error) {
return nil, err
}
n, err := c.DataNodeByHTTPHost(httpAddr)
n, err := c.DataNodeByTCPHost(tcpAddr)
if err != nil {
return nil, err
}
@ -278,6 +278,18 @@ func (c *Client) DataNodeByHTTPHost(httpAddr string) (*NodeInfo, error) {
return nil, ErrNodeNotFound
}
// DataNodeByTCPHost returns the data node with the give http bind address
func (c *Client) DataNodeByTCPHost(tcpAddr string) (*NodeInfo, error) {
nodes, _ := c.DataNodes()
for _, n := range nodes {
if n.TCPHost == tcpAddr {
return &n, nil
}
}
return nil, ErrNodeNotFound
}
// DeleteDataNode deletes a data node from the cluster.
func (c *Client) DeleteDataNode(id uint64) error {
cmd := &internal.DeleteDataNodeCommand{

View File

@ -53,7 +53,7 @@ func (data *Data) DataNode(id uint64) *NodeInfo {
func (data *Data) CreateDataNode(host, tcpHost string) error {
// Ensure a node with the same host doesn't already exist.
for _, n := range data.DataNodes {
if n.Host == host {
if n.TCPHost == tcpHost {
return ErrNodeExists
}
}