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
|
@ -3,33 +3,10 @@ package writecache
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree"
|
||||
"go.etcd.io/bbolt"
|
||||
"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 {
|
||||
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 {
|
||||
cDB, cFS atomic.Uint64
|
||||
|
||||
db *bbolt.DB
|
||||
|
||||
fs *fstree.FSTree
|
||||
}
|
||||
|
||||
func (x *counters) IncDB() {
|
||||
|
@ -74,33 +47,26 @@ func (x *counters) FS() uint64 {
|
|||
return x.cFS.Load()
|
||||
}
|
||||
|
||||
func (x *counters) Read() error {
|
||||
func (c *cache) initCounters() error {
|
||||
var inDB uint64
|
||||
|
||||
err := x.db.View(func(tx *bbolt.Tx) error {
|
||||
err := c.db.View(func(tx *bbolt.Tx) error {
|
||||
b := tx.Bucket(defaultBucket)
|
||||
if b != nil {
|
||||
inDB = uint64(b.Stats().KeyN)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not read write-cache DB counter: %w", err)
|
||||
}
|
||||
|
||||
x.cDB.Store(inDB)
|
||||
|
||||
inFS, err := x.fs.NumberOfObjects()
|
||||
inFS, err := c.fsTree.NumberOfObjects()
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
|
||||
func (x *counters) FlushAndClose() {
|
||||
// values aren't stored
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue