[#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 <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2022-05-31 20:00:41 +03:00 committed by LeL
parent cc6209e8a0
commit 1c30414a6c
218 changed files with 2095 additions and 2521 deletions

View file

@ -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)

View file

@ -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
}

View file

@ -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
}

View file

@ -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)

View file

@ -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])
}
}

View file

@ -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)

View file

@ -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"))
}
}

View file

@ -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)

View file

@ -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 = "<empty>"
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
}

View file

@ -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 = "<empty>"
}
tomb := res.Tombstone()
cmd.Println("Storage group removed successfully.")
cmd.Printf(" Tombstone: %s\n", strID)
cmd.Printf(" Tombstone: %s\n", tomb)
}

View file

@ -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

View file

@ -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
}

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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),

View file

@ -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
}

View file

@ -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

4
go.mod
View file

@ -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

8
go.sum
View file

@ -397,8 +397,8 @@ github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220321144137-d5a9af5860af h1:QO
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220321144137-d5a9af5860af/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
github.com/nspcc-dev/neofs-api-go/v2 v2.11.0-pre.0.20211201134523-3604d96f3fe1/go.mod h1:oS8dycEh8PPf2Jjp6+8dlwWyEv2Dy77h/XhhcdxYEFs=
github.com/nspcc-dev/neofs-api-go/v2 v2.11.1/go.mod h1:oS8dycEh8PPf2Jjp6+8dlwWyEv2Dy77h/XhhcdxYEFs=
github.com/nspcc-dev/neofs-api-go/v2 v2.12.1 h1:PVU2rLlG9S0jDe5eKyaUs4nKo/la+mN5pvz32Gib3qM=
github.com/nspcc-dev/neofs-api-go/v2 v2.12.1/go.mod h1:73j09Xa7I2zQbM3HCvAHnDHPYiiWnEHa1d6Z6RDMBLU=
github.com/nspcc-dev/neofs-api-go/v2 v2.12.2-0.20220530190258-c82dcf7e1610 h1:JwrxHWQJSOxx0LvnEvFj3MpKjWQAPXOq55uuGimghR0=
github.com/nspcc-dev/neofs-api-go/v2 v2.12.2-0.20220530190258-c82dcf7e1610/go.mod h1:73j09Xa7I2zQbM3HCvAHnDHPYiiWnEHa1d6Z6RDMBLU=
github.com/nspcc-dev/neofs-contract v0.15.1 h1:1r27t4SGKF7W1PRPOIfircEXHvALThNYNagT+SIabcA=
github.com/nspcc-dev/neofs-contract v0.15.1/go.mod h1:kxO5ZTqdzFnRM5RMvM+Fhd+3GGrJo6AmG2ZyA9OCqqQ=
github.com/nspcc-dev/neofs-crypto v0.2.0/go.mod h1:F/96fUzPM3wR+UGsPi3faVNmFlA9KAEAUQR7dMxZmNA=
@ -407,8 +407,8 @@ github.com/nspcc-dev/neofs-crypto v0.3.0 h1:zlr3pgoxuzrmGCxc5W8dGVfA9Rro8diFvVnB
github.com/nspcc-dev/neofs-crypto v0.3.0/go.mod h1:8w16GEJbH6791ktVqHN9YRNH3s9BEEKYxGhlFnp0cDw=
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20211201182451-a5b61c4f6477/go.mod h1:dfMtQWmBHYpl9Dez23TGtIUKiFvCIxUZq/CkSIhEpz4=
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20220113123743-7f3162110659/go.mod h1:/jay1lr3w7NQd/VDBkEhkJmDmyPNsu4W+QV2obsUV40=
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.3.0.20220526065457-bef4618cd6b9 h1:TV2/sp/2CY7h7R2MJfU7HYDvXjKGAcOMJvpmV/w4lFk=
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.3.0.20220526065457-bef4618cd6b9/go.mod h1:u567oWTnAyGXbPWMrbcN0NB5zCPF+PqkaKg+vcijcho=
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.3.0.20220531091404-82d762f536a3 h1:AjuzmxXE32Gm/fCvKyRc40Qwqs45J8QSpA7sBR+VD4c=
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.3.0.20220531091404-82d762f536a3/go.mod h1:ci0d8ppgduRvrAhZVGKj6PhuOiVpvKnlDvSlDI9hkJk=
github.com/nspcc-dev/rfc6979 v0.1.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso=
github.com/nspcc-dev/rfc6979 v0.2.0 h1:3e1WNxrN60/6N0DW7+UYisLeZJyfqZTNOjeV/toYvOE=
github.com/nspcc-dev/rfc6979 v0.2.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso=

