Skip to content

Commit

Permalink
Update multipart (#974)
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-khimov authored Aug 6, 2024
2 parents 2ed8aba + 4abdd83 commit fbdcb2c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 22 deletions.
42 changes: 32 additions & 10 deletions api/layer/multipart_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/nspcc-dev/neofs-sdk-go/object"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
"github.com/nspcc-dev/neofs-sdk-go/user"
"github.com/nspcc-dev/neofs-sdk-go/version"
"github.com/nspcc-dev/tzhash/tz"
"go.uber.org/zap"
"golang.org/x/exp/slices"
Expand Down Expand Up @@ -251,11 +252,10 @@ func (n *layer) uploadPart(ctx context.Context, multipartInfo *data.MultipartInf
}

var (
splitPreviousID oid.ID
splitFirstID oid.ID
isSetSplitPreviousID bool
multipartHash = sha256.New()
tzHash hash.Hash
splitPreviousID oid.ID
splitFirstID oid.ID
multipartHash = sha256.New()
tzHash hash.Hash
)

if n.neoFS.IsHomomorphicHashingEnabled() {
Expand All @@ -281,7 +281,6 @@ func (n *layer) uploadPart(ctx context.Context, multipartInfo *data.MultipartInf
}
}

isSetSplitPreviousID = true
splitPreviousID = lastPart.OID

if err = splitFirstID.DecodeString(multipartInfo.UploadID); err != nil {
Expand Down Expand Up @@ -317,9 +316,7 @@ func (n *layer) uploadPart(ctx context.Context, multipartInfo *data.MultipartInf
var totalBytes int
// slice part manually. Simultaneously considering the part is a single object for user.
for {
if isSetSplitPreviousID {
prm.Multipart.SplitPreviousID = &splitPreviousID
}
prm.Multipart.SplitPreviousID = &splitPreviousID

if !splitFirstID.Equals(oid.ID{}) {
prm.Multipart.SplitFirstID = &splitFirstID
Expand All @@ -337,7 +334,6 @@ func (n *layer) uploadPart(ctx context.Context, multipartInfo *data.MultipartInf
return nil, err
}

isSetSplitPreviousID = true
splitPreviousID = id
elements = append(elements, data.LinkObjectPayload{OID: id, Size: uint32(nBts)})
}
Expand Down Expand Up @@ -451,6 +447,31 @@ func (n *layer) uploadZeroPart(ctx context.Context, multipartInfo *data.Multipar
objHashes = append(objHashes, tzHash)
}

attrs := make([]object.Attribute, 0, len(multipartInfo.Meta)+1)
attrs = append(attrs, *object.NewAttribute(object.AttributeTimestamp, strconv.FormatInt(creationTime.Unix(), 10)))

for key, val := range multipartInfo.Meta {
if strings.HasPrefix(key, metaPrefix) {
attrs = append(attrs, *object.NewAttribute(strings.TrimPrefix(key, metaPrefix), val))
}
}

if encInfo.Enabled {
attrs = append(attrs, *object.NewAttribute(AttributeEncryptionAlgorithm, encInfo.Algorithm))
attrs = append(attrs, *object.NewAttribute(AttributeHMACKey, encInfo.HMACKey))
attrs = append(attrs, *object.NewAttribute(AttributeHMACSalt, encInfo.HMACSalt))
}

var hashlessHeaderObject object.Object
hashlessHeaderObject.SetContainerID(bktInfo.CID)
hashlessHeaderObject.SetType(object.TypeRegular)
hashlessHeaderObject.SetOwnerID(&bktInfo.Owner)
hashlessHeaderObject.SetAttributes(attrs...)
hashlessHeaderObject.SetCreationEpoch(n.neoFS.CurrentEpoch())

currentVersion := version.Current()
hashlessHeaderObject.SetVersion(&currentVersion)

prm := PrmObjectCreate{
Container: bktInfo.CID,
Creator: bktInfo.Owner,
Expand All @@ -459,6 +480,7 @@ func (n *layer) uploadZeroPart(ctx context.Context, multipartInfo *data.Multipar
CopiesNumber: multipartInfo.CopiesNumber,
Multipart: &Multipart{
MultipartHashes: objHashes,
HeaderObject: &hashlessHeaderObject,
},
Payload: bytes.NewBuffer(nil),
}
Expand Down
3 changes: 3 additions & 0 deletions api/layer/neofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,7 @@ type NeoFS interface {

// IsHomomorphicHashingEnabled shows if homomorphic hashing is enabled in config.
IsHomomorphicHashingEnabled() bool

// CurrentEpoch returns current epoch.
CurrentEpoch() uint64
}
10 changes: 4 additions & 6 deletions api/layer/neofs_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,11 @@ func (t *TestNeoFS) CreateObject(_ context.Context, prm PrmObjectCreate) (oid.ID
}

if prm.Multipart.HeaderObject != nil {
id, isSet := prm.Multipart.HeaderObject.ID()
if !isSet {
return oid.ID{}, errors.New("HeaderObject id is not set")
}

obj.SetParentID(id)
obj.SetParent(prm.Multipart.HeaderObject)

if hid, isSet := prm.Multipart.HeaderObject.ID(); isSet {
obj.SetParentID(hid)
}
}

if prm.Multipart.Link != nil {
Expand Down
15 changes: 9 additions & 6 deletions internal/neofs/neofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,11 @@ func (x *NeoFS) CreateObject(ctx context.Context, prm layer.PrmObjectCreate) (oi
}

if prm.Multipart.HeaderObject != nil {
id, isSet := prm.Multipart.HeaderObject.ID()
if !isSet {
return oid.ID{}, errors.New("HeaderObject id is not set")
}

obj.SetParentID(id)
obj.SetParent(prm.Multipart.HeaderObject)

if id, isSet := prm.Multipart.HeaderObject.ID(); isSet {
obj.SetParentID(id)
}
}

if prm.Multipart.Link != nil {
Expand Down Expand Up @@ -539,6 +537,11 @@ func (x *NeoFS) IsHomomorphicHashingEnabled() bool {
return x.cfg.IsHomomorphicEnabled
}

// CurrentEpoch returns current epoch.
func (x *NeoFS) CurrentEpoch() uint64 {
return x.epochGetter.CurrentEpoch()
}

func isErrAccessDenied(err error) (string, bool) {
unwrappedErr := errors.Unwrap(err)
for unwrappedErr != nil {
Expand Down

0 comments on commit fbdcb2c

Please sign in to comment.