Skip to content

Commit

Permalink
Merge pull request #4458 from planetscale/ds-zk-dns
Browse files Browse the repository at this point in the history
remove code to resolve dns names while getting a connection to zookeeper, closes #4454
  • Loading branch information
sougou authored Dec 16, 2018
2 parents f4b5377 + 3f51b2c commit 17ccb2c
Showing 1 changed file with 1 addition and 29 deletions.
30 changes: 1 addition & 29 deletions go/vt/topo/zk2topo/zk_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"github.com/samuel/go-zookeeper/zk"
"golang.org/x/net/context"

"vitess.io/vitess/go/netutil"
"vitess.io/vitess/go/sync2"
"vitess.io/vitess/go/vt/log"
)
Expand Down Expand Up @@ -307,11 +306,7 @@ func (c *ZkConn) handleSessionEvents(conn *zk.Conn, session <-chan zk.Event) {

// dialZk dials the server, and waits until connection.
func dialZk(ctx context.Context, addr string) (*zk.Conn, <-chan zk.Event, error) {
servers, err := resolveZkAddr(addr)
if err != nil {
return nil, nil, err
}

servers := strings.Split(addr, ",")
options := zk.WithDialer(net.DialTimeout)
// If TLS is enabled use a TLS enabled dialer option
if *certPath != "" && *keyPath != "" {
Expand Down Expand Up @@ -376,26 +371,3 @@ func dialZk(ctx context.Context, addr string) (*zk.Conn, <-chan zk.Event, error)
}
}
}

// resolveZkAddr takes a comma-separated list of host:port addresses,
// and resolves the host to replace it with the IP address.
// If a resolution fails, the host is skipped.
// If no host can be resolved, an error is returned.
// This is different from the Zookeeper library, that insists on resolving
// *all* hosts successfully before it starts.
func resolveZkAddr(zkAddr string) ([]string, error) {
parts := strings.Split(zkAddr, ",")
resolved := make([]string, 0, len(parts))
for _, part := range parts {
// The Zookeeper client cannot handle IPv6 addresses before version 3.4.x.
if r, err := netutil.ResolveIPv4Addrs(part); err != nil {
log.Warningf("cannot resolve %v, will not use it: %v", part, err)
} else {
resolved = append(resolved, r...)
}
}
if len(resolved) == 0 {
return nil, fmt.Errorf("no valid address found in %v", zkAddr)
}
return resolved, nil
}

0 comments on commit 17ccb2c

Please sign in to comment.