mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcdmain: improve log when join discovery fails
Before this PR, the log is ``` 2015/09/1 13:18:31 etcdmain: client: etcd cluster is unavailable or misconfigured ``` It is quite hard for people to understand what happens. Now we print out the exact reason for the failure, and explains the way to handle it.
This commit is contained in:
parent
5d6457e658
commit
26cc2111cd
@ -159,6 +159,12 @@ func Main() {
|
||||
}
|
||||
os.Exit(1)
|
||||
}
|
||||
if etcdserver.IsDiscoveryError(err) {
|
||||
plog.Errorf("%v", err)
|
||||
plog.Infof("discovery token %s was used, but failed to bootstrap the cluster.", cfg.durl)
|
||||
plog.Infof("please generate a new discovery token and try to bootstrap again.")
|
||||
os.Exit(1)
|
||||
}
|
||||
plog.Fatalf("%v", err)
|
||||
}
|
||||
os.Exit(1)
|
||||
|
@ -16,6 +16,7 @@ package etcdserver
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
etcdErr "github.com/coreos/etcd/error"
|
||||
)
|
||||
@ -37,3 +38,17 @@ func isKeyNotFound(err error) bool {
|
||||
e, ok := err.(*etcdErr.Error)
|
||||
return ok && e.ErrorCode == etcdErr.EcodeKeyNotFound
|
||||
}
|
||||
|
||||
type discoveryError struct {
|
||||
op string
|
||||
err error
|
||||
}
|
||||
|
||||
func (e discoveryError) Error() string {
|
||||
return fmt.Sprintf("failed to %s discovery cluster (%v)", e.op, e.err)
|
||||
}
|
||||
|
||||
func IsDiscoveryError(err error) bool {
|
||||
_, ok := err.(*discoveryError)
|
||||
return ok
|
||||
}
|
||||
|
@ -238,7 +238,7 @@ func NewServer(cfg *ServerConfig) (*EtcdServer, error) {
|
||||
if cfg.ShouldDiscover() {
|
||||
str, err := discovery.JoinCluster(cfg.DiscoveryURL, cfg.DiscoveryProxy, m.ID, cfg.InitialPeerURLsMap.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, &discoveryError{op: "join", err: err}
|
||||
}
|
||||
urlsmap, err := types.NewURLsMap(str)
|
||||
if err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user