[#1323] metabase: Resolve funlen linter

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2024-08-20 12:21:39 +03:00 committed by Evgenii Stratonikov
parent 7bf20c9f1f
commit 0f08a2efba

View file

@ -197,46 +197,17 @@ func (db *DB) insertObject(tx *bbolt.Tx, obj *objectSDK.Object, id []byte, si *o
return nil return nil
} }
func putUniqueIndexes( func putUniqueIndexes(tx *bbolt.Tx, obj *objectSDK.Object, si *objectSDK.SplitInfo, id []byte) error {
tx *bbolt.Tx,
obj *objectSDK.Object,
si *objectSDK.SplitInfo,
id []byte,
) error {
isParent := si != nil isParent := si != nil
addr := objectCore.AddressOf(obj) addr := objectCore.AddressOf(obj)
cnr := addr.Container()
objKey := objectKey(addr.Object(), make([]byte, objectKeySize)) objKey := objectKey(addr.Object(), make([]byte, objectKeySize))
bucketName := make([]byte, bucketKeySize) bucketName := make([]byte, bucketKeySize)
// add value to primary unique bucket
if !isParent { if !isParent {
switch obj.Type() { err := putRawObjectData(tx, obj, bucketName, addr, objKey)
case objectSDK.TypeRegular:
bucketName = primaryBucketName(cnr, bucketName)
case objectSDK.TypeTombstone:
bucketName = tombstoneBucketName(cnr, bucketName)
case objectSDK.TypeLock:
bucketName = bucketNameLockers(cnr, bucketName)
default:
return ErrUnknownObjectType
}
rawObject, err := obj.CutPayload().Marshal()
if err != nil {
return fmt.Errorf("can't marshal object header: %w", err)
}
err = putUniqueIndexItem(tx, namedBucketItem{
name: bucketName,
key: objKey,
val: rawObject,
})
if err != nil { if err != nil {
return err return err
} }
// index storageID if it is present
if id != nil { if id != nil {
if err = setStorageID(tx, objectCore.AddressOf(obj), id, false); err != nil { if err = setStorageID(tx, objectCore.AddressOf(obj), id, false); err != nil {
return err return err
@ -244,10 +215,40 @@ func putUniqueIndexes(
} }
} }
if err := putExpirationEpoch(tx, obj, addr, objKey); err != nil {
return err
}
return putSplitInfo(tx, obj, bucketName, addr, si, objKey)
}
func putRawObjectData(tx *bbolt.Tx, obj *objectSDK.Object, bucketName []byte, addr oid.Address, objKey []byte) error {
switch obj.Type() {
case objectSDK.TypeRegular:
bucketName = primaryBucketName(addr.Container(), bucketName)
case objectSDK.TypeTombstone:
bucketName = tombstoneBucketName(addr.Container(), bucketName)
case objectSDK.TypeLock:
bucketName = bucketNameLockers(addr.Container(), bucketName)
default:
return ErrUnknownObjectType
}
rawObject, err := obj.CutPayload().Marshal()
if err != nil {
return fmt.Errorf("can't marshal object header: %w", err)
}
return putUniqueIndexItem(tx, namedBucketItem{
name: bucketName,
key: objKey,
val: rawObject,
})
}
func putExpirationEpoch(tx *bbolt.Tx, obj *objectSDK.Object, addr oid.Address, objKey []byte) error {
if expEpoch, ok := hasExpirationEpoch(obj); ok { if expEpoch, ok := hasExpirationEpoch(obj); ok {
err := putUniqueIndexItem(tx, namedBucketItem{ err := putUniqueIndexItem(tx, namedBucketItem{
name: expEpochToObjectBucketName, name: expEpochToObjectBucketName,
key: expirationEpochKey(expEpoch, cnr, addr.Object()), key: expirationEpochKey(expEpoch, addr.Container(), addr.Object()),
val: zeroValue, val: zeroValue,
}) })
if err != nil { if err != nil {
@ -256,7 +257,7 @@ func putUniqueIndexes(
val := make([]byte, epochSize) val := make([]byte, epochSize)
binary.LittleEndian.PutUint64(val, expEpoch) binary.LittleEndian.PutUint64(val, expEpoch)
err = putUniqueIndexItem(tx, namedBucketItem{ err = putUniqueIndexItem(tx, namedBucketItem{
name: objectToExpirationEpochBucketName(cnr, make([]byte, bucketKeySize)), name: objectToExpirationEpochBucketName(addr.Container(), make([]byte, bucketKeySize)),
key: objKey, key: objKey,
val: val, val: val,
}) })
@ -264,8 +265,10 @@ func putUniqueIndexes(
return err return err
} }
} }
return nil
}
// index root object func putSplitInfo(tx *bbolt.Tx, obj *objectSDK.Object, bucketName []byte, addr oid.Address, si *objectSDK.SplitInfo, objKey []byte) error {
if obj.Type() == objectSDK.TypeRegular && !obj.HasParent() { if obj.Type() == objectSDK.TypeRegular && !obj.HasParent() {
if ecHead := obj.ECHeader(); ecHead != nil { if ecHead := obj.ECHeader(); ecHead != nil {
parentID := ecHead.Parent() parentID := ecHead.Parent()
@ -283,9 +286,8 @@ func putUniqueIndexes(
} }
objKey = objectKey(parentID, objKey) objKey = objectKey(parentID, objKey)
} }
return updateSplitInfoIndex(tx, objKey, cnr, bucketName, si) return updateSplitInfoIndex(tx, objKey, addr.Container(), bucketName, si)
} }
return nil return nil
} }