[#1214] *: Use single Object
type in whole project
Remove `Object` and `RawObject` types from `pkg/core/object` package. Use `Object` type from NeoFS SDK Go library everywhere. Avoid using the deprecated elements. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
19ad349b27
commit
7ccd1625af
100 changed files with 847 additions and 965 deletions
|
@ -430,7 +430,7 @@ func putObject(cmd *cobra.Command, _ []string) {
|
||||||
expAttr.SetValue(strconv.FormatUint(expiresOn, 10))
|
expAttr.SetValue(strconv.FormatUint(expiresOn, 10))
|
||||||
}
|
}
|
||||||
|
|
||||||
obj := object.NewRaw()
|
obj := object.New()
|
||||||
obj.SetContainerID(cid)
|
obj.SetContainerID(cid)
|
||||||
obj.SetOwnerID(ownerID)
|
obj.SetOwnerID(ownerID)
|
||||||
obj.SetAttributes(attrs...)
|
obj.SetAttributes(attrs...)
|
||||||
|
@ -441,7 +441,7 @@ func putObject(cmd *cobra.Command, _ []string) {
|
||||||
sessionObjectCtxAddress.SetContainerID(cid)
|
sessionObjectCtxAddress.SetContainerID(cid)
|
||||||
prepareSessionPrmWithOwner(cmd, sessionObjectCtxAddress, key, ownerID, &prm)
|
prepareSessionPrmWithOwner(cmd, sessionObjectCtxAddress, key, ownerID, &prm)
|
||||||
prepareObjectPrm(cmd, &prm)
|
prepareObjectPrm(cmd, &prm)
|
||||||
prm.SetHeader(obj.Object())
|
prm.SetHeader(obj)
|
||||||
prm.SetPayloadReader(f)
|
prm.SetPayloadReader(f)
|
||||||
|
|
||||||
res, err := internalclient.PutObject(prm)
|
res, err := internalclient.PutObject(prm)
|
||||||
|
|
|
@ -7,9 +7,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
internalclient "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/client"
|
internalclient "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/client"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/storagegroup"
|
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/storagegroup"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||||
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
||||||
|
@ -149,13 +148,13 @@ func (c sgHeadReceiver) Head(addr *addressSDK.Address) (interface{}, error) {
|
||||||
|
|
||||||
res, err := internalclient.HeadObject(c.prm)
|
res, err := internalclient.HeadObject(c.prm)
|
||||||
|
|
||||||
var errSplitInfo *objectSDK.SplitInfoError
|
var errSplitInfo *object.SplitInfoError
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
default:
|
default:
|
||||||
return nil, err
|
return nil, err
|
||||||
case err == nil:
|
case err == nil:
|
||||||
return object.NewFromSDK(res.Header()), nil
|
return res.Header(), nil
|
||||||
case errors.As(err, &errSplitInfo):
|
case errors.As(err, &errSplitInfo):
|
||||||
return errSplitInfo.SplitInfo(), nil
|
return errSplitInfo.SplitInfo(), nil
|
||||||
}
|
}
|
||||||
|
@ -205,12 +204,12 @@ func putSG(cmd *cobra.Command, _ []string) {
|
||||||
sgContent, err := sg.Marshal()
|
sgContent, err := sg.Marshal()
|
||||||
exitOnErr(cmd, errf("could not marshal storage group: %w", err))
|
exitOnErr(cmd, errf("could not marshal storage group: %w", err))
|
||||||
|
|
||||||
obj := objectSDK.NewRaw()
|
obj := object.New()
|
||||||
obj.SetContainerID(cid)
|
obj.SetContainerID(cid)
|
||||||
obj.SetOwnerID(ownerID)
|
obj.SetOwnerID(ownerID)
|
||||||
obj.SetType(objectSDK.TypeStorageGroup)
|
obj.SetType(object.TypeStorageGroup)
|
||||||
|
|
||||||
putPrm.SetHeader(obj.Object())
|
putPrm.SetHeader(obj)
|
||||||
putPrm.SetPayloadReader(bytes.NewReader(sgContent))
|
putPrm.SetPayloadReader(bytes.NewReader(sgContent))
|
||||||
|
|
||||||
res, err := internalclient.PutObject(putPrm)
|
res, err := internalclient.PutObject(putPrm)
|
||||||
|
|
|
@ -68,7 +68,7 @@ func NewFormatValidator(opts ...FormatValidatorOption) *FormatValidator {
|
||||||
// Does not validate payload checksum and content.
|
// Does not validate payload checksum and content.
|
||||||
//
|
//
|
||||||
// Returns nil error if object has valid structure.
|
// Returns nil error if object has valid structure.
|
||||||
func (v *FormatValidator) Validate(obj *Object) error {
|
func (v *FormatValidator) Validate(obj *object.Object) error {
|
||||||
if obj == nil {
|
if obj == nil {
|
||||||
return errNilObject
|
return errNilObject
|
||||||
} else if obj.ID() == nil {
|
} else if obj.ID() == nil {
|
||||||
|
@ -93,18 +93,18 @@ func (v *FormatValidator) Validate(obj *Object) error {
|
||||||
return fmt.Errorf("object did not pass expiration check: %w", err)
|
return fmt.Errorf("object did not pass expiration check: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := object.CheckHeaderVerificationFields(obj.SDK()); err != nil {
|
if err := object.CheckHeaderVerificationFields(obj); err != nil {
|
||||||
return fmt.Errorf("(%T) could not validate header fields: %w", v, err)
|
return fmt.Errorf("(%T) could not validate header fields: %w", v, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if obj = obj.GetParent(); obj != nil {
|
if obj = obj.Parent(); obj != nil {
|
||||||
return v.Validate(obj)
|
return v.Validate(obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *FormatValidator) validateSignatureKey(obj *Object) error {
|
func (v *FormatValidator) validateSignatureKey(obj *object.Object) error {
|
||||||
token := obj.SessionToken()
|
token := obj.SessionToken()
|
||||||
key := obj.Signature().Key()
|
key := obj.Signature().Key()
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ func (v *FormatValidator) checkOwnerKey(id *owner.ID, key []byte) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateContent validates payload content according to object type.
|
// ValidateContent validates payload content according to object type.
|
||||||
func (v *FormatValidator) ValidateContent(o *Object) error {
|
func (v *FormatValidator) ValidateContent(o *object.Object) error {
|
||||||
switch o.Type() {
|
switch o.Type() {
|
||||||
case object.TypeTombstone:
|
case object.TypeTombstone:
|
||||||
if len(o.Payload()) == 0 {
|
if len(o.Payload()) == 0 {
|
||||||
|
@ -174,7 +174,7 @@ func (v *FormatValidator) ValidateContent(o *Object) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if v.deleteHandler != nil {
|
if v.deleteHandler != nil {
|
||||||
v.deleteHandler.DeleteObjects(o.Address(), addrList...)
|
v.deleteHandler.DeleteObjects(AddressOf(o), addrList...)
|
||||||
}
|
}
|
||||||
case object.TypeStorageGroup:
|
case object.TypeStorageGroup:
|
||||||
if len(o.Payload()) == 0 {
|
if len(o.Payload()) == 0 {
|
||||||
|
@ -201,7 +201,7 @@ func (v *FormatValidator) ValidateContent(o *Object) error {
|
||||||
|
|
||||||
var errExpired = errors.New("object has expired")
|
var errExpired = errors.New("object has expired")
|
||||||
|
|
||||||
func (v *FormatValidator) checkExpiration(obj *Object) error {
|
func (v *FormatValidator) checkExpiration(obj *object.Object) error {
|
||||||
exp, err := expirationEpochAttribute(obj)
|
exp, err := expirationEpochAttribute(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, errNoExpirationEpoch) {
|
if errors.Is(err, errNoExpirationEpoch) {
|
||||||
|
@ -218,7 +218,7 @@ func (v *FormatValidator) checkExpiration(obj *Object) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func expirationEpochAttribute(obj *Object) (uint64, error) {
|
func expirationEpochAttribute(obj *object.Object) (uint64, error) {
|
||||||
for _, a := range obj.Attributes() {
|
for _, a := range obj.Attributes() {
|
||||||
if a.Key() != objectV2.SysAttributeExpEpoch {
|
if a.Key() != objectV2.SysAttributeExpEpoch {
|
||||||
continue
|
continue
|
||||||
|
@ -235,7 +235,7 @@ var (
|
||||||
errEmptyAttrVal = errors.New("empty attribute value")
|
errEmptyAttrVal = errors.New("empty attribute value")
|
||||||
)
|
)
|
||||||
|
|
||||||
func (v *FormatValidator) checkAttributes(obj *Object) error {
|
func (v *FormatValidator) checkAttributes(obj *object.Object) error {
|
||||||
as := obj.Attributes()
|
as := obj.Attributes()
|
||||||
|
|
||||||
mUnique := make(map[string]struct{}, len(as))
|
mUnique := make(map[string]struct{}, len(as))
|
||||||
|
@ -259,7 +259,7 @@ func (v *FormatValidator) checkAttributes(obj *Object) error {
|
||||||
|
|
||||||
var errIncorrectOwner = errors.New("incorrect object owner")
|
var errIncorrectOwner = errors.New("incorrect object owner")
|
||||||
|
|
||||||
func (v *FormatValidator) checkOwner(obj *Object) error {
|
func (v *FormatValidator) checkOwner(obj *object.Object) error {
|
||||||
// TODO: use appropriate functionality after neofs-api-go#352
|
// TODO: use appropriate functionality after neofs-api-go#352
|
||||||
if len(obj.OwnerID().ToV2().GetValue()) != owner.NEO3WalletSize {
|
if len(obj.OwnerID().ToV2().GetValue()) != owner.NEO3WalletSize {
|
||||||
return errIncorrectOwner
|
return errIncorrectOwner
|
||||||
|
|
|
@ -35,8 +35,8 @@ func testObjectID(t *testing.T) *oidSDK.ID {
|
||||||
return id
|
return id
|
||||||
}
|
}
|
||||||
|
|
||||||
func blankValidObject(key *ecdsa.PrivateKey) *RawObject {
|
func blankValidObject(key *ecdsa.PrivateKey) *object.Object {
|
||||||
obj := NewRaw()
|
obj := object.New()
|
||||||
obj.SetContainerID(cidtest.ID())
|
obj.SetContainerID(cidtest.ID())
|
||||||
obj.SetOwnerID(owner.NewIDFromPublicKey(&key.PublicKey))
|
obj.SetOwnerID(owner.NewIDFromPublicKey(&key.PublicKey))
|
||||||
|
|
||||||
|
@ -68,24 +68,24 @@ func TestFormatValidator_Validate(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("nil identifier", func(t *testing.T) {
|
t.Run("nil identifier", func(t *testing.T) {
|
||||||
obj := NewRaw()
|
obj := object.New()
|
||||||
|
|
||||||
require.True(t, errors.Is(v.Validate(obj.Object()), errNilID))
|
require.True(t, errors.Is(v.Validate(obj), errNilID))
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("nil container identifier", func(t *testing.T) {
|
t.Run("nil container identifier", func(t *testing.T) {
|
||||||
obj := NewRaw()
|
obj := object.New()
|
||||||
obj.SetID(testObjectID(t))
|
obj.SetID(testObjectID(t))
|
||||||
|
|
||||||
require.True(t, errors.Is(v.Validate(obj.Object()), errNilCID))
|
require.True(t, errors.Is(v.Validate(obj), errNilCID))
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("unsigned object", func(t *testing.T) {
|
t.Run("unsigned object", func(t *testing.T) {
|
||||||
obj := NewRaw()
|
obj := object.New()
|
||||||
obj.SetContainerID(cidtest.ID())
|
obj.SetContainerID(cidtest.ID())
|
||||||
obj.SetID(testObjectID(t))
|
obj.SetID(testObjectID(t))
|
||||||
|
|
||||||
require.Error(t, v.Validate(obj.Object()))
|
require.Error(t, v.Validate(obj))
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("correct w/ session token", func(t *testing.T) {
|
t.Run("correct w/ session token", func(t *testing.T) {
|
||||||
|
@ -94,29 +94,29 @@ func TestFormatValidator_Validate(t *testing.T) {
|
||||||
tok := sessiontest.Token()
|
tok := sessiontest.Token()
|
||||||
tok.SetOwnerID(oid)
|
tok.SetOwnerID(oid)
|
||||||
|
|
||||||
obj := NewRaw()
|
obj := object.New()
|
||||||
obj.SetContainerID(cidtest.ID())
|
obj.SetContainerID(cidtest.ID())
|
||||||
obj.SetSessionToken(sessiontest.Token())
|
obj.SetSessionToken(sessiontest.Token())
|
||||||
obj.SetOwnerID(tok.OwnerID())
|
obj.SetOwnerID(tok.OwnerID())
|
||||||
|
|
||||||
require.NoError(t, object.SetIDWithSignature(&ownerKey.PrivateKey, obj.SDK()))
|
require.NoError(t, object.SetIDWithSignature(&ownerKey.PrivateKey, obj))
|
||||||
|
|
||||||
require.NoError(t, v.Validate(obj.Object()))
|
require.NoError(t, v.Validate(obj))
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("correct w/o session token", func(t *testing.T) {
|
t.Run("correct w/o session token", func(t *testing.T) {
|
||||||
obj := blankValidObject(&ownerKey.PrivateKey)
|
obj := blankValidObject(&ownerKey.PrivateKey)
|
||||||
|
|
||||||
require.NoError(t, object.SetIDWithSignature(&ownerKey.PrivateKey, obj.SDK()))
|
require.NoError(t, object.SetIDWithSignature(&ownerKey.PrivateKey, obj))
|
||||||
|
|
||||||
require.NoError(t, v.Validate(obj.Object()))
|
require.NoError(t, v.Validate(obj))
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("tombstone content", func(t *testing.T) {
|
t.Run("tombstone content", func(t *testing.T) {
|
||||||
obj := NewRaw()
|
obj := object.New()
|
||||||
obj.SetType(object.TypeTombstone)
|
obj.SetType(object.TypeTombstone)
|
||||||
|
|
||||||
require.Error(t, v.ValidateContent(obj.Object())) // no tombstone content
|
require.Error(t, v.ValidateContent(obj)) // no tombstone content
|
||||||
|
|
||||||
content := object.NewTombstone()
|
content := object.NewTombstone()
|
||||||
content.SetMembers([]*oidSDK.ID{nil})
|
content.SetMembers([]*oidSDK.ID{nil})
|
||||||
|
@ -126,7 +126,7 @@ func TestFormatValidator_Validate(t *testing.T) {
|
||||||
|
|
||||||
obj.SetPayload(data)
|
obj.SetPayload(data)
|
||||||
|
|
||||||
require.Error(t, v.ValidateContent(obj.Object())) // no members in tombstone
|
require.Error(t, v.ValidateContent(obj)) // no members in tombstone
|
||||||
|
|
||||||
content.SetMembers([]*oidSDK.ID{testObjectID(t)})
|
content.SetMembers([]*oidSDK.ID{testObjectID(t)})
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ func TestFormatValidator_Validate(t *testing.T) {
|
||||||
|
|
||||||
obj.SetPayload(data)
|
obj.SetPayload(data)
|
||||||
|
|
||||||
require.Error(t, v.ValidateContent(obj.Object())) // no expiration epoch in tombstone
|
require.Error(t, v.ValidateContent(obj)) // no expiration epoch in tombstone
|
||||||
|
|
||||||
expirationAttribute := object.NewAttribute()
|
expirationAttribute := object.NewAttribute()
|
||||||
expirationAttribute.SetKey(objectV2.SysAttributeExpEpoch)
|
expirationAttribute.SetKey(objectV2.SysAttributeExpEpoch)
|
||||||
|
@ -143,7 +143,7 @@ func TestFormatValidator_Validate(t *testing.T) {
|
||||||
|
|
||||||
obj.SetAttributes(expirationAttribute)
|
obj.SetAttributes(expirationAttribute)
|
||||||
|
|
||||||
require.Error(t, v.ValidateContent(obj.Object())) // different expiration values
|
require.Error(t, v.ValidateContent(obj)) // different expiration values
|
||||||
|
|
||||||
content.SetExpirationEpoch(10)
|
content.SetExpirationEpoch(10)
|
||||||
data, err = content.Marshal()
|
data, err = content.Marshal()
|
||||||
|
@ -151,14 +151,14 @@ func TestFormatValidator_Validate(t *testing.T) {
|
||||||
|
|
||||||
obj.SetPayload(data)
|
obj.SetPayload(data)
|
||||||
|
|
||||||
require.NoError(t, v.ValidateContent(obj.Object())) // all good
|
require.NoError(t, v.ValidateContent(obj)) // all good
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("storage group content", func(t *testing.T) {
|
t.Run("storage group content", func(t *testing.T) {
|
||||||
obj := NewRaw()
|
obj := object.New()
|
||||||
obj.SetType(object.TypeStorageGroup)
|
obj.SetType(object.TypeStorageGroup)
|
||||||
|
|
||||||
require.Error(t, v.ValidateContent(obj.Object()))
|
require.Error(t, v.ValidateContent(obj))
|
||||||
|
|
||||||
content := storagegroup.New()
|
content := storagegroup.New()
|
||||||
content.SetMembers([]*oidSDK.ID{nil})
|
content.SetMembers([]*oidSDK.ID{nil})
|
||||||
|
@ -168,7 +168,7 @@ func TestFormatValidator_Validate(t *testing.T) {
|
||||||
|
|
||||||
obj.SetPayload(data)
|
obj.SetPayload(data)
|
||||||
|
|
||||||
require.Error(t, v.ValidateContent(obj.Object()))
|
require.Error(t, v.ValidateContent(obj))
|
||||||
|
|
||||||
content.SetMembers([]*oidSDK.ID{testObjectID(t)})
|
content.SetMembers([]*oidSDK.ID{testObjectID(t)})
|
||||||
|
|
||||||
|
@ -177,11 +177,11 @@ func TestFormatValidator_Validate(t *testing.T) {
|
||||||
|
|
||||||
obj.SetPayload(data)
|
obj.SetPayload(data)
|
||||||
|
|
||||||
require.NoError(t, v.ValidateContent(obj.Object()))
|
require.NoError(t, v.ValidateContent(obj))
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("expiration", func(t *testing.T) {
|
t.Run("expiration", func(t *testing.T) {
|
||||||
fn := func(val string) *Object {
|
fn := func(val string) *object.Object {
|
||||||
obj := blankValidObject(&ownerKey.PrivateKey)
|
obj := blankValidObject(&ownerKey.PrivateKey)
|
||||||
|
|
||||||
a := object.NewAttribute()
|
a := object.NewAttribute()
|
||||||
|
@ -190,9 +190,9 @@ func TestFormatValidator_Validate(t *testing.T) {
|
||||||
|
|
||||||
obj.SetAttributes(a)
|
obj.SetAttributes(a)
|
||||||
|
|
||||||
require.NoError(t, object.SetIDWithSignature(&ownerKey.PrivateKey, obj.SDK()))
|
require.NoError(t, object.SetIDWithSignature(&ownerKey.PrivateKey, obj))
|
||||||
|
|
||||||
return obj.Object()
|
return obj
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Run("invalid attribute value", func(t *testing.T) {
|
t.Run("invalid attribute value", func(t *testing.T) {
|
||||||
|
@ -228,12 +228,12 @@ func TestFormatValidator_Validate(t *testing.T) {
|
||||||
|
|
||||||
obj.SetAttributes(a1, a2)
|
obj.SetAttributes(a1, a2)
|
||||||
|
|
||||||
err := v.checkAttributes(obj.Object())
|
err := v.checkAttributes(obj)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
a2.SetKey(a1.Key())
|
a2.SetKey(a1.Key())
|
||||||
|
|
||||||
err = v.checkAttributes(obj.Object())
|
err = v.checkAttributes(obj)
|
||||||
require.Equal(t, errDuplAttr, err)
|
require.Equal(t, errDuplAttr, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -245,7 +245,7 @@ func TestFormatValidator_Validate(t *testing.T) {
|
||||||
|
|
||||||
obj.SetAttributes(a)
|
obj.SetAttributes(a)
|
||||||
|
|
||||||
err := v.checkAttributes(obj.Object())
|
err := v.checkAttributes(obj)
|
||||||
require.Equal(t, errEmptyAttrVal, err)
|
require.Equal(t, errEmptyAttrVal, err)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,70 +1,18 @@
|
||||||
package object
|
package object
|
||||||
|
|
||||||
import (
|
import (
|
||||||
objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object"
|
|
||||||
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Object represents the NeoFS object.
|
// AddressOf returns address of the object.
|
||||||
//
|
func AddressOf(obj *object.Object) *addressSDK.Address {
|
||||||
// Object inherits object type from NeoFS SDK.
|
if obj != nil {
|
||||||
// It is used to implement some useful methods and functions
|
addr := addressSDK.NewAddress()
|
||||||
// for convenient processing of an object by a node.
|
addr.SetObjectID(obj.ID())
|
||||||
type Object struct {
|
addr.SetContainerID(obj.ContainerID())
|
||||||
*object.Object
|
|
||||||
}
|
|
||||||
|
|
||||||
// Address returns address of the object.
|
return addr
|
||||||
func (o *Object) Address() *addressSDK.Address {
|
|
||||||
if o != nil {
|
|
||||||
aV2 := new(refs.Address)
|
|
||||||
aV2.SetObjectID(o.ID().ToV2())
|
|
||||||
aV2.SetContainerID(o.ContainerID().ToV2())
|
|
||||||
|
|
||||||
return addressSDK.NewAddressFromV2(aV2)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SDK returns NeoFS SDK object instance.
|
|
||||||
func (o *Object) SDK() *object.Object {
|
|
||||||
if o != nil {
|
|
||||||
return o.Object
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewFromV2 constructs Object instance from v2 Object message.
|
|
||||||
func NewFromV2(obj *objectV2.Object) *Object {
|
|
||||||
return &Object{
|
|
||||||
Object: object.NewFromV2(obj),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewFromSDK constructs Object instance from NeoFS SDK Object.
|
|
||||||
func NewFromSDK(obj *object.Object) *Object {
|
|
||||||
return &Object{
|
|
||||||
Object: obj,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// New constructs blank Object instance.
|
|
||||||
func New() *Object {
|
|
||||||
return NewFromSDK(object.New())
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetParent returns parent object.
|
|
||||||
func (o *Object) GetParent() *Object {
|
|
||||||
if o != nil {
|
|
||||||
if par := o.Object.Parent(); par != nil {
|
|
||||||
return &Object{
|
|
||||||
Object: par,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -1,72 +0,0 @@
|
||||||
package object
|
|
||||||
|
|
||||||
import (
|
|
||||||
objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object"
|
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/object"
|
|
||||||
)
|
|
||||||
|
|
||||||
// RawObject represents the raw NeoFS object.
|
|
||||||
//
|
|
||||||
// RawObject inherits RawObject type from NeoFS SDK.
|
|
||||||
// It is used to implement some useful methods and functions
|
|
||||||
// for convenient processing of a raw object by a node.
|
|
||||||
type RawObject struct {
|
|
||||||
*object.RawObject
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewRawFromV2 constructs RawObject instance from v2 Object message.
|
|
||||||
func NewRawFromV2(obj *objectV2.Object) *RawObject {
|
|
||||||
return &RawObject{
|
|
||||||
RawObject: object.NewRawFromV2(obj),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewRawFrom constructs RawObject instance from NeoFS SDK RawObject.
|
|
||||||
func NewRawFrom(obj *object.RawObject) *RawObject {
|
|
||||||
return &RawObject{
|
|
||||||
RawObject: obj,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewRawFromObject wraps Object instance to RawObject.
|
|
||||||
func NewRawFromObject(obj *Object) *RawObject {
|
|
||||||
return NewRawFrom(object.NewRawFrom(obj.SDK()))
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewRaw constructs blank RawObject instance.
|
|
||||||
func NewRaw() *RawObject {
|
|
||||||
return NewRawFrom(object.NewRaw())
|
|
||||||
}
|
|
||||||
|
|
||||||
// SDK converts RawObject to NeoFS SDK RawObject instance.
|
|
||||||
func (o *RawObject) SDK() *object.RawObject {
|
|
||||||
if o != nil {
|
|
||||||
return o.RawObject
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Object converts RawObject to read-only Object instance.
|
|
||||||
func (o *RawObject) Object() *Object {
|
|
||||||
if o != nil {
|
|
||||||
return &Object{
|
|
||||||
Object: o.RawObject.Object(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// CutPayload returns RawObject w/ empty payload.
|
|
||||||
//
|
|
||||||
// Changes of non-payload fields affect source object.
|
|
||||||
func (o *RawObject) CutPayload() *RawObject {
|
|
||||||
if o != nil {
|
|
||||||
return &RawObject{
|
|
||||||
RawObject: o.RawObject.CutPayload(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
|
@ -160,7 +160,7 @@ func (x Client) GetObject(prm GetObjectPrm) (*GetObjectRes, error) {
|
||||||
return nil, fmt.Errorf("read payload: %w", err)
|
return nil, fmt.Errorf("read payload: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
object.NewRawFrom(&obj).SetPayload(buf)
|
obj.SetPayload(buf)
|
||||||
|
|
||||||
return &GetObjectRes{
|
return &GetObjectRes{
|
||||||
obj: &obj,
|
obj: &obj,
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
|
||||||
storagelog "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/internal/log"
|
storagelog "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/internal/log"
|
||||||
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
@ -572,7 +573,7 @@ func (b *blobovniczas) getObject(blz *blobovnicza.Blobovnicza, prm *blobovnicza.
|
||||||
}
|
}
|
||||||
|
|
||||||
// unmarshal the object
|
// unmarshal the object
|
||||||
obj := object.New()
|
obj := objectSDK.New()
|
||||||
if err := obj.Unmarshal(data); err != nil {
|
if err := obj.Unmarshal(data); err != nil {
|
||||||
return nil, fmt.Errorf("could not unmarshal the object: %w", err)
|
return nil, fmt.Errorf("could not unmarshal the object: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -605,7 +606,7 @@ func (b *blobovniczas) getObjectRange(blz *blobovnicza.Blobovnicza, prm *GetRang
|
||||||
}
|
}
|
||||||
|
|
||||||
// unmarshal the object
|
// unmarshal the object
|
||||||
obj := object.New()
|
obj := objectSDK.New()
|
||||||
if err := obj.Unmarshal(data); err != nil {
|
if err := obj.Unmarshal(data); err != nil {
|
||||||
return nil, fmt.Errorf("could not unmarshal the object: %w", err)
|
return nil, fmt.Errorf("could not unmarshal the object: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,8 +33,8 @@ func testAddress() *addressSDK.Address {
|
||||||
return addr
|
return addr
|
||||||
}
|
}
|
||||||
|
|
||||||
func testObjectRaw(sz uint64) *object.RawObject {
|
func testObject(sz uint64) *objectSDK.Object {
|
||||||
raw := object.NewRaw()
|
raw := objectSDK.New()
|
||||||
|
|
||||||
addr := testAddress()
|
addr := testAddress()
|
||||||
raw.SetID(addr.ObjectID())
|
raw.SetID(addr.ObjectID())
|
||||||
|
@ -51,10 +51,6 @@ func testObjectRaw(sz uint64) *object.RawObject {
|
||||||
return raw
|
return raw
|
||||||
}
|
}
|
||||||
|
|
||||||
func testObject(sz uint64) *object.Object {
|
|
||||||
return testObjectRaw(sz).Object()
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBlobovniczas(t *testing.T) {
|
func TestBlobovniczas(t *testing.T) {
|
||||||
rand.Seed(1024)
|
rand.Seed(1024)
|
||||||
|
|
||||||
|
@ -91,19 +87,21 @@ func TestBlobovniczas(t *testing.T) {
|
||||||
|
|
||||||
for i := uint64(0); i < minFitObjNum; i++ {
|
for i := uint64(0); i < minFitObjNum; i++ {
|
||||||
obj := testObject(objSz)
|
obj := testObject(objSz)
|
||||||
addrList = append(addrList, obj.Address())
|
addr := object.AddressOf(obj)
|
||||||
|
|
||||||
|
addrList = append(addrList, addr)
|
||||||
|
|
||||||
d, err := obj.Marshal()
|
d, err := obj.Marshal()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// save object in blobovnicza
|
// save object in blobovnicza
|
||||||
id, err := b.put(obj.Address(), d)
|
id, err := b.put(addr, d)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// get w/ blobovnicza ID
|
// get w/ blobovnicza ID
|
||||||
prm := new(GetSmallPrm)
|
prm := new(GetSmallPrm)
|
||||||
prm.SetBlobovniczaID(id)
|
prm.SetBlobovniczaID(id)
|
||||||
prm.SetAddress(obj.Address())
|
prm.SetAddress(addr)
|
||||||
|
|
||||||
res, err := b.get(prm)
|
res, err := b.get(prm)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -119,7 +117,7 @@ func TestBlobovniczas(t *testing.T) {
|
||||||
// get range w/ blobovnicza ID
|
// get range w/ blobovnicza ID
|
||||||
rngPrm := new(GetRangeSmallPrm)
|
rngPrm := new(GetRangeSmallPrm)
|
||||||
rngPrm.SetBlobovniczaID(id)
|
rngPrm.SetBlobovniczaID(id)
|
||||||
rngPrm.SetAddress(obj.Address())
|
rngPrm.SetAddress(addr)
|
||||||
|
|
||||||
payload := obj.Payload()
|
payload := obj.Payload()
|
||||||
pSize := uint64(len(obj.Payload()))
|
pSize := uint64(len(obj.Payload()))
|
||||||
|
|
|
@ -29,19 +29,19 @@ func TestCompression(t *testing.T) {
|
||||||
return bs
|
return bs
|
||||||
}
|
}
|
||||||
|
|
||||||
bigObj := make([]*object.Object, objCount)
|
bigObj := make([]*objectSDK.Object, objCount)
|
||||||
smallObj := make([]*object.Object, objCount)
|
smallObj := make([]*objectSDK.Object, objCount)
|
||||||
for i := 0; i < objCount; i++ {
|
for i := 0; i < objCount; i++ {
|
||||||
bigObj[i] = testObject(smallSizeLimit * 2)
|
bigObj[i] = testObject(smallSizeLimit * 2)
|
||||||
smallObj[i] = testObject(smallSizeLimit / 2)
|
smallObj[i] = testObject(smallSizeLimit / 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
testGet := func(t *testing.T, b *BlobStor, i int) {
|
testGet := func(t *testing.T, b *BlobStor, i int) {
|
||||||
res1, err := b.GetSmall(&GetSmallPrm{address: address{smallObj[i].Address()}})
|
res1, err := b.GetSmall(&GetSmallPrm{address: address{object.AddressOf(smallObj[i])}})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, smallObj[i], res1.Object())
|
require.Equal(t, smallObj[i], res1.Object())
|
||||||
|
|
||||||
res2, err := b.GetBig(&GetBigPrm{address: address{bigObj[i].Address()}})
|
res2, err := b.GetBig(&GetBigPrm{address: address{object.AddressOf(bigObj[i])}})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, bigObj[i], res2.Object())
|
require.Equal(t, bigObj[i], res2.Object())
|
||||||
}
|
}
|
||||||
|
@ -95,15 +95,15 @@ func TestBlobstor_needsCompression(t *testing.T) {
|
||||||
return bs
|
return bs
|
||||||
}
|
}
|
||||||
|
|
||||||
newObjectWithCt := func(contentType string) *object.Object {
|
newObjectWithCt := func(contentType string) *objectSDK.Object {
|
||||||
obj := testObjectRaw(smallSizeLimit + 1)
|
obj := testObject(smallSizeLimit + 1)
|
||||||
if contentType != "" {
|
if contentType != "" {
|
||||||
a := objectSDK.NewAttribute()
|
a := objectSDK.NewAttribute()
|
||||||
a.SetKey(objectSDK.AttributeContentType)
|
a.SetKey(objectSDK.AttributeContentType)
|
||||||
a.SetValue(contentType)
|
a.SetValue(contentType)
|
||||||
obj.SetAttributes(a)
|
obj.SetAttributes(a)
|
||||||
}
|
}
|
||||||
return obj.Object()
|
return obj
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Run("content-types specified", func(t *testing.T) {
|
t.Run("content-types specified", func(t *testing.T) {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree"
|
||||||
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetBigPrm groups the parameters of GetBig operation.
|
// GetBigPrm groups the parameters of GetBig operation.
|
||||||
|
@ -42,7 +43,7 @@ func (b *BlobStor) GetBig(prm *GetBigPrm) (*GetBigRes, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// unmarshal the object
|
// unmarshal the object
|
||||||
obj := object.New()
|
obj := objectSDK.New()
|
||||||
if err := obj.Unmarshal(data); err != nil {
|
if err := obj.Unmarshal(data); err != nil {
|
||||||
return nil, fmt.Errorf("could not unmarshal the object: %w", err)
|
return nil, fmt.Errorf("could not unmarshal the object: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree"
|
||||||
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetRangeBigPrm groups the parameters of GetRangeBig operation.
|
// GetRangeBigPrm groups the parameters of GetRangeBig operation.
|
||||||
|
@ -42,7 +43,7 @@ func (b *BlobStor) GetRangeBig(prm *GetRangeBigPrm) (*GetRangeBigRes, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// unmarshal the object
|
// unmarshal the object
|
||||||
obj := object.New()
|
obj := objectSDK.New()
|
||||||
if err := obj.Unmarshal(data); err != nil {
|
if err := obj.Unmarshal(data); err != nil {
|
||||||
return nil, fmt.Errorf("could not unmarshal the object: %w", err)
|
return nil, fmt.Errorf("could not unmarshal the object: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,9 @@ package blobstor
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree"
|
||||||
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,8 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/klauspost/compress/zstd"
|
"github.com/klauspost/compress/zstd"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
|
||||||
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||||
objecttest "github.com/nspcc-dev/neofs-sdk-go/object/address/test"
|
objecttest "github.com/nspcc-dev/neofs-sdk-go/object/address/test"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -117,7 +117,7 @@ func TestIterate_IgnoreErrors(t *testing.T) {
|
||||||
addrs := make([]*addressSDK.Address, objCount)
|
addrs := make([]*addressSDK.Address, objCount)
|
||||||
for i := range addrs {
|
for i := range addrs {
|
||||||
addrs[i] = objecttest.Address()
|
addrs[i] = objecttest.Address()
|
||||||
obj := object.NewRaw()
|
obj := object.New()
|
||||||
obj.SetContainerID(addrs[i].ContainerID())
|
obj.SetContainerID(addrs[i].ContainerID())
|
||||||
obj.SetID(addrs[i].ObjectID())
|
obj.SetID(addrs[i].ObjectID())
|
||||||
obj.SetPayload(make([]byte, smallSize<<(i%2)))
|
obj.SetPayload(make([]byte, smallSize<<(i%2)))
|
||||||
|
|
|
@ -35,14 +35,14 @@ func (b *BlobStor) Put(prm *PutPrm) (*PutRes, error) {
|
||||||
return nil, fmt.Errorf("could not marshal the object: %w", err)
|
return nil, fmt.Errorf("could not marshal the object: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return b.PutRaw(prm.obj.Address(), data, b.NeedsCompression(prm.obj))
|
return b.PutRaw(object.AddressOf(prm.obj), data, b.NeedsCompression(prm.obj))
|
||||||
}
|
}
|
||||||
|
|
||||||
// NeedsCompression returns true if object should be compressed.
|
// NeedsCompression returns true if object should be compressed.
|
||||||
// For object to be compressed 2 conditions must hold:
|
// For object to be compressed 2 conditions must hold:
|
||||||
// 1. Compression is enabled in settings.
|
// 1. Compression is enabled in settings.
|
||||||
// 2. Object MIME Content-Type is allowed for compression.
|
// 2. Object MIME Content-Type is allowed for compression.
|
||||||
func (b *BlobStor) NeedsCompression(obj *object.Object) bool {
|
func (b *BlobStor) NeedsCompression(obj *objectSDK.Object) bool {
|
||||||
if !b.compressionEnabled || len(b.uncompressableContentTypes) == 0 {
|
if !b.compressionEnabled || len(b.uncompressableContentTypes) == 0 {
|
||||||
return b.compressionEnabled
|
return b.compressionEnabled
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
package blobstor
|
package blobstor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -53,11 +52,11 @@ func (v *rwBlobovniczaID) SetBlobovniczaID(id *blobovnicza.ID) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type roRange struct {
|
type roRange struct {
|
||||||
rng *objectSDK.Range
|
rng *object.Range
|
||||||
}
|
}
|
||||||
|
|
||||||
// Range returns range of the object payload.
|
// Range returns range of the object payload.
|
||||||
func (r roRange) Range() *objectSDK.Range {
|
func (r roRange) Range() *object.Range {
|
||||||
return r.rng
|
return r.rng
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +65,7 @@ type rwRange struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetRange sets range of the object payload.
|
// SetRange sets range of the object payload.
|
||||||
func (r *rwRange) SetRange(rng *objectSDK.Range) {
|
func (r *rwRange) SetRange(rng *object.Range) {
|
||||||
r.rng = rng
|
r.rng = rng
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
||||||
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -19,9 +20,9 @@ func TestExecBlocks(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
// put some object
|
// put some object
|
||||||
obj := generateRawObjectWithCID(t, cidtest.ID()).Object()
|
obj := generateObjectWithCID(t, cidtest.ID())
|
||||||
|
|
||||||
addr := obj.Address()
|
addr := object.AddressOf(obj)
|
||||||
|
|
||||||
require.NoError(t, Put(e, obj))
|
require.NoError(t, Put(e, obj))
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor"
|
||||||
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
||||||
|
@ -18,7 +17,7 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/checksum"
|
"github.com/nspcc-dev/neofs-sdk-go/checksum"
|
||||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||||
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
objecttest "github.com/nspcc-dev/neofs-sdk-go/object/address/test"
|
objecttest "github.com/nspcc-dev/neofs-sdk-go/object/address/test"
|
||||||
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
||||||
|
@ -57,7 +56,7 @@ func benchmarkExists(b *testing.B, shardNum int) {
|
||||||
|
|
||||||
addr := objecttest.Address()
|
addr := objecttest.Address()
|
||||||
for i := 0; i < 100; i++ {
|
for i := 0; i < 100; i++ {
|
||||||
obj := generateRawObjectWithCID(b, cidtest.ID())
|
obj := generateObjectWithCID(b, cidtest.ID())
|
||||||
err := Put(e, obj.Object())
|
err := Put(e, obj.Object())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
|
@ -134,7 +133,7 @@ func testOID() *oidSDK.ID {
|
||||||
return id
|
return id
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateRawObjectWithCID(t testing.TB, cid *cid.ID) *object.RawObject {
|
func generateObjectWithCID(t testing.TB, cid *cid.ID) *object.RawObject {
|
||||||
version := version.New()
|
version := version.New()
|
||||||
version.SetMajor(2)
|
version.SetMajor(2)
|
||||||
version.SetMinor(1)
|
version.SetMinor(1)
|
||||||
|
@ -145,7 +144,7 @@ func generateRawObjectWithCID(t testing.TB, cid *cid.ID) *object.RawObject {
|
||||||
csumTZ := new(checksum.Checksum)
|
csumTZ := new(checksum.Checksum)
|
||||||
csumTZ.SetTillichZemor(tz.Sum(csum.Sum()))
|
csumTZ.SetTillichZemor(tz.Sum(csum.Sum()))
|
||||||
|
|
||||||
obj := object.NewRaw()
|
obj := object.New()
|
||||||
obj.SetID(testOID())
|
obj.SetID(testOID())
|
||||||
obj.SetOwnerID(ownertest.ID())
|
obj.SetOwnerID(ownertest.ID())
|
||||||
obj.SetContainerID(cid)
|
obj.SetContainerID(cid)
|
||||||
|
@ -157,8 +156,8 @@ func generateRawObjectWithCID(t testing.TB, cid *cid.ID) *object.RawObject {
|
||||||
return obj
|
return obj
|
||||||
}
|
}
|
||||||
|
|
||||||
func addAttribute(obj *object.RawObject, key, val string) {
|
func addAttribute(obj *object.Object, key, val string) {
|
||||||
attr := objectSDK.NewAttribute()
|
attr := object.NewAttribute()
|
||||||
attr.SetKey(key)
|
attr.SetKey(key)
|
||||||
attr.SetValue(val)
|
attr.SetValue(val)
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
||||||
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
||||||
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"go.uber.org/zap/zaptest"
|
"go.uber.org/zap/zaptest"
|
||||||
)
|
)
|
||||||
|
@ -61,16 +62,16 @@ func TestErrorReporting(t *testing.T) {
|
||||||
t.Run("ignore errors by default", func(t *testing.T) {
|
t.Run("ignore errors by default", func(t *testing.T) {
|
||||||
e, dir, id := newEngineWithErrorThreshold(t, "", 0)
|
e, dir, id := newEngineWithErrorThreshold(t, "", 0)
|
||||||
|
|
||||||
obj := generateRawObjectWithCID(t, cidtest.ID())
|
obj := generateObjectWithCID(t, cidtest.ID())
|
||||||
obj.SetPayload(make([]byte, errSmallSize))
|
obj.SetPayload(make([]byte, errSmallSize))
|
||||||
|
|
||||||
prm := new(shard.PutPrm).WithObject(obj.Object())
|
prm := new(shard.PutPrm).WithObject(obj)
|
||||||
e.mtx.RLock()
|
e.mtx.RLock()
|
||||||
_, err := e.shards[id[0].String()].Shard.Put(prm)
|
_, err := e.shards[id[0].String()].Shard.Put(prm)
|
||||||
e.mtx.RUnlock()
|
e.mtx.RUnlock()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
_, err = e.Get(&GetPrm{addr: obj.Object().Address()})
|
_, err = e.Get(&GetPrm{addr: object.AddressOf(obj)})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
checkShardState(t, e, id[0], 0, shard.ModeReadWrite)
|
checkShardState(t, e, id[0], 0, shard.ModeReadWrite)
|
||||||
|
@ -79,7 +80,7 @@ func TestErrorReporting(t *testing.T) {
|
||||||
corruptSubDir(t, filepath.Join(dir, "0"))
|
corruptSubDir(t, filepath.Join(dir, "0"))
|
||||||
|
|
||||||
for i := uint32(1); i < 3; i++ {
|
for i := uint32(1); i < 3; i++ {
|
||||||
_, err = e.Get(&GetPrm{addr: obj.Object().Address()})
|
_, err = e.Get(&GetPrm{addr: object.AddressOf(obj)})
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
checkShardState(t, e, id[0], i, shard.ModeReadWrite)
|
checkShardState(t, e, id[0], i, shard.ModeReadWrite)
|
||||||
checkShardState(t, e, id[1], 0, shard.ModeReadWrite)
|
checkShardState(t, e, id[1], 0, shard.ModeReadWrite)
|
||||||
|
@ -90,16 +91,16 @@ func TestErrorReporting(t *testing.T) {
|
||||||
|
|
||||||
e, dir, id := newEngineWithErrorThreshold(t, "", errThreshold)
|
e, dir, id := newEngineWithErrorThreshold(t, "", errThreshold)
|
||||||
|
|
||||||
obj := generateRawObjectWithCID(t, cidtest.ID())
|
obj := generateObjectWithCID(t, cidtest.ID())
|
||||||
obj.SetPayload(make([]byte, errSmallSize))
|
obj.SetPayload(make([]byte, errSmallSize))
|
||||||
|
|
||||||
prm := new(shard.PutPrm).WithObject(obj.Object())
|
prm := new(shard.PutPrm).WithObject(obj)
|
||||||
e.mtx.RLock()
|
e.mtx.RLock()
|
||||||
_, err := e.shards[id[0].String()].Put(prm)
|
_, err := e.shards[id[0].String()].Put(prm)
|
||||||
e.mtx.RUnlock()
|
e.mtx.RUnlock()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
_, err = e.Get(&GetPrm{addr: obj.Object().Address()})
|
_, err = e.Get(&GetPrm{addr: object.AddressOf(obj)})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
checkShardState(t, e, id[0], 0, shard.ModeReadWrite)
|
checkShardState(t, e, id[0], 0, shard.ModeReadWrite)
|
||||||
|
@ -108,14 +109,14 @@ func TestErrorReporting(t *testing.T) {
|
||||||
corruptSubDir(t, filepath.Join(dir, "0"))
|
corruptSubDir(t, filepath.Join(dir, "0"))
|
||||||
|
|
||||||
for i := uint32(1); i < errThreshold; i++ {
|
for i := uint32(1); i < errThreshold; i++ {
|
||||||
_, err = e.Get(&GetPrm{addr: obj.Object().Address()})
|
_, err = e.Get(&GetPrm{addr: object.AddressOf(obj)})
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
checkShardState(t, e, id[0], i, shard.ModeReadWrite)
|
checkShardState(t, e, id[0], i, shard.ModeReadWrite)
|
||||||
checkShardState(t, e, id[1], 0, shard.ModeReadWrite)
|
checkShardState(t, e, id[1], 0, shard.ModeReadWrite)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := uint32(0); i < 2; i++ {
|
for i := uint32(0); i < 2; i++ {
|
||||||
_, err = e.Get(&GetPrm{addr: obj.Object().Address()})
|
_, err = e.Get(&GetPrm{addr: object.AddressOf(obj)})
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
checkShardState(t, e, id[0], errThreshold+i, shard.ModeReadOnly)
|
checkShardState(t, e, id[0], errThreshold+i, shard.ModeReadOnly)
|
||||||
checkShardState(t, e, id[1], 0, shard.ModeReadWrite)
|
checkShardState(t, e, id[1], 0, shard.ModeReadWrite)
|
||||||
|
@ -137,9 +138,9 @@ func TestBlobstorFailback(t *testing.T) {
|
||||||
|
|
||||||
e, _, id := newEngineWithErrorThreshold(t, dir, 1)
|
e, _, id := newEngineWithErrorThreshold(t, dir, 1)
|
||||||
|
|
||||||
objs := make([]*object.Object, 0, 2)
|
objs := make([]*objectSDK.Object, 0, 2)
|
||||||
for _, size := range []int{15, errSmallSize + 1} {
|
for _, size := range []int{15, errSmallSize + 1} {
|
||||||
obj := generateRawObjectWithCID(t, cidtest.ID())
|
obj := generateObjectWithCID(t, cidtest.ID())
|
||||||
obj.SetPayload(make([]byte, size))
|
obj.SetPayload(make([]byte, size))
|
||||||
|
|
||||||
prm := new(shard.PutPrm).WithObject(obj.Object())
|
prm := new(shard.PutPrm).WithObject(obj.Object())
|
||||||
|
@ -151,9 +152,10 @@ func TestBlobstorFailback(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range objs {
|
for i := range objs {
|
||||||
_, err = e.Get(&GetPrm{addr: objs[i].Address()})
|
addr := object.AddressOf(objs[i])
|
||||||
|
_, err = e.Get(&GetPrm{addr: addr})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
_, err = e.GetRange(&RngPrm{addr: objs[i].Address()})
|
_, err = e.GetRange(&RngPrm{addr: addr})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,15 +172,16 @@ func TestBlobstorFailback(t *testing.T) {
|
||||||
e, _, id = newEngineWithErrorThreshold(t, dir, 1)
|
e, _, id = newEngineWithErrorThreshold(t, dir, 1)
|
||||||
|
|
||||||
for i := range objs {
|
for i := range objs {
|
||||||
getRes, err := e.Get(&GetPrm{addr: objs[i].Address()})
|
addr := object.AddressOf(objs[i])
|
||||||
|
getRes, err := e.Get(&GetPrm{addr: addr})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, objs[i], getRes.Object())
|
require.Equal(t, objs[i], getRes.Object())
|
||||||
|
|
||||||
rngRes, err := e.GetRange(&RngPrm{addr: objs[i].Address(), off: 1, ln: 10})
|
rngRes, err := e.GetRange(&RngPrm{addr: addr, off: 1, ln: 10})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, objs[i].Payload()[1:11], rngRes.Object().Payload())
|
require.Equal(t, objs[i].Payload()[1:11], rngRes.Object().Payload())
|
||||||
|
|
||||||
_, err = e.GetRange(&RngPrm{addr: objs[i].Address(), off: errSmallSize + 10, ln: 1})
|
_, err = e.GetRange(&RngPrm{addr: addr, off: errSmallSize + 10, ln: 1})
|
||||||
require.True(t, errors.Is(err, object.ErrRangeOutOfBounds), "got: %v", err)
|
require.True(t, errors.Is(err, object.ErrRangeOutOfBounds), "got: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ type GetPrm struct {
|
||||||
|
|
||||||
// GetRes groups resulting values of Get operation.
|
// GetRes groups resulting values of Get operation.
|
||||||
type GetRes struct {
|
type GetRes struct {
|
||||||
obj *object.Object
|
obj *objectSDK.Object
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithAddress is a Get option to set the address of the requested object.
|
// WithAddress is a Get option to set the address of the requested object.
|
||||||
|
@ -33,7 +33,7 @@ func (p *GetPrm) WithAddress(addr *addressSDK.Address) *GetPrm {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Object returns the requested object.
|
// Object returns the requested object.
|
||||||
func (r *GetRes) Object() *object.Object {
|
func (r *GetRes) Object() *objectSDK.Object {
|
||||||
return r.obj
|
return r.obj
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ func (e *StorageEngine) get(prm *GetPrm) (*GetRes, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
obj *object.Object
|
obj *objectSDK.Object
|
||||||
siErr *objectSDK.SplitInfoError
|
siErr *objectSDK.SplitInfoError
|
||||||
|
|
||||||
outSI *objectSDK.SplitInfo
|
outSI *objectSDK.SplitInfo
|
||||||
|
@ -145,7 +145,7 @@ func (e *StorageEngine) get(prm *GetPrm) (*GetRes, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get reads object from local storage by provided address.
|
// Get reads object from local storage by provided address.
|
||||||
func Get(storage *StorageEngine, addr *addressSDK.Address) (*object.Object, error) {
|
func Get(storage *StorageEngine, addr *addressSDK.Address) (*objectSDK.Object, error) {
|
||||||
res, err := storage.Get(new(GetPrm).
|
res, err := storage.Get(new(GetPrm).
|
||||||
WithAddress(addr),
|
WithAddress(addr),
|
||||||
)
|
)
|
||||||
|
|
|
@ -18,7 +18,7 @@ type HeadPrm struct {
|
||||||
|
|
||||||
// HeadRes groups resulting values of Head operation.
|
// HeadRes groups resulting values of Head operation.
|
||||||
type HeadRes struct {
|
type HeadRes struct {
|
||||||
head *object.Object
|
head *objectSDK.Object
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithAddress is a Head option to set the address of the requested object.
|
// WithAddress is a Head option to set the address of the requested object.
|
||||||
|
@ -46,7 +46,7 @@ func (p *HeadPrm) WithRaw(raw bool) *HeadPrm {
|
||||||
// Header returns the requested object header.
|
// Header returns the requested object header.
|
||||||
//
|
//
|
||||||
// Instance has empty payload.
|
// Instance has empty payload.
|
||||||
func (r *HeadRes) Header() *object.Object {
|
func (r *HeadRes) Header() *objectSDK.Object {
|
||||||
return r.head
|
return r.head
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ func (e *StorageEngine) head(prm *HeadPrm) (*HeadRes, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
head *object.Object
|
head *objectSDK.Object
|
||||||
siErr *objectSDK.SplitInfoError
|
siErr *objectSDK.SplitInfoError
|
||||||
|
|
||||||
outSI *objectSDK.SplitInfo
|
outSI *objectSDK.SplitInfo
|
||||||
|
@ -135,7 +135,7 @@ func (e *StorageEngine) head(prm *HeadPrm) (*HeadRes, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Head reads object header from local storage by provided address.
|
// Head reads object header from local storage by provided address.
|
||||||
func Head(storage *StorageEngine, addr *addressSDK.Address) (*object.Object, error) {
|
func Head(storage *StorageEngine, addr *addressSDK.Address) (*objectSDK.Object, error) {
|
||||||
res, err := storage.Head(new(HeadPrm).
|
res, err := storage.Head(new(HeadPrm).
|
||||||
WithAddress(addr),
|
WithAddress(addr),
|
||||||
)
|
)
|
||||||
|
@ -148,7 +148,7 @@ func Head(storage *StorageEngine, addr *addressSDK.Address) (*object.Object, err
|
||||||
|
|
||||||
// HeadRaw reads object header from local storage by provided address and raw
|
// HeadRaw reads object header from local storage by provided address and raw
|
||||||
// flag.
|
// flag.
|
||||||
func HeadRaw(storage *StorageEngine, addr *addressSDK.Address, raw bool) (*object.Object, error) {
|
func HeadRaw(storage *StorageEngine, addr *addressSDK.Address, raw bool) (*objectSDK.Object, error) {
|
||||||
res, err := storage.Head(new(HeadPrm).
|
res, err := storage.Head(new(HeadPrm).
|
||||||
WithAddress(addr).
|
WithAddress(addr).
|
||||||
WithRaw(raw),
|
WithRaw(raw),
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
||||||
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
@ -15,22 +15,22 @@ func TestHeadRaw(t *testing.T) {
|
||||||
defer os.RemoveAll(t.Name())
|
defer os.RemoveAll(t.Name())
|
||||||
|
|
||||||
cid := cidtest.ID()
|
cid := cidtest.ID()
|
||||||
splitID := objectSDK.NewSplitID()
|
splitID := object.NewSplitID()
|
||||||
|
|
||||||
parent := generateRawObjectWithCID(t, cid)
|
parent := generateObjectWithCID(t, cid)
|
||||||
addAttribute(parent, "foo", "bar")
|
addAttribute(parent, "foo", "bar")
|
||||||
|
|
||||||
parentAddr := addressSDK.NewAddress()
|
parentAddr := addressSDK.NewAddress()
|
||||||
parentAddr.SetContainerID(cid)
|
parentAddr.SetContainerID(cid)
|
||||||
parentAddr.SetObjectID(parent.ID())
|
parentAddr.SetObjectID(parent.ID())
|
||||||
|
|
||||||
child := generateRawObjectWithCID(t, cid)
|
child := generateObjectWithCID(t, cid)
|
||||||
child.SetParent(parent.Object().SDK())
|
child.SetParent(parent)
|
||||||
child.SetParentID(parent.ID())
|
child.SetParentID(parent.ID())
|
||||||
child.SetSplitID(splitID)
|
child.SetSplitID(splitID)
|
||||||
|
|
||||||
link := generateRawObjectWithCID(t, cid)
|
link := generateObjectWithCID(t, cid)
|
||||||
link.SetParent(parent.Object().SDK())
|
link.SetParent(parent)
|
||||||
link.SetParentID(parent.ID())
|
link.SetParentID(parent.ID())
|
||||||
link.SetChildren(child.ID())
|
link.SetChildren(child.ID())
|
||||||
link.SetSplitID(splitID)
|
link.SetSplitID(splitID)
|
||||||
|
@ -42,8 +42,8 @@ func TestHeadRaw(t *testing.T) {
|
||||||
e := testNewEngineWithShards(s1, s2)
|
e := testNewEngineWithShards(s1, s2)
|
||||||
defer e.Close()
|
defer e.Close()
|
||||||
|
|
||||||
putPrmLeft := new(shard.PutPrm).WithObject(child.Object())
|
putPrmLeft := new(shard.PutPrm).WithObject(child)
|
||||||
putPrmLink := new(shard.PutPrm).WithObject(link.Object())
|
putPrmLink := new(shard.PutPrm).WithObject(link)
|
||||||
|
|
||||||
// put most left object in one shard
|
// put most left object in one shard
|
||||||
_, err := s1.Put(putPrmLeft)
|
_, err := s1.Put(putPrmLeft)
|
||||||
|
@ -58,7 +58,7 @@ func TestHeadRaw(t *testing.T) {
|
||||||
_, err = e.Head(headPrm)
|
_, err = e.Head(headPrm)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
si, ok := err.(*objectSDK.SplitInfoError)
|
si, ok := err.(*object.SplitInfoError)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
|
|
||||||
// SplitInfoError should contain info from both shards
|
// SplitInfoError should contain info from both shards
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
||||||
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
|
@ -19,16 +20,16 @@ func TestStorageEngine_Inhume(t *testing.T) {
|
||||||
fs := objectSDK.SearchFilters{}
|
fs := objectSDK.SearchFilters{}
|
||||||
fs.AddRootFilter()
|
fs.AddRootFilter()
|
||||||
|
|
||||||
tombstoneID := generateRawObjectWithCID(t, cid).Object().Address()
|
tombstoneID := object.AddressOf(generateObjectWithCID(t, cid))
|
||||||
parent := generateRawObjectWithCID(t, cid)
|
parent := generateObjectWithCID(t, cid)
|
||||||
|
|
||||||
child := generateRawObjectWithCID(t, cid)
|
child := generateObjectWithCID(t, cid)
|
||||||
child.SetParent(parent.Object().SDK())
|
child.SetParent(parent)
|
||||||
child.SetParentID(parent.ID())
|
child.SetParentID(parent.ID())
|
||||||
child.SetSplitID(splitID)
|
child.SetSplitID(splitID)
|
||||||
|
|
||||||
link := generateRawObjectWithCID(t, cid)
|
link := generateObjectWithCID(t, cid)
|
||||||
link.SetParent(parent.Object().SDK())
|
link.SetParent(parent)
|
||||||
link.SetParentID(parent.ID())
|
link.SetParentID(parent.ID())
|
||||||
link.SetChildren(child.ID())
|
link.SetChildren(child.ID())
|
||||||
link.SetSplitID(splitID)
|
link.SetSplitID(splitID)
|
||||||
|
@ -37,10 +38,10 @@ func TestStorageEngine_Inhume(t *testing.T) {
|
||||||
e := testNewEngineWithShardNum(t, 1)
|
e := testNewEngineWithShardNum(t, 1)
|
||||||
defer e.Close()
|
defer e.Close()
|
||||||
|
|
||||||
err := Put(e, parent.Object())
|
err := Put(e, parent)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
inhumePrm := new(InhumePrm).WithTarget(tombstoneID, parent.Object().Address())
|
inhumePrm := new(InhumePrm).WithTarget(tombstoneID, object.AddressOf(parent))
|
||||||
_, err = e.Inhume(inhumePrm)
|
_, err = e.Inhume(inhumePrm)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -56,15 +57,15 @@ func TestStorageEngine_Inhume(t *testing.T) {
|
||||||
e := testNewEngineWithShards(s1, s2)
|
e := testNewEngineWithShards(s1, s2)
|
||||||
defer e.Close()
|
defer e.Close()
|
||||||
|
|
||||||
putChild := new(shard.PutPrm).WithObject(child.Object())
|
putChild := new(shard.PutPrm).WithObject(child)
|
||||||
_, err := s1.Put(putChild)
|
_, err := s1.Put(putChild)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
putLink := new(shard.PutPrm).WithObject(link.Object())
|
putLink := new(shard.PutPrm).WithObject(link)
|
||||||
_, err = s2.Put(putLink)
|
_, err = s2.Put(putLink)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
inhumePrm := new(InhumePrm).WithTarget(tombstoneID, parent.Object().Address())
|
inhumePrm := new(InhumePrm).WithTarget(tombstoneID, object.AddressOf(parent))
|
||||||
_, err = e.Inhume(inhumePrm)
|
_, err = e.Inhume(inhumePrm)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||||
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
||||||
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -28,11 +29,11 @@ func TestListWithCursor(t *testing.T) {
|
||||||
|
|
||||||
for i := 0; i < total; i++ {
|
for i := 0; i < total; i++ {
|
||||||
containerID := cidtest.ID()
|
containerID := cidtest.ID()
|
||||||
obj := generateRawObjectWithCID(t, containerID)
|
obj := generateObjectWithCID(t, containerID)
|
||||||
prm := new(PutPrm).WithObject(obj.Object())
|
prm := new(PutPrm).WithObject(obj)
|
||||||
_, err := e.Put(prm)
|
_, err := e.Put(prm)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
expected = append(expected, obj.Object().Address())
|
expected = append(expected, object.AddressOf(obj))
|
||||||
}
|
}
|
||||||
|
|
||||||
expected = sortAddresses(expected)
|
expected = sortAddresses(expected)
|
||||||
|
|
|
@ -5,12 +5,13 @@ import (
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
||||||
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
// PutPrm groups the parameters of Put operation.
|
// PutPrm groups the parameters of Put operation.
|
||||||
type PutPrm struct {
|
type PutPrm struct {
|
||||||
obj *object.Object
|
obj *objectSDK.Object
|
||||||
}
|
}
|
||||||
|
|
||||||
// PutRes groups resulting values of Put operation.
|
// PutRes groups resulting values of Put operation.
|
||||||
|
@ -21,7 +22,7 @@ var errPutShard = errors.New("could not put object to any shard")
|
||||||
// WithObject is a Put option to set object to save.
|
// WithObject is a Put option to set object to save.
|
||||||
//
|
//
|
||||||
// Option is required.
|
// Option is required.
|
||||||
func (p *PutPrm) WithObject(obj *object.Object) *PutPrm {
|
func (p *PutPrm) WithObject(obj *objectSDK.Object) *PutPrm {
|
||||||
if p != nil {
|
if p != nil {
|
||||||
p.obj = obj
|
p.obj = obj
|
||||||
}
|
}
|
||||||
|
@ -49,19 +50,21 @@ func (e *StorageEngine) put(prm *PutPrm) (*PutRes, error) {
|
||||||
defer elapsed(e.metrics.AddPutDuration)()
|
defer elapsed(e.metrics.AddPutDuration)()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addr := object.AddressOf(prm.obj)
|
||||||
|
|
||||||
// In #1146 this check was parallelized, however, it became
|
// In #1146 this check was parallelized, however, it became
|
||||||
// much slower on fast machines for 4 shards.
|
// much slower on fast machines for 4 shards.
|
||||||
_, err := e.exists(prm.obj.Address())
|
_, err := e.exists(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
existPrm := new(shard.ExistsPrm)
|
existPrm := new(shard.ExistsPrm)
|
||||||
existPrm.WithAddress(prm.obj.Address())
|
existPrm.WithAddress(addr)
|
||||||
|
|
||||||
finished := false
|
finished := false
|
||||||
|
|
||||||
e.iterateOverSortedShards(prm.obj.Address(), func(ind int, sh hashedShard) (stop bool) {
|
e.iterateOverSortedShards(addr, func(ind int, sh hashedShard) (stop bool) {
|
||||||
e.mtx.RLock()
|
e.mtx.RLock()
|
||||||
pool := e.shardPools[sh.ID().String()]
|
pool := e.shardPools[sh.ID().String()]
|
||||||
e.mtx.RUnlock()
|
e.mtx.RUnlock()
|
||||||
|
@ -79,7 +82,7 @@ func (e *StorageEngine) put(prm *PutPrm) (*PutRes, error) {
|
||||||
if exists.Exists() {
|
if exists.Exists() {
|
||||||
if ind != 0 {
|
if ind != 0 {
|
||||||
toMoveItPrm := new(shard.ToMoveItPrm)
|
toMoveItPrm := new(shard.ToMoveItPrm)
|
||||||
toMoveItPrm.WithAddress(prm.obj.Address())
|
toMoveItPrm.WithAddress(addr)
|
||||||
|
|
||||||
_, err = sh.ToMoveIt(toMoveItPrm)
|
_, err = sh.ToMoveIt(toMoveItPrm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -126,7 +129,7 @@ func (e *StorageEngine) put(prm *PutPrm) (*PutRes, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Put writes provided object to local storage.
|
// Put writes provided object to local storage.
|
||||||
func Put(storage *StorageEngine, obj *object.Object) error {
|
func Put(storage *StorageEngine, obj *objectSDK.Object) error {
|
||||||
_, err := storage.Put(new(PutPrm).
|
_, err := storage.Put(new(PutPrm).
|
||||||
WithObject(obj),
|
WithObject(obj),
|
||||||
)
|
)
|
||||||
|
|
|
@ -20,7 +20,7 @@ type RngPrm struct {
|
||||||
|
|
||||||
// RngRes groups resulting values of GetRange operation.
|
// RngRes groups resulting values of GetRange operation.
|
||||||
type RngRes struct {
|
type RngRes struct {
|
||||||
obj *object.Object
|
obj *objectSDK.Object
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithAddress is a GetRng option to set the address of the requested object.
|
// WithAddress is a GetRng option to set the address of the requested object.
|
||||||
|
@ -49,7 +49,7 @@ func (p *RngPrm) WithPayloadRange(rng *objectSDK.Range) *RngPrm {
|
||||||
// Object returns the requested object part.
|
// Object returns the requested object part.
|
||||||
//
|
//
|
||||||
// Instance payload contains the requested range of the original object.
|
// Instance payload contains the requested range of the original object.
|
||||||
func (r *RngRes) Object() *object.Object {
|
func (r *RngRes) Object() *objectSDK.Object {
|
||||||
return r.obj
|
return r.obj
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ func (e *StorageEngine) getRange(prm *RngPrm) (*RngRes, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
obj *object.Object
|
obj *objectSDK.Object
|
||||||
siErr *objectSDK.SplitInfoError
|
siErr *objectSDK.SplitInfoError
|
||||||
|
|
||||||
outSI *objectSDK.SplitInfo
|
outSI *objectSDK.SplitInfo
|
||||||
|
|
|
@ -21,11 +21,11 @@ func TestDB_Containers(t *testing.T) {
|
||||||
cids := make(map[string]int, N)
|
cids := make(map[string]int, N)
|
||||||
|
|
||||||
for i := 0; i < N; i++ {
|
for i := 0; i < N; i++ {
|
||||||
obj := generateRawObject(t)
|
obj := generateObject(t)
|
||||||
|
|
||||||
cids[obj.ContainerID().String()] = 0
|
cids[obj.ContainerID().String()] = 0
|
||||||
|
|
||||||
err := putBig(db, obj.Object())
|
err := putBig(db, obj)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ func TestDB_Containers(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Run("Inhume", func(t *testing.T) {
|
t.Run("Inhume", func(t *testing.T) {
|
||||||
obj := generateRawObject(t).Object()
|
obj := generateObject(t)
|
||||||
|
|
||||||
require.NoError(t, putBig(db, obj))
|
require.NoError(t, putBig(db, obj))
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ func TestDB_Containers(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Contains(t, cnrs, obj.ContainerID())
|
require.Contains(t, cnrs, obj.ContainerID())
|
||||||
|
|
||||||
require.NoError(t, meta.Inhume(db, obj.Address(), generateAddress()))
|
require.NoError(t, meta.Inhume(db, object.AddressOf(obj), generateAddress()))
|
||||||
|
|
||||||
cnrs, err = db.Containers()
|
cnrs, err = db.Containers()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -57,7 +57,7 @@ func TestDB_Containers(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("ToMoveIt", func(t *testing.T) {
|
t.Run("ToMoveIt", func(t *testing.T) {
|
||||||
obj := generateRawObject(t).Object()
|
obj := generateObject(t)
|
||||||
|
|
||||||
require.NoError(t, putBig(db, obj))
|
require.NoError(t, putBig(db, obj))
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ func TestDB_Containers(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Contains(t, cnrs, obj.ContainerID())
|
require.Contains(t, cnrs, obj.ContainerID())
|
||||||
|
|
||||||
require.NoError(t, meta.ToMoveIt(db, obj.Address()))
|
require.NoError(t, meta.ToMoveIt(db, object.AddressOf(obj)))
|
||||||
|
|
||||||
cnrs, err = db.Containers()
|
cnrs, err = db.Containers()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -91,10 +91,10 @@ func TestDB_ContainersCount(t *testing.T) {
|
||||||
|
|
||||||
for _, upload := range uploadObjects {
|
for _, upload := range uploadObjects {
|
||||||
for i := 0; i < upload.amount; i++ {
|
for i := 0; i < upload.amount; i++ {
|
||||||
obj := generateRawObject(t)
|
obj := generateObject(t)
|
||||||
obj.SetType(upload.typ)
|
obj.SetType(upload.typ)
|
||||||
|
|
||||||
err := putBig(db, obj.Object())
|
err := putBig(db, obj)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected = append(expected, obj.ContainerID())
|
expected = append(expected, obj.ContainerID())
|
||||||
|
@ -124,7 +124,7 @@ func TestDB_ContainerSize(t *testing.T) {
|
||||||
)
|
)
|
||||||
|
|
||||||
cids := make(map[*cid.ID]int, C)
|
cids := make(map[*cid.ID]int, C)
|
||||||
objs := make(map[*cid.ID][]*object.RawObject, C*N)
|
objs := make(map[*cid.ID][]*objectSDK.Object, C*N)
|
||||||
|
|
||||||
for i := 0; i < C; i++ {
|
for i := 0; i < C; i++ {
|
||||||
cid := cidtest.ID()
|
cid := cidtest.ID()
|
||||||
|
@ -133,18 +133,18 @@ func TestDB_ContainerSize(t *testing.T) {
|
||||||
for j := 0; j < N; j++ {
|
for j := 0; j < N; j++ {
|
||||||
size := rand.Intn(1024)
|
size := rand.Intn(1024)
|
||||||
|
|
||||||
parent := generateRawObjectWithCID(t, cid)
|
parent := generateObjectWithCID(t, cid)
|
||||||
parent.SetPayloadSize(uint64(size / 2))
|
parent.SetPayloadSize(uint64(size / 2))
|
||||||
|
|
||||||
obj := generateRawObjectWithCID(t, cid)
|
obj := generateObjectWithCID(t, cid)
|
||||||
obj.SetPayloadSize(uint64(size))
|
obj.SetPayloadSize(uint64(size))
|
||||||
obj.SetParentID(parent.ID())
|
obj.SetParentID(parent.ID())
|
||||||
obj.SetParent(parent.Object().SDK())
|
obj.SetParent(parent)
|
||||||
|
|
||||||
cids[cid] += size
|
cids[cid] += size
|
||||||
objs[cid] = append(objs[cid], obj)
|
objs[cid] = append(objs[cid], obj)
|
||||||
|
|
||||||
err := putBig(db, obj.Object())
|
err := putBig(db, obj)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -162,7 +162,7 @@ func TestDB_ContainerSize(t *testing.T) {
|
||||||
for _, obj := range list {
|
for _, obj := range list {
|
||||||
require.NoError(t, meta.Inhume(
|
require.NoError(t, meta.Inhume(
|
||||||
db,
|
db,
|
||||||
obj.Object().Address(),
|
object.AddressOf(obj),
|
||||||
generateAddress(),
|
generateAddress(),
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,8 @@ func TestReset(t *testing.T) {
|
||||||
err := db.Reset()
|
err := db.Reset()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
obj := generateRawObject(t).Object()
|
obj := generateObject(t)
|
||||||
addr := obj.Address()
|
addr := object.AddressOf(obj)
|
||||||
|
|
||||||
addrToInhume := generateAddress()
|
addrToInhume := generateAddress()
|
||||||
|
|
||||||
|
|
|
@ -6,13 +6,12 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
||||||
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/util/test"
|
"github.com/nspcc-dev/neofs-node/pkg/util/test"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/checksum"
|
"github.com/nspcc-dev/neofs-sdk-go/checksum"
|
||||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||||
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||||
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
||||||
|
@ -27,7 +26,7 @@ func putBig(db *meta.DB, obj *object.Object) error {
|
||||||
return meta.Put(db, obj, nil)
|
return meta.Put(db, obj, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testSelect(t *testing.T, db *meta.DB, cid *cid.ID, fs objectSDK.SearchFilters, exp ...*addressSDK.Address) {
|
func testSelect(t *testing.T, db *meta.DB, cid *cid.ID, fs object.SearchFilters, exp ...*addressSDK.Address) {
|
||||||
res, err := meta.Select(db, cid, fs)
|
res, err := meta.Select(db, cid, fs)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Len(t, res, len(exp))
|
require.Len(t, res, len(exp))
|
||||||
|
@ -62,11 +61,11 @@ func newDB(t testing.TB) *meta.DB {
|
||||||
return bdb
|
return bdb
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateRawObject(t *testing.T) *object.RawObject {
|
func generateObject(t *testing.T) *object.Object {
|
||||||
return generateRawObjectWithCID(t, cidtest.ID())
|
return generateObjectWithCID(t, cidtest.ID())
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateRawObjectWithCID(t *testing.T, cid *cid.ID) *object.RawObject {
|
func generateObjectWithCID(t *testing.T, cid *cid.ID) *object.Object {
|
||||||
version := version.New()
|
version := version.New()
|
||||||
version.SetMajor(2)
|
version.SetMajor(2)
|
||||||
version.SetMinor(1)
|
version.SetMinor(1)
|
||||||
|
@ -77,7 +76,7 @@ func generateRawObjectWithCID(t *testing.T, cid *cid.ID) *object.RawObject {
|
||||||
csumTZ := new(checksum.Checksum)
|
csumTZ := new(checksum.Checksum)
|
||||||
csumTZ.SetTillichZemor(tz.Sum(csum.Sum()))
|
csumTZ.SetTillichZemor(tz.Sum(csum.Sum()))
|
||||||
|
|
||||||
obj := object.NewRaw()
|
obj := object.New()
|
||||||
obj.SetID(testOID())
|
obj.SetID(testOID())
|
||||||
obj.SetOwnerID(ownertest.ID())
|
obj.SetOwnerID(ownertest.ID())
|
||||||
obj.SetContainerID(cid)
|
obj.SetContainerID(cid)
|
||||||
|
@ -97,8 +96,8 @@ func generateAddress() *addressSDK.Address {
|
||||||
return addr
|
return addr
|
||||||
}
|
}
|
||||||
|
|
||||||
func addAttribute(obj *object.RawObject, key, val string) {
|
func addAttribute(obj *object.Object, key, val string) {
|
||||||
attr := objectSDK.NewAttribute()
|
attr := object.NewAttribute()
|
||||||
attr.SetKey(key)
|
attr.SetKey(key)
|
||||||
attr.SetValue(val)
|
attr.SetValue(val)
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ type referenceNumber struct {
|
||||||
|
|
||||||
addr *addressSDK.Address
|
addr *addressSDK.Address
|
||||||
|
|
||||||
obj *object.Object
|
obj *objectSDK.Object
|
||||||
}
|
}
|
||||||
|
|
||||||
type referenceCounter map[string]*referenceNumber
|
type referenceCounter map[string]*referenceNumber
|
||||||
|
@ -105,14 +105,14 @@ func (db *DB) delete(tx *bbolt.Tx, addr *addressSDK.Address, refCounter referenc
|
||||||
}
|
}
|
||||||
|
|
||||||
// if object is an only link to a parent, then remove parent
|
// if object is an only link to a parent, then remove parent
|
||||||
if parent := obj.GetParent(); parent != nil {
|
if parent := obj.Parent(); parent != nil {
|
||||||
parAddr := parent.Address()
|
parAddr := object.AddressOf(parent)
|
||||||
sParAddr := parAddr.String()
|
sParAddr := parAddr.String()
|
||||||
|
|
||||||
nRef, ok := refCounter[sParAddr]
|
nRef, ok := refCounter[sParAddr]
|
||||||
if !ok {
|
if !ok {
|
||||||
nRef = &referenceNumber{
|
nRef = &referenceNumber{
|
||||||
all: parentLength(tx, parent.Address()),
|
all: parentLength(tx, parAddr),
|
||||||
addr: parAddr,
|
addr: parAddr,
|
||||||
obj: parent,
|
obj: parent,
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,7 @@ func (db *DB) delete(tx *bbolt.Tx, addr *addressSDK.Address, refCounter referenc
|
||||||
|
|
||||||
func (db *DB) deleteObject(
|
func (db *DB) deleteObject(
|
||||||
tx *bbolt.Tx,
|
tx *bbolt.Tx,
|
||||||
obj *object.Object,
|
obj *objectSDK.Object,
|
||||||
isParent bool,
|
isParent bool,
|
||||||
) error {
|
) error {
|
||||||
uniqueIndexes, err := delUniqueIndexes(obj, isParent)
|
uniqueIndexes, err := delUniqueIndexes(obj, isParent)
|
||||||
|
@ -239,8 +239,8 @@ func delListIndexItem(tx *bbolt.Tx, item namedBucketItem) {
|
||||||
_ = bkt.Put(item.key, encodedLst) // ignore error, best effort there
|
_ = bkt.Put(item.key, encodedLst) // ignore error, best effort there
|
||||||
}
|
}
|
||||||
|
|
||||||
func delUniqueIndexes(obj *object.Object, isParent bool) ([]namedBucketItem, error) {
|
func delUniqueIndexes(obj *objectSDK.Object, isParent bool) ([]namedBucketItem, error) {
|
||||||
addr := obj.Address()
|
addr := object.AddressOf(obj)
|
||||||
objKey := objectKey(addr.ObjectID())
|
objKey := objectKey(addr.ObjectID())
|
||||||
addrKey := addressKey(addr)
|
addrKey := addressKey(addr)
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||||
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
||||||
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
|
@ -14,19 +15,19 @@ func TestDB_Delete(t *testing.T) {
|
||||||
db := newDB(t)
|
db := newDB(t)
|
||||||
|
|
||||||
cid := cidtest.ID()
|
cid := cidtest.ID()
|
||||||
parent := generateRawObjectWithCID(t, cid)
|
parent := generateObjectWithCID(t, cid)
|
||||||
addAttribute(parent, "foo", "bar")
|
addAttribute(parent, "foo", "bar")
|
||||||
|
|
||||||
child := generateRawObjectWithCID(t, cid)
|
child := generateObjectWithCID(t, cid)
|
||||||
child.SetParent(parent.Object().SDK())
|
child.SetParent(parent)
|
||||||
child.SetParentID(parent.ID())
|
child.SetParentID(parent.ID())
|
||||||
|
|
||||||
// put object with parent
|
// put object with parent
|
||||||
err := putBig(db, child.Object())
|
err := putBig(db, child)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// fill ToMoveIt index
|
// fill ToMoveIt index
|
||||||
err = meta.ToMoveIt(db, child.Object().Address())
|
err = meta.ToMoveIt(db, object.AddressOf(child))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// check if Movable list is not empty
|
// check if Movable list is not empty
|
||||||
|
@ -35,20 +36,20 @@ func TestDB_Delete(t *testing.T) {
|
||||||
require.Len(t, l, 1)
|
require.Len(t, l, 1)
|
||||||
|
|
||||||
// try to remove parent unsuccessfully
|
// try to remove parent unsuccessfully
|
||||||
err = meta.Delete(db, parent.Object().Address())
|
err = meta.Delete(db, object.AddressOf(parent))
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
// inhume parent and child so they will be on graveyard
|
// inhume parent and child so they will be on graveyard
|
||||||
ts := generateRawObjectWithCID(t, cid)
|
ts := generateObjectWithCID(t, cid)
|
||||||
|
|
||||||
err = meta.Inhume(db, child.Object().Address(), ts.Object().Address())
|
err = meta.Inhume(db, object.AddressOf(child), object.AddressOf(ts))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
err = meta.Inhume(db, child.Object().Address(), ts.Object().Address())
|
err = meta.Inhume(db, object.AddressOf(child), object.AddressOf(ts))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// delete object
|
// delete object
|
||||||
err = meta.Delete(db, child.Object().Address())
|
err = meta.Delete(db, object.AddressOf(child))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// check if there is no data in Movable index
|
// check if there is no data in Movable index
|
||||||
|
@ -57,11 +58,11 @@ func TestDB_Delete(t *testing.T) {
|
||||||
require.Len(t, l, 0)
|
require.Len(t, l, 0)
|
||||||
|
|
||||||
// check if they removed from graveyard
|
// check if they removed from graveyard
|
||||||
ok, err := meta.Exists(db, child.Object().Address())
|
ok, err := meta.Exists(db, object.AddressOf(child))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.False(t, ok)
|
require.False(t, ok)
|
||||||
|
|
||||||
ok, err = meta.Exists(db, parent.Object().Address())
|
ok, err = meta.Exists(db, object.AddressOf(parent))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.False(t, ok)
|
require.False(t, ok)
|
||||||
}
|
}
|
||||||
|
@ -72,32 +73,32 @@ func TestDeleteAllChildren(t *testing.T) {
|
||||||
cid := cidtest.ID()
|
cid := cidtest.ID()
|
||||||
|
|
||||||
// generate parent object
|
// generate parent object
|
||||||
parent := generateRawObjectWithCID(t, cid)
|
parent := generateObjectWithCID(t, cid)
|
||||||
|
|
||||||
// generate 2 children
|
// generate 2 children
|
||||||
child1 := generateRawObjectWithCID(t, cid)
|
child1 := generateObjectWithCID(t, cid)
|
||||||
child1.SetParent(parent.Object().SDK())
|
child1.SetParent(parent)
|
||||||
child1.SetParentID(parent.ID())
|
child1.SetParentID(parent.ID())
|
||||||
|
|
||||||
child2 := generateRawObjectWithCID(t, cid)
|
child2 := generateObjectWithCID(t, cid)
|
||||||
child2.SetParent(parent.Object().SDK())
|
child2.SetParent(parent)
|
||||||
child2.SetParentID(parent.ID())
|
child2.SetParentID(parent.ID())
|
||||||
|
|
||||||
// put children
|
// put children
|
||||||
require.NoError(t, putBig(db, child1.Object()))
|
require.NoError(t, putBig(db, child1))
|
||||||
require.NoError(t, putBig(db, child2.Object()))
|
require.NoError(t, putBig(db, child2))
|
||||||
|
|
||||||
// Exists should return split info for parent
|
// Exists should return split info for parent
|
||||||
_, err := meta.Exists(db, parent.Object().Address())
|
_, err := meta.Exists(db, object.AddressOf(parent))
|
||||||
siErr := objectSDK.NewSplitInfoError(nil)
|
siErr := objectSDK.NewSplitInfoError(nil)
|
||||||
require.True(t, errors.As(err, &siErr))
|
require.True(t, errors.As(err, &siErr))
|
||||||
|
|
||||||
// remove all children in single call
|
// remove all children in single call
|
||||||
err = meta.Delete(db, child1.Object().Address(), child2.Object().Address())
|
err = meta.Delete(db, object.AddressOf(child1), object.AddressOf(child2))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// parent should not be found now
|
// parent should not be found now
|
||||||
ex, err := meta.Exists(db, parent.Object().Address())
|
ex, err := meta.Exists(db, object.AddressOf(parent))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.False(t, ex)
|
require.False(t, ex)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||||
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
||||||
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
|
@ -14,58 +15,58 @@ func TestDB_Exists(t *testing.T) {
|
||||||
db := newDB(t)
|
db := newDB(t)
|
||||||
|
|
||||||
t.Run("no object", func(t *testing.T) {
|
t.Run("no object", func(t *testing.T) {
|
||||||
nonExist := generateRawObject(t)
|
nonExist := generateObject(t)
|
||||||
exists, err := meta.Exists(db, nonExist.Object().Address())
|
exists, err := meta.Exists(db, object.AddressOf(nonExist))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.False(t, exists)
|
require.False(t, exists)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("regular object", func(t *testing.T) {
|
t.Run("regular object", func(t *testing.T) {
|
||||||
regular := generateRawObject(t)
|
regular := generateObject(t)
|
||||||
err := putBig(db, regular.Object())
|
err := putBig(db, regular)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
exists, err := meta.Exists(db, regular.Object().Address())
|
exists, err := meta.Exists(db, object.AddressOf(regular))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.True(t, exists)
|
require.True(t, exists)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("tombstone object", func(t *testing.T) {
|
t.Run("tombstone object", func(t *testing.T) {
|
||||||
ts := generateRawObject(t)
|
ts := generateObject(t)
|
||||||
ts.SetType(objectSDK.TypeTombstone)
|
ts.SetType(objectSDK.TypeTombstone)
|
||||||
|
|
||||||
err := putBig(db, ts.Object())
|
err := putBig(db, ts)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
exists, err := meta.Exists(db, ts.Object().Address())
|
exists, err := meta.Exists(db, object.AddressOf(ts))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.True(t, exists)
|
require.True(t, exists)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("storage group object", func(t *testing.T) {
|
t.Run("storage group object", func(t *testing.T) {
|
||||||
sg := generateRawObject(t)
|
sg := generateObject(t)
|
||||||
sg.SetType(objectSDK.TypeStorageGroup)
|
sg.SetType(objectSDK.TypeStorageGroup)
|
||||||
|
|
||||||
err := putBig(db, sg.Object())
|
err := putBig(db, sg)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
exists, err := meta.Exists(db, sg.Object().Address())
|
exists, err := meta.Exists(db, object.AddressOf(sg))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.True(t, exists)
|
require.True(t, exists)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("virtual object", func(t *testing.T) {
|
t.Run("virtual object", func(t *testing.T) {
|
||||||
cid := cidtest.ID()
|
cid := cidtest.ID()
|
||||||
parent := generateRawObjectWithCID(t, cid)
|
parent := generateObjectWithCID(t, cid)
|
||||||
|
|
||||||
child := generateRawObjectWithCID(t, cid)
|
child := generateObjectWithCID(t, cid)
|
||||||
child.SetParent(parent.Object().SDK())
|
child.SetParent(parent)
|
||||||
child.SetParentID(parent.ID())
|
child.SetParentID(parent.ID())
|
||||||
|
|
||||||
err := putBig(db, child.Object())
|
err := putBig(db, child)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
_, err = meta.Exists(db, parent.Object().Address())
|
_, err = meta.Exists(db, object.AddressOf(parent))
|
||||||
|
|
||||||
var expectedErr *objectSDK.SplitInfoError
|
var expectedErr *objectSDK.SplitInfoError
|
||||||
require.True(t, errors.As(err, &expectedErr))
|
require.True(t, errors.As(err, &expectedErr))
|
||||||
|
@ -75,28 +76,28 @@ func TestDB_Exists(t *testing.T) {
|
||||||
cid := cidtest.ID()
|
cid := cidtest.ID()
|
||||||
splitID := objectSDK.NewSplitID()
|
splitID := objectSDK.NewSplitID()
|
||||||
|
|
||||||
parent := generateRawObjectWithCID(t, cid)
|
parent := generateObjectWithCID(t, cid)
|
||||||
addAttribute(parent, "foo", "bar")
|
addAttribute(parent, "foo", "bar")
|
||||||
|
|
||||||
child := generateRawObjectWithCID(t, cid)
|
child := generateObjectWithCID(t, cid)
|
||||||
child.SetParent(parent.Object().SDK())
|
child.SetParent(parent)
|
||||||
child.SetParentID(parent.ID())
|
child.SetParentID(parent.ID())
|
||||||
child.SetSplitID(splitID)
|
child.SetSplitID(splitID)
|
||||||
|
|
||||||
link := generateRawObjectWithCID(t, cid)
|
link := generateObjectWithCID(t, cid)
|
||||||
link.SetParent(parent.Object().SDK())
|
link.SetParent(parent)
|
||||||
link.SetParentID(parent.ID())
|
link.SetParentID(parent.ID())
|
||||||
link.SetChildren(child.ID())
|
link.SetChildren(child.ID())
|
||||||
link.SetSplitID(splitID)
|
link.SetSplitID(splitID)
|
||||||
|
|
||||||
t.Run("direct order", func(t *testing.T) {
|
t.Run("direct order", func(t *testing.T) {
|
||||||
err := putBig(db, child.Object())
|
err := putBig(db, child)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
err = putBig(db, link.Object())
|
err = putBig(db, link)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
_, err = meta.Exists(db, parent.Object().Address())
|
_, err = meta.Exists(db, object.AddressOf(parent))
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
si, ok := err.(*objectSDK.SplitInfoError)
|
si, ok := err.(*objectSDK.SplitInfoError)
|
||||||
|
@ -108,13 +109,13 @@ func TestDB_Exists(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("reverse order", func(t *testing.T) {
|
t.Run("reverse order", func(t *testing.T) {
|
||||||
err := meta.Put(db, link.Object(), nil)
|
err := meta.Put(db, link, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
err = putBig(db, child.Object())
|
err = putBig(db, child)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
_, err = meta.Exists(db, parent.Object().Address())
|
_, err = meta.Exists(db, object.AddressOf(parent))
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
si, ok := err.(*objectSDK.SplitInfoError)
|
si, ok := err.(*objectSDK.SplitInfoError)
|
||||||
|
|
|
@ -18,7 +18,7 @@ type GetPrm struct {
|
||||||
|
|
||||||
// GetRes groups resulting values of Get operation.
|
// GetRes groups resulting values of Get operation.
|
||||||
type GetRes struct {
|
type GetRes struct {
|
||||||
hdr *object.Object
|
hdr *objectSDK.Object
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithAddress is a Get option to set the address of the requested object.
|
// WithAddress is a Get option to set the address of the requested object.
|
||||||
|
@ -44,12 +44,12 @@ func (p *GetPrm) WithRaw(raw bool) *GetPrm {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Header returns the requested object header.
|
// Header returns the requested object header.
|
||||||
func (r *GetRes) Header() *object.Object {
|
func (r *GetRes) Header() *objectSDK.Object {
|
||||||
return r.hdr
|
return r.hdr
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get reads the object from DB.
|
// Get reads the object from DB.
|
||||||
func Get(db *DB, addr *addressSDK.Address) (*object.Object, error) {
|
func Get(db *DB, addr *addressSDK.Address) (*objectSDK.Object, error) {
|
||||||
r, err := db.Get(new(GetPrm).WithAddress(addr))
|
r, err := db.Get(new(GetPrm).WithAddress(addr))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -59,7 +59,7 @@ func Get(db *DB, addr *addressSDK.Address) (*object.Object, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRaw reads physically stored object from DB.
|
// GetRaw reads physically stored object from DB.
|
||||||
func GetRaw(db *DB, addr *addressSDK.Address, raw bool) (*object.Object, error) {
|
func GetRaw(db *DB, addr *addressSDK.Address, raw bool) (*objectSDK.Object, error) {
|
||||||
r, err := db.Get(new(GetPrm).WithAddress(addr).WithRaw(raw))
|
r, err := db.Get(new(GetPrm).WithAddress(addr).WithRaw(raw))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -81,8 +81,8 @@ func (db *DB) Get(prm *GetPrm) (res *GetRes, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) get(tx *bbolt.Tx, addr *addressSDK.Address, checkGraveyard, raw bool) (*object.Object, error) {
|
func (db *DB) get(tx *bbolt.Tx, addr *addressSDK.Address, checkGraveyard, raw bool) (*objectSDK.Object, error) {
|
||||||
obj := object.New()
|
obj := objectSDK.New()
|
||||||
key := objectKey(addr.ObjectID())
|
key := objectKey(addr.ObjectID())
|
||||||
cid := addr.ContainerID()
|
cid := addr.ContainerID()
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ func getFromBucket(tx *bbolt.Tx, name, key []byte) []byte {
|
||||||
return bkt.Get(key)
|
return bkt.Get(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getVirtualObject(tx *bbolt.Tx, cid *cid.ID, key []byte, raw bool) (*object.Object, error) {
|
func getVirtualObject(tx *bbolt.Tx, cid *cid.ID, key []byte, raw bool) (*objectSDK.Object, error) {
|
||||||
if raw {
|
if raw {
|
||||||
return nil, getSplitInfoError(tx, cid, key)
|
return nil, getSplitInfoError(tx, cid, key)
|
||||||
}
|
}
|
||||||
|
@ -151,18 +151,20 @@ func getVirtualObject(tx *bbolt.Tx, cid *cid.ID, key []byte, raw bool) (*object.
|
||||||
virtualOID := relativeLst[len(relativeLst)-1]
|
virtualOID := relativeLst[len(relativeLst)-1]
|
||||||
data := getFromBucket(tx, primaryBucketName(cid), virtualOID)
|
data := getFromBucket(tx, primaryBucketName(cid), virtualOID)
|
||||||
|
|
||||||
child := object.New()
|
child := objectSDK.New()
|
||||||
|
|
||||||
err = child.Unmarshal(data)
|
err = child.Unmarshal(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("can't unmarshal child with parent: %w", err)
|
return nil, fmt.Errorf("can't unmarshal child with parent: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if child.GetParent() == nil { // this should never happen though
|
par := child.Parent()
|
||||||
|
|
||||||
|
if par == nil { // this should never happen though
|
||||||
return nil, object.ErrNotFound
|
return nil, object.ErrNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
return child.GetParent(), nil
|
return par, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSplitInfoError(tx *bbolt.Tx, cid *cid.ID, key []byte) error {
|
func getSplitInfoError(tx *bbolt.Tx, cid *cid.ID, key []byte) error {
|
||||||
|
|
|
@ -14,67 +14,67 @@ import (
|
||||||
func TestDB_Get(t *testing.T) {
|
func TestDB_Get(t *testing.T) {
|
||||||
db := newDB(t)
|
db := newDB(t)
|
||||||
|
|
||||||
raw := generateRawObject(t)
|
raw := generateObject(t)
|
||||||
|
|
||||||
// equal fails on diff of <nil> attributes and <{}> attributes,
|
// equal fails on diff of <nil> attributes and <{}> attributes,
|
||||||
/* so we make non empty attribute slice in parent*/
|
/* so we make non empty attribute slice in parent*/
|
||||||
addAttribute(raw, "foo", "bar")
|
addAttribute(raw, "foo", "bar")
|
||||||
|
|
||||||
t.Run("object not found", func(t *testing.T) {
|
t.Run("object not found", func(t *testing.T) {
|
||||||
_, err := meta.Get(db, raw.Object().Address())
|
_, err := meta.Get(db, object.AddressOf(raw))
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("put regular object", func(t *testing.T) {
|
t.Run("put regular object", func(t *testing.T) {
|
||||||
err := putBig(db, raw.Object())
|
err := putBig(db, raw)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
newObj, err := meta.Get(db, raw.Object().Address())
|
newObj, err := meta.Get(db, object.AddressOf(raw))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, raw.CutPayload().Object(), newObj)
|
require.Equal(t, raw.CutPayload(), newObj)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("put tombstone object", func(t *testing.T) {
|
t.Run("put tombstone object", func(t *testing.T) {
|
||||||
raw.SetType(objectSDK.TypeTombstone)
|
raw.SetType(objectSDK.TypeTombstone)
|
||||||
raw.SetID(testOID())
|
raw.SetID(testOID())
|
||||||
|
|
||||||
err := putBig(db, raw.Object())
|
err := putBig(db, raw)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
newObj, err := meta.Get(db, raw.Object().Address())
|
newObj, err := meta.Get(db, object.AddressOf(raw))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, raw.CutPayload().Object(), newObj)
|
require.Equal(t, raw.CutPayload(), newObj)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("put storage group object", func(t *testing.T) {
|
t.Run("put storage group object", func(t *testing.T) {
|
||||||
raw.SetType(objectSDK.TypeStorageGroup)
|
raw.SetType(objectSDK.TypeStorageGroup)
|
||||||
raw.SetID(testOID())
|
raw.SetID(testOID())
|
||||||
|
|
||||||
err := putBig(db, raw.Object())
|
err := putBig(db, raw)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
newObj, err := meta.Get(db, raw.Object().Address())
|
newObj, err := meta.Get(db, object.AddressOf(raw))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, raw.CutPayload().Object(), newObj)
|
require.Equal(t, raw.CutPayload(), newObj)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("put virtual object", func(t *testing.T) {
|
t.Run("put virtual object", func(t *testing.T) {
|
||||||
cid := cidtest.ID()
|
cid := cidtest.ID()
|
||||||
splitID := objectSDK.NewSplitID()
|
splitID := objectSDK.NewSplitID()
|
||||||
|
|
||||||
parent := generateRawObjectWithCID(t, cid)
|
parent := generateObjectWithCID(t, cid)
|
||||||
addAttribute(parent, "foo", "bar")
|
addAttribute(parent, "foo", "bar")
|
||||||
|
|
||||||
child := generateRawObjectWithCID(t, cid)
|
child := generateObjectWithCID(t, cid)
|
||||||
child.SetParent(parent.Object().SDK())
|
child.SetParent(parent)
|
||||||
child.SetParentID(parent.ID())
|
child.SetParentID(parent.ID())
|
||||||
child.SetSplitID(splitID)
|
child.SetSplitID(splitID)
|
||||||
|
|
||||||
err := putBig(db, child.Object())
|
err := putBig(db, child)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
t.Run("raw is true", func(t *testing.T) {
|
t.Run("raw is true", func(t *testing.T) {
|
||||||
_, err = meta.GetRaw(db, parent.Object().Address(), true)
|
_, err = meta.GetRaw(db, object.AddressOf(parent), true)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
siErr, ok := err.(*objectSDK.SplitInfoError)
|
siErr, ok := err.(*objectSDK.SplitInfoError)
|
||||||
|
@ -85,13 +85,13 @@ func TestDB_Get(t *testing.T) {
|
||||||
require.Nil(t, siErr.SplitInfo().Link())
|
require.Nil(t, siErr.SplitInfo().Link())
|
||||||
})
|
})
|
||||||
|
|
||||||
newParent, err := meta.GetRaw(db, parent.Object().Address(), false)
|
newParent, err := meta.GetRaw(db, object.AddressOf(parent), false)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.True(t, binaryEqual(parent.CutPayload().Object(), newParent))
|
require.True(t, binaryEqual(parent.CutPayload(), newParent))
|
||||||
|
|
||||||
newChild, err := meta.GetRaw(db, child.Object().Address(), true)
|
newChild, err := meta.GetRaw(db, object.AddressOf(child), true)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.True(t, binaryEqual(child.CutPayload().Object(), newChild))
|
require.True(t, binaryEqual(child.CutPayload(), newChild))
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("get removed object", func(t *testing.T) {
|
t.Run("get removed object", func(t *testing.T) {
|
||||||
|
@ -111,7 +111,7 @@ func TestDB_Get(t *testing.T) {
|
||||||
|
|
||||||
// binary equal is used when object contains empty lists in the structure and
|
// binary equal is used when object contains empty lists in the structure and
|
||||||
// requre.Equal fails on comparing <nil> and []{} lists.
|
// requre.Equal fails on comparing <nil> and []{} lists.
|
||||||
func binaryEqual(a, b *object.Object) bool {
|
func binaryEqual(a, b *objectSDK.Object) bool {
|
||||||
binaryA, err := a.Marshal()
|
binaryA, err := a.Marshal()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -3,6 +3,7 @@ package meta_test
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||||
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
||||||
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -12,15 +13,15 @@ func TestDB_IterateOverGraveyard(t *testing.T) {
|
||||||
db := newDB(t)
|
db := newDB(t)
|
||||||
|
|
||||||
// generate and put 2 objects
|
// generate and put 2 objects
|
||||||
obj1 := generateRawObject(t)
|
obj1 := generateObject(t)
|
||||||
obj2 := generateRawObject(t)
|
obj2 := generateObject(t)
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
err = putBig(db, obj1.Object())
|
err = putBig(db, obj1)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
err = putBig(db, obj2.Object())
|
err = putBig(db, obj2)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
inhumePrm := new(meta.InhumePrm)
|
inhumePrm := new(meta.InhumePrm)
|
||||||
|
@ -29,14 +30,14 @@ func TestDB_IterateOverGraveyard(t *testing.T) {
|
||||||
addrTombstone := generateAddress()
|
addrTombstone := generateAddress()
|
||||||
|
|
||||||
_, err = db.Inhume(inhumePrm.
|
_, err = db.Inhume(inhumePrm.
|
||||||
WithAddresses(obj1.Object().Address()).
|
WithAddresses(object.AddressOf(obj1)).
|
||||||
WithTombstoneAddress(addrTombstone),
|
WithTombstoneAddress(addrTombstone),
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// inhume with GC mark
|
// inhume with GC mark
|
||||||
_, err = db.Inhume(inhumePrm.
|
_, err = db.Inhume(inhumePrm.
|
||||||
WithAddresses(obj2.Object().Address()).
|
WithAddresses(object.AddressOf(obj2)).
|
||||||
WithGCMark(),
|
WithGCMark(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -60,6 +61,6 @@ func TestDB_IterateOverGraveyard(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
require.Equal(t, 2, counterAll)
|
require.Equal(t, 2, counterAll)
|
||||||
require.Equal(t, []*addressSDK.Address{obj1.Object().Address()}, buriedTS)
|
require.Equal(t, []*addressSDK.Address{object.AddressOf(obj1)}, buriedTS)
|
||||||
require.Equal(t, []*addressSDK.Address{obj2.Object().Address()}, buriedGC)
|
require.Equal(t, []*addressSDK.Address{object.AddressOf(obj2)}, buriedGC)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||||
"go.etcd.io/bbolt"
|
"go.etcd.io/bbolt"
|
||||||
)
|
)
|
||||||
|
@ -100,7 +100,7 @@ func (db *DB) Inhume(prm *InhumePrm) (res *InhumeRes, err error) {
|
||||||
|
|
||||||
// if object is stored and it is regular object then update bucket
|
// if object is stored and it is regular object then update bucket
|
||||||
// with container size estimations
|
// with container size estimations
|
||||||
if err == nil && obj.Type() == objectSDK.TypeRegular {
|
if err == nil && obj.Type() == object.TypeRegular {
|
||||||
err := changeContainerSize(
|
err := changeContainerSize(
|
||||||
tx,
|
tx,
|
||||||
obj.ContainerID(),
|
obj.ContainerID(),
|
||||||
|
|
|
@ -12,21 +12,21 @@ import (
|
||||||
func TestDB_Inhume(t *testing.T) {
|
func TestDB_Inhume(t *testing.T) {
|
||||||
db := newDB(t)
|
db := newDB(t)
|
||||||
|
|
||||||
raw := generateRawObject(t)
|
raw := generateObject(t)
|
||||||
addAttribute(raw, "foo", "bar")
|
addAttribute(raw, "foo", "bar")
|
||||||
|
|
||||||
tombstoneID := generateAddress()
|
tombstoneID := generateAddress()
|
||||||
|
|
||||||
err := putBig(db, raw.Object())
|
err := putBig(db, raw)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
err = meta.Inhume(db, raw.Object().Address(), tombstoneID)
|
err = meta.Inhume(db, object.AddressOf(raw), tombstoneID)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
_, err = meta.Exists(db, raw.Object().Address())
|
_, err = meta.Exists(db, object.AddressOf(raw))
|
||||||
require.EqualError(t, err, object.ErrAlreadyRemoved.Error())
|
require.EqualError(t, err, object.ErrAlreadyRemoved.Error())
|
||||||
|
|
||||||
_, err = meta.Get(db, raw.Object().Address())
|
_, err = meta.Get(db, object.AddressOf(raw))
|
||||||
require.EqualError(t, err, object.ErrAlreadyRemoved.Error())
|
require.EqualError(t, err, object.ErrAlreadyRemoved.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object"
|
objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object"
|
||||||
|
object2 "github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||||
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||||
|
@ -47,14 +48,13 @@ func TestDB_IterateExpired(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func putWithExpiration(t *testing.T, db *meta.DB, typ object.Type, expiresAt uint64) *addressSDK.Address {
|
func putWithExpiration(t *testing.T, db *meta.DB, typ object.Type, expiresAt uint64) *addressSDK.Address {
|
||||||
raw := generateRawObject(t)
|
obj := generateObject(t)
|
||||||
raw.SetType(typ)
|
obj.SetType(typ)
|
||||||
addAttribute(raw, objectV2.SysAttributeExpEpoch, strconv.FormatUint(expiresAt, 10))
|
addAttribute(obj, objectV2.SysAttributeExpEpoch, strconv.FormatUint(expiresAt, 10))
|
||||||
|
|
||||||
obj := raw.Object()
|
|
||||||
require.NoError(t, putBig(db, obj))
|
require.NoError(t, putBig(db, obj))
|
||||||
|
|
||||||
return obj.Address()
|
return object2.AddressOf(obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDB_IterateCoveredByTombstones(t *testing.T) {
|
func TestDB_IterateCoveredByTombstones(t *testing.T) {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||||
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
||||||
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
|
@ -27,46 +28,46 @@ func TestLisObjectsWithCursor(t *testing.T) {
|
||||||
containerID := cidtest.ID()
|
containerID := cidtest.ID()
|
||||||
|
|
||||||
// add one regular object
|
// add one regular object
|
||||||
obj := generateRawObjectWithCID(t, containerID)
|
obj := generateObjectWithCID(t, containerID)
|
||||||
obj.SetType(objectSDK.TypeRegular)
|
obj.SetType(objectSDK.TypeRegular)
|
||||||
err := putBig(db, obj.Object())
|
err := putBig(db, obj)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
expected = append(expected, obj.Object().Address())
|
expected = append(expected, object.AddressOf(obj))
|
||||||
|
|
||||||
// add one tombstone
|
// add one tombstone
|
||||||
obj = generateRawObjectWithCID(t, containerID)
|
obj = generateObjectWithCID(t, containerID)
|
||||||
obj.SetType(objectSDK.TypeTombstone)
|
obj.SetType(objectSDK.TypeTombstone)
|
||||||
err = putBig(db, obj.Object())
|
err = putBig(db, obj)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
expected = append(expected, obj.Object().Address())
|
expected = append(expected, object.AddressOf(obj))
|
||||||
|
|
||||||
// add one storage group
|
// add one storage group
|
||||||
obj = generateRawObjectWithCID(t, containerID)
|
obj = generateObjectWithCID(t, containerID)
|
||||||
obj.SetType(objectSDK.TypeStorageGroup)
|
obj.SetType(objectSDK.TypeStorageGroup)
|
||||||
err = putBig(db, obj.Object())
|
err = putBig(db, obj)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
expected = append(expected, obj.Object().Address())
|
expected = append(expected, object.AddressOf(obj))
|
||||||
|
|
||||||
// add one inhumed (do not include into expected)
|
// add one inhumed (do not include into expected)
|
||||||
obj = generateRawObjectWithCID(t, containerID)
|
obj = generateObjectWithCID(t, containerID)
|
||||||
obj.SetType(objectSDK.TypeRegular)
|
obj.SetType(objectSDK.TypeRegular)
|
||||||
err = putBig(db, obj.Object())
|
err = putBig(db, obj)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
ts := generateRawObjectWithCID(t, containerID)
|
ts := generateObjectWithCID(t, containerID)
|
||||||
err = meta.Inhume(db, obj.Object().Address(), ts.Object().Address())
|
err = meta.Inhume(db, object.AddressOf(obj), object.AddressOf(ts))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// add one child object (do not include parent into expected)
|
// add one child object (do not include parent into expected)
|
||||||
splitID := objectSDK.NewSplitID()
|
splitID := objectSDK.NewSplitID()
|
||||||
parent := generateRawObjectWithCID(t, containerID)
|
parent := generateObjectWithCID(t, containerID)
|
||||||
addAttribute(parent, "foo", "bar")
|
addAttribute(parent, "foo", "bar")
|
||||||
child := generateRawObjectWithCID(t, containerID)
|
child := generateObjectWithCID(t, containerID)
|
||||||
child.SetParent(parent.Object().SDK())
|
child.SetParent(parent)
|
||||||
child.SetParentID(parent.ID())
|
child.SetParentID(parent.ID())
|
||||||
child.SetSplitID(splitID)
|
child.SetSplitID(splitID)
|
||||||
err = putBig(db, child.Object())
|
err = putBig(db, child)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
expected = append(expected, child.Object().Address())
|
expected = append(expected, object.AddressOf(child))
|
||||||
}
|
}
|
||||||
|
|
||||||
expected = sortAddresses(expected)
|
expected = sortAddresses(expected)
|
||||||
|
@ -113,10 +114,10 @@ func TestAddObjectDuringListingWithCursor(t *testing.T) {
|
||||||
|
|
||||||
// fill metabase with objects
|
// fill metabase with objects
|
||||||
for i := 0; i < total; i++ {
|
for i := 0; i < total; i++ {
|
||||||
obj := generateRawObject(t)
|
obj := generateObject(t)
|
||||||
err := putBig(db, obj.Object())
|
err := putBig(db, obj)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
expected[obj.Object().Address().String()] = 0
|
expected[object.AddressOf(obj).String()] = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// get half of the objects
|
// get half of the objects
|
||||||
|
@ -130,8 +131,8 @@ func TestAddObjectDuringListingWithCursor(t *testing.T) {
|
||||||
|
|
||||||
// add new objects
|
// add new objects
|
||||||
for i := 0; i < total; i++ {
|
for i := 0; i < total; i++ {
|
||||||
obj := generateRawObject(t)
|
obj := generateObject(t)
|
||||||
err = putBig(db, obj.Object())
|
err = putBig(db, obj)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package meta_test
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||||
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
@ -10,14 +11,14 @@ import (
|
||||||
func TestDB_Movable(t *testing.T) {
|
func TestDB_Movable(t *testing.T) {
|
||||||
db := newDB(t)
|
db := newDB(t)
|
||||||
|
|
||||||
raw1 := generateRawObject(t)
|
raw1 := generateObject(t)
|
||||||
raw2 := generateRawObject(t)
|
raw2 := generateObject(t)
|
||||||
|
|
||||||
// put two objects in metabase
|
// put two objects in metabase
|
||||||
err := putBig(db, raw1.Object())
|
err := putBig(db, raw1)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
err = putBig(db, raw2.Object())
|
err = putBig(db, raw2)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// check if toMoveIt index empty
|
// check if toMoveIt index empty
|
||||||
|
@ -26,17 +27,17 @@ func TestDB_Movable(t *testing.T) {
|
||||||
require.Len(t, toMoveList, 0)
|
require.Len(t, toMoveList, 0)
|
||||||
|
|
||||||
// mark to move object2
|
// mark to move object2
|
||||||
err = meta.ToMoveIt(db, raw2.Object().Address())
|
err = meta.ToMoveIt(db, object.AddressOf(raw2))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// check if toMoveIt index contains address of object 2
|
// check if toMoveIt index contains address of object 2
|
||||||
toMoveList, err = meta.Movable(db)
|
toMoveList, err = meta.Movable(db)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Len(t, toMoveList, 1)
|
require.Len(t, toMoveList, 1)
|
||||||
require.Contains(t, toMoveList, raw2.Object().Address())
|
require.Contains(t, toMoveList, object.AddressOf(raw2))
|
||||||
|
|
||||||
// remove from toMoveIt index non existing address
|
// remove from toMoveIt index non existing address
|
||||||
err = meta.DoNotMove(db, raw1.Object().Address())
|
err = meta.DoNotMove(db, object.AddressOf(raw1))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// check if toMoveIt index hasn't changed
|
// check if toMoveIt index hasn't changed
|
||||||
|
@ -45,7 +46,7 @@ func TestDB_Movable(t *testing.T) {
|
||||||
require.Len(t, toMoveList, 1)
|
require.Len(t, toMoveList, 1)
|
||||||
|
|
||||||
// remove from toMoveIt index existing address
|
// remove from toMoveIt index existing address
|
||||||
err = meta.DoNotMove(db, raw2.Object().Address())
|
err = meta.DoNotMove(db, object.AddressOf(raw2))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// check if toMoveIt index is empty now
|
// check if toMoveIt index is empty now
|
||||||
|
|
|
@ -22,7 +22,7 @@ type (
|
||||||
|
|
||||||
// PutPrm groups the parameters of Put operation.
|
// PutPrm groups the parameters of Put operation.
|
||||||
type PutPrm struct {
|
type PutPrm struct {
|
||||||
obj *object.Object
|
obj *objectSDK.Object
|
||||||
|
|
||||||
id *blobovnicza.ID
|
id *blobovnicza.ID
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ type PutPrm struct {
|
||||||
type PutRes struct{}
|
type PutRes struct{}
|
||||||
|
|
||||||
// WithObject is a Put option to set object to save.
|
// WithObject is a Put option to set object to save.
|
||||||
func (p *PutPrm) WithObject(obj *object.Object) *PutPrm {
|
func (p *PutPrm) WithObject(obj *objectSDK.Object) *PutPrm {
|
||||||
if p != nil {
|
if p != nil {
|
||||||
p.obj = obj
|
p.obj = obj
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Put saves the object in DB.
|
// Put saves the object in DB.
|
||||||
func Put(db *DB, obj *object.Object, id *blobovnicza.ID) error {
|
func Put(db *DB, obj *objectSDK.Object, id *blobovnicza.ID) error {
|
||||||
_, err := db.Put(new(PutPrm).
|
_, err := db.Put(new(PutPrm).
|
||||||
WithObject(obj).
|
WithObject(obj).
|
||||||
WithBlobovniczaID(id),
|
WithBlobovniczaID(id),
|
||||||
|
@ -72,17 +72,17 @@ func (db *DB) Put(prm *PutPrm) (res *PutRes, err error) {
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
storagelog.Write(db.log,
|
storagelog.Write(db.log,
|
||||||
storagelog.AddressField(prm.obj.Address()),
|
storagelog.AddressField(prm.obj),
|
||||||
storagelog.OpField("metabase PUT"))
|
storagelog.OpField("metabase PUT"))
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) put(tx *bbolt.Tx, obj *object.Object, id *blobovnicza.ID, si *objectSDK.SplitInfo) error {
|
func (db *DB) put(tx *bbolt.Tx, obj *objectSDK.Object, id *blobovnicza.ID, si *objectSDK.SplitInfo) error {
|
||||||
isParent := si != nil
|
isParent := si != nil
|
||||||
|
|
||||||
exists, err := db.exists(tx, obj.Address())
|
exists, err := db.exists(tx, object.AddressOf(obj))
|
||||||
|
|
||||||
if errors.As(err, &splitInfoError) {
|
if errors.As(err, &splitInfoError) {
|
||||||
exists = true // object exists, however it is virtual
|
exists = true // object exists, however it is virtual
|
||||||
|
@ -97,26 +97,26 @@ func (db *DB) put(tx *bbolt.Tx, obj *object.Object, id *blobovnicza.ID, si *obje
|
||||||
// to another, then it calls metabase.Put method with new blobovniczaID
|
// to another, then it calls metabase.Put method with new blobovniczaID
|
||||||
// and this code should be triggered
|
// and this code should be triggered
|
||||||
if !isParent && id != nil {
|
if !isParent && id != nil {
|
||||||
return updateBlobovniczaID(tx, obj.Address(), id)
|
return updateBlobovniczaID(tx, object.AddressOf(obj), id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// when storage already has last object in split hierarchy and there is
|
// 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
|
// a linking object to put (or vice versa), we should update split info
|
||||||
// with object ids of these objects
|
// with object ids of these objects
|
||||||
if isParent {
|
if isParent {
|
||||||
return updateSplitInfo(tx, obj.Address(), si)
|
return updateSplitInfo(tx, object.AddressOf(obj), si)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if obj.GetParent() != nil && !isParent { // limit depth by two
|
if par := obj.Parent(); par != nil && !isParent { // limit depth by two
|
||||||
parentSI, err := splitInfoFromObject(obj)
|
parentSI, err := splitInfoFromObject(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = db.put(tx, obj.GetParent(), id, parentSI)
|
err = db.put(tx, par, id, parentSI)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -181,9 +181,9 @@ func (db *DB) put(tx *bbolt.Tx, obj *object.Object, id *blobovnicza.ID, si *obje
|
||||||
}
|
}
|
||||||
|
|
||||||
// builds list of <unique> indexes from the object.
|
// builds list of <unique> indexes from the object.
|
||||||
func uniqueIndexes(obj *object.Object, si *objectSDK.SplitInfo, id *blobovnicza.ID) ([]namedBucketItem, error) {
|
func uniqueIndexes(obj *objectSDK.Object, si *objectSDK.SplitInfo, id *blobovnicza.ID) ([]namedBucketItem, error) {
|
||||||
isParent := si != nil
|
isParent := si != nil
|
||||||
addr := obj.Address()
|
addr := object.AddressOf(obj)
|
||||||
objKey := objectKey(addr.ObjectID())
|
objKey := objectKey(addr.ObjectID())
|
||||||
result := make([]namedBucketItem, 0, 3)
|
result := make([]namedBucketItem, 0, 3)
|
||||||
|
|
||||||
|
@ -202,7 +202,7 @@ func uniqueIndexes(obj *object.Object, si *objectSDK.SplitInfo, id *blobovnicza.
|
||||||
return nil, ErrUnknownObjectType
|
return nil, ErrUnknownObjectType
|
||||||
}
|
}
|
||||||
|
|
||||||
rawObject, err := object.NewRawFromObject(obj).CutPayload().Marshal()
|
rawObject, err := obj.CutPayload().Marshal()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("can't marshal object header: %w", err)
|
return nil, fmt.Errorf("can't marshal object header: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -248,9 +248,9 @@ func uniqueIndexes(obj *object.Object, si *objectSDK.SplitInfo, id *blobovnicza.
|
||||||
}
|
}
|
||||||
|
|
||||||
// builds list of <list> indexes from the object.
|
// builds list of <list> indexes from the object.
|
||||||
func listIndexes(obj *object.Object) ([]namedBucketItem, error) {
|
func listIndexes(obj *objectSDK.Object) ([]namedBucketItem, error) {
|
||||||
result := make([]namedBucketItem, 0, 3)
|
result := make([]namedBucketItem, 0, 3)
|
||||||
addr := obj.Address()
|
addr := object.AddressOf(obj)
|
||||||
objKey := objectKey(addr.ObjectID())
|
objKey := objectKey(addr.ObjectID())
|
||||||
|
|
||||||
// index payload hashes
|
// index payload hashes
|
||||||
|
@ -282,8 +282,8 @@ func listIndexes(obj *object.Object) ([]namedBucketItem, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// builds list of <fake bucket tree> indexes from the object.
|
// builds list of <fake bucket tree> indexes from the object.
|
||||||
func fkbtIndexes(obj *object.Object) ([]namedBucketItem, error) {
|
func fkbtIndexes(obj *objectSDK.Object) ([]namedBucketItem, error) {
|
||||||
addr := obj.Address()
|
addr := object.AddressOf(obj)
|
||||||
objKey := []byte(addr.ObjectID().String())
|
objKey := []byte(addr.ObjectID().String())
|
||||||
|
|
||||||
attrs := obj.Attributes()
|
attrs := obj.Attributes()
|
||||||
|
@ -429,7 +429,7 @@ func updateSplitInfo(tx *bbolt.Tx, addr *addressSDK.Address, from *objectSDK.Spl
|
||||||
|
|
||||||
// splitInfoFromObject returns split info based on last or linkin object.
|
// splitInfoFromObject returns split info based on last or linkin object.
|
||||||
// Otherwise returns nil, nil.
|
// Otherwise returns nil, nil.
|
||||||
func splitInfoFromObject(obj *object.Object) (*objectSDK.SplitInfo, error) {
|
func splitInfoFromObject(obj *objectSDK.Object) (*objectSDK.SplitInfo, error) {
|
||||||
if obj.Parent() == nil {
|
if obj.Parent() == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
@ -451,12 +451,12 @@ func splitInfoFromObject(obj *object.Object) (*objectSDK.SplitInfo, error) {
|
||||||
|
|
||||||
// isLinkObject returns true if object contains parent header and list
|
// isLinkObject returns true if object contains parent header and list
|
||||||
// of children.
|
// of children.
|
||||||
func isLinkObject(obj *object.Object) bool {
|
func isLinkObject(obj *objectSDK.Object) bool {
|
||||||
return len(obj.Children()) > 0 && obj.Parent() != nil
|
return len(obj.Children()) > 0 && obj.Parent() != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// isLastObject returns true if object contains only parent header without list
|
// isLastObject returns true if object contains only parent header without list
|
||||||
// of children.
|
// of children.
|
||||||
func isLastObject(obj *object.Object) bool {
|
func isLastObject(obj *objectSDK.Object) bool {
|
||||||
return len(obj.Children()) == 0 && obj.Parent() != nil
|
return len(obj.Children()) == 0 && obj.Parent() != nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package meta_test
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
|
||||||
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -11,34 +12,34 @@ import (
|
||||||
func TestDB_PutBlobovnicaUpdate(t *testing.T) {
|
func TestDB_PutBlobovnicaUpdate(t *testing.T) {
|
||||||
db := newDB(t)
|
db := newDB(t)
|
||||||
|
|
||||||
raw1 := generateRawObject(t)
|
raw1 := generateObject(t)
|
||||||
blobovniczaID := blobovnicza.ID{1, 2, 3, 4}
|
blobovniczaID := blobovnicza.ID{1, 2, 3, 4}
|
||||||
|
|
||||||
// put one object with blobovniczaID
|
// put one object with blobovniczaID
|
||||||
err := meta.Put(db, raw1.Object(), &blobovniczaID)
|
err := meta.Put(db, raw1, &blobovniczaID)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
fetchedBlobovniczaID, err := meta.IsSmall(db, raw1.Object().Address())
|
fetchedBlobovniczaID, err := meta.IsSmall(db, object.AddressOf(raw1))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, &blobovniczaID, fetchedBlobovniczaID)
|
require.Equal(t, &blobovniczaID, fetchedBlobovniczaID)
|
||||||
|
|
||||||
t.Run("update blobovniczaID", func(t *testing.T) {
|
t.Run("update blobovniczaID", func(t *testing.T) {
|
||||||
newID := blobovnicza.ID{5, 6, 7, 8}
|
newID := blobovnicza.ID{5, 6, 7, 8}
|
||||||
|
|
||||||
err := meta.Put(db, raw1.Object(), &newID)
|
err := meta.Put(db, raw1, &newID)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
fetchedBlobovniczaID, err := meta.IsSmall(db, raw1.Object().Address())
|
fetchedBlobovniczaID, err := meta.IsSmall(db, object.AddressOf(raw1))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, &newID, fetchedBlobovniczaID)
|
require.Equal(t, &newID, fetchedBlobovniczaID)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("update blobovniczaID on bad object", func(t *testing.T) {
|
t.Run("update blobovniczaID on bad object", func(t *testing.T) {
|
||||||
raw2 := generateRawObject(t)
|
raw2 := generateObject(t)
|
||||||
err := putBig(db, raw2.Object())
|
err := putBig(db, raw2)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
fetchedBlobovniczaID, err := meta.IsSmall(db, raw2.Object().Address())
|
fetchedBlobovniczaID, err := meta.IsSmall(db, object.AddressOf(raw2))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Nil(t, fetchedBlobovniczaID)
|
require.Nil(t, fetchedBlobovniczaID)
|
||||||
})
|
})
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
v2object "github.com/nspcc-dev/neofs-api-go/v2/object"
|
v2object "github.com/nspcc-dev/neofs-api-go/v2/object"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||||
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
||||||
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
|
@ -18,62 +19,62 @@ func TestDB_SelectUserAttributes(t *testing.T) {
|
||||||
|
|
||||||
cid := cidtest.ID()
|
cid := cidtest.ID()
|
||||||
|
|
||||||
raw1 := generateRawObjectWithCID(t, cid)
|
raw1 := generateObjectWithCID(t, cid)
|
||||||
addAttribute(raw1, "foo", "bar")
|
addAttribute(raw1, "foo", "bar")
|
||||||
addAttribute(raw1, "x", "y")
|
addAttribute(raw1, "x", "y")
|
||||||
|
|
||||||
err := putBig(db, raw1.Object())
|
err := putBig(db, raw1)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
raw2 := generateRawObjectWithCID(t, cid)
|
raw2 := generateObjectWithCID(t, cid)
|
||||||
addAttribute(raw2, "foo", "bar")
|
addAttribute(raw2, "foo", "bar")
|
||||||
addAttribute(raw2, "x", "z")
|
addAttribute(raw2, "x", "z")
|
||||||
|
|
||||||
err = putBig(db, raw2.Object())
|
err = putBig(db, raw2)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
raw3 := generateRawObjectWithCID(t, cid)
|
raw3 := generateObjectWithCID(t, cid)
|
||||||
addAttribute(raw3, "a", "b")
|
addAttribute(raw3, "a", "b")
|
||||||
|
|
||||||
err = putBig(db, raw3.Object())
|
err = putBig(db, raw3)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
raw4 := generateRawObjectWithCID(t, cid)
|
raw4 := generateObjectWithCID(t, cid)
|
||||||
addAttribute(raw4, "path", "test/1/2")
|
addAttribute(raw4, "path", "test/1/2")
|
||||||
|
|
||||||
err = putBig(db, raw4.Object())
|
err = putBig(db, raw4)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
raw5 := generateRawObjectWithCID(t, cid)
|
raw5 := generateObjectWithCID(t, cid)
|
||||||
addAttribute(raw5, "path", "test/1/3")
|
addAttribute(raw5, "path", "test/1/3")
|
||||||
|
|
||||||
err = putBig(db, raw5.Object())
|
err = putBig(db, raw5)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
raw6 := generateRawObjectWithCID(t, cid)
|
raw6 := generateObjectWithCID(t, cid)
|
||||||
addAttribute(raw6, "path", "test/2/3")
|
addAttribute(raw6, "path", "test/2/3")
|
||||||
|
|
||||||
err = putBig(db, raw6.Object())
|
err = putBig(db, raw6)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
fs := objectSDK.SearchFilters{}
|
fs := objectSDK.SearchFilters{}
|
||||||
fs.AddFilter("foo", "bar", objectSDK.MatchStringEqual)
|
fs.AddFilter("foo", "bar", objectSDK.MatchStringEqual)
|
||||||
testSelect(t, db, cid, fs,
|
testSelect(t, db, cid, fs,
|
||||||
raw1.Object().Address(),
|
object.AddressOf(raw1),
|
||||||
raw2.Object().Address(),
|
object.AddressOf(raw2),
|
||||||
)
|
)
|
||||||
|
|
||||||
fs = objectSDK.SearchFilters{}
|
fs = objectSDK.SearchFilters{}
|
||||||
fs.AddFilter("x", "y", objectSDK.MatchStringEqual)
|
fs.AddFilter("x", "y", objectSDK.MatchStringEqual)
|
||||||
testSelect(t, db, cid, fs, raw1.Object().Address())
|
testSelect(t, db, cid, fs, object.AddressOf(raw1))
|
||||||
|
|
||||||
fs = objectSDK.SearchFilters{}
|
fs = objectSDK.SearchFilters{}
|
||||||
fs.AddFilter("x", "y", objectSDK.MatchStringNotEqual)
|
fs.AddFilter("x", "y", objectSDK.MatchStringNotEqual)
|
||||||
testSelect(t, db, cid, fs, raw2.Object().Address())
|
testSelect(t, db, cid, fs, object.AddressOf(raw2))
|
||||||
|
|
||||||
fs = objectSDK.SearchFilters{}
|
fs = objectSDK.SearchFilters{}
|
||||||
fs.AddFilter("a", "b", objectSDK.MatchStringEqual)
|
fs.AddFilter("a", "b", objectSDK.MatchStringEqual)
|
||||||
testSelect(t, db, cid, fs, raw3.Object().Address())
|
testSelect(t, db, cid, fs, object.AddressOf(raw3))
|
||||||
|
|
||||||
fs = objectSDK.SearchFilters{}
|
fs = objectSDK.SearchFilters{}
|
||||||
fs.AddFilter("c", "d", objectSDK.MatchStringEqual)
|
fs.AddFilter("c", "d", objectSDK.MatchStringEqual)
|
||||||
|
@ -82,56 +83,56 @@ func TestDB_SelectUserAttributes(t *testing.T) {
|
||||||
fs = objectSDK.SearchFilters{}
|
fs = objectSDK.SearchFilters{}
|
||||||
fs.AddFilter("foo", "", objectSDK.MatchNotPresent)
|
fs.AddFilter("foo", "", objectSDK.MatchNotPresent)
|
||||||
testSelect(t, db, cid, fs,
|
testSelect(t, db, cid, fs,
|
||||||
raw3.Object().Address(),
|
object.AddressOf(raw3),
|
||||||
raw4.Object().Address(),
|
object.AddressOf(raw4),
|
||||||
raw5.Object().Address(),
|
object.AddressOf(raw5),
|
||||||
raw6.Object().Address(),
|
object.AddressOf(raw6),
|
||||||
)
|
)
|
||||||
|
|
||||||
fs = objectSDK.SearchFilters{}
|
fs = objectSDK.SearchFilters{}
|
||||||
fs.AddFilter("a", "", objectSDK.MatchNotPresent)
|
fs.AddFilter("a", "", objectSDK.MatchNotPresent)
|
||||||
testSelect(t, db, cid, fs,
|
testSelect(t, db, cid, fs,
|
||||||
raw1.Object().Address(),
|
object.AddressOf(raw1),
|
||||||
raw2.Object().Address(),
|
object.AddressOf(raw2),
|
||||||
raw4.Object().Address(),
|
object.AddressOf(raw4),
|
||||||
raw5.Object().Address(),
|
object.AddressOf(raw5),
|
||||||
raw6.Object().Address(),
|
object.AddressOf(raw6),
|
||||||
)
|
)
|
||||||
|
|
||||||
fs = objectSDK.SearchFilters{}
|
fs = objectSDK.SearchFilters{}
|
||||||
testSelect(t, db, cid, fs,
|
testSelect(t, db, cid, fs,
|
||||||
raw1.Object().Address(),
|
object.AddressOf(raw1),
|
||||||
raw2.Object().Address(),
|
object.AddressOf(raw2),
|
||||||
raw3.Object().Address(),
|
object.AddressOf(raw3),
|
||||||
raw4.Object().Address(),
|
object.AddressOf(raw4),
|
||||||
raw5.Object().Address(),
|
object.AddressOf(raw5),
|
||||||
raw6.Object().Address(),
|
object.AddressOf(raw6),
|
||||||
)
|
)
|
||||||
|
|
||||||
fs = objectSDK.SearchFilters{}
|
fs = objectSDK.SearchFilters{}
|
||||||
fs.AddFilter("key", "", objectSDK.MatchNotPresent)
|
fs.AddFilter("key", "", objectSDK.MatchNotPresent)
|
||||||
testSelect(t, db, cid, fs,
|
testSelect(t, db, cid, fs,
|
||||||
raw1.Object().Address(),
|
object.AddressOf(raw1),
|
||||||
raw2.Object().Address(),
|
object.AddressOf(raw2),
|
||||||
raw3.Object().Address(),
|
object.AddressOf(raw3),
|
||||||
raw4.Object().Address(),
|
object.AddressOf(raw4),
|
||||||
raw5.Object().Address(),
|
object.AddressOf(raw5),
|
||||||
raw6.Object().Address(),
|
object.AddressOf(raw6),
|
||||||
)
|
)
|
||||||
|
|
||||||
fs = objectSDK.SearchFilters{}
|
fs = objectSDK.SearchFilters{}
|
||||||
fs.AddFilter("path", "test", objectSDK.MatchCommonPrefix)
|
fs.AddFilter("path", "test", objectSDK.MatchCommonPrefix)
|
||||||
testSelect(t, db, cid, fs,
|
testSelect(t, db, cid, fs,
|
||||||
raw4.Object().Address(),
|
object.AddressOf(raw4),
|
||||||
raw5.Object().Address(),
|
object.AddressOf(raw5),
|
||||||
raw6.Object().Address(),
|
object.AddressOf(raw6),
|
||||||
)
|
)
|
||||||
|
|
||||||
fs = objectSDK.SearchFilters{}
|
fs = objectSDK.SearchFilters{}
|
||||||
fs.AddFilter("path", "test/1", objectSDK.MatchCommonPrefix)
|
fs.AddFilter("path", "test/1", objectSDK.MatchCommonPrefix)
|
||||||
testSelect(t, db, cid, fs,
|
testSelect(t, db, cid, fs,
|
||||||
raw4.Object().Address(),
|
object.AddressOf(raw4),
|
||||||
raw5.Object().Address(),
|
object.AddressOf(raw5),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,47 +143,47 @@ func TestDB_SelectRootPhyParent(t *testing.T) {
|
||||||
|
|
||||||
// prepare
|
// prepare
|
||||||
|
|
||||||
small := generateRawObjectWithCID(t, cid)
|
small := generateObjectWithCID(t, cid)
|
||||||
err := putBig(db, small.Object())
|
err := putBig(db, small)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
ts := generateRawObjectWithCID(t, cid)
|
ts := generateObjectWithCID(t, cid)
|
||||||
ts.SetType(objectSDK.TypeTombstone)
|
ts.SetType(objectSDK.TypeTombstone)
|
||||||
err = putBig(db, ts.Object())
|
err = putBig(db, ts)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
sg := generateRawObjectWithCID(t, cid)
|
sg := generateObjectWithCID(t, cid)
|
||||||
sg.SetType(objectSDK.TypeStorageGroup)
|
sg.SetType(objectSDK.TypeStorageGroup)
|
||||||
err = putBig(db, sg.Object())
|
err = putBig(db, sg)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
leftChild := generateRawObjectWithCID(t, cid)
|
leftChild := generateObjectWithCID(t, cid)
|
||||||
leftChild.InitRelations()
|
leftChild.InitRelations()
|
||||||
err = putBig(db, leftChild.Object())
|
err = putBig(db, leftChild)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
parent := generateRawObjectWithCID(t, cid)
|
parent := generateObjectWithCID(t, cid)
|
||||||
|
|
||||||
rightChild := generateRawObjectWithCID(t, cid)
|
rightChild := generateObjectWithCID(t, cid)
|
||||||
rightChild.SetParent(parent.Object().SDK())
|
rightChild.SetParent(parent)
|
||||||
rightChild.SetParentID(parent.ID())
|
rightChild.SetParentID(parent.ID())
|
||||||
err = putBig(db, rightChild.Object())
|
err = putBig(db, rightChild)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
link := generateRawObjectWithCID(t, cid)
|
link := generateObjectWithCID(t, cid)
|
||||||
link.SetParent(parent.Object().SDK())
|
link.SetParent(parent)
|
||||||
link.SetParentID(parent.ID())
|
link.SetParentID(parent.ID())
|
||||||
link.SetChildren(leftChild.ID(), rightChild.ID())
|
link.SetChildren(leftChild.ID(), rightChild.ID())
|
||||||
|
|
||||||
err = putBig(db, link.Object())
|
err = putBig(db, link)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
t.Run("root objects", func(t *testing.T) {
|
t.Run("root objects", func(t *testing.T) {
|
||||||
fs := objectSDK.SearchFilters{}
|
fs := objectSDK.SearchFilters{}
|
||||||
fs.AddRootFilter()
|
fs.AddRootFilter()
|
||||||
testSelect(t, db, cid, fs,
|
testSelect(t, db, cid, fs,
|
||||||
small.Object().Address(),
|
object.AddressOf(small),
|
||||||
parent.Object().Address(),
|
object.AddressOf(parent),
|
||||||
)
|
)
|
||||||
|
|
||||||
fs = objectSDK.SearchFilters{}
|
fs = objectSDK.SearchFilters{}
|
||||||
|
@ -194,12 +195,12 @@ func TestDB_SelectRootPhyParent(t *testing.T) {
|
||||||
fs := objectSDK.SearchFilters{}
|
fs := objectSDK.SearchFilters{}
|
||||||
fs.AddPhyFilter()
|
fs.AddPhyFilter()
|
||||||
testSelect(t, db, cid, fs,
|
testSelect(t, db, cid, fs,
|
||||||
small.Object().Address(),
|
object.AddressOf(small),
|
||||||
ts.Object().Address(),
|
object.AddressOf(ts),
|
||||||
sg.Object().Address(),
|
object.AddressOf(sg),
|
||||||
leftChild.Object().Address(),
|
object.AddressOf(leftChild),
|
||||||
rightChild.Object().Address(),
|
object.AddressOf(rightChild),
|
||||||
link.Object().Address(),
|
object.AddressOf(link),
|
||||||
)
|
)
|
||||||
|
|
||||||
fs = objectSDK.SearchFilters{}
|
fs = objectSDK.SearchFilters{}
|
||||||
|
@ -211,18 +212,18 @@ func TestDB_SelectRootPhyParent(t *testing.T) {
|
||||||
fs := objectSDK.SearchFilters{}
|
fs := objectSDK.SearchFilters{}
|
||||||
fs.AddFilter(v2object.FilterHeaderObjectType, v2object.TypeRegular.String(), objectSDK.MatchStringEqual)
|
fs.AddFilter(v2object.FilterHeaderObjectType, v2object.TypeRegular.String(), objectSDK.MatchStringEqual)
|
||||||
testSelect(t, db, cid, fs,
|
testSelect(t, db, cid, fs,
|
||||||
small.Object().Address(),
|
object.AddressOf(small),
|
||||||
leftChild.Object().Address(),
|
object.AddressOf(leftChild),
|
||||||
rightChild.Object().Address(),
|
object.AddressOf(rightChild),
|
||||||
link.Object().Address(),
|
object.AddressOf(link),
|
||||||
parent.Object().Address(),
|
object.AddressOf(parent),
|
||||||
)
|
)
|
||||||
|
|
||||||
fs = objectSDK.SearchFilters{}
|
fs = objectSDK.SearchFilters{}
|
||||||
fs.AddFilter(v2object.FilterHeaderObjectType, v2object.TypeRegular.String(), objectSDK.MatchStringNotEqual)
|
fs.AddFilter(v2object.FilterHeaderObjectType, v2object.TypeRegular.String(), objectSDK.MatchStringNotEqual)
|
||||||
testSelect(t, db, cid, fs,
|
testSelect(t, db, cid, fs,
|
||||||
ts.Object().Address(),
|
object.AddressOf(ts),
|
||||||
sg.Object().Address(),
|
object.AddressOf(sg),
|
||||||
)
|
)
|
||||||
|
|
||||||
fs = objectSDK.SearchFilters{}
|
fs = objectSDK.SearchFilters{}
|
||||||
|
@ -233,17 +234,17 @@ func TestDB_SelectRootPhyParent(t *testing.T) {
|
||||||
t.Run("tombstone objects", func(t *testing.T) {
|
t.Run("tombstone objects", func(t *testing.T) {
|
||||||
fs := objectSDK.SearchFilters{}
|
fs := objectSDK.SearchFilters{}
|
||||||
fs.AddFilter(v2object.FilterHeaderObjectType, v2object.TypeTombstone.String(), objectSDK.MatchStringEqual)
|
fs.AddFilter(v2object.FilterHeaderObjectType, v2object.TypeTombstone.String(), objectSDK.MatchStringEqual)
|
||||||
testSelect(t, db, cid, fs, ts.Object().Address())
|
testSelect(t, db, cid, fs, object.AddressOf(ts))
|
||||||
|
|
||||||
fs = objectSDK.SearchFilters{}
|
fs = objectSDK.SearchFilters{}
|
||||||
fs.AddFilter(v2object.FilterHeaderObjectType, v2object.TypeTombstone.String(), objectSDK.MatchStringNotEqual)
|
fs.AddFilter(v2object.FilterHeaderObjectType, v2object.TypeTombstone.String(), objectSDK.MatchStringNotEqual)
|
||||||
testSelect(t, db, cid, fs,
|
testSelect(t, db, cid, fs,
|
||||||
small.Object().Address(),
|
object.AddressOf(small),
|
||||||
leftChild.Object().Address(),
|
object.AddressOf(leftChild),
|
||||||
rightChild.Object().Address(),
|
object.AddressOf(rightChild),
|
||||||
link.Object().Address(),
|
object.AddressOf(link),
|
||||||
parent.Object().Address(),
|
object.AddressOf(parent),
|
||||||
sg.Object().Address(),
|
object.AddressOf(sg),
|
||||||
)
|
)
|
||||||
|
|
||||||
fs = objectSDK.SearchFilters{}
|
fs = objectSDK.SearchFilters{}
|
||||||
|
@ -254,17 +255,17 @@ func TestDB_SelectRootPhyParent(t *testing.T) {
|
||||||
t.Run("storage group objects", func(t *testing.T) {
|
t.Run("storage group objects", func(t *testing.T) {
|
||||||
fs := objectSDK.SearchFilters{}
|
fs := objectSDK.SearchFilters{}
|
||||||
fs.AddFilter(v2object.FilterHeaderObjectType, v2object.TypeStorageGroup.String(), objectSDK.MatchStringEqual)
|
fs.AddFilter(v2object.FilterHeaderObjectType, v2object.TypeStorageGroup.String(), objectSDK.MatchStringEqual)
|
||||||
testSelect(t, db, cid, fs, sg.Object().Address())
|
testSelect(t, db, cid, fs, object.AddressOf(sg))
|
||||||
|
|
||||||
fs = objectSDK.SearchFilters{}
|
fs = objectSDK.SearchFilters{}
|
||||||
fs.AddFilter(v2object.FilterHeaderObjectType, v2object.TypeStorageGroup.String(), objectSDK.MatchStringNotEqual)
|
fs.AddFilter(v2object.FilterHeaderObjectType, v2object.TypeStorageGroup.String(), objectSDK.MatchStringNotEqual)
|
||||||
testSelect(t, db, cid, fs,
|
testSelect(t, db, cid, fs,
|
||||||
small.Object().Address(),
|
object.AddressOf(small),
|
||||||
leftChild.Object().Address(),
|
object.AddressOf(leftChild),
|
||||||
rightChild.Object().Address(),
|
object.AddressOf(rightChild),
|
||||||
link.Object().Address(),
|
object.AddressOf(link),
|
||||||
parent.Object().Address(),
|
object.AddressOf(parent),
|
||||||
ts.Object().Address(),
|
object.AddressOf(ts),
|
||||||
)
|
)
|
||||||
|
|
||||||
fs = objectSDK.SearchFilters{}
|
fs = objectSDK.SearchFilters{}
|
||||||
|
@ -279,8 +280,8 @@ func TestDB_SelectRootPhyParent(t *testing.T) {
|
||||||
objectSDK.MatchStringEqual)
|
objectSDK.MatchStringEqual)
|
||||||
|
|
||||||
testSelect(t, db, cid, fs,
|
testSelect(t, db, cid, fs,
|
||||||
rightChild.Object().Address(),
|
object.AddressOf(rightChild),
|
||||||
link.Object().Address(),
|
object.AddressOf(link),
|
||||||
)
|
)
|
||||||
|
|
||||||
fs = objectSDK.SearchFilters{}
|
fs = objectSDK.SearchFilters{}
|
||||||
|
@ -291,13 +292,13 @@ func TestDB_SelectRootPhyParent(t *testing.T) {
|
||||||
t.Run("all objects", func(t *testing.T) {
|
t.Run("all objects", func(t *testing.T) {
|
||||||
fs := objectSDK.SearchFilters{}
|
fs := objectSDK.SearchFilters{}
|
||||||
testSelect(t, db, cid, fs,
|
testSelect(t, db, cid, fs,
|
||||||
small.Object().Address(),
|
object.AddressOf(small),
|
||||||
ts.Object().Address(),
|
object.AddressOf(ts),
|
||||||
sg.Object().Address(),
|
object.AddressOf(sg),
|
||||||
leftChild.Object().Address(),
|
object.AddressOf(leftChild),
|
||||||
rightChild.Object().Address(),
|
object.AddressOf(rightChild),
|
||||||
link.Object().Address(),
|
object.AddressOf(link),
|
||||||
parent.Object().Address(),
|
object.AddressOf(parent),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -307,30 +308,30 @@ func TestDB_SelectInhume(t *testing.T) {
|
||||||
|
|
||||||
cid := cidtest.ID()
|
cid := cidtest.ID()
|
||||||
|
|
||||||
raw1 := generateRawObjectWithCID(t, cid)
|
raw1 := generateObjectWithCID(t, cid)
|
||||||
err := putBig(db, raw1.Object())
|
err := putBig(db, raw1)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
raw2 := generateRawObjectWithCID(t, cid)
|
raw2 := generateObjectWithCID(t, cid)
|
||||||
err = putBig(db, raw2.Object())
|
err = putBig(db, raw2)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
fs := objectSDK.SearchFilters{}
|
fs := objectSDK.SearchFilters{}
|
||||||
testSelect(t, db, cid, fs,
|
testSelect(t, db, cid, fs,
|
||||||
raw1.Object().Address(),
|
object.AddressOf(raw1),
|
||||||
raw2.Object().Address(),
|
object.AddressOf(raw2),
|
||||||
)
|
)
|
||||||
|
|
||||||
tombstone := addressSDK.NewAddress()
|
tombstone := addressSDK.NewAddress()
|
||||||
tombstone.SetContainerID(cid)
|
tombstone.SetContainerID(cid)
|
||||||
tombstone.SetObjectID(testOID())
|
tombstone.SetObjectID(testOID())
|
||||||
|
|
||||||
err = meta.Inhume(db, raw2.Object().Address(), tombstone)
|
err = meta.Inhume(db, object.AddressOf(raw2), tombstone)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
fs = objectSDK.SearchFilters{}
|
fs = objectSDK.SearchFilters{}
|
||||||
testSelect(t, db, cid, fs,
|
testSelect(t, db, cid, fs,
|
||||||
raw1.Object().Address(),
|
object.AddressOf(raw1),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,12 +340,12 @@ func TestDB_SelectPayloadHash(t *testing.T) {
|
||||||
|
|
||||||
cid := cidtest.ID()
|
cid := cidtest.ID()
|
||||||
|
|
||||||
raw1 := generateRawObjectWithCID(t, cid)
|
raw1 := generateObjectWithCID(t, cid)
|
||||||
err := putBig(db, raw1.Object())
|
err := putBig(db, raw1)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
raw2 := generateRawObjectWithCID(t, cid)
|
raw2 := generateObjectWithCID(t, cid)
|
||||||
err = putBig(db, raw2.Object())
|
err = putBig(db, raw2)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
fs := objectSDK.SearchFilters{}
|
fs := objectSDK.SearchFilters{}
|
||||||
|
@ -352,14 +353,14 @@ func TestDB_SelectPayloadHash(t *testing.T) {
|
||||||
hex.EncodeToString(raw1.PayloadChecksum().Sum()),
|
hex.EncodeToString(raw1.PayloadChecksum().Sum()),
|
||||||
objectSDK.MatchStringEqual)
|
objectSDK.MatchStringEqual)
|
||||||
|
|
||||||
testSelect(t, db, cid, fs, raw1.Object().Address())
|
testSelect(t, db, cid, fs, object.AddressOf(raw1))
|
||||||
|
|
||||||
fs = objectSDK.SearchFilters{}
|
fs = objectSDK.SearchFilters{}
|
||||||
fs.AddFilter(v2object.FilterHeaderPayloadHash,
|
fs.AddFilter(v2object.FilterHeaderPayloadHash,
|
||||||
hex.EncodeToString(raw1.PayloadChecksum().Sum()),
|
hex.EncodeToString(raw1.PayloadChecksum().Sum()),
|
||||||
objectSDK.MatchStringNotEqual)
|
objectSDK.MatchStringNotEqual)
|
||||||
|
|
||||||
testSelect(t, db, cid, fs, raw2.Object().Address())
|
testSelect(t, db, cid, fs, object.AddressOf(raw2))
|
||||||
|
|
||||||
fs = objectSDK.SearchFilters{}
|
fs = objectSDK.SearchFilters{}
|
||||||
fs.AddFilter(v2object.FilterHeaderPayloadHash,
|
fs.AddFilter(v2object.FilterHeaderPayloadHash,
|
||||||
|
@ -381,18 +382,18 @@ func TestDB_SelectWithSlowFilters(t *testing.T) {
|
||||||
v21.SetMajor(2)
|
v21.SetMajor(2)
|
||||||
v21.SetMinor(1)
|
v21.SetMinor(1)
|
||||||
|
|
||||||
raw1 := generateRawObjectWithCID(t, cid)
|
raw1 := generateObjectWithCID(t, cid)
|
||||||
raw1.SetPayloadSize(10)
|
raw1.SetPayloadSize(10)
|
||||||
raw1.SetCreationEpoch(11)
|
raw1.SetCreationEpoch(11)
|
||||||
raw1.SetVersion(v20)
|
raw1.SetVersion(v20)
|
||||||
err := putBig(db, raw1.Object())
|
err := putBig(db, raw1)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
raw2 := generateRawObjectWithCID(t, cid)
|
raw2 := generateObjectWithCID(t, cid)
|
||||||
raw2.SetPayloadSize(20)
|
raw2.SetPayloadSize(20)
|
||||||
raw2.SetCreationEpoch(21)
|
raw2.SetCreationEpoch(21)
|
||||||
raw2.SetVersion(v21)
|
raw2.SetVersion(v21)
|
||||||
err = putBig(db, raw2.Object())
|
err = putBig(db, raw2)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
t.Run("object with TZHash", func(t *testing.T) {
|
t.Run("object with TZHash", func(t *testing.T) {
|
||||||
|
@ -401,14 +402,14 @@ func TestDB_SelectWithSlowFilters(t *testing.T) {
|
||||||
hex.EncodeToString(raw1.PayloadHomomorphicHash().Sum()),
|
hex.EncodeToString(raw1.PayloadHomomorphicHash().Sum()),
|
||||||
objectSDK.MatchStringEqual)
|
objectSDK.MatchStringEqual)
|
||||||
|
|
||||||
testSelect(t, db, cid, fs, raw1.Object().Address())
|
testSelect(t, db, cid, fs, object.AddressOf(raw1))
|
||||||
|
|
||||||
fs = objectSDK.SearchFilters{}
|
fs = objectSDK.SearchFilters{}
|
||||||
fs.AddFilter(v2object.FilterHeaderHomomorphicHash,
|
fs.AddFilter(v2object.FilterHeaderHomomorphicHash,
|
||||||
hex.EncodeToString(raw1.PayloadHomomorphicHash().Sum()),
|
hex.EncodeToString(raw1.PayloadHomomorphicHash().Sum()),
|
||||||
objectSDK.MatchStringNotEqual)
|
objectSDK.MatchStringNotEqual)
|
||||||
|
|
||||||
testSelect(t, db, cid, fs, raw2.Object().Address())
|
testSelect(t, db, cid, fs, object.AddressOf(raw2))
|
||||||
|
|
||||||
fs = objectSDK.SearchFilters{}
|
fs = objectSDK.SearchFilters{}
|
||||||
fs.AddFilter(v2object.FilterHeaderHomomorphicHash,
|
fs.AddFilter(v2object.FilterHeaderHomomorphicHash,
|
||||||
|
@ -422,12 +423,12 @@ func TestDB_SelectWithSlowFilters(t *testing.T) {
|
||||||
fs := objectSDK.SearchFilters{}
|
fs := objectSDK.SearchFilters{}
|
||||||
fs.AddFilter(v2object.FilterHeaderPayloadLength, "20", objectSDK.MatchStringEqual)
|
fs.AddFilter(v2object.FilterHeaderPayloadLength, "20", objectSDK.MatchStringEqual)
|
||||||
|
|
||||||
testSelect(t, db, cid, fs, raw2.Object().Address())
|
testSelect(t, db, cid, fs, object.AddressOf(raw2))
|
||||||
|
|
||||||
fs = objectSDK.SearchFilters{}
|
fs = objectSDK.SearchFilters{}
|
||||||
fs.AddFilter(v2object.FilterHeaderPayloadLength, "20", objectSDK.MatchStringNotEqual)
|
fs.AddFilter(v2object.FilterHeaderPayloadLength, "20", objectSDK.MatchStringNotEqual)
|
||||||
|
|
||||||
testSelect(t, db, cid, fs, raw1.Object().Address())
|
testSelect(t, db, cid, fs, object.AddressOf(raw1))
|
||||||
|
|
||||||
fs = objectSDK.SearchFilters{}
|
fs = objectSDK.SearchFilters{}
|
||||||
fs.AddFilter(v2object.FilterHeaderPayloadLength, "", objectSDK.MatchNotPresent)
|
fs.AddFilter(v2object.FilterHeaderPayloadLength, "", objectSDK.MatchNotPresent)
|
||||||
|
@ -439,12 +440,12 @@ func TestDB_SelectWithSlowFilters(t *testing.T) {
|
||||||
fs := objectSDK.SearchFilters{}
|
fs := objectSDK.SearchFilters{}
|
||||||
fs.AddFilter(v2object.FilterHeaderCreationEpoch, "11", objectSDK.MatchStringEqual)
|
fs.AddFilter(v2object.FilterHeaderCreationEpoch, "11", objectSDK.MatchStringEqual)
|
||||||
|
|
||||||
testSelect(t, db, cid, fs, raw1.Object().Address())
|
testSelect(t, db, cid, fs, object.AddressOf(raw1))
|
||||||
|
|
||||||
fs = objectSDK.SearchFilters{}
|
fs = objectSDK.SearchFilters{}
|
||||||
fs.AddFilter(v2object.FilterHeaderCreationEpoch, "11", objectSDK.MatchStringNotEqual)
|
fs.AddFilter(v2object.FilterHeaderCreationEpoch, "11", objectSDK.MatchStringNotEqual)
|
||||||
|
|
||||||
testSelect(t, db, cid, fs, raw2.Object().Address())
|
testSelect(t, db, cid, fs, object.AddressOf(raw2))
|
||||||
|
|
||||||
fs = objectSDK.SearchFilters{}
|
fs = objectSDK.SearchFilters{}
|
||||||
fs.AddFilter(v2object.FilterHeaderCreationEpoch, "", objectSDK.MatchNotPresent)
|
fs.AddFilter(v2object.FilterHeaderCreationEpoch, "", objectSDK.MatchNotPresent)
|
||||||
|
@ -455,11 +456,11 @@ func TestDB_SelectWithSlowFilters(t *testing.T) {
|
||||||
t.Run("object with version", func(t *testing.T) {
|
t.Run("object with version", func(t *testing.T) {
|
||||||
fs := objectSDK.SearchFilters{}
|
fs := objectSDK.SearchFilters{}
|
||||||
fs.AddObjectVersionFilter(objectSDK.MatchStringEqual, v21)
|
fs.AddObjectVersionFilter(objectSDK.MatchStringEqual, v21)
|
||||||
testSelect(t, db, cid, fs, raw2.Object().Address())
|
testSelect(t, db, cid, fs, object.AddressOf(raw2))
|
||||||
|
|
||||||
fs = objectSDK.SearchFilters{}
|
fs = objectSDK.SearchFilters{}
|
||||||
fs.AddObjectVersionFilter(objectSDK.MatchStringNotEqual, v21)
|
fs.AddObjectVersionFilter(objectSDK.MatchStringNotEqual, v21)
|
||||||
testSelect(t, db, cid, fs, raw1.Object().Address())
|
testSelect(t, db, cid, fs, object.AddressOf(raw1))
|
||||||
|
|
||||||
fs = objectSDK.SearchFilters{}
|
fs = objectSDK.SearchFilters{}
|
||||||
fs.AddObjectVersionFilter(objectSDK.MatchNotPresent, nil)
|
fs.AddObjectVersionFilter(objectSDK.MatchNotPresent, nil)
|
||||||
|
@ -474,23 +475,23 @@ func TestDB_SelectObjectID(t *testing.T) {
|
||||||
|
|
||||||
// prepare
|
// prepare
|
||||||
|
|
||||||
parent := generateRawObjectWithCID(t, cid)
|
parent := generateObjectWithCID(t, cid)
|
||||||
|
|
||||||
regular := generateRawObjectWithCID(t, cid)
|
regular := generateObjectWithCID(t, cid)
|
||||||
regular.SetParentID(parent.ID())
|
regular.SetParentID(parent.ID())
|
||||||
regular.SetParent(parent.Object().SDK())
|
regular.SetParent(parent)
|
||||||
|
|
||||||
err := putBig(db, regular.Object())
|
err := putBig(db, regular)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
ts := generateRawObjectWithCID(t, cid)
|
ts := generateObjectWithCID(t, cid)
|
||||||
ts.SetType(objectSDK.TypeTombstone)
|
ts.SetType(objectSDK.TypeTombstone)
|
||||||
err = putBig(db, ts.Object())
|
err = putBig(db, ts)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
sg := generateRawObjectWithCID(t, cid)
|
sg := generateObjectWithCID(t, cid)
|
||||||
sg.SetType(objectSDK.TypeStorageGroup)
|
sg.SetType(objectSDK.TypeStorageGroup)
|
||||||
err = putBig(db, sg.Object())
|
err = putBig(db, sg)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
t.Run("not present", func(t *testing.T) {
|
t.Run("not present", func(t *testing.T) {
|
||||||
|
@ -500,7 +501,7 @@ func TestDB_SelectObjectID(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("not found objects", func(t *testing.T) {
|
t.Run("not found objects", func(t *testing.T) {
|
||||||
raw := generateRawObjectWithCID(t, cid)
|
raw := generateObjectWithCID(t, cid)
|
||||||
|
|
||||||
fs := objectSDK.SearchFilters{}
|
fs := objectSDK.SearchFilters{}
|
||||||
fs.AddObjectIDFilter(objectSDK.MatchStringEqual, raw.ID())
|
fs.AddObjectIDFilter(objectSDK.MatchStringEqual, raw.ID())
|
||||||
|
@ -511,66 +512,66 @@ func TestDB_SelectObjectID(t *testing.T) {
|
||||||
fs.AddObjectIDFilter(objectSDK.MatchStringNotEqual, raw.ID())
|
fs.AddObjectIDFilter(objectSDK.MatchStringNotEqual, raw.ID())
|
||||||
|
|
||||||
testSelect(t, db, cid, fs,
|
testSelect(t, db, cid, fs,
|
||||||
regular.Object().Address(),
|
object.AddressOf(regular),
|
||||||
parent.Object().Address(),
|
object.AddressOf(parent),
|
||||||
sg.Object().Address(),
|
object.AddressOf(sg),
|
||||||
ts.Object().Address(),
|
object.AddressOf(ts),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("regular objects", func(t *testing.T) {
|
t.Run("regular objects", func(t *testing.T) {
|
||||||
fs := objectSDK.SearchFilters{}
|
fs := objectSDK.SearchFilters{}
|
||||||
fs.AddObjectIDFilter(objectSDK.MatchStringEqual, regular.ID())
|
fs.AddObjectIDFilter(objectSDK.MatchStringEqual, regular.ID())
|
||||||
testSelect(t, db, cid, fs, regular.Object().Address())
|
testSelect(t, db, cid, fs, object.AddressOf(regular))
|
||||||
|
|
||||||
fs = objectSDK.SearchFilters{}
|
fs = objectSDK.SearchFilters{}
|
||||||
fs.AddObjectIDFilter(objectSDK.MatchStringNotEqual, regular.ID())
|
fs.AddObjectIDFilter(objectSDK.MatchStringNotEqual, regular.ID())
|
||||||
testSelect(t, db, cid, fs,
|
testSelect(t, db, cid, fs,
|
||||||
parent.Object().Address(),
|
object.AddressOf(parent),
|
||||||
sg.Object().Address(),
|
object.AddressOf(sg),
|
||||||
ts.Object().Address(),
|
object.AddressOf(ts),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("tombstone objects", func(t *testing.T) {
|
t.Run("tombstone objects", func(t *testing.T) {
|
||||||
fs := objectSDK.SearchFilters{}
|
fs := objectSDK.SearchFilters{}
|
||||||
fs.AddObjectIDFilter(objectSDK.MatchStringEqual, ts.ID())
|
fs.AddObjectIDFilter(objectSDK.MatchStringEqual, ts.ID())
|
||||||
testSelect(t, db, cid, fs, ts.Object().Address())
|
testSelect(t, db, cid, fs, object.AddressOf(ts))
|
||||||
|
|
||||||
fs = objectSDK.SearchFilters{}
|
fs = objectSDK.SearchFilters{}
|
||||||
fs.AddObjectIDFilter(objectSDK.MatchStringNotEqual, ts.ID())
|
fs.AddObjectIDFilter(objectSDK.MatchStringNotEqual, ts.ID())
|
||||||
testSelect(t, db, cid, fs,
|
testSelect(t, db, cid, fs,
|
||||||
regular.Object().Address(),
|
object.AddressOf(regular),
|
||||||
parent.Object().Address(),
|
object.AddressOf(parent),
|
||||||
sg.Object().Address(),
|
object.AddressOf(sg),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("storage group objects", func(t *testing.T) {
|
t.Run("storage group objects", func(t *testing.T) {
|
||||||
fs := objectSDK.SearchFilters{}
|
fs := objectSDK.SearchFilters{}
|
||||||
fs.AddObjectIDFilter(objectSDK.MatchStringEqual, sg.ID())
|
fs.AddObjectIDFilter(objectSDK.MatchStringEqual, sg.ID())
|
||||||
testSelect(t, db, cid, fs, sg.Object().Address())
|
testSelect(t, db, cid, fs, object.AddressOf(sg))
|
||||||
|
|
||||||
fs = objectSDK.SearchFilters{}
|
fs = objectSDK.SearchFilters{}
|
||||||
fs.AddObjectIDFilter(objectSDK.MatchStringNotEqual, sg.ID())
|
fs.AddObjectIDFilter(objectSDK.MatchStringNotEqual, sg.ID())
|
||||||
testSelect(t, db, cid, fs,
|
testSelect(t, db, cid, fs,
|
||||||
regular.Object().Address(),
|
object.AddressOf(regular),
|
||||||
parent.Object().Address(),
|
object.AddressOf(parent),
|
||||||
ts.Object().Address(),
|
object.AddressOf(ts),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("parent objects", func(t *testing.T) {
|
t.Run("parent objects", func(t *testing.T) {
|
||||||
fs := objectSDK.SearchFilters{}
|
fs := objectSDK.SearchFilters{}
|
||||||
fs.AddObjectIDFilter(objectSDK.MatchStringEqual, parent.ID())
|
fs.AddObjectIDFilter(objectSDK.MatchStringEqual, parent.ID())
|
||||||
testSelect(t, db, cid, fs, parent.Object().Address())
|
testSelect(t, db, cid, fs, object.AddressOf(parent))
|
||||||
|
|
||||||
fs = objectSDK.SearchFilters{}
|
fs = objectSDK.SearchFilters{}
|
||||||
fs.AddObjectIDFilter(objectSDK.MatchStringNotEqual, parent.ID())
|
fs.AddObjectIDFilter(objectSDK.MatchStringNotEqual, parent.ID())
|
||||||
testSelect(t, db, cid, fs,
|
testSelect(t, db, cid, fs,
|
||||||
regular.Object().Address(),
|
object.AddressOf(regular),
|
||||||
sg.Object().Address(),
|
object.AddressOf(sg),
|
||||||
ts.Object().Address(),
|
object.AddressOf(ts),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -580,9 +581,9 @@ func TestDB_SelectSplitID(t *testing.T) {
|
||||||
|
|
||||||
cid := cidtest.ID()
|
cid := cidtest.ID()
|
||||||
|
|
||||||
child1 := generateRawObjectWithCID(t, cid)
|
child1 := generateObjectWithCID(t, cid)
|
||||||
child2 := generateRawObjectWithCID(t, cid)
|
child2 := generateObjectWithCID(t, cid)
|
||||||
child3 := generateRawObjectWithCID(t, cid)
|
child3 := generateObjectWithCID(t, cid)
|
||||||
|
|
||||||
split1 := objectSDK.NewSplitID()
|
split1 := objectSDK.NewSplitID()
|
||||||
split2 := objectSDK.NewSplitID()
|
split2 := objectSDK.NewSplitID()
|
||||||
|
@ -591,9 +592,9 @@ func TestDB_SelectSplitID(t *testing.T) {
|
||||||
child2.SetSplitID(split1)
|
child2.SetSplitID(split1)
|
||||||
child3.SetSplitID(split2)
|
child3.SetSplitID(split2)
|
||||||
|
|
||||||
require.NoError(t, putBig(db, child1.Object()))
|
require.NoError(t, putBig(db, child1))
|
||||||
require.NoError(t, putBig(db, child2.Object()))
|
require.NoError(t, putBig(db, child2))
|
||||||
require.NoError(t, putBig(db, child3.Object()))
|
require.NoError(t, putBig(db, child3))
|
||||||
|
|
||||||
t.Run("not present", func(t *testing.T) {
|
t.Run("not present", func(t *testing.T) {
|
||||||
fs := objectSDK.SearchFilters{}
|
fs := objectSDK.SearchFilters{}
|
||||||
|
@ -605,13 +606,13 @@ func TestDB_SelectSplitID(t *testing.T) {
|
||||||
fs := objectSDK.SearchFilters{}
|
fs := objectSDK.SearchFilters{}
|
||||||
fs.AddFilter(v2object.FilterHeaderSplitID, split1.String(), objectSDK.MatchStringEqual)
|
fs.AddFilter(v2object.FilterHeaderSplitID, split1.String(), objectSDK.MatchStringEqual)
|
||||||
testSelect(t, db, cid, fs,
|
testSelect(t, db, cid, fs,
|
||||||
child1.Object().Address(),
|
object.AddressOf(child1),
|
||||||
child2.Object().Address(),
|
object.AddressOf(child2),
|
||||||
)
|
)
|
||||||
|
|
||||||
fs = objectSDK.SearchFilters{}
|
fs = objectSDK.SearchFilters{}
|
||||||
fs.AddFilter(v2object.FilterHeaderSplitID, split2.String(), objectSDK.MatchStringEqual)
|
fs.AddFilter(v2object.FilterHeaderSplitID, split2.String(), objectSDK.MatchStringEqual)
|
||||||
testSelect(t, db, cid, fs, child3.Object().Address())
|
testSelect(t, db, cid, fs, object.AddressOf(child3))
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("empty split", func(t *testing.T) {
|
t.Run("empty split", func(t *testing.T) {
|
||||||
|
@ -634,12 +635,12 @@ func TestDB_SelectContainerID(t *testing.T) {
|
||||||
|
|
||||||
cid := cidtest.ID()
|
cid := cidtest.ID()
|
||||||
|
|
||||||
obj1 := generateRawObjectWithCID(t, cid)
|
obj1 := generateObjectWithCID(t, cid)
|
||||||
err := putBig(db, obj1.Object())
|
err := putBig(db, obj1)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
obj2 := generateRawObjectWithCID(t, cid)
|
obj2 := generateObjectWithCID(t, cid)
|
||||||
err = putBig(db, obj2.Object())
|
err = putBig(db, obj2)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
t.Run("same cid", func(t *testing.T) {
|
t.Run("same cid", func(t *testing.T) {
|
||||||
|
@ -647,16 +648,16 @@ func TestDB_SelectContainerID(t *testing.T) {
|
||||||
fs.AddObjectContainerIDFilter(objectSDK.MatchStringEqual, cid)
|
fs.AddObjectContainerIDFilter(objectSDK.MatchStringEqual, cid)
|
||||||
|
|
||||||
testSelect(t, db, cid, fs,
|
testSelect(t, db, cid, fs,
|
||||||
obj1.Object().Address(),
|
object.AddressOf(obj1),
|
||||||
obj2.Object().Address(),
|
object.AddressOf(obj2),
|
||||||
)
|
)
|
||||||
|
|
||||||
fs = objectSDK.SearchFilters{}
|
fs = objectSDK.SearchFilters{}
|
||||||
fs.AddObjectContainerIDFilter(objectSDK.MatchStringNotEqual, cid)
|
fs.AddObjectContainerIDFilter(objectSDK.MatchStringNotEqual, cid)
|
||||||
|
|
||||||
testSelect(t, db, cid, fs,
|
testSelect(t, db, cid, fs,
|
||||||
obj1.Object().Address(),
|
object.AddressOf(obj1),
|
||||||
obj2.Object().Address(),
|
object.AddressOf(obj2),
|
||||||
)
|
)
|
||||||
|
|
||||||
fs = objectSDK.SearchFilters{}
|
fs = objectSDK.SearchFilters{}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package meta_test
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
|
||||||
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -11,31 +12,31 @@ import (
|
||||||
func TestDB_IsSmall(t *testing.T) {
|
func TestDB_IsSmall(t *testing.T) {
|
||||||
db := newDB(t)
|
db := newDB(t)
|
||||||
|
|
||||||
raw1 := generateRawObject(t)
|
raw1 := generateObject(t)
|
||||||
raw2 := generateRawObject(t)
|
raw2 := generateObject(t)
|
||||||
|
|
||||||
blobovniczaID := blobovnicza.ID{1, 2, 3, 4}
|
blobovniczaID := blobovnicza.ID{1, 2, 3, 4}
|
||||||
|
|
||||||
// check IsSmall from empty database
|
// check IsSmall from empty database
|
||||||
fetchedBlobovniczaID, err := meta.IsSmall(db, raw1.Object().Address())
|
fetchedBlobovniczaID, err := meta.IsSmall(db, object.AddressOf(raw1))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Nil(t, fetchedBlobovniczaID)
|
require.Nil(t, fetchedBlobovniczaID)
|
||||||
|
|
||||||
// put one object with blobovniczaID
|
// put one object with blobovniczaID
|
||||||
err = meta.Put(db, raw1.Object(), &blobovniczaID)
|
err = meta.Put(db, raw1, &blobovniczaID)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// put one object without blobovniczaID
|
// put one object without blobovniczaID
|
||||||
err = putBig(db, raw2.Object())
|
err = putBig(db, raw2)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// check IsSmall for object without blobovniczaID
|
// check IsSmall for object without blobovniczaID
|
||||||
fetchedBlobovniczaID, err = meta.IsSmall(db, raw2.Object().Address())
|
fetchedBlobovniczaID, err = meta.IsSmall(db, object.AddressOf(raw2))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Nil(t, fetchedBlobovniczaID)
|
require.Nil(t, fetchedBlobovniczaID)
|
||||||
|
|
||||||
// check IsSmall for object with blobovniczaID
|
// check IsSmall for object with blobovniczaID
|
||||||
fetchedBlobovniczaID, err = meta.IsSmall(db, raw1.Object().Address())
|
fetchedBlobovniczaID, err = meta.IsSmall(db, object.AddressOf(raw1))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, &blobovniczaID, fetchedBlobovniczaID)
|
require.Equal(t, &blobovniczaID, fetchedBlobovniczaID)
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ func (s *Shard) refillMetabase() error {
|
||||||
return fmt.Errorf("could not reset metabase: %w", err)
|
return fmt.Errorf("could not reset metabase: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return blobstor.IterateObjects(s.blobStor, func(obj *object.Object, blzID *blobovnicza.ID) error {
|
return blobstor.IterateObjects(s.blobStor, func(obj *objectSDK.Object, blzID *blobovnicza.ID) error {
|
||||||
if obj.Type() == objectSDK.TypeTombstone {
|
if obj.Type() == objectSDK.TypeTombstone {
|
||||||
tombstone := objectSDK.NewTombstone()
|
tombstone := objectSDK.NewTombstone()
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ func (s *Shard) refillMetabase() error {
|
||||||
return fmt.Errorf("could not unmarshal tombstone content: %w", err)
|
return fmt.Errorf("could not unmarshal tombstone content: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
tombAddr := obj.Address()
|
tombAddr := object.AddressOf(obj)
|
||||||
cid := tombAddr.ContainerID()
|
cid := tombAddr.ContainerID()
|
||||||
memberIDs := tombstone.Members()
|
memberIDs := tombstone.Members()
|
||||||
tombMembers := make([]*addressSDK.Address, 0, len(memberIDs))
|
tombMembers := make([]*addressSDK.Address, 0, len(memberIDs))
|
||||||
|
|
|
@ -41,19 +41,17 @@ func TestRefillMetabase(t *testing.T) {
|
||||||
const objNum = 5
|
const objNum = 5
|
||||||
|
|
||||||
type objAddr struct {
|
type objAddr struct {
|
||||||
obj *object.Object
|
obj *objectSDK.Object
|
||||||
addr *addressSDK.Address
|
addr *addressSDK.Address
|
||||||
}
|
}
|
||||||
|
|
||||||
mObjs := make(map[string]objAddr)
|
mObjs := make(map[string]objAddr)
|
||||||
|
|
||||||
for i := uint64(0); i < objNum; i++ {
|
for i := uint64(0); i < objNum; i++ {
|
||||||
rawObj := objecttest.Raw()
|
obj := objecttest.Object()
|
||||||
rawObj.SetType(objectSDK.TypeRegular)
|
obj.SetType(objectSDK.TypeRegular)
|
||||||
|
|
||||||
obj := object.NewFromSDK(rawObj.Object())
|
addr := object.AddressOf(obj)
|
||||||
|
|
||||||
addr := obj.Address()
|
|
||||||
|
|
||||||
mObjs[addr.String()] = objAddr{
|
mObjs[addr.String()] = objAddr{
|
||||||
obj: obj,
|
obj: obj,
|
||||||
|
@ -61,17 +59,15 @@ func TestRefillMetabase(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tombObjRaw := object.NewRawFrom(objecttest.Raw())
|
tombObj := objecttest.Object()
|
||||||
tombObjRaw.SetType(objectSDK.TypeTombstone)
|
tombObj.SetType(objectSDK.TypeTombstone)
|
||||||
|
|
||||||
tombstone := objecttest.Tombstone()
|
tombstone := objecttest.Tombstone()
|
||||||
|
|
||||||
tombData, err := tombstone.Marshal()
|
tombData, err := tombstone.Marshal()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
tombObjRaw.SetPayload(tombData)
|
tombObj.SetPayload(tombData)
|
||||||
|
|
||||||
tombObj := tombObjRaw.Object()
|
|
||||||
|
|
||||||
tombMembers := make([]*addressSDK.Address, 0, len(tombstone.Members()))
|
tombMembers := make([]*addressSDK.Address, 0, len(tombstone.Members()))
|
||||||
|
|
||||||
|
@ -93,12 +89,12 @@ func TestRefillMetabase(t *testing.T) {
|
||||||
_, err = sh.Put(putPrm.WithObject(tombObj))
|
_, err = sh.Put(putPrm.WithObject(tombObj))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
_, err = sh.Inhume(new(InhumePrm).WithTarget(tombObj.Address(), tombMembers...))
|
_, err = sh.Inhume(new(InhumePrm).WithTarget(object.AddressOf(tombObj), tombMembers...))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
var headPrm HeadPrm
|
var headPrm HeadPrm
|
||||||
|
|
||||||
checkObj := func(addr *addressSDK.Address, expObj *object.Object) {
|
checkObj := func(addr *addressSDK.Address, expObj *objectSDK.Object) {
|
||||||
res, err := sh.Head(headPrm.WithAddress(addr))
|
res, err := sh.Head(headPrm.WithAddress(addr))
|
||||||
|
|
||||||
if expObj == nil {
|
if expObj == nil {
|
||||||
|
@ -107,7 +103,7 @@ func TestRefillMetabase(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, object.NewRawFromObject(expObj).CutPayload().Object(), res.Object())
|
require.Equal(t, expObj.CutPayload(), res.Object())
|
||||||
}
|
}
|
||||||
|
|
||||||
checkAllObjs := func(exists bool) {
|
checkAllObjs := func(exists bool) {
|
||||||
|
@ -133,7 +129,7 @@ func TestRefillMetabase(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
checkAllObjs(true)
|
checkAllObjs(true)
|
||||||
checkObj(tombObj.Address(), tombObj)
|
checkObj(object.AddressOf(tombObj), tombObj)
|
||||||
checkTombMembers(true)
|
checkTombMembers(true)
|
||||||
|
|
||||||
err = sh.Close()
|
err = sh.Close()
|
||||||
|
@ -155,13 +151,13 @@ func TestRefillMetabase(t *testing.T) {
|
||||||
defer sh.Close()
|
defer sh.Close()
|
||||||
|
|
||||||
checkAllObjs(false)
|
checkAllObjs(false)
|
||||||
checkObj(tombObj.Address(), nil)
|
checkObj(object.AddressOf(tombObj), nil)
|
||||||
checkTombMembers(false)
|
checkTombMembers(false)
|
||||||
|
|
||||||
err = sh.refillMetabase()
|
err = sh.refillMetabase()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
checkAllObjs(true)
|
checkAllObjs(true)
|
||||||
checkObj(tombObj.Address(), tombObj)
|
checkObj(object.AddressOf(tombObj), tombObj)
|
||||||
checkTombMembers(true)
|
checkTombMembers(true)
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ func testShardDelete(t *testing.T, hasWriteCache bool) {
|
||||||
|
|
||||||
cid := cidtest.ID()
|
cid := cidtest.ID()
|
||||||
|
|
||||||
obj := generateRawObjectWithCID(t, cid)
|
obj := generateObjectWithCID(t, cid)
|
||||||
addAttribute(obj, "foo", "bar")
|
addAttribute(obj, "foo", "bar")
|
||||||
|
|
||||||
putPrm := new(shard.PutPrm)
|
putPrm := new(shard.PutPrm)
|
||||||
|
@ -34,11 +34,11 @@ func testShardDelete(t *testing.T, hasWriteCache bool) {
|
||||||
t.Run("big object", func(t *testing.T) {
|
t.Run("big object", func(t *testing.T) {
|
||||||
addPayload(obj, 1<<20)
|
addPayload(obj, 1<<20)
|
||||||
|
|
||||||
putPrm.WithObject(obj.Object())
|
putPrm.WithObject(obj)
|
||||||
getPrm.WithAddress(obj.Object().Address())
|
getPrm.WithAddress(object.AddressOf(obj))
|
||||||
|
|
||||||
delPrm := new(shard.DeletePrm)
|
delPrm := new(shard.DeletePrm)
|
||||||
delPrm.WithAddresses(obj.Object().Address())
|
delPrm.WithAddresses(object.AddressOf(obj))
|
||||||
|
|
||||||
_, err := sh.Put(putPrm)
|
_, err := sh.Put(putPrm)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -57,11 +57,11 @@ func testShardDelete(t *testing.T, hasWriteCache bool) {
|
||||||
obj.SetID(generateOID())
|
obj.SetID(generateOID())
|
||||||
addPayload(obj, 1<<5)
|
addPayload(obj, 1<<5)
|
||||||
|
|
||||||
putPrm.WithObject(obj.Object())
|
putPrm.WithObject(obj)
|
||||||
getPrm.WithAddress(obj.Object().Address())
|
getPrm.WithAddress(object.AddressOf(obj))
|
||||||
|
|
||||||
delPrm := new(shard.DeletePrm)
|
delPrm := new(shard.DeletePrm)
|
||||||
delPrm.WithAddresses(obj.Object().Address())
|
delPrm.WithAddresses(object.AddressOf(obj))
|
||||||
|
|
||||||
_, err := sh.Put(putPrm)
|
_, err := sh.Put(putPrm)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -18,6 +18,7 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/writecache"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/writecache"
|
||||||
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
||||||
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||||
objecttest "github.com/nspcc-dev/neofs-sdk-go/object/id/test"
|
objecttest "github.com/nspcc-dev/neofs-sdk-go/object/id/test"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -72,7 +73,7 @@ func testDump(t *testing.T, objCount int, hasWriteCache bool) {
|
||||||
// Approximate object header size.
|
// Approximate object header size.
|
||||||
const headerSize = 400
|
const headerSize = 400
|
||||||
|
|
||||||
objects := make([]*object.Object, objCount)
|
objects := make([]*objectSDK.Object, objCount)
|
||||||
for i := 0; i < objCount; i++ {
|
for i := 0; i < objCount; i++ {
|
||||||
cid := cidtest.ID()
|
cid := cidtest.ID()
|
||||||
var size int
|
var size int
|
||||||
|
@ -88,8 +89,8 @@ func testDump(t *testing.T, objCount int, hasWriteCache bool) {
|
||||||
}
|
}
|
||||||
data := make([]byte, size)
|
data := make([]byte, size)
|
||||||
rand.Read(data)
|
rand.Read(data)
|
||||||
obj := generateRawObjectWithPayload(cid, data)
|
obj := generateObjectWithPayload(cid, data)
|
||||||
objects[i] = obj.Object()
|
objects[i] = obj
|
||||||
|
|
||||||
prm := new(shard.PutPrm).WithObject(objects[i])
|
prm := new(shard.PutPrm).WithObject(objects[i])
|
||||||
_, err := sh.Put(prm)
|
_, err := sh.Put(prm)
|
||||||
|
@ -192,11 +193,11 @@ func TestStream(t *testing.T) {
|
||||||
defer releaseShard(sh2, t)
|
defer releaseShard(sh2, t)
|
||||||
|
|
||||||
const objCount = 5
|
const objCount = 5
|
||||||
objects := make([]*object.Object, objCount)
|
objects := make([]*objectSDK.Object, objCount)
|
||||||
for i := 0; i < objCount; i++ {
|
for i := 0; i < objCount; i++ {
|
||||||
cid := cidtest.ID()
|
cid := cidtest.ID()
|
||||||
obj := generateRawObjectWithCID(t, cid)
|
obj := generateObjectWithCID(t, cid)
|
||||||
objects[i] = obj.Object()
|
objects[i] = obj
|
||||||
|
|
||||||
prm := new(shard.PutPrm).WithObject(objects[i])
|
prm := new(shard.PutPrm).WithObject(objects[i])
|
||||||
_, err := sh1.Put(prm)
|
_, err := sh1.Put(prm)
|
||||||
|
@ -227,13 +228,13 @@ func TestStream(t *testing.T) {
|
||||||
}, time.Second, time.Millisecond)
|
}, time.Second, time.Millisecond)
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkRestore(t *testing.T, sh *shard.Shard, prm *shard.RestorePrm, objects []*object.Object) {
|
func checkRestore(t *testing.T, sh *shard.Shard, prm *shard.RestorePrm, objects []*objectSDK.Object) {
|
||||||
res, err := sh.Restore(prm)
|
res, err := sh.Restore(prm)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, len(objects), res.Count())
|
require.Equal(t, len(objects), res.Count())
|
||||||
|
|
||||||
for i := range objects {
|
for i := range objects {
|
||||||
res, err := sh.Get(new(shard.GetPrm).WithAddress(objects[i].Address()))
|
res, err := sh.Get(new(shard.GetPrm).WithAddress(object.AddressOf(objects[i])))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, objects[i], res.Object())
|
require.Equal(t, objects[i], res.Object())
|
||||||
}
|
}
|
||||||
|
@ -268,11 +269,11 @@ func TestDumpIgnoreErrors(t *testing.T) {
|
||||||
}
|
}
|
||||||
sh := newCustomShard(t, dir, true, wcOpts, bsOpts)
|
sh := newCustomShard(t, dir, true, wcOpts, bsOpts)
|
||||||
|
|
||||||
objects := make([]*object.Object, objCount)
|
objects := make([]*objectSDK.Object, objCount)
|
||||||
for i := 0; i < objCount; i++ {
|
for i := 0; i < objCount; i++ {
|
||||||
size := (wcSmallObjectSize << (i % 4)) - headerSize
|
size := (wcSmallObjectSize << (i % 4)) - headerSize
|
||||||
obj := generateRawObjectWithPayload(cidtest.ID(), make([]byte, size))
|
obj := generateObjectWithPayload(cidtest.ID(), make([]byte, size))
|
||||||
objects[i] = obj.Object()
|
objects[i] = obj
|
||||||
|
|
||||||
prm := new(shard.PutPrm).WithObject(objects[i])
|
prm := new(shard.PutPrm).WithObject(objects[i])
|
||||||
_, err := sh.Put(prm)
|
_, err := sh.Put(prm)
|
||||||
|
|
|
@ -8,13 +8,14 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor"
|
||||||
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
||||||
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
// storFetcher is a type to unify object fetching mechanism in `fetchObjectData`
|
// storFetcher is a type to unify object fetching mechanism in `fetchObjectData`
|
||||||
// method. It represents generalization of `getSmall` and `getBig` methods.
|
// method. It represents generalization of `getSmall` and `getBig` methods.
|
||||||
type storFetcher = func(stor *blobstor.BlobStor, id *blobovnicza.ID) (*object.Object, error)
|
type storFetcher = func(stor *blobstor.BlobStor, id *blobovnicza.ID) (*objectSDK.Object, error)
|
||||||
|
|
||||||
// GetPrm groups the parameters of Get operation.
|
// GetPrm groups the parameters of Get operation.
|
||||||
type GetPrm struct {
|
type GetPrm struct {
|
||||||
|
@ -24,7 +25,7 @@ type GetPrm struct {
|
||||||
|
|
||||||
// GetRes groups resulting values of Get operation.
|
// GetRes groups resulting values of Get operation.
|
||||||
type GetRes struct {
|
type GetRes struct {
|
||||||
obj *object.Object
|
obj *objectSDK.Object
|
||||||
hasMeta bool
|
hasMeta bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +48,7 @@ func (p *GetPrm) WithIgnoreMeta(ignore bool) *GetPrm {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Object returns the requested object.
|
// Object returns the requested object.
|
||||||
func (r *GetRes) Object() *object.Object {
|
func (r *GetRes) Object() *objectSDK.Object {
|
||||||
return r.obj
|
return r.obj
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +66,7 @@ func (r *GetRes) HasMeta() bool {
|
||||||
func (s *Shard) Get(prm *GetPrm) (*GetRes, error) {
|
func (s *Shard) Get(prm *GetPrm) (*GetRes, error) {
|
||||||
var big, small storFetcher
|
var big, small storFetcher
|
||||||
|
|
||||||
big = func(stor *blobstor.BlobStor, _ *blobovnicza.ID) (*object.Object, error) {
|
big = func(stor *blobstor.BlobStor, _ *blobovnicza.ID) (*objectSDK.Object, error) {
|
||||||
getBigPrm := new(blobstor.GetBigPrm)
|
getBigPrm := new(blobstor.GetBigPrm)
|
||||||
getBigPrm.SetAddress(prm.addr)
|
getBigPrm.SetAddress(prm.addr)
|
||||||
|
|
||||||
|
@ -77,7 +78,7 @@ func (s *Shard) Get(prm *GetPrm) (*GetRes, error) {
|
||||||
return res.Object(), nil
|
return res.Object(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
small = func(stor *blobstor.BlobStor, id *blobovnicza.ID) (*object.Object, error) {
|
small = func(stor *blobstor.BlobStor, id *blobovnicza.ID) (*objectSDK.Object, error) {
|
||||||
getSmallPrm := new(blobstor.GetSmallPrm)
|
getSmallPrm := new(blobstor.GetSmallPrm)
|
||||||
getSmallPrm.SetAddress(prm.addr)
|
getSmallPrm.SetAddress(prm.addr)
|
||||||
getSmallPrm.SetBlobovniczaID(id)
|
getSmallPrm.SetBlobovniczaID(id)
|
||||||
|
@ -99,10 +100,10 @@ func (s *Shard) Get(prm *GetPrm) (*GetRes, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetchObjectData looks through writeCache and blobStor to find object.
|
// fetchObjectData looks through writeCache and blobStor to find object.
|
||||||
func (s *Shard) fetchObjectData(addr *addressSDK.Address, skipMeta bool, big, small storFetcher) (*object.Object, bool, error) {
|
func (s *Shard) fetchObjectData(addr *addressSDK.Address, skipMeta bool, big, small storFetcher) (*objectSDK.Object, bool, error) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
res *object.Object
|
res *objectSDK.Object
|
||||||
)
|
)
|
||||||
|
|
||||||
if s.hasWriteCache() {
|
if s.hasWriteCache() {
|
||||||
|
|
|
@ -31,67 +31,67 @@ func testShardGet(t *testing.T, hasWriteCache bool) {
|
||||||
getPrm := new(shard.GetPrm)
|
getPrm := new(shard.GetPrm)
|
||||||
|
|
||||||
t.Run("small object", func(t *testing.T) {
|
t.Run("small object", func(t *testing.T) {
|
||||||
obj := generateRawObject(t)
|
obj := generateObject(t)
|
||||||
addAttribute(obj, "foo", "bar")
|
addAttribute(obj, "foo", "bar")
|
||||||
addPayload(obj, 1<<5)
|
addPayload(obj, 1<<5)
|
||||||
|
|
||||||
putPrm.WithObject(obj.Object())
|
putPrm.WithObject(obj)
|
||||||
|
|
||||||
_, err := sh.Put(putPrm)
|
_, err := sh.Put(putPrm)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
getPrm.WithAddress(obj.Object().Address())
|
getPrm.WithAddress(object.AddressOf(obj))
|
||||||
|
|
||||||
res, err := testGet(t, sh, getPrm, hasWriteCache)
|
res, err := testGet(t, sh, getPrm, hasWriteCache)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, obj.Object(), res.Object())
|
require.Equal(t, obj, res.Object())
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("big object", func(t *testing.T) {
|
t.Run("big object", func(t *testing.T) {
|
||||||
obj := generateRawObject(t)
|
obj := generateObject(t)
|
||||||
addAttribute(obj, "foo", "bar")
|
addAttribute(obj, "foo", "bar")
|
||||||
obj.SetID(generateOID())
|
obj.SetID(generateOID())
|
||||||
addPayload(obj, 1<<20) // big obj
|
addPayload(obj, 1<<20) // big obj
|
||||||
|
|
||||||
putPrm.WithObject(obj.Object())
|
putPrm.WithObject(obj)
|
||||||
|
|
||||||
_, err := sh.Put(putPrm)
|
_, err := sh.Put(putPrm)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
getPrm.WithAddress(obj.Object().Address())
|
getPrm.WithAddress(object.AddressOf(obj))
|
||||||
|
|
||||||
res, err := testGet(t, sh, getPrm, hasWriteCache)
|
res, err := testGet(t, sh, getPrm, hasWriteCache)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, obj.Object(), res.Object())
|
require.Equal(t, obj, res.Object())
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("parent object", func(t *testing.T) {
|
t.Run("parent object", func(t *testing.T) {
|
||||||
obj := generateRawObject(t)
|
obj := generateObject(t)
|
||||||
addAttribute(obj, "foo", "bar")
|
addAttribute(obj, "foo", "bar")
|
||||||
cid := cidtest.ID()
|
cid := cidtest.ID()
|
||||||
splitID := objectSDK.NewSplitID()
|
splitID := objectSDK.NewSplitID()
|
||||||
|
|
||||||
parent := generateRawObjectWithCID(t, cid)
|
parent := generateObjectWithCID(t, cid)
|
||||||
addAttribute(parent, "parent", "attribute")
|
addAttribute(parent, "parent", "attribute")
|
||||||
|
|
||||||
child := generateRawObjectWithCID(t, cid)
|
child := generateObjectWithCID(t, cid)
|
||||||
child.SetParent(parent.Object().SDK())
|
child.SetParent(parent)
|
||||||
child.SetParentID(parent.ID())
|
child.SetParentID(parent.ID())
|
||||||
child.SetSplitID(splitID)
|
child.SetSplitID(splitID)
|
||||||
addPayload(child, 1<<5)
|
addPayload(child, 1<<5)
|
||||||
|
|
||||||
putPrm.WithObject(child.Object())
|
putPrm.WithObject(child)
|
||||||
|
|
||||||
_, err := sh.Put(putPrm)
|
_, err := sh.Put(putPrm)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
getPrm.WithAddress(child.Object().Address())
|
getPrm.WithAddress(object.AddressOf(child))
|
||||||
|
|
||||||
res, err := testGet(t, sh, getPrm, hasWriteCache)
|
res, err := testGet(t, sh, getPrm, hasWriteCache)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.True(t, binaryEqual(child.Object(), res.Object()))
|
require.True(t, binaryEqual(child, res.Object()))
|
||||||
|
|
||||||
getPrm.WithAddress(parent.Object().Address())
|
getPrm.WithAddress(object.AddressOf(parent))
|
||||||
|
|
||||||
_, err = testGet(t, sh, getPrm, hasWriteCache)
|
_, err = testGet(t, sh, getPrm, hasWriteCache)
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ func testGet(t *testing.T, sh *shard.Shard, getPrm *shard.GetPrm, hasWriteCache
|
||||||
|
|
||||||
// binary equal is used when object contains empty lists in the structure and
|
// binary equal is used when object contains empty lists in the structure and
|
||||||
// requre.Equal fails on comparing <nil> and []{} lists.
|
// requre.Equal fails on comparing <nil> and []{} lists.
|
||||||
func binaryEqual(a, b *object.Object) bool {
|
func binaryEqual(a, b *objectSDK.Object) bool {
|
||||||
binaryA, err := a.Marshal()
|
binaryA, err := a.Marshal()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||||
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
||||||
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -17,7 +18,7 @@ type HeadPrm struct {
|
||||||
|
|
||||||
// HeadRes groups resulting values of Head operation.
|
// HeadRes groups resulting values of Head operation.
|
||||||
type HeadRes struct {
|
type HeadRes struct {
|
||||||
obj *object.Object
|
obj *objectSDK.Object
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithAddress is a Head option to set the address of the requested object.
|
// WithAddress is a Head option to set the address of the requested object.
|
||||||
|
@ -43,7 +44,7 @@ func (p *HeadPrm) WithRaw(raw bool) *HeadPrm {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Object returns the requested object header.
|
// Object returns the requested object header.
|
||||||
func (r *HeadRes) Object() *object.Object {
|
func (r *HeadRes) Object() *objectSDK.Object {
|
||||||
return r.obj
|
return r.obj
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,39 +30,39 @@ func testShardHead(t *testing.T, hasWriteCache bool) {
|
||||||
headPrm := new(shard.HeadPrm)
|
headPrm := new(shard.HeadPrm)
|
||||||
|
|
||||||
t.Run("regular object", func(t *testing.T) {
|
t.Run("regular object", func(t *testing.T) {
|
||||||
obj := generateRawObject(t)
|
obj := generateObject(t)
|
||||||
addAttribute(obj, "foo", "bar")
|
addAttribute(obj, "foo", "bar")
|
||||||
|
|
||||||
putPrm.WithObject(obj.Object())
|
putPrm.WithObject(obj)
|
||||||
|
|
||||||
_, err := sh.Put(putPrm)
|
_, err := sh.Put(putPrm)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
headPrm.WithAddress(obj.Object().Address())
|
headPrm.WithAddress(object.AddressOf(obj))
|
||||||
|
|
||||||
res, err := testHead(t, sh, headPrm, hasWriteCache)
|
res, err := testHead(t, sh, headPrm, hasWriteCache)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, obj.CutPayload().Object(), res.Object())
|
require.Equal(t, obj.CutPayload(), res.Object())
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("virtual object", func(t *testing.T) {
|
t.Run("virtual object", func(t *testing.T) {
|
||||||
cid := cidtest.ID()
|
cid := cidtest.ID()
|
||||||
splitID := objectSDK.NewSplitID()
|
splitID := objectSDK.NewSplitID()
|
||||||
|
|
||||||
parent := generateRawObjectWithCID(t, cid)
|
parent := generateObjectWithCID(t, cid)
|
||||||
addAttribute(parent, "foo", "bar")
|
addAttribute(parent, "foo", "bar")
|
||||||
|
|
||||||
child := generateRawObjectWithCID(t, cid)
|
child := generateObjectWithCID(t, cid)
|
||||||
child.SetParent(parent.Object().SDK())
|
child.SetParent(parent)
|
||||||
child.SetParentID(parent.ID())
|
child.SetParentID(parent.ID())
|
||||||
child.SetSplitID(splitID)
|
child.SetSplitID(splitID)
|
||||||
|
|
||||||
putPrm.WithObject(child.Object())
|
putPrm.WithObject(child)
|
||||||
|
|
||||||
_, err := sh.Put(putPrm)
|
_, err := sh.Put(putPrm)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
headPrm.WithAddress(parent.Object().Address())
|
headPrm.WithAddress(object.AddressOf(parent))
|
||||||
headPrm.WithRaw(true)
|
headPrm.WithRaw(true)
|
||||||
|
|
||||||
var siErr *objectSDK.SplitInfoError
|
var siErr *objectSDK.SplitInfoError
|
||||||
|
@ -70,12 +70,12 @@ func testShardHead(t *testing.T, hasWriteCache bool) {
|
||||||
_, err = testHead(t, sh, headPrm, hasWriteCache)
|
_, err = testHead(t, sh, headPrm, hasWriteCache)
|
||||||
require.True(t, errors.As(err, &siErr))
|
require.True(t, errors.As(err, &siErr))
|
||||||
|
|
||||||
headPrm.WithAddress(parent.Object().Address())
|
headPrm.WithAddress(object.AddressOf(parent))
|
||||||
headPrm.WithRaw(false)
|
headPrm.WithRaw(false)
|
||||||
|
|
||||||
head, err := sh.Head(headPrm)
|
head, err := sh.Head(headPrm)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, parent.CutPayload().Object(), head.Object())
|
require.Equal(t, parent.CutPayload(), head.Object())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,19 +25,19 @@ func testShardInhume(t *testing.T, hasWriteCache bool) {
|
||||||
|
|
||||||
cid := cidtest.ID()
|
cid := cidtest.ID()
|
||||||
|
|
||||||
obj := generateRawObjectWithCID(t, cid)
|
obj := generateObjectWithCID(t, cid)
|
||||||
addAttribute(obj, "foo", "bar")
|
addAttribute(obj, "foo", "bar")
|
||||||
|
|
||||||
ts := generateRawObjectWithCID(t, cid)
|
ts := generateObjectWithCID(t, cid)
|
||||||
|
|
||||||
putPrm := new(shard.PutPrm)
|
putPrm := new(shard.PutPrm)
|
||||||
putPrm.WithObject(obj.Object())
|
putPrm.WithObject(obj)
|
||||||
|
|
||||||
inhPrm := new(shard.InhumePrm)
|
inhPrm := new(shard.InhumePrm)
|
||||||
inhPrm.WithTarget(ts.Object().Address(), obj.Object().Address())
|
inhPrm.WithTarget(object.AddressOf(ts), object.AddressOf(obj))
|
||||||
|
|
||||||
getPrm := new(shard.GetPrm)
|
getPrm := new(shard.GetPrm)
|
||||||
getPrm.WithAddress(obj.Object().Address())
|
getPrm.WithAddress(object.AddressOf(obj))
|
||||||
|
|
||||||
_, err := sh.Put(putPrm)
|
_, err := sh.Put(putPrm)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -3,6 +3,7 @@ package shard_test
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
||||||
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -37,17 +38,17 @@ func testShardList(t *testing.T, sh *shard.Shard) {
|
||||||
cid := cidtest.ID()
|
cid := cidtest.ID()
|
||||||
|
|
||||||
for j := 0; j < N; j++ {
|
for j := 0; j < N; j++ {
|
||||||
obj := generateRawObjectWithCID(t, cid)
|
obj := generateObjectWithCID(t, cid)
|
||||||
addPayload(obj, 1<<2)
|
addPayload(obj, 1<<2)
|
||||||
|
|
||||||
// add parent as virtual object, it must be ignored in List()
|
// add parent as virtual object, it must be ignored in List()
|
||||||
parent := generateRawObjectWithCID(t, cid)
|
parent := generateObjectWithCID(t, cid)
|
||||||
obj.SetParentID(parent.Object().ID())
|
obj.SetParentID(parent.ID())
|
||||||
obj.SetParent(parent.Object().SDK())
|
obj.SetParent(parent)
|
||||||
|
|
||||||
objs[obj.Object().Address().String()] = 0
|
objs[object.AddressOf(obj).String()] = 0
|
||||||
|
|
||||||
putPrm.WithObject(obj.Object())
|
putPrm.WithObject(obj)
|
||||||
|
|
||||||
_, err := sh.Put(putPrm)
|
_, err := sh.Put(putPrm)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -3,9 +3,9 @@ package shard
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor"
|
||||||
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
||||||
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
package shard
|
package shard
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -73,7 +72,7 @@ func (r *RngRes) HasMeta() bool {
|
||||||
func (s *Shard) GetRange(prm *RngPrm) (*RngRes, error) {
|
func (s *Shard) GetRange(prm *RngPrm) (*RngRes, error) {
|
||||||
var big, small storFetcher
|
var big, small storFetcher
|
||||||
|
|
||||||
rng := objectSDK.NewRange()
|
rng := object.NewRange()
|
||||||
rng.SetOffset(prm.off)
|
rng.SetOffset(prm.off)
|
||||||
rng.SetLength(prm.ln)
|
rng.SetLength(prm.ln)
|
||||||
|
|
||||||
|
@ -87,10 +86,10 @@ func (s *Shard) GetRange(prm *RngPrm) (*RngRes, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
obj := object.NewRaw()
|
obj := object.New()
|
||||||
obj.SetPayload(res.RangeData())
|
obj.SetPayload(res.RangeData())
|
||||||
|
|
||||||
return obj.Object(), nil
|
return obj, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
small = func(stor *blobstor.BlobStor, id *blobovnicza.ID) (*object.Object, error) {
|
small = func(stor *blobstor.BlobStor, id *blobovnicza.ID) (*object.Object, error) {
|
||||||
|
@ -104,10 +103,10 @@ func (s *Shard) GetRange(prm *RngPrm) (*RngRes, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
obj := object.NewRaw()
|
obj := object.New()
|
||||||
obj.SetPayload(res.RangeData())
|
obj.SetPayload(res.RangeData())
|
||||||
|
|
||||||
return obj.Object(), nil
|
return obj, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
obj, hasMeta, err := s.fetchObjectData(prm.addr, prm.skipMeta, big, small)
|
obj, hasMeta, err := s.fetchObjectData(prm.addr, prm.skipMeta, big, small)
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ErrInvalidMagic is returned when dump format is invalid.
|
// ErrInvalidMagic is returned when dump format is invalid.
|
||||||
|
|
|
@ -5,14 +5,14 @@ import (
|
||||||
|
|
||||||
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
||||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SelectPrm groups the parameters of Select operation.
|
// SelectPrm groups the parameters of Select operation.
|
||||||
type SelectPrm struct {
|
type SelectPrm struct {
|
||||||
cid *cid.ID
|
cid *cid.ID
|
||||||
filters objectSDK.SearchFilters
|
filters object.SearchFilters
|
||||||
}
|
}
|
||||||
|
|
||||||
// SelectRes groups resulting values of Select operation.
|
// SelectRes groups resulting values of Select operation.
|
||||||
|
@ -30,7 +30,7 @@ func (p *SelectPrm) WithContainerID(cid *cid.ID) *SelectPrm {
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithFilters is a Select option to set the object filters.
|
// WithFilters is a Select option to set the object filters.
|
||||||
func (p *SelectPrm) WithFilters(fs objectSDK.SearchFilters) *SelectPrm {
|
func (p *SelectPrm) WithFilters(fs object.SearchFilters) *SelectPrm {
|
||||||
if p != nil {
|
if p != nil {
|
||||||
p.filters = fs
|
p.filters = fs
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor"
|
||||||
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
||||||
|
@ -17,7 +16,7 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/checksum"
|
"github.com/nspcc-dev/neofs-sdk-go/checksum"
|
||||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||||
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
||||||
ownertest "github.com/nspcc-dev/neofs-sdk-go/owner/test"
|
ownertest "github.com/nspcc-dev/neofs-sdk-go/owner/test"
|
||||||
|
@ -73,16 +72,16 @@ func releaseShard(s *shard.Shard, t testing.TB) {
|
||||||
os.RemoveAll(strings.Split(t.Name(), string(os.PathSeparator))[0])
|
os.RemoveAll(strings.Split(t.Name(), string(os.PathSeparator))[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateRawObject(t *testing.T) *object.RawObject {
|
func generateObject(t *testing.T) *object.Object {
|
||||||
return generateRawObjectWithCID(t, cidtest.ID())
|
return generateObjectWithCID(t, cidtest.ID())
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateRawObjectWithCID(t *testing.T, cid *cid.ID) *object.RawObject {
|
func generateObjectWithCID(t *testing.T, cid *cid.ID) *object.Object {
|
||||||
data := owner.PublicKeyToIDBytes(&test.DecodeKey(-1).PublicKey)
|
data := owner.PublicKeyToIDBytes(&test.DecodeKey(-1).PublicKey)
|
||||||
return generateRawObjectWithPayload(cid, data)
|
return generateObjectWithPayload(cid, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateRawObjectWithPayload(cid *cid.ID, data []byte) *object.RawObject {
|
func generateObjectWithPayload(cid *cid.ID, data []byte) *object.Object {
|
||||||
version := version.New()
|
version := version.New()
|
||||||
version.SetMajor(2)
|
version.SetMajor(2)
|
||||||
version.SetMinor(1)
|
version.SetMinor(1)
|
||||||
|
@ -93,7 +92,7 @@ func generateRawObjectWithPayload(cid *cid.ID, data []byte) *object.RawObject {
|
||||||
csumTZ := new(checksum.Checksum)
|
csumTZ := new(checksum.Checksum)
|
||||||
csumTZ.SetTillichZemor(tz.Sum(csum.Sum()))
|
csumTZ.SetTillichZemor(tz.Sum(csum.Sum()))
|
||||||
|
|
||||||
obj := object.NewRaw()
|
obj := object.New()
|
||||||
obj.SetID(generateOID())
|
obj.SetID(generateOID())
|
||||||
obj.SetOwnerID(ownertest.ID())
|
obj.SetOwnerID(ownertest.ID())
|
||||||
obj.SetContainerID(cid)
|
obj.SetContainerID(cid)
|
||||||
|
@ -105,8 +104,8 @@ func generateRawObjectWithPayload(cid *cid.ID, data []byte) *object.RawObject {
|
||||||
return obj
|
return obj
|
||||||
}
|
}
|
||||||
|
|
||||||
func addAttribute(obj *object.RawObject, key, val string) {
|
func addAttribute(obj *object.Object, key, val string) {
|
||||||
attr := objectSDK.NewAttribute()
|
attr := object.NewAttribute()
|
||||||
attr.SetKey(key)
|
attr.SetKey(key)
|
||||||
attr.SetValue(val)
|
attr.SetValue(val)
|
||||||
|
|
||||||
|
@ -115,7 +114,7 @@ func addAttribute(obj *object.RawObject, key, val string) {
|
||||||
obj.SetAttributes(attrs...)
|
obj.SetAttributes(attrs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func addPayload(obj *object.RawObject, size int) {
|
func addPayload(obj *object.Object, size int) {
|
||||||
buf := make([]byte, size)
|
buf := make([]byte, size)
|
||||||
_, _ = rand.Read(buf)
|
_, _ = rand.Read(buf)
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/writecache"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/writecache"
|
||||||
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
||||||
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -17,16 +18,16 @@ func TestWriteCacheObjectLoss(t *testing.T) {
|
||||||
objCount = 100
|
objCount = 100
|
||||||
)
|
)
|
||||||
|
|
||||||
objects := make([]*object.Object, objCount)
|
objects := make([]*objectSDK.Object, objCount)
|
||||||
for i := range objects {
|
for i := range objects {
|
||||||
size := smallSize
|
size := smallSize
|
||||||
//if i%2 == 0 {
|
// if i%2 == 0 {
|
||||||
size = smallSize / 2
|
size = smallSize / 2
|
||||||
//}
|
// }
|
||||||
data := make([]byte, size)
|
data := make([]byte, size)
|
||||||
rand.Read(data)
|
rand.Read(data)
|
||||||
|
|
||||||
objects[i] = generateRawObjectWithPayload(cidtest.ID(), data).Object()
|
objects[i] = generateObjectWithPayload(cidtest.ID(), data)
|
||||||
}
|
}
|
||||||
|
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
|
@ -46,7 +47,7 @@ func TestWriteCacheObjectLoss(t *testing.T) {
|
||||||
defer releaseShard(sh, t)
|
defer releaseShard(sh, t)
|
||||||
|
|
||||||
for i := range objects {
|
for i := range objects {
|
||||||
_, err := sh.Get(new(shard.GetPrm).WithAddress(objects[i].Address()))
|
_, err := sh.Get(new(shard.GetPrm).WithAddress(object.AddressOf(objects[i])))
|
||||||
require.NoError(t, err, i)
|
require.NoError(t, err, i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MergeSplitInfo ignores conflicts and rewrites `to` with non empty values
|
// MergeSplitInfo ignores conflicts and rewrites `to` with non empty values
|
||||||
// from `from`.
|
// from `from`.
|
||||||
func MergeSplitInfo(from, to *objectSDK.SplitInfo) *objectSDK.SplitInfo {
|
func MergeSplitInfo(from, to *object.SplitInfo) *object.SplitInfo {
|
||||||
to.SetSplitID(from.SplitID()) // overwrite SplitID and ignore conflicts
|
to.SetSplitID(from.SplitID()) // overwrite SplitID and ignore conflicts
|
||||||
|
|
||||||
if lp := from.LastPart(); lp != nil {
|
if lp := from.LastPart(); lp != nil {
|
||||||
|
|
|
@ -5,11 +5,11 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/mr-tron/base58"
|
"github.com/mr-tron/base58"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree"
|
||||||
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
||||||
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||||
"go.etcd.io/bbolt"
|
"go.etcd.io/bbolt"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
|
|
@ -2,12 +2,13 @@ package writecache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||||
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||||
"go.etcd.io/bbolt"
|
"go.etcd.io/bbolt"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Get returns object from write-cache.
|
// Get returns object from write-cache.
|
||||||
func (c *cache) Get(addr *addressSDK.Address) (*object.Object, error) {
|
func (c *cache) Get(addr *addressSDK.Address) (*objectSDK.Object, error) {
|
||||||
saddr := addr.String()
|
saddr := addr.String()
|
||||||
|
|
||||||
c.mtx.RLock()
|
c.mtx.RLock()
|
||||||
|
@ -22,7 +23,7 @@ func (c *cache) Get(addr *addressSDK.Address) (*object.Object, error) {
|
||||||
|
|
||||||
value, err := Get(c.db, []byte(saddr))
|
value, err := Get(c.db, []byte(saddr))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
obj := object.New()
|
obj := objectSDK.New()
|
||||||
c.flushed.Get(saddr)
|
c.flushed.Get(saddr)
|
||||||
return obj, obj.Unmarshal(value)
|
return obj, obj.Unmarshal(value)
|
||||||
}
|
}
|
||||||
|
@ -32,7 +33,7 @@ func (c *cache) Get(addr *addressSDK.Address) (*object.Object, error) {
|
||||||
return nil, object.ErrNotFound
|
return nil, object.ErrNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
obj := object.New()
|
obj := objectSDK.New()
|
||||||
if err := obj.Unmarshal(data); err != nil {
|
if err := obj.Unmarshal(data); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -42,7 +43,7 @@ func (c *cache) Get(addr *addressSDK.Address) (*object.Object, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Head returns object header from write-cache.
|
// Head returns object header from write-cache.
|
||||||
func (c *cache) Head(addr *addressSDK.Address) (*object.Object, error) {
|
func (c *cache) Head(addr *addressSDK.Address) (*objectSDK.Object, error) {
|
||||||
// TODO: #1149 easiest to implement solution is presented here, consider more efficient way, e.g.:
|
// TODO: #1149 easiest to implement solution is presented here, consider more efficient way, e.g.:
|
||||||
// - provide header as common object.Object to Put, but marked to prevent correlation with full object
|
// - provide header as common object.Object to Put, but marked to prevent correlation with full object
|
||||||
// (all write-cache logic will automatically spread to headers, except flushing)
|
// (all write-cache logic will automatically spread to headers, except flushing)
|
||||||
|
@ -55,7 +56,7 @@ func (c *cache) Head(addr *addressSDK.Address) (*object.Object, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: resetting the payload via the setter can lead to data corruption of in-memory objects, but ok for others
|
// NOTE: resetting the payload via the setter can lead to data corruption of in-memory objects, but ok for others
|
||||||
return object.NewRawFromObject(obj).CutPayload().Object(), nil
|
return obj.CutPayload(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get fetches object from the underlying database.
|
// Get fetches object from the underlying database.
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||||
storagelog "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/internal/log"
|
storagelog "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/internal/log"
|
||||||
"go.etcd.io/bbolt"
|
"go.etcd.io/bbolt"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
@ -112,7 +113,7 @@ func (c *cache) persistBigObject(objInfo objectInfo) {
|
||||||
cacheSz := c.estimateCacheSize()
|
cacheSz := c.estimateCacheSize()
|
||||||
metaIndex := 0
|
metaIndex := 0
|
||||||
if c.incSizeFS(cacheSz) <= c.maxCacheSize {
|
if c.incSizeFS(cacheSz) <= c.maxCacheSize {
|
||||||
err := c.fsTree.Put(objInfo.obj.Address(), objInfo.data)
|
err := c.fsTree.Put(object.AddressOf(objInfo.obj), objInfo.data)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
metaIndex = 1
|
metaIndex = 1
|
||||||
if c.blobstor.NeedsCompression(objInfo.obj) {
|
if c.blobstor.NeedsCompression(objInfo.obj) {
|
||||||
|
|
|
@ -5,13 +5,14 @@ import (
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||||
storagelog "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/internal/log"
|
storagelog "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/internal/log"
|
||||||
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ErrBigObject is returned when object is too big to be placed in cache.
|
// ErrBigObject is returned when object is too big to be placed in cache.
|
||||||
var ErrBigObject = errors.New("too big object")
|
var ErrBigObject = errors.New("too big object")
|
||||||
|
|
||||||
// Put puts object to write-cache.
|
// Put puts object to write-cache.
|
||||||
func (c *cache) Put(o *object.Object) error {
|
func (c *cache) Put(o *objectSDK.Object) error {
|
||||||
c.modeMtx.RLock()
|
c.modeMtx.RLock()
|
||||||
defer c.modeMtx.RUnlock()
|
defer c.modeMtx.RUnlock()
|
||||||
if c.mode == ModeReadOnly {
|
if c.mode == ModeReadOnly {
|
||||||
|
@ -29,7 +30,7 @@ func (c *cache) Put(o *object.Object) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
oi := objectInfo{
|
oi := objectInfo{
|
||||||
addr: o.Address().String(),
|
addr: object.AddressOf(o).String(),
|
||||||
obj: o,
|
obj: o,
|
||||||
data: data,
|
data: data,
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,8 @@ package writecache
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree"
|
||||||
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
|
@ -9,10 +9,9 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object"
|
objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object"
|
||||||
"github.com/nspcc-dev/neofs-api-go/v2/session"
|
"github.com/nspcc-dev/neofs-api-go/v2/session"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
||||||
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
||||||
eaclSDK "github.com/nspcc-dev/neofs-sdk-go/eacl"
|
eaclSDK "github.com/nspcc-dev/neofs-sdk-go/eacl"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
objectSDKAddress "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
objectSDKAddress "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||||
objectSDKID "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
objectSDKID "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -86,11 +85,11 @@ func TestHeadRequest(t *testing.T) {
|
||||||
|
|
||||||
meta.SetXHeaders(xHdrs)
|
meta.SetXHeaders(xHdrs)
|
||||||
|
|
||||||
obj := object.NewRaw()
|
obj := object.New()
|
||||||
|
|
||||||
attrKey := "attr_key"
|
attrKey := "attr_key"
|
||||||
attrVal := "attr_val"
|
attrVal := "attr_val"
|
||||||
attr := objectSDK.NewAttribute()
|
attr := object.NewAttribute()
|
||||||
attr.SetKey(attrKey)
|
attr.SetKey(attrKey)
|
||||||
attr.SetValue(attrVal)
|
attr.SetValue(attrVal)
|
||||||
obj.SetAttributes(attr)
|
obj.SetAttributes(attr)
|
||||||
|
@ -113,7 +112,7 @@ func TestHeadRequest(t *testing.T) {
|
||||||
lStorage := &testLocalStorage{
|
lStorage := &testLocalStorage{
|
||||||
t: t,
|
t: t,
|
||||||
expAddr: addr,
|
expAddr: addr,
|
||||||
obj: obj.Object(),
|
obj: obj,
|
||||||
}
|
}
|
||||||
|
|
||||||
cid := addr.ContainerID()
|
cid := addr.ContainerID()
|
||||||
|
|
|
@ -7,9 +7,9 @@ import (
|
||||||
objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object"
|
objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object"
|
||||||
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
||||||
"github.com/nspcc-dev/neofs-api-go/v2/session"
|
"github.com/nspcc-dev/neofs-api-go/v2/session"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
||||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||||
eaclSDK "github.com/nspcc-dev/neofs-sdk-go/eacl"
|
eaclSDK "github.com/nspcc-dev/neofs-sdk-go/eacl"
|
||||||
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
objectSDKAddress "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
objectSDKAddress "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||||
objectSDKID "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
objectSDKID "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||||
sessionSDK "github.com/nspcc-dev/neofs-sdk-go/session"
|
sessionSDK "github.com/nspcc-dev/neofs-sdk-go/session"
|
||||||
|
|
|
@ -3,8 +3,8 @@ package v2
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine"
|
||||||
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
objectSDKAddress "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
objectSDKAddress "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,9 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-api-go/v2/acl"
|
"github.com/nspcc-dev/neofs-api-go/v2/acl"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
||||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||||
eaclSDK "github.com/nspcc-dev/neofs-sdk-go/eacl"
|
eaclSDK "github.com/nspcc-dev/neofs-sdk-go/eacl"
|
||||||
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
objectSDKAddress "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
objectSDKAddress "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||||
objectSDKID "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
objectSDKID "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
||||||
|
@ -42,12 +42,12 @@ func u64Value(v uint64) string {
|
||||||
|
|
||||||
func headersFromObject(obj *object.Object, addr *objectSDKAddress.Address) []eaclSDK.Header {
|
func headersFromObject(obj *object.Object, addr *objectSDKAddress.Address) []eaclSDK.Header {
|
||||||
var count int
|
var count int
|
||||||
for obj := obj; obj != nil; obj = obj.GetParent() {
|
for obj := obj; obj != nil; obj = obj.Parent() {
|
||||||
count += 9 + len(obj.Attributes())
|
count += 9 + len(obj.Attributes())
|
||||||
}
|
}
|
||||||
|
|
||||||
res := make([]eaclSDK.Header, 0, count)
|
res := make([]eaclSDK.Header, 0, count)
|
||||||
for ; obj != nil; obj = obj.GetParent() {
|
for ; obj != nil; obj = obj.Parent() {
|
||||||
res = append(res,
|
res = append(res,
|
||||||
cidHeader(addr.ContainerID()),
|
cidHeader(addr.ContainerID()),
|
||||||
// owner ID
|
// owner ID
|
||||||
|
|
|
@ -5,11 +5,10 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object"
|
objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
||||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||||
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
@ -31,11 +30,11 @@ type execCtx struct {
|
||||||
|
|
||||||
log *logger.Logger
|
log *logger.Logger
|
||||||
|
|
||||||
tombstone *objectSDK.Tombstone
|
tombstone *object.Tombstone
|
||||||
|
|
||||||
splitInfo *objectSDK.SplitInfo
|
splitInfo *object.SplitInfo
|
||||||
|
|
||||||
tombstoneObj *object.RawObject
|
tombstoneObj *object.Object
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -240,13 +239,13 @@ func (exec *execCtx) initTombstoneObject() bool {
|
||||||
tombOwnerID = exec.svc.netInfo.LocalNodeID()
|
tombOwnerID = exec.svc.netInfo.LocalNodeID()
|
||||||
}
|
}
|
||||||
|
|
||||||
exec.tombstoneObj = object.NewRaw()
|
exec.tombstoneObj = object.New()
|
||||||
exec.tombstoneObj.SetContainerID(exec.containerID())
|
exec.tombstoneObj.SetContainerID(exec.containerID())
|
||||||
exec.tombstoneObj.SetOwnerID(tombOwnerID)
|
exec.tombstoneObj.SetOwnerID(tombOwnerID)
|
||||||
exec.tombstoneObj.SetType(objectSDK.TypeTombstone)
|
exec.tombstoneObj.SetType(object.TypeTombstone)
|
||||||
exec.tombstoneObj.SetPayload(payload)
|
exec.tombstoneObj.SetPayload(payload)
|
||||||
|
|
||||||
a := objectSDK.NewAttribute()
|
a := object.NewAttribute()
|
||||||
a.SetKey(objectV2.SysAttributeExpEpoch)
|
a.SetKey(objectV2.SysAttributeExpEpoch)
|
||||||
a.SetValue(strconv.FormatUint(exec.tombstone.ExpirationEpoch(), 10))
|
a.SetValue(strconv.FormatUint(exec.tombstone.ExpirationEpoch(), 10))
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package deletesvc
|
package deletesvc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
@ -39,7 +39,7 @@ func (exec *execCtx) formTombstone() (ok bool) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
exec.tombstone = objectSDK.NewTombstone()
|
exec.tombstone = object.NewTombstone()
|
||||||
exec.tombstone.SetExpirationEpoch(
|
exec.tombstone.SetExpirationEpoch(
|
||||||
exec.svc.netInfo.CurrentEpoch() + tsLifetime,
|
exec.svc.netInfo.CurrentEpoch() + tsLifetime,
|
||||||
)
|
)
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
putsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/put"
|
putsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/put"
|
||||||
searchsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/search"
|
searchsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/search"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
@ -38,7 +38,7 @@ type cfg struct {
|
||||||
|
|
||||||
header interface {
|
header interface {
|
||||||
// must return (nil, nil) for PHY objects
|
// must return (nil, nil) for PHY objects
|
||||||
splitInfo(*execCtx) (*objectSDK.SplitInfo, error)
|
splitInfo(*execCtx) (*object.SplitInfo, error)
|
||||||
|
|
||||||
children(*execCtx) ([]*oidSDK.ID, error)
|
children(*execCtx) ([]*oidSDK.ID, error)
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,11 @@ package deletesvc
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
||||||
getsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/get"
|
getsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/get"
|
||||||
putsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/put"
|
putsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/put"
|
||||||
searchsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/search"
|
searchsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/search"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement"
|
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||||
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||||
)
|
)
|
||||||
|
@ -40,10 +39,10 @@ func (w *headSvcWrapper) headAddress(exec *execCtx, addr *addressSDK.Address) (*
|
||||||
return wr.Object(), nil
|
return wr.Object(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *headSvcWrapper) splitInfo(exec *execCtx) (*objectSDK.SplitInfo, error) {
|
func (w *headSvcWrapper) splitInfo(exec *execCtx) (*object.SplitInfo, error) {
|
||||||
_, err := w.headAddress(exec, exec.address())
|
_, err := w.headAddress(exec, exec.address())
|
||||||
|
|
||||||
var errSplitInfo *objectSDK.SplitInfoError
|
var errSplitInfo *object.SplitInfoError
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case err == nil:
|
case err == nil:
|
||||||
|
@ -78,8 +77,8 @@ func (w *headSvcWrapper) previous(exec *execCtx, id *oidSDK.ID) (*oidSDK.ID, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *searchSvcWrapper) splitMembers(exec *execCtx) ([]*oidSDK.ID, error) {
|
func (w *searchSvcWrapper) splitMembers(exec *execCtx) ([]*oidSDK.ID, error) {
|
||||||
fs := objectSDK.SearchFilters{}
|
fs := object.SearchFilters{}
|
||||||
fs.AddSplitIDFilter(objectSDK.MatchStringEqual, exec.splitInfo.SplitID())
|
fs.AddSplitIDFilter(object.MatchStringEqual, exec.splitInfo.SplitID())
|
||||||
|
|
||||||
wr := new(simpleIDWriter)
|
wr := new(simpleIDWriter)
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ func (exec *execCtx) initFromChild(id *oidSDK.ID) (prev *oidSDK.ID, children []*
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
par := child.GetParent()
|
par := child.Parent()
|
||||||
if par == nil {
|
if par == nil {
|
||||||
exec.status = statusUndefined
|
exec.status = statusUndefined
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ func (exec *execCtx) initFromChild(id *oidSDK.ID) (prev *oidSDK.ID, children []*
|
||||||
payload = child.Payload()
|
payload = child.Payload()
|
||||||
}
|
}
|
||||||
|
|
||||||
object.NewRawFromObject(exec.collectedObject).SetPayload(payload)
|
exec.collectedObject.SetPayload(payload)
|
||||||
|
|
||||||
return child.PreviousID(), child.Children()
|
return child.PreviousID(), child.Children()
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ type execCtx struct {
|
||||||
|
|
||||||
log *logger.Logger
|
log *logger.Logger
|
||||||
|
|
||||||
collectedObject *object.Object
|
collectedObject *objectSDK.Object
|
||||||
|
|
||||||
curOff uint64
|
curOff uint64
|
||||||
|
|
||||||
|
@ -99,9 +99,9 @@ func (exec execCtx) address() *addressSDK.Address {
|
||||||
return exec.prm.addr
|
return exec.prm.addr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (exec execCtx) isChild(obj *object.Object) bool {
|
func (exec execCtx) isChild(obj *objectSDK.Object) bool {
|
||||||
par := obj.GetParent()
|
par := obj.Parent()
|
||||||
return par != nil && equalAddresses(exec.address(), par.Address())
|
return par != nil && equalAddresses(exec.address(), object.AddressOf(par))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (exec execCtx) key() (*ecdsa.PrivateKey, error) {
|
func (exec execCtx) key() (*ecdsa.PrivateKey, error) {
|
||||||
|
@ -178,7 +178,7 @@ func (exec *execCtx) generateTraverser(addr *addressSDK.Address) (*placement.Tra
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (exec *execCtx) getChild(id *oidSDK.ID, rng *objectSDK.Range, withHdr bool) (*object.Object, bool) {
|
func (exec *execCtx) getChild(id *oidSDK.ID, rng *objectSDK.Range, withHdr bool) (*objectSDK.Object, bool) {
|
||||||
w := NewSimpleObjectWriter()
|
w := NewSimpleObjectWriter()
|
||||||
|
|
||||||
p := exec.prm
|
p := exec.prm
|
||||||
|
@ -207,7 +207,7 @@ func (exec *execCtx) getChild(id *oidSDK.ID, rng *objectSDK.Range, withHdr bool)
|
||||||
return child, ok
|
return child, ok
|
||||||
}
|
}
|
||||||
|
|
||||||
func (exec *execCtx) headChild(id *oidSDK.ID) (*object.Object, bool) {
|
func (exec *execCtx) headChild(id *oidSDK.ID) (*objectSDK.Object, bool) {
|
||||||
childAddr := addressSDK.NewAddress()
|
childAddr := addressSDK.NewAddress()
|
||||||
childAddr.SetContainerID(exec.containerID())
|
childAddr.SetContainerID(exec.containerID())
|
||||||
childAddr.SetObjectID(id)
|
childAddr.SetObjectID(id)
|
||||||
|
@ -288,7 +288,7 @@ func (exec *execCtx) writeCollectedHeader() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
err := exec.prm.objWriter.WriteHeader(
|
err := exec.prm.objWriter.WriteHeader(
|
||||||
object.NewRawFromObject(exec.collectedObject).CutPayload().Object(),
|
exec.collectedObject.CutPayload(),
|
||||||
)
|
)
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
|
@ -307,7 +307,7 @@ func (exec *execCtx) writeCollectedHeader() bool {
|
||||||
return exec.status == statusOK
|
return exec.status == statusOK
|
||||||
}
|
}
|
||||||
|
|
||||||
func (exec *execCtx) writeObjectPayload(obj *object.Object) bool {
|
func (exec *execCtx) writeObjectPayload(obj *objectSDK.Object) bool {
|
||||||
if exec.headOnly() {
|
if exec.headOnly() {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/util"
|
"github.com/nspcc-dev/neofs-node/pkg/util"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ func (s *Service) get(ctx context.Context, prm commonPrm, opts ...execOption) st
|
||||||
prm: RangePrm{
|
prm: RangePrm{
|
||||||
commonPrm: prm,
|
commonPrm: prm,
|
||||||
},
|
},
|
||||||
infoSplit: objectSDK.NewSplitInfo(),
|
infoSplit: object.NewSplitInfo(),
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range opts {
|
for i := range opts {
|
||||||
|
|
|
@ -30,7 +30,7 @@ type testStorage struct {
|
||||||
|
|
||||||
virtual map[string]*objectSDK.SplitInfo
|
virtual map[string]*objectSDK.SplitInfo
|
||||||
|
|
||||||
phy map[string]*object.Object
|
phy map[string]*objectSDK.Object
|
||||||
}
|
}
|
||||||
|
|
||||||
type testTraverserGenerator struct {
|
type testTraverserGenerator struct {
|
||||||
|
@ -48,7 +48,7 @@ type testClientCache struct {
|
||||||
|
|
||||||
type testClient struct {
|
type testClient struct {
|
||||||
results map[string]struct {
|
results map[string]struct {
|
||||||
obj *object.RawObject
|
obj *objectSDK.Object
|
||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ func newTestStorage() *testStorage {
|
||||||
return &testStorage{
|
return &testStorage{
|
||||||
inhumed: make(map[string]struct{}),
|
inhumed: make(map[string]struct{}),
|
||||||
virtual: make(map[string]*objectSDK.SplitInfo),
|
virtual: make(map[string]*objectSDK.SplitInfo),
|
||||||
phy: make(map[string]*object.Object),
|
phy: make(map[string]*objectSDK.Object),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ func (c *testClientCache) get(info client.NodeInfo) (getClient, error) {
|
||||||
func newTestClient() *testClient {
|
func newTestClient() *testClient {
|
||||||
return &testClient{
|
return &testClient{
|
||||||
results: map[string]struct {
|
results: map[string]struct {
|
||||||
obj *object.RawObject
|
obj *objectSDK.Object
|
||||||
err error
|
err error
|
||||||
}{},
|
}{},
|
||||||
}
|
}
|
||||||
|
@ -113,20 +113,20 @@ func (c *testClient) getObject(exec *execCtx, _ client.NodeInfo) (*objectSDK.Obj
|
||||||
return nil, v.err
|
return nil, v.err
|
||||||
}
|
}
|
||||||
|
|
||||||
return cutToRange(v.obj.Object(), exec.ctxRange()).SDK(), nil
|
return cutToRange(v.obj, exec.ctxRange()), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *testClient) addResult(addr *addressSDK.Address, obj *object.RawObject, err error) {
|
func (c *testClient) addResult(addr *addressSDK.Address, obj *objectSDK.Object, err error) {
|
||||||
c.results[addr.String()] = struct {
|
c.results[addr.String()] = struct {
|
||||||
obj *object.RawObject
|
obj *objectSDK.Object
|
||||||
err error
|
err error
|
||||||
}{obj: obj, err: err}
|
}{obj: obj, err: err}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *testStorage) get(exec *execCtx) (*object.Object, error) {
|
func (s *testStorage) get(exec *execCtx) (*objectSDK.Object, error) {
|
||||||
var (
|
var (
|
||||||
ok bool
|
ok bool
|
||||||
obj *object.Object
|
obj *objectSDK.Object
|
||||||
sAddr = exec.address().String()
|
sAddr = exec.address().String()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -145,26 +145,24 @@ func (s *testStorage) get(exec *execCtx) (*object.Object, error) {
|
||||||
return nil, object.ErrNotFound
|
return nil, object.ErrNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
func cutToRange(o *object.Object, rng *objectSDK.Range) *object.Object {
|
func cutToRange(o *objectSDK.Object, rng *objectSDK.Range) *objectSDK.Object {
|
||||||
obj := object.NewRawFromObject(o)
|
|
||||||
|
|
||||||
if rng == nil {
|
if rng == nil {
|
||||||
return obj.Object()
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
from := rng.GetOffset()
|
from := rng.GetOffset()
|
||||||
to := from + rng.GetLength()
|
to := from + rng.GetLength()
|
||||||
|
|
||||||
payload := obj.Payload()
|
payload := o.Payload()
|
||||||
|
|
||||||
obj = obj.CutPayload()
|
o = o.CutPayload()
|
||||||
obj.SetPayload(payload[from:to])
|
o.SetPayload(payload[from:to])
|
||||||
|
|
||||||
return obj.Object()
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *testStorage) addPhy(addr *addressSDK.Address, obj *object.RawObject) {
|
func (s *testStorage) addPhy(addr *addressSDK.Address, obj *objectSDK.Object) {
|
||||||
s.phy[addr.String()] = obj.Object()
|
s.phy[addr.String()] = obj
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *testStorage) addVirtual(addr *addressSDK.Address, info *objectSDK.SplitInfo) {
|
func (s *testStorage) addVirtual(addr *addressSDK.Address, info *objectSDK.SplitInfo) {
|
||||||
|
@ -196,8 +194,8 @@ func generateAddress() *addressSDK.Address {
|
||||||
return addr
|
return addr
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateObject(addr *addressSDK.Address, prev *oidSDK.ID, payload []byte, children ...*oidSDK.ID) *object.RawObject {
|
func generateObject(addr *addressSDK.Address, prev *oidSDK.ID, payload []byte, children ...*oidSDK.ID) *objectSDK.Object {
|
||||||
obj := object.NewRaw()
|
obj := objectSDK.New()
|
||||||
obj.SetContainerID(addr.ContainerID())
|
obj.SetContainerID(addr.ContainerID())
|
||||||
obj.SetID(addr.ObjectID())
|
obj.SetID(addr.ObjectID())
|
||||||
obj.SetPayload(payload)
|
obj.SetPayload(payload)
|
||||||
|
@ -277,7 +275,7 @@ func TestGetLocalOnly(t *testing.T) {
|
||||||
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
require.Equal(t, obj.Object(), w.Object())
|
require.Equal(t, obj, w.Object())
|
||||||
|
|
||||||
w = NewSimpleObjectWriter()
|
w = NewSimpleObjectWriter()
|
||||||
|
|
||||||
|
@ -294,7 +292,7 @@ func TestGetLocalOnly(t *testing.T) {
|
||||||
|
|
||||||
err = svc.Head(ctx, headPrm)
|
err = svc.Head(ctx, headPrm)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, obj.CutPayload().Object(), w.Object())
|
require.Equal(t, obj.CutPayload(), w.Object())
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("INHUMED", func(t *testing.T) {
|
t.Run("INHUMED", func(t *testing.T) {
|
||||||
|
@ -429,14 +427,14 @@ func testNodeMatrix(t testing.TB, dim []int) ([]netmap.Nodes, [][]string) {
|
||||||
return mNodes, mAddr
|
return mNodes, mAddr
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateChain(ln int, cid *cid.ID) ([]*object.RawObject, []*oidSDK.ID, []byte) {
|
func generateChain(ln int, cid *cid.ID) ([]*objectSDK.Object, []*oidSDK.ID, []byte) {
|
||||||
curID := generateID()
|
curID := generateID()
|
||||||
var prevID *oidSDK.ID
|
var prevID *oidSDK.ID
|
||||||
|
|
||||||
addr := addressSDK.NewAddress()
|
addr := addressSDK.NewAddress()
|
||||||
addr.SetContainerID(cid)
|
addr.SetContainerID(cid)
|
||||||
|
|
||||||
res := make([]*object.RawObject, 0, ln)
|
res := make([]*objectSDK.Object, 0, ln)
|
||||||
ids := make([]*oidSDK.ID, 0, ln)
|
ids := make([]*oidSDK.ID, 0, ln)
|
||||||
payload := make([]byte, 0, ln*10)
|
payload := make([]byte, 0, ln*10)
|
||||||
|
|
||||||
|
@ -560,13 +558,13 @@ func TestGetRemoteSmall(t *testing.T) {
|
||||||
|
|
||||||
err := svc.Get(ctx, p)
|
err := svc.Get(ctx, p)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, obj.Object(), w.Object())
|
require.Equal(t, obj, w.Object())
|
||||||
|
|
||||||
*c1, *c2 = *c2, *c1
|
*c1, *c2 = *c2, *c1
|
||||||
|
|
||||||
err = svc.Get(ctx, p)
|
err = svc.Get(ctx, p)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, obj.Object(), w.Object())
|
require.Equal(t, obj, w.Object())
|
||||||
|
|
||||||
w = NewSimpleObjectWriter()
|
w = NewSimpleObjectWriter()
|
||||||
rngPrm := newRngPrm(false, w, payloadSz/3, payloadSz/3)
|
rngPrm := newRngPrm(false, w, payloadSz/3, payloadSz/3)
|
||||||
|
@ -582,7 +580,7 @@ func TestGetRemoteSmall(t *testing.T) {
|
||||||
|
|
||||||
err = svc.Head(ctx, headPrm)
|
err = svc.Head(ctx, headPrm)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, obj.CutPayload().Object(), w.Object())
|
require.Equal(t, obj.CutPayload(), w.Object())
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("INHUMED", func(t *testing.T) {
|
t.Run("INHUMED", func(t *testing.T) {
|
||||||
|
@ -758,7 +756,7 @@ func TestGetRemoteSmall(t *testing.T) {
|
||||||
|
|
||||||
linkingObj := generateObject(linkAddr, nil, nil, childIDs...)
|
linkingObj := generateObject(linkAddr, nil, nil, childIDs...)
|
||||||
linkingObj.SetParentID(addr.ObjectID())
|
linkingObj.SetParentID(addr.ObjectID())
|
||||||
linkingObj.SetParent(srcObj.Object().SDK())
|
linkingObj.SetParent(srcObj)
|
||||||
|
|
||||||
child1Addr := addressSDK.NewAddress()
|
child1Addr := addressSDK.NewAddress()
|
||||||
child1Addr.SetContainerID(cid)
|
child1Addr.SetContainerID(cid)
|
||||||
|
@ -826,7 +824,7 @@ func TestGetRemoteSmall(t *testing.T) {
|
||||||
children, childIDs, payload := generateChain(2, cid)
|
children, childIDs, payload := generateChain(2, cid)
|
||||||
srcObj.SetPayload(payload)
|
srcObj.SetPayload(payload)
|
||||||
srcObj.SetPayloadSize(uint64(len(payload)))
|
srcObj.SetPayloadSize(uint64(len(payload)))
|
||||||
children[len(children)-1].SetParent(srcObj.Object().SDK())
|
children[len(children)-1].SetParent(srcObj)
|
||||||
|
|
||||||
linkAddr := addressSDK.NewAddress()
|
linkAddr := addressSDK.NewAddress()
|
||||||
linkAddr.SetContainerID(cid)
|
linkAddr.SetContainerID(cid)
|
||||||
|
@ -834,7 +832,7 @@ func TestGetRemoteSmall(t *testing.T) {
|
||||||
|
|
||||||
linkingObj := generateObject(linkAddr, nil, nil, childIDs...)
|
linkingObj := generateObject(linkAddr, nil, nil, childIDs...)
|
||||||
linkingObj.SetParentID(addr.ObjectID())
|
linkingObj.SetParentID(addr.ObjectID())
|
||||||
linkingObj.SetParent(srcObj.Object().SDK())
|
linkingObj.SetParent(srcObj)
|
||||||
|
|
||||||
child1Addr := addressSDK.NewAddress()
|
child1Addr := addressSDK.NewAddress()
|
||||||
child1Addr.SetContainerID(cid)
|
child1Addr.SetContainerID(cid)
|
||||||
|
@ -881,7 +879,7 @@ func TestGetRemoteSmall(t *testing.T) {
|
||||||
|
|
||||||
err := svc.Get(ctx, p)
|
err := svc.Get(ctx, p)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, srcObj.Object(), w.Object())
|
require.Equal(t, srcObj, w.Object())
|
||||||
|
|
||||||
w = NewSimpleObjectWriter()
|
w = NewSimpleObjectWriter()
|
||||||
payloadSz := srcObj.PayloadSize()
|
payloadSz := srcObj.PayloadSize()
|
||||||
|
@ -972,9 +970,9 @@ func TestGetRemoteSmall(t *testing.T) {
|
||||||
rightObj := children[len(children)-1]
|
rightObj := children[len(children)-1]
|
||||||
|
|
||||||
rightObj.SetParentID(addr.ObjectID())
|
rightObj.SetParentID(addr.ObjectID())
|
||||||
rightObj.SetParent(srcObj.Object().SDK())
|
rightObj.SetParent(srcObj)
|
||||||
|
|
||||||
preRightAddr := children[len(children)-2].Object().Address()
|
preRightAddr := object.AddressOf(children[len(children)-2])
|
||||||
|
|
||||||
c1 := newTestClient()
|
c1 := newTestClient()
|
||||||
c1.addResult(addr, nil, errors.New("any error"))
|
c1.addResult(addr, nil, errors.New("any error"))
|
||||||
|
@ -1037,20 +1035,20 @@ func TestGetRemoteSmall(t *testing.T) {
|
||||||
|
|
||||||
rightObj.SetID(splitInfo.LastPart())
|
rightObj.SetID(splitInfo.LastPart())
|
||||||
rightObj.SetParentID(addr.ObjectID())
|
rightObj.SetParentID(addr.ObjectID())
|
||||||
rightObj.SetParent(srcObj.Object().SDK())
|
rightObj.SetParent(srcObj)
|
||||||
|
|
||||||
c1 := newTestClient()
|
c1 := newTestClient()
|
||||||
c1.addResult(addr, nil, errors.New("any error"))
|
c1.addResult(addr, nil, errors.New("any error"))
|
||||||
|
|
||||||
for i := range children {
|
for i := range children {
|
||||||
c1.addResult(children[i].Object().Address(), nil, errors.New("any error"))
|
c1.addResult(object.AddressOf(children[i]), nil, errors.New("any error"))
|
||||||
}
|
}
|
||||||
|
|
||||||
c2 := newTestClient()
|
c2 := newTestClient()
|
||||||
c2.addResult(addr, nil, objectSDK.NewSplitInfoError(splitInfo))
|
c2.addResult(addr, nil, objectSDK.NewSplitInfoError(splitInfo))
|
||||||
|
|
||||||
for i := range children {
|
for i := range children {
|
||||||
c2.addResult(children[i].Object().Address(), children[i], nil)
|
c2.addResult(object.AddressOf(children[i]), children[i], nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
builder := &testPlacementBuilder{
|
builder := &testPlacementBuilder{
|
||||||
|
@ -1060,7 +1058,7 @@ func TestGetRemoteSmall(t *testing.T) {
|
||||||
builder.vectors[addr.String()] = ns
|
builder.vectors[addr.String()] = ns
|
||||||
|
|
||||||
for i := range children {
|
for i := range children {
|
||||||
builder.vectors[children[i].Object().Address().String()] = ns
|
builder.vectors[object.AddressOf(children[i]).String()] = ns
|
||||||
}
|
}
|
||||||
|
|
||||||
svc := newSvc(builder, &testClientCache{
|
svc := newSvc(builder, &testClientCache{
|
||||||
|
@ -1079,7 +1077,7 @@ func TestGetRemoteSmall(t *testing.T) {
|
||||||
|
|
||||||
err := svc.Get(ctx, p)
|
err := svc.Get(ctx, p)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, srcObj.Object(), w.Object())
|
require.Equal(t, srcObj, w.Object())
|
||||||
|
|
||||||
w = NewSimpleObjectWriter()
|
w = NewSimpleObjectWriter()
|
||||||
payloadSz := srcObj.PayloadSize()
|
payloadSz := srcObj.PayloadSize()
|
||||||
|
@ -1188,7 +1186,7 @@ func TestGetFromPastEpoch(t *testing.T) {
|
||||||
|
|
||||||
err = svc.Get(ctx, p)
|
err = svc.Get(ctx, p)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, obj.Object(), w.Object())
|
require.Equal(t, obj, w.Object())
|
||||||
|
|
||||||
rp := RangePrm{}
|
rp := RangePrm{}
|
||||||
rp.SetChunkWriter(w)
|
rp.SetChunkWriter(w)
|
||||||
|
@ -1230,5 +1228,5 @@ func TestGetFromPastEpoch(t *testing.T) {
|
||||||
|
|
||||||
err = svc.Head(ctx, hp)
|
err = svc.Head(ctx, hp)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, obj.CutPayload().Object(), w.Object())
|
require.Equal(t, obj.CutPayload(), w.Object())
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,8 @@ import (
|
||||||
"hash"
|
"hash"
|
||||||
|
|
||||||
coreclient "github.com/nspcc-dev/neofs-node/pkg/core/client"
|
coreclient "github.com/nspcc-dev/neofs-node/pkg/core/client"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -19,7 +18,7 @@ type Prm struct {
|
||||||
type RangePrm struct {
|
type RangePrm struct {
|
||||||
commonPrm
|
commonPrm
|
||||||
|
|
||||||
rng *objectSDK.Range
|
rng *object.Range
|
||||||
}
|
}
|
||||||
|
|
||||||
// RangeHashPrm groups parameters of GetRange service call.
|
// RangeHashPrm groups parameters of GetRange service call.
|
||||||
|
@ -28,12 +27,12 @@ type RangeHashPrm struct {
|
||||||
|
|
||||||
hashGen func() hash.Hash
|
hashGen func() hash.Hash
|
||||||
|
|
||||||
rngs []*objectSDK.Range
|
rngs []*object.Range
|
||||||
|
|
||||||
salt []byte
|
salt []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
type RequestForwarder func(coreclient.NodeInfo, coreclient.MultiAddressClient) (*objectSDK.Object, error)
|
type RequestForwarder func(coreclient.NodeInfo, coreclient.MultiAddressClient) (*object.Object, error)
|
||||||
|
|
||||||
// HeadPrm groups parameters of Head service call.
|
// HeadPrm groups parameters of Head service call.
|
||||||
type HeadPrm struct {
|
type HeadPrm struct {
|
||||||
|
@ -83,12 +82,12 @@ func (p *RangePrm) SetChunkWriter(w ChunkWriter) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetRange sets range of the requested payload data.
|
// SetRange sets range of the requested payload data.
|
||||||
func (p *RangePrm) SetRange(rng *objectSDK.Range) {
|
func (p *RangePrm) SetRange(rng *object.Range) {
|
||||||
p.rng = rng
|
p.rng = rng
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetRangeList sets list of object payload ranges.
|
// SetRangeList sets list of object payload ranges.
|
||||||
func (p *RangeHashPrm) SetRangeList(rngs []*objectSDK.Range) {
|
func (p *RangeHashPrm) SetRangeList(rngs []*object.Range) {
|
||||||
p.rngs = rngs
|
p.rngs = rngs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ func (exec *execCtx) processNode(ctx context.Context, info client.NodeInfo) bool
|
||||||
case err == nil:
|
case err == nil:
|
||||||
exec.status = statusOK
|
exec.status = statusOK
|
||||||
exec.err = nil
|
exec.err = nil
|
||||||
exec.collectedObject = object.NewFromSDK(obj)
|
exec.collectedObject = obj
|
||||||
exec.writeCollectedObject()
|
exec.writeCollectedObject()
|
||||||
case errors.Is(err, object.ErrAlreadyRemoved):
|
case errors.Is(err, object.ErrAlreadyRemoved):
|
||||||
exec.status = statusINHUMED
|
exec.status = statusINHUMED
|
||||||
|
|
|
@ -5,12 +5,11 @@ import (
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/client"
|
"github.com/nspcc-dev/neofs-node/pkg/core/client"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement"
|
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/session"
|
"github.com/nspcc-dev/neofs-sdk-go/session"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
@ -25,7 +24,7 @@ type Service struct {
|
||||||
type Option func(*cfg)
|
type Option func(*cfg)
|
||||||
|
|
||||||
type getClient interface {
|
type getClient interface {
|
||||||
getObject(*execCtx, client.NodeInfo) (*objectSDK.Object, error)
|
getObject(*execCtx, client.NodeInfo) (*object.Object, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type cfg struct {
|
type cfg struct {
|
||||||
|
|
|
@ -5,15 +5,14 @@ import (
|
||||||
|
|
||||||
coreclient "github.com/nspcc-dev/neofs-node/pkg/core/client"
|
coreclient "github.com/nspcc-dev/neofs-node/pkg/core/client"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine"
|
||||||
internal "github.com/nspcc-dev/neofs-node/pkg/services/object/internal/client"
|
internal "github.com/nspcc-dev/neofs-node/pkg/services/object/internal/client"
|
||||||
internalclient "github.com/nspcc-dev/neofs-node/pkg/services/object/internal/client"
|
internalclient "github.com/nspcc-dev/neofs-node/pkg/services/object/internal/client"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SimpleObjectWriter struct {
|
type SimpleObjectWriter struct {
|
||||||
obj *object.RawObject
|
obj *object.Object
|
||||||
|
|
||||||
pld []byte
|
pld []byte
|
||||||
}
|
}
|
||||||
|
@ -48,12 +47,12 @@ type nmSrcWrapper struct {
|
||||||
|
|
||||||
func NewSimpleObjectWriter() *SimpleObjectWriter {
|
func NewSimpleObjectWriter() *SimpleObjectWriter {
|
||||||
return &SimpleObjectWriter{
|
return &SimpleObjectWriter{
|
||||||
obj: object.NewRaw(),
|
obj: object.New(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SimpleObjectWriter) WriteHeader(obj *object.Object) error {
|
func (s *SimpleObjectWriter) WriteHeader(obj *object.Object) error {
|
||||||
s.obj = object.NewRawFromObject(obj)
|
s.obj = obj
|
||||||
|
|
||||||
s.pld = make([]byte, 0, obj.PayloadSize())
|
s.pld = make([]byte, 0, obj.PayloadSize())
|
||||||
|
|
||||||
|
@ -70,7 +69,7 @@ func (s *SimpleObjectWriter) Object() *object.Object {
|
||||||
s.obj.SetPayload(s.pld)
|
s.obj.SetPayload(s.pld)
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.obj.Object()
|
return s.obj
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *clientCacheWrapper) get(info coreclient.NodeInfo) (getClient, error) {
|
func (c *clientCacheWrapper) get(info coreclient.NodeInfo) (getClient, error) {
|
||||||
|
@ -84,7 +83,7 @@ func (c *clientCacheWrapper) get(info coreclient.NodeInfo) (getClient, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *clientWrapper) getObject(exec *execCtx, info coreclient.NodeInfo) (*objectSDK.Object, error) {
|
func (c *clientWrapper) getObject(exec *execCtx, info coreclient.NodeInfo) (*object.Object, error) {
|
||||||
if exec.isForwardingEnabled() {
|
if exec.isForwardingEnabled() {
|
||||||
return exec.prm.forwarder(info, c.client)
|
return exec.prm.forwarder(info, c.client)
|
||||||
}
|
}
|
||||||
|
@ -211,11 +210,11 @@ func (w *partWriter) WriteHeader(o *object.Object) error {
|
||||||
return w.headWriter.WriteHeader(o)
|
return w.headWriter.WriteHeader(o)
|
||||||
}
|
}
|
||||||
|
|
||||||
func payloadOnlyObject(payload []byte) *objectSDK.Object {
|
func payloadOnlyObject(payload []byte) *object.Object {
|
||||||
rawObj := object.NewRaw()
|
obj := object.New()
|
||||||
rawObj.SetPayload(payload)
|
obj.SetPayload(payload)
|
||||||
|
|
||||||
return rawObj.Object().SDK()
|
return obj
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *hasherWrapper) WriteChunk(p []byte) error {
|
func (h *hasherWrapper) WriteChunk(p []byte) error {
|
||||||
|
|
|
@ -2,8 +2,8 @@ package getsvc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object"
|
objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
||||||
objectSvc "github.com/nspcc-dev/neofs-node/pkg/services/object"
|
objectSvc "github.com/nspcc-dev/neofs-node/pkg/services/object"
|
||||||
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
)
|
)
|
||||||
|
|
||||||
type streamObjectWriter struct {
|
type streamObjectWriter struct {
|
||||||
|
|
|
@ -16,13 +16,12 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-api-go/v2/session"
|
"github.com/nspcc-dev/neofs-api-go/v2/session"
|
||||||
"github.com/nspcc-dev/neofs-api-go/v2/signature"
|
"github.com/nspcc-dev/neofs-api-go/v2/signature"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/client"
|
"github.com/nspcc-dev/neofs-node/pkg/core/client"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/network"
|
"github.com/nspcc-dev/neofs-node/pkg/network"
|
||||||
objectSvc "github.com/nspcc-dev/neofs-node/pkg/services/object"
|
objectSvc "github.com/nspcc-dev/neofs-node/pkg/services/object"
|
||||||
getsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/get"
|
getsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/get"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/object/internal"
|
"github.com/nspcc-dev/neofs-node/pkg/services/object/internal"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||||
signature2 "github.com/nspcc-dev/neofs-sdk-go/util/signature"
|
signature2 "github.com/nspcc-dev/neofs-sdk-go/util/signature"
|
||||||
"github.com/nspcc-dev/tzhash/tz"
|
"github.com/nspcc-dev/tzhash/tz"
|
||||||
|
@ -49,7 +48,7 @@ func (s *Service) toPrm(req *objectV2.GetRequest, stream objectSvc.GetObjectStre
|
||||||
if !commonPrm.LocalOnly() {
|
if !commonPrm.LocalOnly() {
|
||||||
var onceResign sync.Once
|
var onceResign sync.Once
|
||||||
|
|
||||||
p.SetRequestForwarder(groupAddressRequestForwarder(func(addr network.Address, c client.MultiAddressClient, pubkey []byte) (*objectSDK.Object, error) {
|
p.SetRequestForwarder(groupAddressRequestForwarder(func(addr network.Address, c client.MultiAddressClient, pubkey []byte) (*object.Object, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
key, err := s.keyStorage.GetKey(nil)
|
key, err := s.keyStorage.GetKey(nil)
|
||||||
|
@ -139,15 +138,15 @@ func (s *Service) toPrm(req *objectV2.GetRequest, stream objectSvc.GetObjectStre
|
||||||
|
|
||||||
payload = append(payload, v.GetChunk()...)
|
payload = append(payload, v.GetChunk()...)
|
||||||
case *objectV2.SplitInfo:
|
case *objectV2.SplitInfo:
|
||||||
si := objectSDK.NewSplitInfoFromV2(v)
|
si := object.NewSplitInfoFromV2(v)
|
||||||
return nil, objectSDK.NewSplitInfoError(si)
|
return nil, object.NewSplitInfoError(si)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
obj.SetPayload(payload)
|
obj.SetPayload(payload)
|
||||||
|
|
||||||
// convert the object
|
// convert the object
|
||||||
return objectSDK.NewFromV2(obj), nil
|
return object.NewFromV2(obj), nil
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,7 +168,7 @@ func (s *Service) toRangePrm(req *objectV2.GetRangeRequest, stream objectSvc.Get
|
||||||
p.WithAddress(addressSDK.NewAddressFromV2(body.GetAddress()))
|
p.WithAddress(addressSDK.NewAddressFromV2(body.GetAddress()))
|
||||||
p.WithRawFlag(body.GetRaw())
|
p.WithRawFlag(body.GetRaw())
|
||||||
p.SetChunkWriter(&streamObjectRangeWriter{stream})
|
p.SetChunkWriter(&streamObjectRangeWriter{stream})
|
||||||
p.SetRange(objectSDK.NewRangeFromV2(body.GetRange()))
|
p.SetRange(object.NewRangeFromV2(body.GetRange()))
|
||||||
|
|
||||||
if !commonPrm.LocalOnly() {
|
if !commonPrm.LocalOnly() {
|
||||||
var onceResign sync.Once
|
var onceResign sync.Once
|
||||||
|
@ -179,7 +178,7 @@ func (s *Service) toRangePrm(req *objectV2.GetRangeRequest, stream objectSvc.Get
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
p.SetRequestForwarder(groupAddressRequestForwarder(func(addr network.Address, c client.MultiAddressClient, pubkey []byte) (*objectSDK.Object, error) {
|
p.SetRequestForwarder(groupAddressRequestForwarder(func(addr network.Address, c client.MultiAddressClient, pubkey []byte) (*object.Object, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
// once compose and resign forwarding request
|
// once compose and resign forwarding request
|
||||||
|
@ -239,16 +238,16 @@ func (s *Service) toRangePrm(req *objectV2.GetRangeRequest, stream objectSvc.Get
|
||||||
case *objectV2.GetRangePartChunk:
|
case *objectV2.GetRangePartChunk:
|
||||||
payload = append(payload, v.GetChunk()...)
|
payload = append(payload, v.GetChunk()...)
|
||||||
case *objectV2.SplitInfo:
|
case *objectV2.SplitInfo:
|
||||||
si := objectSDK.NewSplitInfoFromV2(v)
|
si := object.NewSplitInfoFromV2(v)
|
||||||
|
|
||||||
return nil, objectSDK.NewSplitInfoError(si)
|
return nil, object.NewSplitInfoError(si)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
obj := objectSDK.NewRaw()
|
obj := object.New()
|
||||||
obj.SetPayload(payload)
|
obj.SetPayload(payload)
|
||||||
|
|
||||||
return obj.Object(), nil
|
return obj, nil
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,10 +267,10 @@ func (s *Service) toHashRangePrm(req *objectV2.GetRangeHashRequest) (*getsvc.Ran
|
||||||
p.WithAddress(addressSDK.NewAddressFromV2(body.GetAddress()))
|
p.WithAddress(addressSDK.NewAddressFromV2(body.GetAddress()))
|
||||||
|
|
||||||
rngsV2 := body.GetRanges()
|
rngsV2 := body.GetRanges()
|
||||||
rngs := make([]*objectSDK.Range, 0, len(rngsV2))
|
rngs := make([]*object.Range, 0, len(rngsV2))
|
||||||
|
|
||||||
for i := range rngsV2 {
|
for i := range rngsV2 {
|
||||||
rngs = append(rngs, objectSDK.NewRangeFromV2(rngsV2[i]))
|
rngs = append(rngs, object.NewRangeFromV2(rngsV2[i]))
|
||||||
}
|
}
|
||||||
|
|
||||||
p.SetRangeList(rngs)
|
p.SetRangeList(rngs)
|
||||||
|
@ -334,7 +333,7 @@ func (s *Service) toHeadPrm(ctx context.Context, req *objectV2.HeadRequest, resp
|
||||||
if !commonPrm.LocalOnly() {
|
if !commonPrm.LocalOnly() {
|
||||||
var onceResign sync.Once
|
var onceResign sync.Once
|
||||||
|
|
||||||
p.SetRequestForwarder(groupAddressRequestForwarder(func(addr network.Address, c client.MultiAddressClient, pubkey []byte) (*objectSDK.Object, error) {
|
p.SetRequestForwarder(groupAddressRequestForwarder(func(addr network.Address, c client.MultiAddressClient, pubkey []byte) (*object.Object, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
key, err := s.keyStorage.GetKey(nil)
|
key, err := s.keyStorage.GetKey(nil)
|
||||||
|
@ -429,27 +428,27 @@ func (s *Service) toHeadPrm(ctx context.Context, req *objectV2.HeadRequest, resp
|
||||||
return nil, fmt.Errorf("incorrect object header signature: %w", err)
|
return nil, fmt.Errorf("incorrect object header signature: %w", err)
|
||||||
}
|
}
|
||||||
case *objectV2.SplitInfo:
|
case *objectV2.SplitInfo:
|
||||||
si := objectSDK.NewSplitInfoFromV2(v)
|
si := object.NewSplitInfoFromV2(v)
|
||||||
|
|
||||||
return nil, objectSDK.NewSplitInfoError(si)
|
return nil, object.NewSplitInfoError(si)
|
||||||
}
|
}
|
||||||
|
|
||||||
obj := new(objectV2.Object)
|
objv2 := new(objectV2.Object)
|
||||||
obj.SetHeader(hdr)
|
objv2.SetHeader(hdr)
|
||||||
obj.SetSignature(idSig)
|
objv2.SetSignature(idSig)
|
||||||
|
|
||||||
raw := object.NewRawFromV2(obj)
|
obj := object.NewFromV2(objv2)
|
||||||
raw.SetID(objAddr.ObjectID())
|
obj.SetID(objAddr.ObjectID())
|
||||||
|
|
||||||
// convert the object
|
// convert the object
|
||||||
return raw.Object().SDK(), nil
|
return obj, nil
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func splitInfoResponse(info *objectSDK.SplitInfo) *objectV2.GetResponse {
|
func splitInfoResponse(info *object.SplitInfo) *objectV2.GetResponse {
|
||||||
resp := new(objectV2.GetResponse)
|
resp := new(objectV2.GetResponse)
|
||||||
|
|
||||||
body := new(objectV2.GetResponseBody)
|
body := new(objectV2.GetResponseBody)
|
||||||
|
@ -460,7 +459,7 @@ func splitInfoResponse(info *objectSDK.SplitInfo) *objectV2.GetResponse {
|
||||||
return resp
|
return resp
|
||||||
}
|
}
|
||||||
|
|
||||||
func splitInfoRangeResponse(info *objectSDK.SplitInfo) *objectV2.GetRangeResponse {
|
func splitInfoRangeResponse(info *object.SplitInfo) *objectV2.GetRangeResponse {
|
||||||
resp := new(objectV2.GetRangeResponse)
|
resp := new(objectV2.GetRangeResponse)
|
||||||
|
|
||||||
body := new(objectV2.GetRangeResponseBody)
|
body := new(objectV2.GetRangeResponseBody)
|
||||||
|
@ -471,7 +470,7 @@ func splitInfoRangeResponse(info *objectSDK.SplitInfo) *objectV2.GetRangeRespons
|
||||||
return resp
|
return resp
|
||||||
}
|
}
|
||||||
|
|
||||||
func setSplitInfoHeadResponse(info *objectSDK.SplitInfo, resp *objectV2.HeadResponse) {
|
func setSplitInfoHeadResponse(info *object.SplitInfo, resp *objectV2.HeadResponse) {
|
||||||
resp.GetBody().SetHeaderPart(info.ToV2())
|
resp.GetBody().SetHeaderPart(info.ToV2())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -512,11 +511,11 @@ func toShortObjectHeader(hdr *object.Object) objectV2.GetHeaderPart {
|
||||||
return sh
|
return sh
|
||||||
}
|
}
|
||||||
|
|
||||||
func groupAddressRequestForwarder(f func(network.Address, client.MultiAddressClient, []byte) (*objectSDK.Object, error)) getsvc.RequestForwarder {
|
func groupAddressRequestForwarder(f func(network.Address, client.MultiAddressClient, []byte) (*object.Object, error)) getsvc.RequestForwarder {
|
||||||
return func(info client.NodeInfo, c client.MultiAddressClient) (*objectSDK.Object, error) {
|
return func(info client.NodeInfo, c client.MultiAddressClient) (*object.Object, error) {
|
||||||
var (
|
var (
|
||||||
firstErr error
|
firstErr error
|
||||||
res *objectSDK.Object
|
res *object.Object
|
||||||
|
|
||||||
key = info.PublicKey()
|
key = info.PublicKey()
|
||||||
)
|
)
|
||||||
|
|
|
@ -6,10 +6,10 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
clientcore "github.com/nspcc-dev/neofs-node/pkg/core/client"
|
clientcore "github.com/nspcc-dev/neofs-node/pkg/core/client"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
||||||
internalclient "github.com/nspcc-dev/neofs-node/pkg/services/object/internal/client"
|
internalclient "github.com/nspcc-dev/neofs-node/pkg/services/object/internal/client"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/netmap"
|
"github.com/nspcc-dev/neofs-sdk-go/netmap"
|
||||||
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -94,5 +94,5 @@ func (h *RemoteHeader) Head(ctx context.Context, prm *RemoteHeadPrm) (*object.Ob
|
||||||
return nil, fmt.Errorf("(%T) could not head object in %s: %w", h, info.AddressGroup(), err)
|
return nil, fmt.Errorf("(%T) could not head object in %s: %w", h, info.AddressGroup(), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return object.NewFromSDK(res.Header()), nil
|
return res.Header(), nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -195,7 +195,7 @@ func GetObject(prm GetObjectPrm) (*GetObjectRes, error) {
|
||||||
|
|
||||||
// FIXME: #1158 object.ErrAlreadyRemoved never returns
|
// FIXME: #1158 object.ErrAlreadyRemoved never returns
|
||||||
|
|
||||||
object.NewRawFrom(&obj).SetPayload(buf)
|
obj.SetPayload(buf)
|
||||||
|
|
||||||
return &GetObjectRes{
|
return &GetObjectRes{
|
||||||
obj: &obj,
|
obj: &obj,
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/transformer"
|
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/transformer"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/util"
|
"github.com/nspcc-dev/neofs-node/pkg/util"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
||||||
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
)
|
)
|
||||||
|
|
||||||
type distributedTarget struct {
|
type distributedTarget struct {
|
||||||
|
@ -18,7 +19,7 @@ type distributedTarget struct {
|
||||||
|
|
||||||
remotePool, localPool util.WorkerPool
|
remotePool, localPool util.WorkerPool
|
||||||
|
|
||||||
obj *object.RawObject
|
obj *objectSDK.Object
|
||||||
|
|
||||||
chunks [][]byte
|
chunks [][]byte
|
||||||
|
|
||||||
|
@ -54,7 +55,7 @@ func (x errIncompletePut) Error() string {
|
||||||
return commonMsg
|
return commonMsg
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *distributedTarget) WriteHeader(obj *object.RawObject) error {
|
func (t *distributedTarget) WriteHeader(obj *objectSDK.Object) error {
|
||||||
t.obj = obj
|
t.obj = obj
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -81,7 +82,7 @@ func (t *distributedTarget) Close() (*transformer.AccessIdentifiers, error) {
|
||||||
|
|
||||||
t.obj.SetPayload(payload)
|
t.obj.SetPayload(payload)
|
||||||
|
|
||||||
if err := t.fmt.ValidateContent(t.obj.Object()); err != nil {
|
if err := t.fmt.ValidateContent(t.obj); err != nil {
|
||||||
return nil, fmt.Errorf("(%T) could not validate payload content: %w", t, err)
|
return nil, fmt.Errorf("(%T) could not validate payload content: %w", t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,20 +3,20 @@ package putsvc
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/transformer"
|
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/transformer"
|
||||||
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
)
|
)
|
||||||
|
|
||||||
type localTarget struct {
|
type localTarget struct {
|
||||||
storage *engine.StorageEngine
|
storage *engine.StorageEngine
|
||||||
|
|
||||||
obj *object.RawObject
|
obj *object.Object
|
||||||
|
|
||||||
payload []byte
|
payload []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *localTarget) WriteHeader(obj *object.RawObject) error {
|
func (t *localTarget) WriteHeader(obj *object.Object) error {
|
||||||
t.obj = obj
|
t.obj = obj
|
||||||
|
|
||||||
t.payload = make([]byte, 0, obj.PayloadSize())
|
t.payload = make([]byte, 0, obj.PayloadSize())
|
||||||
|
@ -31,7 +31,7 @@ func (t *localTarget) Write(p []byte) (n int, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *localTarget) Close() (*transformer.AccessIdentifiers, error) {
|
func (t *localTarget) Close() (*transformer.AccessIdentifiers, error) {
|
||||||
if err := engine.Put(t.storage, t.obj.Object()); err != nil {
|
if err := engine.Put(t.storage, t.obj); err != nil {
|
||||||
return nil, fmt.Errorf("(%T) could not put object to local storage: %w", t, err)
|
return nil, fmt.Errorf("(%T) could not put object to local storage: %w", t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,15 +2,15 @@ package putsvc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/client"
|
"github.com/nspcc-dev/neofs-node/pkg/core/client"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement"
|
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement"
|
||||||
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PutInitPrm struct {
|
type PutInitPrm struct {
|
||||||
common *util.CommonPrm
|
common *util.CommonPrm
|
||||||
|
|
||||||
hdr *object.RawObject
|
hdr *object.Object
|
||||||
|
|
||||||
traverseOpts []placement.Option
|
traverseOpts []placement.Option
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ func (p *PutInitPrm) WithTraverseOption(opt placement.Option) *PutInitPrm {
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PutInitPrm) WithObject(v *object.RawObject) *PutInitPrm {
|
func (p *PutInitPrm) WithObject(v *object.Object) *PutInitPrm {
|
||||||
if p != nil {
|
if p != nil {
|
||||||
p.hdr = v
|
p.hdr = v
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,11 +5,11 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
clientcore "github.com/nspcc-dev/neofs-node/pkg/core/client"
|
clientcore "github.com/nspcc-dev/neofs-node/pkg/core/client"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
||||||
internalclient "github.com/nspcc-dev/neofs-node/pkg/services/object/internal/client"
|
internalclient "github.com/nspcc-dev/neofs-node/pkg/services/object/internal/client"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/transformer"
|
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/transformer"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/netmap"
|
"github.com/nspcc-dev/neofs-sdk-go/netmap"
|
||||||
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
)
|
)
|
||||||
|
|
||||||
type remoteTarget struct {
|
type remoteTarget struct {
|
||||||
|
@ -43,8 +43,8 @@ type RemotePutPrm struct {
|
||||||
obj *object.Object
|
obj *object.Object
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *remoteTarget) WriteHeader(obj *object.RawObject) error {
|
func (t *remoteTarget) WriteHeader(obj *object.Object) error {
|
||||||
t.obj = obj.Object()
|
t.obj = obj
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ func (t *remoteTarget) Close() (*transformer.AccessIdentifiers, error) {
|
||||||
prm.SetSessionToken(t.commonPrm.SessionToken())
|
prm.SetSessionToken(t.commonPrm.SessionToken())
|
||||||
prm.SetBearerToken(t.commonPrm.BearerToken())
|
prm.SetBearerToken(t.commonPrm.BearerToken())
|
||||||
prm.SetXHeaders(t.commonPrm.XHeaders())
|
prm.SetXHeaders(t.commonPrm.XHeaders())
|
||||||
prm.SetObject(t.obj.SDK())
|
prm.SetObject(t.obj)
|
||||||
|
|
||||||
res, err := internalclient.PutObject(prm)
|
res, err := internalclient.PutObject(prm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -118,7 +118,7 @@ func (s *RemoteSender) PutObject(ctx context.Context, p *RemotePutPrm) error {
|
||||||
return fmt.Errorf("parse client node info: %w", err)
|
return fmt.Errorf("parse client node info: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := t.WriteHeader(object.NewRawFromObject(p.obj)); err != nil {
|
if err := t.WriteHeader(p.obj); err != nil {
|
||||||
return fmt.Errorf("(%T) could not send object header: %w", s, err)
|
return fmt.Errorf("(%T) could not send object header: %w", s, err)
|
||||||
} else if _, err := t.Close(); err != nil {
|
} else if _, err := t.Close(); err != nil {
|
||||||
return fmt.Errorf("(%T) could not send object: %w", s, err)
|
return fmt.Errorf("(%T) could not send object: %w", s, err)
|
||||||
|
|
|
@ -2,9 +2,9 @@ package putsvc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object"
|
objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
||||||
putsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/put"
|
putsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/put"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
||||||
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *streamer) toInitPrm(part *objectV2.PutObjectPartInit, req *objectV2.PutRequest) (*putsvc.PutInitPrm, error) {
|
func (s *streamer) toInitPrm(part *objectV2.PutObjectPartInit, req *objectV2.PutRequest) (*putsvc.PutInitPrm, error) {
|
||||||
|
@ -20,7 +20,7 @@ func (s *streamer) toInitPrm(part *objectV2.PutObjectPartInit, req *objectV2.Put
|
||||||
|
|
||||||
return new(putsvc.PutInitPrm).
|
return new(putsvc.PutInitPrm).
|
||||||
WithObject(
|
WithObject(
|
||||||
object.NewRawFromV2(oV2),
|
object.NewFromV2(oV2),
|
||||||
).
|
).
|
||||||
WithRelay(s.relayRequest).
|
WithRelay(s.relayRequest).
|
||||||
WithCommonPrm(commonPrm), nil
|
WithCommonPrm(commonPrm), nil
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/transformer"
|
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/transformer"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/checksum"
|
"github.com/nspcc-dev/neofs-sdk-go/checksum"
|
||||||
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
"github.com/nspcc-dev/tzhash/tz"
|
"github.com/nspcc-dev/tzhash/tz"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -35,7 +36,7 @@ var (
|
||||||
ErrWrongPayloadSize = errors.New("wrong payload size")
|
ErrWrongPayloadSize = errors.New("wrong payload size")
|
||||||
)
|
)
|
||||||
|
|
||||||
func (t *validatingTarget) WriteHeader(obj *object.RawObject) error {
|
func (t *validatingTarget) WriteHeader(obj *objectSDK.Object) error {
|
||||||
t.payloadSz = obj.PayloadSize()
|
t.payloadSz = obj.PayloadSize()
|
||||||
chunkLn := uint64(len(obj.Payload()))
|
chunkLn := uint64(len(obj.Payload()))
|
||||||
|
|
||||||
|
@ -61,7 +62,7 @@ func (t *validatingTarget) WriteHeader(obj *object.RawObject) error {
|
||||||
|
|
||||||
t.checksum = cs.Sum()
|
t.checksum = cs.Sum()
|
||||||
|
|
||||||
if err := t.fmt.Validate(obj.Object()); err != nil {
|
if err := t.fmt.Validate(obj); err != nil {
|
||||||
return fmt.Errorf("(%T) coult not validate object format: %w", t, err)
|
return fmt.Errorf("(%T) coult not validate object format: %w", t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement"
|
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
||||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
@ -64,7 +64,7 @@ func (exec *execCtx) containerID() *cid.ID {
|
||||||
return exec.prm.cid
|
return exec.prm.cid
|
||||||
}
|
}
|
||||||
|
|
||||||
func (exec *execCtx) searchFilters() objectSDK.SearchFilters {
|
func (exec *execCtx) searchFilters() object.SearchFilters {
|
||||||
return exec.prm.filters
|
return exec.prm.filters
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
coreclient "github.com/nspcc-dev/neofs-node/pkg/core/client"
|
coreclient "github.com/nspcc-dev/neofs-node/pkg/core/client"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
||||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ type Prm struct {
|
||||||
|
|
||||||
cid *cid.ID
|
cid *cid.ID
|
||||||
|
|
||||||
filters objectSDK.SearchFilters
|
filters object.SearchFilters
|
||||||
|
|
||||||
forwarder RequestForwarder
|
forwarder RequestForwarder
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,6 @@ func (p *Prm) WithContainerID(id *cid.ID) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithSearchFilters sets search filters.
|
// WithSearchFilters sets search filters.
|
||||||
func (p *Prm) WithSearchFilters(fs objectSDK.SearchFilters) {
|
func (p *Prm) WithSearchFilters(fs object.SearchFilters) {
|
||||||
p.filters = fs
|
p.filters = fs
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ import (
|
||||||
searchsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/search"
|
searchsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/search"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
||||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ func (s *Service) toPrm(req *objectV2.SearchRequest, stream objectSvc.SearchStre
|
||||||
|
|
||||||
body := req.GetBody()
|
body := req.GetBody()
|
||||||
p.WithContainerID(cid.NewFromV2(body.GetContainerID()))
|
p.WithContainerID(cid.NewFromV2(body.GetContainerID()))
|
||||||
p.WithSearchFilters(objectSDK.NewSearchFiltersFromV2(body.GetFilters()))
|
p.WithSearchFilters(object.NewSearchFiltersFromV2(body.GetFilters()))
|
||||||
|
|
||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,9 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||||
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// HeadReceiver is an interface of entity that can receive
|
// HeadReceiver is an interface of entity that can receive
|
||||||
|
@ -16,7 +14,7 @@ import (
|
||||||
type HeadReceiver interface {
|
type HeadReceiver interface {
|
||||||
// Head must return one of:
|
// Head must return one of:
|
||||||
// * object header (*object.Object);
|
// * object header (*object.Object);
|
||||||
// * structured information about split-chain (*objectSDK.SplitInfo).
|
// * structured information about split-chain (*object.SplitInfo).
|
||||||
Head(*addressSDK.Address) (interface{}, error)
|
Head(*addressSDK.Address) (interface{}, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +86,7 @@ func traverseSplitChain(r HeadReceiver, addr *addressSDK.Address, h SplitMemberH
|
||||||
panic(fmt.Sprintf("unexpected result of %T: %T", r, v))
|
panic(fmt.Sprintf("unexpected result of %T: %T", r, v))
|
||||||
case *object.Object:
|
case *object.Object:
|
||||||
return h(res, false), nil
|
return h(res, false), nil
|
||||||
case *objectSDK.SplitInfo:
|
case *object.SplitInfo:
|
||||||
switch {
|
switch {
|
||||||
default:
|
default:
|
||||||
return false, errors.New("lack of split information")
|
return false, errors.New("lack of split information")
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package storagegroup
|
package storagegroup
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
||||||
objutil "github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
objutil "github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/checksum"
|
"github.com/nspcc-dev/neofs-sdk-go/checksum"
|
||||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||||
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||||
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/storagegroup"
|
"github.com/nspcc-dev/neofs-sdk-go/storagegroup"
|
||||||
|
|
|
@ -5,8 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
|
||||||
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/session"
|
"github.com/nspcc-dev/neofs-sdk-go/session"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/version"
|
"github.com/nspcc-dev/neofs-sdk-go/version"
|
||||||
|
@ -15,7 +14,7 @@ import (
|
||||||
type formatter struct {
|
type formatter struct {
|
||||||
prm *FormatterParams
|
prm *FormatterParams
|
||||||
|
|
||||||
obj *object.RawObject
|
obj *object.Object
|
||||||
|
|
||||||
sz uint64
|
sz uint64
|
||||||
}
|
}
|
||||||
|
@ -48,7 +47,7 @@ func NewFormatTarget(p *FormatterParams) ObjectTarget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *formatter) WriteHeader(obj *object.RawObject) error {
|
func (f *formatter) WriteHeader(obj *object.Object) error {
|
||||||
f.obj = obj
|
f.obj = obj
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -72,26 +71,26 @@ func (f *formatter) Close() (*AccessIdentifiers, error) {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
parID *oidSDK.ID
|
parID *oidSDK.ID
|
||||||
parHdr *objectSDK.Object
|
parHdr *object.Object
|
||||||
)
|
)
|
||||||
|
|
||||||
if par := f.obj.Parent(); par != nil && par.Signature() == nil {
|
if par := f.obj.Parent(); par != nil && par.Signature() == nil {
|
||||||
rawPar := objectSDK.NewRawFromV2(par.ToV2())
|
rawPar := object.NewFromV2(par.ToV2())
|
||||||
|
|
||||||
rawPar.SetSessionToken(f.prm.SessionToken)
|
rawPar.SetSessionToken(f.prm.SessionToken)
|
||||||
rawPar.SetCreationEpoch(curEpoch)
|
rawPar.SetCreationEpoch(curEpoch)
|
||||||
|
|
||||||
if err := objectSDK.SetIDWithSignature(f.prm.Key, rawPar); err != nil {
|
if err := object.SetIDWithSignature(f.prm.Key, rawPar); err != nil {
|
||||||
return nil, fmt.Errorf("could not finalize parent object: %w", err)
|
return nil, fmt.Errorf("could not finalize parent object: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
parID = rawPar.ID()
|
parID = rawPar.ID()
|
||||||
parHdr = rawPar.Object()
|
parHdr = rawPar
|
||||||
|
|
||||||
f.obj.SetParent(parHdr)
|
f.obj.SetParent(parHdr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := objectSDK.SetIDWithSignature(f.prm.Key, f.obj.SDK()); err != nil {
|
if err := object.SetIDWithSignature(f.prm.Key, f.obj); err != nil {
|
||||||
return nil, fmt.Errorf("could not finalize object: %w", err)
|
return nil, fmt.Errorf("could not finalize object: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,8 @@ import (
|
||||||
"hash"
|
"hash"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/checksum"
|
"github.com/nspcc-dev/neofs-sdk-go/checksum"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||||
"github.com/nspcc-dev/tzhash/tz"
|
"github.com/nspcc-dev/tzhash/tz"
|
||||||
)
|
)
|
||||||
|
@ -20,7 +19,7 @@ type payloadSizeLimiter struct {
|
||||||
|
|
||||||
target ObjectTarget
|
target ObjectTarget
|
||||||
|
|
||||||
current, parent *object.RawObject
|
current, parent *object.Object
|
||||||
|
|
||||||
currentHashers, parentHashers []*payloadChecksumHasher
|
currentHashers, parentHashers []*payloadChecksumHasher
|
||||||
|
|
||||||
|
@ -28,9 +27,9 @@ type payloadSizeLimiter struct {
|
||||||
|
|
||||||
chunkWriter io.Writer
|
chunkWriter io.Writer
|
||||||
|
|
||||||
splitID *objectSDK.SplitID
|
splitID *object.SplitID
|
||||||
|
|
||||||
parAttrs []*objectSDK.Attribute
|
parAttrs []*object.Attribute
|
||||||
}
|
}
|
||||||
|
|
||||||
type payloadChecksumHasher struct {
|
type payloadChecksumHasher struct {
|
||||||
|
@ -47,11 +46,11 @@ func NewPayloadSizeLimiter(maxSize uint64, targetInit TargetInitializer) ObjectT
|
||||||
return &payloadSizeLimiter{
|
return &payloadSizeLimiter{
|
||||||
maxSize: maxSize,
|
maxSize: maxSize,
|
||||||
targetInit: targetInit,
|
targetInit: targetInit,
|
||||||
splitID: objectSDK.NewSplitID(),
|
splitID: object.NewSplitID(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *payloadSizeLimiter) WriteHeader(hdr *object.RawObject) error {
|
func (s *payloadSizeLimiter) WriteHeader(hdr *object.Object) error {
|
||||||
s.current = fromObject(hdr)
|
s.current = fromObject(hdr)
|
||||||
|
|
||||||
s.initialize()
|
s.initialize()
|
||||||
|
@ -86,8 +85,8 @@ func (s *payloadSizeLimiter) initialize() {
|
||||||
s.initializeCurrent()
|
s.initializeCurrent()
|
||||||
}
|
}
|
||||||
|
|
||||||
func fromObject(obj *object.RawObject) *object.RawObject {
|
func fromObject(obj *object.Object) *object.Object {
|
||||||
res := object.NewRaw()
|
res := object.New()
|
||||||
res.SetContainerID(obj.ContainerID())
|
res.SetContainerID(obj.ContainerID())
|
||||||
res.SetOwnerID(obj.OwnerID())
|
res.SetOwnerID(obj.OwnerID())
|
||||||
res.SetAttributes(obj.Attributes()...)
|
res.SetAttributes(obj.Attributes()...)
|
||||||
|
@ -125,7 +124,7 @@ func (s *payloadSizeLimiter) initializeCurrent() {
|
||||||
s.chunkWriter = io.MultiWriter(ws...)
|
s.chunkWriter = io.MultiWriter(ws...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func payloadHashersForObject(obj *object.RawObject) []*payloadChecksumHasher {
|
func payloadHashersForObject(obj *object.Object) []*payloadChecksumHasher {
|
||||||
return []*payloadChecksumHasher{
|
return []*payloadChecksumHasher{
|
||||||
{
|
{
|
||||||
hasher: sha256.New(),
|
hasher: sha256.New(),
|
||||||
|
@ -171,7 +170,7 @@ func (s *payloadSizeLimiter) release(close bool) (*AccessIdentifiers, error) {
|
||||||
if withParent {
|
if withParent {
|
||||||
writeHashes(s.parentHashers)
|
writeHashes(s.parentHashers)
|
||||||
s.parent.SetPayloadSize(s.written)
|
s.parent.SetPayloadSize(s.written)
|
||||||
s.current.SetParent(s.parent.SDK().Object())
|
s.current.SetParent(s.parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
// release current object
|
// release current object
|
||||||
|
@ -209,7 +208,7 @@ func writeHashes(hashers []*payloadChecksumHasher) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *payloadSizeLimiter) initializeLinking(parHdr *objectSDK.Object) {
|
func (s *payloadSizeLimiter) initializeLinking(parHdr *object.Object) {
|
||||||
s.current = fromObject(s.current)
|
s.current = fromObject(s.current)
|
||||||
s.current.SetParent(parHdr)
|
s.current.SetParent(parHdr)
|
||||||
s.current.SetChildren(s.previous...)
|
s.current.SetChildren(s.previous...)
|
||||||
|
|
|
@ -3,8 +3,7 @@ package transformer
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
|
||||||
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -14,7 +13,7 @@ import (
|
||||||
type AccessIdentifiers struct {
|
type AccessIdentifiers struct {
|
||||||
par, self *oidSDK.ID
|
par, self *oidSDK.ID
|
||||||
|
|
||||||
parHdr *objectSDK.Object
|
parHdr *object.Object
|
||||||
}
|
}
|
||||||
|
|
||||||
// ObjectTarget is an interface of the object writer.
|
// ObjectTarget is an interface of the object writer.
|
||||||
|
@ -27,7 +26,7 @@ type ObjectTarget interface {
|
||||||
// that depends on the implementation.
|
// that depends on the implementation.
|
||||||
//
|
//
|
||||||
// Must not be called after Close call.
|
// Must not be called after Close call.
|
||||||
WriteHeader(*object.RawObject) error
|
WriteHeader(*object.Object) error
|
||||||
|
|
||||||
// Write writes object payload chunk.
|
// Write writes object payload chunk.
|
||||||
//
|
//
|
||||||
|
@ -93,7 +92,7 @@ func (a *AccessIdentifiers) WithParentID(v *oidSDK.ID) *AccessIdentifiers {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parent return identifier of the parent of the written object.
|
// Parent return identifier of the parent of the written object.
|
||||||
func (a *AccessIdentifiers) Parent() *objectSDK.Object {
|
func (a *AccessIdentifiers) Parent() *object.Object {
|
||||||
if a != nil {
|
if a != nil {
|
||||||
return a.parHdr
|
return a.parHdr
|
||||||
}
|
}
|
||||||
|
@ -102,7 +101,7 @@ func (a *AccessIdentifiers) Parent() *objectSDK.Object {
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithParent returns AccessIdentifiers with passed parent identifier.
|
// WithParent returns AccessIdentifiers with passed parent identifier.
|
||||||
func (a *AccessIdentifiers) WithParent(v *objectSDK.Object) *AccessIdentifiers {
|
func (a *AccessIdentifiers) WithParent(v *object.Object) *AccessIdentifiers {
|
||||||
res := a
|
res := a
|
||||||
if res == nil {
|
if res == nil {
|
||||||
res = new(AccessIdentifiers)
|
res = new(AccessIdentifiers)
|
||||||
|
|
Loading…
Reference in a new issue