satellite/metainfo: support getting specific object version

Protobuf definition is read to support getting specific version of
object so we just need to wire requested version into metainfo.GetObject
endpoint.

https://github.com/storj/storj/issues/6221

Change-Id: If4568b82119a6c893788a0a86e598b05ff5951cf
This commit is contained in:
Michal Niewrzal 2023-09-12 11:50:19 +02:00 committed by Michał Niewrzał
parent 4e4da7be6d
commit e21978f11a
2 changed files with 40 additions and 7 deletions

View File

@ -12,6 +12,7 @@ import (
"github.com/jtolio/eventkit"
"github.com/spacemonkeygo/monkit/v3"
"github.com/zeebo/errs"
"go.uber.org/zap"
"golang.org/x/sync/errgroup"
@ -359,13 +360,23 @@ func (endpoint *Endpoint) GetObject(ctx context.Context, req *pb.ObjectGetReques
return nil, rpcstatus.Error(rpcstatus.InvalidArgument, err.Error())
}
mbObject, err := endpoint.metabase.GetObjectLastCommitted(ctx, metabase.GetObjectLastCommitted{
ObjectLocation: metabase.ObjectLocation{
ProjectID: keyInfo.ProjectID,
BucketName: string(req.Bucket),
ObjectKey: metabase.ObjectKey(req.EncryptedObjectKey),
},
})
objectLocation := metabase.ObjectLocation{
ProjectID: keyInfo.ProjectID,
BucketName: string(req.Bucket),
ObjectKey: metabase.ObjectKey(req.EncryptedObjectKey),
}
var mbObject metabase.Object
if req.Version == 0 {
mbObject, err = endpoint.metabase.GetObjectLastCommitted(ctx, metabase.GetObjectLastCommitted{
ObjectLocation: objectLocation,
})
} else {
mbObject, err = endpoint.metabase.GetObjectExactVersion(ctx, metabase.GetObjectExactVersion{
ObjectLocation: objectLocation,
Version: metabase.Version(req.Version),
})
}
if err != nil {
return nil, endpoint.convertMetabaseErr(err)
}
@ -1528,6 +1539,10 @@ func (endpoint *Endpoint) objectToProto(ctx context.Context, object metabase.Obj
return nil, err
}
if metabase.Version(int32(object.Version)) != object.Version {
return nil, errs.New("unable to convert version for protobuf object")
}
result := &pb.Object{
Bucket: []byte(object.BucketName),
EncryptedObjectKey: []byte(object.ObjectKey),

View File

@ -110,6 +110,24 @@ func TestEndpoint_Object_No_StorageNodes(t *testing.T) {
require.Equal(t, item.EncryptedObjectKey, object.EncryptedObjectKey)
require.NotEmpty(t, object.StreamID)
require.EqualValues(t, item.Version, object.Version)
// get with version
object, err = metainfoClient.GetObject(ctx, metaclient.GetObjectParams{
Bucket: []byte(expectedBucketName),
EncryptedObjectKey: item.EncryptedObjectKey,
Version: item.Version,
})
require.NoError(t, err)
require.Equal(t, item.EncryptedObjectKey, object.EncryptedObjectKey)
// get with WRONG version, should return error
_, err = metainfoClient.GetObject(ctx, metaclient.GetObjectParams{
Bucket: []byte(expectedBucketName),
EncryptedObjectKey: item.EncryptedObjectKey,
Version: item.Version + 1,
})
require.True(t, errs2.IsRPC(err, rpcstatus.NotFound))
}
items, _, err = metainfoClient.ListObjects(ctx, metaclient.ListObjectsParams{