View file

@ -8,7 +8,7 @@ import (
// RemovalWitness groups the information required
// to prove and verify the removal of a container.
type RemovalWitness struct {
cid *cid.ID
cnr cid.ID
sig []byte
@ -17,14 +17,14 @@ type RemovalWitness struct {
// ContainerID returns the identifier of the container
// to be removed.
func (x RemovalWitness) ContainerID() *cid.ID {
return x.cid
func (x RemovalWitness) ContainerID() cid.ID {
return x.cnr
}
// SetContainerID sets the identifier of the container
// to be removed.
func (x *RemovalWitness) SetContainerID(id *cid.ID) {
x.cid = id
func (x *RemovalWitness) SetContainerID(id cid.ID) {
x.cnr = id
}
// Signature returns the signature of the container identifier.

View file

@ -27,10 +27,10 @@ func TestCheckFormat(t *testing.T) {
require.Error(t, CheckFormat(c))
var oid user.ID
user.IDFromKey(&oid, test.DecodeKey(-1).PublicKey)
var idUser user.ID
user.IDFromKey(&idUser, test.DecodeKey(-1).PublicKey)
c.SetOwnerID(&oid)
c.SetOwnerID(&idUser)
// set incorrect nonce
cV2 := c.ToV2()

View file

@ -19,7 +19,7 @@ type Source interface {
//
// Implementations must not retain the container pointer and modify
// the container through it.
Get(*cid.ID) (*container.Container, error)
Get(cid.ID) (*container.Container, error)
}
// IsErrNotFound checks if the error returned by Source.Get corresponds

View file

@ -12,7 +12,6 @@ import (
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
neofsecdsa "github.com/nspcc-dev/neofs-sdk-go/crypto/ecdsa"
"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/storagegroup"
"github.com/nspcc-dev/neofs-sdk-go/user"
@ -40,7 +39,7 @@ type DeleteHandler interface {
//
// Returns apistatus.LockNonRegularObject if at least one object
// is locked.
DeleteObjects(*addressSDK.Address, ...*addressSDK.Address) error
DeleteObjects(oid.Address, ...oid.Address) error
}
// Locker is an object lock storage interface.
@ -100,6 +99,10 @@ func (v *FormatValidator) Validate(obj *object.Object, unprepared bool) error {
return errNilCID
}
if err := v.checkOwner(obj); err != nil {
return err
}
if err := v.checkAttributes(obj); err != nil {
return fmt.Errorf("invalid attributes: %w", err)
}
@ -149,7 +152,7 @@ func (v *FormatValidator) validateSignatureKey(obj *object.Object) error {
token := obj.SessionToken()
if token == nil || !token.AssertAuthKey(&key) {
return v.checkOwnerKey(obj.OwnerID(), key)
return v.checkOwnerKey(*obj.OwnerID(), key)
}
// FIXME: #1159 perform token verification
@ -157,7 +160,7 @@ func (v *FormatValidator) validateSignatureKey(obj *object.Object) error {
return nil
}
func (v *FormatValidator) checkOwnerKey(id *user.ID, key neofsecdsa.PublicKey) error {
func (v *FormatValidator) checkOwnerKey(id user.ID, key neofsecdsa.PublicKey) error {
var id2 user.ID
user.IDFromKey(&id2, (ecdsa.PublicKey)(key))
@ -201,14 +204,11 @@ func (v *FormatValidator) ValidateContent(o *object.Object) error {
}
idList := tombstone.Members()
addrList := make([]*addressSDK.Address, 0, len(idList))
addrList := make([]oid.Address, len(idList))
for i := range idList {
a := addressSDK.NewAddress()
a.SetContainerID(cnr)
a.SetObjectID(idList[i])
addrList = append(addrList, a)
addrList[i].SetContainer(cnr)
addrList[i].SetObject(idList[i])
}
if v.deleteHandler != nil {

View file

@ -11,7 +11,7 @@ import (
objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object"
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
"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"
oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test"
sessiontest "github.com/nspcc-dev/neofs-sdk-go/session/test"
"github.com/nspcc-dev/neofs-sdk-go/storagegroup"
@ -117,7 +117,7 @@ func TestFormatValidator_Validate(t *testing.T) {
require.Error(t, v.ValidateContent(obj)) // no tombstone content
content := object.NewTombstone()
content.SetMembers([]oidSDK.ID{oidtest.ID()})
content.SetMembers([]oid.ID{oidtest.ID()})
data, err := content.Marshal()
require.NoError(t, err)
@ -126,7 +126,7 @@ func TestFormatValidator_Validate(t *testing.T) {
require.Error(t, v.ValidateContent(obj)) // no members in tombstone
content.SetMembers([]oidSDK.ID{oidtest.ID()})
content.SetMembers([]oid.ID{oidtest.ID()})
data, err = content.Marshal()
require.NoError(t, err)
@ -167,7 +167,7 @@ func TestFormatValidator_Validate(t *testing.T) {
require.Error(t, v.ValidateContent(obj))
content.SetMembers([]oidSDK.ID{oidtest.ID()})
content.SetMembers([]oid.ID{oidtest.ID()})
data, err = content.Marshal()
require.NoError(t, err)

View file

@ -2,26 +2,22 @@ package object
import (
"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"
)
// AddressOf returns the address of the object.
func AddressOf(obj *object.Object) *addressSDK.Address {
if obj != nil {
addr := addressSDK.NewAddress()
func AddressOf(obj *object.Object) oid.Address {
var addr oid.Address
id, ok := obj.ID()
if ok {
addr.SetObjectID(id)
}
cnr, ok := obj.ContainerID()
if ok {
addr.SetContainerID(cnr)
}
return addr
id, ok := obj.ID()
if ok {
addr.SetObject(id)
}
return nil
cnr, ok := obj.ContainerID()
if ok {
addr.SetContainer(cnr)
}
return addr
}

View file

@ -13,7 +13,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"
)
@ -38,11 +37,11 @@ func (x *Client) SetPrivateKey(key *ecdsa.PrivateKey) {
type SearchSGPrm struct {
contextPrm
cnrID *cid.ID
cnrID cid.ID
}
// SetContainerID sets the ID of the container to search for storage groups.
func (x *SearchSGPrm) SetContainerID(id *cid.ID) {
func (x *SearchSGPrm) SetContainerID(id cid.ID) {
x.cnrID = id
}
@ -63,8 +62,7 @@ var sgFilter = storagegroup.SearchQuery()
// Returns any error which prevented the operation from completing correctly in error return.
func (x Client) SearchSG(prm SearchSGPrm) (*SearchSGRes, error) {
var cliPrm client.PrmObjectSearch
cliPrm.InContainer(*prm.cnrID)
cliPrm.InContainer(prm.cnrID)
cliPrm.SetFilters(sgFilter)
rdr, err := x.c.ObjectSearchInit(prm.ctx, cliPrm)
@ -124,14 +122,8 @@ func (x GetObjectRes) Object() *object.Object {
// Returns any error which prevented the operation from completing correctly in error return.
func (x Client) GetObject(prm GetObjectPrm) (*GetObjectRes, error) {
var cliPrm client.PrmObjectGet
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())
rdr, err := x.c.ObjectGetInit(prm.ctx, cliPrm)
if err != nil {
@ -210,13 +202,8 @@ func (x Client) HeadObject(prm HeadObjectPrm) (*HeadObjectRes, error) {
cliPrm.MarkLocal()
}
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())
cliRes, err := x.c.ObjectHead(prm.ctx, cliPrm)
if err == nil {
@ -242,7 +229,7 @@ func (x Client) HeadObject(prm HeadObjectPrm) (*HeadObjectRes, error) {
// GetObjectPayload reads an object by address from NeoFS via Client and returns its payload.
//
// Returns any error which prevented the operation from completing correctly in error return.
func GetObjectPayload(ctx context.Context, c Client, addr *addressSDK.Address) ([]byte, error) {
func GetObjectPayload(ctx context.Context, c Client, addr oid.Address) ([]byte, error) {
var prm GetObjectPrm
prm.SetContext(ctx)
@ -256,7 +243,7 @@ func GetObjectPayload(ctx context.Context, c Client, addr *addressSDK.Address) (
return obj.Object().Payload(), nil
}
func headObject(ctx context.Context, c Client, addr *addressSDK.Address, raw bool, ttl uint32) (*object.Object, error) {
func headObject(ctx context.Context, c Client, addr oid.Address, raw bool, ttl uint32) (*object.Object, error) {
var prm HeadObjectPrm
prm.SetContext(ctx)
@ -276,13 +263,13 @@ func headObject(ctx context.Context, c Client, addr *addressSDK.Address, raw boo
}
// GetRawObjectHeaderLocally reads the raw short object header from the server's local storage by address via Client.
func GetRawObjectHeaderLocally(ctx context.Context, c Client, addr *addressSDK.Address) (*object.Object, error) {
func GetRawObjectHeaderLocally(ctx context.Context, c Client, addr oid.Address) (*object.Object, error) {
return headObject(ctx, c, addr, true, 1)
}
// GetObjectHeaderFromContainer reads the short object header by address via Client with TTL = 10
// for deep traversal of the container.
func GetObjectHeaderFromContainer(ctx context.Context, c Client, addr *addressSDK.Address) (*object.Object, error) {
func GetObjectHeaderFromContainer(ctx context.Context, c Client, addr oid.Address) (*object.Object, error) {
return headObject(ctx, c, addr, false, 10)
}
@ -314,15 +301,8 @@ func (x HashPayloadRangeRes) Hash() []byte {
// Returns any error which prevented the operation from completing correctly in error return.
func (x Client) HashPayloadRange(prm HashPayloadRangePrm) (res HashPayloadRangeRes, err 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())
cliPrm.SetRangeList(prm.rng.GetOffset(), prm.rng.GetLength())
cliPrm.TillichZemorAlgo()
@ -349,7 +329,7 @@ func (x Client) HashPayloadRange(prm HashPayloadRangePrm) (res HashPayloadRangeR
// from the remote server's local storage via Client.
//
// Returns any error which prevented the operation from completing correctly in error return.
func HashObjectRange(ctx context.Context, c Client, addr *addressSDK.Address, rng *object.Range) ([]byte, error) {
func HashObjectRange(ctx context.Context, c Client, addr oid.Address, rng *object.Range) ([]byte, error) {
var prm HashPayloadRangePrm
prm.SetContext(ctx)

View file

@ -3,7 +3,7 @@ package neofsapiclient
import (
"context"
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
)
type contextPrm struct {
@ -16,11 +16,11 @@ func (x *contextPrm) SetContext(ctx context.Context) {
}
type objectAddressPrm struct {
objAddr *addressSDK.Address
objAddr oid.Address
}
// SetAddress sets address of the object.
func (x *objectAddressPrm) SetAddress(addr *addressSDK.Address) {
func (x *objectAddressPrm) SetAddress(addr oid.Address) {
x.objAddr = addr
}

View file

@ -11,7 +11,7 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/util/rand"
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"
"go.uber.org/zap"
)
@ -110,8 +110,8 @@ func (ap *Processor) processStartAudit(epoch uint64) {
}
}
func (ap *Processor) findStorageGroups(cid *cid.ID, shuffled netmap.Nodes) []oidSDK.ID {
var sg []oidSDK.ID
func (ap *Processor) findStorageGroups(cnr cid.ID, shuffled netmap.Nodes) []oid.ID {
var sg []oid.ID
ln := len(shuffled)
@ -120,11 +120,11 @@ func (ap *Processor) findStorageGroups(cid *cid.ID, shuffled netmap.Nodes) []oid
prm SearchSGPrm
)
prm.id = cid
prm.id = cnr
for i := range shuffled { // consider iterating over some part of container
log := ap.log.With(
zap.Stringer("cid", cid),
zap.Stringer("cid", cnr),
zap.String("key", hex.EncodeToString(shuffled[0].PublicKey())),
zap.Int("try", i),
zap.Int("total_tries", ln),

View file

@ -13,7 +13,7 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/nspcc-dev/neofs-node/pkg/services/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"
"github.com/panjf2000/ants/v2"
"go.uber.org/zap"
)
@ -67,7 +67,7 @@ type (
type SearchSGPrm struct {
ctx context.Context
id *cid.ID
id cid.ID
info client.NodeInfo
}
@ -78,7 +78,7 @@ func (x SearchSGPrm) Context() context.Context {
}
// CID returns the identifier of the container to search SG in.
func (x SearchSGPrm) CID() *cid.ID {
func (x SearchSGPrm) CID() cid.ID {
return x.id
}
@ -89,11 +89,11 @@ func (x SearchSGPrm) NodeInfo() client.NodeInfo {
// SearchSGDst groups the target values which Processor expects from SG searching to process.
type SearchSGDst struct {
ids []oidSDK.ID
ids []oid.ID
}
// WriteIDList writes a list of identifiers of storage group objects stored in the container.
func (x *SearchSGDst) WriteIDList(ids []oidSDK.ID) {
func (x *SearchSGDst) WriteIDList(ids []oid.ID) {
x.ids = ids
}

View file

@ -12,7 +12,7 @@ import (
var ErrInvalidIRNode = errors.New("node is not in the inner ring list")
func (ap *Processor) selectContainersToAudit(epoch uint64) ([]*cid.ID, error) {
func (ap *Processor) selectContainersToAudit(epoch uint64) ([]cid.ID, error) {
containers, err := ap.containerClient.List(nil)
if err != nil {
return nil, fmt.Errorf("can't get list of containers to start audit: %w", err)
@ -25,7 +25,7 @@ func (ap *Processor) selectContainersToAudit(epoch uint64) ([]*cid.ID, error) {
)
sort.Slice(containers, func(i, j int) bool {
return strings.Compare(containers[i].String(), containers[j].String()) < 0
return strings.Compare(containers[i].EncodeToString(), containers[j].EncodeToString()) < 0
})
ind := ap.irList.InnerRingIndex()
@ -38,7 +38,7 @@ func (ap *Processor) selectContainersToAudit(epoch uint64) ([]*cid.ID, error) {
return Select(containers, epoch, uint64(ind), uint64(irSize)), nil
}
func Select(ids []*cid.ID, epoch, index, size uint64) []*cid.ID {
func Select(ids []cid.ID, epoch, index, size uint64) []cid.ID {
if index >= size {
return nil
}

View file

@ -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

View file

@ -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 {

View file

@ -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)

View file

@ -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)
}

View file

@ -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 {

View file

@ -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

View file

@ -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,
})
}

View file

@ -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 {

View file

@ -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),
})
})

View file

@ -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)
}

View file

@ -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 {

View file

@ -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

View file

@ -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)
}

View file

@ -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)

View file

@ -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
}

View file

@ -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
}

View file

@ -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()

View file

@ -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)

View file

@ -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))
}

View file

@ -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))

View file

@ -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++ {

View file

@ -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]

View file

@ -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())

View file

@ -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) {

View file

@ -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()))
})
}

View file

@ -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 {

View file

@ -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
})

View file

@ -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 {

View file

@ -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
}

View file

@ -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)
}

View file

@ -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...)
}

View file

@ -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)

View file

@ -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

View file

@ -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),
)

View file

@ -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),

View file

@ -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)

View file

@ -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)

View file

@ -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)
})

View file

@ -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()

View file

@ -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
}

View file

@ -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

View file

@ -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)
}

View file

@ -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),

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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))
}

View file

@ -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)

View file

@ -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))

View file

@ -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

View file

@ -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))

View file

@ -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
}

View file

@ -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()

View file

@ -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)
}

View file

@ -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))
})

View file

@ -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

View file

@ -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)).

View file

@ -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
}

View file

@ -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)

View file

@ -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
}

View file

@ -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
})

View file

@ -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

View file

@ -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
}

View file

@ -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 {

View file

@ -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)
})
}

View file

@ -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{

View file

@ -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 {

View file

@ -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)

Some files were not shown because too many files have changed in this diff Show more