forked from TrueCloudLab/frostfs-node
[#1745] writecache: Simplify object counters
Remove unused option and additional pointers to db/fstree. Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
This commit is contained in:
parent
20abdaeed4
commit
bda084f331
3 changed files with 8 additions and 59 deletions
|
@ -31,8 +31,8 @@ type options struct {
|
||||||
// maxCacheSize is the maximum total size of all objects saved in cache (DB + FS).
|
// maxCacheSize is the maximum total size of all objects saved in cache (DB + FS).
|
||||||
// 1 GiB by default.
|
// 1 GiB by default.
|
||||||
maxCacheSize uint64
|
maxCacheSize uint64
|
||||||
// objCounters is an ObjectCounters instance needed for cache size estimation.
|
// objCounters contains atomic counters for the number of objects stored in cache.
|
||||||
objCounters ObjectCounters
|
objCounters counters
|
||||||
// maxBatchSize is the maximum batch size for the small object database.
|
// maxBatchSize is the maximum batch size for the small object database.
|
||||||
maxBatchSize int
|
maxBatchSize int
|
||||||
// maxBatchDelay is the maximum batch wait time for the small object database.
|
// maxBatchDelay is the maximum batch wait time for the small object database.
|
||||||
|
@ -100,13 +100,6 @@ 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.
|
// WithMaxCacheSize sets maximum write-cache size in bytes.
|
||||||
func WithMaxCacheSize(sz uint64) Option {
|
func WithMaxCacheSize(sz uint64) Option {
|
||||||
return func(o *options) {
|
return func(o *options) {
|
||||||
|
|
|
@ -3,33 +3,10 @@ package writecache
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree"
|
|
||||||
"go.etcd.io/bbolt"
|
"go.etcd.io/bbolt"
|
||||||
"go.uber.org/atomic"
|
"go.uber.org/atomic"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ObjectCounters is an interface of the storage of cached object amount.
|
|
||||||
type ObjectCounters interface {
|
|
||||||
// Increments number of objects saved in DB.
|
|
||||||
IncDB()
|
|
||||||
// Decrements number of objects saved in DB.
|
|
||||||
DecDB()
|
|
||||||
// Returns number of objects saved in DB.
|
|
||||||
DB() uint64
|
|
||||||
|
|
||||||
// Increments number of objects saved in FSTree.
|
|
||||||
IncFS()
|
|
||||||
// Decrements number of objects saved in FSTree.
|
|
||||||
DecFS()
|
|
||||||
// Returns number of objects saved in FSTree.
|
|
||||||
FS() uint64
|
|
||||||
|
|
||||||
// Reads number of objects saved in write-cache. It is called on write-cache initialization step.
|
|
||||||
Read() error
|
|
||||||
// Flushes the values and closes the storage. It is called on write-cache shutdown.
|
|
||||||
FlushAndClose()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *cache) estimateCacheSize() uint64 {
|
func (c *cache) estimateCacheSize() uint64 {
|
||||||
return c.objCounters.DB()*c.smallObjectSize + c.objCounters.FS()*c.maxObjectSize
|
return c.objCounters.DB()*c.smallObjectSize + c.objCounters.FS()*c.maxObjectSize
|
||||||
}
|
}
|
||||||
|
@ -44,10 +21,6 @@ func (c *cache) incSizeFS(sz uint64) uint64 {
|
||||||
|
|
||||||
type counters struct {
|
type counters struct {
|
||||||
cDB, cFS atomic.Uint64
|
cDB, cFS atomic.Uint64
|
||||||
|
|
||||||
db *bbolt.DB
|
|
||||||
|
|
||||||
fs *fstree.FSTree
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *counters) IncDB() {
|
func (x *counters) IncDB() {
|
||||||
|
@ -74,33 +47,26 @@ func (x *counters) FS() uint64 {
|
||||||
return x.cFS.Load()
|
return x.cFS.Load()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *counters) Read() error {
|
func (c *cache) initCounters() error {
|
||||||
var inDB uint64
|
var inDB uint64
|
||||||
|
err := c.db.View(func(tx *bbolt.Tx) error {
|
||||||
err := x.db.View(func(tx *bbolt.Tx) error {
|
|
||||||
b := tx.Bucket(defaultBucket)
|
b := tx.Bucket(defaultBucket)
|
||||||
if b != nil {
|
if b != nil {
|
||||||
inDB = uint64(b.Stats().KeyN)
|
inDB = uint64(b.Stats().KeyN)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not read write-cache DB counter: %w", err)
|
return fmt.Errorf("could not read write-cache DB counter: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
x.cDB.Store(inDB)
|
inFS, err := c.fsTree.NumberOfObjects()
|
||||||
|
|
||||||
inFS, err := x.fs.NumberOfObjects()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not read write-cache FS counter: %w", err)
|
return fmt.Errorf("could not read write-cache FS counter: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
x.cFS.Store(inFS)
|
c.objCounters.cDB.Store(inDB)
|
||||||
|
c.objCounters.cFS.Store(inFS)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *counters) FlushAndClose() {
|
|
||||||
// values aren't stored
|
|
||||||
}
|
|
||||||
|
|
|
@ -124,12 +124,7 @@ func (c *cache) Open(readOnly bool) error {
|
||||||
// thus we need to create a channel here.
|
// thus we need to create a channel here.
|
||||||
c.closeCh = make(chan struct{})
|
c.closeCh = make(chan struct{})
|
||||||
|
|
||||||
c.objCounters = &counters{
|
return c.initCounters()
|
||||||
db: c.db,
|
|
||||||
fs: c.fsTree,
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.objCounters.Read()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init runs necessary services.
|
// Init runs necessary services.
|
||||||
|
@ -154,11 +149,6 @@ func (c *cache) Close() error {
|
||||||
c.closeCh = nil
|
c.closeCh = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.objCounters != nil {
|
|
||||||
c.objCounters.FlushAndClose()
|
|
||||||
c.objCounters = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
if c.db != nil {
|
if c.db != nil {
|
||||||
err = c.db.Close()
|
err = c.db.Close()
|
||||||
|
|
Loading…
Reference in a new issue