mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-09 22:51:02 +00:00
poll places in usage calculation to check for closing
This commit is contained in:
parent
a9079815b2
commit
041ae01da1
1 changed files with 17 additions and 2 deletions
19
api.go
19
api.go
|
|
@ -994,10 +994,14 @@ func (api *API) calculateUsage() {
|
|||
|
||||
lastUpdated := api.usageCache.lastUpdated
|
||||
if time.Since(lastUpdated) > api.usageCache.refreshInterval {
|
||||
indexDetails, nodeMetadataBytes, err := api.holder.Txf().IndexUsageDetails()
|
||||
indexDetails, nodeMetadataBytes, err := api.holder.Txf().IndexUsageDetails(api.isClosing)
|
||||
if err != nil {
|
||||
api.server.logger.Infof("couldn't get index usage details: %s", err)
|
||||
}
|
||||
if api.isClosing() {
|
||||
return
|
||||
}
|
||||
|
||||
totalSize := nodeMetadataBytes
|
||||
for _, s := range indexDetails {
|
||||
totalSize += s.Total
|
||||
|
|
@ -1042,7 +1046,8 @@ func (api *API) calculateUsage() {
|
|||
}
|
||||
|
||||
// Periodically calculates disk usage
|
||||
func (api *API) RefreshUsageCache(refresh time.Duration, trigger chan bool) {
|
||||
func (api *API) RefreshUsageCache(refresh time.Duration) {
|
||||
trigger := make(chan bool)
|
||||
defer close(trigger)
|
||||
api.usageCache = &usageCache{
|
||||
data: make(map[string]NodeUsage),
|
||||
|
|
@ -1075,6 +1080,16 @@ func (api *API) ResetUsageCache() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// isClosing returns true if the server is shutting down.
|
||||
func (api *API) isClosing() bool {
|
||||
select {
|
||||
case <-api.server.closing:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// RecalculateCaches forces all TopN caches to be updated.
|
||||
// This is done internally within a TopN query, but a user may want to do it ahead of time?
|
||||
func (api *API) RecalculateCaches(ctx context.Context) error {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue