|
@@ -17,7 +17,6 @@ package discovery
|
|
|
import (
|
|
import (
|
|
|
"errors"
|
|
"errors"
|
|
|
"fmt"
|
|
"fmt"
|
|
|
- "log"
|
|
|
|
|
"math"
|
|
"math"
|
|
|
"net/http"
|
|
"net/http"
|
|
|
"net/url"
|
|
"net/url"
|
|
@@ -31,9 +30,12 @@ import (
|
|
|
"github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
|
|
"github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
|
|
|
"github.com/coreos/etcd/client"
|
|
"github.com/coreos/etcd/client"
|
|
|
"github.com/coreos/etcd/pkg/types"
|
|
"github.com/coreos/etcd/pkg/types"
|
|
|
|
|
+ "github.com/coreos/pkg/capnslog"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
var (
|
|
|
|
|
+ plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "discovery")
|
|
|
|
|
+
|
|
|
ErrInvalidURL = errors.New("discovery: invalid URL")
|
|
ErrInvalidURL = errors.New("discovery: invalid URL")
|
|
|
ErrBadSizeKey = errors.New("discovery: size key is bad")
|
|
ErrBadSizeKey = errors.New("discovery: size key is bad")
|
|
|
ErrSizeNotFound = errors.New("discovery: size key not found")
|
|
ErrSizeNotFound = errors.New("discovery: size key not found")
|
|
@@ -102,7 +104,7 @@ func newProxyFunc(proxy string) (func(*http.Request) (*url.URL, error), error) {
|
|
|
return nil, fmt.Errorf("invalid proxy address %q: %v", proxy, err)
|
|
return nil, fmt.Errorf("invalid proxy address %q: %v", proxy, err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- log.Printf("discovery: using proxy %q", proxyURL.String())
|
|
|
|
|
|
|
+ plog.Infof("using proxy %q", proxyURL.String())
|
|
|
return http.ProxyURL(proxyURL), nil
|
|
return http.ProxyURL(proxyURL), nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -250,7 +252,7 @@ func (d *discovery) checkCluster() ([]*client.Node, int, uint64, error) {
|
|
|
func (d *discovery) logAndBackoffForRetry(step string) {
|
|
func (d *discovery) logAndBackoffForRetry(step string) {
|
|
|
d.retries++
|
|
d.retries++
|
|
|
retryTime := time.Second * (0x1 << d.retries)
|
|
retryTime := time.Second * (0x1 << d.retries)
|
|
|
- log.Println("discovery: during", step, "connection to", d.url, "timed out, retrying in", retryTime)
|
|
|
|
|
|
|
+ plog.Infoln("during", step, "connection to", d.url, "timed out, retrying in", retryTime)
|
|
|
d.clock.Sleep(retryTime)
|
|
d.clock.Sleep(retryTime)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -284,15 +286,15 @@ func (d *discovery) waitNodes(nodes []*client.Node, size int, index uint64) ([]*
|
|
|
copy(all, nodes)
|
|
copy(all, nodes)
|
|
|
for _, n := range all {
|
|
for _, n := range all {
|
|
|
if path.Base(n.Key) == path.Base(d.selfKey()) {
|
|
if path.Base(n.Key) == path.Base(d.selfKey()) {
|
|
|
- log.Printf("discovery: found self %s in the cluster", path.Base(d.selfKey()))
|
|
|
|
|
|
|
+ plog.Noticef("found self %s in the cluster", path.Base(d.selfKey()))
|
|
|
} else {
|
|
} else {
|
|
|
- log.Printf("discovery: found peer %s in the cluster", path.Base(n.Key))
|
|
|
|
|
|
|
+ plog.Noticef("found peer %s in the cluster", path.Base(n.Key))
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// wait for others
|
|
// wait for others
|
|
|
for len(all) < size {
|
|
for len(all) < size {
|
|
|
- log.Printf("discovery: found %d peer(s), waiting for %d more", len(all), size-len(all))
|
|
|
|
|
|
|
+ plog.Noticef("found %d peer(s), waiting for %d more", len(all), size-len(all))
|
|
|
resp, err := w.Next(context.Background())
|
|
resp, err := w.Next(context.Background())
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
if err == context.DeadlineExceeded {
|
|
if err == context.DeadlineExceeded {
|
|
@@ -300,10 +302,10 @@ func (d *discovery) waitNodes(nodes []*client.Node, size int, index uint64) ([]*
|
|
|
}
|
|
}
|
|
|
return nil, err
|
|
return nil, err
|
|
|
}
|
|
}
|
|
|
- log.Printf("discovery: found peer %s in the cluster", path.Base(resp.Node.Key))
|
|
|
|
|
|
|
+ plog.Noticef("found peer %s in the cluster", path.Base(resp.Node.Key))
|
|
|
all = append(all, resp.Node)
|
|
all = append(all, resp.Node)
|
|
|
}
|
|
}
|
|
|
- log.Printf("discovery: found %d needed peer(s)", len(all))
|
|
|
|
|
|
|
+ plog.Noticef("found %d needed peer(s)", len(all))
|
|
|
return all, nil
|
|
return all, nil
|
|
|
}
|
|
}
|
|
|
|
|
|