diff --git a/posting/lists.go b/posting/lists.go index fa2fc1c6605..d0c388a7d60 100644 --- a/posting/lists.go +++ b/posting/lists.go @@ -46,9 +46,6 @@ func SetEnabledDetailedMetrics(enableMetrics bool) { EnableDetailedMetrics = enableMetrics } -func UpdateMaxCost(maxCost int64) { -} - // Cleanup waits until the closer has finished processing. func Cleanup() { closer.SignalAndWait() diff --git a/posting/mvcc.go b/posting/mvcc.go index 06b70fdce57..4af32a1e2e3 100644 --- a/posting/mvcc.go +++ b/posting/mvcc.go @@ -405,6 +405,13 @@ func (ml *MemoryLayer) del(key []byte) { ml.cache.del(key) } +func (ml *MemoryLayer) UpdateMaxCost(maxCost int64) { + if ml.cache == nil || ml.cache.data == nil { + return + } + ml.cache.data.UpdateMaxCost(maxCost) +} + type IterateDiskArgs struct { Prefix []byte Prefetch bool diff --git a/worker/worker.go b/worker/worker.go index d48ae161d06..990c49dd348 100644 --- a/worker/worker.go +++ b/worker/worker.go @@ -150,7 +150,9 @@ func UpdateCacheMb(memoryMB int64) error { blockCacheSize := (cachePercent[1] * (memoryMB << 20)) / 100 indexCacheSize := (cachePercent[2] * (memoryMB << 20)) / 100 - posting.UpdateMaxCost(plCacheSize) + if posting.MemLayerInstance != nil { + posting.MemLayerInstance.UpdateMaxCost(plCacheSize) + } if _, err := pstore.CacheMaxCost(badger.BlockCache, blockCacheSize); err != nil { return errors.Wrapf(err, "cannot update block cache size") }