From 0739c36a3b336e8bdce8de34b611a8009ad57c02 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Thu, 30 Mar 2023 13:42:10 +0300 Subject: [PATCH] [#188] metabase: Refactor object put to metabase Resolve funlen linter for db.put method Signed-off-by: Dmitrii Stepanov --- pkg/local_object_storage/metabase/put.go | 53 ++++++++++++++---------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/pkg/local_object_storage/metabase/put.go b/pkg/local_object_storage/metabase/put.go index 07bb4c2b..8e11c5d9 100644 --- a/pkg/local_object_storage/metabase/put.go +++ b/pkg/local_object_storage/metabase/put.go @@ -10,6 +10,7 @@ import ( objectCore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object" storagelog "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/log" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util" + cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" "github.com/nspcc-dev/neo-go/pkg/io" @@ -76,10 +77,11 @@ func (db *DB) Put(prm PutPrm) (res PutRes, err error) { return } -// nolint: funlen -func (db *DB) put( - tx *bbolt.Tx, obj *objectSDK.Object, id []byte, - si *objectSDK.SplitInfo, currEpoch uint64) error { +func (db *DB) put(tx *bbolt.Tx, + obj *objectSDK.Object, + id []byte, + si *objectSDK.SplitInfo, + currEpoch uint64) error { cnr, ok := obj.ContainerID() if !ok { return errors.New("missing container in object") @@ -95,25 +97,34 @@ func (db *DB) put( return err // return any error besides SplitInfoError } - // most right child and split header overlap parent so we have to - // check if object exists to not overwrite it twice if exists { - // When storage engine moves objects between different sub-storages, - // it calls metabase.Put method with new storage ID, thus triggering this code. - if !isParent && id != nil { - return updateStorageID(tx, object.AddressOf(obj), id) - } - - // when storage already has last object in split hierarchy and there is - // a linking object to put (or vice versa), we should update split info - // with object ids of these objects - if isParent { - return updateSplitInfo(tx, object.AddressOf(obj), si) - } - - return nil + return db.updateObj(tx, obj, id, si, isParent) } + return db.insertObject(tx, obj, id, si, isParent, cnr, currEpoch) +} + +func (db *DB) updateObj(tx *bbolt.Tx, obj *objectSDK.Object, id []byte, si *objectSDK.SplitInfo, isParent bool) error { + // most right child and split header overlap parent so we have to + // check if object exists to not overwrite it twice + + // When storage engine moves objects between different sub-storages, + // it calls metabase.Put method with new storage ID, thus triggering this code. + if !isParent && id != nil { + return updateStorageID(tx, object.AddressOf(obj), id) + } + + // when storage already has last object in split hierarchy and there is + // a linking object to put (or vice versa), we should update split info + // with object ids of these objects + if isParent { + return updateSplitInfo(tx, object.AddressOf(obj), si) + } + + return nil +} + +func (db *DB) insertObject(tx *bbolt.Tx, obj *objectSDK.Object, id []byte, si *objectSDK.SplitInfo, isParent bool, cnr cid.ID, currEpoch uint64) error { if par := obj.Parent(); par != nil && !isParent { // limit depth by two parentSI, err := splitInfoFromObject(obj) if err != nil { @@ -126,7 +137,7 @@ func (db *DB) put( } } - err = putUniqueIndexes(tx, obj, si, id) + err := putUniqueIndexes(tx, obj, si, id) if err != nil { return fmt.Errorf("can't put unique indexes: %w", err) }