From 1c30414a6cd1be2b7a5bc7d2954a7743d8fde936 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 31 May 2022 20:00:41 +0300 Subject: [PATCH] [#1454] Upgrade NeoFS SDK Go module with new IDs Core changes: * avoid package-colliding variable naming * avoid using pointers to IDs where unnecessary * avoid using `idSDK` import alias pattern * use `EncodeToString` for protocol string calculation and `String` for printing Signed-off-by: Leonard Lyubich --- cmd/neofs-cli/internal/client/client.go | 114 +++----- cmd/neofs-cli/internal/client/prm.go | 10 +- cmd/neofs-cli/internal/common/token.go | 20 +- cmd/neofs-cli/modules/accounting/balance.go | 8 +- cmd/neofs-cli/modules/container.go | 13 +- cmd/neofs-cli/modules/control/drop_objects.go | 17 +- cmd/neofs-cli/modules/control/util.go | 7 +- cmd/neofs-cli/modules/lock.go | 3 +- cmd/neofs-cli/modules/object.go | 189 +++++++------ cmd/neofs-cli/modules/storagegroup.go | 84 +++--- .../internal/commands/inspect/inspect.go | 8 +- cmd/neofs-lens/internal/commands/list/list.go | 7 +- cmd/neofs-node/cache.go | 26 +- cmd/neofs-node/config.go | 2 +- cmd/neofs-node/container.go | 31 +- cmd/neofs-node/control.go | 4 +- cmd/neofs-node/notificator.go | 10 +- cmd/neofs-node/object.go | 14 +- cmd/neofs-node/session.go | 2 +- go.mod | 4 +- go.sum | Bin 98309 -> 98369 bytes pkg/core/container/delete.go | 10 +- pkg/core/container/fmt_test.go | 6 +- pkg/core/container/storage.go | 2 +- pkg/core/object/fmt.go | 20 +- pkg/core/object/fmt_test.go | 8 +- pkg/core/object/object.go | 28 +- pkg/innerring/internal/client/client.go | 48 +--- pkg/innerring/internal/client/prm.go | 6 +- pkg/innerring/processors/audit/process.go | 10 +- pkg/innerring/processors/audit/processor.go | 10 +- pkg/innerring/processors/audit/scheduler.go | 6 +- .../processors/audit/scheduler_test.go | 23 +- pkg/innerring/processors/container/common.go | 2 +- .../processors/container/process_container.go | 8 +- .../processors/container/process_eacl.go | 2 +- .../processors/settlement/audit/calculate.go | 17 +- .../processors/settlement/audit/prm.go | 4 +- .../processors/settlement/basic/collect.go | 8 +- .../processors/settlement/basic/context.go | 2 +- .../processors/settlement/basic/distribute.go | 6 +- .../processors/settlement/common/types.go | 10 +- .../processors/settlement/common/util.go | 6 +- pkg/innerring/rpc.go | 35 +-- pkg/innerring/settlement.go | 26 +- .../blobovnicza/blobovnicza_test.go | 24 +- .../blobovnicza/delete.go | 6 +- pkg/local_object_storage/blobovnicza/get.go | 6 +- .../blobovnicza/iterate.go | 14 +- .../blobovnicza/iterate_test.go | 4 +- pkg/local_object_storage/blobovnicza/put.go | 23 +- .../blobstor/blobovnicza.go | 22 +- .../blobstor/blobovnicza_test.go | 4 +- pkg/local_object_storage/blobstor/exists.go | 10 +- .../blobstor/exists_test.go | 4 +- .../blobstor/fstree/fstree.go | 46 ++- .../blobstor/fstree/fstree_test.go | 38 +-- pkg/local_object_storage/blobstor/iterate.go | 4 +- .../blobstor/iterate_test.go | 30 +- pkg/local_object_storage/blobstor/put.go | 4 +- pkg/local_object_storage/blobstor/util.go | 6 +- pkg/local_object_storage/engine/container.go | 25 +- pkg/local_object_storage/engine/delete.go | 6 +- .../engine/engine_test.go | 3 +- pkg/local_object_storage/engine/exists.go | 4 +- pkg/local_object_storage/engine/get.go | 8 +- pkg/local_object_storage/engine/head.go | 10 +- pkg/local_object_storage/engine/head_test.go | 16 +- pkg/local_object_storage/engine/inhume.go | 18 +- .../engine/inhume_test.go | 4 +- pkg/local_object_storage/engine/list.go | 8 +- pkg/local_object_storage/engine/list_test.go | 10 +- pkg/local_object_storage/engine/lock.go | 14 +- pkg/local_object_storage/engine/lock_test.go | 36 ++- pkg/local_object_storage/engine/range.go | 12 +- pkg/local_object_storage/engine/select.go | 47 ++-- pkg/local_object_storage/engine/shards.go | 8 +- .../metabase/containers.go | 32 +-- .../metabase/containers_test.go | 28 +- .../metabase/control_test.go | 10 +- pkg/local_object_storage/metabase/db_test.go | 6 +- pkg/local_object_storage/metabase/delete.go | 44 ++- .../metabase/delete_test.go | 22 +- pkg/local_object_storage/metabase/exists.go | 27 +- .../metabase/exists_test.go | 14 +- pkg/local_object_storage/metabase/get.go | 37 ++- pkg/local_object_storage/metabase/get_test.go | 16 +- .../metabase/graveyard.go | 59 ++-- .../metabase/graveyard_test.go | 60 ++-- pkg/local_object_storage/metabase/inhume.go | 27 +- .../metabase/inhume_test.go | 19 +- .../metabase/iterators.go | 28 +- .../metabase/iterators_test.go | 37 +-- pkg/local_object_storage/metabase/list.go | 24 +- .../metabase/list_test.go | 20 +- pkg/local_object_storage/metabase/lock.go | 26 +- .../metabase/lock_test.go | 13 +- pkg/local_object_storage/metabase/movable.go | 26 +- pkg/local_object_storage/metabase/put.go | 70 ++--- pkg/local_object_storage/metabase/put_test.go | 4 +- pkg/local_object_storage/metabase/select.go | 127 ++++----- .../metabase/select_test.go | 196 ++++++------- pkg/local_object_storage/metabase/small.go | 18 +- pkg/local_object_storage/metabase/util.go | 66 +++-- pkg/local_object_storage/shard/container.go | 12 +- pkg/local_object_storage/shard/control.go | 10 +- .../shard/control_test.go | 16 +- pkg/local_object_storage/shard/delete.go | 8 +- pkg/local_object_storage/shard/dump_test.go | 16 +- pkg/local_object_storage/shard/exists.go | 6 +- pkg/local_object_storage/shard/gc.go | 14 +- pkg/local_object_storage/shard/get.go | 8 +- pkg/local_object_storage/shard/head.go | 6 +- pkg/local_object_storage/shard/head_test.go | 6 +- pkg/local_object_storage/shard/inhume.go | 14 +- pkg/local_object_storage/shard/inhume_test.go | 6 +- pkg/local_object_storage/shard/list.go | 14 +- pkg/local_object_storage/shard/list_test.go | 12 +- pkg/local_object_storage/shard/move.go | 6 +- pkg/local_object_storage/shard/range.go | 6 +- pkg/local_object_storage/shard/select.go | 14 +- pkg/local_object_storage/shard/shard.go | 4 +- .../util/splitinfo_test.go | 6 +- pkg/local_object_storage/writecache/delete.go | 6 +- pkg/local_object_storage/writecache/flush.go | 6 +- pkg/local_object_storage/writecache/get.go | 8 +- .../writecache/iterate.go | 16 +- pkg/local_object_storage/writecache/put.go | 2 +- .../writecache/storage.go | 7 +- .../writecache/writecache.go | 8 +- pkg/morph/client/audit/list_results.go | 4 +- pkg/morph/client/audit/result_test.go | 2 +- pkg/morph/client/balance/balanceOf.go | 2 +- pkg/morph/client/balance/transfer.go | 2 +- pkg/morph/client/container/delete.go | 13 +- pkg/morph/client/container/eacl.go | 6 +- pkg/morph/client/container/get.go | 8 +- pkg/morph/client/container/list.go | 10 +- pkg/morph/client/container/load.go | 10 +- pkg/morph/client/neofsid/keys.go | 4 +- pkg/services/accounting/morph/executor.go | 2 +- pkg/services/audit/auditor/context.go | 32 +-- pkg/services/audit/auditor/pdp.go | 4 +- pkg/services/audit/auditor/pop.go | 20 +- pkg/services/audit/auditor/por.go | 15 +- pkg/services/audit/report.go | 14 +- pkg/services/audit/task.go | 18 +- .../load/route/placement/calls.go | 2 +- .../announcement/load/route/placement/deps.go | 4 +- pkg/services/container/morph/executor.go | 8 +- pkg/services/control/common_test.go | 7 +- pkg/services/control/ir/service.go | 16 +- pkg/services/control/ir/service_test.go | 7 +- pkg/services/control/server/gc.go | 12 +- pkg/services/control/service.go | 265 ++++++------------ pkg/services/control/types.go | 164 ++--------- pkg/services/notificator/deps.go | 8 +- pkg/services/notificator/nats/service.go | 13 +- pkg/services/notificator/service.go | 4 +- pkg/services/object/acl/acl.go | 23 +- pkg/services/object/acl/acl_test.go | 12 +- pkg/services/object/acl/eacl/types.go | 2 +- pkg/services/object/acl/eacl/v2/eacl_test.go | 44 ++- pkg/services/object/acl/eacl/v2/headers.go | 59 ++-- pkg/services/object/acl/eacl/v2/localstore.go | 4 +- pkg/services/object/acl/eacl/v2/object.go | 8 +- pkg/services/object/acl/eacl/v2/opts.go | 12 +- pkg/services/object/acl/v2/classifier.go | 4 +- pkg/services/object/acl/v2/request.go | 18 +- pkg/services/object/acl/v2/service.go | 55 ++-- pkg/services/object/acl/v2/types.go | 2 +- pkg/services/object/acl/v2/util.go | 30 +- pkg/services/object/delete/exec.go | 35 +-- pkg/services/object/delete/local.go | 6 +- pkg/services/object/delete/prm.go | 8 +- pkg/services/object/delete/service.go | 12 +- pkg/services/object/delete/util.go | 23 +- pkg/services/object/delete/v2/util.go | 30 +- pkg/services/object/get/assemble.go | 54 ++-- pkg/services/object/get/exec.go | 40 +-- pkg/services/object/get/get_test.go | 249 ++++++++-------- pkg/services/object/get/prm.go | 6 +- pkg/services/object/get/service.go | 5 +- pkg/services/object/get/v2/util.go | 85 ++++-- pkg/services/object/head/prm.go | 6 +- pkg/services/object/head/remote.go | 4 +- pkg/services/object/internal/client/client.go | 67 ++--- pkg/services/object/put/distributed.go | 4 +- pkg/services/object/put/local.go | 2 +- pkg/services/object/put/res.go | 6 +- pkg/services/object/put/streamer.go | 12 +- pkg/services/object/search/exec.go | 12 +- pkg/services/object/search/prm.go | 12 +- pkg/services/object/search/search_test.go | 70 ++--- pkg/services/object/search/service.go | 8 +- pkg/services/object/search/util.go | 24 +- pkg/services/object/search/v2/streamer.go | 4 +- pkg/services/object/search/v2/util.go | 16 +- pkg/services/object/util/chain.go | 34 +-- pkg/services/object/util/key.go | 4 +- pkg/services/object/util/placement.go | 25 +- .../object_manager/placement/netmap.go | 22 +- .../object_manager/placement/traverser.go | 21 +- .../placement/traverser_test.go | 5 +- .../object_manager/storagegroup/collect.go | 13 +- .../object_manager/tombstone/checker.go | 8 +- .../object_manager/tombstone/source/source.go | 6 +- .../object_manager/transformer/fmt.go | 6 +- .../object_manager/transformer/transformer.go | 6 +- .../object_manager/transformer/types.go | 20 +- pkg/services/policer/check.go | 16 +- pkg/services/policer/policer.go | 4 +- pkg/services/policer/process.go | 6 +- pkg/services/policer/queue.go | 4 +- pkg/services/replicator/task.go | 6 +- .../storage/persistent/executor_test.go | 6 +- .../session/storage/persistent/storage.go | 2 +- .../session/storage/temporary/storage.go | 2 +- 218 files changed, 2091 insertions(+), 2517 deletions(-) diff --git a/cmd/neofs-cli/internal/client/client.go b/cmd/neofs-cli/internal/client/client.go index 74cbce03..d76e6052 100644 --- a/cmd/neofs-cli/internal/client/client.go +++ b/cmd/neofs-cli/internal/client/client.go @@ -14,8 +14,7 @@ import ( "github.com/nspcc-dev/neofs-sdk-go/eacl" "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" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/nspcc-dev/neofs-sdk-go/version" ) @@ -77,12 +76,12 @@ type PutContainerPrm struct { // PutContainerRes groups the resulting values of PutContainer operation. type PutContainerRes struct { - cliRes *client.ResContainerPut + cnr cid.ID } // ID returns identifier of the created container. -func (x PutContainerRes) ID() *cid.ID { - return x.cliRes.ID() +func (x PutContainerRes) ID() cid.ID { + return x.cnr } // PutContainer sends a request to save the container in NeoFS. @@ -94,7 +93,15 @@ func (x PutContainerRes) ID() *cid.ID { // // Returns any error which prevented the operation from completing correctly in error return. func PutContainer(prm PutContainerPrm) (res PutContainerRes, err error) { - res.cliRes, err = prm.cli.ContainerPut(context.Background(), prm.PrmContainerPut) + cliRes, err := prm.cli.ContainerPut(context.Background(), prm.PrmContainerPut) + if err == nil { + cnr := cliRes.ID() + if cnr == nil { + err = errors.New("missing container ID in response") + } else { + res.cnr = *cnr + } + } return } @@ -306,11 +313,11 @@ func (x *PutObjectPrm) SetPayloadReader(rdr io.Reader) { // PutObjectRes groups the resulting values of PutObject operation. type PutObjectRes struct { - id *oidSDK.ID + id oid.ID } // ID returns identifier of the created object. -func (x PutObjectRes) ID() *oidSDK.ID { +func (x PutObjectRes) ID() oid.ID { return x.id } @@ -382,20 +389,18 @@ func PutObject(prm PutObjectPrm) (*PutObjectRes, error) { } } - res, err := wrt.Close() + cliRes, err := wrt.Close() if err != nil { // here err already carries both status and client errors return nil, fmt.Errorf("client failure: %w", err) } - var id oidSDK.ID + var res PutObjectRes - if !res.ReadStoredObjectID(&id) { + if !cliRes.ReadStoredObjectID(&res.id) { return nil, errors.New("missing ID of the stored object") } - return &PutObjectRes{ - id: &id, - }, nil + return &res, nil } // DeleteObjectPrm groups parameters of DeleteObject operation. @@ -406,12 +411,12 @@ type DeleteObjectPrm struct { // DeleteObjectRes groups the resulting values of DeleteObject operation. type DeleteObjectRes struct { - addrTombstone *addressSDK.Address + tomb oid.ID } -// TombstoneAddress returns the address of the created object with tombstone. -func (x DeleteObjectRes) TombstoneAddress() *addressSDK.Address { - return x.addrTombstone +// Tombstone returns the ID of the created object with tombstone. +func (x DeleteObjectRes) Tombstone() oid.ID { + return x.tomb } // DeleteObject marks an object to be removed from NeoFS through tombstone placement. @@ -419,15 +424,8 @@ func (x DeleteObjectRes) TombstoneAddress() *addressSDK.Address { // Returns any error which prevented the operation from completing correctly in error return. func DeleteObject(prm DeleteObjectPrm) (*DeleteObjectRes, error) { var delPrm client.PrmObjectDelete - - cnr, ok := prm.objAddr.ContainerID() - if ok { - delPrm.FromContainer(cnr) - } - - if id, ok := prm.objAddr.ObjectID(); ok { - delPrm.ByID(id) - } + delPrm.FromContainer(prm.objAddr.Container()) + delPrm.ByID(prm.objAddr.Object()) if prm.sessionToken != nil { delPrm.WithinSession(*prm.sessionToken) @@ -444,18 +442,14 @@ func DeleteObject(prm DeleteObjectPrm) (*DeleteObjectRes, error) { return nil, fmt.Errorf("remove object via client: %w", err) } - var id oidSDK.ID + var id oid.ID if !cliRes.ReadTombstoneID(&id) { return nil, errors.New("object removed but tombstone ID is missing") } - var addr addressSDK.Address - addr.SetObjectID(id) - addr.SetContainerID(cnr) - return &DeleteObjectRes{ - addrTombstone: &addr, + tomb: id, }, nil } @@ -492,14 +486,8 @@ func (x GetObjectRes) Header() *object.Object { // For raw reading, returns *object.SplitInfoError error if object is virtual. func GetObject(prm GetObjectPrm) (*GetObjectRes, error) { var getPrm client.PrmObjectGet - - if id, ok := prm.objAddr.ContainerID(); ok { - getPrm.FromContainer(id) - } - - if id, ok := prm.objAddr.ObjectID(); ok { - getPrm.ByID(id) - } + getPrm.FromContainer(prm.objAddr.Container()) + getPrm.ByID(prm.objAddr.Object()) if prm.sessionToken != nil { getPrm.WithinSession(*prm.sessionToken) @@ -574,14 +562,8 @@ func (x HeadObjectRes) Header() *object.Object { // For raw reading, returns *object.SplitInfoError error if object is virtual. func HeadObject(prm HeadObjectPrm) (*HeadObjectRes, error) { var cliPrm client.PrmObjectHead - - if id, ok := prm.objAddr.ContainerID(); ok { - cliPrm.FromContainer(id) - } - - if id, ok := prm.objAddr.ObjectID(); ok { - cliPrm.ByID(id) - } + cliPrm.FromContainer(prm.objAddr.Container()) + cliPrm.ByID(prm.objAddr.Object()) if prm.sessionToken != nil { cliPrm.WithinSession(*prm.sessionToken) @@ -632,11 +614,11 @@ func (x *SearchObjectsPrm) SetFilters(filters object.SearchFilters) { // SearchObjectsRes groups the resulting values of SearchObjects operation. type SearchObjectsRes struct { - ids []oidSDK.ID + ids []oid.ID } // IDList returns identifiers of the matched objects. -func (x SearchObjectsRes) IDList() []oidSDK.ID { +func (x SearchObjectsRes) IDList() []oid.ID { return x.ids } @@ -645,11 +627,7 @@ func (x SearchObjectsRes) IDList() []oidSDK.ID { // Returns any error which prevented the operation from completing correctly in error return. func SearchObjects(prm SearchObjectsPrm) (*SearchObjectsRes, error) { var cliPrm client.PrmObjectSearch - - if prm.cnrID != nil { - cliPrm.InContainer(*prm.cnrID) - } - + cliPrm.InContainer(prm.cnrID) cliPrm.SetFilters(prm.filters) if prm.sessionToken != nil { @@ -671,8 +649,8 @@ func SearchObjects(prm SearchObjectsPrm) (*SearchObjectsRes, error) { return nil, fmt.Errorf("init object search: %w", err) } - buf := make([]oidSDK.ID, 10) - var list []oidSDK.ID + buf := make([]oid.ID, 10) + var list []oid.ID var n int var ok bool @@ -739,14 +717,8 @@ func (x HashPayloadRangesRes) HashList() [][]byte { // Returns an error if number of received hashes differs with the number of requested ranges. func HashPayloadRanges(prm HashPayloadRangesPrm) (*HashPayloadRangesRes, error) { var cliPrm client.PrmObjectHash - - if id, ok := prm.objAddr.ContainerID(); ok { - cliPrm.FromContainer(id) - } - - if id, ok := prm.objAddr.ObjectID(); ok { - cliPrm.ByID(id) - } + cliPrm.FromContainer(prm.objAddr.Container()) + cliPrm.ByID(prm.objAddr.Object()) if prm.local { cliPrm.MarkLocal() @@ -813,14 +785,8 @@ type PayloadRangeRes struct{} // For raw reading, returns *object.SplitInfoError error if object is virtual. func PayloadRange(prm PayloadRangePrm) (*PayloadRangeRes, error) { var cliPrm client.PrmObjectRange - - if id, ok := prm.objAddr.ContainerID(); ok { - cliPrm.FromContainer(id) - } - - if id, ok := prm.objAddr.ObjectID(); ok { - cliPrm.ByID(id) - } + cliPrm.FromContainer(prm.objAddr.Container()) + cliPrm.ByID(prm.objAddr.Object()) if prm.sessionToken != nil { cliPrm.WithinSession(*prm.sessionToken) diff --git a/cmd/neofs-cli/internal/client/prm.go b/cmd/neofs-cli/internal/client/prm.go index d4622116..90f585db 100644 --- a/cmd/neofs-cli/internal/client/prm.go +++ b/cmd/neofs-cli/internal/client/prm.go @@ -6,7 +6,7 @@ import ( "github.com/nspcc-dev/neofs-sdk-go/bearer" "github.com/nspcc-dev/neofs-sdk-go/client" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/nspcc-dev/neofs-sdk-go/session" ) @@ -22,11 +22,11 @@ func (x *commonPrm) SetClient(cli *client.Client) { } type containerIDPrm struct { - cnrID *cid.ID + cnrID cid.ID } // SetContainerID sets the container identifier. -func (x *containerIDPrm) SetContainerID(id *cid.ID) { +func (x *containerIDPrm) SetContainerID(id cid.ID) { x.cnrID = id } @@ -40,10 +40,10 @@ func (x *bearerTokenPrm) SetBearerToken(tok *bearer.Token) { } type objectAddressPrm struct { - objAddr *addressSDK.Address + objAddr oid.Address } -func (x *objectAddressPrm) SetAddress(addr *addressSDK.Address) { +func (x *objectAddressPrm) SetAddress(addr oid.Address) { x.objAddr = addr } diff --git a/cmd/neofs-cli/internal/common/token.go b/cmd/neofs-cli/internal/common/token.go index 5300b5f5..1a58a551 100644 --- a/cmd/neofs-cli/internal/common/token.go +++ b/cmd/neofs-cli/internal/common/token.go @@ -2,6 +2,7 @@ package common import ( "encoding/json" + "fmt" "os" "github.com/nspcc-dev/neofs-sdk-go/bearer" @@ -33,13 +34,24 @@ func ReadBearerToken(cmd *cobra.Command, flagname string) *bearer.Token { return &tok } -// ReadSessionToken reads session token as JSON file with session token -// from path provided in a specified flag. +// ReadSessionToken calls ReadSessionTokenErr and exists on error. func ReadSessionToken(cmd *cobra.Command, dst json.Unmarshaler, fPath string) { + ExitOnErr(cmd, "", ReadSessionTokenErr(dst, fPath)) +} + +// ReadSessionTokenErr reads session token as JSON file with session token +// from path provided in a specified flag. +func ReadSessionTokenErr(dst json.Unmarshaler, fPath string) error { // try to read session token from file data, err := os.ReadFile(fPath) - ExitOnErr(cmd, "could not open file with session token: %w", err) + if err != nil { + return fmt.Errorf("could not open file with session token <%s>: %w", fPath, err) + } err = dst.UnmarshalJSON(data) - ExitOnErr(cmd, "could not unmarshal session token from file: %w", err) + if err != nil { + return fmt.Errorf("could not unmarshal session token from file: %w", err) + } + + return nil } diff --git a/cmd/neofs-cli/modules/accounting/balance.go b/cmd/neofs-cli/modules/accounting/balance.go index e4048b7f..583b2b4b 100644 --- a/cmd/neofs-cli/modules/accounting/balance.go +++ b/cmd/neofs-cli/modules/accounting/balance.go @@ -24,22 +24,22 @@ var accountingBalanceCmd = &cobra.Command{ Short: "Get internal balance of NeoFS account", Long: `Get internal balance of NeoFS account`, Run: func(cmd *cobra.Command, args []string) { - var oid user.ID + var idUser user.ID pk := key.GetOrGenerate(cmd) balanceOwner, _ := cmd.Flags().GetString(ownerFlag) if balanceOwner == "" { - user.IDFromKey(&oid, pk.PublicKey) + user.IDFromKey(&idUser, pk.PublicKey) } else { - common.ExitOnErr(cmd, "can't decode owner ID wallet address: %w", oid.DecodeString(balanceOwner)) + common.ExitOnErr(cmd, "can't decode owner ID wallet address: %w", idUser.DecodeString(balanceOwner)) } cli := internalclient.GetSDKClientByFlag(cmd, pk, commonflags.RPC) var prm internalclient.BalanceOfPrm prm.SetClient(cli) - prm.SetAccount(oid) + prm.SetAccount(idUser) res, err := internalclient.BalanceOf(prm) common.ExitOnErr(cmd, "rpc error: %w", err) diff --git a/cmd/neofs-cli/modules/container.go b/cmd/neofs-cli/modules/container.go index 34a39c3d..1bba5812 100644 --- a/cmd/neofs-cli/modules/container.go +++ b/cmd/neofs-cli/modules/container.go @@ -22,7 +22,6 @@ import ( "github.com/nspcc-dev/neofs-sdk-go/eacl" "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" "github.com/nspcc-dev/neofs-sdk-go/policy" "github.com/nspcc-dev/neofs-sdk-go/session" subnetid "github.com/nspcc-dev/neofs-sdk-go/subnet/id" @@ -205,7 +204,7 @@ It will be stored in sidechain when inner ring will accepts it.`, if containerAwait { cmd.Println("awaiting...") - getPrm.SetContainer(*id) + getPrm.SetContainer(id) for i := 0; i < awaitTimeout; i++ { time.Sleep(1 * time.Second) @@ -288,11 +287,9 @@ var listContainerObjectsCmd = &cobra.Command{ var prm internalclient.SearchObjectsPrm - sessionObjectCtxAddress := addressSDK.NewAddress() - sessionObjectCtxAddress.SetContainerID(*id) - prepareSessionPrm(cmd, sessionObjectCtxAddress, &prm) + prepareSessionPrm(cmd, *id, nil, &prm) prepareObjectPrm(cmd, &prm) - prm.SetContainerID(id) + prm.SetContainerID(*id) prm.SetFilters(*filters) res, err := internalclient.SearchObjects(prm) @@ -301,7 +298,7 @@ var listContainerObjectsCmd = &cobra.Command{ objectIDs := res.IDList() for i := range objectIDs { - cmd.Println(objectIDs[i].String()) + cmd.Println(objectIDs[i]) } }, } @@ -603,7 +600,7 @@ func init() { func prettyPrintContainerList(cmd *cobra.Command, list []cid.ID) { for i := range list { - cmd.Println(list[i].String()) + cmd.Println(list[i]) } } diff --git a/cmd/neofs-cli/modules/control/drop_objects.go b/cmd/neofs-cli/modules/control/drop_objects.go index 6651ded4..83957739 100644 --- a/cmd/neofs-cli/modules/control/drop_objects.go +++ b/cmd/neofs-cli/modules/control/drop_objects.go @@ -1,14 +1,11 @@ package control import ( - "fmt" - rawclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client" "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common" "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags" "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key" "github.com/nspcc-dev/neofs-node/pkg/services/control" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" "github.com/spf13/cobra" ) @@ -22,20 +19,10 @@ var dropObjectsCmd = &cobra.Command{ pk := key.Get(cmd) dropObjectsList, _ := cmd.Flags().GetStringSlice(dropObjectsFlag) - binAddrList := make([][]byte, 0, len(dropObjectsList)) + binAddrList := make([][]byte, len(dropObjectsList)) for i := range dropObjectsList { - a := addressSDK.NewAddress() - - err := a.Parse(dropObjectsList[i]) - if err != nil { - common.ExitOnErr(cmd, "", fmt.Errorf("could not parse address #%d: %w", i, err)) - } - - binAddr, err := a.Marshal() - common.ExitOnErr(cmd, "could not marshal the address: %w", err) - - binAddrList = append(binAddrList, binAddr) + binAddrList[i] = []byte(dropObjectsList[i]) } body := new(control.DropObjectsRequest_Body) diff --git a/cmd/neofs-cli/modules/control/util.go b/cmd/neofs-cli/modules/control/util.go index 5f22ae8f..38925121 100644 --- a/cmd/neofs-cli/modules/control/util.go +++ b/cmd/neofs-cli/modules/control/util.go @@ -24,16 +24,13 @@ func verifyResponse(cmd *cobra.Command, GetSign() []byte }, body interface { - StableMarshal([]byte) ([]byte, error) + StableMarshal([]byte) []byte }, ) { if sigControl == nil { common.ExitOnErr(cmd, "", errors.New("missing response signature")) } - bodyData, err := body.StableMarshal(nil) - common.ExitOnErr(cmd, "marshal response body: %w", err) - // TODO(@cthulhu-rider): #1387 use Signature message from NeoFS API to avoid conversion var sigV2 refs.Signature sigV2.SetScheme(refs.ECDSA_SHA512) @@ -43,7 +40,7 @@ func verifyResponse(cmd *cobra.Command, var sig neofscrypto.Signature sig.ReadFromV2(sigV2) - if !sig.Verify(bodyData) { + if !sig.Verify(body.StableMarshal(nil)) { common.ExitOnErr(cmd, "", errors.New("invalid response signature")) } } diff --git a/cmd/neofs-cli/modules/lock.go b/cmd/neofs-cli/modules/lock.go index 56ff107e..39119716 100644 --- a/cmd/neofs-cli/modules/lock.go +++ b/cmd/neofs-cli/modules/lock.go @@ -7,7 +7,6 @@ import ( "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common" "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags" "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key" - objectcore "github.com/nspcc-dev/neofs-node/pkg/core/object" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" "github.com/nspcc-dev/neofs-sdk-go/object" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" @@ -51,7 +50,7 @@ var cmdObjectLock = &cobra.Command{ var prm internalclient.PutObjectPrm - prepareSessionPrmWithOwner(cmd, objectcore.AddressOf(obj), key, idOwner, &prm) + prepareSessionPrmWithOwner(cmd, cnr, nil, key, *idOwner, &prm) prepareObjectPrm(cmd, &prm) prm.SetHeader(obj) diff --git a/cmd/neofs-cli/modules/object.go b/cmd/neofs-cli/modules/object.go index 8e2275fe..b2dacad2 100644 --- a/cmd/neofs-cli/modules/object.go +++ b/cmd/neofs-cli/modules/object.go @@ -25,8 +25,7 @@ import ( "github.com/nspcc-dev/neofs-sdk-go/checksum" 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" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/nspcc-dev/neofs-sdk-go/session" "github.com/nspcc-dev/neofs-sdk-go/user" "github.com/spf13/cobra" @@ -317,24 +316,25 @@ type clientKeySession interface { SetSessionToken(*session.Object) } -func prepareSessionPrm(cmd *cobra.Command, addr *addressSDK.Address, prms ...clientKeySession) { +func prepareSessionPrm(cmd *cobra.Command, cnr cid.ID, obj *oid.ID, prms ...clientKeySession) { pk := key.GetOrGenerate(cmd) - prepareSessionPrmWithKey(cmd, addr, pk, prms...) + prepareSessionPrmWithKey(cmd, cnr, obj, pk, prms...) } -func prepareSessionPrmWithKey(cmd *cobra.Command, addr *addressSDK.Address, key *ecdsa.PrivateKey, prms ...clientKeySession) { +func prepareSessionPrmWithKey(cmd *cobra.Command, cnr cid.ID, obj *oid.ID, key *ecdsa.PrivateKey, prms ...clientKeySession) { ownerID, err := getOwnerID(key) common.ExitOnErr(cmd, "owner ID from key: %w", err) - prepareSessionPrmWithOwner(cmd, addr, key, ownerID, prms...) + prepareSessionPrmWithOwner(cmd, cnr, obj, key, *ownerID, prms...) } func prepareSessionPrmWithOwner( cmd *cobra.Command, - addr *addressSDK.Address, + cnr cid.ID, + obj *oid.ID, key *ecdsa.PrivateKey, - ownerID *user.ID, + ownerID user.ID, prms ...clientKeySession, ) { cli := internalclient.GetSDKClientByFlag(cmd, key, commonflags.RPC) @@ -373,7 +373,11 @@ func prepareSessionPrmWithOwner( panic("invalid client parameter type") } - tok.ApplyTo(*addr) + tok.BindContainer(cnr) + + if obj != nil { + tok.LimitByObject(*obj) + } err := tok.Sign(*key) common.ExitOnErr(cmd, "session token signing: %w", err) @@ -413,8 +417,9 @@ func putObject(cmd *cobra.Command, _ []string) { ownerID, err := getOwnerID(pk) common.ExitOnErr(cmd, "", err) - cnr, err := getCID(cmd) - common.ExitOnErr(cmd, "", err) + + var cnr cid.ID + common.ExitOnErr(cmd, "", readCID(cmd, &cnr)) filename := cmd.Flag("file").Value.String() f, err := os.OpenFile(filename, os.O_RDONLY, os.ModePerm) @@ -447,7 +452,7 @@ func putObject(cmd *cobra.Command, _ []string) { } obj := object.New() - obj.SetContainerID(*cnr) + obj.SetContainerID(cnr) obj.SetOwnerID(ownerID) obj.SetAttributes(attrs...) @@ -460,9 +465,7 @@ func putObject(cmd *cobra.Command, _ []string) { var prm internalclient.PutObjectPrm - sessionObjectCtxAddress := addressSDK.NewAddress() - sessionObjectCtxAddress.SetContainerID(*cnr) - prepareSessionPrmWithOwner(cmd, sessionObjectCtxAddress, pk, ownerID, &prm) + prepareSessionPrmWithOwner(cmd, cnr, nil, pk, *ownerID, &prm) prepareObjectPrm(cmd, &prm) prm.SetHeader(obj) @@ -495,44 +498,37 @@ func putObject(cmd *cobra.Command, _ []string) { } func deleteObject(cmd *cobra.Command, _ []string) { - objAddr, err := getObjectAddress(cmd) + var cnr cid.ID + var obj oid.ID + + err := readObjectAddress(cmd, &cnr, &obj) common.ExitOnErr(cmd, "", err) var prm internalclient.DeleteObjectPrm - prepareSessionPrm(cmd, objAddr, &prm) + prepareSessionPrm(cmd, cnr, &obj, &prm) prepareObjectPrm(cmd, &prm) - prm.SetAddress(objAddr) + + var addr oid.Address + addr.SetContainer(cnr) + addr.SetObject(obj) + + prm.SetAddress(addr) res, err := internalclient.DeleteObject(prm) common.ExitOnErr(cmd, "rpc error: %w", err) - tombstoneAddr := res.TombstoneAddress() + tomb := res.Tombstone() cmd.Println("Object removed successfully.") - - const strEmpty = "" - var strID, strCnr string - - id, ok := tombstoneAddr.ObjectID() - if ok { - strID = id.String() - } else { - strID = strEmpty - } - - cnr, ok := tombstoneAddr.ContainerID() - if ok { - strCnr = cnr.String() - } else { - strCnr = strEmpty - } - - cmd.Printf(" ID: %s\n CID: %s\n", strID, strCnr) + cmd.Printf(" ID: %s\n CID: %s\n", tomb, cnr) } func getObject(cmd *cobra.Command, _ []string) { - objAddr, err := getObjectAddress(cmd) + var cnr cid.ID + var obj oid.ID + + err := readObjectAddress(cmd, &cnr, &obj) common.ExitOnErr(cmd, "", err) var out io.Writer @@ -552,8 +548,13 @@ func getObject(cmd *cobra.Command, _ []string) { var prm internalclient.GetObjectPrm - prepareSessionPrm(cmd, objAddr, &prm) + prepareSessionPrm(cmd, cnr, &obj, &prm) prepareObjectPrmRaw(cmd, &prm) + + var objAddr oid.Address + objAddr.SetContainer(cnr) + objAddr.SetObject(obj) + prm.SetAddress(objAddr) var p *pb.ProgressBar @@ -598,15 +599,23 @@ func getObject(cmd *cobra.Command, _ []string) { } func getObjectHeader(cmd *cobra.Command, _ []string) { - objAddr, err := getObjectAddress(cmd) + var cnr cid.ID + var obj oid.ID + + err := readObjectAddress(cmd, &cnr, &obj) common.ExitOnErr(cmd, "", err) mainOnly, _ := cmd.Flags().GetBool("main-only") var prm internalclient.HeadObjectPrm - prepareSessionPrm(cmd, objAddr, &prm) + prepareSessionPrm(cmd, cnr, &obj, &prm) prepareObjectPrmRaw(cmd, &prm) + + var objAddr oid.Address + objAddr.SetContainer(cnr) + objAddr.SetObject(obj) + prm.SetAddress(objAddr) prm.SetMainOnlyFlag(mainOnly) @@ -624,7 +633,9 @@ func getObjectHeader(cmd *cobra.Command, _ []string) { } func searchObject(cmd *cobra.Command, _ []string) { - cnr, err := getCID(cmd) + var cnr cid.ID + + err := readCID(cmd, &cnr) common.ExitOnErr(cmd, "", err) sf, err := parseSearchFilters(cmd) @@ -632,9 +643,7 @@ func searchObject(cmd *cobra.Command, _ []string) { var prm internalclient.SearchObjectsPrm - sessionObjectCtxAddress := addressSDK.NewAddress() - sessionObjectCtxAddress.SetContainerID(*cnr) - prepareSessionPrm(cmd, sessionObjectCtxAddress, &prm) + prepareSessionPrm(cmd, cnr, nil, &prm) prepareObjectPrm(cmd, &prm) prm.SetContainerID(cnr) prm.SetFilters(sf) @@ -646,12 +655,15 @@ func searchObject(cmd *cobra.Command, _ []string) { cmd.Printf("Found %d objects.\n", len(ids)) for i := range ids { - cmd.Println(ids[i].String()) + cmd.Println(ids[i]) } } func getObjectHash(cmd *cobra.Command, _ []string) { - objAddr, err := getObjectAddress(cmd) + var cnr cid.ID + var obj oid.ID + + err := readObjectAddress(cmd, &cnr, &obj) common.ExitOnErr(cmd, "", err) ranges, err := getRangeList(cmd) common.ExitOnErr(cmd, "", err) @@ -677,9 +689,13 @@ func getObjectHash(cmd *cobra.Command, _ []string) { objPrms = append(objPrms, &headPrm) } - prepareSessionPrm(cmd, objAddr, sesPrms...) + prepareSessionPrm(cmd, cnr, &obj, sesPrms...) prepareObjectPrm(cmd, objPrms...) + var objAddr oid.Address + objAddr.SetContainer(cnr) + objAddr.SetObject(obj) + tz := typ == hashTz if fullHash { @@ -792,10 +808,10 @@ func parseSearchFilters(cmd *cobra.Command) (object.SearchFilters, error) { fs.AddPhyFilter() } - oid, _ := cmd.Flags().GetString(searchOIDFlag) - if oid != "" { - var id oidSDK.ID - if err := id.DecodeString(oid); err != nil { + strObj, _ := cmd.Flags().GetString(searchOIDFlag) + if strObj != "" { + var id oid.ID + if err := id.DecodeString(strObj); err != nil { return nil, fmt.Errorf("could not parse object ID: %w", err) } @@ -879,42 +895,36 @@ func parseObjectNotifications(cmd *cobra.Command) (*object.NotificationInfo, err return ni, nil } -func getCID(cmd *cobra.Command) (*cid.ID, error) { - var id cid.ID - - err := id.DecodeString(cmd.Flag("cid").Value.String()) +func readCID(cmd *cobra.Command, cnr *cid.ID) error { + err := cnr.DecodeString(cmd.Flag("cid").Value.String()) if err != nil { - return nil, fmt.Errorf("could not parse container ID: %w", err) + return fmt.Errorf("decode container ID string: %w", err) } - return &id, nil + return nil } -func getOID(cmd *cobra.Command) (*oidSDK.ID, error) { - var oid oidSDK.ID - - err := oid.DecodeString(cmd.Flag("oid").Value.String()) +func readOID(cmd *cobra.Command, obj *oid.ID) error { + err := obj.DecodeString(cmd.Flag("oid").Value.String()) if err != nil { - return nil, fmt.Errorf("could not parse object ID: %w", err) + return fmt.Errorf("decode container ID string: %w", err) } - return &oid, nil + return nil } -func getObjectAddress(cmd *cobra.Command) (*addressSDK.Address, error) { - cnr, err := getCID(cmd) +func readObjectAddress(cmd *cobra.Command, cnr *cid.ID, obj *oid.ID) error { + err := readCID(cmd, cnr) if err != nil { - return nil, err - } - oid, err := getOID(cmd) - if err != nil { - return nil, err + return err } - objAddr := addressSDK.NewAddress() - objAddr.SetContainerID(*cnr) - objAddr.SetObjectID(*oid) - return objAddr, nil + err = readOID(cmd, obj) + if err != nil { + return err + } + + return nil } func getRangeList(cmd *cobra.Command) ([]*object.Range, error) { @@ -988,7 +998,7 @@ func printChecksum(cmd *cobra.Command, name string, recv func() (checksum.Checks cmd.Printf("%s: %s\n", name, strVal) } -func printObjectID(cmd *cobra.Command, recv func() (oidSDK.ID, bool)) { +func printObjectID(cmd *cobra.Command, recv func() (oid.ID, bool)) { var strID string id, ok := recv() @@ -1044,8 +1054,8 @@ func printSplitHeader(cmd *cobra.Command, obj *object.Object) error { cmd.Printf("Split ID: %s\n", splitID) } - if oid, ok := obj.ParentID(); ok { - cmd.Printf("Split ParentID: %s\n", oid) + if par, ok := obj.ParentID(); ok { + cmd.Printf("Split ParentID: %s\n", par) } if prev, ok := obj.PreviousID(); ok { @@ -1053,7 +1063,7 @@ func printSplitHeader(cmd *cobra.Command, obj *object.Object) error { } for _, child := range obj.Children() { - cmd.Printf("Split ChildID: %s\n", child.String()) + cmd.Printf("Split ChildID: %s\n", child) } if signature := obj.Signature(); signature != nil { @@ -1099,8 +1109,10 @@ func marshalHeader(cmd *cobra.Command, hdr *object.Object) ([]byte, error) { } func getObjectRange(cmd *cobra.Command, _ []string) { - objAddr, err := getObjectAddress(cmd) - common.ExitOnErr(cmd, "", err) + var cnr cid.ID + var obj oid.ID + + common.ExitOnErr(cmd, "", readObjectAddress(cmd, &cnr, &obj)) ranges, err := getRangeList(cmd) common.ExitOnErr(cmd, "", err) @@ -1127,9 +1139,14 @@ func getObjectRange(cmd *cobra.Command, _ []string) { var prm internalclient.PayloadRangePrm - prepareSessionPrm(cmd, objAddr, &prm) + prepareSessionPrm(cmd, cnr, &obj, &prm) prepareObjectPrmRaw(cmd, &prm) - prm.SetAddress(objAddr) + + var addr oid.Address + addr.SetContainer(cnr) + addr.SetObject(obj) + + prm.SetAddress(addr) prm.SetRange(ranges[0]) prm.SetPayloadWriter(out) @@ -1183,10 +1200,10 @@ func marshalSplitInfo(cmd *cobra.Command, info *object.SplitInfo) ([]byte, error b.WriteString("Split ID: " + splitID.String() + "\n") } if link, ok := info.Link(); ok { - b.WriteString("Linking object: " + link.String() + "\n") + b.WriteString(fmt.Sprintf("Linking object: %s\n", link)) } if last, ok := info.LastPart(); ok { - b.WriteString("Last object: " + last.String() + "\n") + b.WriteString(fmt.Sprintf("Last object: %s\n", last)) } return b.Bytes(), nil } diff --git a/cmd/neofs-cli/modules/storagegroup.go b/cmd/neofs-cli/modules/storagegroup.go index 448fd47c..36e3fe00 100644 --- a/cmd/neofs-cli/modules/storagegroup.go +++ b/cmd/neofs-cli/modules/storagegroup.go @@ -11,9 +11,9 @@ import ( "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags" "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key" "github.com/nspcc-dev/neofs-node/pkg/services/object_manager/storagegroup" + 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" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" storagegroupAPI "github.com/nspcc-dev/neofs-sdk-go/storagegroup" "github.com/nspcc-dev/neofs-sdk-go/user" "github.com/spf13/cobra" @@ -141,12 +141,15 @@ func init() { type sgHeadReceiver struct { cmd *cobra.Command key *ecdsa.PrivateKey - ownerID *user.ID + ownerID user.ID prm internalclient.HeadObjectPrm } -func (c sgHeadReceiver) Head(addr *addressSDK.Address) (interface{}, error) { - prepareSessionPrmWithOwner(c.cmd, addr, c.key, c.ownerID, &c.prm) +func (c sgHeadReceiver) Head(addr oid.Address) (interface{}, error) { + obj := addr.Object() + + prepareSessionPrmWithOwner(c.cmd, addr.Container(), &obj, c.key, c.ownerID, &c.prm) + c.prm.SetAddress(addr) res, err := internalclient.HeadObject(c.prm) @@ -169,10 +172,12 @@ func putSG(cmd *cobra.Command, _ []string) { ownerID, err := getOwnerID(pk) common.ExitOnErr(cmd, "", err) - cnr, err := getCID(cmd) + var cnr cid.ID + + err = readCID(cmd, &cnr) common.ExitOnErr(cmd, "", err) - members := make([]oidSDK.ID, len(sgMembers)) + members := make([]oid.ID, len(sgMembers)) for i := range sgMembers { err = members[i].DecodeString(sgMembers[i]) @@ -184,9 +189,7 @@ func putSG(cmd *cobra.Command, _ []string) { putPrm internalclient.PutObjectPrm ) - sessionObjectCtxAddress := addressSDK.NewAddress() - sessionObjectCtxAddress.SetContainerID(*cnr) - prepareSessionPrmWithOwner(cmd, sessionObjectCtxAddress, pk, ownerID, &putPrm) + prepareSessionPrmWithOwner(cmd, cnr, nil, pk, *ownerID, &putPrm) prepareObjectPrm(cmd, &headPrm, &putPrm) headPrm.SetRawFlag(true) @@ -194,7 +197,7 @@ func putSG(cmd *cobra.Command, _ []string) { sg, err := storagegroup.CollectMembers(sgHeadReceiver{ cmd: cmd, key: pk, - ownerID: ownerID, + ownerID: *ownerID, prm: headPrm, }, cnr, members) common.ExitOnErr(cmd, "could not collect storage group members: %w", err) @@ -203,7 +206,7 @@ func putSG(cmd *cobra.Command, _ []string) { common.ExitOnErr(cmd, "could not marshal storage group: %w", err) obj := object.New() - obj.SetContainerID(*cnr) + obj.SetContainerID(cnr) obj.SetOwnerID(ownerID) obj.SetType(object.TypeStorageGroup) @@ -217,32 +220,34 @@ func putSG(cmd *cobra.Command, _ []string) { cmd.Printf(" ID: %s\n CID: %s\n", res.ID(), cnr) } -func getSGID() (*oidSDK.ID, error) { - var oid oidSDK.ID - err := oid.DecodeString(sgID) +func getSGID() (*oid.ID, error) { + var obj oid.ID + err := obj.DecodeString(sgID) if err != nil { return nil, fmt.Errorf("could not parse storage group ID: %w", err) } - return &oid, nil + return &obj, nil } func getSG(cmd *cobra.Command, _ []string) { - cnr, err := getCID(cmd) + var cnr cid.ID + + err := readCID(cmd, &cnr) common.ExitOnErr(cmd, "", err) id, err := getSGID() common.ExitOnErr(cmd, "", err) - addr := addressSDK.NewAddress() - addr.SetContainerID(*cnr) - addr.SetObjectID(*id) + var addr oid.Address + addr.SetContainer(cnr) + addr.SetObject(*id) buf := bytes.NewBuffer(nil) var prm internalclient.GetObjectPrm - prepareSessionPrm(cmd, addr, &prm) + prepareSessionPrm(cmd, cnr, id, &prm) prepareObjectPrmRaw(cmd, &prm) prm.SetAddress(addr) prm.SetPayloadWriter(buf) @@ -263,20 +268,20 @@ func getSG(cmd *cobra.Command, _ []string) { cmd.Println("Members:") for i := range members { - cmd.Printf("\t%s\n", members[i].String()) + cmd.Printf("\t%s\n", members[i]) } } } func listSG(cmd *cobra.Command, _ []string) { - cnr, err := getCID(cmd) + var cnr cid.ID + + err := readCID(cmd, &cnr) common.ExitOnErr(cmd, "", err) var prm internalclient.SearchObjectsPrm - sessionObjectCtxAddress := addressSDK.NewAddress() - sessionObjectCtxAddress.SetContainerID(*cnr) - prepareSessionPrm(cmd, sessionObjectCtxAddress, &prm) + prepareSessionPrm(cmd, cnr, nil, &prm) prepareObjectPrm(cmd, &prm) prm.SetContainerID(cnr) prm.SetFilters(storagegroup.SearchQuery()) @@ -289,41 +294,34 @@ func listSG(cmd *cobra.Command, _ []string) { cmd.Printf("Found %d storage groups.\n", len(ids)) for i := range ids { - cmd.Println(ids[i].String()) + cmd.Println(ids[i]) } } func delSG(cmd *cobra.Command, _ []string) { - cnr, err := getCID(cmd) + var cnr cid.ID + + err := readCID(cmd, &cnr) common.ExitOnErr(cmd, "", err) id, err := getSGID() common.ExitOnErr(cmd, "", err) - addr := addressSDK.NewAddress() - addr.SetContainerID(*cnr) - addr.SetObjectID(*id) + var addr oid.Address + addr.SetContainer(cnr) + addr.SetObject(*id) var prm internalclient.DeleteObjectPrm - prepareSessionPrm(cmd, addr, &prm) + prepareSessionPrm(cmd, cnr, id, &prm) prepareObjectPrm(cmd, &prm) prm.SetAddress(addr) res, err := internalclient.DeleteObject(prm) common.ExitOnErr(cmd, "rpc error: %w", err) - tombstone := res.TombstoneAddress() - - var strID string - - idTomb, ok := tombstone.ObjectID() - if ok { - strID = idTomb.String() - } else { - strID = "" - } + tomb := res.Tombstone() cmd.Println("Storage group removed successfully.") - cmd.Printf(" Tombstone: %s\n", strID) + cmd.Printf(" Tombstone: %s\n", tomb) } diff --git a/cmd/neofs-lens/internal/commands/inspect/inspect.go b/cmd/neofs-lens/internal/commands/inspect/inspect.go index 6e9be63d..3b387c9f 100644 --- a/cmd/neofs-lens/internal/commands/inspect/inspect.go +++ b/cmd/neofs-lens/internal/commands/inspect/inspect.go @@ -9,7 +9,6 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/writecache" 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" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/spf13/cobra" ) @@ -57,8 +56,9 @@ func init() { } func objectInspectCmd(cmd *cobra.Command, _ []string) { - addr := addressSDK.NewAddress() - err := addr.Parse(vAddress) + var addr oid.Address + + err := addr.DecodeString(vAddress) common.ExitOnErr(cmd, common.Errf("invalid address argument: %w", err)) if vOut == "" && !vHeader { @@ -72,7 +72,7 @@ func objectInspectCmd(cmd *cobra.Command, _ []string) { defer db.Close() - data, err := writecache.Get(db, []byte(addr.String())) + data, err := writecache.Get(db, []byte(vAddress)) common.ExitOnErr(cmd, common.Errf("could not fetch object: %w", err)) printObjectInfo(cmd, data) return diff --git a/cmd/neofs-lens/internal/commands/list/list.go b/cmd/neofs-lens/internal/commands/list/list.go index a43599d7..18b8c562 100644 --- a/cmd/neofs-lens/internal/commands/list/list.go +++ b/cmd/neofs-lens/internal/commands/list/list.go @@ -1,12 +1,13 @@ package cmdlist import ( + "fmt" "io" common "github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/writecache" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/spf13/cobra" ) @@ -40,8 +41,8 @@ var Command = &cobra.Command{ // other targets can be supported w := cmd.OutOrStderr() - wAddr := func(addr *addressSDK.Address) error { - _, err := io.WriteString(w, addr.String()+"\n") + wAddr := func(addr oid.Address) error { + _, err := io.WriteString(w, fmt.Sprintf("%s\n", addr)) return err } diff --git a/cmd/neofs-node/cache.go b/cmd/neofs-node/cache.go index a0c66abd..74cac13e 100644 --- a/cmd/neofs-node/cache.go +++ b/cmd/neofs-node/cache.go @@ -141,7 +141,7 @@ func newCachedContainerStorage(v container.Source) *ttlContainerStorage { return nil, err } - return v.Get(&id) + return v.Get(id) }) return (*ttlContainerStorage)(lruCnrCache) @@ -149,8 +149,8 @@ func newCachedContainerStorage(v container.Source) *ttlContainerStorage { // Get returns container value from the cache. If value is missing in the cache // or expired, then it returns value from side chain and updates the cache. -func (s *ttlContainerStorage) Get(cid *cid.ID) (*containerSDK.Container, error) { - val, err := (*ttlNetCache)(s).get(cid.String()) +func (s *ttlContainerStorage) Get(cnr cid.ID) (*containerSDK.Container, error) { + val, err := (*ttlNetCache)(s).get(cnr.EncodeToString()) if err != nil { return nil, err } @@ -174,7 +174,7 @@ func newCachedEACLStorage(v eacl.Source) *ttlEACLStorage { return nil, err } - return v.GetEACL(&id) + return v.GetEACL(id) }) return (*ttlEACLStorage)(lruCnrCache) @@ -182,8 +182,8 @@ func newCachedEACLStorage(v eacl.Source) *ttlEACLStorage { // GetEACL returns eACL value from the cache. If value is missing in the cache // or expired, then it returns value from side chain and updates cache. -func (s *ttlEACLStorage) GetEACL(cid *cid.ID) (*eaclSDK.Table, error) { - val, err := (*ttlNetCache)(s).get(cid.String()) +func (s *ttlEACLStorage) GetEACL(cnr cid.ID) (*eaclSDK.Table, error) { + val, err := (*ttlNetCache)(s).get(cnr.EncodeToString()) if err != nil { return nil, err } @@ -192,8 +192,8 @@ func (s *ttlEACLStorage) GetEACL(cid *cid.ID) (*eaclSDK.Table, error) { } // InvalidateEACL removes cached eACL value. -func (s *ttlEACLStorage) InvalidateEACL(cid *cid.ID) { - (*ttlNetCache)(s).remove(cid.String()) +func (s *ttlEACLStorage) InvalidateEACL(cnr cid.ID) { + (*ttlNetCache)(s).remove(cnr.EncodeToString()) } type lruNetmapSource struct { @@ -270,11 +270,11 @@ func newCachedContainerLister(c *cntClient.Client) *ttlContainerLister { // List returns list of container IDs from the cache. If list is missing in the // cache or expired, then it returns container IDs from side chain and updates // the cache. -func (s *ttlContainerLister) List(id *user.ID) ([]*cid.ID, error) { +func (s *ttlContainerLister) List(id *user.ID) ([]cid.ID, error) { var str string if id != nil { - str = id.String() + str = id.EncodeToString() } val, err := (*ttlNetCache)(s).get(str) @@ -282,12 +282,12 @@ func (s *ttlContainerLister) List(id *user.ID) ([]*cid.ID, error) { return nil, err } - return val.([]*cid.ID), nil + return val.([]cid.ID), nil } // InvalidateContainerList removes cached list of container IDs. -func (s *ttlContainerLister) InvalidateContainerList(id *user.ID) { - (*ttlNetCache)(s).remove(id.String()) +func (s *ttlContainerLister) InvalidateContainerList(id user.ID) { + (*ttlNetCache)(s).remove(id.EncodeToString()) } type cachedIRFetcher ttlNetCache diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index 658bf26f..6ce5772e 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -54,7 +54,7 @@ import ( "google.golang.org/grpc" ) -const addressSize = 72 // 32 bytes oid, 32 bytes cid, 8 bytes protobuf encoding +const addressSize = 72 // 32 bytes object ID, 32 bytes container ID, 8 bytes protobuf encoding const maxMsgSize = 4 << 20 // transport msg limit 4 MiB diff --git a/cmd/neofs-node/container.go b/cmd/neofs-node/container.go index a29aba24..4e708089 100644 --- a/cmd/neofs-node/container.go +++ b/cmd/neofs-node/container.go @@ -329,8 +329,8 @@ type loadPlacementBuilder struct { cnrSrc containerCore.Source } -func (l *loadPlacementBuilder) BuildPlacement(epoch uint64, cid *cid.ID) ([]netmap.Nodes, error) { - cnrNodes, nm, err := l.buildPlacement(epoch, cid) +func (l *loadPlacementBuilder) BuildPlacement(epoch uint64, cnr cid.ID) ([]netmap.Nodes, error) { + cnrNodes, nm, err := l.buildPlacement(epoch, cnr) if err != nil { return nil, err } @@ -349,7 +349,7 @@ func (l *loadPlacementBuilder) BuildPlacement(epoch uint64, cid *cid.ID) ([]netm return placement, nil } -func (l *loadPlacementBuilder) buildPlacement(epoch uint64, idCnr *cid.ID) (netmap.ContainerNodes, *netmap.Netmap, error) { +func (l *loadPlacementBuilder) buildPlacement(epoch uint64, idCnr cid.ID) (netmap.ContainerNodes, *netmap.Netmap, error) { cnr, err := l.cnrSrc.Get(idCnr) if err != nil { return nil, nil, err @@ -400,7 +400,7 @@ func (d *localStorageLoad) Iterate(f loadcontroller.UsedSpaceFilter, h loadcontr ) a := containerSDK.NewAnnouncement() - a.SetContainerID(*idList[i]) + a.SetContainerID(idList[i]) a.SetUsedSpace(sz) if f != nil && !f(*a) { @@ -506,8 +506,8 @@ func (*containerOnlyKeyRemoteServerInfo) NumberOfAddresses() int { return 0 } -func (l *loadPlacementBuilder) isNodeFromContainerKey(epoch uint64, cid *cid.ID, key []byte) (bool, error) { - cnrNodes, _, err := l.buildPlacement(epoch, cid) +func (l *loadPlacementBuilder) isNodeFromContainerKey(epoch uint64, cnr cid.ID, key []byte) (bool, error) { + cnrNodes, _, err := l.buildPlacement(epoch, cnr) if err != nil { return false, err } @@ -530,7 +530,7 @@ func (c *usedSpaceService) processLoadValue(_ context.Context, a containerSDK.Us return errors.New("missing container ID in load announcement") } - fromCnr, err := c.loadPlacementBuilder.isNodeFromContainerKey(a.Epoch(), &cnr, route[0].PublicKey()) + fromCnr, err := c.loadPlacementBuilder.isNodeFromContainerKey(a.Epoch(), cnr, route[0].PublicKey()) if err != nil { return fmt.Errorf("could not verify that the sender belongs to the container: %w", err) } else if !fromCnr { @@ -557,19 +557,19 @@ type morphContainerReader struct { get containerCore.Source lister interface { - List(*user.ID) ([]*cid.ID, error) + List(*user.ID) ([]cid.ID, error) } } -func (x *morphContainerReader) Get(id *cid.ID) (*containerSDK.Container, error) { +func (x *morphContainerReader) Get(id cid.ID) (*containerSDK.Container, error) { return x.get.Get(id) } -func (x *morphContainerReader) GetEACL(id *cid.ID) (*eaclSDK.Table, error) { +func (x *morphContainerReader) GetEACL(id cid.ID) (*eaclSDK.Table, error) { return x.eacl.GetEACL(id) } -func (x *morphContainerReader) List(id *user.ID) ([]*cid.ID, error) { +func (x *morphContainerReader) List(id *user.ID) ([]cid.ID, error) { return x.lister.List(id) } @@ -587,8 +587,13 @@ func (m morphContainerWriter) Put(cnr *containerSDK.Container) (*cid.ID, error) return nil, err } + idOwner := cnr.OwnerID() + if idOwner == nil { + return nil, errors.New("missing container owner") + } + if m.cacheEnabled { - m.lists.InvalidateContainerList(cnr.OwnerID()) + m.lists.InvalidateContainerList(*idOwner) } return containerID, nil @@ -606,7 +611,7 @@ func (m morphContainerWriter) PutEACL(table *eaclSDK.Table) error { if m.cacheEnabled { id, _ := table.CID() - m.eacls.InvalidateEACL(&id) + m.eacls.InvalidateEACL(id) } return nil diff --git a/cmd/neofs-node/control.go b/cmd/neofs-node/control.go index 015b41b5..ea6c7ced 100644 --- a/cmd/neofs-node/control.go +++ b/cmd/neofs-node/control.go @@ -8,7 +8,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine" "github.com/nspcc-dev/neofs-node/pkg/services/control" controlSvc "github.com/nspcc-dev/neofs-node/pkg/services/control/server" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "google.golang.org/grpc" ) @@ -33,7 +33,7 @@ func initControlService(c *cfg) { controlSvc.WithHealthChecker(c), controlSvc.WithNetMapSource(c.netMapSource), controlSvc.WithNodeState(c), - controlSvc.WithDeletedObjectHandler(func(addrList []*addressSDK.Address) error { + controlSvc.WithDeletedObjectHandler(func(addrList []oid.Address) error { prm := new(engine.DeletePrm).WithAddresses(addrList...) _, err := c.cfgObject.cfgLocalStorage.localStorage.Delete(prm) diff --git a/cmd/neofs-node/notificator.go b/cmd/neofs-node/notificator.go index 9944fc05..15dea7ad 100644 --- a/cmd/neofs-node/notificator.go +++ b/cmd/neofs-node/notificator.go @@ -11,7 +11,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/services/notificator" "github.com/nspcc-dev/neofs-node/pkg/services/notificator/nats" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.uber.org/zap" ) @@ -21,7 +21,7 @@ type notificationSource struct { defaultTopic string } -func (n *notificationSource) Iterate(epoch uint64, handler func(topic string, addr *addressSDK.Address)) { +func (n *notificationSource) Iterate(epoch uint64, handler func(topic string, addr oid.Address)) { log := n.l.With(zap.Uint64("epoch", epoch)) listRes, err := n.e.ListContainers(engine.ListContainersPrm{}) @@ -64,8 +64,8 @@ func (n *notificationSource) Iterate(epoch uint64, handler func(topic string, ad } func (n *notificationSource) processAddress( - a *addressSDK.Address, - h func(topic string, addr *addressSDK.Address), + a oid.Address, + h func(topic string, addr oid.Address), ) error { prm := new(engine.HeadPrm) prm.WithAddress(a) @@ -96,7 +96,7 @@ type notificationWriter struct { w *nats.Writer } -func (n notificationWriter) Notify(topic string, address *addressSDK.Address) { +func (n notificationWriter) Notify(topic string, address oid.Address) { if err := n.w.Notify(topic, address); err != nil { n.l.Warn("could not write object notification", zap.Stringer("address", address), diff --git a/cmd/neofs-node/object.go b/cmd/neofs-node/object.go index 06852efa..7b7fe767 100644 --- a/cmd/neofs-node/object.go +++ b/cmd/neofs-node/object.go @@ -42,7 +42,7 @@ import ( cid "github.com/nspcc-dev/neofs-sdk-go/container/id" eaclSDK "github.com/nspcc-dev/neofs-sdk-go/eacl" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/nspcc-dev/neofs-sdk-go/user" "go.uber.org/zap" ) @@ -102,7 +102,7 @@ type localObjectInhumer struct { log *logger.Logger } -func (r *localObjectInhumer) DeleteObjects(ts *addressSDK.Address, addr ...*addressSDK.Address) error { +func (r *localObjectInhumer) DeleteObjects(ts oid.Address, addr ...oid.Address) error { prm := new(engine.InhumePrm) prm.WithTarget(ts, addr...) @@ -124,8 +124,8 @@ func (i *delNetInfo) TombstoneLifetime() (uint64, error) { // returns node owner ID calculated from configured private key. // // Implements method needed for Object.Delete service. -func (i *delNetInfo) LocalNodeID() *user.ID { - return &i.cfg.ownerIDFromKey +func (i *delNetInfo) LocalNodeID() user.ID { + return i.cfg.ownerIDFromKey } type innerRingFetcherWithNotary struct { @@ -234,7 +234,7 @@ func initObjectService(c *cfg) { policerconfig.HeadTimeout(c.appCfg), ), policer.WithReplicator(repl), - policer.WithRedundantCopyCallback(func(addr *addressSDK.Address) { + policer.WithRedundantCopyCallback(func(addr oid.Address) { _, err := ls.Inhume(new(engine.InhumePrm).MarkAsGarbage(addr)) if err != nil { c.log.Warn("could not inhume mark redundant copy as garbage", @@ -412,8 +412,8 @@ func (s *signedEACLTable) SignedDataSize() int { return (*eaclSDK.Table)(s).ToV2().StableSize() } -func (s *morphEACLFetcher) GetEACL(cid *cid.ID) (*eaclSDK.Table, error) { - table, err := s.w.GetEACL(cid) +func (s *morphEACLFetcher) GetEACL(cnr cid.ID) (*eaclSDK.Table, error) { + table, err := s.w.GetEACL(cnr) if err != nil { return nil, err } diff --git a/cmd/neofs-node/session.go b/cmd/neofs-node/session.go index b96e9d7b..ea8c794d 100644 --- a/cmd/neofs-node/session.go +++ b/cmd/neofs-node/session.go @@ -20,7 +20,7 @@ import ( type sessionStorage interface { Create(ctx context.Context, body *session.CreateRequestBody) (*session.CreateResponseBody, error) - Get(ownerID *user.ID, tokenID []byte) *storage.PrivateToken + Get(ownerID user.ID, tokenID []byte) *storage.PrivateToken RemoveOld(epoch uint64) Close() error diff --git a/go.mod b/go.mod index 78c1bf64..c8a462f3 100644 --- a/go.mod +++ b/go.mod @@ -17,9 +17,9 @@ require ( github.com/nspcc-dev/hrw v1.0.9 github.com/nspcc-dev/neo-go v0.98.3 github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220321144137-d5a9af5860af // indirect - github.com/nspcc-dev/neofs-api-go/v2 v2.12.1 + github.com/nspcc-dev/neofs-api-go/v2 v2.12.2-0.20220530190258-c82dcf7e1610 github.com/nspcc-dev/neofs-contract v0.15.1 - github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.3.0.20220526065457-bef4618cd6b9 + github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.3.0.20220531091404-82d762f536a3 github.com/nspcc-dev/tzhash v1.5.2 github.com/panjf2000/ants/v2 v2.4.0 github.com/paulmach/orb v0.2.2 diff --git a/go.sum b/go.sum index 20a826f66136dd84a6776855e4eb13db4477857c..c54d95d6456548c3b43bec29ecac051f08b0e740 100644 GIT binary patch delta 301 zcmZo|U_02rwn1`+pOLPCo{@o(k%6hPfuW^=k*S4lvV~Dfa+-Onp_!q9LWZH0S9wu| zM|hxDuzy8`flpbUYnfY?v2THQR(POeK!ksxscC7cduDEWMv%ee#M!cw<)`y08tD-* zcysxTdCV@xh6a{~CI%+DKr7A7jM7Yv%@U14b~?aZ>G^uO`6(bXlQRucED8$JQ%Zx% yiX1bd!rZ;H%mOk>{WHS~%DnS(T*`uTTs$o^vc0k=FPtns*>5iQ=6`e89|HiAkX`No delta 235 zcmX@uz}DKpwn1`+zM(>fp;bUws8Nwmj=N>BL6%FZX{vW+Vra2Ro_D@}PNH_MpJ_o^ zm9dd~W|DE?Z$=+`M_lJZ2XoGXpbI6H{~Dq|`JMGee8y6tg5tkf9-A zM*77C`bN%?<{9QeM!sHYq2?ZuE@cr}-tLac{=Qyi1-W7Rh1rST>Dpz= size { return nil } diff --git a/pkg/innerring/processors/audit/scheduler_test.go b/pkg/innerring/processors/audit/scheduler_test.go index aff172b4..2318044a 100644 --- a/pkg/innerring/processors/audit/scheduler_test.go +++ b/pkg/innerring/processors/audit/scheduler_test.go @@ -26,10 +26,10 @@ func TestSelect(t *testing.T) { require.Equal(t, len(cids)/irSize, len(s)) for _, id := range s { - n, ok := m[id.String()] + n, ok := m[id.EncodeToString()] require.True(t, ok) require.Equal(t, 0, n) - m[id.String()] = 1 + m[id.EncodeToString()] = 1 } } @@ -45,10 +45,10 @@ func TestSelect(t *testing.T) { s := audit.Select(cids, 0, uint64(i), irSize) for _, id := range s { - n, ok := m[id.String()] + n, ok := m[id.EncodeToString()] require.True(t, ok) require.Equal(t, 0, n) - m[id.String()] = 1 + m[id.EncodeToString()] = 1 } } @@ -64,10 +64,10 @@ func TestSelect(t *testing.T) { s := audit.Select(cids, uint64(i), 0, irSize) for _, id := range s { - n, ok := m[id.String()] + n, ok := m[id.EncodeToString()] require.True(t, ok) require.Equal(t, 0, n) - m[id.String()] = 1 + m[id.EncodeToString()] = 1 } } @@ -75,22 +75,21 @@ func TestSelect(t *testing.T) { }) } -func generateContainers(n int) []*cid.ID { - result := make([]*cid.ID, 0, n) +func generateContainers(n int) []cid.ID { + result := make([]cid.ID, n) for i := 0; i < n; i++ { - v := cidtest.ID() - result = append(result, &v) + result[i] = cidtest.ID() } return result } -func hitMap(ids []*cid.ID) map[string]int { +func hitMap(ids []cid.ID) map[string]int { result := make(map[string]int, len(ids)) for _, id := range ids { - result[id.String()] = 0 + result[id.EncodeToString()] = 0 } return result diff --git a/pkg/innerring/processors/container/common.go b/pkg/innerring/processors/container/common.go index 0463e0a3..df45a5bf 100644 --- a/pkg/innerring/processors/container/common.go +++ b/pkg/innerring/processors/container/common.go @@ -115,7 +115,7 @@ func (cp *Processor) verifySignature(v signatureVerificationData) error { if verificationKeys == nil { var prm neofsid.AccountKeysPrm - prm.SetID(&v.ownerContainer) + prm.SetID(v.ownerContainer) ownerKeys, err := cp.idClient.AccountKeys(prm) if err != nil { diff --git a/pkg/innerring/processors/container/process_container.go b/pkg/innerring/processors/container/process_container.go index 5c7739f0..bb464da5 100644 --- a/pkg/innerring/processors/container/process_container.go +++ b/pkg/innerring/processors/container/process_container.go @@ -154,17 +154,17 @@ func (cp *Processor) processContainerDelete(delete *containerEvent.Delete) { } func (cp *Processor) checkDeleteContainer(e *containerEvent.Delete) error { - binCID := e.ContainerID() + binCnr := e.ContainerID() var idCnr cid.ID - err := idCnr.Decode(binCID) + err := idCnr.Decode(binCnr) if err != nil { return fmt.Errorf("invalid container ID: %w", err) } // receive owner of the related container - cnr, err := cp.cnrClient.Get(binCID) + cnr, err := cp.cnrClient.Get(binCnr) if err != nil { return fmt.Errorf("could not receive the container: %w", err) } @@ -181,7 +181,7 @@ func (cp *Processor) checkDeleteContainer(e *containerEvent.Delete) error { idContainer: idCnr, binTokenSession: e.SessionToken(), signature: e.Signature(), - signedData: binCID, + signedData: binCnr, }) if err != nil { return fmt.Errorf("auth container removal: %w", err) diff --git a/pkg/innerring/processors/container/process_eacl.go b/pkg/innerring/processors/container/process_eacl.go index 52d61933..7c347f9a 100644 --- a/pkg/innerring/processors/container/process_eacl.go +++ b/pkg/innerring/processors/container/process_eacl.go @@ -46,7 +46,7 @@ func (cp *Processor) checkSetEACL(e container.SetEACL) error { } // receive owner of the related container - cnr, err := cntClient.Get(cp.cnrClient, &idCnr) + cnr, err := cntClient.Get(cp.cnrClient, idCnr) if err != nil { return fmt.Errorf("could not receive the container: %w", err) } diff --git a/pkg/innerring/processors/settlement/audit/calculate.go b/pkg/innerring/processors/settlement/audit/calculate.go index 0d3a120f..38800a06 100644 --- a/pkg/innerring/processors/settlement/audit/calculate.go +++ b/pkg/innerring/processors/settlement/audit/calculate.go @@ -12,7 +12,6 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/nspcc-dev/neofs-sdk-go/audit" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/nspcc-dev/neofs-sdk-go/user" "go.uber.org/zap" @@ -152,7 +151,7 @@ func (c *Calculator) readContainerInfo(ctx *singleResultCtx) bool { var err error - ctx.cnrInfo, err = c.prm.ContainerStorage.ContainerInfo(&cnr) + ctx.cnrInfo, err = c.prm.ContainerStorage.ContainerInfo(cnr) if err != nil { ctx.log.Error("could not get container info", zap.String("error", err.Error()), @@ -217,11 +216,11 @@ func (c *Calculator) sumSGSizes(ctx *singleResultCtx) bool { sumPassSGSize := uint64(0) fail := false - addr := addressSDK.NewAddress() - addr.SetContainerID(*ctx.containerID()) + var addr oid.Address + addr.SetContainer(ctx.containerID()) ctx.auditResult.IteratePassedStorageGroups(func(id oid.ID) bool { - addr.SetObjectID(id) + addr.SetObject(id) sgInfo, err := c.prm.SGStorage.SGInfo(addr) if err != nil { @@ -285,7 +284,7 @@ func (c *Calculator) fillTransferTable(ctx *singleResultCtx) bool { ctx.txTable.Transfer(&common.TransferTx{ From: cnrOwner, - To: ownerID, + To: *ownerID, Amount: fee, }) } @@ -303,16 +302,16 @@ func (c *Calculator) fillTransferTable(ctx *singleResultCtx) bool { ctx.txTable.Transfer(&common.TransferTx{ From: cnrOwner, - To: auditIR, + To: *auditIR, Amount: ctx.auditFee, }) return false } -func (c *singleResultCtx) containerID() *cid.ID { +func (c *singleResultCtx) containerID() cid.ID { cnr, _ := c.auditResult.Container() - return &cnr + return cnr } func (c *singleResultCtx) auditEpoch() uint64 { diff --git a/pkg/innerring/processors/settlement/audit/prm.go b/pkg/innerring/processors/settlement/audit/prm.go index 4f7b0349..1da0e733 100644 --- a/pkg/innerring/processors/settlement/audit/prm.go +++ b/pkg/innerring/processors/settlement/audit/prm.go @@ -3,7 +3,7 @@ package audit import ( "github.com/nspcc-dev/neofs-node/pkg/innerring/processors/settlement/common" "github.com/nspcc-dev/neofs-sdk-go/audit" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) // CalculatorPrm groups the parameters of Calculator's constructor. @@ -39,7 +39,7 @@ type SGInfo interface { // SGStorage is an interface of storage of the storage groups. type SGStorage interface { // Must return information about the storage group by address. - SGInfo(*addressSDK.Address) (SGInfo, error) + SGInfo(oid.Address) (SGInfo, error) } // FeeFetcher wraps AuditFee method that returns audit fee price from diff --git a/pkg/innerring/processors/settlement/basic/collect.go b/pkg/innerring/processors/settlement/basic/collect.go index 6ea9adb5..748ab8c8 100644 --- a/pkg/innerring/processors/settlement/basic/collect.go +++ b/pkg/innerring/processors/settlement/basic/collect.go @@ -41,7 +41,8 @@ func (inc *IncomeSettlementContext) Collect() { if err != nil { inc.log.Warn("can't fetch container info", zap.Uint64("epoch", inc.epoch), - zap.Stringer("container_id", cnrEstimations[i].ContainerID)) + zap.Stringer("container_id", cnrEstimations[i].ContainerID), + ) continue } @@ -50,7 +51,8 @@ func (inc *IncomeSettlementContext) Collect() { if err != nil { inc.log.Debug("can't fetch container info", zap.Uint64("epoch", inc.epoch), - zap.Stringer("container_id", cnrEstimations[i].ContainerID)) + zap.Stringer("container_id", cnrEstimations[i].ContainerID), + ) continue } @@ -65,7 +67,7 @@ func (inc *IncomeSettlementContext) Collect() { txTable.Transfer(&common.TransferTx{ From: owner.Owner(), - To: &inc.bankOwner, + To: inc.bankOwner, Amount: total, }) } diff --git a/pkg/innerring/processors/settlement/basic/context.go b/pkg/innerring/processors/settlement/basic/context.go index c7756762..4c9c32eb 100644 --- a/pkg/innerring/processors/settlement/basic/context.go +++ b/pkg/innerring/processors/settlement/basic/context.go @@ -22,7 +22,7 @@ type ( // BalanceFetcher uses NEP-17 compatible balance contract BalanceFetcher interface { - Balance(id *user.ID) (*big.Int, error) + Balance(id user.ID) (*big.Int, error) } IncomeSettlementContext struct { diff --git a/pkg/innerring/processors/settlement/basic/distribute.go b/pkg/innerring/processors/settlement/basic/distribute.go index 28b455d9..f89a2af8 100644 --- a/pkg/innerring/processors/settlement/basic/distribute.go +++ b/pkg/innerring/processors/settlement/basic/distribute.go @@ -14,7 +14,7 @@ func (inc *IncomeSettlementContext) Distribute() { txTable := common.NewTransferTable() - bankBalance, err := inc.balances.Balance(&inc.bankOwner) + bankBalance, err := inc.balances.Balance(inc.bankOwner) if err != nil { inc.log.Error("can't fetch balance of banking account", zap.String("error", err.Error())) @@ -35,8 +35,8 @@ func (inc *IncomeSettlementContext) Distribute() { } txTable.Transfer(&common.TransferTx{ - From: &inc.bankOwner, - To: nodeOwner, + From: inc.bankOwner, + To: *nodeOwner, Amount: normalizedValue(n, total, bankBalance), }) }) diff --git a/pkg/innerring/processors/settlement/common/types.go b/pkg/innerring/processors/settlement/common/types.go index c8172011..9cd8a021 100644 --- a/pkg/innerring/processors/settlement/common/types.go +++ b/pkg/innerring/processors/settlement/common/types.go @@ -21,21 +21,21 @@ type NodeInfo interface { // necessary for calculating audit fee. type ContainerInfo interface { // Must return identifier of the container owner. - Owner() *user.ID + Owner() user.ID } // ContainerStorage is an interface of // storage of the NeoFS containers. type ContainerStorage interface { // Must return information about the container by ID. - ContainerInfo(*cid.ID) (ContainerInfo, error) + ContainerInfo(cid.ID) (ContainerInfo, error) } // PlacementCalculator is a component interface // that builds placement vectors. type PlacementCalculator interface { - // Must return information about the nodes from container cid of the epoch e. - ContainerNodes(e uint64, cid *cid.ID) ([]NodeInfo, error) + // Must return information about the nodes from container by its ID of the given epoch. + ContainerNodes(uint64, cid.ID) ([]NodeInfo, error) } // AccountStorage is an network member accounts interface. @@ -50,5 +50,5 @@ type Exchanger interface { // Must transfer amount of GASe-12 from sender to recipient. // // Amount must be positive. - Transfer(sender, recipient *user.ID, amount *big.Int, details []byte) + Transfer(sender, recipient user.ID, amount *big.Int, details []byte) } diff --git a/pkg/innerring/processors/settlement/common/util.go b/pkg/innerring/processors/settlement/common/util.go index 56e50d1f..6b5db233 100644 --- a/pkg/innerring/processors/settlement/common/util.go +++ b/pkg/innerring/processors/settlement/common/util.go @@ -11,7 +11,7 @@ type TransferTable struct { } type TransferTx struct { - From, To *user.ID + From, To user.ID Amount *big.Int } @@ -23,11 +23,11 @@ func NewTransferTable() *TransferTable { } func (t *TransferTable) Transfer(tx *TransferTx) { - if tx.From.Equals(*tx.To) { + if tx.From.Equals(tx.To) { return } - from, to := tx.From.String(), tx.To.String() + from, to := tx.From.EncodeToString(), tx.To.EncodeToString() m, ok := t.txs[from] if !ok { diff --git a/pkg/innerring/rpc.go b/pkg/innerring/rpc.go index 2d8d6d94..b23e0e3d 100644 --- a/pkg/innerring/rpc.go +++ b/pkg/innerring/rpc.go @@ -3,7 +3,6 @@ package innerring import ( "context" "crypto/ecdsa" - "errors" "fmt" "time" @@ -16,8 +15,7 @@ import ( apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" "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" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/nspcc-dev/neofs-sdk-go/storagegroup" "go.uber.org/zap" ) @@ -63,19 +61,16 @@ func (c *ClientCache) Get(info clientcore.NodeInfo) (clientcore.Client, error) { // Returns storage groups structure from received object. // // Returns an error of type apistatus.ObjectNotFound if storage group is missing. -func (c *ClientCache) GetSG(task *audit.Task, id *oidSDK.ID) (*storagegroup.StorageGroup, error) { - sgAddress := new(addressSDK.Address) - sgAddress.SetContainerID(*task.ContainerID()) - sgAddress.SetObjectID(*id) +func (c *ClientCache) GetSG(task *audit.Task, id oid.ID) (*storagegroup.StorageGroup, error) { + var sgAddress oid.Address + sgAddress.SetContainer(task.ContainerID()) + sgAddress.SetObject(id) return c.getSG(task.AuditContext(), sgAddress, task.NetworkMap(), task.ContainerNodes()) } -func (c *ClientCache) getSG(ctx context.Context, addr *addressSDK.Address, nm *netmap.Netmap, cn netmap.ContainerNodes) (*storagegroup.StorageGroup, error) { - obj, ok := addr.ObjectID() - if !ok { - return nil, errors.New("missing object ID in object address") - } +func (c *ClientCache) getSG(ctx context.Context, addr oid.Address, nm *netmap.Netmap, cn netmap.ContainerNodes) (*storagegroup.StorageGroup, error) { + obj := addr.Object() nodes, err := placement.BuildObjectPlacement(nm, cn, &obj) if err != nil { @@ -129,10 +124,10 @@ func (c *ClientCache) getSG(ctx context.Context, addr *addressSDK.Address, nm *n } // GetHeader requests node from the container under audit to return object header by id. -func (c *ClientCache) GetHeader(task *audit.Task, node *netmap.Node, id *oidSDK.ID, relay bool) (*object.Object, error) { - objAddress := new(addressSDK.Address) - objAddress.SetContainerID(*task.ContainerID()) - objAddress.SetObjectID(*id) +func (c *ClientCache) GetHeader(task *audit.Task, node *netmap.Node, id oid.ID, relay bool) (*object.Object, error) { + var objAddress oid.Address + objAddress.SetContainer(task.ContainerID()) + objAddress.SetObject(id) var info clientcore.NodeInfo @@ -167,10 +162,10 @@ func (c *ClientCache) GetHeader(task *audit.Task, node *netmap.Node, id *oidSDK. // GetRangeHash requests node from the container under audit to return Tillich-Zemor hash of the // payload range of the object with specified identifier. -func (c *ClientCache) GetRangeHash(task *audit.Task, node *netmap.Node, id *oidSDK.ID, rng *object.Range) ([]byte, error) { - objAddress := new(addressSDK.Address) - objAddress.SetContainerID(*task.ContainerID()) - objAddress.SetObjectID(*id) +func (c *ClientCache) GetRangeHash(task *audit.Task, node *netmap.Node, id oid.ID, rng *object.Range) ([]byte, error) { + var objAddress oid.Address + objAddress.SetContainer(task.ContainerID()) + objAddress.SetObject(id) var info clientcore.NodeInfo diff --git a/pkg/innerring/settlement.go b/pkg/innerring/settlement.go index 6c116a3c..b7f01af5 100644 --- a/pkg/innerring/settlement.go +++ b/pkg/innerring/settlement.go @@ -6,7 +6,6 @@ import ( "crypto/elliptic" "crypto/sha256" "encoding/hex" - "errors" "fmt" "math/big" @@ -24,7 +23,7 @@ import ( containerAPI "github.com/nspcc-dev/neofs-sdk-go/container" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" netmapAPI "github.com/nspcc-dev/neofs-sdk-go/netmap" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/nspcc-dev/neofs-sdk-go/storagegroup" "github.com/nspcc-dev/neofs-sdk-go/user" "go.uber.org/zap" @@ -93,8 +92,8 @@ func (n nodeInfoWrapper) Price() *big.Int { return big.NewInt(int64(n.ni.Price)) } -func (c *containerWrapper) Owner() *user.ID { - return (*containerAPI.Container)(c).OwnerID() +func (c *containerWrapper) Owner() user.ID { + return *(*containerAPI.Container)(c).OwnerID() } func (s settlementDeps) AuditResultsForEpoch(epoch uint64) ([]*auditAPI.Result, error) { @@ -117,7 +116,7 @@ func (s settlementDeps) AuditResultsForEpoch(epoch uint64) ([]*auditAPI.Result, return res, nil } -func (s settlementDeps) ContainerInfo(cid *cid.ID) (common.ContainerInfo, error) { +func (s settlementDeps) ContainerInfo(cid cid.ID) (common.ContainerInfo, error) { cnr, err := s.cnrSrc.Get(cid) if err != nil { return nil, fmt.Errorf("could not get container from storage: %w", err) @@ -126,7 +125,7 @@ func (s settlementDeps) ContainerInfo(cid *cid.ID) (common.ContainerInfo, error) return (*containerWrapper)(cnr), nil } -func (s settlementDeps) buildContainer(e uint64, cid *cid.ID) (netmapAPI.ContainerNodes, *netmapAPI.Netmap, error) { +func (s settlementDeps) buildContainer(e uint64, cid cid.ID) (netmapAPI.ContainerNodes, *netmapAPI.Netmap, error) { var ( nm *netmapAPI.Netmap err error @@ -161,7 +160,7 @@ func (s settlementDeps) buildContainer(e uint64, cid *cid.ID) (netmapAPI.Contain return cn, nm, nil } -func (s settlementDeps) ContainerNodes(e uint64, cid *cid.ID) ([]common.NodeInfo, error) { +func (s settlementDeps) ContainerNodes(e uint64, cid cid.ID) ([]common.NodeInfo, error) { cn, _, err := s.buildContainer(e, cid) if err != nil { return nil, err @@ -182,13 +181,10 @@ func (s settlementDeps) ContainerNodes(e uint64, cid *cid.ID) ([]common.NodeInfo // SGInfo returns audit.SGInfo by object address. // // Returns an error of type apistatus.ObjectNotFound if storage group is missing. -func (s settlementDeps) SGInfo(addr *addressSDK.Address) (audit.SGInfo, error) { - cnr, ok := addr.ContainerID() - if !ok { - return nil, errors.New("missing container in object address") - } +func (s settlementDeps) SGInfo(addr oid.Address) (audit.SGInfo, error) { + cnr := addr.Container() - cn, nm, err := s.buildContainer(0, &cnr) + cn, nm, err := s.buildContainer(0, cnr) if err != nil { return nil, err } @@ -213,7 +209,7 @@ func (s settlementDeps) ResolveKey(ni common.NodeInfo) (*user.ID, error) { return &id, nil } -func (s settlementDeps) Transfer(sender, recipient *user.ID, amount *big.Int, details []byte) { +func (s settlementDeps) Transfer(sender, recipient user.ID, amount *big.Int, details []byte) { if s.settlementCtx == "" { panic("unknown settlement deps context") } @@ -278,7 +274,7 @@ func (b basicIncomeSettlementDeps) Estimations(epoch uint64) ([]*containerClient return result, nil } -func (b basicIncomeSettlementDeps) Balance(id *user.ID) (*big.Int, error) { +func (b basicIncomeSettlementDeps) Balance(id user.ID) (*big.Int, error) { return b.balanceClient.BalanceOf(id) } diff --git a/pkg/local_object_storage/blobovnicza/blobovnicza_test.go b/pkg/local_object_storage/blobovnicza/blobovnicza_test.go index 3c3b632f..16fc7ed5 100644 --- a/pkg/local_object_storage/blobovnicza/blobovnicza_test.go +++ b/pkg/local_object_storage/blobovnicza/blobovnicza_test.go @@ -8,12 +8,12 @@ import ( "testing" "github.com/nspcc-dev/neofs-node/pkg/util/logger/test" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" - objecttest "github.com/nspcc-dev/neofs-sdk-go/object/address/test" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" + oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test" "github.com/stretchr/testify/require" ) -func testPutGet(t *testing.T, blz *Blobovnicza, addr *addressSDK.Address, sz uint64, assertErrPut, assertErrGet func(error) bool) *addressSDK.Address { +func testPutGet(t *testing.T, blz *Blobovnicza, addr oid.Address, sz uint64, assertErrPut, assertErrGet func(error) bool) oid.Address { // create binary object data := make([]byte, sz) rand.Read(data) @@ -28,16 +28,14 @@ func testPutGet(t *testing.T, blz *Blobovnicza, addr *addressSDK.Address, sz uin require.NoError(t, err) } - if assertErrPut != nil { - return nil + if assertErrGet != nil { + testGet(t, blz, addr, data, assertErrGet) } - testGet(t, blz, addr, data, assertErrGet) - return addr } -func testGet(t *testing.T, blz *Blobovnicza, addr *addressSDK.Address, expObj []byte, assertErr func(error) bool) { +func testGet(t *testing.T, blz *Blobovnicza, addr oid.Address, expObj []byte, assertErr func(error) bool) { pGet := new(GetPrm) pGet.SetAddress(addr) @@ -79,12 +77,12 @@ func TestBlobovnicza(t *testing.T) { require.NoError(t, blz.Init()) // try to read non-existent address - testGet(t, blz, objecttest.Address(), nil, IsErrNotFound) + testGet(t, blz, oidtest.Address(), nil, IsErrNotFound) filled := uint64(15 * 1 << 10) // test object 15KB - addr := testPutGet(t, blz, objecttest.Address(), filled, nil, nil) + addr := testPutGet(t, blz, oidtest.Address(), filled, nil, nil) // remove the object dPrm := new(DeletePrm) @@ -98,11 +96,11 @@ func TestBlobovnicza(t *testing.T) { // fill Blobovnicza fully for ; filled < sizeLim; filled += objSizeLim { - testPutGet(t, blz, objecttest.Address(), objSizeLim, nil, nil) + testPutGet(t, blz, oidtest.Address(), objSizeLim, nil, nil) } // from now objects should not be saved - testPutGet(t, blz, objecttest.Address(), 1024, func(err error) bool { + testPutGet(t, blz, oidtest.Address(), 1024, func(err error) bool { return errors.Is(err, ErrFull) }, nil) @@ -142,7 +140,7 @@ func TestIterateObjects(t *testing.T) { var putPrm PutPrm for _, v := range mObjs { - putPrm.SetAddress(objecttest.Address()) + putPrm.SetAddress(oidtest.Address()) putPrm.SetMarshaledObject(v) _, err := blz.Put(&putPrm) diff --git a/pkg/local_object_storage/blobovnicza/delete.go b/pkg/local_object_storage/blobovnicza/delete.go index 9a4dbe92..6c598e1c 100644 --- a/pkg/local_object_storage/blobovnicza/delete.go +++ b/pkg/local_object_storage/blobovnicza/delete.go @@ -2,14 +2,14 @@ package blobovnicza import ( apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.etcd.io/bbolt" "go.uber.org/zap" ) // DeletePrm groups the parameters of Delete operation. type DeletePrm struct { - addr *addressSDK.Address + addr oid.Address } // DeleteRes groups the resulting values of Delete operation. @@ -17,7 +17,7 @@ type DeleteRes struct { } // SetAddress sets the address of the requested object. -func (p *DeletePrm) SetAddress(addr *addressSDK.Address) { +func (p *DeletePrm) SetAddress(addr oid.Address) { p.addr = addr } diff --git a/pkg/local_object_storage/blobovnicza/get.go b/pkg/local_object_storage/blobovnicza/get.go index e7e75777..661d7b20 100644 --- a/pkg/local_object_storage/blobovnicza/get.go +++ b/pkg/local_object_storage/blobovnicza/get.go @@ -3,14 +3,14 @@ package blobovnicza import ( "github.com/nspcc-dev/neo-go/pkg/util/slice" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.etcd.io/bbolt" "go.uber.org/zap" ) // GetPrm groups the parameters of Get operation. type GetPrm struct { - addr *addressSDK.Address + addr oid.Address } // GetRes groups the resulting values of Get operation. @@ -19,7 +19,7 @@ type GetRes struct { } // SetAddress sets the address of the requested object. -func (p *GetPrm) SetAddress(addr *addressSDK.Address) { +func (p *GetPrm) SetAddress(addr oid.Address) { p.addr = addr } diff --git a/pkg/local_object_storage/blobovnicza/iterate.go b/pkg/local_object_storage/blobovnicza/iterate.go index 79b3771d..7fbeb070 100644 --- a/pkg/local_object_storage/blobovnicza/iterate.go +++ b/pkg/local_object_storage/blobovnicza/iterate.go @@ -3,7 +3,7 @@ package blobovnicza import ( "fmt" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.etcd.io/bbolt" ) @@ -57,7 +57,7 @@ func max(a, b uint64) uint64 { // IterationElement represents a unit of elements through which Iterate operation passes. type IterationElement struct { - addr *addressSDK.Address + addr oid.Address data []byte } @@ -68,7 +68,7 @@ func (x IterationElement) ObjectData() []byte { } // Address returns address of the stored object. -func (x IterationElement) Address() *addressSDK.Address { +func (x IterationElement) Address() oid.Address { return x.addr } @@ -124,11 +124,7 @@ func (b *Blobovnicza) Iterate(prm IteratePrm) (*IterateRes, error) { return tx.ForEach(func(name []byte, buck *bbolt.Bucket) error { return buck.ForEach(func(k, v []byte) error { if prm.decodeAddresses { - if elem.addr == nil { - elem.addr = addressSDK.NewAddress() - } - - if err := addressFromKey(elem.addr, k); err != nil { + if err := addressFromKey(&elem.addr, k); err != nil { if prm.ignoreErrors { return nil } @@ -164,7 +160,7 @@ func IterateObjects(blz *Blobovnicza, f func([]byte) error) error { } // IterateAddresses is a helper function which iterates over Blobovnicza and passes addresses of the objects to f. -func IterateAddresses(blz *Blobovnicza, f func(*addressSDK.Address) error) error { +func IterateAddresses(blz *Blobovnicza, f func(oid.Address) error) error { var prm IteratePrm prm.DecodeAddresses() diff --git a/pkg/local_object_storage/blobovnicza/iterate_test.go b/pkg/local_object_storage/blobovnicza/iterate_test.go index fa508b25..94a6ebab 100644 --- a/pkg/local_object_storage/blobovnicza/iterate_test.go +++ b/pkg/local_object_storage/blobovnicza/iterate_test.go @@ -6,7 +6,7 @@ import ( "testing" "github.com/nspcc-dev/neo-go/pkg/util/slice" - objecttest "github.com/nspcc-dev/neofs-sdk-go/object/address/test" + oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test" "github.com/stretchr/testify/require" "go.etcd.io/bbolt" ) @@ -18,7 +18,7 @@ func TestBlobovniczaIterate(t *testing.T) { require.NoError(t, b.Init()) data := [][]byte{{0, 1, 2, 3}, {5, 6, 7, 8}} - addr := objecttest.Address() + addr := oidtest.Address() _, err := b.Put(&PutPrm{addr: addr, objData: data[0]}) require.NoError(t, err) diff --git a/pkg/local_object_storage/blobovnicza/put.go b/pkg/local_object_storage/blobovnicza/put.go index 3a001bc4..16d490c9 100644 --- a/pkg/local_object_storage/blobovnicza/put.go +++ b/pkg/local_object_storage/blobovnicza/put.go @@ -4,13 +4,13 @@ import ( "errors" "fmt" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.etcd.io/bbolt" ) // PutPrm groups the parameters of Put operation. type PutPrm struct { - addr *addressSDK.Address + addr oid.Address objData []byte } @@ -23,10 +23,8 @@ type PutRes struct { // object to a filled blobovnicza. var ErrFull = errors.New("blobovnicza is full") -var errNilAddress = errors.New("object address is nil") - // SetAddress sets the address of the saving object. -func (p *PutPrm) SetAddress(addr *addressSDK.Address) { +func (p *PutPrm) SetAddress(addr oid.Address) { p.addr = addr } @@ -50,14 +48,9 @@ func (p *PutPrm) SetMarshaledObject(data []byte) { // // Should not be called in read-only configuration. func (b *Blobovnicza) Put(prm *PutPrm) (*PutRes, error) { - addr := prm.addr - if addr == nil { - return nil, errNilAddress - } - sz := uint64(len(prm.objData)) bucketName := bucketForSize(sz) - key := addressKey(addr) + key := addressKey(prm.addr) err := b.boltDB.Batch(func(tx *bbolt.Tx) error { if b.full() { @@ -86,10 +79,10 @@ func (b *Blobovnicza) Put(prm *PutPrm) (*PutRes, error) { return nil, err } -func addressKey(addr *addressSDK.Address) []byte { - return []byte(addr.String()) +func addressKey(addr oid.Address) []byte { + return []byte(addr.EncodeToString()) } -func addressFromKey(dst *addressSDK.Address, data []byte) error { - return dst.Parse(string(data)) +func addressFromKey(dst *oid.Address, data []byte) error { + return dst.DecodeString(string(data)) } diff --git a/pkg/local_object_storage/blobstor/blobovnicza.go b/pkg/local_object_storage/blobstor/blobovnicza.go index b09d50ff..79552b6e 100644 --- a/pkg/local_object_storage/blobstor/blobovnicza.go +++ b/pkg/local_object_storage/blobstor/blobovnicza.go @@ -15,7 +15,7 @@ import ( storagelog "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/internal/log" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.uber.org/zap" ) @@ -136,7 +136,7 @@ func indexSlice(number uint64) []uint64 { // save object in the maximum weight blobobnicza. // // returns error if could not save object in any blobovnicza. -func (b *blobovniczas) put(addr *addressSDK.Address, data []byte) (*blobovnicza.ID, error) { +func (b *blobovniczas) put(addr oid.Address, data []byte) (*blobovnicza.ID, error) { prm := new(blobovnicza.PutPrm) prm.SetAddress(addr) prm.SetMarshaledObject(data) @@ -220,7 +220,7 @@ func (b *blobovniczas) get(prm *GetSmallPrm) (res *GetSmallRes, err error) { activeCache := make(map[string]struct{}) - err = b.iterateSortedLeaves(prm.addr, func(p string) (bool, error) { + err = b.iterateSortedLeaves(&prm.addr, func(p string) (bool, error) { dirPath := filepath.Dir(p) _, ok := activeCache[dirPath] @@ -270,7 +270,7 @@ func (b *blobovniczas) delete(prm *DeleteSmallPrm) (res *DeleteSmallRes, err err activeCache := make(map[string]struct{}) - err = b.iterateSortedLeaves(prm.addr, func(p string) (bool, error) { + err = b.iterateSortedLeaves(&prm.addr, func(p string) (bool, error) { dirPath := filepath.Dir(p) // don't process active blobovnicza of the level twice @@ -322,7 +322,7 @@ func (b *blobovniczas) getRange(prm *GetRangeSmallPrm) (res *GetRangeSmallRes, e activeCache := make(map[string]struct{}) - err = b.iterateSortedLeaves(prm.addr, func(p string) (bool, error) { + err = b.iterateSortedLeaves(&prm.addr, func(p string) (bool, error) { dirPath := filepath.Dir(p) _, ok := activeCache[dirPath] @@ -665,7 +665,7 @@ func (b *blobovniczas) iterateBlobovniczas(ignoreErrors bool, f func(string, *bl } // iterator over the paths of blobovniczas sorted by weight. -func (b *blobovniczas) iterateSortedLeaves(addr *addressSDK.Address, f func(string) (bool, error)) error { +func (b *blobovniczas) iterateSortedLeaves(addr *oid.Address, f func(string) (bool, error)) error { _, err := b.iterateSorted( addr, make([]string, 0, b.blzShallowDepth), @@ -677,14 +677,14 @@ func (b *blobovniczas) iterateSortedLeaves(addr *addressSDK.Address, f func(stri } // iterator over directories with blobovniczas sorted by weight. -func (b *blobovniczas) iterateDeepest(addr *addressSDK.Address, f func(string) (bool, error)) error { +func (b *blobovniczas) iterateDeepest(addr oid.Address, f func(string) (bool, error)) error { depth := b.blzShallowDepth if depth > 0 { depth-- } _, err := b.iterateSorted( - addr, + &addr, make([]string, 0, depth), depth, func(p []string) (bool, error) { return f(filepath.Join(p...)) }, @@ -694,7 +694,7 @@ func (b *blobovniczas) iterateDeepest(addr *addressSDK.Address, f func(string) ( } // iterator over particular level of directories. -func (b *blobovniczas) iterateSorted(addr *addressSDK.Address, curPath []string, execDepth uint64, f func([]string) (bool, error)) (bool, error) { +func (b *blobovniczas) iterateSorted(addr *oid.Address, curPath []string, execDepth uint64, f func([]string) (bool, error)) (bool, error) { indices := indexSlice(b.blzShallowWidth) hrw.SortSliceByValue(indices, addressHash(addr, filepath.Join(curPath...))) @@ -934,11 +934,11 @@ func (b *blobovniczas) openBlobovnicza(p string) (*blobovnicza.Blobovnicza, erro } // returns hash of the object address. -func addressHash(addr *addressSDK.Address, path string) uint64 { +func addressHash(addr *oid.Address, path string) uint64 { var a string if addr != nil { - a = addr.String() + a = addr.EncodeToString() } return hrw.Hash([]byte(a + path)) diff --git a/pkg/local_object_storage/blobstor/blobovnicza_test.go b/pkg/local_object_storage/blobstor/blobovnicza_test.go index d3b4b560..1e647b47 100644 --- a/pkg/local_object_storage/blobstor/blobovnicza_test.go +++ b/pkg/local_object_storage/blobstor/blobovnicza_test.go @@ -10,7 +10,7 @@ import ( apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" 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" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test" "github.com/stretchr/testify/require" ) @@ -63,7 +63,7 @@ func TestBlobovniczas(t *testing.T) { objSz := uint64(szLim / 2) - addrList := make([]*addressSDK.Address, 0) + addrList := make([]oid.Address, 0) minFitObjNum := width * depth * szLim / objSz for i := uint64(0); i < minFitObjNum; i++ { diff --git a/pkg/local_object_storage/blobstor/exists.go b/pkg/local_object_storage/blobstor/exists.go index 7496bcaa..54413871 100644 --- a/pkg/local_object_storage/blobstor/exists.go +++ b/pkg/local_object_storage/blobstor/exists.go @@ -6,7 +6,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.uber.org/zap" ) @@ -64,7 +64,7 @@ func (b *BlobStor) Exists(prm *ExistsPrm) (*ExistsRes, error) { } // checks if object is presented in shallow dir. -func (b *BlobStor) existsBig(addr *addressSDK.Address) (bool, error) { +func (b *BlobStor) existsBig(addr oid.Address) (bool, error) { _, err := b.fsTree.Exists(addr) if errors.Is(err, fstree.ErrFileNotFound) { return false, nil @@ -74,18 +74,18 @@ func (b *BlobStor) existsBig(addr *addressSDK.Address) (bool, error) { } // existsSmall checks if object is presented in blobovnicza. -func (b *BlobStor) existsSmall(addr *addressSDK.Address) (bool, error) { +func (b *BlobStor) existsSmall(addr oid.Address) (bool, error) { return b.blobovniczas.existsSmall(addr) } -func (b *blobovniczas) existsSmall(addr *addressSDK.Address) (bool, error) { +func (b *blobovniczas) existsSmall(addr oid.Address) (bool, error) { activeCache := make(map[string]struct{}) prm := new(blobovnicza.GetPrm) prm.SetAddress(addr) var found bool - err := b.iterateSortedLeaves(addr, func(p string) (bool, error) { + err := b.iterateSortedLeaves(&addr, func(p string) (bool, error) { dirPath := filepath.Dir(p) _, ok := activeCache[dirPath] diff --git a/pkg/local_object_storage/blobstor/exists_test.go b/pkg/local_object_storage/blobstor/exists_test.go index f7c43cab..98bcf0c5 100644 --- a/pkg/local_object_storage/blobstor/exists_test.go +++ b/pkg/local_object_storage/blobstor/exists_test.go @@ -7,7 +7,7 @@ import ( objectCore "github.com/nspcc-dev/neofs-node/pkg/core/object" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" - objecttest "github.com/nspcc-dev/neofs-sdk-go/object/address/test" + oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test" "github.com/stretchr/testify/require" ) @@ -45,7 +45,7 @@ func TestExists(t *testing.T) { require.True(t, res.Exists()) } - prm.SetAddress(objecttest.Address()) + prm.SetAddress(oidtest.Address()) res, err := b.Exists(prm) require.NoError(t, err) require.False(t, res.Exists()) diff --git a/pkg/local_object_storage/blobstor/fstree/fstree.go b/pkg/local_object_storage/blobstor/fstree/fstree.go index 5fd77393..d93fe63d 100644 --- a/pkg/local_object_storage/blobstor/fstree/fstree.go +++ b/pkg/local_object_storage/blobstor/fstree/fstree.go @@ -11,8 +11,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/util" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) // FSTree represents an object storage as a filesystem tree. @@ -42,44 +41,41 @@ const ( // ErrFileNotFound is returned when file is missing. var ErrFileNotFound = errors.New("file not found") -func stringifyAddress(addr *addressSDK.Address) string { - id, _ := addr.ObjectID() - cnr, _ := addr.ContainerID() - - return id.EncodeToString() + "." + cnr.EncodeToString() +func stringifyAddress(addr oid.Address) string { + return addr.Object().EncodeToString() + "." + addr.Container().EncodeToString() } -func addressFromString(s string) (*addressSDK.Address, error) { +func addressFromString(s string) (*oid.Address, error) { ss := strings.SplitN(s, ".", 2) if len(ss) != 2 { return nil, errors.New("invalid address") } - var oid oidSDK.ID - if err := oid.DecodeString(ss[0]); err != nil { + var obj oid.ID + if err := obj.DecodeString(ss[0]); err != nil { return nil, err } - var id cid.ID - if err := id.DecodeString(ss[1]); err != nil { + var cnr cid.ID + if err := cnr.DecodeString(ss[1]); err != nil { return nil, err } - addr := addressSDK.NewAddress() - addr.SetObjectID(oid) - addr.SetContainerID(id) + var addr oid.Address + addr.SetObject(obj) + addr.SetContainer(cnr) - return addr, nil + return &addr, nil } // IterationPrm contains iteraction parameters. type IterationPrm struct { - handler func(addr *addressSDK.Address, data []byte) error + handler func(addr oid.Address, data []byte) error ignoreErrors bool } // WithHandler sets a function to call on each object. -func (p *IterationPrm) WithHandler(f func(addr *addressSDK.Address, data []byte) error) *IterationPrm { +func (p *IterationPrm) WithHandler(f func(addr oid.Address, data []byte) error) *IterationPrm { p.handler = f return p } @@ -138,7 +134,7 @@ func (t *FSTree) iterate(depth int, curPath []string, prm *IterationPrm) error { return err } - if err := prm.handler(addr, data); err != nil { + if err := prm.handler(*addr, data); err != nil { // Error occurred in handler, outside of our scope, needs to be reported. return err } @@ -147,7 +143,7 @@ func (t *FSTree) iterate(depth int, curPath []string, prm *IterationPrm) error { return nil } -func (t *FSTree) treePath(addr *addressSDK.Address) string { +func (t *FSTree) treePath(addr oid.Address) string { sAddr := stringifyAddress(addr) dirs := make([]string, 0, t.Depth+1+1) // 1 for root, 1 for file @@ -164,7 +160,7 @@ func (t *FSTree) treePath(addr *addressSDK.Address) string { } // Delete removes the object with the specified address from the storage. -func (t *FSTree) Delete(addr *addressSDK.Address) error { +func (t *FSTree) Delete(addr oid.Address) error { p, err := t.Exists(addr) if err != nil { return err @@ -175,7 +171,7 @@ func (t *FSTree) Delete(addr *addressSDK.Address) error { // Exists returns the path to the file with object contents if it exists in the storage // and an error otherwise. -func (t *FSTree) Exists(addr *addressSDK.Address) (string, error) { +func (t *FSTree) Exists(addr oid.Address) (string, error) { p := t.treePath(addr) _, err := os.Stat(p) @@ -187,7 +183,7 @@ func (t *FSTree) Exists(addr *addressSDK.Address) (string, error) { } // Put puts an object in the storage. -func (t *FSTree) Put(addr *addressSDK.Address, data []byte) error { +func (t *FSTree) Put(addr oid.Address, data []byte) error { p := t.treePath(addr) if err := util.MkdirAllX(filepath.Dir(p), t.Permissions); err != nil { @@ -198,7 +194,7 @@ func (t *FSTree) Put(addr *addressSDK.Address, data []byte) error { } // PutStream puts executes handler on a file opened for write. -func (t *FSTree) PutStream(addr *addressSDK.Address, handler func(*os.File) error) error { +func (t *FSTree) PutStream(addr oid.Address, handler func(*os.File) error) error { p := t.treePath(addr) if err := util.MkdirAllX(filepath.Dir(p), t.Permissions); err != nil { @@ -215,7 +211,7 @@ func (t *FSTree) PutStream(addr *addressSDK.Address, handler func(*os.File) erro } // Get returns an object from the storage by address. -func (t *FSTree) Get(addr *addressSDK.Address) ([]byte, error) { +func (t *FSTree) Get(addr oid.Address) ([]byte, error) { p := t.treePath(addr) if _, err := os.Stat(p); os.IsNotExist(err) { diff --git a/pkg/local_object_storage/blobstor/fstree/fstree_test.go b/pkg/local_object_storage/blobstor/fstree/fstree_test.go index d1e306b1..7b319006 100644 --- a/pkg/local_object_storage/blobstor/fstree/fstree_test.go +++ b/pkg/local_object_storage/blobstor/fstree/fstree_test.go @@ -8,17 +8,17 @@ import ( "testing" "github.com/nspcc-dev/neofs-node/pkg/util" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" - objecttest "github.com/nspcc-dev/neofs-sdk-go/object/address/test" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" + oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test" "github.com/stretchr/testify/require" ) func TestAddressToString(t *testing.T) { - addr := objecttest.Address() + addr := oidtest.Address() s := stringifyAddress(addr) actual, err := addressFromString(s) require.NoError(t, err) - require.Equal(t, addr, actual) + require.Equal(t, addr, *actual) } func TestFSTree(t *testing.T) { @@ -36,28 +36,28 @@ func TestFSTree(t *testing.T) { } const count = 3 - var addrs []*addressSDK.Address + var addrs []oid.Address store := map[string][]byte{} for i := 0; i < count; i++ { - a := objecttest.Address() + a := oidtest.Address() addrs = append(addrs, a) data := make([]byte, 10) _, _ = rand.Read(data[:]) require.NoError(t, fs.Put(a, data)) - store[a.String()] = data + store[a.EncodeToString()] = data } t.Run("get", func(t *testing.T) { for _, a := range addrs { actual, err := fs.Get(a) require.NoError(t, err) - require.Equal(t, store[a.String()], actual) + require.Equal(t, store[a.EncodeToString()], actual) } - _, err := fs.Get(objecttest.Address()) + _, err := fs.Get(oidtest.Address()) require.Error(t, err) }) @@ -67,16 +67,16 @@ func TestFSTree(t *testing.T) { require.NoError(t, err) } - _, err := fs.Exists(objecttest.Address()) + _, err := fs.Exists(oidtest.Address()) require.Error(t, err) }) t.Run("iterate", func(t *testing.T) { n := 0 - err := fs.Iterate(new(IterationPrm).WithHandler(func(addr *addressSDK.Address, data []byte) error { + err := fs.Iterate(new(IterationPrm).WithHandler(func(addr oid.Address, data []byte) error { n++ - expected, ok := store[addr.String()] - require.True(t, ok, "object %s was not found", addr.String()) + expected, ok := store[addr.EncodeToString()] + require.True(t, ok, "object %s was not found", addr.EncodeToString()) require.Equal(t, data, expected) return nil })) @@ -87,7 +87,7 @@ func TestFSTree(t *testing.T) { t.Run("leave early", func(t *testing.T) { n := 0 errStop := errors.New("stop") - err := fs.Iterate(new(IterationPrm).WithHandler(func(addr *addressSDK.Address, data []byte) error { + err := fs.Iterate(new(IterationPrm).WithHandler(func(addr oid.Address, data []byte) error { if n++; n == count-1 { return errStop } @@ -105,16 +105,16 @@ func TestFSTree(t *testing.T) { require.NoError(t, os.Mkdir(filepath.Join(fs.RootPath, "ZZ"), 0)) // Unreadable file. - p := fs.treePath(objecttest.Address()) + p := fs.treePath(oidtest.Address()) require.NoError(t, util.MkdirAllX(filepath.Dir(p), fs.Permissions)) require.NoError(t, os.WriteFile(p, []byte{1, 2, 3}, 0)) // Invalid address. - p = fs.treePath(objecttest.Address()) + ".invalid" + p = fs.treePath(oidtest.Address()) + ".invalid" require.NoError(t, util.MkdirAllX(filepath.Dir(p), fs.Permissions)) require.NoError(t, os.WriteFile(p, []byte{1, 2, 3}, fs.Permissions)) - err := fs.Iterate(new(IterationPrm).WithHandler(func(addr *addressSDK.Address, data []byte) error { + err := fs.Iterate(new(IterationPrm).WithHandler(func(addr oid.Address, data []byte) error { n++ return nil }).WithIgnoreErrors(true)) @@ -124,7 +124,7 @@ func TestFSTree(t *testing.T) { t.Run("error from handler is returned", func(t *testing.T) { expectedErr := errors.New("expected error") n := 0 - err := fs.Iterate(new(IterationPrm).WithHandler(func(addr *addressSDK.Address, data []byte) error { + err := fs.Iterate(new(IterationPrm).WithHandler(func(addr oid.Address, data []byte) error { n++ if n == count/2 { // process some iterations return expectedErr @@ -146,6 +146,6 @@ func TestFSTree(t *testing.T) { _, err = fs.Exists(addrs[1]) require.NoError(t, err) - require.Error(t, fs.Delete(objecttest.Address())) + require.Error(t, fs.Delete(oidtest.Address())) }) } diff --git a/pkg/local_object_storage/blobstor/iterate.go b/pkg/local_object_storage/blobstor/iterate.go index 134fafc2..f525262a 100644 --- a/pkg/local_object_storage/blobstor/iterate.go +++ b/pkg/local_object_storage/blobstor/iterate.go @@ -6,7 +6,7 @@ import ( "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" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) // IterationElement represents a unit of elements through which Iterate operation passes. @@ -88,7 +88,7 @@ func (b *BlobStor) Iterate(prm IteratePrm) (*IterateRes, error) { elem.blzID = nil - err = b.fsTree.Iterate(new(fstree.IterationPrm).WithHandler(func(_ *addressSDK.Address, data []byte) error { + err = b.fsTree.Iterate(new(fstree.IterationPrm).WithHandler(func(_ oid.Address, data []byte) error { // decompress the data elem.data, err = b.decompressor(data) if err != nil { diff --git a/pkg/local_object_storage/blobstor/iterate_test.go b/pkg/local_object_storage/blobstor/iterate_test.go index ee27f8c1..fb26080f 100644 --- a/pkg/local_object_storage/blobstor/iterate_test.go +++ b/pkg/local_object_storage/blobstor/iterate_test.go @@ -12,8 +12,8 @@ import ( "github.com/klauspost/compress/zstd" "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" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" + oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test" "github.com/stretchr/testify/require" ) @@ -45,7 +45,7 @@ func TestIterateObjects(t *testing.T) { type addrData struct { big bool - addr *addressSDK.Address + addr oid.Address data []byte } @@ -62,7 +62,7 @@ func TestIterateObjects(t *testing.T) { data := make([]byte, sz) binary.BigEndian.PutUint64(data, i) - addr := objecttest.Address() + addr := oidtest.Address() mObjs[string(data)] = addrData{ big: big, @@ -114,15 +114,13 @@ func TestIterate_IgnoreErrors(t *testing.T) { require.NoError(t, bs.Open()) require.NoError(t, bs.Init()) - addrs := make([]*addressSDK.Address, objCount) + addrs := make([]oid.Address, objCount) for i := range addrs { - addrs[i] = objecttest.Address() - id, _ := addrs[i].ObjectID() - cnr, _ := addrs[i].ContainerID() + addrs[i] = oidtest.Address() obj := object.New() - obj.SetContainerID(cnr) - obj.SetID(id) + obj.SetContainerID(addrs[i].Container()) + obj.SetID(addrs[i].Object()) obj.SetPayload(make([]byte, smallSize<<(i%2))) objData, err := obj.Marshal() @@ -142,9 +140,9 @@ func TestIterate_IgnoreErrors(t *testing.T) { rawData[i] ^= 0xFF } // Will be put uncompressed but fetched as compressed because of magic. - _, err = bs.PutRaw(objecttest.Address(), rawData, false) + _, err = bs.PutRaw(oidtest.Address(), rawData, false) require.NoError(t, err) - require.NoError(t, bs.fsTree.Put(objecttest.Address(), rawData)) + require.NoError(t, bs.fsTree.Put(oidtest.Address(), rawData)) require.NoError(t, bs.Close()) @@ -178,7 +176,7 @@ func TestIterate_IgnoreErrors(t *testing.T) { prm.IgnoreErrors() t.Run("skip invalid objects", func(t *testing.T) { - actual := make([]*addressSDK.Address, 0, len(addrs)) + actual := make([]oid.Address, 0, len(addrs)) prm.SetIterationHandler(func(e IterationElement) error { obj := object.New() err := obj.Unmarshal(e.data) @@ -186,11 +184,11 @@ func TestIterate_IgnoreErrors(t *testing.T) { return err } - addr := addressSDK.NewAddress() + var addr oid.Address cnr, _ := obj.ContainerID() - addr.SetContainerID(cnr) + addr.SetContainer(cnr) id, _ := obj.ID() - addr.SetObjectID(id) + addr.SetObject(id) actual = append(actual, addr) return nil }) diff --git a/pkg/local_object_storage/blobstor/put.go b/pkg/local_object_storage/blobstor/put.go index a7c9e6fa..289840e0 100644 --- a/pkg/local_object_storage/blobstor/put.go +++ b/pkg/local_object_storage/blobstor/put.go @@ -9,7 +9,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/core/object" 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" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) // PutPrm groups the parameters of Put operation. @@ -72,7 +72,7 @@ func (b *BlobStor) NeedsCompression(obj *objectSDK.Object) bool { } // PutRaw saves an already marshaled object in BLOB storage. -func (b *BlobStor) PutRaw(addr *addressSDK.Address, data []byte, compress bool) (*PutRes, error) { +func (b *BlobStor) PutRaw(addr oid.Address, data []byte, compress bool) (*PutRes, error) { big := b.isBig(data) if big { diff --git a/pkg/local_object_storage/blobstor/util.go b/pkg/local_object_storage/blobstor/util.go index 909ffaa0..c7c9d3b5 100644 --- a/pkg/local_object_storage/blobstor/util.go +++ b/pkg/local_object_storage/blobstor/util.go @@ -3,15 +3,15 @@ package blobstor import ( "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" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) type address struct { - addr *addressSDK.Address + addr oid.Address } // SetAddress sets the address of the requested object. -func (a *address) SetAddress(addr *addressSDK.Address) { +func (a *address) SetAddress(addr oid.Address) { a.addr = addr } diff --git a/pkg/local_object_storage/engine/container.go b/pkg/local_object_storage/engine/container.go index 43da38af..5468bad1 100644 --- a/pkg/local_object_storage/engine/container.go +++ b/pkg/local_object_storage/engine/container.go @@ -8,7 +8,7 @@ import ( // ContainerSizePrm groups parameters of ContainerSize operation. type ContainerSizePrm struct { - cid *cid.ID + cnr cid.ID } // ContainerSizeRes resulting values of ContainerSize operation. @@ -21,12 +21,12 @@ type ListContainersPrm struct{} // ListContainersRes groups the resulting values of ListContainers operation. type ListContainersRes struct { - containers []*cid.ID + containers []cid.ID } // SetContainerID sets the identifier of the container to estimate the size. -func (p *ContainerSizePrm) SetContainerID(cid *cid.ID) { - p.cid = cid +func (p *ContainerSizePrm) SetContainerID(cnr cid.ID) { + p.cnr = cnr } // Size returns calculated estimation of the container size. @@ -35,7 +35,7 @@ func (r ContainerSizeRes) Size() uint64 { } // Containers returns a list of identifiers of the containers in which local objects are stored. -func (r ListContainersRes) Containers() []*cid.ID { +func (r ListContainersRes) Containers() []cid.ID { return r.containers } @@ -52,7 +52,7 @@ func (e *StorageEngine) ContainerSize(prm ContainerSizePrm) (res *ContainerSizeR } // ContainerSize calls ContainerSize method on engine to calculate sum of estimation container sizes among all shards. -func ContainerSize(e *StorageEngine, id *cid.ID) (uint64, error) { +func ContainerSize(e *StorageEngine, id cid.ID) (uint64, error) { var prm ContainerSizePrm prm.SetContainerID(id) @@ -73,10 +73,11 @@ func (e *StorageEngine) containerSize(prm ContainerSizePrm) (*ContainerSizeRes, var res ContainerSizeRes e.iterateOverUnsortedShards(func(sh hashedShard) (stop bool) { - size, err := shard.ContainerSize(sh.Shard, prm.cid) + size, err := shard.ContainerSize(sh.Shard, prm.cnr) if err != nil { e.reportShardError(sh, "can't get container size", err, - zap.Stringer("container_id", prm.cid)) + zap.Stringer("container_id", prm.cnr), + ) return false } @@ -101,7 +102,7 @@ func (e *StorageEngine) ListContainers(_ ListContainersPrm) (res *ListContainers } // ListContainers calls ListContainers method on engine to get a unique container IDs presented in the engine objects. -func ListContainers(e *StorageEngine) ([]*cid.ID, error) { +func ListContainers(e *StorageEngine) ([]cid.ID, error) { var prm ListContainersPrm res, err := e.ListContainers(prm) @@ -117,7 +118,7 @@ func (e *StorageEngine) listContainers() (*ListContainersRes, error) { defer elapsed(e.metrics.AddListContainersDuration)() } - uniqueIDs := make(map[string]*cid.ID) + uniqueIDs := make(map[string]cid.ID) e.iterateOverUnsortedShards(func(sh hashedShard) (stop bool) { cnrs, err := shard.ListContainers(sh.Shard) @@ -127,7 +128,7 @@ func (e *StorageEngine) listContainers() (*ListContainersRes, error) { } for i := range cnrs { - id := cnrs[i].String() + id := cnrs[i].EncodeToString() if _, ok := uniqueIDs[id]; !ok { uniqueIDs[id] = cnrs[i] } @@ -136,7 +137,7 @@ func (e *StorageEngine) listContainers() (*ListContainersRes, error) { return false }) - result := make([]*cid.ID, 0, len(uniqueIDs)) + result := make([]cid.ID, 0, len(uniqueIDs)) for _, v := range uniqueIDs { result = append(result, v) } diff --git a/pkg/local_object_storage/engine/delete.go b/pkg/local_object_storage/engine/delete.go index cafd528f..4cf10d15 100644 --- a/pkg/local_object_storage/engine/delete.go +++ b/pkg/local_object_storage/engine/delete.go @@ -5,12 +5,12 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) // DeletePrm groups the parameters of Delete operation. type DeletePrm struct { - addr []*addressSDK.Address + addr []oid.Address } // DeleteRes groups the resulting values of Delete operation. @@ -19,7 +19,7 @@ type DeleteRes struct{} // WithAddresses is a Delete option to set the addresses of the objects to delete. // // Option is required. -func (p *DeletePrm) WithAddresses(addr ...*addressSDK.Address) *DeletePrm { +func (p *DeletePrm) WithAddresses(addr ...oid.Address) *DeletePrm { if p != nil { p.addr = append(p.addr, addr...) } diff --git a/pkg/local_object_storage/engine/engine_test.go b/pkg/local_object_storage/engine/engine_test.go index 4a126e10..987df2ca 100644 --- a/pkg/local_object_storage/engine/engine_test.go +++ b/pkg/local_object_storage/engine/engine_test.go @@ -14,7 +14,6 @@ import ( cid "github.com/nspcc-dev/neofs-sdk-go/container/id" cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" "github.com/nspcc-dev/neofs-sdk-go/object" - objecttest "github.com/nspcc-dev/neofs-sdk-go/object/address/test" oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test" usertest "github.com/nspcc-dev/neofs-sdk-go/user/test" "github.com/nspcc-dev/neofs-sdk-go/version" @@ -49,7 +48,7 @@ func benchmarkExists(b *testing.B, shardNum int) { _ = os.RemoveAll(b.Name()) }) - addr := objecttest.Address() + addr := oidtest.Address() for i := 0; i < 100; i++ { obj := generateObjectWithCID(b, cidtest.ID()) err := Put(e, obj) diff --git a/pkg/local_object_storage/engine/exists.go b/pkg/local_object_storage/engine/exists.go index b149c98f..b1a1be75 100644 --- a/pkg/local_object_storage/engine/exists.go +++ b/pkg/local_object_storage/engine/exists.go @@ -3,10 +3,10 @@ package engine import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) -func (e *StorageEngine) exists(addr *addressSDK.Address) (bool, error) { +func (e *StorageEngine) exists(addr oid.Address) (bool, error) { shPrm := new(shard.ExistsPrm).WithAddress(addr) alreadyRemoved := false exists := false diff --git a/pkg/local_object_storage/engine/get.go b/pkg/local_object_storage/engine/get.go index 1d753126..8d6a2669 100644 --- a/pkg/local_object_storage/engine/get.go +++ b/pkg/local_object_storage/engine/get.go @@ -7,13 +7,13 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.uber.org/zap" ) // GetPrm groups the parameters of Get operation. type GetPrm struct { - addr *addressSDK.Address + addr oid.Address } // GetRes groups the resulting values of Get operation. @@ -24,7 +24,7 @@ type GetRes struct { // WithAddress is a Get option to set the address of the requested object. // // Option is required. -func (p *GetPrm) WithAddress(addr *addressSDK.Address) *GetPrm { +func (p *GetPrm) WithAddress(addr oid.Address) *GetPrm { if p != nil { p.addr = addr } @@ -151,7 +151,7 @@ func (e *StorageEngine) get(prm *GetPrm) (*GetRes, error) { } // Get reads object from local storage by provided address. -func Get(storage *StorageEngine, addr *addressSDK.Address) (*objectSDK.Object, error) { +func Get(storage *StorageEngine, addr oid.Address) (*objectSDK.Object, error) { res, err := storage.Get(new(GetPrm). WithAddress(addr), ) diff --git a/pkg/local_object_storage/engine/head.go b/pkg/local_object_storage/engine/head.go index 43f112b8..3a75289a 100644 --- a/pkg/local_object_storage/engine/head.go +++ b/pkg/local_object_storage/engine/head.go @@ -7,12 +7,12 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) // HeadPrm groups the parameters of Head operation. type HeadPrm struct { - addr *addressSDK.Address + addr oid.Address raw bool } @@ -24,7 +24,7 @@ type HeadRes struct { // WithAddress is a Head option to set the address of the requested object. // // Option is required. -func (p *HeadPrm) WithAddress(addr *addressSDK.Address) *HeadPrm { +func (p *HeadPrm) WithAddress(addr oid.Address) *HeadPrm { if p != nil { p.addr = addr } @@ -140,7 +140,7 @@ func (e *StorageEngine) head(prm *HeadPrm) (*HeadRes, error) { } // Head reads object header from local storage by provided address. -func Head(storage *StorageEngine, addr *addressSDK.Address) (*objectSDK.Object, error) { +func Head(storage *StorageEngine, addr oid.Address) (*objectSDK.Object, error) { res, err := storage.Head(new(HeadPrm). WithAddress(addr), ) @@ -153,7 +153,7 @@ func Head(storage *StorageEngine, addr *addressSDK.Address) (*objectSDK.Object, // HeadRaw reads object header from local storage by provided address and raw // flag. -func HeadRaw(storage *StorageEngine, addr *addressSDK.Address, raw bool) (*objectSDK.Object, error) { +func HeadRaw(storage *StorageEngine, addr oid.Address, raw bool) (*objectSDK.Object, error) { res, err := storage.Head(new(HeadPrm). WithAddress(addr). WithRaw(raw), diff --git a/pkg/local_object_storage/engine/head_test.go b/pkg/local_object_storage/engine/head_test.go index 6218e77f..0bbf5d98 100644 --- a/pkg/local_object_storage/engine/head_test.go +++ b/pkg/local_object_storage/engine/head_test.go @@ -7,31 +7,31 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" "github.com/nspcc-dev/neofs-sdk-go/object" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/stretchr/testify/require" ) func TestHeadRaw(t *testing.T) { defer os.RemoveAll(t.Name()) - cid := cidtest.ID() + cnr := cidtest.ID() splitID := object.NewSplitID() - parent := generateObjectWithCID(t, cid) + parent := generateObjectWithCID(t, cnr) addAttribute(parent, "foo", "bar") - parentAddr := addressSDK.NewAddress() - parentAddr.SetContainerID(cid) + var parentAddr oid.Address + parentAddr.SetContainer(cnr) idParent, _ := parent.ID() - parentAddr.SetObjectID(idParent) + parentAddr.SetObject(idParent) - child := generateObjectWithCID(t, cid) + child := generateObjectWithCID(t, cnr) child.SetParent(parent) child.SetParentID(idParent) child.SetSplitID(splitID) - link := generateObjectWithCID(t, cid) + link := generateObjectWithCID(t, cnr) link.SetParent(parent) link.SetParentID(idParent) diff --git a/pkg/local_object_storage/engine/inhume.go b/pkg/local_object_storage/engine/inhume.go index bab202e9..2419c666 100644 --- a/pkg/local_object_storage/engine/inhume.go +++ b/pkg/local_object_storage/engine/inhume.go @@ -8,13 +8,13 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) // InhumePrm encapsulates parameters for inhume operation. type InhumePrm struct { - tombstone *addressSDK.Address - addrs []*addressSDK.Address + tombstone *oid.Address + addrs []oid.Address } // InhumeRes encapsulates results of inhume operation. @@ -25,10 +25,10 @@ type InhumeRes struct{} // // tombstone should not be nil, addr should not be empty. // Should not be called along with MarkAsGarbage. -func (p *InhumePrm) WithTarget(tombstone *addressSDK.Address, addrs ...*addressSDK.Address) *InhumePrm { +func (p *InhumePrm) WithTarget(tombstone oid.Address, addrs ...oid.Address) *InhumePrm { if p != nil { p.addrs = addrs - p.tombstone = tombstone + p.tombstone = &tombstone } return p @@ -37,7 +37,7 @@ func (p *InhumePrm) WithTarget(tombstone *addressSDK.Address, addrs ...*addressS // MarkAsGarbage marks an object to be physically removed from local storage. // // Should not be called along with WithTarget. -func (p *InhumePrm) MarkAsGarbage(addrs ...*addressSDK.Address) *InhumePrm { +func (p *InhumePrm) MarkAsGarbage(addrs ...oid.Address) *InhumePrm { if p != nil { p.addrs = addrs p.tombstone = nil @@ -73,7 +73,7 @@ func (e *StorageEngine) inhume(prm *InhumePrm) (*InhumeRes, error) { for i := range prm.addrs { if prm.tombstone != nil { - shPrm.WithTarget(prm.tombstone, prm.addrs[i]) + shPrm.WithTarget(*prm.tombstone, prm.addrs[i]) } else { shPrm.MarkAsGarbage(prm.addrs[i]) } @@ -98,7 +98,7 @@ func (e *StorageEngine) inhume(prm *InhumePrm) (*InhumeRes, error) { // 0 - fail // 1 - object locked // 2 - ok -func (e *StorageEngine) inhumeAddr(addr *addressSDK.Address, prm *shard.InhumePrm, checkExists bool) (status uint8) { +func (e *StorageEngine) inhumeAddr(addr oid.Address, prm *shard.InhumePrm, checkExists bool) (status uint8) { root := false var errLocked apistatus.ObjectLocked @@ -167,7 +167,7 @@ func (e *StorageEngine) processExpiredTombstones(ctx context.Context, addrs []me }) } -func (e *StorageEngine) processExpiredLocks(ctx context.Context, lockers []*addressSDK.Address) { +func (e *StorageEngine) processExpiredLocks(ctx context.Context, lockers []oid.Address) { e.iterateOverUnsortedShards(func(sh hashedShard) (stop bool) { sh.HandleExpiredLocks(lockers) diff --git a/pkg/local_object_storage/engine/inhume_test.go b/pkg/local_object_storage/engine/inhume_test.go index 955df1bb..efad4b58 100644 --- a/pkg/local_object_storage/engine/inhume_test.go +++ b/pkg/local_object_storage/engine/inhume_test.go @@ -47,7 +47,7 @@ func TestStorageEngine_Inhume(t *testing.T) { _, err = e.Inhume(inhumePrm) require.NoError(t, err) - addrs, err := Select(e, &cnr, fs) + addrs, err := Select(e, cnr, fs) require.NoError(t, err) require.Empty(t, addrs) }) @@ -71,7 +71,7 @@ func TestStorageEngine_Inhume(t *testing.T) { _, err = e.Inhume(inhumePrm) require.NoError(t, err) - addrs, err := Select(e, &cnr, fs) + addrs, err := Select(e, cnr, fs) require.NoError(t, err) require.Empty(t, addrs) }) diff --git a/pkg/local_object_storage/engine/list.go b/pkg/local_object_storage/engine/list.go index 9bdcbcf5..ec667a29 100644 --- a/pkg/local_object_storage/engine/list.go +++ b/pkg/local_object_storage/engine/list.go @@ -4,7 +4,7 @@ import ( "sort" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) // ErrEndOfListing is returned from an object listing with cursor @@ -40,12 +40,12 @@ func (p *ListWithCursorPrm) WithCursor(cursor *Cursor) *ListWithCursorPrm { // ListWithCursorRes contains values returned from ListWithCursor operation. type ListWithCursorRes struct { - addrList []*addressSDK.Address + addrList []oid.Address cursor *Cursor } // AddressList returns addresses selected by ListWithCursor operation. -func (l ListWithCursorRes) AddressList() []*addressSDK.Address { +func (l ListWithCursorRes) AddressList() []oid.Address { return l.addrList } @@ -62,7 +62,7 @@ func (l ListWithCursorRes) Cursor() *Cursor { // Returns ErrEndOfListing if there are no more objects to return or count // parameter set to zero. func (e *StorageEngine) ListWithCursor(prm *ListWithCursorPrm) (*ListWithCursorRes, error) { - result := make([]*addressSDK.Address, 0, prm.count) + result := make([]oid.Address, 0, prm.count) // 1. Get available shards and sort them. e.mtx.RLock() diff --git a/pkg/local_object_storage/engine/list_test.go b/pkg/local_object_storage/engine/list_test.go index ec9fb5f4..d1c40c5a 100644 --- a/pkg/local_object_storage/engine/list_test.go +++ b/pkg/local_object_storage/engine/list_test.go @@ -8,7 +8,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/core/object" cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/stretchr/testify/require" ) @@ -24,8 +24,8 @@ func TestListWithCursor(t *testing.T) { const total = 20 - expected := make([]*addressSDK.Address, 0, total) - got := make([]*addressSDK.Address, 0, total) + expected := make([]oid.Address, 0, total) + got := make([]oid.Address, 0, total) for i := 0; i < total; i++ { containerID := cidtest.ID() @@ -59,9 +59,9 @@ func TestListWithCursor(t *testing.T) { require.Equal(t, expected, got) } -func sortAddresses(addr []*addressSDK.Address) []*addressSDK.Address { +func sortAddresses(addr []oid.Address) []oid.Address { sort.Slice(addr, func(i, j int) bool { - return addr[i].String() < addr[j].String() + return addr[i].EncodeToString() < addr[j].EncodeToString() }) return addr } diff --git a/pkg/local_object_storage/engine/lock.go b/pkg/local_object_storage/engine/lock.go index 9bd8155b..e2cc9871 100644 --- a/pkg/local_object_storage/engine/lock.go +++ b/pkg/local_object_storage/engine/lock.go @@ -7,7 +7,6 @@ import ( apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" 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/address" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) @@ -26,9 +25,6 @@ func (e *StorageEngine) Lock(idCnr cid.ID, locker oid.ID, locked []oid.ID) error } func (e *StorageEngine) lock(idCnr cid.ID, locker oid.ID, locked []oid.ID) error { - var addr address.Address - addr.SetContainerID(idCnr) - for i := range locked { switch e.lockSingle(idCnr, locker, locked[i], true) { case 1: @@ -55,11 +51,11 @@ func (e *StorageEngine) lockSingle(idCnr cid.ID, locker, locked oid.ID, checkExi root := false var errIrregular apistatus.LockNonRegularObject - var addrLocked address.Address - addrLocked.SetContainerID(idCnr) - addrLocked.SetObjectID(locked) + var addrLocked oid.Address + addrLocked.SetContainer(idCnr) + addrLocked.SetObject(locked) - e.iterateOverSortedShards(&addrLocked, func(_ int, sh hashedShard) (stop bool) { + e.iterateOverSortedShards(addrLocked, func(_ int, sh hashedShard) (stop bool) { defer func() { // if object is root we continue since information about it // can be presented in other shards @@ -70,7 +66,7 @@ func (e *StorageEngine) lockSingle(idCnr cid.ID, locker, locked oid.ID, checkExi if checkExists { exRes, err := sh.Exists(new(shard.ExistsPrm). - WithAddress(&addrLocked), + WithAddress(addrLocked), ) if err != nil { var siErr *objectSDK.SplitInfoError diff --git a/pkg/local_object_storage/engine/lock_test.go b/pkg/local_object_storage/engine/lock_test.go index cce50dda..cab6f127 100644 --- a/pkg/local_object_storage/engine/lock_test.go +++ b/pkg/local_object_storage/engine/lock_test.go @@ -13,8 +13,6 @@ import ( apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" "github.com/nspcc-dev/neofs-sdk-go/object" - "github.com/nspcc-dev/neofs-sdk-go/object/address" - objecttest "github.com/nspcc-dev/neofs-sdk-go/object/address/test" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test" "github.com/panjf2000/ants/v2" @@ -61,26 +59,26 @@ func TestLockUserScenario(t *testing.T) { cnr := cidtest.ID() var err error - var objAddr address.Address - objAddr.SetContainerID(cnr) + var objAddr oid.Address + objAddr.SetContainer(cnr) - var tombAddr address.Address - tombAddr.SetContainerID(cnr) - tombAddr.SetObjectID(tombID) + var tombAddr oid.Address + tombAddr.SetContainer(cnr) + tombAddr.SetObject(tombID) - var lockerAddr address.Address - lockerAddr.SetContainerID(cnr) - lockerAddr.SetObjectID(lockerID) + var lockerAddr oid.Address + lockerAddr.SetContainer(cnr) + lockerAddr.SetObject(lockerID) - var tombForLockAddr address.Address - tombForLockAddr.SetContainerID(cnr) - tombForLockAddr.SetObjectID(tombForLockID) + var tombForLockAddr oid.Address + tombForLockAddr.SetContainer(cnr) + tombForLockAddr.SetObject(tombForLockID) // 1. obj := generateObjectWithCID(t, cnr) id, _ := obj.ID() - objAddr.SetObjectID(id) + objAddr.SetObject(id) err = Put(e, obj) require.NoError(t, err) @@ -90,7 +88,7 @@ func TestLockUserScenario(t *testing.T) { require.NoError(t, err) // 3. - _, err = e.Inhume(new(InhumePrm).WithTarget(&tombAddr, &objAddr)) + _, err = e.Inhume(new(InhumePrm).WithTarget(tombAddr, objAddr)) require.ErrorAs(t, err, new(apistatus.ObjectLocked)) // 4. @@ -106,7 +104,7 @@ func TestLockUserScenario(t *testing.T) { err = Put(e, tombObj) require.NoError(t, err) - _, err = e.Inhume(new(InhumePrm).WithTarget(&tombForLockAddr, &lockerAddr)) + _, err = e.Inhume(new(InhumePrm).WithTarget(tombForLockAddr, lockerAddr)) require.NoError(t, err, new(apistatus.ObjectLocked)) // 5. @@ -117,7 +115,7 @@ func TestLockUserScenario(t *testing.T) { // delay for GC time.Sleep(time.Second) - _, err = e.Inhume(new(InhumePrm).WithTarget(&tombAddr, &objAddr)) + _, err = e.Inhume(new(InhumePrm).WithTarget(tombAddr, objAddr)) require.NoError(t, err) } @@ -179,7 +177,7 @@ func TestLockExpiration(t *testing.T) { err = e.Lock(cnr, idLock, []oid.ID{id}) require.NoError(t, err) - _, err = e.Inhume(new(InhumePrm).WithTarget(objecttest.Address(), objectcore.AddressOf(obj))) + _, err = e.Inhume(new(InhumePrm).WithTarget(oidtest.Address(), objectcore.AddressOf(obj))) require.ErrorAs(t, err, new(apistatus.ObjectLocked)) // 3. @@ -192,6 +190,6 @@ func TestLockExpiration(t *testing.T) { time.Sleep(time.Second) // 4. - _, err = e.Inhume(new(InhumePrm).WithTarget(objecttest.Address(), objectcore.AddressOf(obj))) + _, err = e.Inhume(new(InhumePrm).WithTarget(oidtest.Address(), objectcore.AddressOf(obj))) require.NoError(t, err) } diff --git a/pkg/local_object_storage/engine/range.go b/pkg/local_object_storage/engine/range.go index dc35814f..d081a4c0 100644 --- a/pkg/local_object_storage/engine/range.go +++ b/pkg/local_object_storage/engine/range.go @@ -8,7 +8,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.uber.org/zap" ) @@ -16,7 +16,7 @@ import ( type RngPrm struct { off, ln uint64 - addr *addressSDK.Address + addr oid.Address } // RngRes groups the resulting values of GetRange operation. @@ -27,7 +27,7 @@ type RngRes struct { // WithAddress is a GetRng option to set the address of the requested object. // // Option is required. -func (p *RngPrm) WithAddress(addr *addressSDK.Address) *RngPrm { +func (p *RngPrm) WithAddress(addr oid.Address) *RngPrm { if p != nil { p.addr = addr } @@ -167,7 +167,9 @@ func (e *StorageEngine) getRange(prm *RngPrm) (*RngRes, error) { return nil, outError } e.reportShardError(shardWithMeta, "meta info was present, but object is missing", - metaError, zap.Stringer("address", prm.addr)) + metaError, + zap.Stringer("address", prm.addr), + ) } return &RngRes{ @@ -176,7 +178,7 @@ func (e *StorageEngine) getRange(prm *RngPrm) (*RngRes, error) { } // GetRange reads object payload range from local storage by provided address. -func GetRange(storage *StorageEngine, addr *addressSDK.Address, rng *objectSDK.Range) ([]byte, error) { +func GetRange(storage *StorageEngine, addr oid.Address, rng *objectSDK.Range) ([]byte, error) { res, err := storage.GetRange(new(RngPrm). WithAddress(addr). WithPayloadRange(rng), diff --git a/pkg/local_object_storage/engine/select.go b/pkg/local_object_storage/engine/select.go index 7146c5bc..d69d1b7d 100644 --- a/pkg/local_object_storage/engine/select.go +++ b/pkg/local_object_storage/engine/select.go @@ -1,30 +1,27 @@ package engine import ( - "errors" - - meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" 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" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) // SelectPrm groups the parameters of Select operation. type SelectPrm struct { - cid *cid.ID + cnr cid.ID filters object.SearchFilters } // SelectRes groups the resulting values of Select operation. type SelectRes struct { - addrList []*addressSDK.Address + addrList []oid.Address } // WithContainerID is a Select option to set the container id to search in. -func (p *SelectPrm) WithContainerID(cid *cid.ID) *SelectPrm { +func (p *SelectPrm) WithContainerID(cnr cid.ID) *SelectPrm { if p != nil { - p.cid = cid + p.cnr = cnr } return p @@ -40,7 +37,7 @@ func (p *SelectPrm) WithFilters(fs object.SearchFilters) *SelectPrm { } // AddressList returns list of addresses of the selected objects. -func (r *SelectRes) AddressList() []*addressSDK.Address { +func (r *SelectRes) AddressList() []oid.Address { return r.addrList } @@ -63,32 +60,24 @@ func (e *StorageEngine) _select(prm *SelectPrm) (*SelectRes, error) { defer elapsed(e.metrics.AddSearchDuration)() } - addrList := make([]*addressSDK.Address, 0) + addrList := make([]oid.Address, 0) uniqueMap := make(map[string]struct{}) var outError error shPrm := new(shard.SelectPrm). - WithContainerID(prm.cid). + WithContainerID(prm.cnr). WithFilters(prm.filters) e.iterateOverUnsortedShards(func(sh hashedShard) (stop bool) { res, err := sh.Select(shPrm) if err != nil { - switch { - case errors.Is(err, meta.ErrMissingContainerID): // should never happen - e.log.Error("missing container ID parameter") - outError = err - - return true - default: - e.reportShardError(sh, "could not select objects from shard", err) - return false - } + e.reportShardError(sh, "could not select objects from shard", err) + return false } else { for _, addr := range res.AddressList() { // save only unique values - if _, ok := uniqueMap[addr.String()]; !ok { - uniqueMap[addr.String()] = struct{}{} + if _, ok := uniqueMap[addr.EncodeToString()]; !ok { + uniqueMap[addr.EncodeToString()] = struct{}{} addrList = append(addrList, addr) } } @@ -120,7 +109,7 @@ func (e *StorageEngine) list(limit uint64) (*SelectRes, error) { defer elapsed(e.metrics.AddListObjectsDuration)() } - addrList := make([]*addressSDK.Address, 0, limit) + addrList := make([]oid.Address, 0, limit) uniqueMap := make(map[string]struct{}) ln := uint64(0) @@ -131,8 +120,8 @@ func (e *StorageEngine) list(limit uint64) (*SelectRes, error) { e.reportShardError(sh, "could not select objects from shard", err) } else { for _, addr := range res.AddressList() { // save only unique values - if _, ok := uniqueMap[addr.String()]; !ok { - uniqueMap[addr.String()] = struct{}{} + if _, ok := uniqueMap[addr.EncodeToString()]; !ok { + uniqueMap[addr.EncodeToString()] = struct{}{} addrList = append(addrList, addr) ln++ @@ -152,9 +141,9 @@ func (e *StorageEngine) list(limit uint64) (*SelectRes, error) { } // Select selects objects from local storage using provided filters. -func Select(storage *StorageEngine, cid *cid.ID, fs object.SearchFilters) ([]*addressSDK.Address, error) { +func Select(storage *StorageEngine, cnr cid.ID, fs object.SearchFilters) ([]oid.Address, error) { res, err := storage.Select(new(SelectPrm). - WithContainerID(cid). + WithContainerID(cnr). WithFilters(fs), ) if err != nil { @@ -166,7 +155,7 @@ func Select(storage *StorageEngine, cid *cid.ID, fs object.SearchFilters) ([]*ad // List returns `limit` available physically storage object addresses in // engine. If limit is zero, then returns all available object addresses. -func List(storage *StorageEngine, limit uint64) ([]*addressSDK.Address, error) { +func List(storage *StorageEngine, limit uint64) ([]oid.Address, error) { res, err := storage.List(limit) if err != nil { return nil, err diff --git a/pkg/local_object_storage/engine/shards.go b/pkg/local_object_storage/engine/shards.go index b8f64897..9f68e06a 100644 --- a/pkg/local_object_storage/engine/shards.go +++ b/pkg/local_object_storage/engine/shards.go @@ -7,7 +7,7 @@ import ( "github.com/google/uuid" "github.com/nspcc-dev/hrw" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/panjf2000/ants/v2" "go.uber.org/atomic" ) @@ -79,7 +79,7 @@ func (e *StorageEngine) shardWeight(sh *shard.Shard) float64 { return float64(weightValues.FreeSpace) } -func (e *StorageEngine) sortShardsByWeight(objAddr fmt.Stringer) []hashedShard { +func (e *StorageEngine) sortShardsByWeight(objAddr interface{ EncodeToString() string }) []hashedShard { e.mtx.RLock() defer e.mtx.RUnlock() @@ -91,7 +91,7 @@ func (e *StorageEngine) sortShardsByWeight(objAddr fmt.Stringer) []hashedShard { weights = append(weights, e.shardWeight(sh.Shard)) } - hrw.SortSliceByWeightValue(shards, weights, hrw.Hash([]byte(objAddr.String()))) + hrw.SortSliceByWeightValue(shards, weights, hrw.Hash([]byte(objAddr.EncodeToString()))) return shards } @@ -109,7 +109,7 @@ func (e *StorageEngine) unsortedShards() []hashedShard { return shards } -func (e *StorageEngine) iterateOverSortedShards(addr *addressSDK.Address, handler func(int, hashedShard) (stop bool)) { +func (e *StorageEngine) iterateOverSortedShards(addr oid.Address, handler func(int, hashedShard) (stop bool)) { for i, sh := range e.sortShardsByWeight(addr) { if handler(i, sh) { break diff --git a/pkg/local_object_storage/metabase/containers.go b/pkg/local_object_storage/metabase/containers.go index 8203a80d..7f6ac289 100644 --- a/pkg/local_object_storage/metabase/containers.go +++ b/pkg/local_object_storage/metabase/containers.go @@ -9,7 +9,7 @@ import ( "go.etcd.io/bbolt" ) -func (db *DB) Containers() (list []*cid.ID, err error) { +func (db *DB) Containers() (list []cid.ID, err error) { err = db.boltDB.View(func(tx *bbolt.Tx) error { list, err = db.containers(tx) @@ -19,16 +19,15 @@ func (db *DB) Containers() (list []*cid.ID, err error) { return list, err } -func (db *DB) containers(tx *bbolt.Tx) ([]*cid.ID, error) { - result := make([]*cid.ID, 0) +func (db *DB) containers(tx *bbolt.Tx) ([]cid.ID, error) { + result := make([]cid.ID, 0) unique := make(map[string]struct{}) + var cnr cid.ID err := tx.ForEach(func(name []byte, _ *bbolt.Bucket) error { - id := parseContainerID(name, unique) - - if id != nil { - result = append(result, id) - unique[id.String()] = struct{}{} + if parseContainerID(&cnr, name, unique) { + result = append(result, cnr) + unique[cnr.EncodeToString()] = struct{}{} } return nil @@ -37,7 +36,7 @@ func (db *DB) containers(tx *bbolt.Tx) ([]*cid.ID, error) { return result, err } -func (db *DB) ContainerSize(id *cid.ID) (size uint64, err error) { +func (db *DB) ContainerSize(id cid.ID) (size uint64, err error) { err = db.boltDB.Update(func(tx *bbolt.Tx) error { size, err = db.containerSize(tx, id) @@ -47,7 +46,7 @@ func (db *DB) ContainerSize(id *cid.ID) (size uint64, err error) { return size, err } -func (db *DB) containerSize(tx *bbolt.Tx, id *cid.ID) (uint64, error) { +func (db *DB) containerSize(tx *bbolt.Tx, id cid.ID) (uint64, error) { containerVolume, err := tx.CreateBucketIfNotExists(containerVolumeBucketName) if err != nil { return 0, err @@ -59,19 +58,18 @@ func (db *DB) containerSize(tx *bbolt.Tx, id *cid.ID) (uint64, error) { return parseContainerSize(containerVolume.Get(key)), nil } -func parseContainerID(name []byte, ignore map[string]struct{}) *cid.ID { - var containerID cid.ID +func parseContainerID(dst *cid.ID, name []byte, ignore map[string]struct{}) bool { strContainerID := strings.Split(string(name), invalidBase58String)[0] if _, ok := ignore[strContainerID]; ok { - return nil + return false } - if err := containerID.DecodeString(strContainerID); err != nil { - return nil + if err := dst.DecodeString(strContainerID); err != nil { + return false } - return &containerID + return true } func parseContainerSize(v []byte) uint64 { @@ -82,7 +80,7 @@ func parseContainerSize(v []byte) uint64 { return binary.LittleEndian.Uint64(v) } -func changeContainerSize(tx *bbolt.Tx, id *cid.ID, delta uint64, increase bool) error { +func changeContainerSize(tx *bbolt.Tx, id cid.ID, delta uint64, increase bool) error { containerVolume, err := tx.CreateBucketIfNotExists(containerVolumeBucketName) if err != nil { return err diff --git a/pkg/local_object_storage/metabase/containers_test.go b/pkg/local_object_storage/metabase/containers_test.go index eea241f1..8fb431cc 100644 --- a/pkg/local_object_storage/metabase/containers_test.go +++ b/pkg/local_object_storage/metabase/containers_test.go @@ -10,7 +10,7 @@ import ( cid "github.com/nspcc-dev/neofs-sdk-go/container/id" cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" - objecttest "github.com/nspcc-dev/neofs-sdk-go/object/address/test" + oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test" "github.com/stretchr/testify/require" ) @@ -26,7 +26,7 @@ func TestDB_Containers(t *testing.T) { cnr, _ := obj.ContainerID() - cids[cnr.String()] = 0 + cids[cnr.EncodeToString()] = 0 err := putBig(db, obj) require.NoError(t, err) @@ -35,16 +35,16 @@ func TestDB_Containers(t *testing.T) { lst, err := db.Containers() require.NoError(t, err) - for _, cid := range lst { - i, ok := cids[cid.String()] + for _, cnr := range lst { + i, ok := cids[cnr.EncodeToString()] require.True(t, ok) require.Equal(t, 0, i) - cids[cid.String()] = 1 + cids[cnr.EncodeToString()] = 1 } // require.Contains not working since cnrs is a ptr slice - assertContains := func(cnrs []*cid.ID, cnr cid.ID) { + assertContains := func(cnrs []cid.ID, cnr cid.ID) { found := false for i := 0; !found && i < len(cnrs); i++ { found = cnrs[i].Equals(cnr) @@ -64,7 +64,7 @@ func TestDB_Containers(t *testing.T) { assertContains(cnrs, cnr) - require.NoError(t, meta.Inhume(db, object.AddressOf(obj), objecttest.Address())) + require.NoError(t, meta.Inhume(db, object.AddressOf(obj), oidtest.Address())) cnrs, err = db.Containers() require.NoError(t, err) @@ -104,7 +104,7 @@ func TestDB_ContainersCount(t *testing.T) { {L, objectSDK.TypeLock}, } - expected := make([]*cid.ID, 0, R+T+SG+L) + expected := make([]cid.ID, 0, R+T+SG+L) for _, upload := range uploadObjects { for i := 0; i < upload.amount; i++ { @@ -115,19 +115,19 @@ func TestDB_ContainersCount(t *testing.T) { require.NoError(t, err) cnr, _ := obj.ContainerID() - expected = append(expected, &cnr) + expected = append(expected, cnr) } } sort.Slice(expected, func(i, j int) bool { - return expected[i].String() < expected[j].String() + return expected[i].EncodeToString() < expected[j].EncodeToString() }) got, err := db.Containers() require.NoError(t, err) sort.Slice(got, func(i, j int) bool { - return got[i].String() < got[j].String() + return got[i].EncodeToString() < got[j].EncodeToString() }) require.Equal(t, expected, got) @@ -169,7 +169,7 @@ func TestDB_ContainerSize(t *testing.T) { } for cnr, volume := range cids { - n, err := db.ContainerSize(&cnr) + n, err := db.ContainerSize(cnr) require.NoError(t, err) require.Equal(t, volume, int(n)) } @@ -182,12 +182,12 @@ func TestDB_ContainerSize(t *testing.T) { require.NoError(t, meta.Inhume( db, object.AddressOf(obj), - objecttest.Address(), + oidtest.Address(), )) volume -= int(obj.PayloadSize()) - n, err := db.ContainerSize(&cnr) + n, err := db.ContainerSize(cnr) require.NoError(t, err) require.Equal(t, volume, int(n)) } diff --git a/pkg/local_object_storage/metabase/control_test.go b/pkg/local_object_storage/metabase/control_test.go index 0d9867aa..b41ec0d5 100644 --- a/pkg/local_object_storage/metabase/control_test.go +++ b/pkg/local_object_storage/metabase/control_test.go @@ -5,8 +5,8 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/core/object" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" - objecttest "github.com/nspcc-dev/neofs-sdk-go/object/address/test" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" + oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test" "github.com/stretchr/testify/require" ) @@ -19,9 +19,9 @@ func TestReset(t *testing.T) { obj := generateObject(t) addr := object.AddressOf(obj) - addrToInhume := objecttest.Address() + addrToInhume := oidtest.Address() - assertExists := func(addr *addressSDK.Address, expExists bool, assertErr func(error) bool) { + assertExists := func(addr oid.Address, expExists bool, assertErr func(error) bool) { exists, err := meta.Exists(db, addr) if assertErr != nil { require.True(t, assertErr(err)) @@ -37,7 +37,7 @@ func TestReset(t *testing.T) { err = putBig(db, obj) require.NoError(t, err) - err = meta.Inhume(db, addrToInhume, objecttest.Address()) + err = meta.Inhume(db, addrToInhume, oidtest.Address()) require.NoError(t, err) assertExists(addr, true, nil) diff --git a/pkg/local_object_storage/metabase/db_test.go b/pkg/local_object_storage/metabase/db_test.go index b1590289..b8613f87 100644 --- a/pkg/local_object_storage/metabase/db_test.go +++ b/pkg/local_object_storage/metabase/db_test.go @@ -10,7 +10,7 @@ import ( cid "github.com/nspcc-dev/neofs-sdk-go/container/id" cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" "github.com/nspcc-dev/neofs-sdk-go/object" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test" usertest "github.com/nspcc-dev/neofs-sdk-go/user/test" "github.com/nspcc-dev/neofs-sdk-go/version" @@ -23,8 +23,8 @@ func putBig(db *meta.DB, obj *object.Object) error { return meta.Put(db, obj, nil) } -func testSelect(t *testing.T, db *meta.DB, cnr cid.ID, fs object.SearchFilters, exp ...*addressSDK.Address) { - res, err := meta.Select(db, &cnr, fs) +func testSelect(t *testing.T, db *meta.DB, cnr cid.ID, fs object.SearchFilters, exp ...oid.Address) { + res, err := meta.Select(db, cnr, fs) require.NoError(t, err) require.Len(t, res, len(exp)) diff --git a/pkg/local_object_storage/metabase/delete.go b/pkg/local_object_storage/metabase/delete.go index 43b0ce47..68bd9457 100644 --- a/pkg/local_object_storage/metabase/delete.go +++ b/pkg/local_object_storage/metabase/delete.go @@ -9,13 +9,13 @@ import ( storagelog "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/internal/log" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.etcd.io/bbolt" ) // DeletePrm groups the parameters of Delete operation. type DeletePrm struct { - addrs []*addressSDK.Address + addrs []oid.Address } // DeleteRes groups the resulting values of Delete operation. @@ -24,7 +24,7 @@ type DeleteRes struct{} // WithAddresses is a Delete option to set the addresses of the objects to delete. // // Option is required. -func (p *DeletePrm) WithAddresses(addrs ...*addressSDK.Address) *DeletePrm { +func (p *DeletePrm) WithAddresses(addrs ...oid.Address) *DeletePrm { if p != nil { p.addrs = addrs } @@ -33,7 +33,7 @@ func (p *DeletePrm) WithAddresses(addrs ...*addressSDK.Address) *DeletePrm { } // Delete removes objects from DB. -func Delete(db *DB, addrs ...*addressSDK.Address) error { +func Delete(db *DB, addrs ...oid.Address) error { _, err := db.Delete(new(DeletePrm).WithAddresses(addrs...)) return err } @@ -41,7 +41,7 @@ func Delete(db *DB, addrs ...*addressSDK.Address) error { type referenceNumber struct { all, cur int - addr *addressSDK.Address + addr oid.Address obj *objectSDK.Object } @@ -63,7 +63,7 @@ func (db *DB) Delete(prm *DeletePrm) (*DeleteRes, error) { return new(DeleteRes), err } -func (db *DB) deleteGroup(tx *bbolt.Tx, addrs []*addressSDK.Address) error { +func (db *DB) deleteGroup(tx *bbolt.Tx, addrs []oid.Address) error { refCounter := make(referenceCounter, len(addrs)) for i := range addrs { @@ -85,7 +85,7 @@ func (db *DB) deleteGroup(tx *bbolt.Tx, addrs []*addressSDK.Address) error { return nil } -func (db *DB) delete(tx *bbolt.Tx, addr *addressSDK.Address, refCounter referenceCounter) error { +func (db *DB) delete(tx *bbolt.Tx, addr oid.Address, refCounter referenceCounter) error { // remove record from the garbage bucket garbageBKT := tx.Bucket(garbageBucketName) if garbageBKT != nil { @@ -108,7 +108,7 @@ 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 parent := obj.Parent(); parent != nil { parAddr := object.AddressOf(parent) - sParAddr := parAddr.String() + sParAddr := parAddr.EncodeToString() nRef, ok := refCounter[sParAddr] if !ok { @@ -152,17 +152,13 @@ func (db *DB) deleteObject( } // parentLength returns amount of available children from parentid index. -func parentLength(tx *bbolt.Tx, addr *addressSDK.Address) int { - cnr, _ := addr.ContainerID() - - bkt := tx.Bucket(parentBucketName(&cnr)) +func parentLength(tx *bbolt.Tx, addr oid.Address) int { + bkt := tx.Bucket(parentBucketName(addr.Container())) if bkt == nil { return 0 } - obj, _ := addr.ObjectID() - - lst, err := decodeList(bkt.Get(objectKey(&obj))) + lst, err := decodeList(bkt.Get(objectKey(addr.Object()))) if err != nil { return 0 } @@ -232,11 +228,9 @@ func delListIndexItem(tx *bbolt.Tx, item namedBucketItem) error { func delUniqueIndexes(tx *bbolt.Tx, obj *objectSDK.Object, isParent bool) error { addr := object.AddressOf(obj) - id, _ := addr.ObjectID() - - objKey := objectKey(&id) + objKey := objectKey(addr.Object()) addrKey := addressKey(addr) - cnr, _ := addr.ContainerID() + cnr := addr.Container() // add value to primary unique bucket if !isParent { @@ -244,11 +238,11 @@ func delUniqueIndexes(tx *bbolt.Tx, obj *objectSDK.Object, isParent bool) error switch obj.Type() { case objectSDK.TypeRegular: - bucketName = primaryBucketName(&cnr) + bucketName = primaryBucketName(cnr) case objectSDK.TypeTombstone: - bucketName = tombstoneBucketName(&cnr) + bucketName = tombstoneBucketName(cnr) case objectSDK.TypeStorageGroup: - bucketName = storageGroupBucketName(&cnr) + bucketName = storageGroupBucketName(cnr) case objectSDK.TypeLock: bucketName = bucketNameLockers(cnr) default: @@ -261,17 +255,17 @@ func delUniqueIndexes(tx *bbolt.Tx, obj *objectSDK.Object, isParent bool) error }) } else { delUniqueIndexItem(tx, namedBucketItem{ - name: parentBucketName(&cnr), + name: parentBucketName(cnr), key: objKey, }) } delUniqueIndexItem(tx, namedBucketItem{ // remove from small blobovnicza id index - name: smallBucketName(&cnr), + name: smallBucketName(cnr), key: objKey, }) delUniqueIndexItem(tx, namedBucketItem{ // remove from root index - name: rootBucketName(&cnr), + name: rootBucketName(cnr), key: objKey, }) delUniqueIndexItem(tx, namedBucketItem{ // remove from ToMoveIt index diff --git a/pkg/local_object_storage/metabase/delete_test.go b/pkg/local_object_storage/metabase/delete_test.go index faa93cf2..420758fe 100644 --- a/pkg/local_object_storage/metabase/delete_test.go +++ b/pkg/local_object_storage/metabase/delete_test.go @@ -9,18 +9,18 @@ import ( apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" - objecttest "github.com/nspcc-dev/neofs-sdk-go/object/address/test" + oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test" "github.com/stretchr/testify/require" ) func TestDB_Delete(t *testing.T) { db := newDB(t) - cid := cidtest.ID() - parent := generateObjectWithCID(t, cid) + cnr := cidtest.ID() + parent := generateObjectWithCID(t, cnr) addAttribute(parent, "foo", "bar") - child := generateObjectWithCID(t, cid) + child := generateObjectWithCID(t, cnr) child.SetParent(parent) idParent, _ := parent.ID() child.SetParentID(idParent) @@ -43,7 +43,7 @@ func TestDB_Delete(t *testing.T) { require.Error(t, err) // inhume parent and child so they will be on graveyard - ts := generateObjectWithCID(t, cid) + ts := generateObjectWithCID(t, cnr) err = meta.Inhume(db, object.AddressOf(child), object.AddressOf(ts)) require.NoError(t, err) @@ -71,18 +71,18 @@ func TestDB_Delete(t *testing.T) { func TestDeleteAllChildren(t *testing.T) { db := newDB(t) - cid := cidtest.ID() + cnr := cidtest.ID() // generate parent object - parent := generateObjectWithCID(t, cid) + parent := generateObjectWithCID(t, cnr) // generate 2 children - child1 := generateObjectWithCID(t, cid) + child1 := generateObjectWithCID(t, cnr) child1.SetParent(parent) idParent, _ := parent.ID() child1.SetParentID(idParent) - child2 := generateObjectWithCID(t, cid) + child2 := generateObjectWithCID(t, cnr) child2.SetParent(parent) child2.SetParentID(idParent) @@ -108,10 +108,10 @@ func TestDeleteAllChildren(t *testing.T) { func TestGraveOnlyDelete(t *testing.T) { db := newDB(t) - addr := objecttest.Address() + addr := oidtest.Address() // inhume non-existent object by address - require.NoError(t, meta.Inhume(db, addr, nil)) + require.NoError(t, meta.Inhume(db, addr, oidtest.Address())) // delete the object data require.NoError(t, meta.Delete(db, addr)) diff --git a/pkg/local_object_storage/metabase/exists.go b/pkg/local_object_storage/metabase/exists.go index 4a6b60df..d9840d5e 100644 --- a/pkg/local_object_storage/metabase/exists.go +++ b/pkg/local_object_storage/metabase/exists.go @@ -7,13 +7,13 @@ import ( apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.etcd.io/bbolt" ) // ExistsPrm groups the parameters of Exists operation. type ExistsPrm struct { - addr *addressSDK.Address + addr oid.Address } // ExistsRes groups the resulting values of Exists operation. @@ -24,7 +24,7 @@ type ExistsRes struct { var ErrLackSplitInfo = errors.New("no split info on parent object") // WithAddress is an Exists option to set object checked for existence. -func (p *ExistsPrm) WithAddress(addr *addressSDK.Address) *ExistsPrm { +func (p *ExistsPrm) WithAddress(addr oid.Address) *ExistsPrm { if p != nil { p.addr = addr } @@ -40,7 +40,7 @@ func (p *ExistsRes) Exists() bool { // Exists checks if object is presented in DB. // // See DB.Exists docs. -func Exists(db *DB, addr *addressSDK.Address) (bool, error) { +func Exists(db *DB, addr oid.Address) (bool, error) { r, err := db.Exists(new(ExistsPrm).WithAddress(addr)) if err != nil { return false, err @@ -65,7 +65,7 @@ func (db *DB) Exists(prm *ExistsPrm) (res *ExistsRes, err error) { return } -func (db *DB) exists(tx *bbolt.Tx, addr *addressSDK.Address) (exists bool, err error) { +func (db *DB) exists(tx *bbolt.Tx, addr oid.Address) (exists bool, err error) { // check graveyard first switch inGraveyard(tx, addr) { case 1: @@ -78,19 +78,18 @@ func (db *DB) exists(tx *bbolt.Tx, addr *addressSDK.Address) (exists bool, err e return false, errRemoved } - obj, _ := addr.ObjectID() - objKey := objectKey(&obj) + objKey := objectKey(addr.Object()) - cnr, _ := addr.ContainerID() + cnr := addr.Container() // if graveyard is empty, then check if object exists in primary bucket - if inBucket(tx, primaryBucketName(&cnr), objKey) { + if inBucket(tx, primaryBucketName(cnr), objKey) { return true, nil } // if primary bucket is empty, then check if object exists in parent bucket - if inBucket(tx, parentBucketName(&cnr), objKey) { - splitInfo, err := getSplitInfo(tx, &cnr, objKey) + if inBucket(tx, parentBucketName(cnr), objKey) { + splitInfo, err := getSplitInfo(tx, cnr, objKey) if err != nil { return false, err } @@ -106,7 +105,7 @@ func (db *DB) exists(tx *bbolt.Tx, addr *addressSDK.Address) (exists bool, err e // * 0 if object is not marked for deletion; // * 1 if object with GC mark; // * 2 if object is covered with tombstone. -func inGraveyard(tx *bbolt.Tx, addr *addressSDK.Address) uint8 { +func inGraveyard(tx *bbolt.Tx, addr oid.Address) uint8 { graveyard := tx.Bucket(graveyardBucketName) if graveyard == nil { // incorrect metabase state, does not make @@ -152,8 +151,8 @@ func inBucket(tx *bbolt.Tx, name, key []byte) bool { // getSplitInfo returns SplitInfo structure from root index. Returns error // if there is no `key` record in root index. -func getSplitInfo(tx *bbolt.Tx, cid *cid.ID, key []byte) (*objectSDK.SplitInfo, error) { - rawSplitInfo := getFromBucket(tx, rootBucketName(cid), key) +func getSplitInfo(tx *bbolt.Tx, cnr cid.ID, key []byte) (*objectSDK.SplitInfo, error) { + rawSplitInfo := getFromBucket(tx, rootBucketName(cnr), key) if len(rawSplitInfo) == 0 { return nil, ErrLackSplitInfo } diff --git a/pkg/local_object_storage/metabase/exists_test.go b/pkg/local_object_storage/metabase/exists_test.go index 1c49dfa6..02dacfb3 100644 --- a/pkg/local_object_storage/metabase/exists_test.go +++ b/pkg/local_object_storage/metabase/exists_test.go @@ -68,10 +68,10 @@ func TestDB_Exists(t *testing.T) { }) t.Run("virtual object", func(t *testing.T) { - cid := cidtest.ID() - parent := generateObjectWithCID(t, cid) + cnr := cidtest.ID() + parent := generateObjectWithCID(t, cnr) - child := generateObjectWithCID(t, cid) + child := generateObjectWithCID(t, cnr) child.SetParent(parent) idParent, _ := parent.ID() child.SetParentID(idParent) @@ -86,19 +86,19 @@ func TestDB_Exists(t *testing.T) { }) t.Run("merge split info", func(t *testing.T) { - cid := cidtest.ID() + cnr := cidtest.ID() splitID := objectSDK.NewSplitID() - parent := generateObjectWithCID(t, cid) + parent := generateObjectWithCID(t, cnr) addAttribute(parent, "foo", "bar") - child := generateObjectWithCID(t, cid) + child := generateObjectWithCID(t, cnr) child.SetParent(parent) idParent, _ := parent.ID() child.SetParentID(idParent) child.SetSplitID(splitID) - link := generateObjectWithCID(t, cid) + link := generateObjectWithCID(t, cnr) link.SetParent(parent) link.SetParentID(idParent) idChild, _ := child.ID() diff --git a/pkg/local_object_storage/metabase/get.go b/pkg/local_object_storage/metabase/get.go index e5d7a57e..77da0de4 100644 --- a/pkg/local_object_storage/metabase/get.go +++ b/pkg/local_object_storage/metabase/get.go @@ -6,13 +6,13 @@ import ( apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.etcd.io/bbolt" ) // GetPrm groups the parameters of Get operation. type GetPrm struct { - addr *addressSDK.Address + addr oid.Address raw bool } @@ -24,7 +24,7 @@ type GetRes struct { // WithAddress is a Get option to set the address of the requested object. // // Option is required. -func (p *GetPrm) WithAddress(addr *addressSDK.Address) *GetPrm { +func (p *GetPrm) WithAddress(addr oid.Address) *GetPrm { if p != nil { p.addr = addr } @@ -49,7 +49,7 @@ func (r *GetRes) Header() *objectSDK.Object { } // Get reads the object from DB. -func Get(db *DB, addr *addressSDK.Address) (*objectSDK.Object, error) { +func Get(db *DB, addr oid.Address) (*objectSDK.Object, error) { r, err := db.Get(new(GetPrm).WithAddress(addr)) if err != nil { return nil, err @@ -59,7 +59,7 @@ func Get(db *DB, addr *addressSDK.Address) (*objectSDK.Object, error) { } // GetRaw reads physically stored object from DB. -func GetRaw(db *DB, addr *addressSDK.Address, raw bool) (*objectSDK.Object, error) { +func GetRaw(db *DB, addr oid.Address, raw bool) (*objectSDK.Object, error) { r, err := db.Get(new(GetPrm).WithAddress(addr).WithRaw(raw)) if err != nil { return nil, err @@ -84,10 +84,8 @@ func (db *DB) Get(prm *GetPrm) (res *GetRes, err error) { return } -func (db *DB) get(tx *bbolt.Tx, addr *addressSDK.Address, checkGraveyard, raw bool) (*objectSDK.Object, error) { - id, _ := addr.ObjectID() - key := objectKey(&id) - cnr, _ := addr.ContainerID() +func (db *DB) get(tx *bbolt.Tx, addr oid.Address, checkGraveyard, raw bool) (*objectSDK.Object, error) { + key := objectKey(addr.Object()) if checkGraveyard { switch inGraveyard(tx, addr) { @@ -102,22 +100,23 @@ func (db *DB) get(tx *bbolt.Tx, addr *addressSDK.Address, checkGraveyard, raw bo } } + cnr := addr.Container() obj := objectSDK.New() // check in primary index - data := getFromBucket(tx, primaryBucketName(&cnr), key) + data := getFromBucket(tx, primaryBucketName(cnr), key) if len(data) != 0 { return obj, obj.Unmarshal(data) } // if not found then check in tombstone index - data = getFromBucket(tx, tombstoneBucketName(&cnr), key) + data = getFromBucket(tx, tombstoneBucketName(cnr), key) if len(data) != 0 { return obj, obj.Unmarshal(data) } // if not found then check in storage group index - data = getFromBucket(tx, storageGroupBucketName(&cnr), key) + data = getFromBucket(tx, storageGroupBucketName(cnr), key) if len(data) != 0 { return obj, obj.Unmarshal(data) } @@ -129,7 +128,7 @@ func (db *DB) get(tx *bbolt.Tx, addr *addressSDK.Address, checkGraveyard, raw bo } // if not found then check if object is a virtual - return getVirtualObject(tx, &cnr, key, raw) + return getVirtualObject(tx, cnr, key, raw) } func getFromBucket(tx *bbolt.Tx, name, key []byte) []byte { @@ -141,12 +140,12 @@ func getFromBucket(tx *bbolt.Tx, name, key []byte) []byte { return bkt.Get(key) } -func getVirtualObject(tx *bbolt.Tx, cid *cid.ID, key []byte, raw bool) (*objectSDK.Object, error) { +func getVirtualObject(tx *bbolt.Tx, cnr cid.ID, key []byte, raw bool) (*objectSDK.Object, error) { if raw { - return nil, getSplitInfoError(tx, cid, key) + return nil, getSplitInfoError(tx, cnr, key) } - parentBucket := tx.Bucket(parentBucketName(cid)) + parentBucket := tx.Bucket(parentBucketName(cnr)) if parentBucket == nil { var errNotFound apistatus.ObjectNotFound @@ -168,7 +167,7 @@ func getVirtualObject(tx *bbolt.Tx, cid *cid.ID, key []byte, raw bool) (*objectS // but later list might be sorted so first or last value can be more // prioritized to choose virtualOID := relativeLst[len(relativeLst)-1] - data := getFromBucket(tx, primaryBucketName(cid), virtualOID) + data := getFromBucket(tx, primaryBucketName(cnr), virtualOID) child := objectSDK.New() @@ -188,8 +187,8 @@ func getVirtualObject(tx *bbolt.Tx, cid *cid.ID, key []byte, raw bool) (*objectS return par, nil } -func getSplitInfoError(tx *bbolt.Tx, cid *cid.ID, key []byte) error { - splitInfo, err := getSplitInfo(tx, cid, key) +func getSplitInfoError(tx *bbolt.Tx, cnr cid.ID, key []byte) error { + splitInfo, err := getSplitInfo(tx, cnr, key) if err == nil { return objectSDK.NewSplitInfoError(splitInfo) } diff --git a/pkg/local_object_storage/metabase/get_test.go b/pkg/local_object_storage/metabase/get_test.go index 058984d9..a62051c3 100644 --- a/pkg/local_object_storage/metabase/get_test.go +++ b/pkg/local_object_storage/metabase/get_test.go @@ -9,7 +9,6 @@ import ( apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" - objecttest "github.com/nspcc-dev/neofs-sdk-go/object/address/test" oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test" "github.com/stretchr/testify/require" ) @@ -74,13 +73,13 @@ func TestDB_Get(t *testing.T) { }) t.Run("put virtual object", func(t *testing.T) { - cid := cidtest.ID() + cnr := cidtest.ID() splitID := objectSDK.NewSplitID() - parent := generateObjectWithCID(t, cid) + parent := generateObjectWithCID(t, cnr) addAttribute(parent, "foo", "bar") - child := generateObjectWithCID(t, cid) + child := generateObjectWithCID(t, cnr) child.SetParent(parent) idParent, _ := parent.ID() child.SetParentID(idParent) @@ -116,15 +115,16 @@ func TestDB_Get(t *testing.T) { }) t.Run("get removed object", func(t *testing.T) { - obj := objecttest.Address() - ts := objecttest.Address() + obj := oidtest.Address() + ts := oidtest.Address() require.NoError(t, meta.Inhume(db, obj, ts)) _, err := meta.Get(db, obj) require.ErrorAs(t, err, new(apistatus.ObjectAlreadyRemoved)) - obj = objecttest.Address() - require.NoError(t, meta.Inhume(db, obj, nil)) + obj = oidtest.Address() + _, err = db.Inhume(new(meta.InhumePrm).WithAddresses(obj)) + require.NoError(t, err) _, err = meta.Get(db, obj) require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) }) diff --git a/pkg/local_object_storage/metabase/graveyard.go b/pkg/local_object_storage/metabase/graveyard.go index a8b04cc5..db7750ef 100644 --- a/pkg/local_object_storage/metabase/graveyard.go +++ b/pkg/local_object_storage/metabase/graveyard.go @@ -5,18 +5,18 @@ import ( "errors" "fmt" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.etcd.io/bbolt" ) // GarbageObject represents descriptor of the // object that has been marked with GC. type GarbageObject struct { - addr *addressSDK.Address + addr oid.Address } // Address returns garbage object address. -func (g GarbageObject) Address() *addressSDK.Address { +func (g GarbageObject) Address() oid.Address { return g.addr } @@ -27,7 +27,7 @@ type GarbageHandler func(GarbageObject) error // iteration process. type GarbageIterationPrm struct { h GarbageHandler - offset *addressSDK.Address + offset *oid.Address } // SetHandler sets a handler that will be called on every @@ -49,8 +49,8 @@ func (g *GarbageIterationPrm) SetHandler(h GarbageHandler) *GarbageIterationPrm // next element. // // Nil offset means start an integration from the beginning. -func (g *GarbageIterationPrm) SetOffset(offset *addressSDK.Address) *GarbageIterationPrm { - g.offset = offset +func (g *GarbageIterationPrm) SetOffset(offset oid.Address) *GarbageIterationPrm { + g.offset = &offset return g } @@ -68,18 +68,18 @@ func (db *DB) IterateOverGarbage(p *GarbageIterationPrm) error { // TombstonedObject represents descriptor of the // object that has been covered with tombstone. type TombstonedObject struct { - addr *addressSDK.Address - tomb *addressSDK.Address + addr oid.Address + tomb oid.Address } // Address returns tombstoned object address. -func (g TombstonedObject) Address() *addressSDK.Address { +func (g TombstonedObject) Address() oid.Address { return g.addr } // Tombstone returns address of a tombstone that // covers object. -func (g TombstonedObject) Tombstone() *addressSDK.Address { +func (g TombstonedObject) Tombstone() oid.Address { return g.tomb } @@ -90,7 +90,7 @@ type TombstonedHandler func(object TombstonedObject) error // iteration process. type GraveyardIterationPrm struct { h TombstonedHandler - offset *addressSDK.Address + offset *oid.Address } // SetHandler sets a handler that will be called on every @@ -112,8 +112,8 @@ func (g *GraveyardIterationPrm) SetHandler(h TombstonedHandler) *GraveyardIterat // next element. // // Nil offset means start an integration from the beginning. -func (g *GraveyardIterationPrm) SetOffset(offset *addressSDK.Address) *GraveyardIterationPrm { - g.offset = offset +func (g *GraveyardIterationPrm) SetOffset(offset oid.Address) *GraveyardIterationPrm { + g.offset = &offset return g } @@ -157,7 +157,7 @@ func (g graveyardHandler) handleKV(k, v []byte) error { return g.h(o) } -func (db *DB) iterateDeletedObj(tx *bbolt.Tx, h kvHandler, offset *addressSDK.Address) error { +func (db *DB) iterateDeletedObj(tx *bbolt.Tx, h kvHandler, offset *oid.Address) error { var bkt *bbolt.Bucket switch t := h.(type) { case graveyardHandler: @@ -178,7 +178,7 @@ func (db *DB) iterateDeletedObj(tx *bbolt.Tx, h kvHandler, offset *addressSDK.Ad if offset == nil { k, v = c.First() } else { - rawAddr := addressKey(offset) + rawAddr := addressKey(*offset) k, v = c.Seek(rawAddr) if bytes.Equal(k, rawAddr) { @@ -202,32 +202,23 @@ func (db *DB) iterateDeletedObj(tx *bbolt.Tx, h kvHandler, offset *addressSDK.Ad return nil } -func garbageFromKV(k []byte) (GarbageObject, error) { - addr, err := addressFromKey(k) +func garbageFromKV(k []byte) (res GarbageObject, err error) { + err = decodeAddressFromKey(&res.addr, k) if err != nil { - return GarbageObject{}, fmt.Errorf("could not parse address: %w", err) + err = fmt.Errorf("could not parse address: %w", err) } - return GarbageObject{ - addr: addr, - }, nil + return } -func graveFromKV(k, v []byte) (TombstonedObject, error) { - target, err := addressFromKey(k) - if err != nil { - return TombstonedObject{}, fmt.Errorf("could not parse address: %w", err) +func graveFromKV(k, v []byte) (res TombstonedObject, err error) { + if err = decodeAddressFromKey(&res.addr, k); err != nil { + err = fmt.Errorf("decode tombstone target from key: %w", err) + } else if err = decodeAddressFromKey(&res.tomb, v); err != nil { + err = fmt.Errorf("decode tombstone address from value: %w", err) } - tomb, err := addressFromKey(v) - if err != nil { - return TombstonedObject{}, err - } - - return TombstonedObject{ - addr: target, - tomb: tomb, - }, nil + return } // DropGraves deletes tombstoned objects from the diff --git a/pkg/local_object_storage/metabase/graveyard_test.go b/pkg/local_object_storage/metabase/graveyard_test.go index 0cd8a9a7..6ff0e6a6 100644 --- a/pkg/local_object_storage/metabase/graveyard_test.go +++ b/pkg/local_object_storage/metabase/graveyard_test.go @@ -5,8 +5,8 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/core/object" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" - objecttest "github.com/nspcc-dev/neofs-sdk-go/object/address/test" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" + oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test" "github.com/stretchr/testify/require" ) @@ -39,27 +39,23 @@ func TestDB_Iterate_OffsetNotFound(t *testing.T) { obj1 := generateObject(t) obj2 := generateObject(t) - addr1 := addressSDK.NewAddress() - err := addr1.Parse("AUSF6rhReoAdPVKYUZWW9o2LbtTvekn54B3JXi7pdzmn/2daLhLB7yVXbjBaKkckkuvjX22BxRYuSHy9RPxuH9PZS") + var addr1 oid.Address + err := addr1.DecodeString("AUSF6rhReoAdPVKYUZWW9o2LbtTvekn54B3JXi7pdzmn/2daLhLB7yVXbjBaKkckkuvjX22BxRYuSHy9RPxuH9PZS") require.NoError(t, err) - addr2 := addressSDK.NewAddress() - err = addr2.Parse("CwYYr6sFLU1zK6DeBTVd8SReADUoxYobUhSrxgXYxCVn/ANYbnJoQqdjmU5Dhk3LkxYj5E9nJHQFf8LjTEcap9TxM") + var addr2 oid.Address + err = addr2.DecodeString("CwYYr6sFLU1zK6DeBTVd8SReADUoxYobUhSrxgXYxCVn/ANYbnJoQqdjmU5Dhk3LkxYj5E9nJHQFf8LjTEcap9TxM") require.NoError(t, err) - addr3 := addressSDK.NewAddress() - err = addr3.Parse("6ay4GfhR9RgN28d5ufg63toPetkYHGcpcW7G3b7QWSek/ANYbnJoQqdjmU5Dhk3LkxYj5E9nJHQFf8LjTEcap9TxM") + var addr3 oid.Address + err = addr3.DecodeString("6ay4GfhR9RgN28d5ufg63toPetkYHGcpcW7G3b7QWSek/ANYbnJoQqdjmU5Dhk3LkxYj5E9nJHQFf8LjTEcap9TxM") require.NoError(t, err) - cnr, _ := addr1.ContainerID() - obj1.SetContainerID(cnr) - id, _ := addr1.ObjectID() - obj1.SetID(id) + obj1.SetContainerID(addr1.Container()) + obj1.SetID(addr1.Object()) - cnr, _ = addr2.ContainerID() - obj2.SetContainerID(cnr) - id, _ = addr2.ObjectID() - obj2.SetID(id) + obj2.SetContainerID(addr2.Container()) + obj2.SetID(addr2.Object()) err = putBig(db, obj1) require.NoError(t, err) @@ -75,14 +71,14 @@ func TestDB_Iterate_OffsetNotFound(t *testing.T) { iterGCPRM := new(meta.GarbageIterationPrm). SetOffset(object.AddressOf(obj2)). SetHandler(func(garbage meta.GarbageObject) error { - require.Equal(t, *garbage.Address(), *addr1) + require.Equal(t, garbage.Address(), addr1) counter++ return nil }) err = db.IterateOverGarbage(iterGCPRM.SetHandler(func(garbage meta.GarbageObject) error { - require.Equal(t, *garbage.Address(), *addr1) + require.Equal(t, garbage.Address(), addr1) counter++ return nil @@ -96,7 +92,7 @@ func TestDB_Iterate_OffsetNotFound(t *testing.T) { iterGCPRM.SetOffset(addr3) err = db.IterateOverGarbage(iterGCPRM.SetHandler(func(garbage meta.GarbageObject) error { - require.Equal(t, *garbage.Address(), *addr1) + require.Equal(t, garbage.Address(), addr1) counter++ return nil @@ -135,7 +131,7 @@ func TestDB_IterateDeletedObjects(t *testing.T) { inhumePrm := new(meta.InhumePrm) // inhume with tombstone - addrTombstone := objecttest.Address() + addrTombstone := oidtest.Address() _, err = db.Inhume(inhumePrm. WithAddresses(object.AddressOf(obj1), object.AddressOf(obj2)). @@ -152,13 +148,13 @@ func TestDB_IterateDeletedObjects(t *testing.T) { var ( counterAll int - buriedTS, buriedGC []*addressSDK.Address + buriedTS, buriedGC []oid.Address ) iterGravePRM := new(meta.GraveyardIterationPrm) err = db.IterateOverGraveyard(iterGravePRM.SetHandler(func(tomstoned meta.TombstonedObject) error { - require.Equal(t, *addrTombstone, *tomstoned.Tombstone()) + require.Equal(t, addrTombstone, tomstoned.Tombstone()) buriedTS = append(buriedTS, tomstoned.Address()) counterAll++ @@ -179,12 +175,12 @@ func TestDB_IterateDeletedObjects(t *testing.T) { // objects covered with a tombstone // also receive GS mark - garbageExpected := []*addressSDK.Address{ + garbageExpected := []oid.Address{ object.AddressOf(obj1), object.AddressOf(obj2), object.AddressOf(obj3), object.AddressOf(obj4), } - graveyardExpected := []*addressSDK.Address{ + graveyardExpected := []oid.Address{ object.AddressOf(obj1), object.AddressOf(obj2), } @@ -219,7 +215,7 @@ func TestDB_IterateOverGraveyard_Offset(t *testing.T) { inhumePrm := new(meta.InhumePrm) // inhume with tombstone - addrTombstone := objecttest.Address() + addrTombstone := oidtest.Address() _, err = db.Inhume(inhumePrm. WithAddresses(object.AddressOf(obj1), object.AddressOf(obj2), object.AddressOf(obj3), object.AddressOf(obj4)). @@ -227,7 +223,7 @@ func TestDB_IterateOverGraveyard_Offset(t *testing.T) { ) require.NoError(t, err) - expectedGraveyard := []*addressSDK.Address{ + expectedGraveyard := []oid.Address{ object.AddressOf(obj1), object.AddressOf(obj2), object.AddressOf(obj3), object.AddressOf(obj4), } @@ -236,13 +232,13 @@ func TestDB_IterateOverGraveyard_Offset(t *testing.T) { counter int firstIterationSize = len(expectedGraveyard) / 2 - gotGraveyard []*addressSDK.Address + gotGraveyard []oid.Address ) iterGraveyardPrm := new(meta.GraveyardIterationPrm) err = db.IterateOverGraveyard(iterGraveyardPrm.SetHandler(func(tombstoned meta.TombstonedObject) error { - require.Equal(t, *addrTombstone, *tombstoned.Tombstone()) + require.Equal(t, addrTombstone, tombstoned.Tombstone()) gotGraveyard = append(gotGraveyard, tombstoned.Address()) @@ -262,7 +258,7 @@ func TestDB_IterateOverGraveyard_Offset(t *testing.T) { iterGraveyardPrm.SetOffset(offset) err = db.IterateOverGraveyard(iterGraveyardPrm.SetHandler(func(tombstoned meta.TombstonedObject) error { - require.Equal(t, *addrTombstone, *tombstoned.Tombstone()) + require.Equal(t, addrTombstone, tombstoned.Tombstone()) gotGraveyard = append(gotGraveyard, tombstoned.Address()) counter++ @@ -319,7 +315,7 @@ func TestDB_IterateOverGarbage_Offset(t *testing.T) { ) require.NoError(t, err) - expectedGarbage := []*addressSDK.Address{ + expectedGarbage := []oid.Address{ object.AddressOf(obj1), object.AddressOf(obj2), object.AddressOf(obj3), object.AddressOf(obj4), } @@ -328,7 +324,7 @@ func TestDB_IterateOverGarbage_Offset(t *testing.T) { counter int firstIterationSize = len(expectedGarbage) / 2 - gotGarbage []*addressSDK.Address + gotGarbage []oid.Address ) iterGarbagePrm := new(meta.GarbageIterationPrm) @@ -394,7 +390,7 @@ func TestDB_DropGraves(t *testing.T) { inhumePrm := new(meta.InhumePrm) // inhume with tombstone - addrTombstone := objecttest.Address() + addrTombstone := oidtest.Address() _, err = db.Inhume(inhumePrm. WithAddresses(object.AddressOf(obj1), object.AddressOf(obj2)). diff --git a/pkg/local_object_storage/metabase/inhume.go b/pkg/local_object_storage/metabase/inhume.go index 3e032cfd..4a9f8ee3 100644 --- a/pkg/local_object_storage/metabase/inhume.go +++ b/pkg/local_object_storage/metabase/inhume.go @@ -7,22 +7,22 @@ import ( apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" "github.com/nspcc-dev/neofs-sdk-go/object" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.etcd.io/bbolt" ) // InhumePrm encapsulates parameters for Inhume operation. type InhumePrm struct { - tomb *addressSDK.Address + tomb *oid.Address - target []*addressSDK.Address + target []oid.Address } // InhumeRes encapsulates results of Inhume operation. type InhumeRes struct{} // WithAddresses sets a list of object addresses that should be inhumed. -func (p *InhumePrm) WithAddresses(addrs ...*addressSDK.Address) *InhumePrm { +func (p *InhumePrm) WithAddresses(addrs ...oid.Address) *InhumePrm { if p != nil { p.target = addrs } @@ -34,9 +34,9 @@ func (p *InhumePrm) WithAddresses(addrs ...*addressSDK.Address) *InhumePrm { // // addr should not be nil. // Should not be called along with WithGCMark. -func (p *InhumePrm) WithTombstoneAddress(addr *addressSDK.Address) *InhumePrm { +func (p *InhumePrm) WithTombstoneAddress(addr oid.Address) *InhumePrm { if p != nil { - p.tomb = addr + p.tomb = &addr } return p @@ -56,7 +56,7 @@ func (p *InhumePrm) WithGCMark() *InhumePrm { // Inhume inhumes the object by specified address. // // tomb should not be nil. -func Inhume(db *DB, target, tomb *addressSDK.Address) error { +func Inhume(db *DB, target, tomb oid.Address) error { _, err := db.Inhume(new(InhumePrm). WithAddresses(target). WithTombstoneAddress(tomb), @@ -89,7 +89,7 @@ func (db *DB) Inhume(prm *InhumePrm) (res *InhumeRes, err error) { if prm.tomb != nil { bkt = tx.Bucket(graveyardBucketName) - tombKey := addressKey(prm.tomb) + tombKey := addressKey(*prm.tomb) // it is forbidden to have a tomb-on-tomb in NeoFS, // so graveyard keys must not be addresses of tombstones @@ -108,8 +108,8 @@ func (db *DB) Inhume(prm *InhumePrm) (res *InhumeRes, err error) { } for i := range prm.target { - id, _ := prm.target[i].ObjectID() - cnr, _ := prm.target[i].ContainerID() + id := prm.target[i].Object() + cnr := prm.target[i].Container() // prevent locked objects to be inhumed if objectLocked(tx, cnr, id) { @@ -121,12 +121,7 @@ func (db *DB) Inhume(prm *InhumePrm) (res *InhumeRes, err error) { // if object is stored and it is regular object then update bucket // with container size estimations if err == nil && obj.Type() == object.TypeRegular { - err := changeContainerSize( - tx, - &cnr, - obj.PayloadSize(), - false, - ) + err := changeContainerSize(tx, cnr, obj.PayloadSize(), false) if err != nil { return err } diff --git a/pkg/local_object_storage/metabase/inhume_test.go b/pkg/local_object_storage/metabase/inhume_test.go index a95eb2b1..0dd0467a 100644 --- a/pkg/local_object_storage/metabase/inhume_test.go +++ b/pkg/local_object_storage/metabase/inhume_test.go @@ -6,7 +6,6 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/core/object" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" - objecttest "github.com/nspcc-dev/neofs-sdk-go/object/address/test" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test" "github.com/stretchr/testify/require" @@ -18,7 +17,7 @@ func TestDB_Inhume(t *testing.T) { raw := generateObject(t) addAttribute(raw, "foo", "bar") - tombstoneID := objecttest.Address() + tombstoneID := oidtest.Address() err := putBig(db, raw) require.NoError(t, err) @@ -39,9 +38,9 @@ func TestInhumeTombOnTomb(t *testing.T) { var ( err error - addr1 = objecttest.Address() - addr2 = objecttest.Address() - addr3 = objecttest.Address() + addr1 = oidtest.Address() + addr2 = oidtest.Address() + addr3 = oidtest.Address() inhumePrm = new(meta.InhumePrm) existsPrm = new(meta.ExistsPrm) ) @@ -78,7 +77,7 @@ func TestInhumeTombOnTomb(t *testing.T) { // try to inhume addr1 (which is already a tombstone in graveyard) _, err = db.Inhume(inhumePrm. WithAddresses(addr1). - WithTombstoneAddress(objecttest.Address()), + WithTombstoneAddress(oidtest.Address()), ) require.NoError(t, err) @@ -92,15 +91,13 @@ func TestInhumeTombOnTomb(t *testing.T) { func TestInhumeLocked(t *testing.T) { db := newDB(t) - locked := *objecttest.Address() - cnr, _ := locked.ContainerID() - id, _ := locked.ObjectID() + locked := oidtest.Address() - err := db.Lock(cnr, oidtest.ID(), []oid.ID{id}) + err := db.Lock(locked.Container(), oidtest.ID(), []oid.ID{locked.Object()}) require.NoError(t, err) var prm meta.InhumePrm - prm.WithAddresses(&locked) + prm.WithAddresses(locked) _, err = db.Inhume(&prm) diff --git a/pkg/local_object_storage/metabase/iterators.go b/pkg/local_object_storage/metabase/iterators.go index 89072524..97a6c263 100644 --- a/pkg/local_object_storage/metabase/iterators.go +++ b/pkg/local_object_storage/metabase/iterators.go @@ -8,8 +8,7 @@ import ( objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object" 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" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.etcd.io/bbolt" ) @@ -17,7 +16,7 @@ import ( type ExpiredObject struct { typ object.Type - addr *addressSDK.Address + addr oid.Address } // Type returns type of the expired object. @@ -26,7 +25,7 @@ func (e *ExpiredObject) Type() object.Type { } // Address returns address of the expired object. -func (e *ExpiredObject) Address() *addressSDK.Address { +func (e *ExpiredObject) Address() oid.Address { return e.addr } @@ -70,7 +69,7 @@ func (db *DB) iterateExpired(tx *bbolt.Tx, epoch uint64, h ExpiredObjectHandler) } return bktExpired.ForEach(func(idKey, _ []byte) error { - var id oidSDK.ID + var id oid.ID err = id.DecodeString(string(idKey)) if err != nil { @@ -92,9 +91,9 @@ func (db *DB) iterateExpired(tx *bbolt.Tx, epoch uint64, h ExpiredObjectHandler) return nil } - addr := addressSDK.NewAddress() - addr.SetContainerID(cnrID) - addr.SetObjectID(id) + var addr oid.Address + addr.SetContainer(cnrID) + addr.SetObject(id) return h(&ExpiredObject{ typ: firstIrregularObjectType(tx, cnrID, idKey), @@ -119,13 +118,13 @@ func (db *DB) iterateExpired(tx *bbolt.Tx, epoch uint64, h ExpiredObjectHandler) // Returns other errors of h directly. // // Does not modify tss. -func (db *DB) IterateCoveredByTombstones(tss map[string]*addressSDK.Address, h func(*addressSDK.Address) error) error { +func (db *DB) IterateCoveredByTombstones(tss map[string]oid.Address, h func(oid.Address) error) error { return db.boltDB.View(func(tx *bbolt.Tx) error { return db.iterateCoveredByTombstones(tx, tss, h) }) } -func (db *DB) iterateCoveredByTombstones(tx *bbolt.Tx, tss map[string]*addressSDK.Address, h func(*addressSDK.Address) error) error { +func (db *DB) iterateCoveredByTombstones(tx *bbolt.Tx, tss map[string]oid.Address, h func(oid.Address) error) error { bktGraveyard := tx.Bucket(graveyardBucketName) if bktGraveyard == nil { return nil @@ -133,15 +132,14 @@ func (db *DB) iterateCoveredByTombstones(tx *bbolt.Tx, tss map[string]*addressSD err := bktGraveyard.ForEach(func(k, v []byte) error { if _, ok := tss[string(v)]; ok { - addr, err := addressFromKey(k) + var addr oid.Address + + err := decodeAddressFromKey(&addr, k) if err != nil { return fmt.Errorf("could not parse address of the object under tombstone: %w", err) } - cnr, _ := addr.ContainerID() - obj, _ := addr.ObjectID() - - if objectLocked(tx, cnr, obj) { + if objectLocked(tx, addr.Container(), addr.Object()) { return nil } diff --git a/pkg/local_object_storage/metabase/iterators_test.go b/pkg/local_object_storage/metabase/iterators_test.go index 57a4d645..114b3ab1 100644 --- a/pkg/local_object_storage/metabase/iterators_test.go +++ b/pkg/local_object_storage/metabase/iterators_test.go @@ -8,8 +8,6 @@ import ( object2 "github.com/nspcc-dev/neofs-node/pkg/core/object" 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" - objecttest "github.com/nspcc-dev/neofs-sdk-go/object/address/test" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test" "github.com/stretchr/testify/require" @@ -20,8 +18,8 @@ func TestDB_IterateExpired(t *testing.T) { const epoch = 13 - mAlive := map[object.Type]*addressSDK.Address{} - mExpired := map[object.Type]*addressSDK.Address{} + mAlive := map[object.Type]oid.Address{} + mExpired := map[object.Type]oid.Address{} for _, typ := range []object.Type{ object.TypeRegular, @@ -34,10 +32,8 @@ func TestDB_IterateExpired(t *testing.T) { } expiredLocked := putWithExpiration(t, db, object.TypeRegular, epoch-1) - cnrExpiredLocked, _ := expiredLocked.ContainerID() - idExpiredLocked, _ := expiredLocked.ObjectID() - require.NoError(t, db.Lock(cnrExpiredLocked, oidtest.ID(), []oid.ID{idExpiredLocked})) + require.NoError(t, db.Lock(expiredLocked.Container(), oidtest.ID(), []oid.ID{expiredLocked.Object()})) err := db.IterateExpired(epoch, func(exp *meta.ExpiredObject) error { if addr, ok := mAlive[exp.Type()]; ok { @@ -59,7 +55,7 @@ func TestDB_IterateExpired(t *testing.T) { require.Empty(t, mExpired) } -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) oid.Address { obj := generateObject(t) obj.SetType(typ) addAttribute(obj, objectV2.SysAttributeExpEpoch, strconv.FormatUint(expiresAt, 10)) @@ -72,11 +68,11 @@ func putWithExpiration(t *testing.T, db *meta.DB, typ object.Type, expiresAt uin func TestDB_IterateCoveredByTombstones(t *testing.T) { db := newDB(t) - ts := objecttest.Address() - protected1 := objecttest.Address() - protected2 := objecttest.Address() - protectedLocked := objecttest.Address() - garbage := objecttest.Address() + ts := oidtest.Address() + protected1 := oidtest.Address() + protected2 := oidtest.Address() + protectedLocked := oidtest.Address() + garbage := oidtest.Address() prm := new(meta.InhumePrm) @@ -94,13 +90,13 @@ func TestDB_IterateCoveredByTombstones(t *testing.T) { ) require.NoError(t, err) - var handled []*addressSDK.Address + var handled []oid.Address - tss := map[string]*addressSDK.Address{ - ts.String(): ts, + tss := map[string]oid.Address{ + ts.EncodeToString(): ts, } - err = db.IterateCoveredByTombstones(tss, func(addr *addressSDK.Address) error { + err = db.IterateCoveredByTombstones(tss, func(addr oid.Address) error { handled = append(handled, addr) return nil }) @@ -111,15 +107,12 @@ func TestDB_IterateCoveredByTombstones(t *testing.T) { require.Contains(t, handled, protected2) require.Contains(t, handled, protectedLocked) - cnrProtectedLocked, _ := protectedLocked.ContainerID() - idProtectedLocked, _ := protectedLocked.ObjectID() - - err = db.Lock(cnrProtectedLocked, oidtest.ID(), []oid.ID{idProtectedLocked}) + err = db.Lock(protectedLocked.Container(), oidtest.ID(), []oid.ID{protectedLocked.Object()}) require.NoError(t, err) handled = handled[:0] - err = db.IterateCoveredByTombstones(tss, func(addr *addressSDK.Address) error { + err = db.IterateCoveredByTombstones(tss, func(addr oid.Address) error { handled = append(handled, addr) return nil }) diff --git a/pkg/local_object_storage/metabase/list.go b/pkg/local_object_storage/metabase/list.go index 99dc587f..252b4a82 100644 --- a/pkg/local_object_storage/metabase/list.go +++ b/pkg/local_object_storage/metabase/list.go @@ -5,7 +5,7 @@ import ( "strings" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.etcd.io/bbolt" ) @@ -42,12 +42,12 @@ func (l *ListPrm) WithCursor(cursor *Cursor) *ListPrm { // ListRes contains values returned from ListWithCursor operation. type ListRes struct { - addrList []*addressSDK.Address + addrList []oid.Address cursor *Cursor } // AddressList returns addresses selected by ListWithCursor operation. -func (l ListRes) AddressList() []*addressSDK.Address { +func (l ListRes) AddressList() []oid.Address { return l.addrList } @@ -62,7 +62,7 @@ func (l ListRes) Cursor() *Cursor { // // Returns ErrEndOfListing if there are no more objects to return or count // parameter set to zero. -func ListWithCursor(db *DB, count uint32, cursor *Cursor) ([]*addressSDK.Address, *Cursor, error) { +func ListWithCursor(db *DB, count uint32, cursor *Cursor) ([]oid.Address, *Cursor, error) { r, err := db.ListWithCursor(new(ListPrm).WithCount(count).WithCursor(cursor)) if err != nil { return nil, nil, err @@ -87,9 +87,9 @@ func (db *DB) ListWithCursor(prm *ListPrm) (res *ListRes, err error) { return res, err } -func (db *DB) listWithCursor(tx *bbolt.Tx, count int, cursor *Cursor) ([]*addressSDK.Address, *Cursor, error) { +func (db *DB) listWithCursor(tx *bbolt.Tx, count int, cursor *Cursor) ([]oid.Address, *Cursor, error) { threshold := cursor == nil // threshold is a flag to ignore cursor - result := make([]*addressSDK.Address, 0, count) + result := make([]oid.Address, 0, count) var bucketName []byte c := tx.Cursor() @@ -116,7 +116,7 @@ loop: continue } - prefix := containerID.String() + "/" + prefix := containerID.EncodeToString() + "/" result, cursor = selectNFromBucket(tx, name, prefix, result, count, cursor, threshold) bucketName = name @@ -145,12 +145,12 @@ loop: // object to start selecting from. Ignores inhumed objects. func selectNFromBucket(tx *bbolt.Tx, name []byte, // bucket name - prefix string, // string of CID, optimization - to []*addressSDK.Address, // listing result + prefix string, // string of container ID, optimization + to []oid.Address, // listing result limit int, // stop listing at `limit` items in result cursor *Cursor, // start from cursor object threshold bool, // ignore cursor and start immediately -) ([]*addressSDK.Address, *Cursor) { +) ([]oid.Address, *Cursor) { bkt := tx.Bucket(name) if bkt == nil { return to, cursor @@ -175,8 +175,8 @@ func selectNFromBucket(tx *bbolt.Tx, if count >= limit { break } - a := addressSDK.NewAddress() - if err := a.Parse(prefix + string(k)); err != nil { + var a oid.Address + if err := a.DecodeString(prefix + string(k)); err != nil { break } offset = k diff --git a/pkg/local_object_storage/metabase/list_test.go b/pkg/local_object_storage/metabase/list_test.go index 9bca2d79..a731bda7 100644 --- a/pkg/local_object_storage/metabase/list_test.go +++ b/pkg/local_object_storage/metabase/list_test.go @@ -9,7 +9,7 @@ import ( meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" 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" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/stretchr/testify/require" ) @@ -21,7 +21,7 @@ func TestLisObjectsWithCursor(t *testing.T) { total = containers * 5 // regular + ts + sg + child + lock ) - expected := make([]*addressSDK.Address, 0, total) + expected := make([]oid.Address, 0, total) // fill metabase with objects for i := 0; i < containers; i++ { @@ -82,7 +82,7 @@ func TestLisObjectsWithCursor(t *testing.T) { t.Run("success with various count", func(t *testing.T) { for countPerReq := 1; countPerReq <= total; countPerReq++ { - got := make([]*addressSDK.Address, 0, total) + got := make([]oid.Address, 0, total) res, cursor, err := meta.ListWithCursor(db, uint32(countPerReq), nil) require.NoError(t, err, "count:%d", countPerReq) @@ -125,15 +125,15 @@ func TestAddObjectDuringListingWithCursor(t *testing.T) { obj := generateObject(t) err := putBig(db, obj) require.NoError(t, err) - expected[object.AddressOf(obj).String()] = 0 + expected[object.AddressOf(obj).EncodeToString()] = 0 } // get half of the objects got, cursor, err := meta.ListWithCursor(db, total/2, nil) require.NoError(t, err) for _, obj := range got { - if _, ok := expected[obj.String()]; ok { - expected[obj.String()]++ + if _, ok := expected[obj.EncodeToString()]; ok { + expected[obj.EncodeToString()]++ } } @@ -151,8 +151,8 @@ func TestAddObjectDuringListingWithCursor(t *testing.T) { break } for _, obj := range got { - if _, ok := expected[obj.String()]; ok { - expected[obj.String()]++ + if _, ok := expected[obj.EncodeToString()]; ok { + expected[obj.EncodeToString()]++ } } } @@ -164,9 +164,9 @@ func TestAddObjectDuringListingWithCursor(t *testing.T) { } -func sortAddresses(addr []*addressSDK.Address) []*addressSDK.Address { +func sortAddresses(addr []oid.Address) []oid.Address { sort.Slice(addr, func(i, j int) bool { - return addr[i].String() < addr[j].String() + return addr[i].EncodeToString() < addr[j].EncodeToString() }) return addr } diff --git a/pkg/local_object_storage/metabase/lock.go b/pkg/local_object_storage/metabase/lock.go index 7ea2b084..1331d62d 100644 --- a/pkg/local_object_storage/metabase/lock.go +++ b/pkg/local_object_storage/metabase/lock.go @@ -7,7 +7,6 @@ import ( apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" 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" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.etcd.io/bbolt" ) @@ -20,7 +19,7 @@ const bucketNameSuffixLockers = invalidBase58String + "LOCKER" // returns name of the bucket with objects of type LOCK for specified container. func bucketNameLockers(idCnr cid.ID) []byte { - return []byte(idCnr.String() + bucketNameSuffixLockers) + return []byte(idCnr.EncodeToString() + bucketNameSuffixLockers) } // Lock marks objects as locked with another object. All objects are from the @@ -39,7 +38,7 @@ func (db *DB) Lock(cnr cid.ID, locker oid.ID, locked []oid.ID) error { bucketKeysLocked := make([][]byte, len(locked)) for i := range locked { - bucketKeysLocked[i] = objectKey(&locked[i]) + bucketKeysLocked[i] = objectKey(locked[i]) } if firstIrregularObjectType(tx, cnr, bucketKeysLocked...) != object.TypeRegular { @@ -51,12 +50,12 @@ func (db *DB) Lock(cnr cid.ID, locker oid.ID, locked []oid.ID) error { return fmt.Errorf("create global bucket for locked objects: %w", err) } - bucketLockedContainer, err := bucketLocked.CreateBucketIfNotExists([]byte(cnr.String())) + bucketLockedContainer, err := bucketLocked.CreateBucketIfNotExists([]byte(cnr.EncodeToString())) if err != nil { return fmt.Errorf("create container bucket for locked objects %v: %w", cnr, err) } - keyLocker := objectKey(&locker) + keyLocker := objectKey(locker) var exLockers [][]byte var updLockers []byte @@ -93,15 +92,12 @@ func (db *DB) Lock(cnr cid.ID, locker oid.ID, locked []oid.ID) error { } // FreeLockedBy unlocks all objects in DB which are locked by lockers. -func (db *DB) FreeLockedBy(lockers []*addressSDK.Address) error { +func (db *DB) FreeLockedBy(lockers []oid.Address) error { return db.boltDB.Update(func(tx *bbolt.Tx) error { var err error - for _, addr := range lockers { - cnr, _ := addr.ContainerID() - obj, _ := addr.ObjectID() - - err = freePotentialLocks(tx, cnr, obj) + for i := range lockers { + err = freePotentialLocks(tx, lockers[i].Container(), lockers[i].Object()) if err != nil { return err } @@ -115,9 +111,9 @@ func (db *DB) FreeLockedBy(lockers []*addressSDK.Address) error { func objectLocked(tx *bbolt.Tx, idCnr cid.ID, idObj oid.ID) bool { bucketLocked := tx.Bucket(bucketNameLocked) if bucketLocked != nil { - bucketLockedContainer := bucketLocked.Bucket([]byte(idCnr.String())) + bucketLockedContainer := bucketLocked.Bucket([]byte(idCnr.EncodeToString())) if bucketLockedContainer != nil { - return bucketLockedContainer.Get(objectKey(&idObj)) != nil + return bucketLockedContainer.Get(objectKey(idObj)) != nil } } @@ -132,9 +128,9 @@ func objectLocked(tx *bbolt.Tx, idCnr cid.ID, idObj oid.ID) bool { func freePotentialLocks(tx *bbolt.Tx, idCnr cid.ID, locker oid.ID) error { bucketLocked := tx.Bucket(bucketNameLocked) if bucketLocked != nil { - bucketLockedContainer := bucketLocked.Bucket([]byte(idCnr.String())) + bucketLockedContainer := bucketLocked.Bucket([]byte(idCnr.EncodeToString())) if bucketLockedContainer != nil { - keyLocker := objectKey(&locker) + keyLocker := objectKey(locker) return bucketLockedContainer.ForEach(func(k, v []byte) error { keyLockers, err := decodeList(v) if err != nil { diff --git a/pkg/local_object_storage/metabase/lock_test.go b/pkg/local_object_storage/metabase/lock_test.go index c0ea942a..8f8cbbb7 100644 --- a/pkg/local_object_storage/metabase/lock_test.go +++ b/pkg/local_object_storage/metabase/lock_test.go @@ -8,7 +8,6 @@ import ( apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" "github.com/nspcc-dev/neofs-sdk-go/object" - "github.com/nspcc-dev/neofs-sdk-go/object/address" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test" objecttest "github.com/nspcc-dev/neofs-sdk-go/object/test" @@ -71,20 +70,20 @@ func TestDB_Lock(t *testing.T) { err = db.Lock(cnr, tombID, []oid.ID{id}) require.NoError(t, err) - var tombAddr address.Address - tombAddr.SetContainerID(cnr) - tombAddr.SetObjectID(tombID) + var tombAddr oid.Address + tombAddr.SetContainer(cnr) + tombAddr.SetObject(tombID) // try to inhume locked object using tombstone - err = meta.Inhume(db, objectcore.AddressOf(obj), &tombAddr) + err = meta.Inhume(db, objectcore.AddressOf(obj), tombAddr) require.ErrorAs(t, err, new(apistatus.ObjectLocked)) // inhume the tombstone - _, err = db.Inhume(new(meta.InhumePrm).WithAddresses(&tombAddr).WithGCMark()) + _, err = db.Inhume(new(meta.InhumePrm).WithAddresses(tombAddr).WithGCMark()) require.NoError(t, err) // now we can inhume the object - err = meta.Inhume(db, objectcore.AddressOf(obj), &tombAddr) + err = meta.Inhume(db, objectcore.AddressOf(obj), tombAddr) require.NoError(t, err) }) } diff --git a/pkg/local_object_storage/metabase/movable.go b/pkg/local_object_storage/metabase/movable.go index 6f837205..60fcfe66 100644 --- a/pkg/local_object_storage/metabase/movable.go +++ b/pkg/local_object_storage/metabase/movable.go @@ -3,20 +3,20 @@ package meta import ( "fmt" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.etcd.io/bbolt" ) // ToMoveItPrm groups the parameters of ToMoveIt operation. type ToMoveItPrm struct { - addr *addressSDK.Address + addr oid.Address } // ToMoveItRes groups the resulting values of ToMoveIt operation. type ToMoveItRes struct{} // WithAddress sets address of the object to move into another shard. -func (p *ToMoveItPrm) WithAddress(addr *addressSDK.Address) *ToMoveItPrm { +func (p *ToMoveItPrm) WithAddress(addr oid.Address) *ToMoveItPrm { if p != nil { p.addr = addr } @@ -26,14 +26,14 @@ func (p *ToMoveItPrm) WithAddress(addr *addressSDK.Address) *ToMoveItPrm { // DoNotMovePrm groups the parameters of DoNotMove operation. type DoNotMovePrm struct { - addr *addressSDK.Address + addr oid.Address } // DoNotMoveRes groups the resulting values of DoNotMove operation. type DoNotMoveRes struct{} // WithAddress sets address of the object to prevent moving into another shard. -func (p *DoNotMovePrm) WithAddress(addr *addressSDK.Address) *DoNotMovePrm { +func (p *DoNotMovePrm) WithAddress(addr oid.Address) *DoNotMovePrm { if p != nil { p.addr = addr } @@ -46,16 +46,16 @@ type MovablePrm struct{} // MovableRes groups the resulting values of Movable operation. type MovableRes struct { - addrList []*addressSDK.Address + addrList []oid.Address } // AddressList returns resulting addresses of Movable operation. -func (p *MovableRes) AddressList() []*addressSDK.Address { +func (p *MovableRes) AddressList() []oid.Address { return p.addrList } // ToMoveIt marks object to move it into another shard. -func ToMoveIt(db *DB, addr *addressSDK.Address) error { +func ToMoveIt(db *DB, addr oid.Address) error { _, err := db.ToMoveIt(new(ToMoveItPrm).WithAddress(addr)) return err } @@ -76,7 +76,7 @@ func (db *DB) ToMoveIt(prm *ToMoveItPrm) (res *ToMoveItRes, err error) { } // DoNotMove prevents the object to be moved into another shard. -func DoNotMove(db *DB, addr *addressSDK.Address) error { +func DoNotMove(db *DB, addr oid.Address) error { _, err := db.DoNotMove(new(DoNotMovePrm).WithAddress(addr)) return err } @@ -96,7 +96,7 @@ func (db *DB) DoNotMove(prm *DoNotMovePrm) (res *DoNotMoveRes, err error) { } // Movable returns all movable objects of DB. -func Movable(db *DB) ([]*addressSDK.Address, error) { +func Movable(db *DB) ([]oid.Address, error) { r, err := db.Movable(new(MovablePrm)) if err != nil { return nil, err @@ -128,16 +128,14 @@ func (db *DB) Movable(prm *MovablePrm) (*MovableRes, error) { // we can parse strings to structures in-place, but probably it seems // more efficient to keep bolt db TX code smaller because it might be // bottleneck. - addrs := make([]*addressSDK.Address, 0, len(strAddrs)) + addrs := make([]oid.Address, len(strAddrs)) for i := range strAddrs { - addr, err := addressFromKey([]byte(strAddrs[i])) + err = decodeAddressFromKey(&addrs[i], []byte(strAddrs[i])) if err != nil { return nil, fmt.Errorf("can't parse object address %v: %w", strAddrs[i], err) } - - addrs = append(addrs, addr) } return &MovableRes{ diff --git a/pkg/local_object_storage/metabase/put.go b/pkg/local_object_storage/metabase/put.go index 6ee7b7e9..f2fedc83 100644 --- a/pkg/local_object_storage/metabase/put.go +++ b/pkg/local_object_storage/metabase/put.go @@ -13,7 +13,7 @@ import ( storagelog "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/internal/log" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.etcd.io/bbolt" ) @@ -151,12 +151,7 @@ func (db *DB) put(tx *bbolt.Tx, obj *objectSDK.Object, id *blobovnicza.ID, si *o // update container volume size estimation if obj.Type() == objectSDK.TypeRegular && !isParent { - err = changeContainerSize( - tx, - &cnr, - obj.PayloadSize(), - true, - ) + err = changeContainerSize(tx, cnr, obj.PayloadSize(), true) if err != nil { return err } @@ -173,9 +168,8 @@ func putUniqueIndexes( ) error { isParent := si != nil addr := object.AddressOf(obj) - idObj, _ := addr.ObjectID() - cnr, _ := addr.ContainerID() - objKey := objectKey(&idObj) + cnr := addr.Container() + objKey := objectKey(addr.Object()) // add value to primary unique bucket if !isParent { @@ -183,11 +177,11 @@ func putUniqueIndexes( switch obj.Type() { case objectSDK.TypeRegular: - bucketName = primaryBucketName(&cnr) + bucketName = primaryBucketName(cnr) case objectSDK.TypeTombstone: - bucketName = tombstoneBucketName(&cnr) + bucketName = tombstoneBucketName(cnr) case objectSDK.TypeStorageGroup: - bucketName = storageGroupBucketName(&cnr) + bucketName = storageGroupBucketName(cnr) case objectSDK.TypeLock: bucketName = bucketNameLockers(cnr) default: @@ -211,7 +205,7 @@ func putUniqueIndexes( // index blobovniczaID if it is present if id != nil { err = putUniqueIndexItem(tx, namedBucketItem{ - name: smallBucketName(&cnr), + name: smallBucketName(cnr), key: objKey, val: *id, }) @@ -236,7 +230,7 @@ func putUniqueIndexes( } err = putUniqueIndexItem(tx, namedBucketItem{ - name: rootBucketName(&cnr), + name: rootBucketName(cnr), key: objKey, val: splitInfo, }) @@ -251,16 +245,15 @@ func putUniqueIndexes( type updateIndexItemFunc = func(tx *bbolt.Tx, item namedBucketItem) error func updateListIndexes(tx *bbolt.Tx, obj *objectSDK.Object, f updateIndexItemFunc) error { - addr := object.AddressOf(obj) - idObj, _ := addr.ObjectID() - cnr, _ := addr.ContainerID() - objKey := objectKey(&idObj) + idObj, _ := obj.ID() + cnr, _ := obj.ContainerID() + objKey := objectKey(idObj) cs, _ := obj.PayloadChecksum() // index payload hashes err := f(tx, namedBucketItem{ - name: payloadHashBucketName(&cnr), + name: payloadHashBucketName(cnr), key: cs.Value(), val: objKey, }) @@ -273,8 +266,8 @@ func updateListIndexes(tx *bbolt.Tx, obj *objectSDK.Object, f updateIndexItemFun // index parent ids if ok { err := f(tx, namedBucketItem{ - name: parentBucketName(&cnr), - key: objectKey(&idParent), + name: parentBucketName(cnr), + key: objectKey(idParent), val: objKey, }) if err != nil { @@ -285,7 +278,7 @@ func updateListIndexes(tx *bbolt.Tx, obj *objectSDK.Object, f updateIndexItemFun // index split ids if obj.SplitID() != nil { err := f(tx, namedBucketItem{ - name: splitBucketName(&cnr), + name: splitBucketName(cnr), key: obj.SplitID().ToV2(), val: objKey, }) @@ -298,16 +291,15 @@ func updateListIndexes(tx *bbolt.Tx, obj *objectSDK.Object, f updateIndexItemFun } func updateFKBTIndexes(tx *bbolt.Tx, obj *objectSDK.Object, f updateIndexItemFunc) error { - addr := object.AddressOf(obj) - cnr, _ := addr.ContainerID() - id, _ := addr.ObjectID() + id, _ := obj.ID() + cnr, _ := obj.ContainerID() objKey := []byte(id.EncodeToString()) attrs := obj.Attributes() err := f(tx, namedBucketItem{ - name: ownerBucketName(&cnr), - key: []byte(obj.OwnerID().String()), + name: ownerBucketName(cnr), + key: []byte(obj.OwnerID().EncodeToString()), val: objKey, }) if err != nil { @@ -317,7 +309,7 @@ func updateFKBTIndexes(tx *bbolt.Tx, obj *objectSDK.Object, f updateIndexItemFun // user specified attributes for i := range attrs { err := f(tx, namedBucketItem{ - name: attributeBucketName(&cnr, attrs[i].Key()), + name: attributeBucketName(cnr, attrs[i].Key()), key: []byte(attrs[i].Value()), val: objKey, }) @@ -445,34 +437,26 @@ func getVarUint(data []byte) (uint64, int, error) { // updateBlobovniczaID for existing objects if they were moved from from // one blobovnicza to another. -func updateBlobovniczaID(tx *bbolt.Tx, addr *addressSDK.Address, id *blobovnicza.ID) error { - cnr, _ := addr.ContainerID() - - bkt, err := tx.CreateBucketIfNotExists(smallBucketName(&cnr)) +func updateBlobovniczaID(tx *bbolt.Tx, addr oid.Address, id *blobovnicza.ID) error { + bkt, err := tx.CreateBucketIfNotExists(smallBucketName(addr.Container())) if err != nil { return err } - idObj, _ := addr.ObjectID() - - return bkt.Put(objectKey(&idObj), *id) + return bkt.Put(objectKey(addr.Object()), *id) } // updateSpliInfo for existing objects if storage filled with extra information // about last object in split hierarchy or linking object. -func updateSplitInfo(tx *bbolt.Tx, addr *addressSDK.Address, from *objectSDK.SplitInfo) error { - cnr, _ := addr.ContainerID() - - bkt := tx.Bucket(rootBucketName(&cnr)) +func updateSplitInfo(tx *bbolt.Tx, addr oid.Address, from *objectSDK.SplitInfo) error { + bkt := tx.Bucket(rootBucketName(addr.Container())) if bkt == nil { // if object doesn't exists and we want to update split info on it // then ignore, this should never happen return ErrIncorrectSplitInfoUpdate } - id, _ := addr.ObjectID() - - objectKey := objectKey(&id) + objectKey := objectKey(addr.Object()) rawSplitInfo := bkt.Get(objectKey) if len(rawSplitInfo) == 0 { diff --git a/pkg/local_object_storage/metabase/put_test.go b/pkg/local_object_storage/metabase/put_test.go index 24c0b93c..c0194aa1 100644 --- a/pkg/local_object_storage/metabase/put_test.go +++ b/pkg/local_object_storage/metabase/put_test.go @@ -18,11 +18,11 @@ import ( ) func prepareObjects(t testing.TB, n int) []*objectSDK.Object { - cid := cidtest.ID() + cnr := cidtest.ID() parentID := objecttest.ID() objs := make([]*objectSDK.Object, n) for i := range objs { - objs[i] = generateObjectWithCID(t, cid) + objs[i] = generateObjectWithCID(t, cnr) // FKBT indices. attrs := make([]objectSDK.Attribute, 20) diff --git a/pkg/local_object_storage/metabase/select.go b/pkg/local_object_storage/metabase/select.go index 6e2eb715..cef43f59 100644 --- a/pkg/local_object_storage/metabase/select.go +++ b/pkg/local_object_storage/metabase/select.go @@ -9,7 +9,7 @@ import ( v2object "github.com/nspcc-dev/neofs-api-go/v2/object" 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" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.etcd.io/bbolt" "go.uber.org/zap" ) @@ -20,27 +20,29 @@ type ( // objects, and slow filters, that applied after fast filters created // smaller set of objects to check. filterGroup struct { - cid *cid.ID - fastFilters object.SearchFilters - slowFilters object.SearchFilters + withCnrFilter bool + + cnr cid.ID + + fastFilters, slowFilters object.SearchFilters } ) // SelectPrm groups the parameters of Select operation. type SelectPrm struct { - cid *cid.ID + cnr cid.ID filters object.SearchFilters } // SelectRes groups the resulting values of Select operation. type SelectRes struct { - addrList []*addressSDK.Address + addrList []oid.Address } // WithContainerID is a Select option to set the container id to search in. -func (p *SelectPrm) WithContainerID(cid *cid.ID) *SelectPrm { +func (p *SelectPrm) WithContainerID(cnr cid.ID) *SelectPrm { if p != nil { - p.cid = cid + p.cnr = cnr } return p @@ -56,15 +58,13 @@ func (p *SelectPrm) WithFilters(fs object.SearchFilters) *SelectPrm { } // AddressList returns list of addresses of the selected objects. -func (r *SelectRes) AddressList() []*addressSDK.Address { +func (r *SelectRes) AddressList() []oid.Address { return r.addrList } -var ErrMissingContainerID = errors.New("missing container id field") - // Select selects the objects from DB with filtering. -func Select(db *DB, cid *cid.ID, fs object.SearchFilters) ([]*addressSDK.Address, error) { - r, err := db.Select(new(SelectPrm).WithFilters(fs).WithContainerID(cid)) +func Select(db *DB, cnr cid.ID, fs object.SearchFilters) ([]oid.Address, error) { + r, err := db.Select(new(SelectPrm).WithFilters(fs).WithContainerID(cnr)) if err != nil { return nil, err } @@ -81,25 +81,21 @@ func (db *DB) Select(prm *SelectPrm) (res *SelectRes, err error) { } return res, db.boltDB.View(func(tx *bbolt.Tx) error { - res.addrList, err = db.selectObjects(tx, prm.cid, prm.filters) + res.addrList, err = db.selectObjects(tx, prm.cnr, prm.filters) return err }) } -func (db *DB) selectObjects(tx *bbolt.Tx, cnr *cid.ID, fs object.SearchFilters) ([]*addressSDK.Address, error) { - if cnr == nil { - return nil, ErrMissingContainerID - } - +func (db *DB) selectObjects(tx *bbolt.Tx, cnr cid.ID, fs object.SearchFilters) ([]oid.Address, error) { group, err := groupFilters(fs) if err != nil { return nil, err } - // if there are conflicts in query and cid then it means that there is no + // if there are conflicts in query and container then it means that there is no // objects to match this query. - if group.cid != nil && !cnr.Equals(*group.cid) { + if group.withCnrFilter && !cnr.Equals(group.cnr) { return nil, nil } @@ -119,14 +115,16 @@ func (db *DB) selectObjects(tx *bbolt.Tx, cnr *cid.ID, fs object.SearchFilters) } } - res := make([]*addressSDK.Address, 0, len(mAddr)) + res := make([]oid.Address, 0, len(mAddr)) for a, ind := range mAddr { if ind != expLen { continue // ignore objects with unmatched fast filters } - addr, err := addressFromKey([]byte(a)) + var addr oid.Address + + err = decodeAddressFromKey(&addr, []byte(a)) if err != nil { return nil, err } @@ -146,14 +144,14 @@ func (db *DB) selectObjects(tx *bbolt.Tx, cnr *cid.ID, fs object.SearchFilters) } // selectAll adds to resulting cache all available objects in metabase. -func (db *DB) selectAll(tx *bbolt.Tx, cid *cid.ID, to map[string]int) { - prefix := cid.String() + "/" +func (db *DB) selectAll(tx *bbolt.Tx, cnr cid.ID, to map[string]int) { + prefix := cnr.EncodeToString() + "/" - selectAllFromBucket(tx, primaryBucketName(cid), prefix, to, 0) - selectAllFromBucket(tx, tombstoneBucketName(cid), prefix, to, 0) - selectAllFromBucket(tx, storageGroupBucketName(cid), prefix, to, 0) - selectAllFromBucket(tx, parentBucketName(cid), prefix, to, 0) - selectAllFromBucket(tx, bucketNameLockers(*cid), prefix, to, 0) + selectAllFromBucket(tx, primaryBucketName(cnr), prefix, to, 0) + selectAllFromBucket(tx, tombstoneBucketName(cnr), prefix, to, 0) + selectAllFromBucket(tx, storageGroupBucketName(cnr), prefix, to, 0) + selectAllFromBucket(tx, parentBucketName(cnr), prefix, to, 0) + selectAllFromBucket(tx, bucketNameLockers(cnr), prefix, to, 0) } // selectAllFromBucket goes through all keys in bucket and adds them in a @@ -176,75 +174,73 @@ func selectAllFromBucket(tx *bbolt.Tx, name []byte, prefix string, to map[string // looking through user attribute buckets otherwise. func (db *DB) selectFastFilter( tx *bbolt.Tx, - cid *cid.ID, // container we search on + cnr cid.ID, // container we search on f object.SearchFilter, // fast filter to map[string]int, // resulting cache fNum int, // index of filter ) { - prefix := cid.String() + "/" + prefix := cnr.EncodeToString() + "/" switch f.Header() { case v2object.FilterHeaderObjectID: - db.selectObjectID(tx, f, cid, to, fNum) + db.selectObjectID(tx, f, cnr, to, fNum) case v2object.FilterHeaderOwnerID: - bucketName := ownerBucketName(cid) + bucketName := ownerBucketName(cnr) db.selectFromFKBT(tx, bucketName, f, prefix, to, fNum) case v2object.FilterHeaderPayloadHash: - bucketName := payloadHashBucketName(cid) + bucketName := payloadHashBucketName(cnr) db.selectFromList(tx, bucketName, f, prefix, to, fNum) case v2object.FilterHeaderObjectType: - for _, bucketName := range bucketNamesForType(cid, f.Operation(), f.Value()) { + for _, bucketName := range bucketNamesForType(cnr, f.Operation(), f.Value()) { selectAllFromBucket(tx, bucketName, prefix, to, fNum) } case v2object.FilterHeaderParent: - bucketName := parentBucketName(cid) + bucketName := parentBucketName(cnr) db.selectFromList(tx, bucketName, f, prefix, to, fNum) case v2object.FilterHeaderSplitID: - bucketName := splitBucketName(cid) + bucketName := splitBucketName(cnr) db.selectFromList(tx, bucketName, f, prefix, to, fNum) case v2object.FilterPropertyRoot: - selectAllFromBucket(tx, rootBucketName(cid), prefix, to, fNum) + selectAllFromBucket(tx, rootBucketName(cnr), prefix, to, fNum) case v2object.FilterPropertyPhy: - selectAllFromBucket(tx, primaryBucketName(cid), prefix, to, fNum) - selectAllFromBucket(tx, tombstoneBucketName(cid), prefix, to, fNum) - selectAllFromBucket(tx, storageGroupBucketName(cid), prefix, to, fNum) - selectAllFromBucket(tx, bucketNameLockers(*cid), prefix, to, fNum) + selectAllFromBucket(tx, primaryBucketName(cnr), prefix, to, fNum) + selectAllFromBucket(tx, tombstoneBucketName(cnr), prefix, to, fNum) + selectAllFromBucket(tx, storageGroupBucketName(cnr), prefix, to, fNum) + selectAllFromBucket(tx, bucketNameLockers(cnr), prefix, to, fNum) default: // user attribute - bucketName := attributeBucketName(cid, f.Header()) + bucketName := attributeBucketName(cnr, f.Header()) if f.Operation() == object.MatchNotPresent { - selectOutsideFKBT(tx, allBucketNames(cid), bucketName, f, prefix, to, fNum) + selectOutsideFKBT(tx, allBucketNames(cnr), bucketName, f, prefix, to, fNum) } else { db.selectFromFKBT(tx, bucketName, f, prefix, to, fNum) } } } -var mBucketNaming = map[string][]func(*cid.ID) []byte{ +var mBucketNaming = map[string][]func(cid.ID) []byte{ v2object.TypeRegular.String(): {primaryBucketName, parentBucketName}, v2object.TypeTombstone.String(): {tombstoneBucketName}, v2object.TypeStorageGroup.String(): {storageGroupBucketName}, - v2object.TypeLock.String(): {func(id *cid.ID) []byte { - return bucketNameLockers(*id) - }}, + v2object.TypeLock.String(): {bucketNameLockers}, } -func allBucketNames(cid *cid.ID) (names [][]byte) { +func allBucketNames(cnr cid.ID) (names [][]byte) { for _, fns := range mBucketNaming { for _, fn := range fns { - names = append(names, fn(cid)) + names = append(names, fn(cnr)) } } return } -func bucketNamesForType(cid *cid.ID, mType object.SearchMatchType, typeVal string) (names [][]byte) { +func bucketNamesForType(cnr cid.ID, mType object.SearchMatchType, typeVal string) (names [][]byte) { appendNames := func(key string) { fns, ok := mBucketNaming[key] if ok { for _, fn := range fns { - names = append(names, fn(cid)) + names = append(names, fn(cnr)) } } } @@ -433,16 +429,17 @@ func (db *DB) selectFromList( func (db *DB) selectObjectID( tx *bbolt.Tx, f object.SearchFilter, - cid *cid.ID, + cnr cid.ID, to map[string]int, // resulting cache fNum int, // index of filter ) { - prefix := cid.String() + "/" + prefix := cnr.EncodeToString() + "/" - appendOID := func(oid string) { - addrStr := prefix + string(oid) + appendOID := func(strObj string) { + addrStr := prefix + strObj + var addr oid.Address - addr, err := addressFromKey([]byte(addrStr)) + err := decodeAddressFromKey(&addr, []byte(addrStr)) if err != nil { db.log.Debug("can't decode object id address", zap.String("addr", addrStr), @@ -470,7 +467,7 @@ func (db *DB) selectObjectID( return } - for _, bucketName := range bucketNamesForType(cid, object.MatchStringNotEqual, "") { + for _, bucketName := range bucketNamesForType(cnr, object.MatchStringNotEqual, "") { // copy-paste from DB.selectAllFrom bkt := tx.Bucket(bucketName) if bkt == nil { @@ -478,8 +475,8 @@ func (db *DB) selectObjectID( } err := bkt.ForEach(func(k, v []byte) error { - if oid := string(k); fMatch(f.Header(), k, f.Value()) { - appendOID(oid) + if obj := string(k); fMatch(f.Header(), k, f.Value()) { + appendOID(obj) } return nil @@ -494,7 +491,7 @@ func (db *DB) selectObjectID( } // matchSlowFilters return true if object header is matched by all slow filters. -func (db *DB) matchSlowFilters(tx *bbolt.Tx, addr *addressSDK.Address, f object.SearchFilters) bool { +func (db *DB) matchSlowFilters(tx *bbolt.Tx, addr oid.Address, f object.SearchFilters) bool { if len(f) == 0 { return true } @@ -548,12 +545,12 @@ func groupFilters(filters object.SearchFilters) (*filterGroup, error) { for i := range filters { switch filters[i].Header() { case v2object.FilterHeaderContainerID: // support deprecated field - res.cid = new(cid.ID) - - err := res.cid.DecodeString(filters[i].Value()) + err := res.cnr.DecodeString(filters[i].Value()) if err != nil { return nil, fmt.Errorf("can't parse container id: %w", err) } + + res.withCnrFilter = true case // slow filters v2object.FilterHeaderVersion, v2object.FilterHeaderCreationEpoch, diff --git a/pkg/local_object_storage/metabase/select_test.go b/pkg/local_object_storage/metabase/select_test.go index 7ff6783c..2d735366 100644 --- a/pkg/local_object_storage/metabase/select_test.go +++ b/pkg/local_object_storage/metabase/select_test.go @@ -9,7 +9,7 @@ import ( meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" 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" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test" "github.com/nspcc-dev/neofs-sdk-go/version" "github.com/stretchr/testify/require" @@ -140,44 +140,44 @@ func TestDB_SelectUserAttributes(t *testing.T) { func TestDB_SelectRootPhyParent(t *testing.T) { db := newDB(t) - cid := cidtest.ID() + cnr := cidtest.ID() // prepare - small := generateObjectWithCID(t, cid) + small := generateObjectWithCID(t, cnr) err := putBig(db, small) require.NoError(t, err) - ts := generateObjectWithCID(t, cid) + ts := generateObjectWithCID(t, cnr) ts.SetType(objectSDK.TypeTombstone) err = putBig(db, ts) require.NoError(t, err) - sg := generateObjectWithCID(t, cid) + sg := generateObjectWithCID(t, cnr) sg.SetType(objectSDK.TypeStorageGroup) err = putBig(db, sg) require.NoError(t, err) - leftChild := generateObjectWithCID(t, cid) + leftChild := generateObjectWithCID(t, cnr) leftChild.InitRelations() err = putBig(db, leftChild) require.NoError(t, err) - lock := generateObjectWithCID(t, cid) + lock := generateObjectWithCID(t, cnr) lock.SetType(objectSDK.TypeLock) err = putBig(db, lock) require.NoError(t, err) - parent := generateObjectWithCID(t, cid) + parent := generateObjectWithCID(t, cnr) - rightChild := generateObjectWithCID(t, cid) + rightChild := generateObjectWithCID(t, cnr) rightChild.SetParent(parent) idParent, _ := parent.ID() rightChild.SetParentID(idParent) err = putBig(db, rightChild) require.NoError(t, err) - link := generateObjectWithCID(t, cid) + link := generateObjectWithCID(t, cnr) link.SetParent(parent) link.SetParentID(idParent) idLeftChild, _ := leftChild.ID() @@ -190,20 +190,20 @@ func TestDB_SelectRootPhyParent(t *testing.T) { t.Run("root objects", func(t *testing.T) { fs := objectSDK.SearchFilters{} fs.AddRootFilter() - testSelect(t, db, cid, fs, + testSelect(t, db, cnr, fs, object.AddressOf(small), object.AddressOf(parent), ) fs = objectSDK.SearchFilters{} fs.AddFilter(v2object.FilterPropertyRoot, "", objectSDK.MatchNotPresent) - testSelect(t, db, cid, fs) + testSelect(t, db, cnr, fs) }) t.Run("phy objects", func(t *testing.T) { fs := objectSDK.SearchFilters{} fs.AddPhyFilter() - testSelect(t, db, cid, fs, + testSelect(t, db, cnr, fs, object.AddressOf(small), object.AddressOf(ts), object.AddressOf(sg), @@ -215,13 +215,13 @@ func TestDB_SelectRootPhyParent(t *testing.T) { fs = objectSDK.SearchFilters{} fs.AddFilter(v2object.FilterPropertyPhy, "", objectSDK.MatchNotPresent) - testSelect(t, db, cid, fs) + testSelect(t, db, cnr, fs) }) t.Run("regular objects", func(t *testing.T) { fs := objectSDK.SearchFilters{} fs.AddFilter(v2object.FilterHeaderObjectType, v2object.TypeRegular.String(), objectSDK.MatchStringEqual) - testSelect(t, db, cid, fs, + testSelect(t, db, cnr, fs, object.AddressOf(small), object.AddressOf(leftChild), object.AddressOf(rightChild), @@ -231,7 +231,7 @@ func TestDB_SelectRootPhyParent(t *testing.T) { fs = objectSDK.SearchFilters{} fs.AddFilter(v2object.FilterHeaderObjectType, v2object.TypeRegular.String(), objectSDK.MatchStringNotEqual) - testSelect(t, db, cid, fs, + testSelect(t, db, cnr, fs, object.AddressOf(ts), object.AddressOf(sg), object.AddressOf(lock), @@ -239,17 +239,17 @@ func TestDB_SelectRootPhyParent(t *testing.T) { fs = objectSDK.SearchFilters{} fs.AddFilter(v2object.FilterHeaderObjectType, "", objectSDK.MatchNotPresent) - testSelect(t, db, cid, fs) + testSelect(t, db, cnr, fs) }) t.Run("tombstone objects", func(t *testing.T) { fs := objectSDK.SearchFilters{} fs.AddFilter(v2object.FilterHeaderObjectType, v2object.TypeTombstone.String(), objectSDK.MatchStringEqual) - testSelect(t, db, cid, fs, object.AddressOf(ts)) + testSelect(t, db, cnr, fs, object.AddressOf(ts)) fs = objectSDK.SearchFilters{} fs.AddFilter(v2object.FilterHeaderObjectType, v2object.TypeTombstone.String(), objectSDK.MatchStringNotEqual) - testSelect(t, db, cid, fs, + testSelect(t, db, cnr, fs, object.AddressOf(small), object.AddressOf(leftChild), object.AddressOf(rightChild), @@ -261,17 +261,17 @@ func TestDB_SelectRootPhyParent(t *testing.T) { fs = objectSDK.SearchFilters{} fs.AddFilter(v2object.FilterHeaderObjectType, "", objectSDK.MatchNotPresent) - testSelect(t, db, cid, fs) + testSelect(t, db, cnr, fs) }) t.Run("storage group objects", func(t *testing.T) { fs := objectSDK.SearchFilters{} fs.AddFilter(v2object.FilterHeaderObjectType, v2object.TypeStorageGroup.String(), objectSDK.MatchStringEqual) - testSelect(t, db, cid, fs, object.AddressOf(sg)) + testSelect(t, db, cnr, fs, object.AddressOf(sg)) fs = objectSDK.SearchFilters{} fs.AddFilter(v2object.FilterHeaderObjectType, v2object.TypeStorageGroup.String(), objectSDK.MatchStringNotEqual) - testSelect(t, db, cid, fs, + testSelect(t, db, cnr, fs, object.AddressOf(small), object.AddressOf(leftChild), object.AddressOf(rightChild), @@ -283,7 +283,7 @@ func TestDB_SelectRootPhyParent(t *testing.T) { fs = objectSDK.SearchFilters{} fs.AddFilter(v2object.FilterHeaderObjectType, "", objectSDK.MatchNotPresent) - testSelect(t, db, cid, fs) + testSelect(t, db, cnr, fs) }) t.Run("objects with parent", func(t *testing.T) { @@ -294,19 +294,19 @@ func TestDB_SelectRootPhyParent(t *testing.T) { idParent.EncodeToString(), objectSDK.MatchStringEqual) - testSelect(t, db, cid, fs, + testSelect(t, db, cnr, fs, object.AddressOf(rightChild), object.AddressOf(link), ) fs = objectSDK.SearchFilters{} fs.AddFilter(v2object.FilterHeaderParent, "", objectSDK.MatchNotPresent) - testSelect(t, db, cid, fs) + testSelect(t, db, cnr, fs) }) t.Run("all objects", func(t *testing.T) { fs := objectSDK.SearchFilters{} - testSelect(t, db, cid, fs, + testSelect(t, db, cnr, fs, object.AddressOf(small), object.AddressOf(ts), object.AddressOf(sg), @@ -322,31 +322,31 @@ func TestDB_SelectRootPhyParent(t *testing.T) { func TestDB_SelectInhume(t *testing.T) { db := newDB(t) - cid := cidtest.ID() + cnr := cidtest.ID() - raw1 := generateObjectWithCID(t, cid) + raw1 := generateObjectWithCID(t, cnr) err := putBig(db, raw1) require.NoError(t, err) - raw2 := generateObjectWithCID(t, cid) + raw2 := generateObjectWithCID(t, cnr) err = putBig(db, raw2) require.NoError(t, err) fs := objectSDK.SearchFilters{} - testSelect(t, db, cid, fs, + testSelect(t, db, cnr, fs, object.AddressOf(raw1), object.AddressOf(raw2), ) - tombstone := addressSDK.NewAddress() - tombstone.SetContainerID(cid) - tombstone.SetObjectID(oidtest.ID()) + var tombstone oid.Address + tombstone.SetContainer(cnr) + tombstone.SetObject(oidtest.ID()) err = meta.Inhume(db, object.AddressOf(raw2), tombstone) require.NoError(t, err) fs = objectSDK.SearchFilters{} - testSelect(t, db, cid, fs, + testSelect(t, db, cnr, fs, object.AddressOf(raw1), ) } @@ -354,13 +354,13 @@ func TestDB_SelectInhume(t *testing.T) { func TestDB_SelectPayloadHash(t *testing.T) { db := newDB(t) - cid := cidtest.ID() + cnr := cidtest.ID() - raw1 := generateObjectWithCID(t, cid) + raw1 := generateObjectWithCID(t, cnr) err := putBig(db, raw1) require.NoError(t, err) - raw2 := generateObjectWithCID(t, cid) + raw2 := generateObjectWithCID(t, cnr) err = putBig(db, raw2) require.NoError(t, err) @@ -371,46 +371,46 @@ func TestDB_SelectPayloadHash(t *testing.T) { hex.EncodeToString(cs.Value()), objectSDK.MatchStringEqual) - testSelect(t, db, cid, fs, object.AddressOf(raw1)) + testSelect(t, db, cnr, fs, object.AddressOf(raw1)) fs = objectSDK.SearchFilters{} fs.AddFilter(v2object.FilterHeaderPayloadHash, hex.EncodeToString(cs.Value()), objectSDK.MatchStringNotEqual) - testSelect(t, db, cid, fs, object.AddressOf(raw2)) + testSelect(t, db, cnr, fs, object.AddressOf(raw2)) fs = objectSDK.SearchFilters{} fs.AddFilter(v2object.FilterHeaderPayloadHash, "", objectSDK.MatchNotPresent) - testSelect(t, db, cid, fs) + testSelect(t, db, cnr, fs) } func TestDB_SelectWithSlowFilters(t *testing.T) { db := newDB(t) - cid := cidtest.ID() + cnr := cidtest.ID() v20 := new(version.Version) v20.SetMajor(2) - v21 := new(version.Version) + var v21 version.Version v21.SetMajor(2) v21.SetMinor(1) - raw1 := generateObjectWithCID(t, cid) + raw1 := generateObjectWithCID(t, cnr) raw1.SetPayloadSize(10) raw1.SetCreationEpoch(11) raw1.SetVersion(v20) err := putBig(db, raw1) require.NoError(t, err) - raw2 := generateObjectWithCID(t, cid) + raw2 := generateObjectWithCID(t, cnr) raw2.SetPayloadSize(20) raw2.SetCreationEpoch(21) - raw2.SetVersion(v21) + raw2.SetVersion(&v21) err = putBig(db, raw2) require.NoError(t, err) @@ -422,82 +422,82 @@ func TestDB_SelectWithSlowFilters(t *testing.T) { hex.EncodeToString(cs.Value()), objectSDK.MatchStringEqual) - testSelect(t, db, cid, fs, object.AddressOf(raw1)) + testSelect(t, db, cnr, fs, object.AddressOf(raw1)) fs = objectSDK.SearchFilters{} fs.AddFilter(v2object.FilterHeaderHomomorphicHash, hex.EncodeToString(cs.Value()), objectSDK.MatchStringNotEqual) - testSelect(t, db, cid, fs, object.AddressOf(raw2)) + testSelect(t, db, cnr, fs, object.AddressOf(raw2)) fs = objectSDK.SearchFilters{} fs.AddFilter(v2object.FilterHeaderHomomorphicHash, "", objectSDK.MatchNotPresent) - testSelect(t, db, cid, fs) + testSelect(t, db, cnr, fs) }) t.Run("object with payload length", func(t *testing.T) { fs := objectSDK.SearchFilters{} fs.AddFilter(v2object.FilterHeaderPayloadLength, "20", objectSDK.MatchStringEqual) - testSelect(t, db, cid, fs, object.AddressOf(raw2)) + testSelect(t, db, cnr, fs, object.AddressOf(raw2)) fs = objectSDK.SearchFilters{} fs.AddFilter(v2object.FilterHeaderPayloadLength, "20", objectSDK.MatchStringNotEqual) - testSelect(t, db, cid, fs, object.AddressOf(raw1)) + testSelect(t, db, cnr, fs, object.AddressOf(raw1)) fs = objectSDK.SearchFilters{} fs.AddFilter(v2object.FilterHeaderPayloadLength, "", objectSDK.MatchNotPresent) - testSelect(t, db, cid, fs) + testSelect(t, db, cnr, fs) }) t.Run("object with creation epoch", func(t *testing.T) { fs := objectSDK.SearchFilters{} fs.AddFilter(v2object.FilterHeaderCreationEpoch, "11", objectSDK.MatchStringEqual) - testSelect(t, db, cid, fs, object.AddressOf(raw1)) + testSelect(t, db, cnr, fs, object.AddressOf(raw1)) fs = objectSDK.SearchFilters{} fs.AddFilter(v2object.FilterHeaderCreationEpoch, "11", objectSDK.MatchStringNotEqual) - testSelect(t, db, cid, fs, object.AddressOf(raw2)) + testSelect(t, db, cnr, fs, object.AddressOf(raw2)) fs = objectSDK.SearchFilters{} fs.AddFilter(v2object.FilterHeaderCreationEpoch, "", objectSDK.MatchNotPresent) - testSelect(t, db, cid, fs) + testSelect(t, db, cnr, fs) }) t.Run("object with version", func(t *testing.T) { fs := objectSDK.SearchFilters{} fs.AddObjectVersionFilter(objectSDK.MatchStringEqual, v21) - testSelect(t, db, cid, fs, object.AddressOf(raw2)) + testSelect(t, db, cnr, fs, object.AddressOf(raw2)) fs = objectSDK.SearchFilters{} fs.AddObjectVersionFilter(objectSDK.MatchStringNotEqual, v21) - testSelect(t, db, cid, fs, object.AddressOf(raw1)) + testSelect(t, db, cnr, fs, object.AddressOf(raw1)) fs = objectSDK.SearchFilters{} - fs.AddObjectVersionFilter(objectSDK.MatchNotPresent, nil) - testSelect(t, db, cid, fs) + fs.AddObjectVersionFilter(objectSDK.MatchNotPresent, version.Version{}) + testSelect(t, db, cnr, fs) }) } func TestDB_SelectObjectID(t *testing.T) { db := newDB(t) - cid := cidtest.ID() + cnr := cidtest.ID() // prepare - parent := generateObjectWithCID(t, cid) + parent := generateObjectWithCID(t, cnr) - regular := generateObjectWithCID(t, cid) + regular := generateObjectWithCID(t, cnr) idParent, _ := parent.ID() regular.SetParentID(idParent) regular.SetParent(parent) @@ -505,35 +505,35 @@ func TestDB_SelectObjectID(t *testing.T) { err := putBig(db, regular) require.NoError(t, err) - ts := generateObjectWithCID(t, cid) + ts := generateObjectWithCID(t, cnr) ts.SetType(objectSDK.TypeTombstone) err = putBig(db, ts) require.NoError(t, err) - sg := generateObjectWithCID(t, cid) + sg := generateObjectWithCID(t, cnr) sg.SetType(objectSDK.TypeStorageGroup) err = putBig(db, sg) require.NoError(t, err) - lock := generateObjectWithCID(t, cid) + lock := generateObjectWithCID(t, cnr) lock.SetType(objectSDK.TypeLock) err = putBig(db, lock) require.NoError(t, err) t.Run("not found objects", func(t *testing.T) { - raw := generateObjectWithCID(t, cid) + raw := generateObjectWithCID(t, cnr) id, _ := raw.ID() fs := objectSDK.SearchFilters{} fs.AddObjectIDFilter(objectSDK.MatchStringEqual, id) - testSelect(t, db, cid, fs) + testSelect(t, db, cnr, fs) fs = objectSDK.SearchFilters{} fs.AddObjectIDFilter(objectSDK.MatchStringNotEqual, id) - testSelect(t, db, cid, fs, + testSelect(t, db, cnr, fs, object.AddressOf(regular), object.AddressOf(parent), object.AddressOf(sg), @@ -547,11 +547,11 @@ func TestDB_SelectObjectID(t *testing.T) { fs := objectSDK.SearchFilters{} fs.AddObjectIDFilter(objectSDK.MatchStringEqual, id) - testSelect(t, db, cid, fs, object.AddressOf(regular)) + testSelect(t, db, cnr, fs, object.AddressOf(regular)) fs = objectSDK.SearchFilters{} fs.AddObjectIDFilter(objectSDK.MatchStringNotEqual, id) - testSelect(t, db, cid, fs, + testSelect(t, db, cnr, fs, object.AddressOf(parent), object.AddressOf(sg), object.AddressOf(ts), @@ -564,11 +564,11 @@ func TestDB_SelectObjectID(t *testing.T) { fs := objectSDK.SearchFilters{} fs.AddObjectIDFilter(objectSDK.MatchStringEqual, id) - testSelect(t, db, cid, fs, object.AddressOf(ts)) + testSelect(t, db, cnr, fs, object.AddressOf(ts)) fs = objectSDK.SearchFilters{} fs.AddObjectIDFilter(objectSDK.MatchStringNotEqual, id) - testSelect(t, db, cid, fs, + testSelect(t, db, cnr, fs, object.AddressOf(regular), object.AddressOf(parent), object.AddressOf(sg), @@ -581,11 +581,11 @@ func TestDB_SelectObjectID(t *testing.T) { fs := objectSDK.SearchFilters{} fs.AddObjectIDFilter(objectSDK.MatchStringEqual, id) - testSelect(t, db, cid, fs, object.AddressOf(sg)) + testSelect(t, db, cnr, fs, object.AddressOf(sg)) fs = objectSDK.SearchFilters{} fs.AddObjectIDFilter(objectSDK.MatchStringNotEqual, id) - testSelect(t, db, cid, fs, + testSelect(t, db, cnr, fs, object.AddressOf(regular), object.AddressOf(parent), object.AddressOf(ts), @@ -598,11 +598,11 @@ func TestDB_SelectObjectID(t *testing.T) { fs := objectSDK.SearchFilters{} fs.AddObjectIDFilter(objectSDK.MatchStringEqual, id) - testSelect(t, db, cid, fs, object.AddressOf(parent)) + testSelect(t, db, cnr, fs, object.AddressOf(parent)) fs = objectSDK.SearchFilters{} fs.AddObjectIDFilter(objectSDK.MatchStringNotEqual, id) - testSelect(t, db, cid, fs, + testSelect(t, db, cnr, fs, object.AddressOf(regular), object.AddressOf(sg), object.AddressOf(ts), @@ -615,11 +615,11 @@ func TestDB_SelectObjectID(t *testing.T) { fs := objectSDK.SearchFilters{} fs.AddObjectIDFilter(objectSDK.MatchStringEqual, id) - testSelect(t, db, cid, fs, object.AddressOf(lock)) + testSelect(t, db, cnr, fs, object.AddressOf(lock)) fs = objectSDK.SearchFilters{} fs.AddObjectIDFilter(objectSDK.MatchStringNotEqual, id) - testSelect(t, db, cid, fs, + testSelect(t, db, cnr, fs, object.AddressOf(regular), object.AddressOf(parent), object.AddressOf(sg), @@ -631,11 +631,11 @@ func TestDB_SelectObjectID(t *testing.T) { func TestDB_SelectSplitID(t *testing.T) { db := newDB(t) - cid := cidtest.ID() + cnr := cidtest.ID() - child1 := generateObjectWithCID(t, cid) - child2 := generateObjectWithCID(t, cid) - child3 := generateObjectWithCID(t, cid) + child1 := generateObjectWithCID(t, cnr) + child2 := generateObjectWithCID(t, cnr) + child3 := generateObjectWithCID(t, cnr) split1 := objectSDK.NewSplitID() split2 := objectSDK.NewSplitID() @@ -651,26 +651,26 @@ func TestDB_SelectSplitID(t *testing.T) { t.Run("not present", func(t *testing.T) { fs := objectSDK.SearchFilters{} fs.AddFilter(v2object.FilterHeaderSplitID, "", objectSDK.MatchNotPresent) - testSelect(t, db, cid, fs) + testSelect(t, db, cnr, fs) }) t.Run("split id", func(t *testing.T) { fs := objectSDK.SearchFilters{} fs.AddFilter(v2object.FilterHeaderSplitID, split1.String(), objectSDK.MatchStringEqual) - testSelect(t, db, cid, fs, + testSelect(t, db, cnr, fs, object.AddressOf(child1), object.AddressOf(child2), ) fs = objectSDK.SearchFilters{} fs.AddFilter(v2object.FilterHeaderSplitID, split2.String(), objectSDK.MatchStringEqual) - testSelect(t, db, cid, fs, object.AddressOf(child3)) + testSelect(t, db, cnr, fs, object.AddressOf(child3)) }) t.Run("empty split", func(t *testing.T) { fs := objectSDK.SearchFilters{} fs.AddFilter(v2object.FilterHeaderSplitID, "", objectSDK.MatchStringEqual) - testSelect(t, db, cid, fs) + testSelect(t, db, cnr, fs) }) t.Run("unknown split id", func(t *testing.T) { @@ -678,52 +678,52 @@ func TestDB_SelectSplitID(t *testing.T) { fs.AddFilter(v2object.FilterHeaderSplitID, objectSDK.NewSplitID().String(), objectSDK.MatchStringEqual) - testSelect(t, db, cid, fs) + testSelect(t, db, cnr, fs) }) } func TestDB_SelectContainerID(t *testing.T) { db := newDB(t) - cid := cidtest.ID() + cnr := cidtest.ID() - obj1 := generateObjectWithCID(t, cid) + obj1 := generateObjectWithCID(t, cnr) err := putBig(db, obj1) require.NoError(t, err) - obj2 := generateObjectWithCID(t, cid) + obj2 := generateObjectWithCID(t, cnr) err = putBig(db, obj2) require.NoError(t, err) t.Run("same cid", func(t *testing.T) { fs := objectSDK.SearchFilters{} - fs.AddObjectContainerIDFilter(objectSDK.MatchStringEqual, cid) + fs.AddObjectContainerIDFilter(objectSDK.MatchStringEqual, cnr) - testSelect(t, db, cid, fs, + testSelect(t, db, cnr, fs, object.AddressOf(obj1), object.AddressOf(obj2), ) fs = objectSDK.SearchFilters{} - fs.AddObjectContainerIDFilter(objectSDK.MatchStringNotEqual, cid) + fs.AddObjectContainerIDFilter(objectSDK.MatchStringNotEqual, cnr) - testSelect(t, db, cid, fs, + testSelect(t, db, cnr, fs, object.AddressOf(obj1), object.AddressOf(obj2), ) fs = objectSDK.SearchFilters{} - fs.AddObjectContainerIDFilter(objectSDK.MatchNotPresent, cid) + fs.AddObjectContainerIDFilter(objectSDK.MatchNotPresent, cnr) - testSelect(t, db, cid, fs) + testSelect(t, db, cnr, fs) }) t.Run("not same cid", func(t *testing.T) { - newCID := cidtest.ID() + newCnr := cidtest.ID() fs := objectSDK.SearchFilters{} - fs.AddObjectContainerIDFilter(objectSDK.MatchStringEqual, newCID) + fs.AddObjectContainerIDFilter(objectSDK.MatchStringEqual, newCnr) - testSelect(t, db, cid, fs) + testSelect(t, db, cnr, fs) }) } diff --git a/pkg/local_object_storage/metabase/small.go b/pkg/local_object_storage/metabase/small.go index 48d921d9..72986f91 100644 --- a/pkg/local_object_storage/metabase/small.go +++ b/pkg/local_object_storage/metabase/small.go @@ -3,13 +3,13 @@ package meta import ( "github.com/nspcc-dev/neo-go/pkg/util/slice" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.etcd.io/bbolt" ) // IsSmallPrm groups the parameters of IsSmall operation. type IsSmallPrm struct { - addr *addressSDK.Address + addr oid.Address } // IsSmallRes groups the resulting values of IsSmall operation. @@ -18,7 +18,7 @@ type IsSmallRes struct { } // WithAddress is a IsSmall option to set the object address to check. -func (p *IsSmallPrm) WithAddress(addr *addressSDK.Address) *IsSmallPrm { +func (p *IsSmallPrm) WithAddress(addr oid.Address) *IsSmallPrm { if p != nil { p.addr = addr } @@ -34,7 +34,7 @@ func (r *IsSmallRes) BlobovniczaID() *blobovnicza.ID { // IsSmall wraps work with DB.IsSmall method with specified // address and other parameters by default. Returns only // the blobovnicza identifier. -func IsSmall(db *DB, addr *addressSDK.Address) (*blobovnicza.ID, error) { +func IsSmall(db *DB, addr oid.Address) (*blobovnicza.ID, error) { r, err := db.IsSmall(new(IsSmallPrm).WithAddress(addr)) if err != nil { return nil, err @@ -59,17 +59,13 @@ func (db *DB) IsSmall(prm *IsSmallPrm) (res *IsSmallRes, err error) { return } -func (db *DB) isSmall(tx *bbolt.Tx, addr *addressSDK.Address) (*blobovnicza.ID, error) { - cnr, _ := addr.ContainerID() - - smallBucket := tx.Bucket(smallBucketName(&cnr)) +func (db *DB) isSmall(tx *bbolt.Tx, addr oid.Address) (*blobovnicza.ID, error) { + smallBucket := tx.Bucket(smallBucketName(addr.Container())) if smallBucket == nil { return nil, nil } - id, _ := addr.ObjectID() - - blobovniczaID := smallBucket.Get(objectKey(&id)) + blobovniczaID := smallBucket.Get(objectKey(addr.Object())) if len(blobovniczaID) == 0 { return nil, nil } diff --git a/pkg/local_object_storage/metabase/util.go b/pkg/local_object_storage/metabase/util.go index 8f707eb0..db71bbc1 100644 --- a/pkg/local_object_storage/metabase/util.go +++ b/pkg/local_object_storage/metabase/util.go @@ -2,12 +2,12 @@ package meta import ( "bytes" + "fmt" "strings" 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" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.etcd.io/bbolt" ) @@ -49,29 +49,29 @@ var ( ) // primaryBucketName returns . -func primaryBucketName(cid *cid.ID) []byte { - return []byte(cid.String()) +func primaryBucketName(cnr cid.ID) []byte { + return []byte(cnr.EncodeToString()) } // tombstoneBucketName returns _TS. -func tombstoneBucketName(cid *cid.ID) []byte { - return []byte(cid.String() + tombstonePostfix) +func tombstoneBucketName(cnr cid.ID) []byte { + return []byte(cnr.EncodeToString() + tombstonePostfix) } // storageGroupBucketName returns _SG. -func storageGroupBucketName(cid *cid.ID) []byte { - return []byte(cid.String() + storageGroupPostfix) +func storageGroupBucketName(cnr cid.ID) []byte { + return []byte(cnr.EncodeToString() + storageGroupPostfix) } // smallBucketName returns _small. -func smallBucketName(cid *cid.ID) []byte { - return []byte(cid.String() + smallPostfix) // consider caching output values +func smallBucketName(cnr cid.ID) []byte { + return []byte(cnr.EncodeToString() + smallPostfix) // consider caching output values } // attributeBucketName returns _attr_. -func attributeBucketName(cid *cid.ID, attributeKey string) []byte { +func attributeBucketName(cnr cid.ID, attributeKey string) []byte { sb := strings.Builder{} // consider getting string builders from sync.Pool - sb.WriteString(cid.String()) + sb.WriteString(cnr.EncodeToString()) sb.WriteString(userAttributePostfix) sb.WriteString(attributeKey) @@ -89,44 +89,48 @@ func cidFromAttributeBucket(val []byte, attributeKey string) []byte { } // payloadHashBucketName returns _payloadhash. -func payloadHashBucketName(cid *cid.ID) []byte { - return []byte(cid.String() + payloadHashPostfix) +func payloadHashBucketName(cnr cid.ID) []byte { + return []byte(cnr.EncodeToString() + payloadHashPostfix) } // rootBucketName returns _root. -func rootBucketName(cid *cid.ID) []byte { - return []byte(cid.String() + rootPostfix) +func rootBucketName(cnr cid.ID) []byte { + return []byte(cnr.EncodeToString() + rootPostfix) } // ownerBucketName returns _ownerid. -func ownerBucketName(cid *cid.ID) []byte { - return []byte(cid.String() + ownerPostfix) +func ownerBucketName(cnr cid.ID) []byte { + return []byte(cnr.EncodeToString() + ownerPostfix) } // parentBucketName returns _parent. -func parentBucketName(cid *cid.ID) []byte { - return []byte(cid.String() + parentPostfix) +func parentBucketName(cnr cid.ID) []byte { + return []byte(cnr.EncodeToString() + parentPostfix) } // splitBucketName returns _splitid. -func splitBucketName(cid *cid.ID) []byte { - return []byte(cid.String() + splitPostfix) +func splitBucketName(cnr cid.ID) []byte { + return []byte(cnr.EncodeToString() + splitPostfix) } // addressKey returns key for K-V tables when key is a whole address. -func addressKey(addr *addressSDK.Address) []byte { - return []byte(addr.String()) +func addressKey(addr oid.Address) []byte { + return []byte(addr.EncodeToString()) } // parses object address formed by addressKey. -func addressFromKey(k []byte) (*addressSDK.Address, error) { - a := addressSDK.NewAddress() - return a, a.Parse(string(k)) +func decodeAddressFromKey(dst *oid.Address, k []byte) error { + err := dst.DecodeString(string(k)) + if err != nil { + return fmt.Errorf("decode object address from db key: %w", err) + } + + return nil } // objectKey returns key for K-V tables when key is an object id. -func objectKey(oid *oidSDK.ID) []byte { - return []byte(oid.String()) +func objectKey(obj oid.ID) []byte { + return []byte(obj.EncodeToString()) } // removes all bucket elements. @@ -152,8 +156,8 @@ func firstIrregularObjectType(tx *bbolt.Tx, idCnr cid.ID, objs ...[]byte) object typ object.Type name []byte }{ - {object.TypeTombstone, tombstoneBucketName(&idCnr)}, - {object.TypeStorageGroup, storageGroupBucketName(&idCnr)}, + {object.TypeTombstone, tombstoneBucketName(idCnr)}, + {object.TypeStorageGroup, storageGroupBucketName(idCnr)}, {object.TypeLock, bucketNameLockers(idCnr)}, } diff --git a/pkg/local_object_storage/shard/container.go b/pkg/local_object_storage/shard/container.go index bcdba9c8..d1bec812 100644 --- a/pkg/local_object_storage/shard/container.go +++ b/pkg/local_object_storage/shard/container.go @@ -7,16 +7,16 @@ import ( ) type ContainerSizePrm struct { - cid *cid.ID + cnr cid.ID } type ContainerSizeRes struct { size uint64 } -func (p *ContainerSizePrm) WithContainerID(cid *cid.ID) *ContainerSizePrm { +func (p *ContainerSizePrm) WithContainerID(cnr cid.ID) *ContainerSizePrm { if p != nil { - p.cid = cid + p.cnr = cnr } return p @@ -27,7 +27,7 @@ func (r *ContainerSizeRes) Size() uint64 { } func (s *Shard) ContainerSize(prm *ContainerSizePrm) (*ContainerSizeRes, error) { - size, err := s.metaBase.ContainerSize(prm.cid) + size, err := s.metaBase.ContainerSize(prm.cnr) if err != nil { return nil, fmt.Errorf("could not get container size: %w", err) } @@ -37,8 +37,8 @@ func (s *Shard) ContainerSize(prm *ContainerSizePrm) (*ContainerSizeRes, error) }, nil } -func ContainerSize(s *Shard, cid *cid.ID) (uint64, error) { - res, err := s.ContainerSize(&ContainerSizePrm{cid: cid}) +func ContainerSize(s *Shard, cnr cid.ID) (uint64, error) { + res, err := s.ContainerSize(&ContainerSizePrm{cnr: cnr}) if err != nil { return 0, err } diff --git a/pkg/local_object_storage/shard/control.go b/pkg/local_object_storage/shard/control.go index 37dc660a..29fe80b0 100644 --- a/pkg/local_object_storage/shard/control.go +++ b/pkg/local_object_storage/shard/control.go @@ -8,7 +8,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor" 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" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) // Open opens all Shard's components. @@ -89,14 +89,12 @@ func (s *Shard) refillMetabase() error { } tombAddr := object.AddressOf(obj) - cnr, _ := tombAddr.ContainerID() memberIDs := tombstone.Members() - tombMembers := make([]*addressSDK.Address, 0, len(memberIDs)) + tombMembers := make([]oid.Address, 0, len(memberIDs)) for i := range memberIDs { - a := addressSDK.NewAddress() - a.SetContainerID(cnr) - a.SetObjectID(memberIDs[i]) + a := tombAddr + a.SetObject(memberIDs[i]) tombMembers = append(tombMembers, a) } diff --git a/pkg/local_object_storage/shard/control_test.go b/pkg/local_object_storage/shard/control_test.go index b1400162..5dea9b79 100644 --- a/pkg/local_object_storage/shard/control_test.go +++ b/pkg/local_object_storage/shard/control_test.go @@ -10,7 +10,7 @@ import ( meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" objecttest "github.com/nspcc-dev/neofs-sdk-go/object/test" "github.com/stretchr/testify/require" ) @@ -43,7 +43,7 @@ func TestRefillMetabase(t *testing.T) { type objAddr struct { obj *objectSDK.Object - addr *addressSDK.Address + addr oid.Address } mObjs := make(map[string]objAddr) @@ -54,7 +54,7 @@ func TestRefillMetabase(t *testing.T) { addr := object.AddressOf(obj) - mObjs[addr.String()] = objAddr{ + mObjs[addr.EncodeToString()] = objAddr{ obj: obj, addr: addr, } @@ -70,14 +70,14 @@ func TestRefillMetabase(t *testing.T) { tombObj.SetPayload(tombData) - tombMembers := make([]*addressSDK.Address, 0, len(tombstone.Members())) + tombMembers := make([]oid.Address, 0, len(tombstone.Members())) members := tombstone.Members() for i := range tombstone.Members() { - a := addressSDK.NewAddress() - a.SetObjectID(members[i]) + var a oid.Address + a.SetObject(members[i]) cnr, _ := tombObj.ContainerID() - a.SetContainerID(cnr) + a.SetContainer(cnr) tombMembers = append(tombMembers, a) } @@ -97,7 +97,7 @@ func TestRefillMetabase(t *testing.T) { var headPrm HeadPrm - checkObj := func(addr *addressSDK.Address, expObj *objectSDK.Object) { + checkObj := func(addr oid.Address, expObj *objectSDK.Object) { res, err := sh.Head(headPrm.WithAddress(addr)) if expObj == nil { diff --git a/pkg/local_object_storage/shard/delete.go b/pkg/local_object_storage/shard/delete.go index b75b459c..04bcfe56 100644 --- a/pkg/local_object_storage/shard/delete.go +++ b/pkg/local_object_storage/shard/delete.go @@ -5,13 +5,13 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/writecache" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.uber.org/zap" ) // DeletePrm groups the parameters of Delete operation. type DeletePrm struct { - addr []*addressSDK.Address + addr []oid.Address } // DeleteRes groups the resulting values of Delete operation. @@ -20,7 +20,7 @@ type DeleteRes struct{} // WithAddresses is a Delete option to set the addresses of the objects to delete. // // Option is required. -func (p *DeletePrm) WithAddresses(addr ...*addressSDK.Address) *DeletePrm { +func (p *DeletePrm) WithAddresses(addr ...oid.Address) *DeletePrm { if p != nil { p.addr = append(p.addr, addr...) } @@ -39,7 +39,7 @@ func (s *Shard) Delete(prm *DeletePrm) (*DeleteRes, error) { delSmallPrm := new(blobstor.DeleteSmallPrm) delBigPrm := new(blobstor.DeleteBigPrm) - smalls := make(map[*addressSDK.Address]*blobovnicza.ID, ln) + smalls := make(map[oid.Address]*blobovnicza.ID, ln) for i := range prm.addr { if s.hasWriteCache() { diff --git a/pkg/local_object_storage/shard/dump_test.go b/pkg/local_object_storage/shard/dump_test.go index 8cc5c1bf..61ee943e 100644 --- a/pkg/local_object_storage/shard/dump_test.go +++ b/pkg/local_object_storage/shard/dump_test.go @@ -17,7 +17,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/writecache" 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" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" objecttest "github.com/nspcc-dev/neofs-sdk-go/object/id/test" "github.com/stretchr/testify/require" ) @@ -73,7 +73,7 @@ func testDump(t *testing.T, objCount int, hasWriteCache bool) { objects := make([]*objectSDK.Object, objCount) for i := 0; i < objCount; i++ { - cid := cidtest.ID() + cnr := cidtest.ID() var size int switch i % 6 { case 0, 1: @@ -87,7 +87,7 @@ func testDump(t *testing.T, objCount int, hasWriteCache bool) { } data := make([]byte, size) rand.Read(data) - obj := generateObjectWithPayload(cid, data) + obj := generateObjectWithPayload(cnr, data) objects[i] = obj prm := new(shard.PutPrm).WithObject(objects[i]) @@ -193,8 +193,8 @@ func TestStream(t *testing.T) { const objCount = 5 objects := make([]*objectSDK.Object, objCount) for i := 0; i < objCount; i++ { - cid := cidtest.ID() - obj := generateObjectWithCID(t, cid) + cnr := cidtest.ID() + obj := generateObjectWithCID(t, cnr) objects[i] = obj prm := new(shard.PutPrm).WithObject(objects[i]) @@ -301,7 +301,7 @@ func TestDumpIgnoreErrors(t *testing.T) { require.NoError(t, os.WriteFile(filepath.Join(dirName, addr[2:]), corruptedData, os.ModePerm)) // 1.2. Unreadable file. - addr = cidtest.ID().String() + "." + objecttest.ID().String() + addr = cidtest.ID().EncodeToString() + "." + objecttest.ID().EncodeToString() dirName = filepath.Join(bsPath, addr[:2]) require.NoError(t, os.MkdirAll(dirName, os.ModePerm)) @@ -326,7 +326,7 @@ func TestDumpIgnoreErrors(t *testing.T) { // 2.2. Invalid object in valid blobovnicza. prm := new(blobovnicza.PutPrm) - prm.SetAddress(addressSDK.NewAddress()) + prm.SetAddress(oid.Address{}) prm.SetMarshaledObject(corruptedData) b := blobovnicza.New(blobovnicza.WithPath(filepath.Join(bTree, "1", "2"))) require.NoError(t, b.Open()) @@ -338,7 +338,7 @@ func TestDumpIgnoreErrors(t *testing.T) { { // 3. Invalid object in write-cache. Note that because shard is read-only // the object won't be flushed. - addr := cidtest.ID().String() + "." + objecttest.ID().String() + addr := cidtest.ID().EncodeToString() + "." + objecttest.ID().EncodeToString() dir := filepath.Join(wcPath, addr[:1]) require.NoError(t, os.MkdirAll(dir, os.ModePerm)) require.NoError(t, os.WriteFile(filepath.Join(dir, addr[1:]), nil, 0)) diff --git a/pkg/local_object_storage/shard/exists.go b/pkg/local_object_storage/shard/exists.go index 94123856..c2d7fd38 100644 --- a/pkg/local_object_storage/shard/exists.go +++ b/pkg/local_object_storage/shard/exists.go @@ -3,13 +3,13 @@ package shard import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.uber.org/zap" ) // ExistsPrm groups the parameters of Exists operation. type ExistsPrm struct { - addr *addressSDK.Address + addr oid.Address } // ExistsRes groups the resulting values of Exists operation. @@ -18,7 +18,7 @@ type ExistsRes struct { } // WithAddress is an Exists option to set object checked for existence. -func (p *ExistsPrm) WithAddress(addr *addressSDK.Address) *ExistsPrm { +func (p *ExistsPrm) WithAddress(addr oid.Address) *ExistsPrm { if p != nil { p.addr = addr } diff --git a/pkg/local_object_storage/shard/gc.go b/pkg/local_object_storage/shard/gc.go index c3d05c8a..9d8f79a2 100644 --- a/pkg/local_object_storage/shard/gc.go +++ b/pkg/local_object_storage/shard/gc.go @@ -9,7 +9,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/util" "github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/nspcc-dev/neofs-sdk-go/object" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.uber.org/zap" ) @@ -19,7 +19,7 @@ type TombstoneSource interface { // IsTombstoneAvailable must return boolean value that means // provided tombstone's presence in the NeoFS network at the // time of the passed epoch. - IsTombstoneAvailable(ctx context.Context, addr *addressSDK.Address, epoch uint64) bool + IsTombstoneAvailable(ctx context.Context, addr oid.Address, epoch uint64) bool } // Event represents class of external events. @@ -183,7 +183,7 @@ func (s *Shard) removeGarbage() { return } - buf := make([]*addressSDK.Address, 0, s.rmBatchSize) + buf := make([]oid.Address, 0, s.rmBatchSize) iterPrm := new(meta.GarbageIterationPrm) @@ -311,8 +311,8 @@ func (s *Shard) collectExpiredLocks(ctx context.Context, e Event) { s.expiredLocksCallback(ctx, expired) } -func (s *Shard) getExpiredObjects(ctx context.Context, epoch uint64, typeCond func(object.Type) bool) ([]*addressSDK.Address, error) { - var expired []*addressSDK.Address +func (s *Shard) getExpiredObjects(ctx context.Context, epoch uint64, typeCond func(object.Type) bool) ([]oid.Address, error) { + var expired []oid.Address err := s.metaBase.IterateExpired(epoch, func(expiredObject *meta.ExpiredObject) error { select { @@ -339,7 +339,7 @@ func (s *Shard) HandleExpiredTombstones(tss []meta.TombstonedObject) { // Mark tombstones as garbage. var pInhume meta.InhumePrm - tsAddrs := make([]*addressSDK.Address, 0, len(tss)) + tsAddrs := make([]oid.Address, 0, len(tss)) for _, ts := range tss { tsAddrs = append(tsAddrs, ts.Tombstone()) } @@ -367,7 +367,7 @@ func (s *Shard) HandleExpiredTombstones(tss []meta.TombstonedObject) { // HandleExpiredLocks unlocks all objects which were locked by lockers. // If successful, marks lockers themselves as garbage. -func (s *Shard) HandleExpiredLocks(lockers []*addressSDK.Address) { +func (s *Shard) HandleExpiredLocks(lockers []oid.Address) { err := s.metaBase.FreeLockedBy(lockers) if err != nil { s.log.Warn("failure to unlock objects", diff --git a/pkg/local_object_storage/shard/get.go b/pkg/local_object_storage/shard/get.go index f8910e8b..a0465743 100644 --- a/pkg/local_object_storage/shard/get.go +++ b/pkg/local_object_storage/shard/get.go @@ -11,7 +11,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/writecache" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.uber.org/zap" ) @@ -21,7 +21,7 @@ type storFetcher = func(stor *blobstor.BlobStor, id *blobovnicza.ID) (*objectSDK // GetPrm groups the parameters of Get operation. type GetPrm struct { - addr *addressSDK.Address + addr oid.Address skipMeta bool } @@ -34,7 +34,7 @@ type GetRes struct { // WithAddress is a Get option to set the address of the requested object. // // Option is required. -func (p *GetPrm) WithAddress(addr *addressSDK.Address) *GetPrm { +func (p *GetPrm) WithAddress(addr oid.Address) *GetPrm { if p != nil { p.addr = addr } @@ -103,7 +103,7 @@ func (s *Shard) Get(prm *GetPrm) (*GetRes, error) { } // fetchObjectData looks through writeCache and blobStor to find object. -func (s *Shard) fetchObjectData(addr *addressSDK.Address, skipMeta bool, big, small storFetcher) (*objectSDK.Object, bool, error) { +func (s *Shard) fetchObjectData(addr oid.Address, skipMeta bool, big, small storFetcher) (*objectSDK.Object, bool, error) { var ( err error res *objectSDK.Object diff --git a/pkg/local_object_storage/shard/head.go b/pkg/local_object_storage/shard/head.go index 4a86a265..8d5f7b80 100644 --- a/pkg/local_object_storage/shard/head.go +++ b/pkg/local_object_storage/shard/head.go @@ -6,12 +6,12 @@ import ( meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/writecache" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) // HeadPrm groups the parameters of Head operation. type HeadPrm struct { - addr *addressSDK.Address + addr oid.Address raw bool } @@ -23,7 +23,7 @@ type HeadRes struct { // WithAddress is a Head option to set the address of the requested object. // // Option is required. -func (p *HeadPrm) WithAddress(addr *addressSDK.Address) *HeadPrm { +func (p *HeadPrm) WithAddress(addr oid.Address) *HeadPrm { if p != nil { p.addr = addr } diff --git a/pkg/local_object_storage/shard/head_test.go b/pkg/local_object_storage/shard/head_test.go index 4edbb96b..7a4b74a6 100644 --- a/pkg/local_object_storage/shard/head_test.go +++ b/pkg/local_object_storage/shard/head_test.go @@ -46,13 +46,13 @@ func testShardHead(t *testing.T, hasWriteCache bool) { }) t.Run("virtual object", func(t *testing.T) { - cid := cidtest.ID() + cnr := cidtest.ID() splitID := objectSDK.NewSplitID() - parent := generateObjectWithCID(t, cid) + parent := generateObjectWithCID(t, cnr) addAttribute(parent, "foo", "bar") - child := generateObjectWithCID(t, cid) + child := generateObjectWithCID(t, cnr) child.SetParent(parent) idParent, _ := parent.ID() child.SetParentID(idParent) diff --git a/pkg/local_object_storage/shard/inhume.go b/pkg/local_object_storage/shard/inhume.go index 683a77f9..3de993c0 100644 --- a/pkg/local_object_storage/shard/inhume.go +++ b/pkg/local_object_storage/shard/inhume.go @@ -4,14 +4,14 @@ import ( "fmt" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.uber.org/zap" ) // InhumePrm encapsulates parameters for inhume operation. type InhumePrm struct { - target []*addressSDK.Address - tombstone *addressSDK.Address + target []oid.Address + tombstone *oid.Address } // InhumeRes encapsulates results of inhume operation. @@ -22,10 +22,10 @@ type InhumeRes struct{} // // tombstone should not be nil, addr should not be empty. // Should not be called along with MarkAsGarbage. -func (p *InhumePrm) WithTarget(tombstone *addressSDK.Address, addrs ...*addressSDK.Address) *InhumePrm { +func (p *InhumePrm) WithTarget(tombstone oid.Address, addrs ...oid.Address) *InhumePrm { if p != nil { p.target = addrs - p.tombstone = tombstone + p.tombstone = &tombstone } return p @@ -34,7 +34,7 @@ func (p *InhumePrm) WithTarget(tombstone *addressSDK.Address, addrs ...*addressS // MarkAsGarbage marks object to be physically removed from shard. // // Should not be called along with WithTarget. -func (p *InhumePrm) MarkAsGarbage(addr ...*addressSDK.Address) *InhumePrm { +func (p *InhumePrm) MarkAsGarbage(addr ...oid.Address) *InhumePrm { if p != nil { p.target = addr p.tombstone = nil @@ -64,7 +64,7 @@ func (s *Shard) Inhume(prm *InhumePrm) (*InhumeRes, error) { metaPrm := new(meta.InhumePrm).WithAddresses(prm.target...) if prm.tombstone != nil { - metaPrm.WithTombstoneAddress(prm.tombstone) + metaPrm.WithTombstoneAddress(*prm.tombstone) } else { metaPrm.WithGCMark() } diff --git a/pkg/local_object_storage/shard/inhume_test.go b/pkg/local_object_storage/shard/inhume_test.go index 63f08323..ea7621e1 100644 --- a/pkg/local_object_storage/shard/inhume_test.go +++ b/pkg/local_object_storage/shard/inhume_test.go @@ -24,12 +24,12 @@ func testShardInhume(t *testing.T, hasWriteCache bool) { sh := newShard(t, hasWriteCache) defer releaseShard(sh, t) - cid := cidtest.ID() + cnr := cidtest.ID() - obj := generateObjectWithCID(t, cid) + obj := generateObjectWithCID(t, cnr) addAttribute(obj, "foo", "bar") - ts := generateObjectWithCID(t, cid) + ts := generateObjectWithCID(t, cnr) putPrm := new(shard.PutPrm) putPrm.WithObject(obj) diff --git a/pkg/local_object_storage/shard/list.go b/pkg/local_object_storage/shard/list.go index e7d7bcf1..d4c3628e 100644 --- a/pkg/local_object_storage/shard/list.go +++ b/pkg/local_object_storage/shard/list.go @@ -6,7 +6,7 @@ import ( meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" 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" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.uber.org/zap" ) @@ -21,10 +21,10 @@ var ErrEndOfListing = meta.ErrEndOfListing type ListContainersPrm struct{} type ListContainersRes struct { - containers []*cid.ID + containers []cid.ID } -func (r *ListContainersRes) Containers() []*cid.ID { +func (r *ListContainersRes) Containers() []cid.ID { return r.containers } @@ -36,7 +36,7 @@ type ListWithCursorPrm struct { // ListWithCursorRes contains values returned from ListWithCursor operation. type ListWithCursorRes struct { - addrList []*addressSDK.Address + addrList []oid.Address cursor *Cursor } @@ -55,7 +55,7 @@ func (p *ListWithCursorPrm) WithCursor(cursor *Cursor) *ListWithCursorPrm { } // AddressList returns addresses selected by ListWithCursor operation. -func (r ListWithCursorRes) AddressList() []*addressSDK.Address { +func (r ListWithCursorRes) AddressList() []oid.Address { return r.addrList } @@ -102,7 +102,7 @@ func (s *Shard) ListContainers(_ *ListContainersPrm) (*ListContainersRes, error) }, nil } -func ListContainers(s *Shard) ([]*cid.ID, error) { +func ListContainers(s *Shard) ([]cid.ID, error) { res, err := s.ListContainers(&ListContainersPrm{}) if err != nil { return nil, err @@ -136,7 +136,7 @@ func (s *Shard) ListWithCursor(prm *ListWithCursorPrm) (*ListWithCursorRes, erro // // Returns ErrEndOfListing if there are no more objects to return or count // parameter set to zero. -func ListWithCursor(s *Shard, count uint32, cursor *Cursor) ([]*addressSDK.Address, *Cursor, error) { +func ListWithCursor(s *Shard, count uint32, cursor *Cursor) ([]oid.Address, *Cursor, error) { prm := new(ListWithCursorPrm).WithCount(count).WithCursor(cursor) res, err := s.ListWithCursor(prm) if err != nil { diff --git a/pkg/local_object_storage/shard/list_test.go b/pkg/local_object_storage/shard/list_test.go index 540ffd19..20a74eee 100644 --- a/pkg/local_object_storage/shard/list_test.go +++ b/pkg/local_object_storage/shard/list_test.go @@ -35,19 +35,19 @@ func testShardList(t *testing.T, sh *shard.Shard) { putPrm := new(shard.PutPrm) for i := 0; i < C; i++ { - cid := cidtest.ID() + cnr := cidtest.ID() for j := 0; j < N; j++ { - obj := generateObjectWithCID(t, cid) + obj := generateObjectWithCID(t, cnr) addPayload(obj, 1<<2) // add parent as virtual object, it must be ignored in List() - parent := generateObjectWithCID(t, cid) + parent := generateObjectWithCID(t, cnr) idParent, _ := parent.ID() obj.SetParentID(idParent) obj.SetParent(parent) - objs[object.AddressOf(obj).String()] = 0 + objs[object.AddressOf(obj).EncodeToString()] = 0 putPrm.WithObject(obj) @@ -60,10 +60,10 @@ func testShardList(t *testing.T, sh *shard.Shard) { require.NoError(t, err) for _, objID := range res.AddressList() { - i, ok := objs[objID.String()] + i, ok := objs[objID.EncodeToString()] require.True(t, ok) require.Equal(t, 0, i) - objs[objID.String()] = 1 + objs[objID.EncodeToString()] = 1 } } diff --git a/pkg/local_object_storage/shard/move.go b/pkg/local_object_storage/shard/move.go index 826adbbf..225176eb 100644 --- a/pkg/local_object_storage/shard/move.go +++ b/pkg/local_object_storage/shard/move.go @@ -2,13 +2,13 @@ package shard import ( meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.uber.org/zap" ) // ToMoveItPrm encapsulates parameters for ToMoveIt operation. type ToMoveItPrm struct { - addr *addressSDK.Address + addr oid.Address } // ToMoveItRes encapsulates results of ToMoveIt operation. @@ -16,7 +16,7 @@ type ToMoveItRes struct{} // WithAddress sets object address that should be marked to move into another // shard. -func (p *ToMoveItPrm) WithAddress(addr *addressSDK.Address) *ToMoveItPrm { +func (p *ToMoveItPrm) WithAddress(addr oid.Address) *ToMoveItPrm { if p != nil { p.addr = addr } diff --git a/pkg/local_object_storage/shard/range.go b/pkg/local_object_storage/shard/range.go index 2aca6b4e..b10e039d 100644 --- a/pkg/local_object_storage/shard/range.go +++ b/pkg/local_object_storage/shard/range.go @@ -4,7 +4,7 @@ import ( "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-sdk-go/object" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) // RngPrm groups the parameters of GetRange operation. @@ -13,7 +13,7 @@ type RngPrm struct { off uint64 - addr *addressSDK.Address + addr oid.Address skipMeta bool } @@ -27,7 +27,7 @@ type RngRes struct { // WithAddress is a Rng option to set the address of the requested object. // // Option is required. -func (p *RngPrm) WithAddress(addr *addressSDK.Address) *RngPrm { +func (p *RngPrm) WithAddress(addr oid.Address) *RngPrm { if p != nil { p.addr = addr } diff --git a/pkg/local_object_storage/shard/select.go b/pkg/local_object_storage/shard/select.go index 662829d5..85ffe31d 100644 --- a/pkg/local_object_storage/shard/select.go +++ b/pkg/local_object_storage/shard/select.go @@ -6,24 +6,24 @@ import ( meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" 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" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) // SelectPrm groups the parameters of Select operation. type SelectPrm struct { - cid *cid.ID + cnr cid.ID filters object.SearchFilters } // SelectRes groups the resulting values of Select operation. type SelectRes struct { - addrList []*addressSDK.Address + addrList []oid.Address } // WithContainerID is a Select option to set the container id to search in. -func (p *SelectPrm) WithContainerID(cid *cid.ID) *SelectPrm { +func (p *SelectPrm) WithContainerID(cnr cid.ID) *SelectPrm { if p != nil { - p.cid = cid + p.cnr = cnr } return p @@ -39,7 +39,7 @@ func (p *SelectPrm) WithFilters(fs object.SearchFilters) *SelectPrm { } // AddressList returns list of addresses of the selected objects. -func (r *SelectRes) AddressList() []*addressSDK.Address { +func (r *SelectRes) AddressList() []oid.Address { return r.addrList } @@ -48,7 +48,7 @@ func (r *SelectRes) AddressList() []*addressSDK.Address { // Returns any error encountered that // did not allow to completely select the objects. func (s *Shard) Select(prm *SelectPrm) (*SelectRes, error) { - addrList, err := meta.Select(s.metaBase, prm.cid, prm.filters) + addrList, err := meta.Select(s.metaBase, prm.cnr, prm.filters) if err != nil { return nil, fmt.Errorf("could not select objects from metabase: %w", err) } diff --git a/pkg/local_object_storage/shard/shard.go b/pkg/local_object_storage/shard/shard.go index 60ab31c8..e2bdf7f0 100644 --- a/pkg/local_object_storage/shard/shard.go +++ b/pkg/local_object_storage/shard/shard.go @@ -10,7 +10,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/writecache" "github.com/nspcc-dev/neofs-node/pkg/util" "github.com/nspcc-dev/neofs-node/pkg/util/logger" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.uber.org/zap" ) @@ -36,7 +36,7 @@ type Option func(*cfg) type ExpiredTombstonesCallback func(context.Context, []meta.TombstonedObject) // ExpiredObjectsCallback is a callback handling list of expired objects. -type ExpiredObjectsCallback func(context.Context, []*addressSDK.Address) +type ExpiredObjectsCallback func(context.Context, []oid.Address) type cfg struct { m sync.RWMutex diff --git a/pkg/local_object_storage/util/splitinfo_test.go b/pkg/local_object_storage/util/splitinfo_test.go index 63382e26..5b3b0b6e 100644 --- a/pkg/local_object_storage/util/splitinfo_test.go +++ b/pkg/local_object_storage/util/splitinfo_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/uuid" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util" "github.com/nspcc-dev/neofs-sdk-go/object" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/stretchr/testify/require" ) @@ -19,8 +19,8 @@ func TestMergeSplitInfo(t *testing.T) { splitID.SetUUID(uid) var rawLinkID, rawLastID [32]byte - var linkID oidSDK.ID - var lastID oidSDK.ID + var linkID oid.ID + var lastID oid.ID _, err = rand.Read(rawLinkID[:]) require.NoError(t, err) diff --git a/pkg/local_object_storage/writecache/delete.go b/pkg/local_object_storage/writecache/delete.go index 3a90f1b5..4302e16e 100644 --- a/pkg/local_object_storage/writecache/delete.go +++ b/pkg/local_object_storage/writecache/delete.go @@ -6,21 +6,21 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree" storagelog "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/internal/log" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.etcd.io/bbolt" ) // Delete removes object from write-cache. // // Returns an error of type apistatus.ObjectNotFound if object is missing in write-cache. -func (c *cache) Delete(addr *addressSDK.Address) error { +func (c *cache) Delete(addr oid.Address) error { c.modeMtx.RLock() defer c.modeMtx.RUnlock() if c.readOnly() { return ErrReadOnly } - saddr := addr.String() + saddr := addr.EncodeToString() // Check memory cache. c.mtx.Lock() diff --git a/pkg/local_object_storage/writecache/flush.go b/pkg/local_object_storage/writecache/flush.go index c66a13bd..cc94634d 100644 --- a/pkg/local_object_storage/writecache/flush.go +++ b/pkg/local_object_storage/writecache/flush.go @@ -10,7 +10,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree" 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" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.etcd.io/bbolt" "go.uber.org/zap" ) @@ -133,8 +133,8 @@ func (c *cache) flushBigObjects() { } evictNum := 0 - _ = c.fsTree.Iterate(new(fstree.IterationPrm).WithHandler(func(addr *addressSDK.Address, data []byte) error { - sAddr := addr.String() + _ = c.fsTree.Iterate(new(fstree.IterationPrm).WithHandler(func(addr oid.Address, data []byte) error { + sAddr := addr.EncodeToString() if _, ok := c.store.flushed.Peek(sAddr); ok { return nil diff --git a/pkg/local_object_storage/writecache/get.go b/pkg/local_object_storage/writecache/get.go index 838eee70..a815ba3e 100644 --- a/pkg/local_object_storage/writecache/get.go +++ b/pkg/local_object_storage/writecache/get.go @@ -3,15 +3,15 @@ package writecache import ( apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.etcd.io/bbolt" ) // Get returns object from write-cache. // // Returns an error of type apistatus.ObjectNotFound if the requested object is missing in write-cache. -func (c *cache) Get(addr *addressSDK.Address) (*objectSDK.Object, error) { - saddr := addr.String() +func (c *cache) Get(addr oid.Address) (*objectSDK.Object, error) { + saddr := addr.EncodeToString() c.mtx.RLock() for i := range c.mem { @@ -53,7 +53,7 @@ func (c *cache) Get(addr *addressSDK.Address) (*objectSDK.Object, error) { // Head returns object header from write-cache. // // Returns an error of type apistatus.ObjectNotFound if the requested object is missing in write-cache. -func (c *cache) Head(addr *addressSDK.Address) (*objectSDK.Object, error) { +func (c *cache) Head(addr oid.Address) (*objectSDK.Object, error) { obj, err := c.Get(addr) if err != nil { return nil, err diff --git a/pkg/local_object_storage/writecache/iterate.go b/pkg/local_object_storage/writecache/iterate.go index 3c4af31b..a1e59837 100644 --- a/pkg/local_object_storage/writecache/iterate.go +++ b/pkg/local_object_storage/writecache/iterate.go @@ -5,7 +5,7 @@ import ( "fmt" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.etcd.io/bbolt" ) @@ -53,8 +53,8 @@ func (c *cache) Iterate(prm *IterationPrm) error { return err } - return c.fsTree.Iterate(new(fstree.IterationPrm).WithHandler(func(addr *addressSDK.Address, data []byte) error { - if _, ok := c.flushed.Peek(addr.String()); ok { + return c.fsTree.Iterate(new(fstree.IterationPrm).WithHandler(func(addr oid.Address, data []byte) error { + if _, ok := c.flushed.Peek(addr.EncodeToString()); ok { return nil } return prm.handler(data) @@ -67,21 +67,17 @@ func (c *cache) Iterate(prm *IterationPrm) error { // Returns ErrNoDefaultBucket if there is no default bucket in db. // // DB must not be nil and should be opened. -func IterateDB(db *bbolt.DB, f func(*addressSDK.Address) error) error { +func IterateDB(db *bbolt.DB, f func(oid.Address) error) error { return db.View(func(tx *bbolt.Tx) error { b := tx.Bucket(defaultBucket) if b == nil { return ErrNoDefaultBucket } - var addr *addressSDK.Address + var addr oid.Address return b.ForEach(func(k, v []byte) error { - if addr == nil { - addr = addressSDK.NewAddress() - } - - err := addr.Parse(string(k)) + err := addr.DecodeString(string(k)) if err != nil { return fmt.Errorf("could not parse object address: %w", err) } diff --git a/pkg/local_object_storage/writecache/put.go b/pkg/local_object_storage/writecache/put.go index 1f4e6b51..b8900275 100644 --- a/pkg/local_object_storage/writecache/put.go +++ b/pkg/local_object_storage/writecache/put.go @@ -30,7 +30,7 @@ func (c *cache) Put(o *objectSDK.Object) error { } oi := objectInfo{ - addr: object.AddressOf(o).String(), + addr: object.AddressOf(o).EncodeToString(), obj: o, data: data, } diff --git a/pkg/local_object_storage/writecache/storage.go b/pkg/local_object_storage/writecache/storage.go index 6c855699..4f2458c7 100644 --- a/pkg/local_object_storage/writecache/storage.go +++ b/pkg/local_object_storage/writecache/storage.go @@ -11,7 +11,7 @@ import ( storagelog "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/internal/log" "github.com/nspcc-dev/neofs-node/pkg/util" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.etcd.io/bbolt" "go.uber.org/zap" ) @@ -126,11 +126,12 @@ func (c *cache) deleteFromDB(keys [][]byte) error { func (c *cache) deleteFromDisk(keys [][]byte) error { var lastErr error + var addr oid.Address + for i := range keys { - addr := addressSDK.NewAddress() addrStr := string(keys[i]) - if err := addr.Parse(addrStr); err != nil { + if err := addr.DecodeString(addrStr); err != nil { c.log.Error("can't parse address", zap.String("address", addrStr)) continue } diff --git a/pkg/local_object_storage/writecache/writecache.go b/pkg/local_object_storage/writecache/writecache.go index 80a9e9b4..e28b8bf9 100644 --- a/pkg/local_object_storage/writecache/writecache.go +++ b/pkg/local_object_storage/writecache/writecache.go @@ -5,7 +5,7 @@ import ( "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" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.uber.org/zap" ) @@ -17,9 +17,9 @@ type Info struct { // Cache represents write-cache for objects. type Cache interface { - Get(*addressSDK.Address) (*object.Object, error) - Head(*addressSDK.Address) (*object.Object, error) - Delete(*addressSDK.Address) error + Get(address oid.Address) (*object.Object, error) + Head(oid.Address) (*object.Object, error) + Delete(oid.Address) error Iterate(*IterationPrm) error Put(*object.Object) error SetMode(Mode) diff --git a/pkg/morph/client/audit/list_results.go b/pkg/morph/client/audit/list_results.go index aa315749..6f30cf15 100644 --- a/pkg/morph/client/audit/list_results.go +++ b/pkg/morph/client/audit/list_results.go @@ -37,7 +37,7 @@ func (c *Client) ListAuditResultIDByEpoch(epoch uint64) ([]ResultID, error) { // ListAuditResultIDByCID returns a list of audit result IDs inside audit // contract for specific epoch number and container ID. -func (c *Client) ListAuditResultIDByCID(epoch uint64, cnr *cid.ID) ([]ResultID, error) { +func (c *Client) ListAuditResultIDByCID(epoch uint64, cnr cid.ID) ([]ResultID, error) { binCnr := make([]byte, sha256.Size) cnr.Encode(binCnr) @@ -54,7 +54,7 @@ func (c *Client) ListAuditResultIDByCID(epoch uint64, cnr *cid.ID) ([]ResultID, // ListAuditResultIDByNode returns a list of audit result IDs inside audit // contract for specific epoch number, container ID and inner ring public key. -func (c *Client) ListAuditResultIDByNode(epoch uint64, cnr *cid.ID, nodeKey []byte) ([]ResultID, error) { +func (c *Client) ListAuditResultIDByNode(epoch uint64, cnr cid.ID, nodeKey []byte) ([]ResultID, error) { binCnr := make([]byte, sha256.Size) cnr.Encode(binCnr) diff --git a/pkg/morph/client/audit/result_test.go b/pkg/morph/client/audit/result_test.go index 77e5cd54..01f22a0e 100644 --- a/pkg/morph/client/audit/result_test.go +++ b/pkg/morph/client/audit/result_test.go @@ -46,7 +46,7 @@ func TestAuditResults(t *testing.T) { time.Sleep(5 * time.Second) - list, err := auditClientWrapper.ListAuditResultIDByCID(epoch, &id) + list, err := auditClientWrapper.ListAuditResultIDByCID(epoch, id) require.NoError(t, err) require.Len(t, list, 1) diff --git a/pkg/morph/client/balance/balanceOf.go b/pkg/morph/client/balance/balanceOf.go index 0b772046..7f2417a4 100644 --- a/pkg/morph/client/balance/balanceOf.go +++ b/pkg/morph/client/balance/balanceOf.go @@ -11,7 +11,7 @@ import ( // BalanceOf receives the amount of funds in the client's account // through the Balance contract call, and returns it. -func (c *Client) BalanceOf(id *user.ID) (*big.Int, error) { +func (c *Client) BalanceOf(id user.ID) (*big.Int, error) { h, err := address.StringToUint160(id.EncodeToString()) if err != nil { return nil, err diff --git a/pkg/morph/client/balance/transfer.go b/pkg/morph/client/balance/transfer.go index 024fd197..de81adc1 100644 --- a/pkg/morph/client/balance/transfer.go +++ b/pkg/morph/client/balance/transfer.go @@ -12,7 +12,7 @@ import ( type TransferPrm struct { Amount int64 - From, To *user.ID + From, To user.ID Details []byte diff --git a/pkg/morph/client/container/delete.go b/pkg/morph/client/container/delete.go index 157b5e7f..7cd90bce 100644 --- a/pkg/morph/client/container/delete.go +++ b/pkg/morph/client/container/delete.go @@ -13,13 +13,8 @@ import ( // // Returns error if container ID is nil. func Delete(c *Client, witness core.RemovalWitness) error { - id := witness.ContainerID() - if id == nil { - return errNilArgument - } - binCnr := make([]byte, sha256.Size) - id.Encode(binCnr) + witness.ContainerID().Encode(binCnr) var prm DeletePrm @@ -35,7 +30,7 @@ func Delete(c *Client, witness core.RemovalWitness) error { // DeletePrm groups parameters of Delete client operation. type DeletePrm struct { - cid []byte + cnr []byte signature []byte token []byte @@ -44,7 +39,7 @@ type DeletePrm struct { // SetCID sets container ID. func (d *DeletePrm) SetCID(cid []byte) { - d.cid = cid + d.cnr = cid } // SetSignature sets signature. @@ -71,7 +66,7 @@ func (c *Client) Delete(p DeletePrm) error { prm := client.InvokePrm{} prm.SetMethod(deleteMethod) - prm.SetArgs(p.cid, p.signature, p.token) + prm.SetArgs(p.cnr, p.signature, p.token) prm.InvokePrmOptional = p.InvokePrmOptional err := c.client.Invoke(prm) diff --git a/pkg/morph/client/container/eacl.go b/pkg/morph/client/container/eacl.go index 13247e8d..76cee0f4 100644 --- a/pkg/morph/client/container/eacl.go +++ b/pkg/morph/client/container/eacl.go @@ -15,11 +15,7 @@ import ( // GetEACL reads the extended ACL table from NeoFS system // through Container contract call. -func (c *Client) GetEACL(cnr *cid.ID) (*eacl.Table, error) { - if cnr == nil { - return nil, errNilArgument - } - +func (c *Client) GetEACL(cnr cid.ID) (*eacl.Table, error) { binCnr := make([]byte, sha256.Size) cnr.Encode(binCnr) diff --git a/pkg/morph/client/container/get.go b/pkg/morph/client/container/get.go index b6fbb82b..a299f7f1 100644 --- a/pkg/morph/client/container/get.go +++ b/pkg/morph/client/container/get.go @@ -18,8 +18,8 @@ import ( type containerSource Client -func (x *containerSource) Get(cid *cid.ID) (*container.Container, error) { - return Get((*Client)(x), cid) +func (x *containerSource) Get(cnr cid.ID) (*container.Container, error) { + return Get((*Client)(x), cnr) } // AsContainerSource provides container Source interface @@ -29,9 +29,7 @@ func AsContainerSource(w *Client) core.Source { } // Get marshals container ID, and passes it to Wrapper's Get method. -// -// Returns error if cid is nil. -func Get(c *Client, cnr *cid.ID) (*container.Container, error) { +func Get(c *Client, cnr cid.ID) (*container.Container, error) { binCnr := make([]byte, sha256.Size) cnr.Encode(binCnr) diff --git a/pkg/morph/client/container/list.go b/pkg/morph/client/container/list.go index 2f05f0f7..8fb37c26 100644 --- a/pkg/morph/client/container/list.go +++ b/pkg/morph/client/container/list.go @@ -14,7 +14,7 @@ import ( // // Returns the identifiers of all NeoFS containers if pointer // to user identifier is nil. -func (c *Client) List(idUser *user.ID) ([]*cid.ID, error) { +func (c *Client) List(idUser *user.ID) ([]cid.ID, error) { var rawID []byte if idUser != nil { @@ -37,21 +37,21 @@ func (c *Client) List(idUser *user.ID) ([]*cid.ID, error) { return nil, fmt.Errorf("could not get stack item array from stack item (%s): %w", listMethod, err) } - cidList := make([]*cid.ID, 0, len(res)) + cidList := make([]cid.ID, 0, len(res)) for i := range res { - rawCid, err := client.BytesFromStackItem(res[i]) + rawID, err := client.BytesFromStackItem(res[i]) if err != nil { return nil, fmt.Errorf("could not get byte array from stack item (%s): %w", listMethod, err) } var id cid.ID - err = id.Decode(rawCid) + err = id.Decode(rawID) if err != nil { return nil, fmt.Errorf("decode container ID: %w", err) } - cidList = append(cidList, &id) + cidList = append(cidList, id) } return cidList, nil diff --git a/pkg/morph/client/container/load.go b/pkg/morph/client/container/load.go index 9741ac6c..6f9dca47 100644 --- a/pkg/morph/client/container/load.go +++ b/pkg/morph/client/container/load.go @@ -99,7 +99,7 @@ type Estimation struct { // Estimations is a structure of grouped container load estimation inside Container contract. type Estimations struct { - ContainerID *cid.ID + ContainerID cid.ID Values []Estimation } @@ -125,7 +125,7 @@ func (c *Client) GetUsedSpaceEstimations(id EstimationID) (*Estimations, error) return nil, fmt.Errorf("unexpected stack item count of estimations fields (%s)", getSizeMethod) } - rawCID, err := client.BytesFromStackItem(prms[0]) + rawCnr, err := client.BytesFromStackItem(prms[0]) if err != nil { return nil, fmt.Errorf("could not get container ID byte array from stack item (%s): %w", getSizeMethod, err) } @@ -137,15 +137,15 @@ func (c *Client) GetUsedSpaceEstimations(id EstimationID) (*Estimations, error) var cnr cid.ID - err = cnr.Decode(rawCID) + err = cnr.Decode(rawCnr) if err != nil { return nil, fmt.Errorf("decode container ID: %w", err) } v2 := new(v2refs.ContainerID) - v2.SetValue(rawCID) + v2.SetValue(rawCnr) res := &Estimations{ - ContainerID: &cnr, + ContainerID: cnr, Values: make([]Estimation, 0, len(prms)), } diff --git a/pkg/morph/client/neofsid/keys.go b/pkg/morph/client/neofsid/keys.go index cff8a344..d0aa9fe2 100644 --- a/pkg/morph/client/neofsid/keys.go +++ b/pkg/morph/client/neofsid/keys.go @@ -11,11 +11,11 @@ import ( // AccountKeysPrm groups parameters of AccountKeys operation. type AccountKeysPrm struct { - id *user.ID + id user.ID } // SetID sets owner ID. -func (a *AccountKeysPrm) SetID(id *user.ID) { +func (a *AccountKeysPrm) SetID(id user.ID) { a.id = id } diff --git a/pkg/services/accounting/morph/executor.go b/pkg/services/accounting/morph/executor.go index b75beae0..58280226 100644 --- a/pkg/services/accounting/morph/executor.go +++ b/pkg/services/accounting/morph/executor.go @@ -34,7 +34,7 @@ func (s *morphExecutor) Balance(ctx context.Context, body *accounting.BalanceReq return nil, fmt.Errorf("invalid account: %w", err) } - amount, err := s.client.BalanceOf(&id) + amount, err := s.client.BalanceOf(id) if err != nil { return nil, err } diff --git a/pkg/services/audit/auditor/context.go b/pkg/services/audit/auditor/context.go index 9a965241..ef0816f7 100644 --- a/pkg/services/audit/auditor/context.go +++ b/pkg/services/audit/auditor/context.go @@ -11,7 +11,7 @@ import ( cid "github.com/nspcc-dev/neofs-sdk-go/container/id" "github.com/nspcc-dev/neofs-sdk-go/netmap" "github.com/nspcc-dev/neofs-sdk-go/object" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/nspcc-dev/neofs-sdk-go/storagegroup" "go.uber.org/atomic" "go.uber.org/zap" @@ -26,7 +26,7 @@ type Context struct { report *audit.Report sgMembersMtx sync.RWMutex - sgMembersCache map[int][]oidSDK.ID + sgMembersCache map[int][]oid.ID placementMtx sync.Mutex placementCache map[string][]netmap.Nodes @@ -57,7 +57,7 @@ type pairMemberInfo struct { type gamePair struct { n1, n2 *netmap.Node - id *oidSDK.ID + id oid.ID rn1, rn2 []*object.Range @@ -85,14 +85,14 @@ type ContextPrm struct { // component of communication with container nodes. type ContainerCommunicator interface { // Must return storage group structure stored in object from container. - GetSG(*audit.Task, *oidSDK.ID) (*storagegroup.StorageGroup, error) + GetSG(*audit.Task, oid.ID) (*storagegroup.StorageGroup, error) // Must return object header from the container node. - GetHeader(*audit.Task, *netmap.Node, *oidSDK.ID, bool) (*object.Object, error) + GetHeader(*audit.Task, *netmap.Node, oid.ID, bool) (*object.Object, error) // Must return homomorphic Tillich-Zemor hash of payload range of the // object stored in container node. - GetRangeHash(*audit.Task, *netmap.Node, *oidSDK.ID, *object.Range) ([]byte, error) + GetRangeHash(*audit.Task, *netmap.Node, oid.ID, *object.Range) ([]byte, error) } // NewContext creates, initializes and returns Context. @@ -151,14 +151,14 @@ func (c *Context) WithPoRWorkerPool(pool util.WorkerPool) *Context { return c } -func (c *Context) containerID() *cid.ID { +func (c *Context) containerID() cid.ID { return c.task.ContainerID() } func (c *Context) init() { c.report = audit.NewReport(c.containerID()) - c.sgMembersCache = make(map[int][]oidSDK.ID) + c.sgMembersCache = make(map[int][]oid.ID) c.placementCache = make(map[string][]netmap.Nodes) @@ -200,11 +200,11 @@ func (c *Context) writeReport() { } } -func (c *Context) buildPlacement(id *oidSDK.ID) ([]netmap.Nodes, error) { +func (c *Context) buildPlacement(id oid.ID) ([]netmap.Nodes, error) { c.placementMtx.Lock() defer c.placementMtx.Unlock() - strID := id.String() + strID := id.EncodeToString() if nn, ok := c.placementCache[strID]; ok { return nn, nil @@ -213,7 +213,7 @@ func (c *Context) buildPlacement(id *oidSDK.ID) ([]netmap.Nodes, error) { nn, err := placement.BuildObjectPlacement( c.task.NetworkMap(), c.task.ContainerNodes(), - id, + &id, ) if err != nil { return nil, err @@ -224,11 +224,11 @@ func (c *Context) buildPlacement(id *oidSDK.ID) ([]netmap.Nodes, error) { return nn, nil } -func (c *Context) objectSize(id *oidSDK.ID) uint64 { +func (c *Context) objectSize(id oid.ID) uint64 { c.headMtx.RLock() defer c.headMtx.RUnlock() - strID := id.String() + strID := id.EncodeToString() if hdr, ok := c.headResponses[strID]; ok { return hdr.objectSize @@ -237,11 +237,11 @@ func (c *Context) objectSize(id *oidSDK.ID) uint64 { return 0 } -func (c *Context) objectHomoHash(id *oidSDK.ID) []byte { +func (c *Context) objectHomoHash(id oid.ID) []byte { c.headMtx.RLock() defer c.headMtx.RUnlock() - strID := id.String() + strID := id.EncodeToString() if hdr, ok := c.headResponses[strID]; ok { return hdr.tzhash @@ -270,7 +270,7 @@ func (c *Context) updateHeadResponses(hdr *object.Object) { } } -func (c *Context) updateSGInfo(ind int, members []oidSDK.ID) { +func (c *Context) updateSGInfo(ind int, members []oid.ID) { c.sgMembersMtx.Lock() defer c.sgMembersMtx.Unlock() diff --git a/pkg/services/audit/auditor/pdp.go b/pkg/services/audit/auditor/pdp.go index 99786d6f..22ffb1a0 100644 --- a/pkg/services/audit/auditor/pdp.go +++ b/pkg/services/audit/auditor/pdp.go @@ -9,7 +9,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/util/rand" "github.com/nspcc-dev/neofs-sdk-go/netmap" "github.com/nspcc-dev/neofs-sdk-go/object" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/nspcc-dev/tzhash/tz" "go.uber.org/zap" ) @@ -82,7 +82,7 @@ func (c *Context) distributeRanges(p *gamePair) { } } -func (c *Context) splitPayload(id *oidSDK.ID) []uint64 { +func (c *Context) splitPayload(id oid.ID) []uint64 { var ( prev uint64 size = c.objectSize(id) diff --git a/pkg/services/audit/auditor/pop.go b/pkg/services/audit/auditor/pop.go index 8f10d785..c9dbc372 100644 --- a/pkg/services/audit/auditor/pop.go +++ b/pkg/services/audit/auditor/pop.go @@ -2,7 +2,7 @@ package auditor import ( "github.com/nspcc-dev/neofs-sdk-go/netmap" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/nspcc-dev/tzhash/tz" "go.uber.org/zap" ) @@ -27,7 +27,7 @@ func (c *Context) buildCoverage() { // select random member from another storage group // and process all placement vectors - c.iterateSGMembersPlacementRand(func(id *oidSDK.ID, ind int, nodes netmap.Nodes) bool { + c.iterateSGMembersPlacementRand(func(id oid.ID, ind int, nodes netmap.Nodes) bool { c.processObjectPlacement(id, nodes, replicas[ind].Count()) return c.containerCovered() }) @@ -38,7 +38,7 @@ func (c *Context) containerCovered() bool { return c.cnrNodesNum <= len(c.pairedNodes) } -func (c *Context) processObjectPlacement(id *oidSDK.ID, nodes netmap.Nodes, replicas uint32) { +func (c *Context) processObjectPlacement(id oid.ID, nodes netmap.Nodes, replicas uint32) { var ( ok uint32 optimal bool @@ -102,7 +102,7 @@ func (c *Context) processObjectPlacement(id *oidSDK.ID, nodes netmap.Nodes, repl } } -func (c *Context) composePair(id *oidSDK.ID, n1, n2 *netmap.Node) { +func (c *Context) composePair(id oid.ID, n1, n2 *netmap.Node) { c.pairs = append(c.pairs, gamePair{ n1: n1, n2: n2, @@ -117,10 +117,10 @@ func (c *Context) composePair(id *oidSDK.ID, n1, n2 *netmap.Node) { } } -func (c *Context) iterateSGMembersPlacementRand(f func(*oidSDK.ID, int, netmap.Nodes) bool) { +func (c *Context) iterateSGMembersPlacementRand(f func(oid.ID, int, netmap.Nodes) bool) { // iterate over storage groups members for all storage groups (one by one) // with randomly shuffled members - c.iterateSGMembersRand(func(id *oidSDK.ID) bool { + c.iterateSGMembersRand(func(id oid.ID) bool { // build placement vector for the current object nn, err := c.buildPlacement(id) if err != nil { @@ -142,8 +142,8 @@ func (c *Context) iterateSGMembersPlacementRand(f func(*oidSDK.ID, int, netmap.N }) } -func (c *Context) iterateSGMembersRand(f func(*oidSDK.ID) bool) { - c.iterateSGInfo(func(members []oidSDK.ID) bool { +func (c *Context) iterateSGMembersRand(f func(oid.ID) bool) { + c.iterateSGInfo(func(members []oid.ID) bool { ln := len(members) processed := make(map[uint64]struct{}, ln-1) @@ -152,7 +152,7 @@ func (c *Context) iterateSGMembersRand(f func(*oidSDK.ID) bool) { ind := nextRandUint64(uint64(ln), processed) processed[ind] = struct{}{} - if f(&members[ind]) { + if f(members[ind]) { return true } } @@ -161,7 +161,7 @@ func (c *Context) iterateSGMembersRand(f func(*oidSDK.ID) bool) { }) } -func (c *Context) iterateSGInfo(f func([]oidSDK.ID) bool) { +func (c *Context) iterateSGInfo(f func([]oid.ID) bool) { c.sgMembersMtx.RLock() defer c.sgMembersMtx.RUnlock() diff --git a/pkg/services/audit/auditor/por.go b/pkg/services/audit/auditor/por.go index 817b96bc..1a4c183d 100644 --- a/pkg/services/audit/auditor/por.go +++ b/pkg/services/audit/auditor/por.go @@ -7,7 +7,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement" "github.com/nspcc-dev/neofs-node/pkg/util/rand" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/nspcc-dev/tzhash/tz" "go.uber.org/zap" ) @@ -22,7 +22,7 @@ func (c *Context) executePoR() { sg := sgs[i] if err := c.porWorkerPool.Submit(func() { - c.checkStorageGroupPoR(i, &sg) + c.checkStorageGroupPoR(i, sg) wg.Done() }); err != nil { wg.Done() @@ -35,7 +35,7 @@ func (c *Context) executePoR() { c.report.SetPoRCounters(c.porRequests.Load(), c.porRetries.Load()) } -func (c *Context) checkStorageGroupPoR(ind int, sg *oidSDK.ID) { +func (c *Context) checkStorageGroupPoR(ind int, sg oid.ID) { storageGroup, err := c.cnrCom.GetSG(c.task, sg) // get storage group if err != nil { c.log.Warn("can't get storage group", @@ -56,7 +56,7 @@ func (c *Context) checkStorageGroupPoR(ind int, sg *oidSDK.ID) { ) for i := range members { - objectPlacement, err := c.buildPlacement(&members[i]) + objectPlacement, err := c.buildPlacement(members[i]) if err != nil { c.log.Info("can't build placement for storage group member", zap.Stringer("sg", sg), @@ -78,11 +78,12 @@ func (c *Context) checkStorageGroupPoR(ind int, sg *oidSDK.ID) { accRetries++ } - hdr, err := c.cnrCom.GetHeader(c.task, &flat[j], &members[i], true) + hdr, err := c.cnrCom.GetHeader(c.task, &flat[j], members[i], true) if err != nil { c.log.Debug("can't head object", zap.String("remote_node", hex.EncodeToString(flat[j].PublicKey())), - zap.String("oid", members[i].String())) + zap.Stringer("oid", members[i]), + ) continue } @@ -98,7 +99,7 @@ func (c *Context) checkStorageGroupPoR(ind int, sg *oidSDK.ID) { tzHash, err = tz.Concat([][]byte{tzHash, cs.Value()}) if err != nil { c.log.Debug("can't concatenate tz hash", - zap.String("oid", members[i].String()), + zap.Stringer("oid", members[i]), zap.String("error", err.Error())) break diff --git a/pkg/services/audit/report.go b/pkg/services/audit/report.go index 496c12fd..61fc6241 100644 --- a/pkg/services/audit/report.go +++ b/pkg/services/audit/report.go @@ -5,7 +5,7 @@ import ( "github.com/nspcc-dev/neofs-sdk-go/audit" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) // Report tracks the progress of auditing container data. @@ -21,9 +21,9 @@ type Reporter interface { } // NewReport creates and returns blank Report instance. -func NewReport(cid *cid.ID) *Report { +func NewReport(cnr cid.ID) *Report { var rep Report - rep.res.ForContainer(*cid) + rep.res.ForContainer(cnr) return &rep } @@ -45,19 +45,19 @@ func (r *Report) Complete() { } // PassedPoR updates list of passed storage groups. -func (r *Report) PassedPoR(sg *oidSDK.ID) { +func (r *Report) PassedPoR(sg oid.ID) { r.mu.Lock() defer r.mu.Unlock() - r.res.SubmitPassedStorageGroup(*sg) + r.res.SubmitPassedStorageGroup(sg) } // FailedPoR updates list of failed storage groups. -func (r *Report) FailedPoR(sg *oidSDK.ID) { +func (r *Report) FailedPoR(sg oid.ID) { r.mu.Lock() defer r.mu.Unlock() - r.res.SubmitFailedStorageGroup(*sg) + r.res.SubmitFailedStorageGroup(sg) } // SetPlacementCounters sets counters of compliance with placement. diff --git a/pkg/services/audit/task.go b/pkg/services/audit/task.go index 1948add9..93ec3a89 100644 --- a/pkg/services/audit/task.go +++ b/pkg/services/audit/task.go @@ -6,7 +6,7 @@ import ( "github.com/nspcc-dev/neofs-sdk-go/container" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" "github.com/nspcc-dev/neofs-sdk-go/netmap" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) // Task groups groups the container audit parameters. @@ -15,7 +15,7 @@ type Task struct { auditContext context.Context - cid *cid.ID + idCnr cid.ID cnr *container.Container @@ -23,7 +23,7 @@ type Task struct { cnrNodes netmap.ContainerNodes - sgList []oidSDK.ID + sgList []oid.ID } // WithReporter sets audit report writer. @@ -55,17 +55,17 @@ func (t *Task) AuditContext() context.Context { } // WithContainerID sets identifier of the container under audit. -func (t *Task) WithContainerID(cid *cid.ID) *Task { +func (t *Task) WithContainerID(cnr cid.ID) *Task { if t != nil { - t.cid = cid + t.idCnr = cnr } return t } // ContainerID returns identifier of the container under audit. -func (t *Task) ContainerID() *cid.ID { - return t.cid +func (t *Task) ContainerID() cid.ID { + return t.idCnr } // WithContainerStructure sets structure of the container under audit. @@ -111,7 +111,7 @@ func (t *Task) ContainerNodes() netmap.ContainerNodes { } // WithStorageGroupList sets a list of storage groups from container under audit. -func (t *Task) WithStorageGroupList(sgList []oidSDK.ID) *Task { +func (t *Task) WithStorageGroupList(sgList []oid.ID) *Task { if t != nil { t.sgList = sgList } @@ -120,6 +120,6 @@ func (t *Task) WithStorageGroupList(sgList []oidSDK.ID) *Task { } // StorageGroupList returns list of storage groups from container under audit. -func (t *Task) StorageGroupList() []oidSDK.ID { +func (t *Task) StorageGroupList() []oid.ID { return t.sgList } diff --git a/pkg/services/container/announcement/load/route/placement/calls.go b/pkg/services/container/announcement/load/route/placement/calls.go index 2f93dc32..f33bc3be 100644 --- a/pkg/services/container/announcement/load/route/placement/calls.go +++ b/pkg/services/container/announcement/load/route/placement/calls.go @@ -25,7 +25,7 @@ func (b *Builder) NextStage(a container.UsedSpaceAnnouncement, passed []loadrout return nil, errors.New("missing container in load announcement") } - placement, err := b.placementBuilder.BuildPlacement(a.Epoch(), &cnr) + placement, err := b.placementBuilder.BuildPlacement(a.Epoch(), cnr) if err != nil { return nil, fmt.Errorf("could not build placement %s: %w", cnr, err) } diff --git a/pkg/services/container/announcement/load/route/placement/deps.go b/pkg/services/container/announcement/load/route/placement/deps.go index ccf31e01..53ebc9bd 100644 --- a/pkg/services/container/announcement/load/route/placement/deps.go +++ b/pkg/services/container/announcement/load/route/placement/deps.go @@ -8,7 +8,7 @@ import ( // PlacementBuilder describes interface of NeoFS placement calculator. type PlacementBuilder interface { // BuildPlacement must compose and sort (according to a specific algorithm) - // storage nodes from the container with identifier cid using network map + // storage nodes from the container by its identifier using network map // of particular epoch. - BuildPlacement(epoch uint64, cid *cid.ID) ([]netmap.Nodes, error) + BuildPlacement(epoch uint64, cnr cid.ID) ([]netmap.Nodes, error) } diff --git a/pkg/services/container/morph/executor.go b/pkg/services/container/morph/executor.go index bd71ee72..e5508c79 100644 --- a/pkg/services/container/morph/executor.go +++ b/pkg/services/container/morph/executor.go @@ -32,7 +32,7 @@ type Reader interface { // List returns a list of container identifiers belonging // to the specified user of NeoFS system. Returns the identifiers // of all NeoFS containers if pointer to owner identifier is nil. - List(*user.ID) ([]*cid.ID, error) + List(*user.ID) ([]cid.ID, error) } // Writer is an interface of container storage updater. @@ -119,7 +119,7 @@ func (s *morphExecutor) Delete(_ context.Context, tokV2 *sessionV2.Token, body * var rmWitness containercore.RemovalWitness - rmWitness.SetContainerID(&id) + rmWitness.SetContainerID(id) rmWitness.SetSignature(sig) rmWitness.SetSessionToken(tok) @@ -144,7 +144,7 @@ func (s *morphExecutor) Get(ctx context.Context, body *container.GetRequestBody) return nil, fmt.Errorf("invalid container ID: %w", err) } - cnr, err := s.rdr.Get(&id) + cnr, err := s.rdr.Get(id) if err != nil { return nil, err } @@ -247,7 +247,7 @@ func (s *morphExecutor) GetExtendedACL(ctx context.Context, body *container.GetE return nil, fmt.Errorf("invalid container ID: %w", err) } - table, err := s.rdr.GetEACL(&id) + table, err := s.rdr.GetEACL(id) if err != nil { return nil, err } diff --git a/pkg/services/control/common_test.go b/pkg/services/control/common_test.go index 546aa37c..bc512b4b 100644 --- a/pkg/services/control/common_test.go +++ b/pkg/services/control/common_test.go @@ -10,15 +10,12 @@ import ( ) type protoMessage interface { - StableMarshal([]byte) ([]byte, error) + StableMarshal([]byte) []byte proto.Message } func testStableMarshal(t *testing.T, m1, m2 protoMessage, cmp func(m1, m2 protoMessage) bool) { - data, err := m1.StableMarshal(nil) - require.NoError(t, err) - - require.NoError(t, proto.Unmarshal(data, m2)) + require.NoError(t, proto.Unmarshal(m1.StableMarshal(nil), m2)) require.True(t, cmp(m1, m2)) } diff --git a/pkg/services/control/ir/service.go b/pkg/services/control/ir/service.go index 7e542a09..8f61c0c7 100644 --- a/pkg/services/control/ir/service.go +++ b/pkg/services/control/ir/service.go @@ -76,25 +76,21 @@ const ( // // If buffer length is less than x.StableSize(), new buffer is allocated. // -// Returns any error encountered which did not allow writing the data completely. -// Otherwise, returns the buffer in which the data is written. +// Returns the buffer in which the data is written. // // Structures with the same field values have the same binary format. -func (x *HealthCheckResponse_Body) StableMarshal(buf []byte) ([]byte, error) { +func (x *HealthCheckResponse_Body) StableMarshal(buf []byte) []byte { if x == nil { - return []byte{}, nil + return []byte{} } if sz := x.StableSize(); len(buf) < sz { buf = make([]byte, sz) } - _, err := proto.EnumMarshal(healthRespBodyHealthStatusFNum, buf, int32(x.HealthStatus)) - if err != nil { - return nil, err - } + proto.EnumMarshal(healthRespBodyHealthStatusFNum, buf, int32(x.HealthStatus)) - return buf, nil + return buf } // StableSize returns binary size of health check response body @@ -136,7 +132,7 @@ func (x *HealthCheckResponse) SetSignature(v *Signature) { // // Structures with the same field values have the same signed data. func (x *HealthCheckResponse) ReadSignedData(buf []byte) ([]byte, error) { - return x.GetBody().StableMarshal(buf) + return x.GetBody().StableMarshal(buf), nil } // SignedDataSize returns binary size of the signed data diff --git a/pkg/services/control/ir/service_test.go b/pkg/services/control/ir/service_test.go index 9958e0a5..266d8c9c 100644 --- a/pkg/services/control/ir/service_test.go +++ b/pkg/services/control/ir/service_test.go @@ -9,15 +9,12 @@ import ( ) type protoMessage interface { - StableMarshal([]byte) ([]byte, error) + StableMarshal([]byte) []byte proto.Message } func testStableMarshal(t *testing.T, m1, m2 protoMessage, cmp func(m1, m2 protoMessage) bool) { - data, err := m1.StableMarshal(nil) - require.NoError(t, err) - - require.NoError(t, proto.Unmarshal(data, m2)) + require.NoError(t, proto.Unmarshal(m1.StableMarshal(nil), m2)) require.True(t, cmp(m1, m2)) } diff --git a/pkg/services/control/server/gc.go b/pkg/services/control/server/gc.go index 3643a91a..15e37ffa 100644 --- a/pkg/services/control/server/gc.go +++ b/pkg/services/control/server/gc.go @@ -5,13 +5,13 @@ import ( "fmt" "github.com/nspcc-dev/neofs-node/pkg/services/control" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) // DeletedObjectHandler is a handler of objects to be removed. -type DeletedObjectHandler func([]*addressSDK.Address) error +type DeletedObjectHandler func([]oid.Address) error // DropObjects marks objects to be removed from the local node. // @@ -26,19 +26,15 @@ func (s *Server) DropObjects(_ context.Context, req *control.DropObjectsRequest) } binAddrList := req.GetBody().GetAddressList() - addrList := make([]*addressSDK.Address, 0, len(binAddrList)) + addrList := make([]oid.Address, len(binAddrList)) for i := range binAddrList { - a := addressSDK.NewAddress() - - err := a.Unmarshal(binAddrList[i]) + err := addrList[i].DecodeString(string(binAddrList[i])) if err != nil { return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid binary object address: %v", err), ) } - - addrList = append(addrList, a) } err := s.delObjHandler(addrList) diff --git a/pkg/services/control/service.go b/pkg/services/control/service.go index ab93b993..fc0bee47 100644 --- a/pkg/services/control/service.go +++ b/pkg/services/control/service.go @@ -84,37 +84,24 @@ const ( // // If buffer length is less than x.StableSize(), new buffer is allocated. // -// Returns any error encountered which did not allow writing the data completely. -// Otherwise, returns the buffer in which the data is written. +// Returns the buffer in which the data is written. // // Structures with the same field values have the same binary format. -func (x *HealthCheckResponse_Body) StableMarshal(buf []byte) ([]byte, error) { +func (x *HealthCheckResponse_Body) StableMarshal(buf []byte) []byte { if x == nil { - return []byte{}, nil + return []byte{} } if sz := x.StableSize(); len(buf) < sz { buf = make([]byte, sz) } - var ( - offset, n int - err error - ) + var offset int - n, err = proto.EnumMarshal(healthRespBodyStatusFNum, buf[offset:], int32(x.NetmapStatus)) - if err != nil { - return nil, err - } + offset = proto.EnumMarshal(healthRespBodyStatusFNum, buf[offset:], int32(x.NetmapStatus)) + proto.EnumMarshal(healthRespBodyHealthStatusFNum, buf[offset:], int32(x.HealthStatus)) - offset += n - - _, err = proto.EnumMarshal(healthRespBodyHealthStatusFNum, buf[offset:], int32(x.HealthStatus)) - if err != nil { - return nil, err - } - - return buf, nil + return buf } // StableSize returns binary size of health check response body @@ -157,7 +144,7 @@ func (x *HealthCheckResponse) SetSignature(v *Signature) { // // Structures with the same field values have the same signed data. func (x *HealthCheckResponse) ReadSignedData(buf []byte) ([]byte, error) { - return x.GetBody().StableMarshal(buf) + return x.GetBody().StableMarshal(buf), nil } // SignedDataSize returns binary size of the signed data @@ -240,25 +227,21 @@ const ( // // If buffer length is less than x.StableSize(), new buffer is allocated. // -// Returns any error encountered which did not allow writing the data completely. -// Otherwise, returns the buffer in which the data is written. +// Returns the buffer in which the data is written. // // Structures with the same field values have the same binary format. -func (x *NetmapSnapshotResponse_Body) StableMarshal(buf []byte) ([]byte, error) { +func (x *NetmapSnapshotResponse_Body) StableMarshal(buf []byte) []byte { if x == nil { - return []byte{}, nil + return []byte{} } if sz := x.StableSize(); len(buf) < sz { buf = make([]byte, sz) } - _, err := proto.NestedStructureMarshal(snapshotRespBodyNetmapFNum, buf, x.Netmap) - if err != nil { - return nil, err - } + proto.NestedStructureMarshal(snapshotRespBodyNetmapFNum, buf, x.Netmap) - return buf, nil + return buf } // StableSize returns binary size of netmap snapshot response body @@ -300,7 +283,7 @@ func (x *NetmapSnapshotResponse) SetSignature(v *Signature) { // // Structures with the same field values have the same signed data. func (x *NetmapSnapshotResponse) ReadSignedData(buf []byte) ([]byte, error) { - return x.GetBody().StableMarshal(buf) + return x.GetBody().StableMarshal(buf), nil } // SignedDataSize returns binary size of the signed data @@ -328,25 +311,21 @@ const ( // // If buffer length is less than x.StableSize(), new buffer is allocated. // -// Returns any error encountered which did not allow writing the data completely. -// Otherwise, returns the buffer in which the data is written. +// Returns the buffer in which the data is written. // // Structures with the same field values have the same binary format. -func (x *SetNetmapStatusRequest_Body) StableMarshal(buf []byte) ([]byte, error) { +func (x *SetNetmapStatusRequest_Body) StableMarshal(buf []byte) []byte { if x == nil { - return []byte{}, nil + return []byte{} } if sz := x.StableSize(); len(buf) < sz { buf = make([]byte, sz) } - _, err := proto.EnumMarshal(setNetmapStatusReqBodyStatusFNum, buf, int32(x.Status)) - if err != nil { - return nil, err - } + proto.EnumMarshal(setNetmapStatusReqBodyStatusFNum, buf, int32(x.Status)) - return buf, nil + return buf } // StableSize returns binary size of netmap status response body @@ -388,7 +367,7 @@ func (x *SetNetmapStatusRequest) SetSignature(body *Signature) { // // Structures with the same field values have the same signed data. func (x *SetNetmapStatusRequest) ReadSignedData(buf []byte) ([]byte, error) { - return x.GetBody().StableMarshal(buf) + return x.GetBody().StableMarshal(buf), nil } // SignedDataSize returns binary size of the signed data @@ -404,12 +383,11 @@ func (x *SetNetmapStatusRequest) SignedDataSize() int { // // If buffer length is less than x.StableSize(), new buffer is allocated. // -// Returns any error encountered which did not allow writing the data completely. -// Otherwise, returns the buffer in which the data is written. +// Returns the buffer in which the data is written. // // Structures with the same field values have the same binary format. -func (x *SetNetmapStatusResponse_Body) StableMarshal(buf []byte) ([]byte, error) { - return buf, nil +func (x *SetNetmapStatusResponse_Body) StableMarshal(buf []byte) []byte { + return buf } // StableSize returns binary size of set netmap status response body @@ -443,7 +421,7 @@ func (x *SetNetmapStatusResponse) SetSignature(v *Signature) { // // Structures with the same field values have the same signed data. func (x *SetNetmapStatusResponse) ReadSignedData(buf []byte) ([]byte, error) { - return x.GetBody().StableMarshal(buf) + return x.GetBody().StableMarshal(buf), nil } // SignedDataSize returns binary size of the signed data @@ -471,25 +449,21 @@ const ( // // If buffer length is less than x.StableSize(), new buffer is allocated. // -// Returns any error encountered which did not allow writing the data completely. -// Otherwise, returns the buffer in which the data is written. +// Returns the buffer in which the data is written. // // Structures with the same field values have the same binary format. -func (x *DropObjectsRequest_Body) StableMarshal(buf []byte) ([]byte, error) { +func (x *DropObjectsRequest_Body) StableMarshal(buf []byte) []byte { if x == nil { - return []byte{}, nil + return []byte{} } if sz := x.StableSize(); len(buf) < sz { buf = make([]byte, sz) } - _, err := proto.RepeatedBytesMarshal(addrListReqBodyStatusFNum, buf, x.AddressList) - if err != nil { - return nil, err - } + proto.RepeatedBytesMarshal(addrListReqBodyStatusFNum, buf, x.AddressList) - return buf, nil + return buf } // StableSize returns binary size of "Drop objects" response body @@ -531,7 +505,7 @@ func (x *DropObjectsRequest) SetSignature(body *Signature) { // // Structures with the same field values have the same signed data. func (x *DropObjectsRequest) ReadSignedData(buf []byte) ([]byte, error) { - return x.GetBody().StableMarshal(buf) + return x.GetBody().StableMarshal(buf), nil } // SignedDataSize returns binary size of the signed data of "Drop objects" request. @@ -546,12 +520,11 @@ func (x *DropObjectsRequest) SignedDataSize() int { // // If buffer length is less than x.StableSize(), new buffer is allocated. // -// Returns any error encountered which did not allow writing the data completely. -// Otherwise, returns the buffer in which the data is written. +// Returns the buffer in which the data is written. // // Structures with the same field values have the same binary format. -func (x *DropObjectsResponse_Body) StableMarshal(buf []byte) ([]byte, error) { - return buf, nil +func (x *DropObjectsResponse_Body) StableMarshal(buf []byte) []byte { + return buf } // StableSize returns binary size of "Drop objects" response body @@ -585,7 +558,7 @@ func (x *DropObjectsResponse) SetSignature(v *Signature) { // // Structures with the same field values have the same signed data. func (x *DropObjectsResponse) ReadSignedData(buf []byte) ([]byte, error) { - return x.GetBody().StableMarshal(buf) + return x.GetBody().StableMarshal(buf), nil } // SignedDataSize returns binary size of the signed data of "Drop objects" response. @@ -600,12 +573,11 @@ func (x *DropObjectsResponse) SignedDataSize() int { // // If buffer length is less than x.StableSize(), new buffer is allocated. // -// Returns any error encountered which did not allow writing the data completely. -// Otherwise, returns the buffer in which the data is written. +// Returns the buffer in which the data is written. // // Structures with the same field values have the same binary format. -func (x *ListShardsRequest_Body) StableMarshal(buf []byte) ([]byte, error) { - return buf, nil +func (x *ListShardsRequest_Body) StableMarshal(buf []byte) []byte { + return buf } // StableSize returns binary size of list shards request body @@ -639,7 +611,7 @@ func (x *ListShardsRequest) SetSignature(body *Signature) { // // Structures with the same field values have the same signed data. func (x *ListShardsRequest) ReadSignedData(buf []byte) ([]byte, error) { - return x.GetBody().StableMarshal(buf) + return x.GetBody().StableMarshal(buf), nil } // SignedDataSize returns binary size of the signed data @@ -667,34 +639,25 @@ const ( // // If buffer length is less than x.StableSize(), new buffer is allocated. // -// Returns any error encountered which did not allow writing the data completely. -// Otherwise, returns the buffer in which the data is written. +// Returns the buffer in which the data is written. // // Structures with the same field values have the same binary format. -func (x *ListShardsResponse_Body) StableMarshal(buf []byte) ([]byte, error) { +func (x *ListShardsResponse_Body) StableMarshal(buf []byte) []byte { if x == nil { - return []byte{}, nil + return []byte{} } if sz := x.StableSize(); len(buf) < sz { buf = make([]byte, sz) } - var ( - offset, n int - err error - ) + var offset int for i := range x.Shards { - n, err = proto.NestedStructureMarshal(listShardsRespBodyShardsFNum, buf[offset:], x.Shards[i]) - if err != nil { - return nil, err - } - - offset += n + offset += proto.NestedStructureMarshal(listShardsRespBodyShardsFNum, buf[offset:], x.Shards[i]) } - return buf, nil + return buf } // StableSize returns binary size of list shards response body @@ -738,7 +701,7 @@ func (x *ListShardsResponse) SetSignature(v *Signature) { // // Structures with the same field values have the same signed data. func (x *ListShardsResponse) ReadSignedData(buf []byte) ([]byte, error) { - return x.GetBody().StableMarshal(buf) + return x.GetBody().StableMarshal(buf), nil } // SignedDataSize returns binary size of the signed data @@ -778,44 +741,23 @@ const ( // // If buffer length is less than x.StableSize(), new buffer is allocated. // -// Returns any error encountered which did not allow writing the data completely. -// Otherwise, returns the buffer in which the data is written. +// Returns the buffer in which the data is written. // // Structures with the same field values have the same binary format. -func (x *SetShardModeRequest_Body) StableMarshal(buf []byte) ([]byte, error) { +func (x *SetShardModeRequest_Body) StableMarshal(buf []byte) []byte { if x == nil { - return []byte{}, nil + return []byte{} } if sz := x.StableSize(); len(buf) < sz { buf = make([]byte, sz) } - var ( - offset, n int - err error - ) + offset := proto.BytesMarshal(setShardModeReqBodyShardIDFNum, buf, x.Shard_ID) + offset += proto.EnumMarshal(setShardModeReqBodyModeFNum, buf[offset:], int32(x.Mode)) + proto.BoolMarshal(setShardModeReqBodyResetCounterFNum, buf[offset:], x.ResetErrorCounter) - n, err = proto.BytesMarshal(setShardModeReqBodyShardIDFNum, buf, x.Shard_ID) - if err != nil { - return nil, err - } - - offset += n - - n, err = proto.EnumMarshal(setShardModeReqBodyModeFNum, buf[offset:], int32(x.Mode)) - if err != nil { - return nil, err - } - - offset += n - - _, err = proto.BoolMarshal(setShardModeReqBodyResetCounterFNum, buf[offset:], x.ResetErrorCounter) - if err != nil { - return nil, err - } - - return buf, nil + return buf } // StableSize returns binary size of set shard mode response body @@ -859,7 +801,7 @@ func (x *SetShardModeRequest) SetSignature(v *Signature) { // // Structures with the same field values have the same signed data. func (x *SetShardModeRequest) ReadSignedData(buf []byte) ([]byte, error) { - return x.GetBody().StableMarshal(buf) + return x.GetBody().StableMarshal(buf), nil } // SignedDataSize returns binary size of the signed data @@ -875,12 +817,11 @@ func (x *SetShardModeRequest) SignedDataSize() int { // // If buffer length is less than x.StableSize(), new buffer is allocated. // -// Returns any error encountered which did not allow writing the data completely. -// Otherwise, returns the buffer in which the data is written. +// Returns the buffer in which the data is written. // // Structures with the same field values have the same binary format. -func (x *SetShardModeResponse_Body) StableMarshal(buf []byte) ([]byte, error) { - return buf, nil +func (x *SetShardModeResponse_Body) StableMarshal(buf []byte) []byte { + return buf } // StableSize returns binary size of the set shard mode response body @@ -914,7 +855,7 @@ func (x *SetShardModeResponse) SetSignature(v *Signature) { // // Structures with the same field values have the same signed data. func (x *SetShardModeResponse) ReadSignedData(buf []byte) ([]byte, error) { - return x.GetBody().StableMarshal(buf) + return x.GetBody().StableMarshal(buf), nil } // SignedDataSize returns binary size of the signed data @@ -951,44 +892,23 @@ const ( // // If buffer length is less than StableSize(), new buffer is allocated. // -// Returns any error encountered which did not allow writing the data completely. -// Otherwise, returns the buffer in which the data is written. +// Returns the buffer in which the data is written. // // Structures with the same field values have the same binary format. -func (x *DumpShardRequest_Body) StableMarshal(buf []byte) ([]byte, error) { +func (x *DumpShardRequest_Body) StableMarshal(buf []byte) []byte { if x == nil { - return []byte{}, nil + return []byte{} } if sz := x.StableSize(); len(buf) < sz { buf = make([]byte, sz) } - var ( - offset, n int - err error - ) + offset := proto.BytesMarshal(dumpShardReqBodyShardIDFNum, buf, x.Shard_ID) + offset += proto.StringMarshal(dumpShardReqBodyFilepathFNum, buf[offset:], x.Filepath) + proto.BoolMarshal(dumpShardReqBodyIgnoreErrorsFNum, buf[offset:], x.IgnoreErrors) - n, err = proto.BytesMarshal(dumpShardReqBodyShardIDFNum, buf, x.Shard_ID) - if err != nil { - return nil, err - } - - offset += n - - n, err = proto.StringMarshal(dumpShardReqBodyFilepathFNum, buf[offset:], x.Filepath) - if err != nil { - return nil, err - } - - offset += n - - _, err = proto.BoolMarshal(dumpShardReqBodyIgnoreErrorsFNum, buf[offset:], x.IgnoreErrors) - if err != nil { - return nil, err - } - - return buf, nil + return buf } // StableSize returns binary size of the request body in protobuf binary format. @@ -1031,7 +951,7 @@ func (x *DumpShardRequest) SetSignature(v *Signature) { // // Structures with the same field values have the same signed data. func (x *DumpShardRequest) ReadSignedData(buf []byte) ([]byte, error) { - return x.GetBody().StableMarshal(buf) + return x.GetBody().StableMarshal(buf), nil } // SignedDataSize returns size of the request signed data in bytes. @@ -1045,12 +965,11 @@ func (x *DumpShardRequest) SignedDataSize() int { // // If buffer length is less than x.StableSize(), new buffer is allocated. // -// Returns any error encountered which did not allow writing the data completely. -// Otherwise, returns the buffer in which the data is written. +// Returns the buffer in which the data is written. // // Structures with the same field values have the same binary format. -func (x *DumpShardResponse_Body) StableMarshal(buf []byte) ([]byte, error) { - return buf, nil +func (x *DumpShardResponse_Body) StableMarshal(buf []byte) []byte { + return buf } // StableSize returns binary size of the response body @@ -1084,7 +1003,7 @@ func (x *DumpShardResponse) SetSignature(v *Signature) { // // Structures with the same field values have the same signed data. func (x *DumpShardResponse) ReadSignedData(buf []byte) ([]byte, error) { - return x.GetBody().StableMarshal(buf) + return x.GetBody().StableMarshal(buf), nil } // SignedDataSize returns binary size of the signed data. @@ -1120,44 +1039,23 @@ const ( // // If buffer length is less than StableSize(), new buffer is allocated. // -// Returns any error encountered which did not allow writing the data completely. -// Otherwise, returns the buffer in which the data is written. +// Returns the buffer in which the data is written. // // Structures with the same field values have the same binary format. -func (x *RestoreShardRequest_Body) StableMarshal(buf []byte) ([]byte, error) { +func (x *RestoreShardRequest_Body) StableMarshal(buf []byte) []byte { if x == nil { - return []byte{}, nil + return []byte{} } if sz := x.StableSize(); len(buf) < sz { buf = make([]byte, sz) } - var ( - offset, n int - err error - ) + offset := proto.BytesMarshal(restoreShardReqBodyShardIDFNum, buf, x.Shard_ID) + offset += proto.StringMarshal(restoreShardReqBodyFilepathFNum, buf[offset:], x.Filepath) + proto.BoolMarshal(restoreShardReqBodyIgnoreErrorsFNum, buf[offset:], x.IgnoreErrors) - n, err = proto.BytesMarshal(restoreShardReqBodyShardIDFNum, buf, x.Shard_ID) - if err != nil { - return nil, err - } - - offset += n - - n, err = proto.StringMarshal(restoreShardReqBodyFilepathFNum, buf[offset:], x.Filepath) - if err != nil { - return nil, err - } - - offset += n - - _, err = proto.BoolMarshal(restoreShardReqBodyIgnoreErrorsFNum, buf[offset:], x.IgnoreErrors) - if err != nil { - return nil, err - } - - return buf, nil + return buf } // StableSize returns binary size of the request body in protobuf binary format. @@ -1200,7 +1098,7 @@ func (x *RestoreShardRequest) SetSignature(v *Signature) { // // Structures with the same field values have the same signed data. func (x *RestoreShardRequest) ReadSignedData(buf []byte) ([]byte, error) { - return x.GetBody().StableMarshal(buf) + return x.GetBody().StableMarshal(buf), nil } // SignedDataSize returns size of the request signed data in bytes. @@ -1214,12 +1112,11 @@ func (x *RestoreShardRequest) SignedDataSize() int { // // If buffer length is less than x.StableSize(), new buffer is allocated. // -// Returns any error encountered which did not allow writing the data completely. -// Otherwise, returns the buffer in which the data is written. +// Returns the buffer in which the data is written. // // Structures with the same field values have the same binary format. -func (x *RestoreShardResponse_Body) StableMarshal(buf []byte) ([]byte, error) { - return buf, nil +func (x *RestoreShardResponse_Body) StableMarshal(buf []byte) []byte { + return buf } // StableSize returns binary size of the response body @@ -1253,7 +1150,7 @@ func (x *RestoreShardResponse) SetSignature(v *Signature) { // // Structures with the same field values have the same signed data. func (x *RestoreShardResponse) ReadSignedData(buf []byte) ([]byte, error) { - return x.GetBody().StableMarshal(buf) + return x.GetBody().StableMarshal(buf), nil } // SignedDataSize returns binary size of the signed data. diff --git a/pkg/services/control/types.go b/pkg/services/control/types.go index 9f3c374e..9c4fc09c 100644 --- a/pkg/services/control/types.go +++ b/pkg/services/control/types.go @@ -52,48 +52,26 @@ const ( // // If buffer length is less than x.StableSize(), new buffer is allocated. // -// Returns any error encountered which did not allow writing the data completely. -// Otherwise, returns the buffer in which the data is written. +// Returns the buffer in which the data is written. // // Structures with the same field values have the same binary format. -func (x *NodeInfo_Attribute) StableMarshal(buf []byte) ([]byte, error) { +func (x *NodeInfo_Attribute) StableMarshal(buf []byte) []byte { if x == nil { - return []byte{}, nil + return []byte{} } if sz := x.StableSize(); len(buf) < sz { buf = make([]byte, sz) } - var ( - offset, n int - err error - ) - - n, err = proto.StringMarshal(nodeAttrKeyFNum, buf[offset:], x.Key) - if err != nil { - return nil, err - } - - offset += n - - n, err = proto.StringMarshal(nodeAttrValueFNum, buf[offset:], x.Value) - if err != nil { - return nil, err - } - - offset += n + offset := proto.StringMarshal(nodeAttrKeyFNum, buf, x.Key) + offset += proto.StringMarshal(nodeAttrValueFNum, buf[offset:], x.Value) for i := range x.Parents { - n, err = proto.StringMarshal(nodeAttrParentsFNum, buf[offset:], x.Parents[i]) - if err != nil { - return nil, err - } - - offset += n + offset += proto.StringMarshal(nodeAttrParentsFNum, buf[offset:], x.Parents[i]) } - return buf, nil + return buf } // StableSize returns binary size of node attribute @@ -159,53 +137,28 @@ const ( // // If buffer length is less than x.StableSize(), new buffer is allocated. // -// Returns any error encountered which did not allow writing the data completely. -// Otherwise, returns the buffer in which the data is written. +// Returns the buffer in which the data is written. // // Structures with the same field values have the same binary format. -func (x *NodeInfo) StableMarshal(buf []byte) ([]byte, error) { +func (x *NodeInfo) StableMarshal(buf []byte) []byte { if x == nil { - return []byte{}, nil + return []byte{} } if sz := x.StableSize(); len(buf) < sz { buf = make([]byte, sz) } - var ( - offset, n int - err error - ) - - n, err = proto.BytesMarshal(nodePubKeyFNum, buf[offset:], x.PublicKey) - if err != nil { - return nil, err - } - - offset += n - - n, err = proto.RepeatedStringMarshal(nodeAddrFNum, buf[offset:], x.Addresses) - if err != nil { - return nil, err - } - - offset += n + offset := proto.BytesMarshal(nodePubKeyFNum, buf, x.PublicKey) + offset += proto.RepeatedStringMarshal(nodeAddrFNum, buf[offset:], x.Addresses) for i := range x.Attributes { - n, err = proto.NestedStructureMarshal(nodeAttrsFNum, buf[offset:], x.Attributes[i]) - if err != nil { - return nil, err - } - - offset += n + offset += proto.NestedStructureMarshal(nodeAttrsFNum, buf[offset:], x.Attributes[i]) } - _, err = proto.EnumMarshal(nodeStateFNum, buf[offset:], int32(x.State)) - if err != nil { - return nil, err - } + proto.EnumMarshal(nodeStateFNum, buf[offset:], int32(x.State)) - return buf, nil + return buf } // StableSize returns binary size of node information @@ -255,41 +208,25 @@ const ( // // If buffer length is less than x.StableSize(), new buffer is allocated. // -// Returns any error encountered which did not allow writing the data completely. -// Otherwise, returns the buffer in which the data is written. +// Returns the buffer in which the data is written. // // Structures with the same field values have the same binary format. -func (x *Netmap) StableMarshal(buf []byte) ([]byte, error) { +func (x *Netmap) StableMarshal(buf []byte) []byte { if x == nil { - return []byte{}, nil + return []byte{} } if sz := x.StableSize(); len(buf) < sz { buf = make([]byte, sz) } - var ( - offset, n int - err error - ) - - n, err = proto.UInt64Marshal(netmapEpochFNum, buf[offset:], x.Epoch) - if err != nil { - return nil, err - } - - offset += n + offset := proto.UInt64Marshal(netmapEpochFNum, buf, x.Epoch) for i := range x.Nodes { - n, err = proto.NestedStructureMarshal(netmapNodesFNum, buf[offset:], x.Nodes[i]) - if err != nil { - return nil, err - } - - offset += n + offset += proto.NestedStructureMarshal(netmapNodesFNum, buf[offset:], x.Nodes[i]) } - return buf, nil + return buf } // StableSize returns binary size of netmap in protobuf binary format. @@ -383,63 +320,24 @@ func (x *ShardInfo) StableSize() int { // // If buffer length is less than x.StableSize(), new buffer is allocated. // -// Returns any error encountered which did not allow writing the data completely. -// Otherwise, returns the buffer in which the data is written. +// Returns the buffer in which the data is written. // // Structures with the same field values have the same binary format. -func (x *ShardInfo) StableMarshal(buf []byte) ([]byte, error) { +func (x *ShardInfo) StableMarshal(buf []byte) []byte { if x == nil { - return []byte{}, nil + return []byte{} } if sz := x.StableSize(); len(buf) < sz { buf = make([]byte, sz) } - var ( - offset, n int - err error - ) + offset := proto.BytesMarshal(shardInfoIDFNum, buf, x.Shard_ID) + offset += proto.StringMarshal(shardInfoMetabaseFNum, buf[offset:], x.MetabasePath) + offset += proto.StringMarshal(shardInfoBlobstorFNum, buf[offset:], x.BlobstorPath) + offset += proto.StringMarshal(shardInfoWriteCacheFNum, buf[offset:], x.WritecachePath) + offset += proto.EnumMarshal(shardInfoModeFNum, buf[offset:], int32(x.Mode)) + proto.EnumMarshal(shardInfoErrorCountFNum, buf[offset:], int32(x.ErrorCount)) - n, err = proto.BytesMarshal(shardInfoIDFNum, buf[offset:], x.Shard_ID) - if err != nil { - return nil, err - } - - offset += n - - n, err = proto.StringMarshal(shardInfoMetabaseFNum, buf[offset:], x.MetabasePath) - if err != nil { - return nil, err - } - - offset += n - - n, err = proto.StringMarshal(shardInfoBlobstorFNum, buf[offset:], x.BlobstorPath) - if err != nil { - return nil, err - } - - offset += n - - n, err = proto.StringMarshal(shardInfoWriteCacheFNum, buf[offset:], x.WritecachePath) - if err != nil { - return nil, err - } - - offset += n - - n, err = proto.EnumMarshal(shardInfoModeFNum, buf[offset:], int32(x.Mode)) - if err != nil { - return nil, err - } - - offset += n - - _, err = proto.EnumMarshal(shardInfoErrorCountFNum, buf[offset:], int32(x.ErrorCount)) - if err != nil { - return nil, err - } - - return buf, nil + return buf } diff --git a/pkg/services/notificator/deps.go b/pkg/services/notificator/deps.go index 2f7af093..780a89b5 100644 --- a/pkg/services/notificator/deps.go +++ b/pkg/services/notificator/deps.go @@ -1,12 +1,14 @@ package notificator -import objectSDKAddress "github.com/nspcc-dev/neofs-sdk-go/object/address" +import ( + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" +) // NotificationSource is a source of object notifications. type NotificationSource interface { // Iterate must iterate over all notifications for the // provided epoch and call handler for all of them. - Iterate(epoch uint64, handler func(topic string, addr *objectSDKAddress.Address)) + Iterate(epoch uint64, handler func(topic string, addr oid.Address)) } // NotificationWriter notifies all the subscribers @@ -14,5 +16,5 @@ type NotificationSource interface { type NotificationWriter interface { // Notify must notify about an event generated // from an object with a specific topic. - Notify(topic string, address *objectSDKAddress.Address) + Notify(topic string, address oid.Address) } diff --git a/pkg/services/notificator/nats/service.go b/pkg/services/notificator/nats/service.go index 841b96c4..a273217e 100644 --- a/pkg/services/notificator/nats/service.go +++ b/pkg/services/notificator/nats/service.go @@ -7,7 +7,7 @@ import ( "sync" "github.com/nats-io/nats.go" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.uber.org/zap" ) @@ -44,19 +44,14 @@ var errConnIsClosed = errors.New("connection to the server is closed") // Returns error only if: // 1. underlying connection was closed and has not been established again; // 2. NATS server could not respond that it has saved the message. -func (n *Writer) Notify(topic string, address *addressSDK.Address) error { +func (n *Writer) Notify(topic string, address oid.Address) error { if !n.nc.IsConnected() { return errConnIsClosed } - id, ok := address.ObjectID() - if !ok { - return errors.New("missing object ID in object address") - } - // use first 4 byte of the encoded string as // message ID for the 'exactly once' delivery - messageID := id.EncodeToString()[:4] + messageID := address.Object().EncodeToString()[:4] // check if the stream was previously created n.m.RLock() @@ -76,7 +71,7 @@ func (n *Writer) Notify(topic string, address *addressSDK.Address) error { n.m.Unlock() } - _, err := n.js.Publish(topic, []byte(address.String()), nats.MsgId(messageID)) + _, err := n.js.Publish(topic, []byte(address.EncodeToString()), nats.MsgId(messageID)) if err != nil { return err } diff --git a/pkg/services/notificator/service.go b/pkg/services/notificator/service.go index 6994f8b3..e60af0f7 100644 --- a/pkg/services/notificator/service.go +++ b/pkg/services/notificator/service.go @@ -3,7 +3,7 @@ package notificator import ( "fmt" - objectSDKAddress "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.uber.org/zap" ) @@ -74,7 +74,7 @@ func (n *Notificator) ProcessEpoch(epoch uint64) { logger := n.l.With(zap.Uint64("epoch", epoch)) logger.Debug("notificator: start processing object notifications") - n.ns.Iterate(epoch, func(topic string, addr *objectSDKAddress.Address) { + n.ns.Iterate(epoch, func(topic string, addr oid.Address) { n.l.Debug("notificator: processing object notification", zap.String("topic", topic), zap.Stringer("address", addr), diff --git a/pkg/services/object/acl/acl.go b/pkg/services/object/acl/acl.go index 90863d81..547ed287 100644 --- a/pkg/services/object/acl/acl.go +++ b/pkg/services/object/acl/acl.go @@ -111,7 +111,7 @@ func (c *Checker) CheckBasicACL(info v2.RequestInfo) bool { } // StickyBitCheck validates owner field in the request if sticky bit is enabled. -func (c *Checker) StickyBitCheck(info v2.RequestInfo, owner *user.ID) bool { +func (c *Checker) StickyBitCheck(info v2.RequestInfo, owner user.ID) bool { // According to NeoFS specification sticky bit has no effect on system nodes // for correct intra-container work with objects (in particular, replication). if info.RequestRole() == eaclSDK.RoleSystem { @@ -122,7 +122,7 @@ func (c *Checker) StickyBitCheck(info v2.RequestInfo, owner *user.ID) bool { return true } - if owner == nil || len(info.SenderKey()) == 0 { + if len(info.SenderKey()) == 0 { return false } @@ -143,11 +143,11 @@ func (c *Checker) CheckEACL(msg interface{}, reqInfo v2.RequestInfo) error { } var table eaclSDK.Table - cid := reqInfo.ContainerID() + cnr := reqInfo.ContainerID() bearerTok := reqInfo.Bearer() if bearerTok == nil { - pTable, err := c.eaclSrc.GetEACL(&cid) + pTable, err := c.eaclSrc.GetEACL(cnr) if err != nil { if errors.Is(err, container.ErrEACLNotFound) { return nil @@ -169,7 +169,7 @@ func (c *Checker) CheckEACL(msg interface{}, reqInfo v2.RequestInfo) error { hdrSrcOpts = append(hdrSrcOpts, eaclV2.WithLocalObjectStorage(c.localStorage), - eaclV2.WithCID(cid), + eaclV2.WithCID(cnr), eaclV2.WithOID(reqInfo.ObjectID()), ) @@ -192,7 +192,7 @@ func (c *Checker) CheckEACL(msg interface{}, reqInfo v2.RequestInfo) error { action := c.validator.CalculateAction(new(eaclSDK.ValidationUnit). WithRole(reqInfo.RequestRole()). WithOperation(reqInfo.Operation()). - WithContainerID(&cid). + WithContainerID(&cnr). WithSenderKey(reqInfo.SenderKey()). WithHeaderSource(hdrSrc). WithEACLTable(&table), @@ -209,9 +209,6 @@ func (c *Checker) CheckEACL(msg interface{}, reqInfo v2.RequestInfo) error { // require fetching current epoch to check lifetime. func isValidBearer(reqInfo v2.RequestInfo, st netmap.State) error { ownerCnr := reqInfo.ContainerOwner() - if ownerCnr == nil { - return errors.New("missing container owner") - } token := reqInfo.Bearer() @@ -236,7 +233,7 @@ func isValidBearer(reqInfo v2.RequestInfo, st netmap.State) error { panic("unexpected false return from Issuer method on signed bearer token") } - if !issuer.Equals(*ownerCnr) { + if !issuer.Equals(ownerCnr) { // TODO: #767 in this case we can issue all owner keys from neofs.id and check once again return errBearerNotSignedByOwner } @@ -245,7 +242,7 @@ func isValidBearer(reqInfo v2.RequestInfo, st netmap.State) error { tokenOwner := token.OwnerID() requestSenderKey := unmarshalPublicKey(reqInfo.SenderKey()) - if !isOwnerFromKey(&tokenOwner, requestSenderKey) { + if !isOwnerFromKey(tokenOwner, requestSenderKey) { // TODO: #767 in this case we can issue all owner keys from neofs.id and check once again return errBearerInvalidOwner } @@ -262,8 +259,8 @@ func isValidLifetime(t *bearerSDK.Token, epoch uint64) bool { return epoch >= t.NotBefore() && epoch <= t.Expiration() } -func isOwnerFromKey(id *user.ID, key *keys.PublicKey) bool { - if id == nil || key == nil { +func isOwnerFromKey(id user.ID, key *keys.PublicKey) bool { + if key == nil { return false } diff --git a/pkg/services/object/acl/acl_test.go b/pkg/services/object/acl/acl_test.go index 409ab008..501226e3 100644 --- a/pkg/services/object/acl/acl_test.go +++ b/pkg/services/object/acl/acl_test.go @@ -5,7 +5,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine" v2 "github.com/nspcc-dev/neofs-node/pkg/services/object/acl/v2" - cidSDK "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" "github.com/nspcc-dev/neofs-sdk-go/user" usertest "github.com/nspcc-dev/neofs-sdk-go/user/test" @@ -14,7 +14,7 @@ import ( type emptyEACLSource struct{} -func (e emptyEACLSource) GetEACL(_ *cidSDK.ID) (*eaclSDK.Table, error) { +func (e emptyEACLSource) GetEACL(_ cid.ID) (*eaclSDK.Table, error) { return nil, nil } @@ -40,11 +40,11 @@ func TestStickyCheck(t *testing.T) { setSticky(&info, true) - require.True(t, checker.StickyBitCheck(info, usertest.ID())) + require.True(t, checker.StickyBitCheck(info, *usertest.ID())) setSticky(&info, false) - require.True(t, checker.StickyBitCheck(info, usertest.ID())) + require.True(t, checker.StickyBitCheck(info, *usertest.ID())) }) t.Run("owner ID and/or public key emptiness", func(t *testing.T) { @@ -65,10 +65,10 @@ func TestStickyCheck(t *testing.T) { info.SetSenderKey(nil) } - var ownerID *user.ID + var ownerID user.ID if withOwner { - ownerID = usertest.ID() + ownerID = *usertest.ID() } require.Equal(t, expected, checker.StickyBitCheck(info, ownerID)) diff --git a/pkg/services/object/acl/eacl/types.go b/pkg/services/object/acl/eacl/types.go index 700428ba..12f47cf9 100644 --- a/pkg/services/object/acl/eacl/types.go +++ b/pkg/services/object/acl/eacl/types.go @@ -15,5 +15,5 @@ type Source interface { // // Must return pkg/core/container.ErrEACLNotFound if requested // eACL table is not in source. - GetEACL(*cid.ID) (*eacl.Table, error) + GetEACL(cid.ID) (*eacl.Table, error) } diff --git a/pkg/services/object/acl/eacl/v2/eacl_test.go b/pkg/services/object/acl/eacl/v2/eacl_test.go index b9c2406a..d99d73ef 100644 --- a/pkg/services/object/acl/eacl/v2/eacl_test.go +++ b/pkg/services/object/acl/eacl/v2/eacl_test.go @@ -6,38 +6,26 @@ import ( "github.com/nspcc-dev/neo-go/pkg/crypto/keys" 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/session" 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" - objecttest "github.com/nspcc-dev/neofs-sdk-go/object/address/test" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" + oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test" "github.com/stretchr/testify/require" ) type testLocalStorage struct { t *testing.T - expAddr *objectSDKAddress.Address + expAddr oid.Address obj *object.Object } -func (s *testLocalStorage) Head(addr *objectSDKAddress.Address) (*object.Object, error) { - cnr1, ok := s.expAddr.ContainerID() - require.True(s.t, ok) - - cnr2, ok := addr.ContainerID() - require.True(s.t, ok) - - require.True(s.t, cnr1.Equals(cnr2)) - - id1, ok := s.expAddr.ObjectID() - require.True(s.t, ok) - - id2, ok := addr.ObjectID() - require.True(s.t, ok) - - require.True(s.t, id1.Equals(id2)) +func (s *testLocalStorage) Head(addr oid.Address) (*object.Object, error) { + require.True(s.t, addr.Container().Equals(s.expAddr.Container())) + require.True(s.t, addr.Object().Equals(s.expAddr.Object())) return s.obj, nil } @@ -62,8 +50,12 @@ func TestHeadRequest(t *testing.T) { body := new(objectV2.HeadRequestBody) req.SetBody(body) - addr := objecttest.Address() - body.SetAddress(addr.ToV2()) + addr := oidtest.Address() + + var addrV2 refs.Address + addr.WriteToV2(&addrV2) + + body.SetAddress(&addrV2) xKey := "x-key" xVal := "x-val" @@ -103,20 +95,20 @@ func TestHeadRequest(t *testing.T) { obj: obj, } - cid, _ := addr.ContainerID() - oid, _ := addr.ObjectID() + id := addr.Object() newSource := func(t *testing.T) eaclSDK.TypedHeaderSource { hdrSrc, err := NewMessageHeaderSource( WithObjectStorage(lStorage), WithServiceRequest(req), - WithCID(cid), - WithOID(&oid)) + WithCID(addr.Container()), + WithOID(&id)) require.NoError(t, err) return hdrSrc } - cnr, _ := addr.ContainerID() + cnr := addr.Container() + unit := new(eaclSDK.ValidationUnit). WithContainerID(&cnr). WithOperation(eaclSDK.OperationHead). diff --git a/pkg/services/object/acl/eacl/v2/headers.go b/pkg/services/object/acl/eacl/v2/headers.go index 51eb109f..3cf51e93 100644 --- a/pkg/services/object/acl/eacl/v2/headers.go +++ b/pkg/services/object/acl/eacl/v2/headers.go @@ -8,12 +8,11 @@ import ( objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object" refsV2 "github.com/nspcc-dev/neofs-api-go/v2/refs" "github.com/nspcc-dev/neofs-api-go/v2/session" - cidSDK "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" "github.com/nspcc-dev/neofs-sdk-go/object" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/nspcc-dev/neofs-sdk-go/user" ) @@ -24,12 +23,12 @@ type cfg struct { msg xHeaderSource - cid cidSDK.ID - oid *oidSDK.ID + cnr cid.ID + obj *oid.ID } type ObjectStorage interface { - Head(*addressSDK.Address) (*object.Object, error) + Head(oid.Address) (*object.Object, error) } type Request interface { @@ -109,31 +108,31 @@ func (h *cfg) objectHeaders() ([]eaclSDK.Header, error) { case *objectV2.GetRequest, *objectV2.HeadRequest: - if h.oid == nil { + if h.obj == nil { return nil, errMissingOID } - return h.localObjectHeaders(h.cid, h.oid) + return h.localObjectHeaders(h.cnr, h.obj) case *objectV2.GetRangeRequest, *objectV2.GetRangeHashRequest, *objectV2.DeleteRequest: - if h.oid == nil { + if h.obj == nil { return nil, errMissingOID } - return addressHeaders(h.cid, h.oid), nil + return addressHeaders(h.cnr, h.obj), nil case *objectV2.PutRequest: if v, ok := req.GetBody().GetObjectPart().(*objectV2.PutObjectPartInit); ok { oV2 := new(objectV2.Object) oV2.SetObjectID(v.GetObjectID()) oV2.SetHeader(v.GetHeader()) - return headersFromObject(object.NewFromV2(oV2), h.cid, h.oid), nil + return headersFromObject(object.NewFromV2(oV2), h.cnr, h.obj), nil } case *objectV2.SearchRequest: cnrV2 := req.GetBody().GetContainerID() - var cnr cidSDK.ID + var cnr cid.ID if cnrV2 != nil { if err := cnr.ReadFromV2(*cnrV2); err != nil { @@ -146,7 +145,7 @@ func (h *cfg) objectHeaders() ([]eaclSDK.Header, error) { case responseXHeaderSource: switch resp := m.resp.(type) { default: - hs, _ := h.localObjectHeaders(h.cid, h.oid) + hs, _ := h.localObjectHeaders(h.cnr, h.obj) return hs, nil case *objectV2.GetResponse: if v, ok := resp.GetBody().GetObjectPart().(*objectV2.GetObjectPartInit); ok { @@ -154,7 +153,7 @@ func (h *cfg) objectHeaders() ([]eaclSDK.Header, error) { oV2.SetObjectID(v.GetObjectID()) oV2.SetHeader(v.GetHeader()) - return headersFromObject(object.NewFromV2(oV2), h.cid, h.oid), nil + return headersFromObject(object.NewFromV2(oV2), h.cnr, h.obj), nil } case *objectV2.HeadResponse: oV2 := new(objectV2.Object) @@ -166,7 +165,7 @@ func (h *cfg) objectHeaders() ([]eaclSDK.Header, error) { hdr = new(objectV2.Header) var idV2 refsV2.ContainerID - h.cid.WriteToV2(&idV2) + h.cnr.WriteToV2(&idV2) hdr.SetContainerID(&idV2) hdr.SetVersion(v.GetVersion()) @@ -180,56 +179,56 @@ func (h *cfg) objectHeaders() ([]eaclSDK.Header, error) { oV2.SetHeader(hdr) - return headersFromObject(object.NewFromV2(oV2), h.cid, h.oid), nil + return headersFromObject(object.NewFromV2(oV2), h.cnr, h.obj), nil } } return nil, nil } -func (h *cfg) localObjectHeaders(cid cidSDK.ID, oid *oidSDK.ID) ([]eaclSDK.Header, error) { +func (h *cfg) localObjectHeaders(cnr cid.ID, idObj *oid.ID) ([]eaclSDK.Header, error) { var obj *objectSDK.Object var err error - if oid != nil { - var addr addressSDK.Address - addr.SetContainerID(cid) - addr.SetObjectID(*oid) + if idObj != nil { + var addr oid.Address + addr.SetContainer(cnr) + addr.SetObject(*idObj) - obj, err = h.storage.Head(&addr) + obj, err = h.storage.Head(addr) if err == nil { - return headersFromObject(obj, cid, oid), nil + return headersFromObject(obj, cnr, idObj), nil } } // Still parse addressHeaders, because the errors is ignored in some places. - return addressHeaders(cid, oid), err + return addressHeaders(cnr, idObj), err } -func cidHeader(idCnr cidSDK.ID) sysObjHdr { +func cidHeader(idCnr cid.ID) sysObjHdr { return sysObjHdr{ k: acl.FilterObjectContainerID, v: idCnr.EncodeToString(), } } -func oidHeader(oid oidSDK.ID) sysObjHdr { +func oidHeader(obj oid.ID) sysObjHdr { return sysObjHdr{ k: acl.FilterObjectID, - v: oid.EncodeToString(), + v: obj.EncodeToString(), } } func ownerIDHeader(ownerID user.ID) sysObjHdr { return sysObjHdr{ k: acl.FilterObjectOwnerID, - v: ownerID.String(), + v: ownerID.EncodeToString(), } } -func addressHeaders(cid cidSDK.ID, oid *oidSDK.ID) []eaclSDK.Header { +func addressHeaders(cnr cid.ID, oid *oid.ID) []eaclSDK.Header { hh := make([]eaclSDK.Header, 0, 2) - hh = append(hh, cidHeader(cid)) + hh = append(hh, cidHeader(cnr)) if oid != nil { hh = append(hh, oidHeader(*oid)) diff --git a/pkg/services/object/acl/eacl/v2/localstore.go b/pkg/services/object/acl/eacl/v2/localstore.go index ee237453..74192c58 100644 --- a/pkg/services/object/acl/eacl/v2/localstore.go +++ b/pkg/services/object/acl/eacl/v2/localstore.go @@ -5,14 +5,14 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" - objectSDKAddress "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) type localStorage struct { ls *engine.StorageEngine } -func (s *localStorage) Head(addr *objectSDKAddress.Address) (*objectSDK.Object, error) { +func (s *localStorage) Head(addr oid.Address) (*objectSDK.Object, error) { if s.ls == nil { return nil, io.ErrUnexpectedEOF } diff --git a/pkg/services/object/acl/eacl/v2/object.go b/pkg/services/object/acl/eacl/v2/object.go index 1c3e4ee2..4a1e043e 100644 --- a/pkg/services/object/acl/eacl/v2/object.go +++ b/pkg/services/object/acl/eacl/v2/object.go @@ -4,10 +4,10 @@ import ( "strconv" "github.com/nspcc-dev/neofs-api-go/v2/acl" - cidSDK "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" "github.com/nspcc-dev/neofs-sdk-go/object" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) type sysObjHdr struct { @@ -26,7 +26,7 @@ func u64Value(v uint64) string { return strconv.FormatUint(v, 10) } -func headersFromObject(obj *object.Object, cid cidSDK.ID, oid *oidSDK.ID) []eaclSDK.Header { +func headersFromObject(obj *object.Object, cnr cid.ID, oid *oid.ID) []eaclSDK.Header { var count int for obj := obj; obj != nil; obj = obj.Parent() { count += 9 + len(obj.Attributes()) @@ -35,7 +35,7 @@ func headersFromObject(obj *object.Object, cid cidSDK.ID, oid *oidSDK.ID) []eacl res := make([]eaclSDK.Header, 0, count) for ; obj != nil; obj = obj.Parent() { res = append(res, - cidHeader(cid), + cidHeader(cnr), // creation epoch sysObjHdr{ k: acl.FilterObjectCreationEpoch, diff --git a/pkg/services/object/acl/eacl/v2/opts.go b/pkg/services/object/acl/eacl/v2/opts.go index 6eaf84b0..4a653757 100644 --- a/pkg/services/object/acl/eacl/v2/opts.go +++ b/pkg/services/object/acl/eacl/v2/opts.go @@ -2,8 +2,8 @@ package v2 import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine" - cidSDK "github.com/nspcc-dev/neofs-sdk-go/container/id" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + cid "github.com/nspcc-dev/neofs-sdk-go/container/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) func WithObjectStorage(v ObjectStorage) Option { @@ -37,14 +37,14 @@ func WithServiceResponse(resp Response, req Request) Option { } } -func WithCID(v cidSDK.ID) Option { +func WithCID(v cid.ID) Option { return func(c *cfg) { - c.cid = v + c.cnr = v } } -func WithOID(v *oidSDK.ID) Option { +func WithOID(v *oid.ID) Option { return func(c *cfg) { - c.oid = v + c.obj = v } } diff --git a/pkg/services/object/acl/v2/classifier.go b/pkg/services/object/acl/v2/classifier.go index 809779ab..d5ece10a 100644 --- a/pkg/services/object/acl/v2/classifier.go +++ b/pkg/services/object/acl/v2/classifier.go @@ -7,7 +7,7 @@ import ( core "github.com/nspcc-dev/neofs-node/pkg/core/netmap" "github.com/nspcc-dev/neofs-sdk-go/container" - cidSDK "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" "github.com/nspcc-dev/neofs-sdk-go/netmap" "go.uber.org/zap" @@ -27,7 +27,7 @@ type classifyResult struct { func (c senderClassifier) classify( req MetaWithToken, - idCnr cidSDK.ID, + idCnr cid.ID, cnr *container.Container) (res *classifyResult, err error) { ownerCnr := cnr.OwnerID() if ownerCnr == nil { diff --git a/pkg/services/object/acl/v2/request.go b/pkg/services/object/acl/v2/request.go index 3f8cce75..a136c9d5 100644 --- a/pkg/services/object/acl/v2/request.go +++ b/pkg/services/object/acl/v2/request.go @@ -7,9 +7,9 @@ import ( "github.com/nspcc-dev/neo-go/pkg/crypto/keys" sessionV2 "github.com/nspcc-dev/neofs-api-go/v2/session" "github.com/nspcc-dev/neofs-sdk-go/bearer" - containerIDSDK "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" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" sessionSDK "github.com/nspcc-dev/neofs-sdk-go/session" "github.com/nspcc-dev/neofs-sdk-go/user" ) @@ -21,13 +21,13 @@ type RequestInfo struct { requestRole eaclSDK.Role isInnerRing bool operation eaclSDK.Operation // put, get, head, etc. - cnrOwner *user.ID // container owner + cnrOwner user.ID // container owner - idCnr containerIDSDK.ID + idCnr cid.ID // optional for some request // e.g. Put, Search - oid *oidSDK.ID + obj *oid.ID senderKey []byte @@ -54,17 +54,17 @@ func (r RequestInfo) Request() interface{} { } // ContainerOwner returns owner if the container. -func (r RequestInfo) ContainerOwner() *user.ID { +func (r RequestInfo) ContainerOwner() user.ID { return r.cnrOwner } // ObjectID return object ID. -func (r RequestInfo) ObjectID() *oidSDK.ID { - return r.oid +func (r RequestInfo) ObjectID() *oid.ID { + return r.obj } // ContainerID return container ID. -func (r RequestInfo) ContainerID() containerIDSDK.ID { +func (r RequestInfo) ContainerID() cid.ID { return r.idCnr } diff --git a/pkg/services/object/acl/v2/service.go b/pkg/services/object/acl/v2/service.go index 36c6073e..55756f14 100644 --- a/pkg/services/object/acl/v2/service.go +++ b/pkg/services/object/acl/v2/service.go @@ -9,7 +9,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/core/container" "github.com/nspcc-dev/neofs-node/pkg/core/netmap" "github.com/nspcc-dev/neofs-node/pkg/services/object" - cidSDK "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" sessionSDK "github.com/nspcc-dev/neofs-sdk-go/session" "github.com/nspcc-dev/neofs-sdk-go/user" @@ -108,7 +108,7 @@ func New(opts ...Option) Service { // Get implements ServiceServer interface, makes ACL checks and calls // next Get method in the ServiceServer pipeline. func (b Service) Get(request *objectV2.GetRequest, stream object.GetObjectStream) error { - cid, err := getContainerIDFromRequest(request) + cnr, err := getContainerIDFromRequest(request) if err != nil { return err } @@ -125,12 +125,12 @@ func (b Service) Get(request *objectV2.GetRequest, stream object.GetObjectStream src: request, } - reqInfo, err := b.findRequestInfo(req, cid, eaclSDK.OperationGet) + reqInfo, err := b.findRequestInfo(req, cnr, eaclSDK.OperationGet) if err != nil { return err } - reqInfo.oid, err = getObjectIDFromRequestBody(request.GetBody()) + reqInfo.obj, err = getObjectIDFromRequestBody(request.GetBody()) if err != nil { return err } @@ -162,7 +162,7 @@ func (b Service) Put(ctx context.Context) (object.PutObjectStream, error) { func (b Service) Head( ctx context.Context, request *objectV2.HeadRequest) (*objectV2.HeadResponse, error) { - cid, err := getContainerIDFromRequest(request) + cnr, err := getContainerIDFromRequest(request) if err != nil { return nil, err } @@ -179,12 +179,12 @@ func (b Service) Head( src: request, } - reqInfo, err := b.findRequestInfo(req, cid, eaclSDK.OperationHead) + reqInfo, err := b.findRequestInfo(req, cnr, eaclSDK.OperationHead) if err != nil { return nil, err } - reqInfo.oid, err = getObjectIDFromRequestBody(request.GetBody()) + reqInfo.obj, err = getObjectIDFromRequestBody(request.GetBody()) if err != nil { return nil, err } @@ -230,7 +230,7 @@ func (b Service) Search(request *objectV2.SearchRequest, stream object.SearchStr return err } - reqInfo.oid, err = getObjectIDFromRequestBody(request.GetBody()) + reqInfo.obj, err = getObjectIDFromRequestBody(request.GetBody()) if err != nil { return err } @@ -251,7 +251,7 @@ func (b Service) Search(request *objectV2.SearchRequest, stream object.SearchStr func (b Service) Delete( ctx context.Context, request *objectV2.DeleteRequest) (*objectV2.DeleteResponse, error) { - cid, err := getContainerIDFromRequest(request) + cnr, err := getContainerIDFromRequest(request) if err != nil { return nil, err } @@ -268,12 +268,12 @@ func (b Service) Delete( src: request, } - reqInfo, err := b.findRequestInfo(req, cid, eaclSDK.OperationDelete) + reqInfo, err := b.findRequestInfo(req, cnr, eaclSDK.OperationDelete) if err != nil { return nil, err } - reqInfo.oid, err = getObjectIDFromRequestBody(request.GetBody()) + reqInfo.obj, err = getObjectIDFromRequestBody(request.GetBody()) if err != nil { return nil, err } @@ -290,7 +290,7 @@ func (b Service) Delete( } func (b Service) GetRange(request *objectV2.GetRangeRequest, stream object.GetObjectRangeStream) error { - cid, err := getContainerIDFromRequest(request) + cnr, err := getContainerIDFromRequest(request) if err != nil { return err } @@ -307,12 +307,12 @@ func (b Service) GetRange(request *objectV2.GetRangeRequest, stream object.GetOb src: request, } - reqInfo, err := b.findRequestInfo(req, cid, eaclSDK.OperationRange) + reqInfo, err := b.findRequestInfo(req, cnr, eaclSDK.OperationRange) if err != nil { return err } - reqInfo.oid, err = getObjectIDFromRequestBody(request.GetBody()) + reqInfo.obj, err = getObjectIDFromRequestBody(request.GetBody()) if err != nil { return err } @@ -334,7 +334,7 @@ func (b Service) GetRange(request *objectV2.GetRangeRequest, stream object.GetOb func (b Service) GetRangeHash( ctx context.Context, request *objectV2.GetRangeHashRequest) (*objectV2.GetRangeHashResponse, error) { - cid, err := getContainerIDFromRequest(request) + cnr, err := getContainerIDFromRequest(request) if err != nil { return nil, err } @@ -351,12 +351,12 @@ func (b Service) GetRangeHash( src: request, } - reqInfo, err := b.findRequestInfo(req, cid, eaclSDK.OperationRangeHash) + reqInfo, err := b.findRequestInfo(req, cnr, eaclSDK.OperationRangeHash) if err != nil { return nil, err } - reqInfo.oid, err = getObjectIDFromRequestBody(request.GetBody()) + reqInfo.obj, err = getObjectIDFromRequestBody(request.GetBody()) if err != nil { return nil, err } @@ -380,7 +380,7 @@ func (p putStreamBasicChecker) Send(request *objectV2.PutRequest) error { part := body.GetObjectPart() if part, ok := part.(*objectV2.PutObjectPartInit); ok { - cid, err := getContainerIDFromRequest(request) + cnr, err := getContainerIDFromRequest(request) if err != nil { return err } @@ -415,19 +415,19 @@ func (p putStreamBasicChecker) Send(request *objectV2.PutRequest) error { src: request, } - reqInfo, err := p.source.findRequestInfo(req, cid, eaclSDK.OperationPut) + reqInfo, err := p.source.findRequestInfo(req, cnr, eaclSDK.OperationPut) if err != nil { return err } - reqInfo.oid, err = getObjectIDFromRequestBody(part) + reqInfo.obj, err = getObjectIDFromRequestBody(part) if err != nil { return err } useObjectIDFromSession(&reqInfo, sTok) - if !p.source.checker.CheckBasicACL(reqInfo) || !p.source.checker.StickyBitCheck(reqInfo, &idOwner) { + if !p.source.checker.CheckBasicACL(reqInfo) || !p.source.checker.StickyBitCheck(reqInfo, idOwner) { return basicACLErr(reqInfo) } else if err := p.source.checker.CheckEACL(request, reqInfo); err != nil { return eACLErr(reqInfo, err) @@ -467,11 +467,8 @@ func (g *searchStreamBasicChecker) Send(resp *objectV2.SearchResponse) error { return g.SearchStream.Send(resp) } -func (b Service) findRequestInfo( - req MetaWithToken, - cid cidSDK.ID, - op eaclSDK.Operation) (info RequestInfo, err error) { - cnr, err := b.containers.Get(&cid) // fetch actual container +func (b Service) findRequestInfo(req MetaWithToken, idCnr cid.ID, op eaclSDK.Operation) (info RequestInfo, err error) { + cnr, err := b.containers.Get(idCnr) // fetch actual container if err != nil { return info, err } else if cnr.OwnerID() == nil { @@ -494,7 +491,7 @@ func (b Service) findRequestInfo( } // find request role and key - res, err := b.c.classify(req, cid, cnr) + res, err := b.c.classify(req, idCnr, cnr) if err != nil { return info, err } @@ -507,8 +504,8 @@ func (b Service) findRequestInfo( info.requestRole = res.role info.isInnerRing = res.isIR info.operation = op - info.cnrOwner = cnr.OwnerID() - info.idCnr = cid + info.cnrOwner = *cnr.OwnerID() + info.idCnr = idCnr // it is assumed that at the moment the key will be valid, // otherwise the request would not pass validation diff --git a/pkg/services/object/acl/v2/types.go b/pkg/services/object/acl/v2/types.go index bf92c4ac..392a72b1 100644 --- a/pkg/services/object/acl/v2/types.go +++ b/pkg/services/object/acl/v2/types.go @@ -16,7 +16,7 @@ type ACLChecker interface { // StickyBitCheck must return true only if sticky bit // is disabled or enabled but request contains correct // owner field. - StickyBitCheck(RequestInfo, *user.ID) bool + StickyBitCheck(RequestInfo, user.ID) bool } // InnerRingFetcher is an interface that must provide diff --git a/pkg/services/object/acl/v2/util.go b/pkg/services/object/acl/v2/util.go index d679a394..31d047e4 100644 --- a/pkg/services/object/acl/v2/util.go +++ b/pkg/services/object/acl/v2/util.go @@ -11,18 +11,18 @@ import ( refsV2 "github.com/nspcc-dev/neofs-api-go/v2/refs" sessionV2 "github.com/nspcc-dev/neofs-api-go/v2/session" "github.com/nspcc-dev/neofs-sdk-go/bearer" - containerIDSDK "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" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" sessionSDK "github.com/nspcc-dev/neofs-sdk-go/session" "github.com/nspcc-dev/neofs-sdk-go/user" ) var errMissingContainerID = errors.New("missing container ID") -func getContainerIDFromRequest(req interface{}) (containerIDSDK.ID, error) { +func getContainerIDFromRequest(req interface{}) (cid.ID, error) { var idV2 *refsV2.ContainerID - var id containerIDSDK.ID + var id cid.ID switch v := req.(type) { case *objectV2.GetRequest: @@ -30,7 +30,7 @@ func getContainerIDFromRequest(req interface{}) (containerIDSDK.ID, error) { case *objectV2.PutRequest: part, ok := v.GetBody().GetObjectPart().(*objectV2.PutObjectPartInit) if !ok { - return containerIDSDK.ID{}, errors.New("can't get container ID in chunk") + return cid.ID{}, errors.New("can't get container ID in chunk") } idV2 = part.GetHeader().GetContainerID() @@ -45,11 +45,11 @@ func getContainerIDFromRequest(req interface{}) (containerIDSDK.ID, error) { case *objectV2.GetRangeHashRequest: idV2 = v.GetBody().GetAddress().GetContainerID() default: - return containerIDSDK.ID{}, errors.New("unknown request type") + return cid.ID{}, errors.New("unknown request type") } if idV2 == nil { - return containerIDSDK.ID{}, errMissingContainerID + return cid.ID{}, errMissingContainerID } return id, id.ReadFromV2(*idV2) @@ -95,7 +95,7 @@ func originalSessionToken(header *sessionV2.RequestMetaHeader) (*sessionSDK.Obje return &tok, nil } -func getObjectIDFromRequestBody(body interface{}) (*oidSDK.ID, error) { +func getObjectIDFromRequestBody(body interface{}) (*oid.ID, error) { var idV2 *refsV2.ObjectID switch v := body.(type) { @@ -115,7 +115,7 @@ func getObjectIDFromRequestBody(body interface{}) (*oidSDK.ID, error) { return nil, nil } - var id oidSDK.ID + var id oid.ID err := id.ReadFromV2(*idV2) if err != nil { @@ -145,9 +145,9 @@ func useObjectIDFromSession(req *RequestInfo, token *sessionSDK.Object) { return } - req.oid = new(oidSDK.ID) + req.obj = new(oid.ID) - err := req.oid.ReadFromV2(*idV2) + err := req.obj.ReadFromV2(*idV2) if err != nil { panic(fmt.Sprintf("unexpected protocol violation error after correct session token decoding: %v", err)) } @@ -171,7 +171,7 @@ func ownerFromToken(token *sessionSDK.Object) (*user.ID, *keys.PublicKey, error) tokenIssuer := token.Issuer() - if !isOwnerFromKey(&tokenIssuer, tokenIssuerKey) { + if !isOwnerFromKey(tokenIssuer, tokenIssuerKey) { // TODO: #767 in this case we can issue all owner keys from neofs.id and check once again return nil, nil, fmt.Errorf("%w: invalid session token owner", ErrMalformedRequest) } @@ -195,15 +195,15 @@ func unmarshalPublicKey(bs []byte) (*keys.PublicKey, error) { return keys.NewPublicKeyFromBytes(bs, elliptic.P256()) } -func isOwnerFromKey(id *user.ID, key *keys.PublicKey) bool { - if id == nil || key == nil { +func isOwnerFromKey(id user.ID, key *keys.PublicKey) bool { + if key == nil { return false } var id2 user.ID user.IDFromKey(&id2, (ecdsa.PublicKey)(*key)) - return id2.Equals(*id) + return id2.Equals(id) } // assertVerb checks that token verb corresponds to op. diff --git a/pkg/services/object/delete/exec.go b/pkg/services/object/delete/exec.go index ab012ab3..9c1dcb62 100644 --- a/pkg/services/object/delete/exec.go +++ b/pkg/services/object/delete/exec.go @@ -9,8 +9,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/util/logger" 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" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.uber.org/zap" ) @@ -60,27 +59,22 @@ func (exec execCtx) isLocal() bool { return exec.prm.common.LocalOnly() } -func (exec *execCtx) address() *addressSDK.Address { +func (exec *execCtx) address() oid.Address { return exec.prm.addr } -func (exec *execCtx) containerID() *cid.ID { - id, ok := exec.prm.addr.ContainerID() - if ok { - return &id - } - - return nil +func (exec *execCtx) containerID() cid.ID { + return exec.prm.addr.Container() } func (exec *execCtx) commonParameters() *util.CommonPrm { return exec.prm.common } -func (exec *execCtx) newAddress(id *oidSDK.ID) *addressSDK.Address { - a := addressSDK.NewAddress() - a.SetObjectID(*id) - a.SetContainerID(*exec.containerID()) +func (exec *execCtx) newAddress(id oid.ID) oid.Address { + var a oid.Address + a.SetObject(id) + a.SetContainer(exec.containerID()) return a } @@ -129,14 +123,14 @@ func (exec *execCtx) collectMembers() (ok bool) { } func (exec *execCtx) collectChain() bool { - var chain []oidSDK.ID + var chain []oid.ID exec.log.Debug("assembling chain...") for prev, withPrev := exec.splitInfo.LastPart(); withPrev; { chain = append(chain, prev) - p, err := exec.svc.header.previous(exec, &prev) + p, err := exec.svc.header.previous(exec, prev) switch { default: @@ -217,7 +211,7 @@ func (exec *execCtx) supplementBySplitID() bool { } } -func (exec *execCtx) addMembers(incoming []oidSDK.ID) { +func (exec *execCtx) addMembers(incoming []oid.ID) { members := exec.tombstone.Members() for i := range members { @@ -246,7 +240,7 @@ func (exec *execCtx) initTombstoneObject() bool { } exec.tombstoneObj = object.New() - exec.tombstoneObj.SetContainerID(*exec.containerID()) + exec.tombstoneObj.SetContainerID(exec.containerID()) exec.tombstoneObj.SetType(object.TypeTombstone) exec.tombstoneObj.SetPayload(payload) @@ -256,7 +250,8 @@ func (exec *execCtx) initTombstoneObject() bool { exec.tombstoneObj.SetOwnerID(&issuer) } else { // make local node a tombstone object owner - exec.tombstoneObj.SetOwnerID(exec.svc.netInfo.LocalNodeID()) + localUser := exec.svc.netInfo.LocalNodeID() + exec.tombstoneObj.SetOwnerID(&localUser) } var a object.Attribute @@ -286,7 +281,7 @@ func (exec *execCtx) saveTombstone() bool { exec.err = nil exec.prm.tombAddrWriter. - SetAddress(exec.newAddress(id)) + SetAddress(exec.newAddress(*id)) } return true diff --git a/pkg/services/object/delete/local.go b/pkg/services/object/delete/local.go index dbca9c24..5b8f63ac 100644 --- a/pkg/services/object/delete/local.go +++ b/pkg/services/object/delete/local.go @@ -2,7 +2,7 @@ package deletesvc import ( "github.com/nspcc-dev/neofs-sdk-go/object" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.uber.org/zap" ) @@ -32,13 +32,11 @@ func (exec *execCtx) formTombstone() (ok bool) { return false } - id, _ := exec.address().ObjectID() - exec.tombstone = object.NewTombstone() exec.tombstone.SetExpirationEpoch( exec.svc.netInfo.CurrentEpoch() + tsLifetime, ) - exec.addMembers([]oidSDK.ID{id}) + exec.addMembers([]oid.ID{exec.address().Object()}) exec.log.Debug("forming split info...") diff --git a/pkg/services/object/delete/prm.go b/pkg/services/object/delete/prm.go index 849b743f..cdbc3e1d 100644 --- a/pkg/services/object/delete/prm.go +++ b/pkg/services/object/delete/prm.go @@ -2,19 +2,19 @@ package deletesvc import ( "github.com/nspcc-dev/neofs-node/pkg/services/object/util" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) // TombstoneAddressWriter is an interface of tombstone address setter. type TombstoneAddressWriter interface { - SetAddress(*addressSDK.Address) + SetAddress(address oid.Address) } // Prm groups parameters of Delete service call. type Prm struct { common *util.CommonPrm - addr *addressSDK.Address + addr oid.Address tombAddrWriter TombstoneAddressWriter } @@ -25,7 +25,7 @@ func (p *Prm) SetCommonParameters(common *util.CommonPrm) { } // WithAddress sets address of the object to be removed. -func (p *Prm) WithAddress(addr *addressSDK.Address) { +func (p *Prm) WithAddress(addr oid.Address) { p.addr = addr } diff --git a/pkg/services/object/delete/service.go b/pkg/services/object/delete/service.go index 45ebe7fe..a56ad7dc 100644 --- a/pkg/services/object/delete/service.go +++ b/pkg/services/object/delete/service.go @@ -7,7 +7,7 @@ import ( 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-sdk-go/object" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/nspcc-dev/neofs-sdk-go/user" "go.uber.org/zap" ) @@ -30,7 +30,7 @@ type NetworkInfo interface { // Returns user ID of the local storage node. Result must not be nil. // New tombstone objects will have the result as an owner ID if removal is executed w/o a session. - LocalNodeID() *user.ID + LocalNodeID() user.ID } type cfg struct { @@ -40,18 +40,18 @@ type cfg struct { // must return (nil, nil) for PHY objects splitInfo(*execCtx) (*object.SplitInfo, error) - children(*execCtx) ([]oidSDK.ID, error) + children(*execCtx) ([]oid.ID, error) // must return (nil, nil) for 1st object in chain - previous(*execCtx, *oidSDK.ID) (*oidSDK.ID, error) + previous(*execCtx, oid.ID) (*oid.ID, error) } searcher interface { - splitMembers(*execCtx) ([]oidSDK.ID, error) + splitMembers(*execCtx) ([]oid.ID, error) } placer interface { - put(*execCtx) (*oidSDK.ID, error) + put(*execCtx) (*oid.ID, error) } netInfo NetworkInfo diff --git a/pkg/services/object/delete/util.go b/pkg/services/object/delete/util.go index c5984b7e..2d97ddc4 100644 --- a/pkg/services/object/delete/util.go +++ b/pkg/services/object/delete/util.go @@ -7,8 +7,7 @@ import ( putsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/put" searchsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/search" "github.com/nspcc-dev/neofs-sdk-go/object" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) type headSvcWrapper getsvc.Service @@ -18,10 +17,10 @@ type searchSvcWrapper searchsvc.Service type putSvcWrapper putsvc.Service type simpleIDWriter struct { - ids []oidSDK.ID + ids []oid.ID } -func (w *headSvcWrapper) headAddress(exec *execCtx, addr *addressSDK.Address) (*object.Object, error) { +func (w *headSvcWrapper) headAddress(exec *execCtx, addr oid.Address) (*object.Object, error) { wr := getsvc.NewSimpleObjectWriter() p := getsvc.HeadPrm{} @@ -53,10 +52,10 @@ func (w *headSvcWrapper) splitInfo(exec *execCtx) (*object.SplitInfo, error) { } } -func (w *headSvcWrapper) children(exec *execCtx) ([]oidSDK.ID, error) { +func (w *headSvcWrapper) children(exec *execCtx) ([]oid.ID, error) { link, _ := exec.splitInfo.Link() - a := exec.newAddress(&link) + a := exec.newAddress(link) linking, err := w.headAddress(exec, a) if err != nil { @@ -66,7 +65,7 @@ func (w *headSvcWrapper) children(exec *execCtx) ([]oidSDK.ID, error) { return linking.Children(), nil } -func (w *headSvcWrapper) previous(exec *execCtx, id *oidSDK.ID) (*oidSDK.ID, error) { +func (w *headSvcWrapper) previous(exec *execCtx, id oid.ID) (*oid.ID, error) { a := exec.newAddress(id) h, err := w.headAddress(exec, a) @@ -82,7 +81,7 @@ func (w *headSvcWrapper) previous(exec *execCtx, id *oidSDK.ID) (*oidSDK.ID, err return nil, nil } -func (w *searchSvcWrapper) splitMembers(exec *execCtx) ([]oidSDK.ID, error) { +func (w *searchSvcWrapper) splitMembers(exec *execCtx) ([]oid.ID, error) { fs := object.SearchFilters{} fs.AddSplitIDFilter(object.MatchStringEqual, exec.splitInfo.SplitID()) @@ -102,13 +101,13 @@ func (w *searchSvcWrapper) splitMembers(exec *execCtx) ([]oidSDK.ID, error) { return wr.ids, nil } -func (s *simpleIDWriter) WriteIDs(ids []oidSDK.ID) error { +func (s *simpleIDWriter) WriteIDs(ids []oid.ID) error { s.ids = append(s.ids, ids...) return nil } -func (w *putSvcWrapper) put(exec *execCtx) (*oidSDK.ID, error) { +func (w *putSvcWrapper) put(exec *execCtx) (*oid.ID, error) { streamer, err := (*putsvc.Service)(w).Put(exec.context()) if err != nil { return nil, err @@ -135,5 +134,7 @@ func (w *putSvcWrapper) put(exec *execCtx) (*oidSDK.ID, error) { return nil, err } - return r.ObjectID(), nil + id := r.ObjectID() + + return &id, nil } diff --git a/pkg/services/object/delete/v2/util.go b/pkg/services/object/delete/v2/util.go index c446f7f2..bf056450 100644 --- a/pkg/services/object/delete/v2/util.go +++ b/pkg/services/object/delete/v2/util.go @@ -1,10 +1,14 @@ package deletesvc import ( + "errors" + "fmt" + objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object" + "github.com/nspcc-dev/neofs-api-go/v2/refs" deletesvc "github.com/nspcc-dev/neofs-node/pkg/services/object/delete" "github.com/nspcc-dev/neofs-node/pkg/services/object/util" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) type tombstoneBodyWriter struct { @@ -12,6 +16,20 @@ type tombstoneBodyWriter struct { } func (s *Service) toPrm(req *objectV2.DeleteRequest, respBody *objectV2.DeleteResponseBody) (*deletesvc.Prm, error) { + body := req.GetBody() + + addrV2 := body.GetAddress() + if addrV2 == nil { + return nil, errors.New("missing object address") + } + + var addr oid.Address + + err := addr.ReadFromV2(*addrV2) + if err != nil { + return nil, fmt.Errorf("invalid object address: %w", err) + } + commonPrm, err := util.CommonPrmFromV2(req) if err != nil { return nil, err @@ -20,8 +38,7 @@ func (s *Service) toPrm(req *objectV2.DeleteRequest, respBody *objectV2.DeleteRe p := new(deletesvc.Prm) p.SetCommonParameters(commonPrm) - body := req.GetBody() - p.WithAddress(addressSDK.NewAddressFromV2(body.GetAddress())) + p.WithAddress(addr) p.WithTombstoneAddressTarget(&tombstoneBodyWriter{ body: respBody, }) @@ -29,6 +46,9 @@ func (s *Service) toPrm(req *objectV2.DeleteRequest, respBody *objectV2.DeleteRe return p, nil } -func (w *tombstoneBodyWriter) SetAddress(addr *addressSDK.Address) { - w.body.SetTombstone(addr.ToV2()) +func (w *tombstoneBodyWriter) SetAddress(addr oid.Address) { + var addrV2 refs.Address + addr.WriteToV2(&addrV2) + + w.body.SetTombstone(&addrV2) } diff --git a/pkg/services/object/get/assemble.go b/pkg/services/object/get/assemble.go index 8ebb6e06..0d14578d 100644 --- a/pkg/services/object/get/assemble.go +++ b/pkg/services/object/get/assemble.go @@ -3,8 +3,7 @@ package getsvc import ( "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" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.uber.org/zap" ) @@ -25,10 +24,14 @@ func (exec *execCtx) assemble() { childID, ok := splitInfo.Link() if !ok { - childID, _ = splitInfo.LastPart() + childID, ok = splitInfo.LastPart() + if !ok { + exec.log.Debug("neither linking nor last part of split-chain is presented in split info") + return + } } - prev, children := exec.initFromChild(&childID) + prev, children := exec.initFromChild(childID) if len(children) > 0 { if exec.ctxRange() == nil { @@ -61,12 +64,12 @@ func (exec *execCtx) assemble() { } } -func (exec *execCtx) initFromChild(id *oidSDK.ID) (prev *oidSDK.ID, children []oidSDK.ID) { - log := exec.log.With(zap.Stringer("child ID", id)) +func (exec *execCtx) initFromChild(obj oid.ID) (prev *oid.ID, children []oid.ID) { + log := exec.log.With(zap.Stringer("child ID", obj)) log.Debug("starting assembling from child") - child, ok := exec.getChild(id, nil, true) + child, ok := exec.getChild(obj, nil, true) if !ok { return } @@ -125,7 +128,7 @@ func (exec *execCtx) initFromChild(id *oidSDK.ID) (prev *oidSDK.ID, children []o return nil, child.Children() } -func (exec *execCtx) overtakePayloadDirectly(children []oidSDK.ID, rngs []objectSDK.Range, checkRight bool) { +func (exec *execCtx) overtakePayloadDirectly(children []oid.ID, rngs []objectSDK.Range, checkRight bool) { withRng := len(rngs) > 0 && exec.ctxRange() != nil for i := range children { @@ -134,7 +137,7 @@ func (exec *execCtx) overtakePayloadDirectly(children []oidSDK.ID, rngs []object r = &rngs[i] } - child, ok := exec.getChild(&children[i], r, !withRng && checkRight) + child, ok := exec.getChild(children[i], r, !withRng && checkRight) if !ok { return } @@ -148,7 +151,7 @@ func (exec *execCtx) overtakePayloadDirectly(children []oidSDK.ID, rngs []object exec.err = nil } -func (exec *execCtx) overtakePayloadInReverse(prev oidSDK.ID) bool { +func (exec *execCtx) overtakePayloadInReverse(prev oid.ID) bool { chain, rngs, ok := exec.buildChainInReverse(prev) if !ok { return false @@ -170,9 +173,9 @@ func (exec *execCtx) overtakePayloadInReverse(prev oidSDK.ID) bool { return exec.status == statusOK } -func (exec *execCtx) buildChainInReverse(prev oidSDK.ID) ([]oidSDK.ID, []objectSDK.Range, bool) { +func (exec *execCtx) buildChainInReverse(prev oid.ID) ([]oid.ID, []objectSDK.Range, bool) { var ( - chain = make([]oidSDK.ID, 0) + chain = make([]oid.ID, 0) rngs = make([]objectSDK.Range, 0) seekRng = exec.ctxRange() from = seekRng.GetOffset() @@ -187,7 +190,7 @@ func (exec *execCtx) buildChainInReverse(prev oidSDK.ID) ([]oidSDK.ID, []objectS break } - head, ok := exec.headChild(&prev) + head, ok := exec.headChild(prev) if !ok { return nil, nil, false } @@ -227,27 +230,6 @@ func (exec *execCtx) buildChainInReverse(prev oidSDK.ID) ([]oidSDK.ID, []objectS return chain, rngs, true } -func equalAddresses(a, b *addressSDK.Address) bool { - cnr1, ok := a.ContainerID() - if !ok { - return false - } - - cnr2, ok := b.ContainerID() - if !ok { - return false - } - - if !cnr1.Equals(cnr2) { - return false - } - - id1, ok := a.ObjectID() - if !ok { - return false - } - - id2, ok := a.ObjectID() - - return ok && id1.Equals(id2) +func equalAddresses(a, b oid.Address) bool { + return a.Container().Equals(b.Container()) && a.Object().Equals(b.Object()) } diff --git a/pkg/services/object/get/exec.go b/pkg/services/object/get/exec.go index 1e4f20d1..11365dce 100644 --- a/pkg/services/object/get/exec.go +++ b/pkg/services/object/get/exec.go @@ -12,8 +12,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/util/logger" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.uber.org/zap" ) @@ -96,7 +95,7 @@ func (exec execCtx) isRaw() bool { return exec.prm.raw } -func (exec execCtx) address() *addressSDK.Address { +func (exec execCtx) address() oid.Address { return exec.prm.addr } @@ -126,13 +125,8 @@ func (exec *execCtx) splitInfo() *objectSDK.SplitInfo { return exec.infoSplit } -func (exec *execCtx) containerID() *cid.ID { - cnr, ok := exec.address().ContainerID() - if ok { - return &cnr - } - - return nil +func (exec *execCtx) containerID() cid.ID { + return exec.address().Container() } func (exec *execCtx) ctxRange() *objectSDK.Range { @@ -175,8 +169,10 @@ func (exec *execCtx) initEpoch() bool { } } -func (exec *execCtx) generateTraverser(addr *addressSDK.Address) (*placement.Traverser, bool) { - t, err := exec.svc.traverserGenerator.GenerateTraverser(addr, exec.curProcEpoch) +func (exec *execCtx) generateTraverser(addr oid.Address) (*placement.Traverser, bool) { + obj := addr.Object() + + t, err := exec.svc.traverserGenerator.GenerateTraverser(addr.Container(), &obj, exec.curProcEpoch) switch { default: @@ -193,7 +189,7 @@ func (exec *execCtx) generateTraverser(addr *addressSDK.Address) (*placement.Tra } } -func (exec *execCtx) getChild(id *oidSDK.ID, rng *objectSDK.Range, withHdr bool) (*objectSDK.Object, bool) { +func (exec *execCtx) getChild(id oid.ID, rng *objectSDK.Range, withHdr bool) (*objectSDK.Object, bool) { w := NewSimpleObjectWriter() p := exec.prm @@ -201,13 +197,8 @@ func (exec *execCtx) getChild(id *oidSDK.ID, rng *objectSDK.Range, withHdr bool) p.objWriter = w p.SetRange(rng) - cnr, _ := exec.address().ContainerID() - - addr := addressSDK.NewAddress() - addr.SetContainerID(cnr) - addr.SetObjectID(*id) - - p.addr = addr + p.addr.SetContainer(exec.containerID()) + p.addr.SetObject(id) exec.statusError = exec.svc.get(exec.context(), p.commonPrm, withPayloadRange(rng)) @@ -224,14 +215,11 @@ func (exec *execCtx) getChild(id *oidSDK.ID, rng *objectSDK.Range, withHdr bool) return child, ok } -func (exec *execCtx) headChild(id *oidSDK.ID) (*objectSDK.Object, bool) { - childAddr := addressSDK.NewAddress() - childAddr.SetContainerID(*exec.containerID()) - childAddr.SetObjectID(*id) - +func (exec *execCtx) headChild(id oid.ID) (*objectSDK.Object, bool) { p := exec.prm p.common = p.common.WithLocalOnly(false) - p.addr = childAddr + p.addr.SetContainer(exec.containerID()) + p.addr.SetObject(id) prm := HeadPrm{ commonPrm: p.commonPrm, diff --git a/pkg/services/object/get/get_test.go b/pkg/services/object/get/get_test.go index f0b084af..e34b679d 100644 --- a/pkg/services/object/get/get_test.go +++ b/pkg/services/object/get/get_test.go @@ -19,9 +19,7 @@ import ( cid "github.com/nspcc-dev/neofs-sdk-go/container/id" "github.com/nspcc-dev/neofs-sdk-go/netmap" objectSDK "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" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test" "github.com/stretchr/testify/require" ) @@ -68,26 +66,30 @@ func newTestStorage() *testStorage { } } -func (g *testTraverserGenerator) GenerateTraverser(addr *addressSDK.Address, e uint64) (*placement.Traverser, error) { - id, ok := addr.ObjectID() - var optObj placement.Option - - if ok { - optObj = placement.ForObject(&id) - } else { - optObj = placement.ForObject(nil) - } - - return placement.NewTraverser( +func (g *testTraverserGenerator) GenerateTraverser(cnr cid.ID, obj *oid.ID, e uint64) (*placement.Traverser, error) { + opts := make([]placement.Option, 3, 4) + opts = append(opts, placement.ForContainer(g.c), - optObj, placement.UseBuilder(g.b[e]), placement.SuccessAfter(1), ) + + if obj != nil { + opts = append(opts, placement.ForObject(*obj)) + } + + return placement.NewTraverser(opts...) } -func (p *testPlacementBuilder) BuildPlacement(addr *addressSDK.Address, _ *netmap.PlacementPolicy) ([]netmap.Nodes, error) { - vs, ok := p.vectors[addr.String()] +func (p *testPlacementBuilder) BuildPlacement(cnr cid.ID, obj *oid.ID, _ *netmap.PlacementPolicy) ([]netmap.Nodes, error) { + var addr oid.Address + addr.SetContainer(cnr) + + if obj != nil { + addr.SetObject(*obj) + } + + vs, ok := p.vectors[addr.EncodeToString()] if !ok { return nil, errors.New("vectors for address not found") } @@ -114,7 +116,7 @@ func newTestClient() *testClient { } func (c *testClient) getObject(exec *execCtx, _ client.NodeInfo) (*objectSDK.Object, error) { - v, ok := c.results[exec.address().String()] + v, ok := c.results[exec.address().EncodeToString()] if !ok { var errNotFound apistatus.ObjectNotFound @@ -128,8 +130,8 @@ func (c *testClient) getObject(exec *execCtx, _ client.NodeInfo) (*objectSDK.Obj return cutToRange(v.obj, exec.ctxRange()), nil } -func (c *testClient) addResult(addr *addressSDK.Address, obj *objectSDK.Object, err error) { - c.results[addr.String()] = struct { +func (c *testClient) addResult(addr oid.Address, obj *objectSDK.Object, err error) { + c.results[addr.EncodeToString()] = struct { obj *objectSDK.Object err error }{obj: obj, err: err} @@ -139,7 +141,7 @@ func (s *testStorage) get(exec *execCtx) (*objectSDK.Object, error) { var ( ok bool obj *objectSDK.Object - sAddr = exec.address().String() + sAddr = exec.address().EncodeToString() ) if _, ok = s.inhumed[sAddr]; ok { @@ -177,25 +179,22 @@ func cutToRange(o *objectSDK.Object, rng *objectSDK.Range) *objectSDK.Object { return o } -func (s *testStorage) addPhy(addr *addressSDK.Address, obj *objectSDK.Object) { - s.phy[addr.String()] = obj +func (s *testStorage) addPhy(addr oid.Address, obj *objectSDK.Object) { + s.phy[addr.EncodeToString()] = obj } -func (s *testStorage) addVirtual(addr *addressSDK.Address, info *objectSDK.SplitInfo) { - s.virtual[addr.String()] = info +func (s *testStorage) addVirtual(addr oid.Address, info *objectSDK.SplitInfo) { + s.virtual[addr.EncodeToString()] = info } -func (s *testStorage) inhume(addr *addressSDK.Address) { - s.inhumed[addr.String()] = struct{}{} +func (s *testStorage) inhume(addr oid.Address) { + s.inhumed[addr.EncodeToString()] = struct{}{} } -func generateObject(addr *addressSDK.Address, prev *oidSDK.ID, payload []byte, children ...oidSDK.ID) *objectSDK.Object { - cnr, _ := addr.ContainerID() - id, _ := addr.ObjectID() - +func generateObject(addr oid.Address, prev *oid.ID, payload []byte, children ...oid.ID) *objectSDK.Object { obj := objectSDK.New() - obj.SetContainerID(cnr) - obj.SetID(id) + obj.SetContainerID(addr.Container()) + obj.SetID(addr.Object()) obj.SetPayload(payload) obj.SetPayloadSize(uint64(len(payload))) if prev != nil { @@ -262,7 +261,7 @@ func TestGetLocalOnly(t *testing.T) { payload := make([]byte, payloadSz) rand.Read(payload) - addr := objecttest.Address() + addr := oidtest.Address() obj := generateObject(addr, nil, payload) storage.addPhy(addr, obj) @@ -301,7 +300,7 @@ func TestGetLocalOnly(t *testing.T) { p := newPrm(false, nil) - addr := objecttest.Address() + addr := oidtest.Address() storage.inhume(addr) @@ -330,7 +329,7 @@ func TestGetLocalOnly(t *testing.T) { p := newPrm(false, nil) - addr := objecttest.Address() + addr := oidtest.Address() p.WithAddress(addr) @@ -358,7 +357,7 @@ func TestGetLocalOnly(t *testing.T) { p := newPrm(true, nil) - addr := objecttest.Address() + addr := oidtest.Address() splitInfo := objectSDK.NewSplitInfo() splitInfo.SetSplitID(objectSDK.NewSplitID()) @@ -427,20 +426,20 @@ func testNodeMatrix(t testing.TB, dim []int) ([]netmap.Nodes, [][]string) { return mNodes, mAddr } -func generateChain(ln int, cnr cid.ID) ([]*objectSDK.Object, []oidSDK.ID, []byte) { +func generateChain(ln int, cnr cid.ID) ([]*objectSDK.Object, []oid.ID, []byte) { curID := oidtest.ID() - var prevID *oidSDK.ID + var prevID *oid.ID - addr := addressSDK.NewAddress() - addr.SetContainerID(cnr) + var addr oid.Address + addr.SetContainer(cnr) res := make([]*objectSDK.Object, 0, ln) - ids := make([]oidSDK.ID, 0, ln) + ids := make([]oid.ID, 0, ln) payload := make([]byte, 0, ln*10) for i := 0; i < ln; i++ { ids = append(ids, curID) - addr.SetObjectID(curID) + addr.SetObject(curID) payloadPart := make([]byte, 10) rand.Read(payloadPart) @@ -522,14 +521,14 @@ func TestGetRemoteSmall(t *testing.T) { } t.Run("OK", func(t *testing.T) { - addr := objecttest.Address() - addr.SetContainerID(idCnr) + addr := oidtest.Address() + addr.SetContainer(idCnr) ns, as := testNodeMatrix(t, []int{2}) builder := &testPlacementBuilder{ vectors: map[string][]netmap.Nodes{ - addr.String(): ns, + addr.EncodeToString(): ns, }, } @@ -585,14 +584,14 @@ func TestGetRemoteSmall(t *testing.T) { }) t.Run("INHUMED", func(t *testing.T) { - addr := objecttest.Address() - addr.SetContainerID(idCnr) + addr := oidtest.Address() + addr.SetContainer(idCnr) ns, as := testNodeMatrix(t, []int{2}) builder := &testPlacementBuilder{ vectors: map[string][]netmap.Nodes{ - addr.String(): ns, + addr.EncodeToString(): ns, }, } @@ -629,14 +628,14 @@ func TestGetRemoteSmall(t *testing.T) { }) t.Run("404", func(t *testing.T) { - addr := objecttest.Address() - addr.SetContainerID(idCnr) + addr := oidtest.Address() + addr.SetContainer(idCnr) ns, as := testNodeMatrix(t, []int{2}) builder := &testPlacementBuilder{ vectors: map[string][]netmap.Nodes{ - addr.String(): ns, + addr.EncodeToString(): ns, }, } @@ -673,7 +672,7 @@ func TestGetRemoteSmall(t *testing.T) { }) t.Run("VIRTUAL", func(t *testing.T) { - testHeadVirtual := func(svc *Service, addr *addressSDK.Address, i *objectSDK.SplitInfo) { + testHeadVirtual := func(svc *Service, addr oid.Address, i *objectSDK.SplitInfo) { headPrm := newHeadPrm(false, nil) headPrm.WithAddress(addr) @@ -686,19 +685,19 @@ func TestGetRemoteSmall(t *testing.T) { t.Run("linking", func(t *testing.T) { t.Run("get linking failure", func(t *testing.T) { - addr := objecttest.Address() - addr.SetContainerID(idCnr) - addr.SetObjectID(oidtest.ID()) + addr := oidtest.Address() + addr.SetContainer(idCnr) + addr.SetObject(oidtest.ID()) ns, as := testNodeMatrix(t, []int{2}) splitInfo := objectSDK.NewSplitInfo() splitInfo.SetLink(oidtest.ID()) - splitAddr := addressSDK.NewAddress() - splitAddr.SetContainerID(idCnr) + var splitAddr oid.Address + splitAddr.SetContainer(idCnr) idLink, _ := splitInfo.Link() - splitAddr.SetObjectID(idLink) + splitAddr.SetObject(idLink) c1 := newTestClient() c1.addResult(addr, nil, errors.New("any error")) @@ -710,8 +709,8 @@ func TestGetRemoteSmall(t *testing.T) { builder := &testPlacementBuilder{ vectors: map[string][]netmap.Nodes{ - addr.String(): ns, - splitAddr.String(): ns, + addr.EncodeToString(): ns, + splitAddr.EncodeToString(): ns, }, } @@ -738,9 +737,9 @@ func TestGetRemoteSmall(t *testing.T) { }) t.Run("get chain element failure", func(t *testing.T) { - addr := objecttest.Address() - addr.SetContainerID(idCnr) - addr.SetObjectID(oidtest.ID()) + addr := oidtest.Address() + addr.SetContainer(idCnr) + addr.SetObject(oidtest.ID()) srcObj := generateObject(addr, nil, nil) srcObj.SetPayloadSize(10) @@ -752,23 +751,22 @@ func TestGetRemoteSmall(t *testing.T) { children, childIDs, _ := generateChain(2, idCnr) - linkAddr := addressSDK.NewAddress() - linkAddr.SetContainerID(idCnr) + var linkAddr oid.Address + linkAddr.SetContainer(idCnr) idLink, _ := splitInfo.Link() - linkAddr.SetObjectID(idLink) + linkAddr.SetObject(idLink) linkingObj := generateObject(linkAddr, nil, nil, childIDs...) - id, _ := addr.ObjectID() - linkingObj.SetParentID(id) + linkingObj.SetParentID(addr.Object()) linkingObj.SetParent(srcObj) - child1Addr := addressSDK.NewAddress() - child1Addr.SetContainerID(idCnr) - child1Addr.SetObjectID(childIDs[0]) + var child1Addr oid.Address + child1Addr.SetContainer(idCnr) + child1Addr.SetObject(childIDs[0]) - child2Addr := addressSDK.NewAddress() - child2Addr.SetContainerID(idCnr) - child2Addr.SetObjectID(childIDs[1]) + var child2Addr oid.Address + child2Addr.SetContainer(idCnr) + child2Addr.SetObject(childIDs[1]) c1 := newTestClient() c1.addResult(addr, nil, errors.New("any error")) @@ -784,10 +782,10 @@ func TestGetRemoteSmall(t *testing.T) { builder := &testPlacementBuilder{ vectors: map[string][]netmap.Nodes{ - addr.String(): ns, - linkAddr.String(): ns, - child1Addr.String(): ns, - child2Addr.String(): ns, + addr.EncodeToString(): ns, + linkAddr.EncodeToString(): ns, + child1Addr.EncodeToString(): ns, + child2Addr.EncodeToString(): ns, }, } @@ -814,9 +812,9 @@ func TestGetRemoteSmall(t *testing.T) { }) t.Run("OK", func(t *testing.T) { - addr := objecttest.Address() - addr.SetContainerID(idCnr) - addr.SetObjectID(oidtest.ID()) + addr := oidtest.Address() + addr.SetContainer(idCnr) + addr.SetObject(oidtest.ID()) srcObj := generateObject(addr, nil, nil) @@ -830,23 +828,22 @@ func TestGetRemoteSmall(t *testing.T) { srcObj.SetPayloadSize(uint64(len(payload))) children[len(children)-1].SetParent(srcObj) - linkAddr := addressSDK.NewAddress() - linkAddr.SetContainerID(idCnr) + var linkAddr oid.Address + linkAddr.SetContainer(idCnr) idLink, _ := splitInfo.Link() - linkAddr.SetObjectID(idLink) + linkAddr.SetObject(idLink) linkingObj := generateObject(linkAddr, nil, nil, childIDs...) - id, _ := addr.ObjectID() - linkingObj.SetParentID(id) + linkingObj.SetParentID(addr.Object()) linkingObj.SetParent(srcObj) - child1Addr := addressSDK.NewAddress() - child1Addr.SetContainerID(idCnr) - child1Addr.SetObjectID(childIDs[0]) + var child1Addr oid.Address + child1Addr.SetContainer(idCnr) + child1Addr.SetObject(childIDs[0]) - child2Addr := addressSDK.NewAddress() - child2Addr.SetContainerID(idCnr) - child2Addr.SetObjectID(childIDs[1]) + var child2Addr oid.Address + child2Addr.SetContainer(idCnr) + child2Addr.SetObject(childIDs[1]) c1 := newTestClient() c1.addResult(addr, nil, errors.New("any error")) @@ -862,10 +859,10 @@ func TestGetRemoteSmall(t *testing.T) { builder := &testPlacementBuilder{ vectors: map[string][]netmap.Nodes{ - addr.String(): ns, - linkAddr.String(): ns, - child1Addr.String(): ns, - child2Addr.String(): ns, + addr.EncodeToString(): ns, + linkAddr.EncodeToString(): ns, + child1Addr.EncodeToString(): ns, + child2Addr.EncodeToString(): ns, }, } @@ -904,19 +901,19 @@ func TestGetRemoteSmall(t *testing.T) { t.Run("right child", func(t *testing.T) { t.Run("get right child failure", func(t *testing.T) { - addr := objecttest.Address() - addr.SetContainerID(idCnr) - addr.SetObjectID(oidtest.ID()) + addr := oidtest.Address() + addr.SetContainer(idCnr) + addr.SetObject(oidtest.ID()) ns, as := testNodeMatrix(t, []int{2}) splitInfo := objectSDK.NewSplitInfo() splitInfo.SetLastPart(oidtest.ID()) - splitAddr := addressSDK.NewAddress() - splitAddr.SetContainerID(idCnr) + var splitAddr oid.Address + splitAddr.SetContainer(idCnr) idLast, _ := splitInfo.LastPart() - splitAddr.SetObjectID(idLast) + splitAddr.SetObject(idLast) c1 := newTestClient() c1.addResult(addr, nil, errors.New("any error")) @@ -928,8 +925,8 @@ func TestGetRemoteSmall(t *testing.T) { builder := &testPlacementBuilder{ vectors: map[string][]netmap.Nodes{ - addr.String(): ns, - splitAddr.String(): ns, + addr.EncodeToString(): ns, + splitAddr.EncodeToString(): ns, }, } @@ -956,9 +953,9 @@ func TestGetRemoteSmall(t *testing.T) { }) t.Run("get chain element failure", func(t *testing.T) { - addr := objecttest.Address() - addr.SetContainerID(idCnr) - addr.SetObjectID(oidtest.ID()) + addr := oidtest.Address() + addr.SetContainer(idCnr) + addr.SetObject(oidtest.ID()) srcObj := generateObject(addr, nil, nil) srcObj.SetPayloadSize(10) @@ -970,15 +967,14 @@ func TestGetRemoteSmall(t *testing.T) { children, _, _ := generateChain(2, idCnr) - rightAddr := addressSDK.NewAddress() - rightAddr.SetContainerID(idCnr) + var rightAddr oid.Address + rightAddr.SetContainer(idCnr) idLast, _ := splitInfo.LastPart() - rightAddr.SetObjectID(idLast) + rightAddr.SetObject(idLast) rightObj := children[len(children)-1] - id, _ := addr.ObjectID() - rightObj.SetParentID(id) + rightObj.SetParentID(addr.Object()) rightObj.SetParent(srcObj) preRightAddr := object.AddressOf(children[len(children)-2]) @@ -993,9 +989,9 @@ func TestGetRemoteSmall(t *testing.T) { builder := &testPlacementBuilder{ vectors: map[string][]netmap.Nodes{ - addr.String(): ns, - rightAddr.String(): ns, - preRightAddr.String(): ns, + addr.EncodeToString(): ns, + rightAddr.EncodeToString(): ns, + preRightAddr.EncodeToString(): ns, }, } @@ -1025,9 +1021,9 @@ func TestGetRemoteSmall(t *testing.T) { }) t.Run("OK", func(t *testing.T) { - addr := objecttest.Address() - addr.SetContainerID(idCnr) - addr.SetObjectID(oidtest.ID()) + addr := oidtest.Address() + addr.SetContainer(idCnr) + addr.SetObject(oidtest.ID()) srcObj := generateObject(addr, nil, nil) @@ -1044,8 +1040,7 @@ func TestGetRemoteSmall(t *testing.T) { idLast, _ := splitInfo.LastPart() rightObj.SetID(idLast) - id, _ := addr.ObjectID() - rightObj.SetParentID(id) + rightObj.SetParentID(addr.Object()) rightObj.SetParent(srcObj) c1 := newTestClient() @@ -1066,10 +1061,10 @@ func TestGetRemoteSmall(t *testing.T) { vectors: map[string][]netmap.Nodes{}, } - builder.vectors[addr.String()] = ns + builder.vectors[addr.EncodeToString()] = ns for i := range children { - builder.vectors[object.AddressOf(children[i]).String()] = ns + builder.vectors[object.AddressOf(children[i]).EncodeToString()] = ns } svc := newSvc(builder, &testClientCache{ @@ -1124,8 +1119,8 @@ func TestGetFromPastEpoch(t *testing.T) { cnr := container.New(container.WithPolicy(new(netmap.PlacementPolicy))) idCnr := container.CalculateID(cnr) - addr := objecttest.Address() - addr.SetContainerID(idCnr) + addr := oidtest.Address() + addr.SetContainer(idCnr) payloadSz := uint64(10) payload := make([]byte, payloadSz) @@ -1159,12 +1154,12 @@ func TestGetFromPastEpoch(t *testing.T) { b: map[uint64]placement.Builder{ curEpoch: &testPlacementBuilder{ vectors: map[string][]netmap.Nodes{ - addr.String(): ns[:1], + addr.EncodeToString(): ns[:1], }, }, curEpoch - 1: &testPlacementBuilder{ vectors: map[string][]netmap.Nodes{ - addr.String(): ns[1:], + addr.EncodeToString(): ns[1:], }, }, }, diff --git a/pkg/services/object/get/prm.go b/pkg/services/object/get/prm.go index 75f00fc3..4bffbc44 100644 --- a/pkg/services/object/get/prm.go +++ b/pkg/services/object/get/prm.go @@ -6,7 +6,7 @@ import ( 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-sdk-go/object" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) // Prm groups parameters of Get service call. @@ -44,7 +44,7 @@ type commonPrm struct { common *util.CommonPrm - addr *addressSDK.Address + addr oid.Address raw bool @@ -111,7 +111,7 @@ func (p *commonPrm) SetRequestForwarder(f RequestForwarder) { } // WithAddress sets object address to be read. -func (p *commonPrm) WithAddress(addr *addressSDK.Address) { +func (p *commonPrm) WithAddress(addr oid.Address) { p.addr = addr } diff --git a/pkg/services/object/get/service.go b/pkg/services/object/get/service.go index 61924627..c48fc554 100644 --- a/pkg/services/object/get/service.go +++ b/pkg/services/object/get/service.go @@ -7,8 +7,9 @@ import ( "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/util/logger" + 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" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.uber.org/zap" ) @@ -38,7 +39,7 @@ type cfg struct { } traverserGenerator interface { - GenerateTraverser(*addressSDK.Address, uint64) (*placement.Traverser, error) + GenerateTraverser(cid.ID, *oid.ID, uint64) (*placement.Traverser, error) } currentEpochReceiver interface { diff --git a/pkg/services/object/get/v2/util.go b/pkg/services/object/get/v2/util.go index ec403ed0..332937e0 100644 --- a/pkg/services/object/get/v2/util.go +++ b/pkg/services/object/get/v2/util.go @@ -23,13 +23,27 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/services/object/util" neofscrypto "github.com/nspcc-dev/neofs-sdk-go/crypto" "github.com/nspcc-dev/neofs-sdk-go/object" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/nspcc-dev/tzhash/tz" ) var errWrongMessageSeq = errors.New("incorrect message sequence") func (s *Service) toPrm(req *objectV2.GetRequest, stream objectSvc.GetObjectStream) (*getsvc.Prm, error) { + body := req.GetBody() + + addrV2 := body.GetAddress() + if addrV2 == nil { + return nil, errors.New("missing object address") + } + + var addr oid.Address + + err := addr.ReadFromV2(*addrV2) + if err != nil { + return nil, fmt.Errorf("invalid object address: %w", err) + } + meta := req.GetMetaHeader() commonPrm, err := util.CommonPrmFromV2(req) @@ -40,8 +54,7 @@ func (s *Service) toPrm(req *objectV2.GetRequest, stream objectSvc.GetObjectStre p := new(getsvc.Prm) p.SetCommonParameters(commonPrm) - body := req.GetBody() - p.WithAddress(addressSDK.NewAddressFromV2(body.GetAddress())) + p.WithAddress(addr) p.WithRawFlag(body.GetRaw()) p.SetObjectWriter(&streamObjectWriter{stream}) @@ -158,6 +171,20 @@ func (s *Service) toPrm(req *objectV2.GetRequest, stream objectSvc.GetObjectStre } func (s *Service) toRangePrm(req *objectV2.GetRangeRequest, stream objectSvc.GetObjectRangeStream) (*getsvc.RangePrm, error) { + body := req.GetBody() + + addrV2 := body.GetAddress() + if addrV2 == nil { + return nil, errors.New("missing object address") + } + + var addr oid.Address + + err := addr.ReadFromV2(*addrV2) + if err != nil { + return nil, fmt.Errorf("invalid object address: %w", err) + } + meta := req.GetMetaHeader() commonPrm, err := util.CommonPrmFromV2(req) @@ -168,8 +195,7 @@ func (s *Service) toRangePrm(req *objectV2.GetRangeRequest, stream objectSvc.Get p := new(getsvc.RangePrm) p.SetCommonParameters(commonPrm) - body := req.GetBody() - p.WithAddress(addressSDK.NewAddressFromV2(body.GetAddress())) + p.WithAddress(addr) p.WithRawFlag(body.GetRaw()) p.SetChunkWriter(&streamObjectRangeWriter{stream}) p.SetRange(object.NewRangeFromV2(body.GetRange())) @@ -263,6 +289,20 @@ func (s *Service) toRangePrm(req *objectV2.GetRangeRequest, stream objectSvc.Get } func (s *Service) toHashRangePrm(req *objectV2.GetRangeHashRequest) (*getsvc.RangeHashPrm, error) { + body := req.GetBody() + + addrV2 := body.GetAddress() + if addrV2 == nil { + return nil, errors.New("missing object address") + } + + var addr oid.Address + + err := addr.ReadFromV2(*addrV2) + if err != nil { + return nil, fmt.Errorf("invalid object address: %w", err) + } + commonPrm, err := util.CommonPrmFromV2(req) if err != nil { return nil, err @@ -271,8 +311,7 @@ func (s *Service) toHashRangePrm(req *objectV2.GetRangeHashRequest) (*getsvc.Ran p := new(getsvc.RangeHashPrm) p.SetCommonParameters(commonPrm) - body := req.GetBody() - p.WithAddress(addressSDK.NewAddressFromV2(body.GetAddress())) + p.WithAddress(addr) rngsV2 := body.GetRanges() rngs := make([]object.Range, len(rngsV2)) @@ -317,6 +356,20 @@ func (w *headResponseWriter) WriteHeader(hdr *object.Object) error { } func (s *Service) toHeadPrm(ctx context.Context, req *objectV2.HeadRequest, resp *objectV2.HeadResponse) (*getsvc.HeadPrm, error) { + body := req.GetBody() + + addrV2 := body.GetAddress() + if addrV2 == nil { + return nil, errors.New("missing object address") + } + + var objAddr oid.Address + + err := objAddr.ReadFromV2(*addrV2) + if err != nil { + return nil, fmt.Errorf("invalid object address: %w", err) + } + meta := req.GetMetaHeader() commonPrm, err := util.CommonPrmFromV2(req) @@ -327,10 +380,6 @@ func (s *Service) toHeadPrm(ctx context.Context, req *objectV2.HeadRequest, resp p := new(getsvc.HeadPrm) p.SetCommonParameters(commonPrm) - body := req.GetBody() - - objAddr := addressSDK.NewAddressFromV2(body.GetAddress()) - p.WithAddress(objAddr) p.WithRawFlag(body.GetRaw()) p.SetHeaderWriter(&headResponseWriter{ @@ -429,24 +478,16 @@ func (s *Service) toHeadPrm(ctx context.Context, req *objectV2.HeadRequest, resp hdr = hdrWithSig.GetHeader() idSig = hdrWithSig.GetSignature() - id, ok := objAddr.ObjectID() - if !ok { - return nil, errors.New("missing object ID") - } - if idSig == nil { // TODO(@cthulhu-rider): #1387 use "const" error return nil, errors.New("missing signature") } - binID, err := id.Marshal() + binID, err := objAddr.Object().Marshal() if err != nil { return nil, fmt.Errorf("marshal ID: %w", err) } - var idV2 refs.ObjectID - id.WriteToV2(&idV2) - var sig neofscrypto.Signature sig.ReadFromV2(*idSig) @@ -463,10 +504,8 @@ func (s *Service) toHeadPrm(ctx context.Context, req *objectV2.HeadRequest, resp objv2.SetHeader(hdr) objv2.SetSignature(idSig) - id, _ := objAddr.ObjectID() - obj := object.NewFromV2(objv2) - obj.SetID(id) + obj.SetID(objAddr.Object()) // convert the object return obj, nil diff --git a/pkg/services/object/head/prm.go b/pkg/services/object/head/prm.go index 185f0572..ddc77024 100644 --- a/pkg/services/object/head/prm.go +++ b/pkg/services/object/head/prm.go @@ -1,14 +1,14 @@ package headsvc import ( - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) type Prm struct { - addr *addressSDK.Address + addr oid.Address } -func (p *Prm) WithAddress(v *addressSDK.Address) *Prm { +func (p *Prm) WithAddress(v oid.Address) *Prm { if p != nil { p.addr = v } diff --git a/pkg/services/object/head/remote.go b/pkg/services/object/head/remote.go index ae6df25b..50ed1190 100644 --- a/pkg/services/object/head/remote.go +++ b/pkg/services/object/head/remote.go @@ -10,7 +10,7 @@ import ( "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/object" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) type ClientConstructor interface { @@ -54,7 +54,7 @@ func (p *RemoteHeadPrm) WithNodeInfo(v *netmap.NodeInfo) *RemoteHeadPrm { } // WithObjectAddress sets object address. -func (p *RemoteHeadPrm) WithObjectAddress(v *addressSDK.Address) *RemoteHeadPrm { +func (p *RemoteHeadPrm) WithObjectAddress(v oid.Address) *RemoteHeadPrm { if p != nil { p.commonHeadPrm = new(Prm).WithAddress(v) } diff --git a/pkg/services/object/internal/client/client.go b/pkg/services/object/internal/client/client.go index 7326a055..091b3ac8 100644 --- a/pkg/services/object/internal/client/client.go +++ b/pkg/services/object/internal/client/client.go @@ -13,8 +13,7 @@ import ( apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" 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" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/nspcc-dev/neofs-sdk-go/session" ) @@ -109,14 +108,9 @@ func (x *GetObjectPrm) SetRawFlag() { // SetAddress sets object address. // // Required parameter. -func (x *GetObjectPrm) SetAddress(addr *addressSDK.Address) { - if id, ok := addr.ContainerID(); ok { - x.cliPrm.FromContainer(id) - } - - if id, ok := addr.ObjectID(); ok { - x.cliPrm.ByID(id) - } +func (x *GetObjectPrm) SetAddress(addr oid.Address) { + x.cliPrm.FromContainer(addr.Container()) + x.cliPrm.ByID(addr.Object()) } // GetObjectRes groups the resulting values of GetObject operation. @@ -204,14 +198,9 @@ func (x *HeadObjectPrm) SetRawFlag() { // SetAddress sets object address. // // Required parameter. -func (x *HeadObjectPrm) SetAddress(addr *addressSDK.Address) { - if id, ok := addr.ContainerID(); ok { - x.cliPrm.FromContainer(id) - } - - if id, ok := addr.ObjectID(); ok { - x.cliPrm.ByID(id) - } +func (x *HeadObjectPrm) SetAddress(addr oid.Address) { + x.cliPrm.FromContainer(addr.Container()) + x.cliPrm.ByID(addr.Object()) } // HeadObjectRes groups the resulting values of GetObject operation. @@ -287,14 +276,9 @@ func (x *PayloadRangePrm) SetRawFlag() { // SetAddress sets object address. // // Required parameter. -func (x *PayloadRangePrm) SetAddress(addr *addressSDK.Address) { - if id, ok := addr.ContainerID(); ok { - x.cliPrm.FromContainer(id) - } - - if id, ok := addr.ObjectID(); ok { - x.cliPrm.ByID(id) - } +func (x *PayloadRangePrm) SetAddress(addr oid.Address) { + x.cliPrm.FromContainer(addr.Container()) + x.cliPrm.ByID(addr.Object()) } // SetRange range of the object payload to be read. @@ -372,11 +356,11 @@ func (x *PutObjectPrm) SetObject(obj *object.Object) { // PutObjectRes groups the resulting values of PutObject operation. type PutObjectRes struct { - id *oidSDK.ID + id oid.ID } // ID returns identifier of the stored object. -func (x PutObjectRes) ID() *oidSDK.ID { +func (x PutObjectRes) ID() oid.ID { return x.id } @@ -413,23 +397,22 @@ func PutObject(prm PutObjectPrm) (*PutObjectRes, error) { w.WritePayloadChunk(prm.obj.Payload()) } - res, err := w.Close() + cliRes, err := w.Close() if err == nil { - err = apistatus.ErrFromStatus(res.Status()) + err = apistatus.ErrFromStatus(cliRes.Status()) } if err != nil { return nil, fmt.Errorf("write object via client: %w", err) } - var id oidSDK.ID - if !res.ReadStoredObjectID(&id) { + var res PutObjectRes + + if !cliRes.ReadStoredObjectID(&res.id) { return nil, errors.New("missing identifier in the response") } - return &PutObjectRes{ - id: &id, - }, nil + return &res, nil } // SearchObjectsPrm groups parameters of SearchObjects operation. @@ -442,10 +425,8 @@ type SearchObjectsPrm struct { // SetContainerID sets identifier of the container to search the objects. // // Required parameter. -func (x *SearchObjectsPrm) SetContainerID(id *cid.ID) { - if id != nil { - x.cliPrm.InContainer(*id) - } +func (x *SearchObjectsPrm) SetContainerID(id cid.ID) { + x.cliPrm.InContainer(id) } // SetFilters sets search filters. @@ -455,11 +436,11 @@ func (x *SearchObjectsPrm) SetFilters(fs object.SearchFilters) { // SearchObjectsRes groups the resulting values of SearchObjects operation. type SearchObjectsRes struct { - ids []oidSDK.ID + ids []oid.ID } // IDList returns identifiers of the matched objects. -func (x SearchObjectsRes) IDList() []oidSDK.ID { +func (x SearchObjectsRes) IDList() []oid.ID { return x.ids } @@ -490,8 +471,8 @@ func SearchObjects(prm SearchObjectsPrm) (*SearchObjectsRes, error) { rdr.UseKey(*prm.key) } - buf := make([]oidSDK.ID, 10) - var ids []oidSDK.ID + buf := make([]oid.ID, 10) + var ids []oid.ID var n int var ok bool diff --git a/pkg/services/object/put/distributed.go b/pkg/services/object/put/distributed.go index 629d777d..5e0e8c11 100644 --- a/pkg/services/object/put/distributed.go +++ b/pkg/services/object/put/distributed.go @@ -146,7 +146,7 @@ func (t *distributedTarget) iteratePlacement(f func(nodeDesc) error) (*transform id, _ := t.obj.ID() traverser, err := placement.NewTraverser( - append(t.traversal.opts, placement.ForObject(&id))..., + append(t.traversal.opts, placement.ForObject(id))..., ) if err != nil { return nil, fmt.Errorf("(%T) could not create object placement traverser: %w", t, err) @@ -236,5 +236,5 @@ loop: id, _ = t.obj.ID() return new(transformer.AccessIdentifiers). - WithSelfID(&id), nil + WithSelfID(id), nil } diff --git a/pkg/services/object/put/local.go b/pkg/services/object/put/local.go index 81f45c30..e90e0ec0 100644 --- a/pkg/services/object/put/local.go +++ b/pkg/services/object/put/local.go @@ -35,5 +35,5 @@ func (t *localTarget) Close() (*transformer.AccessIdentifiers, error) { id, _ := t.obj.ID() return new(transformer.AccessIdentifiers). - WithSelfID(&id), nil + WithSelfID(id), nil } diff --git a/pkg/services/object/put/res.go b/pkg/services/object/put/res.go index 8610f6de..920a86a0 100644 --- a/pkg/services/object/put/res.go +++ b/pkg/services/object/put/res.go @@ -1,13 +1,13 @@ package putsvc import ( - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) type PutResponse struct { - id *oidSDK.ID + id oid.ID } -func (r *PutResponse) ObjectID() *oidSDK.ID { +func (r *PutResponse) ObjectID() oid.ID { return r.id } diff --git a/pkg/services/object/put/streamer.go b/pkg/services/object/put/streamer.go index 54ebd999..7b7e738b 100644 --- a/pkg/services/object/put/streamer.go +++ b/pkg/services/object/put/streamer.go @@ -148,7 +148,7 @@ func (p *Streamer) preparePrm(prm *PutInitPrm) error { } // get container to store the object - cnr, err := p.cnrSrc.Get(&idCnr) + cnr, err := p.cnrSrc.Get(idCnr) if err != nil { return fmt.Errorf("(%T) could not get container by ID: %w", p, err) } @@ -162,7 +162,7 @@ func (p *Streamer) preparePrm(prm *PutInitPrm) error { if id, ok := prm.hdr.ID(); ok { prm.traverseOpts = append(prm.traverseOpts, // set identifier of the processing object - placement.ForObject(&id), + placement.ForObject(id), ) } @@ -262,11 +262,13 @@ func (p *Streamer) Close() (*PutResponse, error) { } id := ids.ParentID() - if id == nil { - id = ids.SelfID() + if id != nil { + return &PutResponse{ + id: *id, + }, nil } return &PutResponse{ - id: id, + id: ids.SelfID(), }, nil } diff --git a/pkg/services/object/search/exec.go b/pkg/services/object/search/exec.go index 2d7d17ce..97b5dc27 100644 --- a/pkg/services/object/search/exec.go +++ b/pkg/services/object/search/exec.go @@ -8,7 +8,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/util/logger" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" "github.com/nspcc-dev/neofs-sdk-go/object" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.uber.org/zap" ) @@ -60,8 +60,8 @@ func (exec execCtx) isLocal() bool { return exec.prm.common.LocalOnly() } -func (exec *execCtx) containerID() *cid.ID { - return exec.prm.cid +func (exec *execCtx) containerID() cid.ID { + return exec.prm.cnr } func (exec *execCtx) searchFilters() object.SearchFilters { @@ -100,8 +100,8 @@ func (exec *execCtx) initEpoch() bool { } } -func (exec *execCtx) generateTraverser(cid *cid.ID) (*placement.Traverser, bool) { - t, err := exec.svc.traverserGenerator.generateTraverser(cid, exec.curProcEpoch) +func (exec *execCtx) generateTraverser(cnr cid.ID) (*placement.Traverser, bool) { + t, err := exec.svc.traverserGenerator.generateTraverser(cnr, exec.curProcEpoch) switch { default: @@ -133,7 +133,7 @@ func (exec execCtx) remoteClient(info client.NodeInfo) (searchClient, bool) { return nil, false } -func (exec *execCtx) writeIDList(ids []oidSDK.ID) { +func (exec *execCtx) writeIDList(ids []oid.ID) { err := exec.prm.writer.WriteIDs(ids) switch { diff --git a/pkg/services/object/search/prm.go b/pkg/services/object/search/prm.go index 59ea82f4..0baf8c61 100644 --- a/pkg/services/object/search/prm.go +++ b/pkg/services/object/search/prm.go @@ -5,7 +5,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/services/object/util" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" "github.com/nspcc-dev/neofs-sdk-go/object" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) // Prm groups parameters of Get service call. @@ -14,7 +14,7 @@ type Prm struct { common *util.CommonPrm - cid *cid.ID + cnr cid.ID filters object.SearchFilters @@ -24,12 +24,12 @@ type Prm struct { // IDListWriter is an interface of target component // to write list of object identifiers. type IDListWriter interface { - WriteIDs([]oidSDK.ID) error + WriteIDs([]oid.ID) error } // RequestForwarder is a callback for forwarding of the // original Search requests. -type RequestForwarder func(coreclient.NodeInfo, coreclient.MultiAddressClient) ([]oidSDK.ID, error) +type RequestForwarder func(coreclient.NodeInfo, coreclient.MultiAddressClient) ([]oid.ID, error) // SetCommonParameters sets common parameters of the operation. func (p *Prm) SetCommonParameters(common *util.CommonPrm) { @@ -48,8 +48,8 @@ func (p *Prm) SetRequestForwarder(f RequestForwarder) { } // WithContainerID sets identifier of the container to search the objects. -func (p *Prm) WithContainerID(id *cid.ID) { - p.cid = id +func (p *Prm) WithContainerID(id cid.ID) { + p.cnr = id } // WithSearchFilters sets search filters. diff --git a/pkg/services/object/search/search_test.go b/pkg/services/object/search/search_test.go index 41a686a0..80847850 100644 --- a/pkg/services/object/search/search_test.go +++ b/pkg/services/object/search/search_test.go @@ -18,13 +18,12 @@ import ( cid "github.com/nspcc-dev/neofs-sdk-go/container/id" cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" "github.com/nspcc-dev/neofs-sdk-go/netmap" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/stretchr/testify/require" ) type idsErr struct { - ids []oidSDK.ID + ids []oid.ID err error } @@ -46,7 +45,7 @@ type testClientCache struct { } type simpleIDWriter struct { - ids []oidSDK.ID + ids []oid.ID } type testEpochReceiver uint64 @@ -55,7 +54,7 @@ func (e testEpochReceiver) currentEpoch() (uint64, error) { return uint64(e), nil } -func (s *simpleIDWriter) WriteIDs(ids []oidSDK.ID) error { +func (s *simpleIDWriter) WriteIDs(ids []oid.ID) error { s.ids = append(s.ids, ids...) return nil } @@ -66,7 +65,7 @@ func newTestStorage() *testStorage { } } -func (g *testTraverserGenerator) generateTraverser(_ *cid.ID, epoch uint64) (*placement.Traverser, error) { +func (g *testTraverserGenerator) generateTraverser(_ cid.ID, epoch uint64) (*placement.Traverser, error) { return placement.NewTraverser( placement.ForContainer(g.c), placement.UseBuilder(g.b[epoch]), @@ -74,8 +73,15 @@ func (g *testTraverserGenerator) generateTraverser(_ *cid.ID, epoch uint64) (*pl ) } -func (p *testPlacementBuilder) BuildPlacement(addr *addressSDK.Address, _ *netmap.PlacementPolicy) ([]netmap.Nodes, error) { - vs, ok := p.vectors[addr.String()] +func (p *testPlacementBuilder) BuildPlacement(cnr cid.ID, obj *oid.ID, _ *netmap.PlacementPolicy) ([]netmap.Nodes, error) { + var addr oid.Address + addr.SetContainer(cnr) + + if obj != nil { + addr.SetObject(*obj) + } + + vs, ok := p.vectors[addr.EncodeToString()] if !ok { return nil, errors.New("vectors for address not found") } @@ -95,8 +101,8 @@ func (c *testClientCache) get(info clientcore.NodeInfo) (searchClient, error) { return v, nil } -func (s *testStorage) search(exec *execCtx) ([]oidSDK.ID, error) { - v, ok := s.items[exec.containerID().String()] +func (s *testStorage) search(exec *execCtx) ([]oid.ID, error) { + v, ok := s.items[exec.containerID().EncodeToString()] if !ok { return nil, nil } @@ -104,8 +110,8 @@ func (s *testStorage) search(exec *execCtx) ([]oidSDK.ID, error) { return v.ids, v.err } -func (c *testStorage) searchObjects(exec *execCtx, _ clientcore.NodeInfo) ([]oidSDK.ID, error) { - v, ok := c.items[exec.containerID().String()] +func (c *testStorage) searchObjects(exec *execCtx, _ clientcore.NodeInfo) ([]oid.ID, error) { + v, ok := c.items[exec.containerID().EncodeToString()] if !ok { return nil, nil } @@ -113,8 +119,8 @@ func (c *testStorage) searchObjects(exec *execCtx, _ clientcore.NodeInfo) ([]oid return v.ids, v.err } -func (c *testStorage) addResult(addr cid.ID, ids []oidSDK.ID, err error) { - c.items[addr.String()] = idsErr{ +func (c *testStorage) addResult(addr cid.ID, ids []oid.ID, err error) { + c.items[addr.EncodeToString()] = idsErr{ ids: ids, err: err, } @@ -125,8 +131,8 @@ func testSHA256() (cs [sha256.Size]byte) { return cs } -func generateIDs(num int) []oidSDK.ID { - res := make([]oidSDK.ID, num) +func generateIDs(num int) []oid.ID { + res := make([]oid.ID, num) for i := 0; i < num; i++ { res[i].SetSHA256(testSHA256()) @@ -148,7 +154,7 @@ func TestGetLocalOnly(t *testing.T) { newPrm := func(cnr cid.ID, w IDListWriter) Prm { p := Prm{} - p.WithContainerID(&cnr) + p.WithContainerID(cnr) p.SetWriter(w) p.common = new(util.CommonPrm).WithLocalOnly(true) @@ -258,7 +264,7 @@ func TestGetRemoteSmall(t *testing.T) { newPrm := func(id cid.ID, w IDListWriter) Prm { p := Prm{} - p.WithContainerID(&id) + p.WithContainerID(id) p.SetWriter(w) p.common = new(util.CommonPrm).WithLocalOnly(false) @@ -266,14 +272,14 @@ func TestGetRemoteSmall(t *testing.T) { } t.Run("OK", func(t *testing.T) { - addr := addressSDK.NewAddress() - addr.SetContainerID(id) + var addr oid.Address + addr.SetContainer(id) ns, as := testNodeMatrix(t, placementDim) builder := &testPlacementBuilder{ vectors: map[string][]netmap.Nodes{ - addr.String(): ns, + addr.EncodeToString(): ns, }, } @@ -321,28 +327,28 @@ func TestGetFromPastEpoch(t *testing.T) { pp.SetReplicas(rs...) cnr := container.New(container.WithPolicy(pp)) - cid := container.CalculateID(cnr) + idCnr := container.CalculateID(cnr) - addr := addressSDK.NewAddress() - addr.SetContainerID(cid) + var addr oid.Address + addr.SetContainer(idCnr) ns, as := testNodeMatrix(t, placementDim) c11 := newTestStorage() ids11 := generateIDs(10) - c11.addResult(cid, ids11, nil) + c11.addResult(idCnr, ids11, nil) c12 := newTestStorage() ids12 := generateIDs(10) - c12.addResult(cid, ids12, nil) + c12.addResult(idCnr, ids12, nil) c21 := newTestStorage() ids21 := generateIDs(10) - c21.addResult(cid, ids21, nil) + c21.addResult(idCnr, ids21, nil) c22 := newTestStorage() ids22 := generateIDs(10) - c22.addResult(cid, ids22, nil) + c22.addResult(idCnr, ids22, nil) svc := &Service{cfg: new(cfg)} svc.log = test.NewLogger(false) @@ -355,12 +361,12 @@ func TestGetFromPastEpoch(t *testing.T) { b: map[uint64]placement.Builder{ curEpoch: &testPlacementBuilder{ vectors: map[string][]netmap.Nodes{ - addr.String(): ns[:1], + addr.EncodeToString(): ns[:1], }, }, curEpoch - 1: &testPlacementBuilder{ vectors: map[string][]netmap.Nodes{ - addr.String(): ns[1:], + addr.EncodeToString(): ns[1:], }, }, }, @@ -380,13 +386,13 @@ func TestGetFromPastEpoch(t *testing.T) { w := new(simpleIDWriter) p := Prm{} - p.WithContainerID(&cid) + p.WithContainerID(idCnr) p.SetWriter(w) commonPrm := new(util.CommonPrm) p.SetCommonParameters(commonPrm) - assertContains := func(idsList ...[]oidSDK.ID) { + assertContains := func(idsList ...[]oid.ID) { var sz int for _, ids := range idsList { diff --git a/pkg/services/object/search/service.go b/pkg/services/object/search/service.go index cf4d143e..43ca797f 100644 --- a/pkg/services/object/search/service.go +++ b/pkg/services/object/search/service.go @@ -8,7 +8,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement" "github.com/nspcc-dev/neofs-node/pkg/util/logger" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.uber.org/zap" ) @@ -22,7 +22,7 @@ type Service struct { type Option func(*cfg) type searchClient interface { - searchObjects(*execCtx, client.NodeInfo) ([]oidSDK.ID, error) + searchObjects(*execCtx, client.NodeInfo) ([]oid.ID, error) } type ClientConstructor interface { @@ -33,7 +33,7 @@ type cfg struct { log *logger.Logger localStorage interface { - search(*execCtx) ([]oidSDK.ID, error) + search(*execCtx) ([]oid.ID, error) } clientConstructor interface { @@ -41,7 +41,7 @@ type cfg struct { } traverserGenerator interface { - generateTraverser(*cid.ID, uint64) (*placement.Traverser, error) + generateTraverser(cid.ID, uint64) (*placement.Traverser, error) } currentEpochReceiver interface { diff --git a/pkg/services/object/search/util.go b/pkg/services/object/search/util.go index 5fb07f45..a6ef7f3b 100644 --- a/pkg/services/object/search/util.go +++ b/pkg/services/object/search/util.go @@ -10,8 +10,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/services/object/util" "github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) type uniqueIDWriter struct { @@ -45,11 +44,11 @@ func newUniqueAddressWriter(w IDListWriter) IDListWriter { } } -func (w *uniqueIDWriter) WriteIDs(list []oidSDK.ID) error { +func (w *uniqueIDWriter) WriteIDs(list []oid.ID) error { w.mtx.Lock() for i := 0; i < len(list); i++ { // don't use range, slice mutates in body - s := list[i].String() + s := list[i].EncodeToString() // standard stringer is quite costly, it is better // to facilitate the calculation of the key @@ -80,7 +79,7 @@ func (c *clientConstructorWrapper) get(info client.NodeInfo) (searchClient, erro }, nil } -func (c *clientWrapper) searchObjects(exec *execCtx, info client.NodeInfo) ([]oidSDK.ID, error) { +func (c *clientWrapper) searchObjects(exec *execCtx, info client.NodeInfo) ([]oid.ID, error) { if exec.prm.forwarder != nil { return exec.prm.forwarder(info, c.client) } @@ -120,7 +119,7 @@ func (c *clientWrapper) searchObjects(exec *execCtx, info client.NodeInfo) ([]oi return res.IDList(), nil } -func (e *storageEngineWrapper) search(exec *execCtx) ([]oidSDK.ID, error) { +func (e *storageEngineWrapper) search(exec *execCtx) ([]oid.ID, error) { r, err := (*engine.StorageEngine)(e).Select(new(engine.SelectPrm). WithFilters(exec.searchFilters()). WithContainerID(exec.containerID()), @@ -132,21 +131,18 @@ func (e *storageEngineWrapper) search(exec *execCtx) ([]oidSDK.ID, error) { return idsFromAddresses(r.AddressList()), nil } -func idsFromAddresses(addrs []*addressSDK.Address) []oidSDK.ID { - ids := make([]oidSDK.ID, len(addrs)) +func idsFromAddresses(addrs []oid.Address) []oid.ID { + ids := make([]oid.ID, len(addrs)) for i := range addrs { - ids[i], _ = addrs[i].ObjectID() + ids[i] = addrs[i].Object() } return ids } -func (e *traverseGeneratorWrapper) generateTraverser(cnr *cid.ID, epoch uint64) (*placement.Traverser, error) { - a := addressSDK.NewAddress() - a.SetContainerID(*cnr) - - return (*util.TraverserGenerator)(e).GenerateTraverser(a, epoch) +func (e *traverseGeneratorWrapper) generateTraverser(cnr cid.ID, epoch uint64) (*placement.Traverser, error) { + return (*util.TraverserGenerator)(e).GenerateTraverser(cnr, nil, epoch) } func (n *nmSrcWrapper) currentEpoch() (uint64, error) { diff --git a/pkg/services/object/search/v2/streamer.go b/pkg/services/object/search/v2/streamer.go index 5301ba97..a1731a28 100644 --- a/pkg/services/object/search/v2/streamer.go +++ b/pkg/services/object/search/v2/streamer.go @@ -4,14 +4,14 @@ import ( "github.com/nspcc-dev/neofs-api-go/v2/object" "github.com/nspcc-dev/neofs-api-go/v2/refs" objectSvc "github.com/nspcc-dev/neofs-node/pkg/services/object" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) type streamWriter struct { stream objectSvc.SearchStream } -func (s *streamWriter) WriteIDs(ids []oidSDK.ID) error { +func (s *streamWriter) WriteIDs(ids []oid.ID) error { r := new(object.SearchResponse) body := new(object.SearchResponseBody) diff --git a/pkg/services/object/search/v2/util.go b/pkg/services/object/search/v2/util.go index a745f67f..10903fe0 100644 --- a/pkg/services/object/search/v2/util.go +++ b/pkg/services/object/search/v2/util.go @@ -19,7 +19,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/services/object/util" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" "github.com/nspcc-dev/neofs-sdk-go/object" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) func (s *Service) toPrm(req *objectV2.SearchRequest, stream objectSvc.SearchStream) (*searchsvc.Prm, error) { @@ -59,7 +59,7 @@ func (s *Service) toPrm(req *objectV2.SearchRequest, stream objectSvc.SearchStre return nil, err } - p.SetRequestForwarder(groupAddressRequestForwarder(func(addr network.Address, c client.MultiAddressClient, pubkey []byte) ([]oidSDK.ID, error) { + p.SetRequestForwarder(groupAddressRequestForwarder(func(addr network.Address, c client.MultiAddressClient, pubkey []byte) ([]oid.ID, error) { var err error // once compose and resign forwarding request @@ -91,7 +91,7 @@ func (s *Service) toPrm(req *objectV2.SearchRequest, stream objectSvc.SearchStre // code below is copy-pasted from c.SearchObjects implementation, // perhaps it is worth highlighting the utility function in neofs-api-go var ( - searchResult []oidSDK.ID + searchResult []oid.ID resp = new(objectV2.SearchResponse) ) @@ -117,7 +117,7 @@ func (s *Service) toPrm(req *objectV2.SearchRequest, stream objectSvc.SearchStre } chunk := resp.GetBody().GetIDList() - var id oidSDK.ID + var id oid.ID for i := range chunk { err = id.ReadFromV2(chunk[i]) @@ -133,17 +133,17 @@ func (s *Service) toPrm(req *objectV2.SearchRequest, stream objectSvc.SearchStre })) } - p.WithContainerID(&id) + p.WithContainerID(id) p.WithSearchFilters(object.NewSearchFiltersFromV2(body.GetFilters())) return p, nil } -func groupAddressRequestForwarder(f func(network.Address, client.MultiAddressClient, []byte) ([]oidSDK.ID, error)) searchsvc.RequestForwarder { - return func(info client.NodeInfo, c client.MultiAddressClient) ([]oidSDK.ID, error) { +func groupAddressRequestForwarder(f func(network.Address, client.MultiAddressClient, []byte) ([]oid.ID, error)) searchsvc.RequestForwarder { + return func(info client.NodeInfo, c client.MultiAddressClient) ([]oid.ID, error) { var ( firstErr error - res []oidSDK.ID + res []oid.ID key = info.PublicKey() ) diff --git a/pkg/services/object/util/chain.go b/pkg/services/object/util/chain.go index f26094ca..ebc8a62d 100644 --- a/pkg/services/object/util/chain.go +++ b/pkg/services/object/util/chain.go @@ -5,8 +5,7 @@ import ( "fmt" "github.com/nspcc-dev/neofs-sdk-go/object" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) // HeadReceiver is an interface of entity that can receive @@ -15,7 +14,7 @@ type HeadReceiver interface { // Head must return one of: // * object header (*object.Object); // * structured information about split-chain (*object.SplitInfo). - Head(*addressSDK.Address) (interface{}, error) + Head(id oid.Address) (interface{}, error) } // SplitMemberHandler is a handler of next split-chain element. @@ -25,7 +24,7 @@ type HeadReceiver interface { type SplitMemberHandler func(member *object.Object, reverseDirection bool) (stop bool) // IterateAllSplitLeaves is an iterator over all object split-tree leaves in direct order. -func IterateAllSplitLeaves(r HeadReceiver, addr *addressSDK.Address, h func(*object.Object)) error { +func IterateAllSplitLeaves(r HeadReceiver, addr oid.Address, h func(*object.Object)) error { return IterateSplitLeaves(r, addr, func(leaf *object.Object) bool { h(leaf) return false @@ -35,7 +34,7 @@ func IterateAllSplitLeaves(r HeadReceiver, addr *addressSDK.Address, h func(*obj // IterateSplitLeaves is an iterator over object split-tree leaves in direct order. // // If member handler returns true, then the iterator aborts without error. -func IterateSplitLeaves(r HeadReceiver, addr *addressSDK.Address, h func(*object.Object) bool) error { +func IterateSplitLeaves(r HeadReceiver, addr oid.Address, h func(*object.Object) bool) error { var ( reverse bool leaves []*object.Object @@ -68,21 +67,18 @@ func IterateSplitLeaves(r HeadReceiver, addr *addressSDK.Address, h func(*object // Traversal occurs in one of two directions, which depends on what pslit info was received: // * in direct order for link part; // * in reverse order for last part. -func TraverseSplitChain(r HeadReceiver, addr *addressSDK.Address, h SplitMemberHandler) error { +func TraverseSplitChain(r HeadReceiver, addr oid.Address, h SplitMemberHandler) error { _, err := traverseSplitChain(r, addr, h) return err } -func traverseSplitChain(r HeadReceiver, addr *addressSDK.Address, h SplitMemberHandler) (bool, error) { +func traverseSplitChain(r HeadReceiver, addr oid.Address, h SplitMemberHandler) (bool, error) { v, err := r.Head(addr) if err != nil { return false, err } - cnr, ok := addr.ContainerID() - if !ok { - return false, errors.New("missing container in object address") - } + cnr := addr.Container() switch res := v.(type) { default: @@ -97,11 +93,11 @@ func traverseSplitChain(r HeadReceiver, addr *addressSDK.Address, h SplitMemberH default: return false, errors.New("lack of split information") case withLink: - addr := addressSDK.NewAddress() - addr.SetContainerID(cnr) - addr.SetObjectID(link) + var addr oid.Address + addr.SetContainer(cnr) + addr.SetObject(link) - chain := make([]oidSDK.ID, 0) + chain := make([]oid.ID, 0) if _, err := traverseSplitChain(r, addr, func(member *object.Object, reverseDirection bool) (stop bool) { children := member.Children() @@ -120,7 +116,7 @@ func traverseSplitChain(r HeadReceiver, addr *addressSDK.Address, h SplitMemberH var reverseChain []*object.Object for i := range chain { - addr.SetObjectID(chain[i]) + addr.SetObject(chain[i]) if stop, err := traverseSplitChain(r, addr, func(member *object.Object, reverseDirection bool) (stop bool) { if !reverseDirection { @@ -140,11 +136,11 @@ func traverseSplitChain(r HeadReceiver, addr *addressSDK.Address, h SplitMemberH } } case withLast: - addr := addressSDK.NewAddress() - addr.SetContainerID(cnr) + var addr oid.Address + addr.SetContainer(cnr) for last, withLast = res.LastPart(); withLast; { - addr.SetObjectID(last) + addr.SetObject(last) var directChain []*object.Object diff --git a/pkg/services/object/util/key.go b/pkg/services/object/util/key.go index 32849ec8..d0df5577 100644 --- a/pkg/services/object/util/key.go +++ b/pkg/services/object/util/key.go @@ -20,7 +20,7 @@ type SessionSource interface { // token has not been created, has been expired // of it is impossible to get information about the // token Get must return nil. - Get(owner *user.ID, tokenID []byte) *storage.PrivateToken + Get(owner user.ID, tokenID []byte) *storage.PrivateToken } // KeyStorage represents private key storage of the local node. @@ -62,7 +62,7 @@ func (s *KeyStorage) GetKey(info *SessionInfo) (*ecdsa.PrivateKey, error) { return nil, fmt.Errorf("marshal ID: %w", err) } - pToken := s.tokenStore.Get(&info.Owner, binID) + pToken := s.tokenStore.Get(info.Owner, binID) if pToken != nil { if pToken.ExpiredAt() <= s.networkState.CurrentEpoch() { var errExpired apistatus.SessionTokenExpired diff --git a/pkg/services/object/util/placement.go b/pkg/services/object/util/placement.go index 1ef96bf7..3e52c398 100644 --- a/pkg/services/object/util/placement.go +++ b/pkg/services/object/util/placement.go @@ -1,15 +1,15 @@ package util import ( - "errors" "fmt" "github.com/nspcc-dev/neofs-node/pkg/core/container" "github.com/nspcc-dev/neofs-node/pkg/core/netmap" "github.com/nspcc-dev/neofs-node/pkg/network" "github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement" + cid "github.com/nspcc-dev/neofs-sdk-go/container/id" netmapSDK "github.com/nspcc-dev/neofs-sdk-go/netmap" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) type localPlacement struct { @@ -43,8 +43,8 @@ func NewLocalPlacement(b placement.Builder, s netmap.AnnouncedKeys) placement.Bu } } -func (p *localPlacement) BuildPlacement(addr *addressSDK.Address, policy *netmapSDK.PlacementPolicy) ([]netmapSDK.Nodes, error) { - vs, err := p.builder.BuildPlacement(addr, policy) +func (p *localPlacement) BuildPlacement(cnr cid.ID, obj *oid.ID, policy *netmapSDK.PlacementPolicy) ([]netmapSDK.Nodes, error) { + vs, err := p.builder.BuildPlacement(cnr, obj, policy) if err != nil { return nil, fmt.Errorf("(%T) could not build object placement: %w", p, err) } @@ -76,8 +76,8 @@ func NewRemotePlacementBuilder(b placement.Builder, s netmap.AnnouncedKeys) plac } } -func (p *remotePlacement) BuildPlacement(addr *addressSDK.Address, policy *netmapSDK.PlacementPolicy) ([]netmapSDK.Nodes, error) { - vs, err := p.builder.BuildPlacement(addr, policy) +func (p *remotePlacement) BuildPlacement(cnr cid.ID, obj *oid.ID, policy *netmapSDK.PlacementPolicy) ([]netmapSDK.Nodes, error) { + vs, err := p.builder.BuildPlacement(cnr, obj, policy) if err != nil { return nil, fmt.Errorf("(%T) could not build object placement: %w", p, err) } @@ -122,12 +122,7 @@ func (g *TraverserGenerator) WithTraverseOptions(opts ...placement.Option) *Trav // GenerateTraverser generates placement Traverser for provided object address // using epoch-th network map. -func (g *TraverserGenerator) GenerateTraverser(addr *addressSDK.Address, epoch uint64) (*placement.Traverser, error) { - idCnr, ok := addr.ContainerID() - if !ok { - return nil, errors.New("missing container in object address") - } - +func (g *TraverserGenerator) GenerateTraverser(idCnr cid.ID, idObj *oid.ID, epoch uint64) (*placement.Traverser, error) { // get network map by epoch nm, err := g.netMapSrc.GetNetMapByEpoch(epoch) if err != nil { @@ -135,7 +130,7 @@ func (g *TraverserGenerator) GenerateTraverser(addr *addressSDK.Address, epoch u } // get container related container - cnr, err := g.cnrSrc.Get(&idCnr) + cnr, err := g.cnrSrc.Get(idCnr) if err != nil { return nil, fmt.Errorf("could not get container: %w", err) } @@ -158,10 +153,10 @@ func (g *TraverserGenerator) GenerateTraverser(addr *addressSDK.Address, epoch u placement.UseBuilder(builder), ) - if idObj, ok := addr.ObjectID(); ok { + if idObj != nil { traverseOpts = append(traverseOpts, // set identifier of the processing object - placement.ForObject(&idObj), + placement.ForObject(*idObj), ) } diff --git a/pkg/services/object_manager/placement/netmap.go b/pkg/services/object_manager/placement/netmap.go index 0ff8fce5..32f1adef 100644 --- a/pkg/services/object_manager/placement/netmap.go +++ b/pkg/services/object_manager/placement/netmap.go @@ -2,13 +2,12 @@ package placement import ( "crypto/sha256" - "errors" "fmt" "github.com/nspcc-dev/neofs-node/pkg/core/netmap" + cid "github.com/nspcc-dev/neofs-sdk-go/container/id" netmapSDK "github.com/nspcc-dev/neofs-sdk-go/netmap" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) type netMapBuilder struct { @@ -37,12 +36,7 @@ func (s *netMapSrc) GetNetMap(diff uint64) (*netmapSDK.Netmap, error) { return s.nm, nil } -func (b *netMapBuilder) BuildPlacement(a *addressSDK.Address, p *netmapSDK.PlacementPolicy) ([]netmapSDK.Nodes, error) { - cnr, ok := a.ContainerID() - if !ok { - return nil, errors.New("missing container in object address") - } - +func (b *netMapBuilder) BuildPlacement(cnr cid.ID, obj *oid.ID, p *netmapSDK.PlacementPolicy) ([]netmapSDK.Nodes, error) { nm, err := netmap.GetLatestNetworkMap(b.nmSrc) if err != nil { return nil, fmt.Errorf("could not get network map: %w", err) @@ -56,16 +50,10 @@ func (b *netMapBuilder) BuildPlacement(a *addressSDK.Address, p *netmapSDK.Place return nil, fmt.Errorf("could not get container nodes: %w", err) } - var idPtr *oidSDK.ID - - if id, ok := a.ObjectID(); ok { - idPtr = &id - } - - return BuildObjectPlacement(nm, cn, idPtr) + return BuildObjectPlacement(nm, cn, obj) } -func BuildObjectPlacement(nm *netmapSDK.Netmap, cnrNodes netmapSDK.ContainerNodes, id *oidSDK.ID) ([]netmapSDK.Nodes, error) { +func BuildObjectPlacement(nm *netmapSDK.Netmap, cnrNodes netmapSDK.ContainerNodes, id *oid.ID) ([]netmapSDK.Nodes, error) { if id == nil { return cnrNodes.Replicas(), nil } diff --git a/pkg/services/object_manager/placement/traverser.go b/pkg/services/object_manager/placement/traverser.go index 7ce07db6..3f78bcfa 100644 --- a/pkg/services/object_manager/placement/traverser.go +++ b/pkg/services/object_manager/placement/traverser.go @@ -7,9 +7,9 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/network" "github.com/nspcc-dev/neofs-sdk-go/container" + cid "github.com/nspcc-dev/neofs-sdk-go/container/id" "github.com/nspcc-dev/neofs-sdk-go/netmap" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) // Builder is an interface of the @@ -20,7 +20,7 @@ type Builder interface { // // Must return all container nodes if object identifier // is nil. - BuildPlacement(*addressSDK.Address, *netmap.PlacementPolicy) ([]netmap.Nodes, error) + BuildPlacement(cid.ID, *oid.ID, *netmap.PlacementPolicy) ([]netmap.Nodes, error) } // Option represents placement traverser option. @@ -41,7 +41,9 @@ type cfg struct { flatSuccess *uint32 - addr *addressSDK.Address + cnr cid.ID + + obj *oid.ID policy *netmap.PlacementPolicy @@ -57,7 +59,6 @@ var errNilPolicy = errors.New("placement policy is nil") func defaultCfg() *cfg { return &cfg{ trackCopies: true, - addr: addressSDK.NewAddress(), } } @@ -77,7 +78,7 @@ func NewTraverser(opts ...Option) (*Traverser, error) { return nil, fmt.Errorf("%s: %w", invalidOptsMsg, errNilPolicy) } - ns, err := cfg.builder.BuildPlacement(cfg.addr, cfg.policy) + ns, err := cfg.builder.BuildPlacement(cfg.cnr, cfg.obj, cfg.policy) if err != nil { return nil, fmt.Errorf("could not build placement: %w", err) } @@ -221,16 +222,14 @@ func UseBuilder(b Builder) Option { func ForContainer(cnr *container.Container) Option { return func(c *cfg) { c.policy = cnr.PlacementPolicy() - c.addr.SetContainerID(container.CalculateID(cnr)) + c.cnr = container.CalculateID(cnr) } } // ForObject is a processing object setting option. -func ForObject(id *oidSDK.ID) Option { +func ForObject(id oid.ID) Option { return func(c *cfg) { - if id != nil { - c.addr.SetObjectID(*id) - } + c.obj = &id } } diff --git a/pkg/services/object_manager/placement/traverser_test.go b/pkg/services/object_manager/placement/traverser_test.go index 6378a062..d2e159f8 100644 --- a/pkg/services/object_manager/placement/traverser_test.go +++ b/pkg/services/object_manager/placement/traverser_test.go @@ -6,8 +6,9 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/network" "github.com/nspcc-dev/neofs-sdk-go/container" + cid "github.com/nspcc-dev/neofs-sdk-go/container/id" "github.com/nspcc-dev/neofs-sdk-go/netmap" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ type testBuilder struct { vectors []netmap.Nodes } -func (b testBuilder) BuildPlacement(*addressSDK.Address, *netmap.PlacementPolicy) ([]netmap.Nodes, error) { +func (b testBuilder) BuildPlacement(cid.ID, *oid.ID, *netmap.PlacementPolicy) ([]netmap.Nodes, error) { return b.vectors, nil } diff --git a/pkg/services/object_manager/storagegroup/collect.go b/pkg/services/object_manager/storagegroup/collect.go index 6232fc75..8b26b270 100644 --- a/pkg/services/object_manager/storagegroup/collect.go +++ b/pkg/services/object_manager/storagegroup/collect.go @@ -5,8 +5,7 @@ import ( "github.com/nspcc-dev/neofs-sdk-go/checksum" 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" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/nspcc-dev/neofs-sdk-go/storagegroup" "github.com/nspcc-dev/tzhash/tz" ) @@ -15,19 +14,19 @@ import ( // with information about members collected via HeadReceiver. // // Resulting storage group consists of physically stored objects only. -func CollectMembers(r objutil.HeadReceiver, cnr *cid.ID, members []oidSDK.ID) (*storagegroup.StorageGroup, error) { +func CollectMembers(r objutil.HeadReceiver, cnr cid.ID, members []oid.ID) (*storagegroup.StorageGroup, error) { var ( sumPhySize uint64 - phyMembers []oidSDK.ID + phyMembers []oid.ID phyHashes [][]byte - addr = addressSDK.NewAddress() + addr oid.Address sg storagegroup.StorageGroup ) - addr.SetContainerID(*cnr) + addr.SetContainer(cnr) for i := range members { - addr.SetObjectID(members[i]) + addr.SetObject(members[i]) if err := objutil.IterateAllSplitLeaves(r, addr, func(leaf *object.Object) { id, ok := leaf.ID() diff --git a/pkg/services/object_manager/tombstone/checker.go b/pkg/services/object_manager/tombstone/checker.go index 7ee3edaf..de59dc00 100644 --- a/pkg/services/object_manager/tombstone/checker.go +++ b/pkg/services/object_manager/tombstone/checker.go @@ -7,7 +7,7 @@ import ( lru "github.com/hashicorp/golang-lru" objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object" "github.com/nspcc-dev/neofs-sdk-go/object" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.uber.org/zap" ) @@ -19,7 +19,7 @@ type Source interface { // // Tombstone MUST return (nil, nil) if requested tombstone is // missing in the storage for the provided epoch. - Tombstone(ctx context.Context, a *addressSDK.Address, epoch uint64) (*object.Object, error) + Tombstone(ctx context.Context, a oid.Address, epoch uint64) (*object.Object, error) } // ExpirationChecker is a tombstone source wrapper. @@ -44,8 +44,8 @@ type ExpirationChecker struct { // // If a tombstone was successfully fetched (regardless of its expiration) // it is cached in the LRU cache. -func (g *ExpirationChecker) IsTombstoneAvailable(ctx context.Context, a *addressSDK.Address, epoch uint64) bool { - addrStr := a.String() +func (g *ExpirationChecker) IsTombstoneAvailable(ctx context.Context, a oid.Address, epoch uint64) bool { + addrStr := a.EncodeToString() log := g.log.With(zap.String("address", addrStr)) expEpoch, ok := g.cache.Get(addrStr) diff --git a/pkg/services/object_manager/tombstone/source/source.go b/pkg/services/object_manager/tombstone/source/source.go index b0a7fd5b..52036f1b 100644 --- a/pkg/services/object_manager/tombstone/source/source.go +++ b/pkg/services/object_manager/tombstone/source/source.go @@ -10,7 +10,7 @@ import ( apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" "github.com/nspcc-dev/neofs-sdk-go/object" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) // Source represents wrapper over the object service that @@ -59,13 +59,13 @@ func (h *headerWriter) WriteHeader(o *objectSDK.Object) error { // Tombstone checks if the engine stores tombstone. // Returns nil, nil if the tombstone has been removed // or marked for removal. -func (s Source) Tombstone(ctx context.Context, a *addressSDK.Address, _ uint64) (*object.Object, error) { +func (s Source) Tombstone(ctx context.Context, a oid.Address, _ uint64) (*object.Object, error) { var hr headerWriter var headPrm getsvc.HeadPrm headPrm.WithAddress(a) headPrm.SetHeaderWriter(&hr) - headPrm.SetCommonParameters(&util.CommonPrm{}) //default values are ok for that operation + headPrm.SetCommonParameters(&util.CommonPrm{}) // default values are ok for that operation err := s.s.Head(ctx, headPrm) switch { diff --git a/pkg/services/object_manager/transformer/fmt.go b/pkg/services/object_manager/transformer/fmt.go index 88677f4c..3ebac97d 100644 --- a/pkg/services/object_manager/transformer/fmt.go +++ b/pkg/services/object_manager/transformer/fmt.go @@ -6,7 +6,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/core/netmap" "github.com/nspcc-dev/neofs-sdk-go/object" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/nspcc-dev/neofs-sdk-go/session" "github.com/nspcc-dev/neofs-sdk-go/version" ) @@ -71,7 +71,7 @@ func (f *formatter) Close() (*AccessIdentifiers, error) { f.obj.SetCreationEpoch(curEpoch) var ( - parID *oidSDK.ID + parID *oid.ID parHdr *object.Object ) @@ -107,7 +107,7 @@ func (f *formatter) Close() (*AccessIdentifiers, error) { id, _ := f.obj.ID() return new(AccessIdentifiers). - WithSelfID(&id). + WithSelfID(id). WithParentID(parID). WithParent(parHdr), nil } diff --git a/pkg/services/object_manager/transformer/transformer.go b/pkg/services/object_manager/transformer/transformer.go index e58765a1..f7e79499 100644 --- a/pkg/services/object_manager/transformer/transformer.go +++ b/pkg/services/object_manager/transformer/transformer.go @@ -8,7 +8,7 @@ import ( "github.com/nspcc-dev/neofs-sdk-go/checksum" "github.com/nspcc-dev/neofs-sdk-go/object" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/nspcc-dev/tzhash/tz" ) @@ -23,7 +23,7 @@ type payloadSizeLimiter struct { currentHashers, parentHashers []*payloadChecksumHasher - previous []oidSDK.ID + previous []oid.ID chunkWriter io.Writer @@ -189,7 +189,7 @@ func (s *payloadSizeLimiter) release(close bool) (*AccessIdentifiers, error) { } // save identifier of the released object - s.previous = append(s.previous, *ids.SelfID()) + s.previous = append(s.previous, ids.SelfID()) if withParent { // generate and release linking object diff --git a/pkg/services/object_manager/transformer/types.go b/pkg/services/object_manager/transformer/types.go index c66f7d2d..1331db91 100644 --- a/pkg/services/object_manager/transformer/types.go +++ b/pkg/services/object_manager/transformer/types.go @@ -4,14 +4,16 @@ import ( "io" "github.com/nspcc-dev/neofs-sdk-go/object" - oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) // AccessIdentifiers represents group of the object identifiers // that are returned after writing the object. // Consists of the ID of the stored object and the ID of the parent object. type AccessIdentifiers struct { - par, self *oidSDK.ID + par *oid.ID + + self oid.ID parHdr *object.Object } @@ -50,16 +52,12 @@ type ObjectTarget interface { type TargetInitializer func() ObjectTarget // SelfID returns identifier of the written object. -func (a *AccessIdentifiers) SelfID() *oidSDK.ID { - if a != nil { - return a.self - } - - return nil +func (a AccessIdentifiers) SelfID() oid.ID { + return a.self } // WithSelfID returns AccessIdentifiers with passed self identifier. -func (a *AccessIdentifiers) WithSelfID(v *oidSDK.ID) *AccessIdentifiers { +func (a *AccessIdentifiers) WithSelfID(v oid.ID) *AccessIdentifiers { res := a if res == nil { res = new(AccessIdentifiers) @@ -71,7 +69,7 @@ func (a *AccessIdentifiers) WithSelfID(v *oidSDK.ID) *AccessIdentifiers { } // ParentID return identifier of the parent of the written object. -func (a *AccessIdentifiers) ParentID() *oidSDK.ID { +func (a *AccessIdentifiers) ParentID() *oid.ID { if a != nil { return a.par } @@ -80,7 +78,7 @@ func (a *AccessIdentifiers) ParentID() *oidSDK.ID { } // WithParentID returns AccessIdentifiers with passed parent identifier. -func (a *AccessIdentifiers) WithParentID(v *oidSDK.ID) *AccessIdentifiers { +func (a *AccessIdentifiers) WithParentID(v *oid.ID) *AccessIdentifiers { res := a if res == nil { res = new(AccessIdentifiers) diff --git a/pkg/services/policer/check.go b/pkg/services/policer/check.go index b3334ca5..4d62380b 100644 --- a/pkg/services/policer/check.go +++ b/pkg/services/policer/check.go @@ -10,14 +10,14 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/services/replicator" "github.com/nspcc-dev/neofs-sdk-go/client" "github.com/nspcc-dev/neofs-sdk-go/netmap" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.uber.org/zap" ) -func (p *Policer) processObject(ctx context.Context, addr *addressSDK.Address) { - idCnr, _ := addr.ContainerID() +func (p *Policer) processObject(ctx context.Context, addr oid.Address) { + idCnr := addr.Container() - cnr, err := p.cnrSrc.Get(&idCnr) + cnr, err := p.cnrSrc.Get(idCnr) if err != nil { p.log.Error("could not get container", zap.Stringer("cid", idCnr), @@ -28,10 +28,9 @@ func (p *Policer) processObject(ctx context.Context, addr *addressSDK.Address) { prm.MarkAsGarbage(addr) _, err := p.jobQueue.localStorage.Inhume(prm) if err != nil { - id, _ := addr.ObjectID() p.log.Error("could not inhume object with missing container", zap.Stringer("cid", idCnr), - zap.Stringer("oid", id), + zap.Stringer("oid", addr.Object()), zap.String("error", err.Error())) } } @@ -40,8 +39,9 @@ func (p *Policer) processObject(ctx context.Context, addr *addressSDK.Address) { } policy := cnr.PlacementPolicy() + obj := addr.Object() - nn, err := p.placementBuilder.BuildPlacement(addr, policy) + nn, err := p.placementBuilder.BuildPlacement(idCnr, &obj, policy) if err != nil { p.log.Error("could not build placement vector for object", zap.String("error", err.Error()), @@ -80,7 +80,7 @@ type processPlacementContext struct { needLocalCopy bool } -func (p *Policer) processNodes(ctx *processPlacementContext, addr *addressSDK.Address, nodes netmap.Nodes, shortage uint32) { +func (p *Policer) processNodes(ctx *processPlacementContext, addr oid.Address, nodes netmap.Nodes, shortage uint32) { log := p.log.With( zap.Stringer("object", addr), ) diff --git a/pkg/services/policer/policer.go b/pkg/services/policer/policer.go index 9dc3f1ce..ac747f58 100644 --- a/pkg/services/policer/policer.go +++ b/pkg/services/policer/policer.go @@ -11,7 +11,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement" "github.com/nspcc-dev/neofs-node/pkg/services/replicator" "github.com/nspcc-dev/neofs-node/pkg/util/logger" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/panjf2000/ants/v2" "go.uber.org/zap" ) @@ -35,7 +35,7 @@ type Option func(*cfg) // RedundantCopyCallback is a callback to pass // the redundant local copy of the object. -type RedundantCopyCallback func(*addressSDK.Address) +type RedundantCopyCallback func(oid.Address) type cfg struct { headTimeout time.Duration diff --git a/pkg/services/policer/process.go b/pkg/services/policer/process.go index 8e5995df..6834d735 100644 --- a/pkg/services/policer/process.go +++ b/pkg/services/policer/process.go @@ -6,7 +6,7 @@ import ( "time" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.uber.org/zap" ) @@ -21,7 +21,7 @@ func (p *Policer) Run(ctx context.Context) { func (p *Policer) shardPolicyWorker(ctx context.Context) { var ( - addrs []*addressSDK.Address + addrs []oid.Address cursor *engine.Cursor err error ) @@ -48,7 +48,7 @@ func (p *Policer) shardPolicyWorker(ctx context.Context) { return default: addr := addrs[i] - addrStr := addr.String() + addrStr := addr.EncodeToString() err = p.taskPool.Submit(func() { v, ok := p.cache.Get(addrStr) if ok && time.Since(v.(time.Time)) < p.evictDuration { diff --git a/pkg/services/policer/queue.go b/pkg/services/policer/queue.go index 3eb7e2ad..8c729749 100644 --- a/pkg/services/policer/queue.go +++ b/pkg/services/policer/queue.go @@ -4,14 +4,14 @@ import ( "fmt" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) type jobQueue struct { localStorage *engine.StorageEngine } -func (q *jobQueue) Select(cursor *engine.Cursor, count uint32) ([]*addressSDK.Address, *engine.Cursor, error) { +func (q *jobQueue) Select(cursor *engine.Cursor, count uint32) ([]oid.Address, *engine.Cursor, error) { prm := new(engine.ListWithCursorPrm) prm.WithCursor(cursor) prm.WithCount(count) diff --git a/pkg/services/replicator/task.go b/pkg/services/replicator/task.go index 308b5579..ad7178bd 100644 --- a/pkg/services/replicator/task.go +++ b/pkg/services/replicator/task.go @@ -2,14 +2,14 @@ package replicator import ( "github.com/nspcc-dev/neofs-sdk-go/netmap" - addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) // Task represents group of Replicator task parameters. type Task struct { quantity uint32 - addr *addressSDK.Address + addr oid.Address nodes netmap.Nodes } @@ -35,7 +35,7 @@ func (t *Task) WithCopiesNumber(v uint32) *Task { } // WithObjectAddress sets address of local object. -func (t *Task) WithObjectAddress(v *addressSDK.Address) *Task { +func (t *Task) WithObjectAddress(v oid.Address) *Task { if t != nil { t.addr = v } diff --git a/pkg/services/session/storage/persistent/executor_test.go b/pkg/services/session/storage/persistent/executor_test.go index ea7933c5..577eab12 100644 --- a/pkg/services/session/storage/persistent/executor_test.go +++ b/pkg/services/session/storage/persistent/executor_test.go @@ -22,7 +22,7 @@ func TestTokenStore(t *testing.T) { defer ts.Close() - owner := usertest.ID() + owner := *usertest.ID() var ownerV2 refs.OwnerID owner.WriteToV2(&ownerV2) @@ -66,7 +66,7 @@ func TestTokenStore_Persistent(t *testing.T) { ts, err := NewTokenStore(path) require.NoError(t, err) - idOwner := usertest.ID() + idOwner := *usertest.ID() var idOwnerV2 refs.OwnerID idOwner.WriteToV2(&idOwnerV2) @@ -127,7 +127,7 @@ func TestTokenStore_RemoveOld(t *testing.T) { defer ts.Close() - owner := usertest.ID() + owner := *usertest.ID() var ownerV2 refs.OwnerID owner.WriteToV2(&ownerV2) diff --git a/pkg/services/session/storage/persistent/storage.go b/pkg/services/session/storage/persistent/storage.go index 65f1e388..4dd9fe82 100644 --- a/pkg/services/session/storage/persistent/storage.go +++ b/pkg/services/session/storage/persistent/storage.go @@ -83,7 +83,7 @@ func NewTokenStore(path string, opts ...Option) (*TokenStore, error) { // Get returns private token corresponding to the given identifiers. // // Returns nil is there is no element in storage. -func (s *TokenStore) Get(ownerID *user.ID, tokenID []byte) (t *storage.PrivateToken) { +func (s *TokenStore) Get(ownerID user.ID, tokenID []byte) (t *storage.PrivateToken) { err := s.db.View(func(tx *bbolt.Tx) error { rootBucket := tx.Bucket(sessionsBucket) diff --git a/pkg/services/session/storage/temporary/storage.go b/pkg/services/session/storage/temporary/storage.go index 7ea5bd1a..10a95af8 100644 --- a/pkg/services/session/storage/temporary/storage.go +++ b/pkg/services/session/storage/temporary/storage.go @@ -36,7 +36,7 @@ func NewTokenStore() *TokenStore { // Get returns private token corresponding to the given identifiers. // // Returns nil is there is no element in storage. -func (s *TokenStore) Get(ownerID *user.ID, tokenID []byte) *storage.PrivateToken { +func (s *TokenStore) Get(ownerID user.ID, tokenID []byte) *storage.PrivateToken { s.mtx.RLock() t := s.tokens[key{ tokenID: base58.Encode(tokenID),