etcdserver: add timeout param on getClusterFromRemotePeers

It sets 10s timeout for public GetClusterFromRemotePeers.

This helps the following cases to work well in high latency scenario:

1. proxy sync members from the cluster
2. newly-joined member sync members from the cluster

Besides 10s request timeout, the request is also controlled by dial
timeout and read connection timeout.
This commit is contained in:
Yicheng Qin
2015-08-31 15:12:58 -07:00
parent 57b39aca4e
commit f3bfcb9dee

View File

@@ -30,7 +30,7 @@ import (
// isMemberBootstrapped tries to check if the given member has been bootstrapped
// in the given cluster.
func isMemberBootstrapped(cl *cluster, member string, tr *http.Transport) bool {
rcl, err := getClusterFromRemotePeers(getRemotePeerURLs(cl, member), false, tr)
rcl, err := getClusterFromRemotePeers(getRemotePeerURLs(cl, member), time.Second, false, tr)
if err != nil {
return false
}
@@ -50,15 +50,17 @@ func isMemberBootstrapped(cl *cluster, member string, tr *http.Transport) bool {
// these URLs. The first URL to provide a response is used. If no URLs provide
// a response, or a Cluster cannot be successfully created from a received
// response, an error is returned.
// Each request has a 10-second timeout. Because the upper limit of TTL is 5s,
// 10 second is enough for building connection and finishing request.
func GetClusterFromRemotePeers(urls []string, tr *http.Transport) (*cluster, error) {
return getClusterFromRemotePeers(urls, true, tr)
return getClusterFromRemotePeers(urls, 10*time.Second, true, tr)
}
// If logerr is true, it prints out more error messages.
func getClusterFromRemotePeers(urls []string, logerr bool, tr *http.Transport) (*cluster, error) {
func getClusterFromRemotePeers(urls []string, timeout time.Duration, logerr bool, tr *http.Transport) (*cluster, error) {
cc := &http.Client{
Transport: tr,
Timeout: time.Second,
Timeout: timeout,
}
for _, u := range urls {
resp, err := cc.Get(u + "/members")