Skip to content

Commit

Permalink
layer: Save object nonce only for containers with enabled versions
Browse files Browse the repository at this point in the history
Signed-off-by: Evgenii Baidakov <[email protected]>
  • Loading branch information
smallhive committed Aug 30, 2024
1 parent 550251b commit 16b7476
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 14 deletions.
6 changes: 6 additions & 0 deletions api/layer/cors.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,19 @@ func (n *layer) PutBucketCORS(ctx context.Context, p *PutCORSParams) error {
return err
}

bktSettings, err := n.GetBucketSettings(ctx, p.BktInfo)
if err != nil {
return fmt.Errorf("couldn't get versioning settings object: %w", err)
}

prm := PrmObjectCreate{
Container: p.BktInfo.CID,
Creator: p.BktInfo.Owner,
Payload: &buf,
Filepath: p.BktInfo.CORSObjectName(),
CreationTime: TimeNow(ctx),
CopiesNumber: p.CopiesNumber,
IsVersioned: bktSettings.VersioningEnabled(),
}

objID, _, err := n.objectPutAndHash(ctx, prm, p.BktInfo)
Expand Down
30 changes: 22 additions & 8 deletions api/layer/multipart_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ func (n *layer) uploadPart(ctx context.Context, multipartInfo *data.MultipartInf
objHashes = append(objHashes, tzHash)
}

bktSettings, err := n.GetBucketSettings(ctx, bktInfo)
if err != nil {
return nil, fmt.Errorf("couldn't get versioning settings object: %w", err)
}

