frostfs-node/pkg/local_object_storage/writecache/state.go
Dmitrii Stepanov b142b6f48e [#1367] fstree: Add size to file counter
FSTree file counter used by writecache. As writecache has now only one
storage, so it is required to use real object size to get writecache
size more accurate than `count * max_object_size`.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2024-09-12 15:06:33 +03:00

25 lines
587 B
Go

package writecache
func (c *cache) estimateCacheSize() (uint64, uint64) {
count, size := c.counter.CountSize()
c.metrics.SetEstimateSize(0, size)
c.metrics.SetActualCounters(0, count)
return count, size
}
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
}
func (c *cache) initCounters() error {
c.estimateCacheSize()
return nil
}