mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
reset cache if outdated on call
This commit is contained in:
parent
4baffff847
commit
486244ab58
1 changed files with 19 additions and 0 deletions
19
api.go
19
api.go
|
|
@ -957,7 +957,17 @@ func (api *API) Usage(ctx context.Context, remote bool) (map[string]NodeUsage, e
|
|||
|
||||
api.usageCache.muAssign.Lock()
|
||||
lastUpdated := api.usageCache.lastUpdated
|
||||
cacheN := len(api.usageCache.data[api.server.nodeID].Disk.IndexUsage)
|
||||
api.usageCache.muAssign.Unlock()
|
||||
holderN := len(api.holder.Indexes())
|
||||
|
||||
// reset cache if server was started with no data, and data has subsequently been added
|
||||
if cacheN == 0 && holderN > 0 {
|
||||
err := api.ResetUsageCache()
|
||||
if err != nil {
|
||||
api.server.logger.Infof("data detected but could not recalculate cache: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
var t time.Time
|
||||
if lastUpdated == t {
|
||||
|
|
@ -968,6 +978,15 @@ func (api *API) Usage(ctx context.Context, remote bool) (map[string]NodeUsage, e
|
|||
api.requestUsageOfNodes()
|
||||
}
|
||||
|
||||
// triggers recalculation of cache in background, ahead of schedule, if number of indexes in
|
||||
// cache differs from number of indexes in holder
|
||||
if cacheN > 0 && cacheN != holderN {
|
||||
err := api.ResetUsageCache()
|
||||
if err != nil {
|
||||
api.server.logger.Infof("resetting cache in background: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
return api.usageCache.data, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue