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:
Aditya Manthramurthy
2018-08-27 02:58:23 -07:00
committed by Nitish Tiwari
parent cea4f82586
commit e6d740ce09
19 changed files with 926 additions and 69 deletions

View File

@@ -17,6 +17,7 @@
package cmd
import (
"bytes"
"context"
"encoding/hex"
"io"
@@ -162,6 +163,53 @@ func (xl xlObjects) CopyObject(ctx context.Context, srcBucket, srcObject, dstBuc
return objInfo, nil
}
func (xl xlObjects) GetObjectNInfo(ctx context.Context, bucket, object string, rs *HTTPRangeSpec) (objInfo ObjectInfo, reader io.ReadCloser, err error) {
// Acquire lock
lock := xl.nsMutex.NewNSLock(bucket, object)
if err = lock.GetRLock(globalObjectTimeout); err != nil {
return objInfo, nil, err
}
objReader := &GetObjectReader{
lock: lock,
}
if err = checkGetObjArgs(ctx, bucket, object); err != nil {
return objInfo, objReader, err
}
if hasSuffix(object, slashSeparator) {
if !xl.isObjectDir(bucket, object) {
return objInfo, objReader, toObjectErr(errFileNotFound, bucket, object)
}
var e error
if objInfo, e = xl.getObjectInfoDir(ctx, bucket, object); e != nil {
return objInfo, objReader, toObjectErr(e, bucket, object)
}
objReader.pr = bytes.NewBuffer(nil)
return objInfo, objReader, nil
}
objInfo, err = xl.getObjectInfo(ctx, bucket, object)
if err != nil {
return objInfo, objReader, toObjectErr(err, bucket, object)
}
startOffset, readLength := int64(0), objInfo.Size
if rs != nil {
startOffset, readLength = rs.GetOffsetLength(objInfo.Size)
}
pr, pw := io.Pipe()
objReader.pr = pr
go func() {
err := xl.getObject(ctx, bucket, object, startOffset, readLength, pw, "")
pw.CloseWithError(err)
}()
return objInfo, objReader, nil
}
// GetObject - reads an object erasured coded across multiple
// disks. Supports additional parameters like offset and length
// which are synonymous with HTTP Range requests.