mirror of
https://github.com/minio/minio.git
synced 2025-11-07 04:42:56 -05:00
Implement GetObjectNInfo object layer call (#6290)
This combines calling GetObjectInfo and GetObject while returning a io.ReadCloser for the object's body. This allows the two operations to be under a single lock, fixing a race between getting object info and reading the object body.
This commit is contained in:
committed by
Nitish Tiwari
parent
cea4f82586
commit
e6d740ce09
@@ -615,6 +615,27 @@ func (a *azureObjects) ListObjectsV2(ctx context.Context, bucket, prefix, contin
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (a *azureObjects) GetObjectNInfo(ctx context.Context, bucket, object string, rs *minio.HTTPRangeSpec) (objInfo minio.ObjectInfo, reader io.ReadCloser, err error) {
|
||||
objInfo, err = a.GetObjectInfo(ctx, bucket, object)
|
||||
if err != nil {
|
||||
return objInfo, reader, err
|
||||
}
|
||||
|
||||
startOffset, length := int64(0), objInfo.Size
|
||||
if rs != nil {
|
||||
startOffset, length = rs.GetOffsetLength(objInfo.Size)
|
||||
}
|
||||
|
||||
pr, pw := io.Pipe()
|
||||
objReader := minio.NewGetObjectReader(pr, nil, nil)
|
||||
go func() {
|
||||
err := a.GetObject(ctx, bucket, object, startOffset, length, pw, objInfo.ETag)
|
||||
pw.CloseWithError(err)
|
||||
}()
|
||||
|
||||
return objInfo, objReader, nil
|
||||
}
|
||||
|
||||
// GetObject - reads an object from azure. Supports additional
|
||||
// parameters like offset and length which are synonymous with
|
||||
// HTTP Range requests.
|
||||
|
||||
@@ -394,6 +394,27 @@ func (l *b2Objects) ListObjectsV2(ctx context.Context, bucket, prefix, continuat
|
||||
return loi, nil
|
||||
}
|
||||
|
||||
func (l *b2Objects) GetObjectNInfo(ctx context.Context, bucket, object string, rs *minio.HTTPRangeSpec) (objInfo minio.ObjectInfo, reader io.ReadCloser, err error) {
|
||||
objInfo, err = l.GetObjectInfo(ctx, bucket, object)
|
||||
if err != nil {
|
||||
return objInfo, reader, err
|
||||
}
|
||||
|
||||
startOffset, length := int64(0), objInfo.Size
|
||||
if rs != nil {
|
||||
startOffset, length = rs.GetOffsetLength(objInfo.Size)
|
||||
}
|
||||
|
||||
pr, pw := io.Pipe()
|
||||
objReader := minio.NewGetObjectReader(pr, nil, nil)
|
||||
go func() {
|
||||
err := l.GetObject(ctx, bucket, object, startOffset, length, pw, objInfo.ETag)
|
||||
pw.CloseWithError(err)
|
||||
}()
|
||||
|
||||
return objInfo, objReader, nil
|
||||
}
|
||||
|
||||
// GetObject reads an object from B2. Supports additional
|
||||
// parameters like offset and length which are synonymous with
|
||||
// HTTP Range requests.
|
||||
|
||||
@@ -732,6 +732,27 @@ func (l *gcsGateway) ListObjectsV2(ctx context.Context, bucket, prefix, continua
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (l *gcsGateway) GetObjectNInfo(ctx context.Context, bucket, object string, rs *minio.HTTPRangeSpec) (objInfo minio.ObjectInfo, reader io.ReadCloser, err error) {
|
||||
objInfo, err = l.GetObjectInfo(ctx, bucket, object)
|
||||
if err != nil {
|
||||
return objInfo, reader, err
|
||||
}
|
||||
|
||||
startOffset, length := int64(0), objInfo.Size
|
||||
if rs != nil {
|
||||
startOffset, length = rs.GetOffsetLength(objInfo.Size)
|
||||
}
|
||||
|
||||
pr, pw := io.Pipe()
|
||||
objReader := minio.NewGetObjectReader(pr, nil, nil)
|
||||
go func() {
|
||||
err := l.GetObject(ctx, bucket, object, startOffset, length, pw, objInfo.ETag)
|
||||
pw.CloseWithError(err)
|
||||
}()
|
||||
|
||||
return objInfo, objReader, nil
|
||||
}
|
||||
|
||||
// GetObject - reads an object from GCS. Supports additional
|
||||
// parameters like offset and length which are synonymous with
|
||||
// HTTP Range requests.
|
||||
|
||||
@@ -497,6 +497,27 @@ func (t *tritonObjects) ListObjectsV2(ctx context.Context, bucket, prefix, conti
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (t *tritonObjects) GetObjectNInfo(ctx context.Context, bucket, object string, rs *minio.HTTPRangeSpec) (objInfo minio.ObjectInfo, reader io.ReadCloser, err error) {
|
||||
objInfo, err = t.GetObjectInfo(ctx, bucket, object)
|
||||
if err != nil {
|
||||
return objInfo, reader, err
|
||||
}
|
||||
|
||||
startOffset, length := int64(0), objInfo.Size
|
||||
if rs != nil {
|
||||
startOffset, length = rs.GetOffsetLength(objInfo.Size)
|
||||
}
|
||||
|
||||
pr, pw := io.Pipe()
|
||||
objReader := minio.NewGetObjectReader(pr, nil, nil)
|
||||
go func() {
|
||||
err := t.GetObject(ctx, bucket, object, startOffset, length, pw, objInfo.ETag)
|
||||
pw.CloseWithError(err)
|
||||
}()
|
||||
|
||||
return objInfo, objReader, nil
|
||||
}
|
||||
|
||||
// GetObject - Reads an object from Manta. Supports additional parameters like
|
||||
// offset and length which are synonymous with HTTP Range requests.
|
||||
//
|
||||
|
||||
@@ -69,7 +69,7 @@ ENVIRONMENT VARIABLES:
|
||||
|
||||
DOMAIN:
|
||||
MINIO_DOMAIN: To enable virtual-host-style requests, set this value to Minio host domain name.
|
||||
|
||||
|
||||
CACHE:
|
||||
MINIO_CACHE_DRIVES: List of mounted drives or directories delimited by ";".
|
||||
MINIO_CACHE_EXCLUDE: List of cache exclusion patterns delimited by ";".
|
||||
@@ -547,6 +547,27 @@ func ossGetObject(ctx context.Context, client *oss.Client, bucket, key string, s
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *ossObjects) GetObjectNInfo(ctx context.Context, bucket, object string, rs *minio.HTTPRangeSpec) (objInfo minio.ObjectInfo, reader io.ReadCloser, err error) {
|
||||
objInfo, err = l.GetObjectInfo(ctx, bucket, object)
|
||||
if err != nil {
|
||||
return objInfo, reader, err
|
||||
}
|
||||
|
||||
startOffset, length := int64(0), objInfo.Size
|
||||
if rs != nil {
|
||||
startOffset, length = rs.GetOffsetLength(objInfo.Size)
|
||||
}
|
||||
|
||||
pr, pw := io.Pipe()
|
||||
objReader := minio.NewGetObjectReader(pr, nil, nil)
|
||||
go func() {
|
||||
err := l.GetObject(ctx, bucket, object, startOffset, length, pw, objInfo.ETag)
|
||||
pw.CloseWithError(err)
|
||||
}()
|
||||
|
||||
return objInfo, objReader, nil
|
||||
}
|
||||
|
||||
// GetObject reads an object on OSS. Supports additional
|
||||
// parameters like offset and length which are synonymous with
|
||||
// HTTP Range requests.
|
||||
|
||||
@@ -301,6 +301,27 @@ func (l *s3Objects) ListObjectsV2(ctx context.Context, bucket, prefix, continuat
|
||||
return minio.FromMinioClientListBucketV2Result(bucket, result), nil
|
||||
}
|
||||
|
||||
func (l *s3Objects) GetObjectNInfo(ctx context.Context, bucket, object string, rs *minio.HTTPRangeSpec) (objInfo minio.ObjectInfo, reader io.ReadCloser, err error) {
|
||||
objInfo, err = l.GetObjectInfo(ctx, bucket, object)
|
||||
if err != nil {
|
||||
return objInfo, reader, err
|
||||
}
|
||||
|
||||
startOffset, length := int64(0), objInfo.Size
|
||||
if rs != nil {
|
||||
startOffset, length = rs.GetOffsetLength(objInfo.Size)
|
||||
}
|
||||
|
||||
pr, pw := io.Pipe()
|
||||
objReader := minio.NewGetObjectReader(pr, nil, nil)
|
||||
go func() {
|
||||
err := l.GetObject(ctx, bucket, object, startOffset, length, pw, objInfo.ETag)
|
||||
pw.CloseWithError(err)
|
||||
}()
|
||||
|
||||
return objInfo, objReader, nil
|
||||
}
|
||||
|
||||
// GetObject reads an object from S3. Supports additional
|
||||
// parameters like offset and length which are synonymous with
|
||||
// HTTP Range requests.
|
||||
@@ -313,6 +334,9 @@ func (l *s3Objects) GetObject(ctx context.Context, bucket string, key string, st
|
||||
}
|
||||
|
||||
opts := miniogo.GetObjectOptions{}
|
||||
if etag != "" {
|
||||
opts.SetMatchETag(etag)
|
||||
}
|
||||
if startOffset >= 0 && length >= 0 {
|
||||
if err := opts.SetRange(startOffset, startOffset+length-1); err != nil {
|
||||
logger.LogIf(ctx, err)
|
||||
|
||||
@@ -431,6 +431,27 @@ func (s *siaObjects) ListObjects(ctx context.Context, bucket string, prefix stri
|
||||
return loi, nil
|
||||
}
|
||||
|
||||
func (s *siaObjects) GetObjectNInfo(ctx context.Context, bucket, object string, rs *minio.HTTPRangeSpec) (objInfo minio.ObjectInfo, reader io.ReadCloser, err error) {
|
||||
objInfo, err = s.GetObjectInfo(ctx, bucket, object)
|
||||
if err != nil {
|
||||
return objInfo, reader, err
|
||||
}
|
||||
|
||||
startOffset, length := int64(0), objInfo.Size
|
||||
if rs != nil {
|
||||
startOffset, length = rs.GetOffsetLength(objInfo.Size)
|
||||
}
|
||||
|
||||
pr, pw := io.Pipe()
|
||||
objReader := minio.NewGetObjectReader(pr, nil, nil)
|
||||
go func() {
|
||||
err := s.GetObject(ctx, bucket, object, startOffset, length, pw, objInfo.ETag)
|
||||
pw.CloseWithError(err)
|
||||
}()
|
||||
|
||||
return objInfo, objReader, nil
|
||||
}
|
||||
|
||||
func (s *siaObjects) GetObject(ctx context.Context, bucket string, object string, startOffset int64, length int64, writer io.Writer, etag string) error {
|
||||
dstFile := path.Join(s.TempDir, minio.MustGetUUID())
|
||||
defer os.Remove(dstFile)
|
||||
|
||||
Reference in New Issue
Block a user