[#1658] meta: Force counters resync process

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-09-08 20:32:02 +03:00 committed by LeL
parent beb7f2a048
commit d872862710
3 changed files with 21 additions and 4 deletions

View file

@ -106,7 +106,7 @@ func (db *DB) init(reset bool) error {
}
if !reset {
err = syncCounter(tx)
err = syncCounter(tx, false)
if err != nil {
return fmt.Errorf("could not sync object counter: %w", err)
}
@ -128,6 +128,13 @@ func (db *DB) init(reset bool) error {
})
}
// SyncCounters forces to synchronize the object counters.
func (db *DB) SyncCounters() error {
return db.boltDB.Update(func(tx *bbolt.Tx) error {
return syncCounter(tx, true)
})
}
// Close closes boltDB instance.
func (db *DB) Close() error {
if db.boltDB != nil {

View file

@ -66,7 +66,7 @@ func (db *DB) updateCounter(tx *bbolt.Tx, delta uint64, inc bool) error {
// Tx MUST be writable.
//
// Does nothing if counter not empty.
func syncCounter(tx *bbolt.Tx) error {
func syncCounter(tx *bbolt.Tx, force bool) error {
var counter uint64
b, err := tx.CreateBucketIfNotExists(shardInfoBucket)
@ -75,7 +75,7 @@ func syncCounter(tx *bbolt.Tx) error {
}
data := b.Get(objectCounterKey)
if len(data) == 8 {
if len(data) == 8 && !force {
return nil
}

View file

@ -159,7 +159,7 @@ func (s *Shard) refillMetabase() error {
obj := objectSDK.New()
return blobstor.IterateBinaryObjects(s.blobStor, func(addr oid.Address, data []byte, descriptor []byte) error {
err = blobstor.IterateBinaryObjects(s.blobStor, func(addr oid.Address, data []byte, descriptor []byte) error {
if err := obj.Unmarshal(data); err != nil {
s.log.Warn("could not unmarshal object",
zap.Stringer("address", addr),
@ -224,6 +224,16 @@ func (s *Shard) refillMetabase() error {
return nil
})
if err != nil {
return fmt.Errorf("could not put objects to the meta: %w", err)
}
err = s.metaBase.SyncCounters()
if err != nil {
return fmt.Errorf("could not sync object counters: %w", err)
}
return nil
}
// Close releases all Shard's components.