[#1658] meta: Do not check object expiration in counters

Do not perform operations that produce unused results in `syncCounter`.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-09-12 20:35:44 +03:00 committed by LeL
parent 431e331373
commit 532c41ca05
2 changed files with 9 additions and 8 deletions

View file

@ -83,8 +83,6 @@ func (db *DB) init(reset bool) error {
string(shardInfoBucket): {},
}
epoch := db.epochState.CurrentEpoch()
return db.boltDB.Update(func(tx *bbolt.Tx) error {
var err error
if !reset {
@ -108,7 +106,7 @@ func (db *DB) init(reset bool) error {
}
if !reset {
err = syncCounter(tx, epoch, false)
err = syncCounter(tx, false)
if err != nil {
return fmt.Errorf("could not sync object counter: %w", err)
}
@ -132,10 +130,8 @@ func (db *DB) init(reset bool) error {
// SyncCounters forces to synchronize the object counters.
func (db *DB) SyncCounters() error {
epoch := db.epochState.CurrentEpoch()
return db.boltDB.Update(func(tx *bbolt.Tx) error {
return syncCounter(tx, epoch, true)
return syncCounter(tx, true)
})
}

View file

@ -108,7 +108,7 @@ func (db *DB) updateCounter(tx *bbolt.Tx, typ objectType, delta uint64, inc bool
//
// Does nothing if counters are not empty and force is false. If force is
// true, updates the counters anyway.
func syncCounter(tx *bbolt.Tx, epoch uint64, force bool) error {
func syncCounter(tx *bbolt.Tx, force bool) error {
b, err := tx.CreateBucketIfNotExists(shardInfoBucket)
if err != nil {
return fmt.Errorf("could not get shard info bucket: %w", err)
@ -123,13 +123,18 @@ func syncCounter(tx *bbolt.Tx, epoch uint64, force bool) error {
var phyCounter uint64
var logicCounter uint64
graveyardBKT := tx.Bucket(graveyardBucketName)
garbageBKT := tx.Bucket(garbageBucketName)
err = iteratePhyObjects(tx, func(cnr cid.ID, obj oid.ID) error {
phyCounter++
addr.SetContainer(cnr)
addr.SetObject(obj)
if st := objectStatus(tx, addr, epoch); st == 0 || st == 3 {
// check if an object is available: not with GCMark
// and not covered with a tombstone
if inGraveyardWithKey(addressKey(addr), graveyardBKT, garbageBKT) == 0 {
logicCounter++
}