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"
|
"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 {
|
type Etcd struct {
|
||||||
Config *config.Config // etcd config
|
Config *config.Config // etcd config
|
||||||
|
@ -140,12 +146,6 @@ func (e *Etcd) Run() {
|
||||||
dialTimeout := (3 * heartbeatInterval) + electionTimeout
|
dialTimeout := (3 * heartbeatInterval) + electionTimeout
|
||||||
responseHeaderTimeout := (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{
|
clientTransporter := &httpclient.Transport{
|
||||||
ResponseHeaderTimeout: responseHeaderTimeout + extraTimeout,
|
ResponseHeaderTimeout: responseHeaderTimeout + extraTimeout,
|
||||||
// This is a workaround for Transport.CancelRequest doesn't work on
|
// This is a workaround for Transport.CancelRequest doesn't work on
|
||||||
|
|
|
@ -16,6 +16,8 @@ import (
|
||||||
|
|
||||||
// Client sends various requests using HTTP API.
|
// Client sends various requests using HTTP API.
|
||||||
// It is different from raft communication, and doesn't record anything in the log.
|
// 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
|
// Public functions return "etcd/error".Error intentionally to figure out
|
||||||
// etcd error code easily.
|
// etcd error code easily.
|
||||||
// TODO(yichengq): It is similar to go-etcd. But it could have many efforts
|
// 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.
|
// Parse version number.
|
||||||
version, _ := strconv.Atoi(string(body))
|
version, err := strconv.Atoi(string(body))
|
||||||
|
if err != nil {
|
||||||
|
return 0, clientError(err)
|
||||||
|
}
|
||||||
return version, nil
|
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
|
// Our version must match the leaders version
|
||||||
version, err := s.client.GetVersion(u)
|
version, err := s.client.GetVersion(u)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debugf("fail checking join version")
|
return fmt.Errorf("fail checking join version: %v", err)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
if version < store.MinVersion() || version > store.MaxVersion() {
|
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("fail passing version compatibility(%d-%d) using %d", store.MinVersion(), store.MaxVersion(), version)
|
||||||
return fmt.Errorf("incompatible version")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch current peer list
|
// Fetch current peer list
|
||||||
machines, err := s.client.GetMachines(u)
|
machines, err := s.client.GetMachines(u)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debugf("fail getting machine messages")
|
return fmt.Errorf("fail getting machine messages: %v", err)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
exist := false
|
exist := false
|
||||||
for _, machine := range machines {
|
for _, machine := range machines {
|
||||||
if machine.Name == server.Name() {
|
if machine.Name == server.Name() {
|
||||||
exist = true
|
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
|
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.
|
// Fetch cluster config to see whether exists some place.
|
||||||
clusterConfig, err := s.client.GetClusterConfig(u)
|
clusterConfig, err := s.client.GetClusterConfig(u)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debugf("fail getting cluster config")
|
return fmt.Errorf("fail getting cluster config: %v", err)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
if !exist && clusterConfig.ActiveSize <= len(machines) {
|
if !exist && clusterConfig.ActiveSize <= len(machines) {
|
||||||
log.Infof("stop joining because the cluster is full with %d nodes", len(machines))
|
return fmt.Errorf("stop joining because the cluster is full with %d nodes", len(machines))
|
||||||
return fmt.Errorf("out of quota")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
joinIndex, err := s.client.AddMachine(u,
|
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(),
|
EtcdURL: s.server.URL(),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debugf("fail on join request")
|
return fmt.Errorf("fail on join request: %v", err)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s.joinIndex = joinIndex
|
s.joinIndex = joinIndex
|
||||||
|
|
Loading…
Reference in New Issue