forked from TrueCloudLab/frostfs-node
[#1377] oid, cid: Upgrade SDK package
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
f65898a354
commit
f15e6e888f
118 changed files with 1455 additions and 886 deletions
|
@ -87,6 +87,11 @@ func (db *DB) Put(prm *PutPrm) (res *PutRes, err error) {
|
|||
}
|
||||
|
||||
func (db *DB) put(tx *bbolt.Tx, obj *objectSDK.Object, id *blobovnicza.ID, si *objectSDK.SplitInfo) error {
|
||||
cnr, ok := obj.ContainerID()
|
||||
if !ok {
|
||||
return errors.New("missing container in object")
|
||||
}
|
||||
|
||||
isParent := si != nil
|
||||
|
||||
exists, err := db.exists(tx, object.AddressOf(obj))
|
||||
|
@ -148,7 +153,7 @@ func (db *DB) put(tx *bbolt.Tx, obj *objectSDK.Object, id *blobovnicza.ID, si *o
|
|||
if obj.Type() == objectSDK.TypeRegular && !isParent {
|
||||
err = changeContainerSize(
|
||||
tx,
|
||||
obj.ContainerID(),
|
||||
&cnr,
|
||||
obj.PayloadSize(),
|
||||
true,
|
||||
)
|
||||
|
@ -168,7 +173,9 @@ func putUniqueIndexes(
|
|||
) error {
|
||||
isParent := si != nil
|
||||
addr := object.AddressOf(obj)
|
||||
objKey := objectKey(addr.ObjectID())
|
||||
idObj, _ := addr.ObjectID()
|
||||
cnr, _ := addr.ContainerID()
|
||||
objKey := objectKey(&idObj)
|
||||
|
||||
// add value to primary unique bucket
|
||||
if !isParent {
|
||||
|
@ -176,13 +183,13 @@ func putUniqueIndexes(
|
|||
|
||||
switch obj.Type() {
|
||||
case objectSDK.TypeRegular:
|
||||
bucketName = primaryBucketName(addr.ContainerID())
|
||||
bucketName = primaryBucketName(&cnr)
|
||||
case objectSDK.TypeTombstone:
|
||||
bucketName = tombstoneBucketName(addr.ContainerID())
|
||||
bucketName = tombstoneBucketName(&cnr)
|
||||
case objectSDK.TypeStorageGroup:
|
||||
bucketName = storageGroupBucketName(addr.ContainerID())
|
||||
bucketName = storageGroupBucketName(&cnr)
|
||||
case objectSDK.TypeLock:
|
||||
bucketName = bucketNameLockers(*addr.ContainerID())
|
||||
bucketName = bucketNameLockers(cnr)
|
||||
default:
|
||||
return ErrUnknownObjectType
|
||||
}
|
||||
|
@ -204,7 +211,7 @@ func putUniqueIndexes(
|
|||
// index blobovniczaID if it is present
|
||||
if id != nil {
|
||||
err = putUniqueIndexItem(tx, namedBucketItem{
|
||||
name: smallBucketName(addr.ContainerID()),
|
||||
name: smallBucketName(&cnr),
|
||||
key: objKey,
|
||||
val: *id,
|
||||
})
|
||||
|
@ -229,7 +236,7 @@ func putUniqueIndexes(
|
|||
}
|
||||
|
||||
err = putUniqueIndexItem(tx, namedBucketItem{
|
||||
name: rootBucketName(addr.ContainerID()),
|
||||
name: rootBucketName(&cnr),
|
||||
key: objKey,
|
||||
val: splitInfo,
|
||||
})
|
||||
|
@ -245,13 +252,15 @@ type updateIndexItemFunc = func(tx *bbolt.Tx, item namedBucketItem) error
|
|||
|
||||
func updateListIndexes(tx *bbolt.Tx, obj *objectSDK.Object, f updateIndexItemFunc) error {
|
||||
addr := object.AddressOf(obj)
|
||||
objKey := objectKey(addr.ObjectID())
|
||||
idObj, _ := addr.ObjectID()
|
||||
cnr, _ := addr.ContainerID()
|
||||
objKey := objectKey(&idObj)
|
||||
|
||||
cs, _ := obj.PayloadChecksum()
|
||||
|
||||
// index payload hashes
|
||||
err := f(tx, namedBucketItem{
|
||||
name: payloadHashBucketName(addr.ContainerID()),
|
||||
name: payloadHashBucketName(&cnr),
|
||||
key: cs.Value(),
|
||||
val: objKey,
|
||||
})
|
||||
|
@ -259,11 +268,13 @@ func updateListIndexes(tx *bbolt.Tx, obj *objectSDK.Object, f updateIndexItemFun
|
|||
return err
|
||||
}
|
||||
|
||||
idParent, ok := obj.ParentID()
|
||||
|
||||
// index parent ids
|
||||
if obj.ParentID() != nil {
|
||||
if ok {
|
||||
err := f(tx, namedBucketItem{
|
||||
name: parentBucketName(addr.ContainerID()),
|
||||
key: objectKey(obj.ParentID()),
|
||||
name: parentBucketName(&cnr),
|
||||
key: objectKey(&idParent),
|
||||
val: objKey,
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -274,7 +285,7 @@ func updateListIndexes(tx *bbolt.Tx, obj *objectSDK.Object, f updateIndexItemFun
|
|||
// index split ids
|
||||
if obj.SplitID() != nil {
|
||||
err := f(tx, namedBucketItem{
|
||||
name: splitBucketName(addr.ContainerID()),
|
||||
name: splitBucketName(&cnr),
|
||||
key: obj.SplitID().ToV2(),
|
||||
val: objKey,
|
||||
})
|
||||
|
@ -288,12 +299,14 @@ func updateListIndexes(tx *bbolt.Tx, obj *objectSDK.Object, f updateIndexItemFun
|
|||
|
||||
func updateFKBTIndexes(tx *bbolt.Tx, obj *objectSDK.Object, f updateIndexItemFunc) error {
|
||||
addr := object.AddressOf(obj)
|
||||
objKey := []byte(addr.ObjectID().String())
|
||||
cnr, _ := addr.ContainerID()
|
||||
id, _ := addr.ObjectID()
|
||||
objKey := []byte(id.EncodeToString())
|
||||
|
||||
attrs := obj.Attributes()
|
||||
|
||||
err := f(tx, namedBucketItem{
|
||||
name: ownerBucketName(addr.ContainerID()),
|
||||
name: ownerBucketName(&cnr),
|
||||
key: []byte(obj.OwnerID().String()),
|
||||
val: objKey,
|
||||
})
|
||||
|
@ -304,7 +317,7 @@ func updateFKBTIndexes(tx *bbolt.Tx, obj *objectSDK.Object, f updateIndexItemFun
|
|||
// user specified attributes
|
||||
for i := range attrs {
|
||||
err := f(tx, namedBucketItem{
|
||||
name: attributeBucketName(addr.ContainerID(), attrs[i].Key()),
|
||||
name: attributeBucketName(&cnr, attrs[i].Key()),
|
||||
key: []byte(attrs[i].Value()),
|
||||
val: objKey,
|
||||
})
|
||||
|
@ -433,25 +446,33 @@ func getVarUint(data []byte) (uint64, int, error) {
|
|||
// updateBlobovniczaID for existing objects if they were moved from from
|
||||
// one blobovnicza to another.
|
||||
func updateBlobovniczaID(tx *bbolt.Tx, addr *addressSDK.Address, id *blobovnicza.ID) error {
|
||||
bkt, err := tx.CreateBucketIfNotExists(smallBucketName(addr.ContainerID()))
|
||||
cnr, _ := addr.ContainerID()
|
||||
|
||||
bkt, err := tx.CreateBucketIfNotExists(smallBucketName(&cnr))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return bkt.Put(objectKey(addr.ObjectID()), *id)
|
||||
idObj, _ := addr.ObjectID()
|
||||
|
||||
return bkt.Put(objectKey(&idObj), *id)
|
||||
}
|
||||
|
||||
// updateSpliInfo for existing objects if storage filled with extra information
|
||||
// about last object in split hierarchy or linking object.
|
||||
func updateSplitInfo(tx *bbolt.Tx, addr *addressSDK.Address, from *objectSDK.SplitInfo) error {
|
||||
bkt := tx.Bucket(rootBucketName(addr.ContainerID()))
|
||||
cnr, _ := addr.ContainerID()
|
||||
|
||||
bkt := tx.Bucket(rootBucketName(&cnr))
|
||||
if bkt == nil {
|
||||
// if object doesn't exists and we want to update split info on it
|
||||
// then ignore, this should never happen
|
||||
return ErrIncorrectSplitInfoUpdate
|
||||
}
|
||||
|
||||
objectKey := objectKey(addr.ObjectID())
|
||||
id, _ := addr.ObjectID()
|
||||
|
||||
objectKey := objectKey(&id)
|
||||
|
||||
rawSplitInfo := bkt.Get(objectKey)
|
||||
if len(rawSplitInfo) == 0 {
|
||||
|
@ -487,9 +508,19 @@ func splitInfoFromObject(obj *objectSDK.Object) (*objectSDK.SplitInfo, error) {
|
|||
|
||||
switch {
|
||||
case isLinkObject(obj):
|
||||
info.SetLink(obj.ID())
|
||||
id, ok := obj.ID()
|
||||
if !ok {
|
||||
return nil, errors.New("missing object ID")
|
||||
}
|
||||
|
||||
info.SetLink(id)
|
||||
case isLastObject(obj):
|
||||
info.SetLastPart(obj.ID())
|
||||
id, ok := obj.ID()
|
||||
if !ok {
|
||||
return nil, errors.New("missing object ID")
|
||||
}
|
||||
|
||||
info.SetLastPart(id)
|
||||
default:
|
||||
return nil, ErrIncorrectRootObject // should never happen
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue