Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package datastorecache | 5 package datastorecache |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "math" | 8 "math" |
| 9 "time" | 9 "time" |
| 10 | 10 |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 329 refreshValue, delta, err = doRefresh(c, bci.h, & e, userNS) | 329 refreshValue, delta, err = doRefresh(c, bci.h, & e, userNS) |
| 330 return | 330 return |
| 331 }) | 331 }) |
| 332 switch err { | 332 switch err { |
| 333 case nil: | 333 case nil: |
| 334 // Successfully loaded. | 334 // Successfully loaded. |
| 335 return nil | 335 return nil |
| 336 | 336 |
| 337 case ErrFailedToLock: | 337 case ErrFailedToLock: |
| 338 // Retry after delay. | 338 // Retry after delay. |
| 339 » » » » return errors.WrapTransient(err) | 339 » » » » return retry.Tag.Apply(err) |
|
dnj
2017/06/24 14:53:54
I don't like "retry.Tag.Apply" as a way of express
iannucci
2017/06/24 20:16:09
Done.
| |
| 340 | 340 |
| 341 default: | 341 default: |
| 342 log.WithError(err).Warningf(c, "Unexpected failu re obtaining initial load lock.") | 342 log.WithError(err).Warningf(c, "Unexpected failu re obtaining initial load lock.") |
| 343 return err | 343 return err |
| 344 } | 344 } |
| 345 }, func(err error, d time.Duration) { | 345 }, func(err error, d time.Duration) { |
| 346 log.WithError(err).Debugf(c, "Failed to acquire initial refresh lock. Retrying...") | 346 log.WithError(err).Debugf(c, "Failed to acquire initial refresh lock. Retrying...") |
| 347 }) | 347 }) |
| 348 if err != nil { | 348 if err != nil { |
| 349 // If we actually acquired the lock, then this refresh was a fai lure, and | 349 // If we actually acquired the lock, then this refresh was a fai lure, and |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 455 // delta is a factor representing the amount of time that it takes to | 455 // delta is a factor representing the amount of time that it takes to |
| 456 // recalculate the value. Higher delta values allow for earlier recomputation | 456 // recalculate the value. Higher delta values allow for earlier recomputation |
| 457 // for values that take longer to calculate. | 457 // for values that take longer to calculate. |
| 458 // | 458 // |
| 459 // beta can be set to >1 to favor earlier recomputations; however, in practice | 459 // beta can be set to >1 to favor earlier recomputations; however, in practice |
| 460 // beta=1 works well. | 460 // beta=1 works well. |
| 461 func xFetch(now, expiry time.Time, delta time.Duration, beta float64, rf randFun c) bool { | 461 func xFetch(now, expiry time.Time, delta time.Duration, beta float64, rf randFun c) bool { |
| 462 offset := time.Duration(float64(delta) * beta * math.Log(rf())) | 462 offset := time.Duration(float64(delta) * beta * math.Log(rf())) |
| 463 return !now.Add(-offset).Before(expiry) | 463 return !now.Add(-offset).Before(expiry) |
| 464 } | 464 } |
| OLD | NEW |