Skip to content

Commit fbdcb2c

Browse files
authored
Update multipart (#974)
2 parents 2ed8aba + 4abdd83 commit fbdcb2c

File tree

4 files changed

+48
-22
lines changed

4 files changed

+48
-22
lines changed

api/layer/multipart_upload.go

+32-10
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/nspcc-dev/neofs-sdk-go/object"
2525
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
2626
"github.com/nspcc-dev/neofs-sdk-go/user"
27+
"github.com/nspcc-dev/neofs-sdk-go/version"
2728
"github.com/nspcc-dev/tzhash/tz"
2829
"go.uber.org/zap"
2930
"golang.org/x/exp/slices"
@@ -251,11 +252,10 @@ func (n *layer) uploadPart(ctx context.Context, multipartInfo *data.MultipartInf
251252
}
252253

253254
var (
254-
splitPreviousID oid.ID
255-
splitFirstID oid.ID
256-
isSetSplitPreviousID bool
257-
multipartHash = sha256.New()
258-
tzHash hash.Hash
255+
splitPreviousID oid.ID
256+
splitFirstID oid.ID
257+
multipartHash = sha256.New()
258+
tzHash hash.Hash
259259
)
260260

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

284-
isSetSplitPreviousID = true
285284
splitPreviousID = lastPart.OID
286285

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

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

340-
isSetSplitPreviousID = true
341337
splitPreviousID = id
342338
elements = append(elements, data.LinkObjectPayload{OID: id, Size: uint32(nBts)})
343339
}
@@ -451,6 +447,31 @@ func (n *layer) uploadZeroPart(ctx context.Context, multipartInfo *data.Multipar
451447
objHashes = append(objHashes, tzHash)
452448
}
453449

450+
attrs := make([]object.Attribute, 0, len(multipartInfo.Meta)+1)
451+
attrs = append(attrs, *object.NewAttribute(object.AttributeTimestamp, strconv.FormatInt(creationTime.Unix(), 10)))
452+
453+
for key, val := range multipartInfo.Meta {
454+
if strings.HasPrefix(key, metaPrefix) {
455+
attrs = append(attrs, *object.NewAttribute(strings.TrimPrefix(key, metaPrefix), val))
456+
}
457+
}
458+
459+
if encInfo.Enabled {
460+
attrs = append(attrs, *object.NewAttribute(AttributeEncryptionAlgorithm, encInfo.Algorithm))
461+
attrs = append(attrs, *object.NewAttribute(AttributeHMACKey, encInfo.HMACKey))
462+
attrs = append(attrs, *object.NewAttribute(AttributeHMACSalt, encInfo.HMACSalt))
463+
}
464+
465+
var hashlessHeaderObject object.Object
466+
hashlessHeaderObject.SetContainerID(bktInfo.CID)
467+
hashlessHeaderObject.SetType(object.TypeRegular)
468+
hashlessHeaderObject.SetOwnerID(&bktInfo.Owner)
469+
hashlessHeaderObject.SetAttributes(attrs...)
470+
hashlessHeaderObject.SetCreationEpoch(n.neoFS.CurrentEpoch())
471+
472+
currentVersion := version.Current()
473+
hashlessHeaderObject.SetVersion(&currentVersion)
474+
454475
prm := PrmObjectCreate{
455476
Container: bktInfo.CID,
456477
Creator: bktInfo.Owner,
@@ -459,6 +480,7 @@ func (n *layer) uploadZeroPart(ctx context.Context, multipartInfo *data.Multipar
459480
CopiesNumber: multipartInfo.CopiesNumber,
460481
Multipart: &Multipart{
461482
MultipartHashes: objHashes,
483+
HeaderObject: &hashlessHeaderObject,
462484
},
463485
Payload: bytes.NewBuffer(nil),
464486
}

api/layer/neofs.go

+3
Original file line numberDiff line numberDiff line change
@@ -250,4 +250,7 @@ type NeoFS interface {
250250

251251
// IsHomomorphicHashingEnabled shows if homomorphic hashing is enabled in config.
252252
IsHomomorphicHashingEnabled() bool
253+
254+
// CurrentEpoch returns current epoch.
255+
CurrentEpoch() uint64
253256
}

api/layer/neofs_mock.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,11 @@ func (t *TestNeoFS) CreateObject(_ context.Context, prm PrmObjectCreate) (oid.ID
280280
}
281281

282282
if prm.Multipart.HeaderObject != nil {
283-
id, isSet := prm.Multipart.HeaderObject.ID()
284-
if !isSet {
285-
return oid.ID{}, errors.New("HeaderObject id is not set")
286-
}
287-
288-
obj.SetParentID(id)
289283
obj.SetParent(prm.Multipart.HeaderObject)
284+
285+
if hid, isSet := prm.Multipart.HeaderObject.ID(); isSet {
286+
obj.SetParentID(hid)
287+
}
290288
}
291289

292290
if prm.Multipart.Link != nil {

internal/neofs/neofs.go

+9-6
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,11 @@ func (x *NeoFS) CreateObject(ctx context.Context, prm layer.PrmObjectCreate) (oi
284284
}
285285

286286
if prm.Multipart.HeaderObject != nil {
287-
id, isSet := prm.Multipart.HeaderObject.ID()
288-
if !isSet {
289-
return oid.ID{}, errors.New("HeaderObject id is not set")
290-
}
291-
292-
obj.SetParentID(id)
293287
obj.SetParent(prm.Multipart.HeaderObject)
288+
289+
if id, isSet := prm.Multipart.HeaderObject.ID(); isSet {
290+
obj.SetParentID(id)
291+
}
294292
}
295293

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

540+
// CurrentEpoch returns current epoch.
541+
func (x *NeoFS) CurrentEpoch() uint64 {
542+
return x.epochGetter.CurrentEpoch()
543+
}
544+
542545
func isErrAccessDenied(err error) (string, bool) {
543546
unwrappedErr := errors.Unwrap(err)
544547
for unwrappedErr != nil {

0 commit comments

Comments
 (0)