prm := PrmObjectCreate{
Container: bktInfo.CID,
Creator: bktInfo.Owner,
Expand All @@ -310,6 +315,7 @@ func (n *layer) uploadPart(ctx context.Context, multipartInfo *data.MultipartInf
Multipart: &Multipart{
MultipartHashes: objHashes,
},
IsVersioned: bktSettings.VersioningEnabled(),
}

chunk := n.buffers.Get().(*[]byte)
Expand Down Expand Up @@ -472,6 +478,11 @@ func (n *layer) uploadZeroPart(ctx context.Context, multipartInfo *data.Multipar
currentVersion := version.Current()
hashlessHeaderObject.SetVersion(&currentVersion)

bktSettings, err := n.GetBucketSettings(ctx, bktInfo)
if err != nil {
return nil, fmt.Errorf("couldn't get versioning settings object: %w", err)
}

prm := PrmObjectCreate{
Container: bktInfo.CID,
Creator: bktInfo.Owner,
Expand All @@ -482,10 +493,11 @@ func (n *layer) uploadZeroPart(ctx context.Context, multipartInfo *data.Multipar
MultipartHashes: objHashes,
HeaderObject: &hashlessHeaderObject,
},
Payload: bytes.NewBuffer(nil),
Payload: bytes.NewBuffer(nil),
IsVersioned: bktSettings.VersioningEnabled(),
}

id, _, err := n.objectPutAndHash(ctx, prm, bktInfo)
id, _, err = n.objectPutAndHash(ctx, prm, bktInfo)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -796,6 +808,11 @@ func (n *layer) CompleteMultipartUpload(ctx context.Context, p *CompleteMultipar
return nil, nil, err
}

bktSettings, err := n.GetBucketSettings(ctx, p.Info.Bkt)
if err != nil {
return nil, nil, fmt.Errorf("couldn't get versioning settings object: %w", err)
}

// last part
prm := PrmObjectCreate{
Container: p.Info.Bkt.CID,
Expand All @@ -808,7 +825,8 @@ func (n *layer) CompleteMultipartUpload(ctx context.Context, p *CompleteMultipar
SplitPreviousID: &splitPreviousID,
HeaderObject: header,
},
Payload: bytes.NewBuffer(nil),
Payload: bytes.NewBuffer(nil),
IsVersioned: bktSettings.VersioningEnabled(),
}

lastPartObjID, _, err := n.objectPutAndHash(ctx, prm, p.Info.Bkt)
Expand All @@ -835,18 +853,14 @@ func (n *layer) CompleteMultipartUpload(ctx context.Context, p *CompleteMultipar
SplitFirstID: &splitFirstID,
Link: &linkObj,
},
IsVersioned: bktSettings.VersioningEnabled(),
}

_, _, err = n.objectPutAndHash(ctx, prm, p.Info.Bkt)
if err != nil {
return nil, nil, err
}

bktSettings, err := n.GetBucketSettings(ctx, p.Info.Bkt)
if err != nil {
return nil, nil, fmt.Errorf("couldn't get versioning settings object: %w", err)
}

headerObjectID, _ := header.ID()

// the "big object" is not presented in system, but we have to put correct info about it and its version.
Expand Down
3 changes: 3 additions & 0 deletions api/layer/neofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ type PrmObjectCreate struct {
CopiesNumber uint32

Multipart *Multipart

// IsVersioned is true if bucket versioning is enabled.
IsVersioned bool
}

// Multipart contains info for local object slicing inside s3-gate during multipart upload operation.
Expand Down
6 changes: 6 additions & 0 deletions api/layer/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,19 @@ func (n *layer) PutBucketNotificationConfiguration(ctx context.Context, p *PutBu
return fmt.Errorf("marshal notify configuration: %w", err)
}

bktSettings, err := n.GetBucketSettings(ctx, p.BktInfo)
if err != nil {
return fmt.Errorf("couldn't get versioning settings object: %w", err)
}

prm := PrmObjectCreate{
Container: p.BktInfo.CID,
Creator: p.BktInfo.Owner,
Payload: bytes.NewReader(confXML),
Filepath: p.BktInfo.NotificationConfigurationObjectName(),
CreationTime: TimeNow(ctx),
CopiesNumber: p.CopiesNumber,
IsVersioned: bktSettings.VersioningEnabled(),
}

objID, _, err := n.objectPutAndHash(ctx, prm, p.BktInfo)
Expand Down
1 change: 1 addition & 0 deletions api/layer/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ func (n *layer) PutObject(ctx context.Context, p *PutObjectParams) (*data.Extend
Payload: r,
CreationTime: TimeNow(ctx),
CopiesNumber: p.CopiesNumber,
IsVersioned: bktSettings.VersioningEnabled(),
}

prm.Attributes = make([][2]string, 0, len(p.Header))
Expand Down
7 changes: 6 additions & 1 deletion api/layer/system_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,20 @@ func (n *layer) getNodeVersionFromCacheOrNeofs(ctx context.Context, objVersion *
}

func (n *layer) putLockObject(ctx context.Context, bktInfo *data.BucketInfo, objID oid.ID, lock *data.ObjectLock, copiesNumber uint32) (oid.ID, error) {
bktSettings, err := n.GetBucketSettings(ctx, bktInfo)
if err != nil {
return oid.ID{}, fmt.Errorf("couldn't get versioning settings object: %w", err)
}

prm := PrmObjectCreate{
Container: bktInfo.CID,
Creator: bktInfo.Owner,
Locks: []oid.ID{objID},
CreationTime: TimeNow(ctx),
CopiesNumber: copiesNumber,
IsVersioned: bktSettings.VersioningEnabled(),
}

var err error
prm.Attributes, err = n.attributesFromLock(ctx, lock)
if err != nil {
return oid.ID{}, err
Expand Down
12 changes: 7 additions & 5 deletions internal/neofs/neofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,14 @@ func (x *NeoFS) CreateObject(ctx context.Context, prm layer.PrmObjectCreate) (oi
attrs = append(attrs, *a)
}

nonce := make([]byte, objectNonceSize)
if _, err := rand.Read(nonce); err != nil {
return oid.ID{}, fmt.Errorf("object nonce: %w", err)
if prm.IsVersioned {
nonce := make([]byte, objectNonceSize)
if _, err := rand.Read(nonce); err != nil {
return oid.ID{}, fmt.Errorf("object nonce: %w", err)
}
objectNonceAttr := object.NewAttribute(objectNonceAttribute, base64.StdEncoding.EncodeToString(nonce))
attrs = append(attrs, *objectNonceAttr)
}
objectNonceAttr := object.NewAttribute(objectNonceAttribute, base64.StdEncoding.EncodeToString(nonce))
attrs = append(attrs, *objectNonceAttr)

var obj object.Object
obj.SetContainerID(prm.Container)
Expand Down

0 comments on commit 16b7476

Please sign in to comment.