forked from TrueCloudLab/frostfs-node
[#776] writecache: Limit size of used disk space
There is a need to limit disk space used by write-cache. It is almost impossible to calculate the value exactly. It is proposed to estimate the size of the cache by the number of objects stored in it. Track amounts of objects saved in DB and FSTree separately. To do this, `ObjectCounters` interface is defined. It is generalized to a store of numbers that can be made persistent (new option `WithObjectCounters`). By default DB number is calculated as key number in default bucket, and FS number is set same to DB since it is currently hard to read the actual value from `FSTree` instance. Each PUT/DELETE operation to DB or FS increases/decreases corresponding counter. Before each PUT op an overflow check is performed with the following formula for evaluating the occupied space: `NumDB * MaxDBSize + NumFS * MaxFSSize`. If next PUT can cause write-cache overflow, object is written to the main storage. By default maximum write-cache size is set to 1GB. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
0a130177d6
commit
a1696a81b6
6 changed files with 203 additions and 10 deletions
|
@ -26,6 +26,11 @@ type options struct {
|
|||
smallObjectSize uint64
|
||||
// workersCount is the number of workers flushing objects in parallel.
|
||||
workersCount int
|
||||
// maxCacheSize is the maximum total size of all objects saved in cache (DB + FS).
|
||||
// 1 GiB by default.
|
||||
maxCacheSize uint64
|
||||
// objCounters is an ObjectCounters instance needed for cache size estimation.
|
||||
objCounters ObjectCounters
|
||||
}
|
||||
|
||||
// WithLogger sets logger.
|
||||
|
@ -88,3 +93,17 @@ func WithFlushWorkersCount(c int) Option {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// WithObjectCounters sets ObjectCounters instance needed for cache write-cache size estimation.
|
||||
func WithObjectCounters(v ObjectCounters) Option {
|
||||
return func(o *options) {
|
||||
o.objCounters = v
|
||||
}
|
||||
}
|
||||
|
||||
// WithMaxCacheSize sets maximum write-cache size in bytes.
|
||||
func WithMaxCacheSize(sz uint64) Option {
|
||||
return func(o *options) {
|
||||
o.maxCacheSize = sz
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue