X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/b1ef43a1dbb4a66e1646fc68ac88ff6d54026ac1..7846843453df9846c346f85c20a8d6d051066f52:/services/keepproxy/keepproxy.go diff --git a/services/keepproxy/keepproxy.go b/services/keepproxy/keepproxy.go index 2efc9cef5b..226c388ae2 100644 --- a/services/keepproxy/keepproxy.go +++ b/services/keepproxy/keepproxy.go @@ -14,7 +14,6 @@ import ( "net/http" "os" "os/signal" - "reflect" "regexp" "sync" "syscall" @@ -104,7 +103,7 @@ func main() { kc.Want_replicas = default_replicas kc.Client.Timeout = time.Duration(timeout) * time.Second - go RefreshServicesList(kc, 5*time.Minute, 3*time.Second) + go kc.RefreshServices(5*time.Minute, 3*time.Second) listener, err = net.Listen("tcp", listen) if err != nil { @@ -135,42 +134,6 @@ type ApiTokenCache struct { expireTime int64 } -// Refresh the keep service list on SIGHUP; when the given interval -// has elapsed since the last refresh; and (if the last refresh -// failed) the given errInterval has elapsed. -func RefreshServicesList(kc *keepclient.KeepClient, interval, errInterval time.Duration) { - var previousRoots = []map[string]string{} - - timer := time.NewTimer(interval) - gotHUP := make(chan os.Signal, 1) - signal.Notify(gotHUP, syscall.SIGHUP) - - for { - select { - case <-gotHUP: - case <-timer.C: - } - timer.Reset(interval) - - if err := kc.DiscoverKeepServers(); err != nil { - log.Println("Error retrieving services list: %v (retrying in %v)", err, errInterval) - timer.Reset(errInterval) - continue - } - newRoots := []map[string]string{kc.LocalRoots(), kc.GatewayRoots()} - - if !reflect.DeepEqual(previousRoots, newRoots) { - log.Printf("Updated services list: locals %v gateways %v", newRoots[0], newRoots[1]) - previousRoots = newRoots - } - - if len(newRoots[0]) == 0 { - log.Printf("WARNING: No local services (retrying in %v)", errInterval) - timer.Reset(errInterval) - } - } -} - // Cache the token and set an expire time. If we already have an expire time // on the token, it is not updated. func (this *ApiTokenCache) RememberToken(token string) { @@ -222,7 +185,7 @@ func CheckAuthorizationHeader(kc *keepclient.KeepClient, cache *ApiTokenCache, r } if cache.RecallToken(tok) { - // Valid in the cache, short circut + // Valid in the cache, short circuit return true, tok } @@ -404,7 +367,7 @@ func (this PutBlockHandler) ServeHTTP(resp http.ResponseWriter, req *http.Reques kc := *this.KeepClient var err error - var expectLength int64 = -1 + var expectLength int64 var status = http.StatusInternalServerError var wroteReplicas int var locatorOut string = "-" @@ -418,15 +381,8 @@ func (this PutBlockHandler) ServeHTTP(resp http.ResponseWriter, req *http.Reques locatorIn := mux.Vars(req)["locator"] - if req.Header.Get("Content-Length") != "" { - _, err := fmt.Sscanf(req.Header.Get("Content-Length"), "%d", &expectLength) - if err != nil { - resp.Header().Set("Content-Length", fmt.Sprintf("%d", expectLength)) - } - - } - - if expectLength < 0 { + _, err = fmt.Sscanf(req.Header.Get("Content-Length"), "%d", &expectLength) + if err != nil || expectLength < 0 { err = LengthRequiredError status = http.StatusLengthRequired return @@ -461,7 +417,7 @@ func (this PutBlockHandler) ServeHTTP(resp http.ResponseWriter, req *http.Reques if req.Header.Get("X-Keep-Desired-Replicas") != "" { var r int _, err := fmt.Sscanf(req.Header.Get(keepclient.X_Keep_Desired_Replicas), "%d", &r) - if err != nil { + if err == nil { kc.Want_replicas = r } }