cache/dynacache: Prevent multiple concurrent resizes

Updates #12129
This commit is contained in:
Bjørn Erik Pedersen 2024-02-23 17:23:37 +01:00
parent bf14d0cb26
commit 564bae06f6
No known key found for this signature in database

View file

@ -119,7 +119,8 @@ func (o OptionsPartition) CalculateMaxSize(maxSizePerPartition int) int {
// A dynamic partitioned cache.
type Cache struct {
mu sync.RWMutex
mu sync.RWMutex
resizeMu sync.Mutex
partitions map[string]PartitionManager
@ -231,6 +232,12 @@ func (c *Cache) Stop() {
}
func (c *Cache) adjustCurrentMaxSize() {
if !c.resizeMu.TryLock() {
// Prevent multiple concurrent resizes.
return
}
defer c.resizeMu.Unlock()
c.mu.RLock()
defer c.mu.RUnlock()