chore(client): minor changes based on comments
The changes are made on error handling, comments and constant.release-0.4
parent
ae81f843f1
commit
e960a0e03c
14
etcd/etcd.go
14
etcd/etcd.go
|
@ -38,7 +38,13 @@ import (
|
|||
"github.com/coreos/etcd/store"
|
||||
)
|
||||
|
||||
const extraTimeout = 1000
|
||||
// TODO(yichengq): constant extraTimeout is a hack.
|
||||
// Current problem is that there is big lag between join command
|
||||
// execution and join success.
|
||||
// Fix it later. It should be removed when proper method is found and
|
||||
// enough tests are provided. It is expected to be calculated from
|
||||
// heartbeatInterval and electionTimeout only.
|
||||
const extraTimeout = time.Duration(1000) * time.Millisecond
|
||||
|
||||
type Etcd struct {
|
||||
Config *config.Config // etcd config
|
||||
|
@ -140,12 +146,6 @@ func (e *Etcd) Run() {
|
|||
dialTimeout := (3 * heartbeatInterval) + electionTimeout
|
||||
responseHeaderTimeout := (3 * heartbeatInterval) + electionTimeout
|
||||
|
||||
// TODO(yichengq): constant extraTimeout is a hack here.
|
||||
// Current problem is that there is big lag between join command
|
||||
// execution and join success.
|
||||
// Fix it later. It should be removed when proper method is found and
|
||||
// enough tests are provided. It is expected to be calculated from
|
||||
// heartbeatInterval and electionTimeout only.
|
||||
clientTransporter := &httpclient.Transport{
|
||||
ResponseHeaderTimeout: responseHeaderTimeout + extraTimeout,
|
||||
// This is a workaround for Transport.CancelRequest doesn't work on
|
||||
|
|
|
@ -16,6 +16,8 @@ import (
|
|||
|
||||
// Client sends various requests using HTTP API.
|
||||
// It is different from raft communication, and doesn't record anything in the log.
|
||||
// The argument url is required to contain scheme and host only, and
|
||||
// there is no trailing slash in it.
|
||||
// Public functions return "etcd/error".Error intentionally to figure out
|
||||
// etcd error code easily.
|
||||
// TODO(yichengq): It is similar to go-etcd. But it could have many efforts
|
||||
|
@ -55,7 +57,10 @@ func (c *Client) GetVersion(url string) (int, *etcdErr.Error) {
|
|||
}
|
||||
|
||||
// Parse version number.
|
||||
version, _ := strconv.Atoi(string(body))
|
||||
version, err := strconv.Atoi(string(body))
|
||||
if err != nil {
|
||||
return 0, clientError(err)
|
||||
}
|
||||
return version, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -485,31 +485,21 @@ func (s *PeerServer) joinByPeer(server raft.Server, peer string, scheme string)
|
|||
// Our version must match the leaders version
|
||||
version, err := s.client.GetVersion(u)
|
||||
if err != nil {
|
||||
log.Debugf("fail checking join version")
|
||||
return err
|
||||
return fmt.Errorf("fail checking join version: %v", err)
|
||||
}
|
||||
if version < store.MinVersion() || version > store.MaxVersion() {
|
||||
log.Infof("fail passing version compatibility(%d-%d) using %d", store.MinVersion(), store.MaxVersion(), version)
|
||||
return fmt.Errorf("incompatible version")
|
||||
return fmt.Errorf("fail passing version compatibility(%d-%d) using %d", store.MinVersion(), store.MaxVersion(), version)
|
||||
}
|
||||
|
||||
// Fetch current peer list
|
||||
machines, err := s.client.GetMachines(u)
|
||||
if err != nil {
|
||||
log.Debugf("fail getting machine messages")
|
||||
return err
|
||||
return fmt.Errorf("fail getting machine messages: %v", err)
|
||||
}
|
||||
exist := false
|
||||
for _, machine := range machines {
|
||||
if machine.Name == server.Name() {
|
||||
exist = true
|
||||
// TODO(yichengq): cannot set join index for it.
|
||||
// Need discussion about the best way to do it.
|
||||
//
|
||||
// if machine.PeerURL == s.Config.URL {
|
||||
// log.Infof("has joined the cluster(%v) before", machines)
|
||||
// return nil
|
||||
// }
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@ -517,12 +507,10 @@ func (s *PeerServer) joinByPeer(server raft.Server, peer string, scheme string)
|
|||
// Fetch cluster config to see whether exists some place.
|
||||
clusterConfig, err := s.client.GetClusterConfig(u)
|
||||
if err != nil {
|
||||
log.Debugf("fail getting cluster config")
|
||||
return err
|
||||
return fmt.Errorf("fail getting cluster config: %v", err)
|
||||
}
|
||||
if !exist && clusterConfig.ActiveSize <= len(machines) {
|
||||
log.Infof("stop joining because the cluster is full with %d nodes", len(machines))
|
||||
return fmt.Errorf("out of quota")
|
||||
return fmt.Errorf("stop joining because the cluster is full with %d nodes", len(machines))
|
||||
}
|
||||
|
||||
joinIndex, err := s.client.AddMachine(u,
|
||||
|
@ -534,8 +522,7 @@ func (s *PeerServer) joinByPeer(server raft.Server, peer string, scheme string)
|
|||
EtcdURL: s.server.URL(),
|
||||
})
|
||||
if err != nil {
|
||||
log.Debugf("fail on join request")
|
||||
return err
|
||||
return fmt.Errorf("fail on join request: %v", err)
|
||||
}
|
||||
|
||||
s.joinIndex = joinIndex
|
||||
|
|
Loading…
Reference in New Issue