2023-12-22 09:58:20 +00:00
|
|
|
package writecache
|
2021-09-08 09:32:20 +00:00
|
|
|
|
2024-08-06 12:09:12 +00:00
|
|
|
func (c *cache) estimateCacheSize() (uint64, uint64) {
|
2024-09-10 08:01:30 +00:00
|
|
|
count, size := c.counter.CountSize()
|
2024-09-11 06:55:08 +00:00
|
|
|
c.metrics.SetEstimateSize(size)
|
|
|
|
c.metrics.SetActualCounters(count)
|
2024-09-10 08:01:30 +00:00
|
|
|
return count, size
|
2021-09-08 09:32:20 +00:00
|
|
|
}
|
|
|
|
|
2024-08-06 12:09:12 +00:00
|
|
|
func (c *cache) hasEnoughSpaceFS() bool {
|
|
|
|
return c.hasEnoughSpace(c.maxObjectSize)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *cache) hasEnoughSpace(objectSize uint64) bool {
|
|
|
|
count, size := c.estimateCacheSize()
|
|
|
|
if c.maxCacheCount > 0 && count+1 > c.maxCacheCount {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return c.maxCacheSize >= size+objectSize
|
2021-09-08 09:32:20 +00:00
|
|
|
}
|
|
|
|
|
2023-08-11 08:32:43 +00:00
|
|
|
func (c *cache) initCounters() error {
|
2023-10-27 06:53:12 +00:00
|
|
|
c.estimateCacheSize()
|
2021-09-08 09:32:20 +00:00
|
|
|
return nil
|
|
|
|
}
|