Compare commits

...

10 Commits

Author SHA1 Message Date
Yicheng Qin 5dcbb998f1 *: bump to v2.1.3+git 2015-09-03 13:33:49 -07:00
Yicheng Qin 30801de468 *: bump to v2.1.3 2015-09-03 13:33:27 -07:00
Yicheng Qin dbac8c8f42 etcdmain: check error before assigning peer transport
Or it may panic when new transport fails, e.g., TLS info is invalid.
2015-09-03 13:22:19 -07:00
Yicheng Qin 151c18d650 *: bump to v2.1.2+git 2015-08-21 16:20:16 -07:00
Yicheng Qin ff8d1ecb9f *: bump to v2.1.2 2015-08-21 16:19:55 -07:00
Yicheng Qin ccb67a691b pkg/netutil: stop resolving in place
It helps to copy out a and b, and not modify the original a and b.
2015-08-21 15:39:57 -07:00
Yicheng Qin 059233768e pkg/netutil: not introduce empty url when converting
It should not make slices with length and append elements at the same
time.
2015-08-21 15:39:48 -07:00
Yicheng Qin c530acf6a4 pkg/netutil: not export resolve and urlsEqual functions
They are only used in this package, so there is no need to public them.
2015-08-21 15:39:38 -07:00
Yicheng Qin bad1b20620 pkg/netutil: fix false negative comparison
Sort the resolved URLs before DeepEqual, so it will not compare URLs
that may be out of order due to resolution.
2015-08-21 15:39:29 -07:00
Yicheng Qin 89640cf08f etcdserver: remove TODO to delete URLStringsEqual
Discovery SRV supports to compare IP addresses with domain names,
so we need URLStringsEqual function.
2015-08-21 15:39:19 -07:00
6 changed files with 58 additions and 32 deletions

View File

