@@ -148,10 +148,10 @@ func (server CacheServer) CacheHandler(w http.ResponseWriter, r *http.Request) {
148
148
resultKey := server .HashURL (server .ReorderQueryString (r .URL ))
149
149
150
150
if UseLock {
151
- attempt := 0
151
+ attempt := 1
152
152
for {
153
153
// 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 ))
155
155
if cachedDataBytes := server .CheckCache (resultKey ); cachedDataBytes != nil {
156
156
serveFromCache (cachedDataBytes , server , w , r )
157
157
return
@@ -160,8 +160,8 @@ func (server CacheServer) CacheHandler(w http.ResponseWriter, r *http.Request) {
160
160
// try to acquire the lock
161
161
server .Logger .Info ("acquiring the lock" , zap .String ("key" , key ))
162
162
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 ) )
165
165
defer func () {
166
166
// release the lock
167
167
if err := server .LockMgr .Release (key ); err != nil {
@@ -252,9 +252,8 @@ func (server CacheServer) ReorderQueryString(url *url.URL) string {
252
252
}
253
253
254
254
func (server CacheServer ) GetBackoff (attempt int ) time.Duration {
255
- if attempt < 10 {
255
+ if attempt <= 10 {
256
256
return 100 * time .Millisecond
257
- } else {
258
- return 500 * time .Millisecond
259
257
}
258
+ return 500 * time .Millisecond
260
259
}
0 commit comments