forked from TrueCloudLab/frostfs-node
[#1296] writecache: Add count limit
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
36efccd862
commit
08b1f18bca
10 changed files with 65 additions and 20 deletions
|
@ -9,7 +9,7 @@ import (
|
|||
"go.etcd.io/bbolt"
|
||||
)
|
||||
|
||||
func (c *cache) estimateCacheSize() uint64 {
|
||||
func (c *cache) estimateCacheSize() (uint64, uint64) {
|
||||
dbCount := c.objCounters.DB()
|
||||
fsCount := c.objCounters.FS()
|
||||
if fsCount > 0 {
|
||||
|
@ -19,15 +19,23 @@ func (c *cache) estimateCacheSize() uint64 {
|
|||
fsSize := fsCount * c.maxObjectSize
|
||||
c.metrics.SetEstimateSize(dbSize, fsSize)
|
||||
c.metrics.SetActualCounters(dbCount, fsCount)
|
||||
return dbSize + fsSize
|
||||
return dbCount + fsCount, dbSize + fsSize
|
||||
}
|
||||
|
||||
func (c *cache) incSizeDB(sz uint64) uint64 {
|
||||
return sz + c.smallObjectSize
|
||||
func (c *cache) hasEnoughSpaceDB() bool {
|
||||
return c.hasEnoughSpace(c.smallObjectSize)
|
||||
}
|
||||
|
||||
func (c *cache) incSizeFS(sz uint64) uint64 {
|
||||
return sz + c.maxObjectSize
|
||||
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
|
||||
}
|
||||
|
||||
var _ fstree.FileCounter = &counters{}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue