mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-27 02:46:47 +01:00
04a05f161c
This is needed for preserving backwards compatibility with the previous releases of VictoriaMetrics. Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3203
34 lines
512 B
Go
34 lines
512 B
Go
package promql
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
|
|
)
|
|
|
|
type memoryLimiter struct {
|
|
MaxSize uint64
|
|
|
|
mu sync.Mutex
|
|
usage uint64
|
|
}
|
|
|
|
func (ml *memoryLimiter) Get(n uint64) bool {
|
|
ml.mu.Lock()
|
|
ok := n <= ml.MaxSize && ml.MaxSize-n >= ml.usage
|
|
if ok {
|
|
ml.usage += n
|
|
}
|
|
ml.mu.Unlock()
|
|
return ok
|
|
}
|
|
|
|
func (ml *memoryLimiter) Put(n uint64) {
|
|
ml.mu.Lock()
|
|
if n > ml.usage {
|
|
logger.Panicf("BUG: n=%d cannot exceed %d", n, ml.usage)
|
|
}
|
|
ml.usage -= n
|
|
ml.mu.Unlock()
|
|
}
|