| 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 "strings" | 9 "strings" |
| 10 "time" | 10 "time" |
| 11 | 11 |
| 12 "github.com/luci/luci-go/appengine/memlock" | 12 "github.com/luci/luci-go/appengine/memlock" |
| 13 "github.com/luci/luci-go/common/clock" | 13 "github.com/luci/luci-go/common/clock" |
| 14 "github.com/luci/luci-go/common/data/rand/mathrand" | 14 "github.com/luci/luci-go/common/data/rand/mathrand" |
| 15 "github.com/luci/luci-go/common/errors" | 15 "github.com/luci/luci-go/common/errors" |
| 16 log "github.com/luci/luci-go/common/logging" | 16 log "github.com/luci/luci-go/common/logging" |
| 17 "github.com/luci/luci-go/common/retry" | 17 "github.com/luci/luci-go/common/retry" |
| 18 "github.com/luci/luci-go/server/router" | 18 "github.com/luci/luci-go/server/router" |
| 19 | 19 |
| 20 "github.com/luci/gae/impl/prod/constraints" |
| 20 "github.com/luci/gae/service/datastore" | 21 "github.com/luci/gae/service/datastore" |
| 21 "github.com/luci/gae/service/info" | 22 "github.com/luci/gae/service/info" |
| 22 | 23 |
| 23 "golang.org/x/net/context" | 24 "golang.org/x/net/context" |
| 24 ) | 25 ) |
| 25 | 26 |
| 26 const ( | 27 const ( |
| 27 initialLoadLockRetries = 3 | 28 initialLoadLockRetries = 3 |
| 28 initialLoadDelay = 10 * time.Millisecond | 29 initialLoadDelay = 10 * time.Millisecond |
| 29 | 30 |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 func (cache *Cache) pruneInterval() time.Duration { | 169 func (cache *Cache) pruneInterval() time.Duration { |
| 169 if cache.AccessUpdateInterval > 0 && cache.PruneFactor > 0 { | 170 if cache.AccessUpdateInterval > 0 && cache.PruneFactor > 0 { |
| 170 return cache.AccessUpdateInterval * time.Duration(1+cache.PruneF
actor) | 171 return cache.AccessUpdateInterval * time.Duration(1+cache.PruneF
actor) |
| 171 } | 172 } |
| 172 return 0 | 173 return 0 |
| 173 } | 174 } |
| 174 | 175 |
| 175 func (cache *Cache) manager() *manager { | 176 func (cache *Cache) manager() *manager { |
| 176 return &manager{ | 177 return &manager{ |
| 177 cache: cache, | 178 cache: cache, |
| 178 » » queryBatchSize: managerQueryBatchSize, | 179 » » queryBatchSize: constraints.DS().QueryBatchSize, |
| 179 } | 180 } |
| 180 } | 181 } |
| 181 | 182 |
| 182 // InstallCronRoute installs a handler for this Cache's management cron task | 183 // InstallCronRoute installs a handler for this Cache's management cron task |
| 183 // into the supplied Router at the specified path. | 184 // into the supplied Router at the specified path. |
| 184 // | 185 // |
| 185 // It is recommended to assert in the middleware that this endpoint is only | 186 // It is recommended to assert in the middleware that this endpoint is only |
| 186 // accessible from a cron task. | 187 // accessible from a cron task. |
| 187 func (cache *Cache) InstallCronRoute(path string, r *router.Router, base router.
MiddlewareChain) { | 188 func (cache *Cache) InstallCronRoute(path string, r *router.Router, base router.
MiddlewareChain) { |
| 188 m := cache.manager() | 189 m := cache.manager() |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 // delta is a factor representing the amount of time that it takes to | 469 // delta is a factor representing the amount of time that it takes to |
| 469 // recalculate the value. Higher delta values allow for earlier recomputation | 470 // recalculate the value. Higher delta values allow for earlier recomputation |
| 470 // for values that take longer to calculate. | 471 // for values that take longer to calculate. |
| 471 // | 472 // |
| 472 // beta can be set to >1 to favor earlier recomputations; however, in practice | 473 // beta can be set to >1 to favor earlier recomputations; however, in practice |
| 473 // beta=1 works well. | 474 // beta=1 works well. |
| 474 func xFetch(now, expiry time.Time, delta time.Duration, beta float64, rf randFun
c) bool { | 475 func xFetch(now, expiry time.Time, delta time.Duration, beta float64, rf randFun
c) bool { |
| 475 offset := time.Duration(float64(delta) * beta * math.Log(rf())) | 476 offset := time.Duration(float64(delta) * beta * math.Log(rf())) |
| 476 return !now.Add(-offset).Before(expiry) | 477 return !now.Add(-offset).Before(expiry) |
| 477 } | 478 } |
| OLD | NEW |