Skip to content

Commit

Permalink
uplink,private/{metaclient,object}: add retention info to download info
Browse files Browse the repository at this point in the history
This change includes the retention mode and retention period expiration
in the download info for versioned objects. This makes it possible for
the gateway to return retention info via the GetObject and HeadObject
S3 actions.

Change-Id: Id2594240b8072de1a3f01ec20946044cf73b6986
  • Loading branch information
jewharton committed Apr 24, 2024
1 parent ac2a872 commit 9a8ce9b
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 10 deletions.
20 changes: 15 additions & 5 deletions download.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (project *Project) downloadObjectWithVersion(ctx context.Context, bucket, k
}
download.streams = streams

download.object = convertObject(&objectDownload.Object)
download.object = &objectDownload.Object
download.download = stream.NewDownloadRange(ctx, objectDownload, streams, streamRange.Start, streamRange.Limit-streamRange.Start)
download.tracker = project.tracker.Child("download", 1)
return download, nil
Expand All @@ -133,7 +133,7 @@ func (project *Project) downloadObjectWithVersion(ctx context.Context, bucket, k
type Download struct {
mu sync.Mutex
download *stream.Download
object *Object
object *metaclient.Object
bucket string
streams *streams.Store

Expand All @@ -149,7 +149,7 @@ type Download struct {

// Info returns the last information about the object.
func (download *Download) Info() *Object {
return download.object
return convertObject(download.object)
}

// Read downloads up to len(p) bytes into p from the object's data stream.
Expand All @@ -167,7 +167,7 @@ func (download *Download) Read(p []byte) (n int, err error) {
}
track()
download.mu.Unlock()
return n, convertKnownErrors(err, download.bucket, download.object.Key)
return n, convertKnownErrors(err, download.bucket, download.object.Path)
}

// Close closes the reader of the download.
Expand All @@ -183,7 +183,7 @@ func (download *Download) Close() error {
download.stats.flagFailure(err)
download.emitEvent()
download.mu.Unlock()
return convertKnownErrors(err, download.bucket, download.object.Key)
return convertKnownErrors(err, download.bucket, download.object.Path)
}

func pathChecksum(encPath paths.Encrypted) []byte {
Expand Down Expand Up @@ -232,3 +232,13 @@ func (download *Download) emitEvent() {
func downloadObjectWithVersion(ctx context.Context, project *Project, bucket, key string, version []byte, options *DownloadOptions) (_ *Download, err error) {
return project.downloadObjectWithVersion(ctx, bucket, key, version, options)
}

// download_getMetaclientObject exposes the object downloaded from the metainfo database.
//
// NB: this is used with linkname in private/object.
// It needs to be updated when this is updated.
//
//lint:ignore U1000, used with linkname
//nolint:deadcode,unused
//go:linkname download_getMetaclientObject
func download_getMetaclientObject(dl *Download) *metaclient.Object { return dl.object }
4 changes: 2 additions & 2 deletions object.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ func (project *Project) UpdateObjectMetadata(ctx context.Context, bucket, key st
return nil
}

// convertObject converts metainfo.Object to uplink.Object.
// convertObject converts metaclient.Object to uplink.Object.
func convertObject(obj *metaclient.Object) *Object {
if obj.Bucket.Name == "" { // zero object
if obj == nil || obj.Bucket.Name == "" { // nil or zero object
return nil
}

Expand Down
7 changes: 7 additions & 0 deletions private/metaclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,13 @@ func newObjectInfo(object *pb.Object) RawObjectItem {
EncryptedMetadataEncryptedKey: object.EncryptedMetadataEncryptedKey,
}

if object.Retention != nil {
info.Retention = &Retention{
Mode: storj.RetentionMode(object.Retention.Mode),
RetainUntil: object.Retention.RetainUntil,
}
}

if object.EncryptionParameters != nil {
info.EncryptionParameters = storj.EncryptionParameters{
CipherSuite: storj.CipherSuite(object.EncryptionParameters.CipherSuite),
Expand Down
2 changes: 2 additions & 0 deletions private/metaclient/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,8 @@ func (db *DB) ObjectFromRawObjectItem(ctx context.Context, bucket, key string, o
Modified: objectInfo.Created, // TODO: use correct field
Expires: objectInfo.Expires, // TODO: use correct field

Retention: objectInfo.Retention,

Stream: Stream{
ID: objectInfo.StreamID,

Expand Down
10 changes: 10 additions & 0 deletions private/metaclient/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ type RawObjectItem struct {

EncryptionParameters storj.EncryptionParameters
RedundancyScheme storj.RedundancyScheme

Retention *Retention
}

// Retention represents an object's Object Lock retention information.
type Retention struct {
Mode storj.RetentionMode
RetainUntil time.Time
}

// IsDeleteMarker returns true if object is a delete marker.
Expand Down Expand Up @@ -127,6 +135,8 @@ type Object struct {
Modified time.Time
Expires time.Time

Retention *Retention

Stream
}

Expand Down
10 changes: 7 additions & 3 deletions private/object/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type VersionedObject struct {
uplink.Object
Version []byte
IsDeleteMarker bool
Retention *metaclient.Retention
}

// VersionedUpload represents upload which returnes object version at the end.
Expand Down Expand Up @@ -94,8 +95,7 @@ type VersionedDownload struct {

// Info returns the last information about the object.
func (download *VersionedDownload) Info() *VersionedObject {
info := download.download.Info()
return convertUplinkObject(info)
return convertObject(download_getMetaclientObject(download.download))
}

// Read downloads up to len(p) bytes into p from the object's data stream.
Expand Down Expand Up @@ -283,7 +283,7 @@ func CopyObject(ctx context.Context, project *uplink.Project, sourceBucket, sour

// convertObject converts metainfo.Object to Version.
func convertObject(obj *metaclient.Object) *VersionedObject {
if obj.Bucket.Name == "" { // zero object
if obj == nil || obj.Bucket.Name == "" { // nil or zero object
return nil
}

Expand All @@ -300,6 +300,7 @@ func convertObject(obj *metaclient.Object) *VersionedObject {
},
Version: obj.Version,
IsDeleteMarker: obj.IsDeleteMarker,
Retention: obj.Retention,
}
}

Expand Down Expand Up @@ -336,3 +337,6 @@ func objectVersion(object *uplink.Object) []byte

//go:linkname downloadObjectWithVersion storj.io/uplink.downloadObjectWithVersion
func downloadObjectWithVersion(ctx context.Context, project *uplink.Project, bucket, key string, version []byte, options *uplink.DownloadOptions) (_ *uplink.Download, err error)

//go:linkname download_getMetaclientObject storj.io/uplink.download_getMetaclientObject
func download_getMetaclientObject(dl *uplink.Download) *metaclient.Object

0 comments on commit 9a8ce9b

Please sign in to comment.