Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove code to resolve dns names while getting a connection to zookeeper, closes #4454 #4458

Merged
merged 1 commit into from
Dec 16, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}