@ -261,10 +261,10 @@ func startProxy(cfg *config) error {
}
pt, err := transport.NewTimeoutTransport(cfg.peerTLSInfo, time.Duration(cfg.proxyDialTimeoutMs)*time.Millisecond, time.Duration(cfg.proxyReadTimeoutMs)*time.Millisecond, time.Duration(cfg.proxyWriteTimeoutMs)*time.Millisecond)
pt.MaxIdleConnsPerHost = proxy.DefaultMaxIdleConnsPerHost
if err != nil {
return err
}
pt.MaxIdleConnsPerHost = proxy.DefaultMaxIdleConnsPerHost
tr, err := transport.NewTimeoutTransport(cfg.peerTLSInfo, time.Duration(cfg.proxyDialTimeoutMs)*time.Millisecond, time.Duration(cfg.proxyReadTimeoutMs)*time.Millisecond, time.Duration(cfg.proxyWriteTimeoutMs)*time.Millisecond)
if err != nil {

View File

@ -421,7 +421,6 @@ func ValidateClusterAndAssignIDs(local *cluster, existing *cluster) error {
sort.Sort(MembersByPeerURLs(lms))
for i := range ems {
// TODO: Remove URLStringsEqual after improvement of using hostnames #2150 #2123
if !netutil.URLStringsEqual(ems[i].PeerURLs, lms[i].PeerURLs) {
return fmt.Errorf("unmatched member while checking PeerURLs")
}

View File

@ -89,7 +89,6 @@ func (c *ServerConfig) verifyLocalMember(strict bool) error {
}
// Advertised peer URLs must match those in the cluster peer list
// TODO: Remove URLStringsEqual after improvement of using hostnames #2150 #2123
apurls := c.PeerURLs.StringSlice()
sort.Strings(apurls)
urls.Sort()

View File

@ -20,9 +20,11 @@ import (
"net/http"
"net/url"
"reflect"
"sort"
"strings"
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/coreos/pkg/capnslog"
"github.com/coreos/etcd/pkg/types"
)
var (
@ -32,16 +34,25 @@ var (
resolveTCPAddr = net.ResolveTCPAddr
)
// ResolveTCPAddrs is a convenience wrapper for net.ResolveTCPAddr.
// ResolveTCPAddrs resolves all DNS hostnames in-place for the given set of
// url.URLs.
func ResolveTCPAddrs(urls ...[]url.URL) error {
// resolveTCPAddrs is a convenience wrapper for net.ResolveTCPAddr.
// resolveTCPAddrs return a new set of url.URLs, in which all DNS hostnames
// are resolved.
func resolveTCPAddrs(urls [][]url.URL) ([][]url.URL, error) {
newurls := make([][]url.URL, 0)
for _, us := range urls {
nus := make([]url.URL, len(us))
for i, u := range us {
nu, err := url.Parse(u.String())
if err != nil {
return nil, err
}
nus[i] = *nu
}
for i, u := range nus {
host, _, err := net.SplitHostPort(u.Host)
if err != nil {
plog.Errorf("could not parse url %s during tcp resolving", u.Host)
return err
return nil, err
}
if host == "localhost" {
continue
@ -52,30 +63,32 @@ func ResolveTCPAddrs(urls ...[]url.URL) error {
tcpAddr, err := resolveTCPAddr("tcp", u.Host)
if err != nil {
plog.Errorf("could not resolve host %s", u.Host)
return err
return nil, err
}
plog.Infof("resolving %s to %s", u.Host, tcpAddr.String())
us[i].Host = tcpAddr.String()
nus[i].Host = tcpAddr.String()
}
newurls = append(newurls, nus)
}
return nil
return newurls, nil
}
// URLsEqual checks equality of url.URLS between two arrays.
// urlsEqual checks equality of url.URLS between two arrays.
// This check pass even if an URL is in hostname and opposite is in IP address.
func URLsEqual(a []url.URL, b []url.URL) bool {
func urlsEqual(a []url.URL, b []url.URL) bool {
if len(a) != len(b) {
return false
}
for i, urlA := range a {
urlB := b[i]
if !reflect.DeepEqual(urlA, urlB) {
urls := []url.URL{urlA, urlB}
ResolveTCPAddrs(urls)
if !reflect.DeepEqual(urls[0], urls[1]) {
return false
}
urls, err := resolveTCPAddrs([][]url.URL{a, b})
if err != nil {
return false
}
a, b = urls[0], urls[1]
sort.Sort(types.URLs(a))
sort.Sort(types.URLs(b))
for i := range a {
if !reflect.DeepEqual(a[i], b[i]) {
return false
}
}
@ -86,7 +99,7 @@ func URLStringsEqual(a []string, b []string) bool {
if len(a) != len(b) {
return false
}
urlsA := make([]url.URL, len(a))
urlsA := make([]url.URL, 0)
for _, str := range a {
u, err := url.Parse(str)
if err != nil {
@ -94,7 +107,7 @@ func URLStringsEqual(a []string, b []string) bool {
}
urlsA = append(urlsA, *u)
}
urlsB := make([]url.URL, len(b))
urlsB := make([]url.URL, 0)
for _, str := range b {
u, err := url.Parse(str)
if err != nil {
@ -103,7 +116,7 @@ func URLStringsEqual(a []string, b []string) bool {
urlsB = append(urlsB, *u)
}
return URLsEqual(urlsA, urlsB)
return urlsEqual(urlsA, urlsB)
}
// BasicAuth returns the username and password provided in the request's

View File

@ -124,31 +124,36 @@ func TestResolveTCPAddrs(t *testing.T) {
}
return &net.TCPAddr{IP: net.ParseIP(tt.hostMap[host]), Port: i, Zone: ""}, nil
}
err := ResolveTCPAddrs(tt.urls...)
urls, err := resolveTCPAddrs(tt.urls)
if tt.hasError {
if err == nil {
t.Errorf("expected error")
}
continue
}
if !reflect.DeepEqual(tt.urls, tt.expected) {
t.Errorf("expected: %v, got %v", tt.expected, tt.urls)
if !reflect.DeepEqual(urls, tt.expected) {
t.Errorf("expected: %v, got %v", tt.expected, urls)
}
}
}
func TestURLsEqual(t *testing.T) {
defer func() { resolveTCPAddr = net.ResolveTCPAddr }()
hostm := map[string]string{
"example.com": "10.0.10.1",
"first.com": "10.0.11.1",
"second.com": "10.0.11.2",
}
resolveTCPAddr = func(network, addr string) (*net.TCPAddr, error) {
host, port, err := net.SplitHostPort(addr)
if host != "example.com" {
if _, ok := hostm[host]; !ok {
return nil, errors.New("cannot resolve host.")
}
i, err := strconv.Atoi(port)
if err != nil {
return nil, err
}
return &net.TCPAddr{IP: net.ParseIP("10.0.10.1"), Port: i, Zone: ""}, nil
return &net.TCPAddr{IP: net.ParseIP(hostm[host]), Port: i, Zone: ""}, nil
}
tests := []struct {
@ -226,10 +231,20 @@ func TestURLsEqual(t *testing.T) {
b: []url.URL{{Scheme: "http", Host: "10.0.0.1:2379"}, {Scheme: "http", Host: "127.0.0.1:2380"}},
expect: false,
},
{
a: []url.URL{{Scheme: "http", Host: "first.com:2379"}, {Scheme: "http", Host: "second.com:2380"}},
b: []url.URL{{Scheme: "http", Host: "10.0.11.1:2379"}, {Scheme: "http", Host: "10.0.11.2:2380"}},
expect: true,
},
{
a: []url.URL{{Scheme: "http", Host: "second.com:2380"}, {Scheme: "http", Host: "first.com:2379"}},
b: []url.URL{{Scheme: "http", Host: "10.0.11.1:2379"}, {Scheme: "http", Host: "10.0.11.2:2380"}},
expect: true,
},
}
for _, test := range tests {
result := URLsEqual(test.a, test.b)
result := urlsEqual(test.a, test.b)
if result != test.expect {
t.Errorf("a:%v b:%v, expected %v but %v", test.a, test.b, test.expect, result)
}

View File

@ -25,7 +25,7 @@ import (
var (
// MinClusterVersion is the min cluster version this etcd binary is compatible with.
MinClusterVersion = "2.0.0"
Version = "2.1.1+git"
Version = "2.1.3+git"
// Git SHA Value will be set during build
GitSHA = "Not provided (use ./build instead of go build)"