@@ -148,10 +148,10 @@ func (server CacheServer) CacheHandler(w http.ResponseWriter, r *http.Request) {
148148 resultKey := server .HashURL (server .ReorderQueryString (r .URL ))
149149
150150 if UseLock {
151- attempt := 0
151+ attempt := 1
152152 for {
153153 // check the cache
154- server .Logger .Info ("checking the cache" , zap .String ("resultKey" , resultKey ), zap .Int ("attempt" , attempt + 1 ))
154+ server .Logger .Info ("checking the cache" , zap .String ("resultKey" , resultKey ), zap .Int ("attempt" , attempt ))
155155 if cachedDataBytes := server .CheckCache (resultKey ); cachedDataBytes != nil {
156156 serveFromCache (cachedDataBytes , server , w , r )
157157 return
@@ -160,8 +160,8 @@ func (server CacheServer) CacheHandler(w http.ResponseWriter, r *http.Request) {
160160 // try to acquire the lock
161161 server .Logger .Info ("acquiring the lock" , zap .String ("key" , key ))
162162 if err := server .LockMgr .Acquire (key , LockTtl ); err == nil {
163- server .Prometheus .LockAcquiringAttemptsHistogram .Observe (float64 (attempt ) + 1 )
164- server .Logger .Info ("lock acquired" , zap .String ("key" , key ))
163+ server .Prometheus .LockAcquiringAttemptsHistogram .Observe (float64 (attempt ))
164+ server .Logger .Info ("lock acquired" , zap .String ("key" , key ), zap . Int ( "attempt" , attempt ) )
165165 defer func () {
166166 // release the lock
167167 if err := server .LockMgr .Release (key ); err != nil {
@@ -252,9 +252,8 @@ func (server CacheServer) ReorderQueryString(url *url.URL) string {
252252}
253253
254254func (server CacheServer ) GetBackoff (attempt int ) time.Duration {
255- if attempt < 10 {
255+ if attempt <= 10 {
256256 return 100 * time .Millisecond
257- } else {
258- return 500 * time .Millisecond
259257 }
258+ return 500 * time .Millisecond
260259}
0 commit comments