[#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:
Leonard Lyubich 2022-03-03 17:19:05 +03:00 committed by Alex Vanin
parent 19ad349b27
commit 7ccd1625af
100 changed files with 847 additions and 965 deletions

View file

@ -13,6 +13,7 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/core/object"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
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"
"go.uber.org/zap"
)
@ -572,7 +573,7 @@ func (b *blobovniczas) getObject(blz *blobovnicza.Blobovnicza, prm *blobovnicza.
}
// unmarshal the object
obj := object.New()
obj := objectSDK.New()
if err := obj.Unmarshal(data); err != nil {
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
obj := object.New()
obj := objectSDK.New()
if err := obj.Unmarshal(data); err != nil {
return nil, fmt.Errorf("could not unmarshal the object: %w", err)
}

View file

@ -33,8 +33,8 @@ func testAddress() *addressSDK.Address {
return addr
}
func testObjectRaw(sz uint64) *object.RawObject {
raw := object.NewRaw()
func testObject(sz uint64) *objectSDK.Object {
raw := objectSDK.New()
addr := testAddress()
raw.SetID(addr.ObjectID())
@ -51,10 +51,6 @@ func testObjectRaw(sz uint64) *object.RawObject {
return raw
}
func testObject(sz uint64) *object.Object {
return testObjectRaw(sz).Object()
}
func TestBlobovniczas(t *testing.T) {
rand.Seed(1024)
@ -91,19 +87,21 @@ func TestBlobovniczas(t *testing.T) {
for i := uint64(0); i < minFitObjNum; i++ {
obj := testObject(objSz)
addrList = append(addrList, obj.Address())
addr := object.AddressOf(obj)
addrList = append(addrList, addr)
d, err := obj.Marshal()
require.NoError(t, err)
// save object in blobovnicza
id, err := b.put(obj.Address(), d)
id, err := b.put(addr, d)
require.NoError(t, err)
// get w/ blobovnicza ID
prm := new(GetSmallPrm)
prm.SetBlobovniczaID(id)
prm.SetAddress(obj.Address())
prm.SetAddress(addr)
res, err := b.get(prm)
require.NoError(t, err)
@ -119,7 +117,7 @@ func TestBlobovniczas(t *testing.T) {
// get range w/ blobovnicza ID
rngPrm := new(GetRangeSmallPrm)
rngPrm.SetBlobovniczaID(id)
rngPrm.SetAddress(obj.Address())
rngPrm.SetAddress(addr)
payload := obj.Payload()
pSize := uint64(len(obj.Payload()))

View file

@ -29,19 +29,19 @@ func TestCompression(t *testing.T) {
return bs
}
bigObj := make([]*object.Object, objCount)
smallObj := make([]*object.Object, objCount)
bigObj := make([]*objectSDK.Object, objCount)
smallObj := make([]*objectSDK.Object, objCount)
for i := 0; i < objCount; i++ {
bigObj[i] = testObject(smallSizeLimit * 2)
smallObj[i] = testObject(smallSizeLimit / 2)
}
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.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.Equal(t, bigObj[i], res2.Object())
}
@ -95,15 +95,15 @@ func TestBlobstor_needsCompression(t *testing.T) {
return bs
}
newObjectWithCt := func(contentType string) *object.Object {
obj := testObjectRaw(smallSizeLimit + 1)
newObjectWithCt := func(contentType string) *objectSDK.Object {
obj := testObject(smallSizeLimit + 1)
if contentType != "" {
a := objectSDK.NewAttribute()
a.SetKey(objectSDK.AttributeContentType)
a.SetValue(contentType)
obj.SetAttributes(a)
}
return obj.Object()
return obj
}
t.Run("content-types specified", func(t *testing.T) {

View file

@ -6,6 +6,7 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/core/object"
"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.
@ -42,7 +43,7 @@ func (b *BlobStor) GetBig(prm *GetBigPrm) (*GetBigRes, error) {
}
// unmarshal the object
obj := object.New()
obj := objectSDK.New()
if err := obj.Unmarshal(data); err != nil {
return nil, fmt.Errorf("could not unmarshal the object: %w", err)
}

View file

@ -6,6 +6,7 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/core/object"
"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.
@ -42,7 +43,7 @@ func (b *BlobStor) GetRangeBig(prm *GetRangeBigPrm) (*GetRangeBigRes, error) {
}
// unmarshal the object
obj := object.New()
obj := objectSDK.New()
if err := obj.Unmarshal(data); err != nil {
return nil, fmt.Errorf("could not unmarshal the object: %w", err)
}

View file

@ -3,9 +3,9 @@ package blobstor
import (
"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/blobstor/fstree"
"github.com/nspcc-dev/neofs-sdk-go/object"
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
)

View file

@ -10,8 +10,8 @@ import (
"testing"
"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-sdk-go/object"
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
objecttest "github.com/nspcc-dev/neofs-sdk-go/object/address/test"
"github.com/stretchr/testify/require"
@ -117,7 +117,7 @@ func TestIterate_IgnoreErrors(t *testing.T) {
addrs := make([]*addressSDK.Address, objCount)
for i := range addrs {
addrs[i] = objecttest.Address()
obj := object.NewRaw()
obj := object.New()
obj.SetContainerID(addrs[i].ContainerID())
obj.SetID(addrs[i].ObjectID())
obj.SetPayload(make([]byte, smallSize<<(i%2)))

View file

@ -35,14 +35,14 @@ func (b *BlobStor) Put(prm *PutPrm) (*PutRes, error) {
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.
// For object to be compressed 2 conditions must hold:
// 1. Compression is enabled in settings.
// 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 {
return b.compressionEnabled
}

View file

@ -1,9 +1,8 @@
package blobstor
import (
"github.com/nspcc-dev/neofs-node/pkg/core/object"
"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"
)
@ -53,11 +52,11 @@ func (v *rwBlobovniczaID) SetBlobovniczaID(id *blobovnicza.ID) {
}
type roRange struct {
rng *objectSDK.Range
rng *object.Range
}
// Range returns range of the object payload.
func (r roRange) Range() *objectSDK.Range {
func (r roRange) Range() *object.Range {
return r.rng
}
@ -66,7 +65,7 @@ type rwRange struct {
}
// SetRange sets range of the object payload.
func (r *rwRange) SetRange(rng *objectSDK.Range) {
func (r *rwRange) SetRange(rng *object.Range) {
r.rng = rng
}