2016-05-20 23:48:47 -04:00
|
|
|
/*
|
2017-03-18 14:28:41 -04:00
|
|
|
* Minio Cloud Storage, (C) 2016, 2017 Minio, Inc.
|
2016-05-20 23:48:47 -04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2016-08-18 19:23:42 -04:00
|
|
|
package cmd
|
2016-05-20 23:48:47 -04:00
|
|
|
|
|
|
|
import (
|
2017-10-24 15:25:42 -04:00
|
|
|
"encoding/hex"
|
2016-05-20 23:48:47 -04:00
|
|
|
"fmt"
|
|
|
|
"io"
|
2016-07-08 23:34:27 -04:00
|
|
|
"io/ioutil"
|
2016-05-20 23:48:47 -04:00
|
|
|
"path"
|
2016-05-24 16:35:43 -04:00
|
|
|
"strings"
|
2017-01-26 15:51:12 -05:00
|
|
|
"sync"
|
2016-05-20 23:48:47 -04:00
|
|
|
"time"
|
2016-05-24 16:35:43 -04:00
|
|
|
|
2017-10-22 01:30:34 -04:00
|
|
|
"github.com/minio/minio/pkg/hash"
|
2016-05-24 16:35:43 -04:00
|
|
|
"github.com/minio/minio/pkg/mimedb"
|
2016-05-20 23:48:47 -04:00
|
|
|
)
|
|
|
|
|
2017-01-26 15:51:12 -05:00
|
|
|
// updateUploadJSON - add or remove upload ID info in all `uploads.json`.
|
|
|
|
func (xl xlObjects) updateUploadJSON(bucket, object, uploadID string, initiated time.Time, isRemove bool) error {
|
|
|
|
uploadsPath := path.Join(bucket, object, uploadsJSONFile)
|
|
|
|
tmpUploadsPath := mustGetUUID()
|
|
|
|
|
|
|
|
// slice to store errors from disks
|
|
|
|
errs := make([]error, len(xl.storageDisks))
|
|
|
|
// slice to store if it is a delete operation on a disk
|
|
|
|
isDelete := make([]bool, len(xl.storageDisks))
|
|
|
|
|
|
|
|
wg := sync.WaitGroup{}
|
|
|
|
for index, disk := range xl.storageDisks {
|
|
|
|
if disk == nil {
|
|
|
|
errs[index] = traceError(errDiskNotFound)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
// Update `uploads.json` in a go routine.
|
|
|
|
wg.Add(1)
|
|
|
|
go func(index int, disk StorageAPI) {
|
|
|
|
defer wg.Done()
|
|
|
|
|
|
|
|
// read and parse uploads.json on this disk
|
|
|
|
uploadsJSON, err := readUploadsJSON(bucket, object, disk)
|
|
|
|
if errorCause(err) == errFileNotFound {
|
|
|
|
// If file is not found, we assume an
|
|
|
|
// default (empty) upload info.
|
|
|
|
uploadsJSON, err = newUploadsV1("xl"), nil
|
|
|
|
}
|
|
|
|
// If we have a read error, we store error and
|
|
|
|
// exit.
|
|
|
|
if err != nil {
|
|
|
|
errs[index] = err
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if !isRemove {
|
|
|
|
// Add the uploadID
|
|
|
|
uploadsJSON.AddUploadID(uploadID, initiated)
|
|
|
|
} else {
|
|
|
|
// Remove the upload ID
|
|
|
|
uploadsJSON.RemoveUploadID(uploadID)
|
|
|
|
if len(uploadsJSON.Uploads) == 0 {
|
|
|
|
isDelete[index] = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// For delete, rename to tmp, for the
|
|
|
|
// possibility of recovery in case of quorum
|
|
|
|
// failure.
|
|
|
|
if !isDelete[index] {
|
|
|
|
errs[index] = writeUploadJSON(&uploadsJSON, uploadsPath, tmpUploadsPath, disk)
|
|
|
|
} else {
|
|
|
|
wErr := disk.RenameFile(minioMetaMultipartBucket, uploadsPath, minioMetaTmpBucket, tmpUploadsPath)
|
|
|
|
if wErr != nil {
|
|
|
|
errs[index] = traceError(wErr)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}(index, disk)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait for all the writes to finish.
|
|
|
|
wg.Wait()
|
|
|
|
|
2017-02-01 14:16:17 -05:00
|
|
|
err := reduceWriteQuorumErrs(errs, objectOpIgnoredErrs, xl.writeQuorum)
|
|
|
|
if errorCause(err) == errXLWriteQuorum {
|
2017-01-26 15:51:12 -05:00
|
|
|
// No quorum. Perform cleanup on the minority of disks
|
|
|
|
// on which the operation succeeded.
|
|
|
|
|
|
|
|
// There are two cases:
|
|
|
|
//
|
|
|
|
// 1. uploads.json file was updated -> we delete the
|
|
|
|
// file that we successfully overwrote on the
|
|
|
|
// minority of disks, so that the failed quorum
|
|
|
|
// operation is not partially visible.
|
|
|
|
//
|
|
|
|
// 2. uploads.json was deleted -> in this case since
|
|
|
|
// the delete failed, we restore from tmp.
|
|
|
|
for index, disk := range xl.storageDisks {
|
|
|
|
if disk == nil || errs[index] != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
wg.Add(1)
|
|
|
|
go func(index int, disk StorageAPI) {
|
|
|
|
defer wg.Done()
|
|
|
|
if !isDelete[index] {
|
|
|
|
_ = disk.DeleteFile(
|
|
|
|
minioMetaMultipartBucket,
|
|
|
|
uploadsPath,
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
_ = disk.RenameFile(
|
|
|
|
minioMetaTmpBucket, tmpUploadsPath,
|
|
|
|
minioMetaMultipartBucket, uploadsPath,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}(index, disk)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
2017-02-01 14:16:17 -05:00
|
|
|
return err
|
2017-01-26 15:51:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// we do have quorum, so in case of delete upload.json file
|
|
|
|
// operation, we purge from tmp.
|
|
|
|
for index, disk := range xl.storageDisks {
|
|
|
|
if disk == nil || !isDelete[index] {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
wg.Add(1)
|
|
|
|
go func(index int, disk StorageAPI) {
|
|
|
|
defer wg.Done()
|
|
|
|
// isDelete[index] = true at this point.
|
|
|
|
_ = disk.DeleteFile(minioMetaTmpBucket, tmpUploadsPath)
|
|
|
|
}(index, disk)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
2017-02-01 14:16:17 -05:00
|
|
|
return err
|
2017-01-26 15:51:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// addUploadID - add upload ID and its initiated time to 'uploads.json'.
|
|
|
|
func (xl xlObjects) addUploadID(bucket, object string, uploadID string, initiated time.Time) error {
|
|
|
|
return xl.updateUploadJSON(bucket, object, uploadID, initiated, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
// removeUploadID - remove upload ID in 'uploads.json'.
|
|
|
|
func (xl xlObjects) removeUploadID(bucket, object string, uploadID string) error {
|
|
|
|
return xl.updateUploadJSON(bucket, object, uploadID, time.Time{}, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns if the prefix is a multipart upload.
|
|
|
|
func (xl xlObjects) isMultipartUpload(bucket, prefix string) bool {
|
|
|
|
for _, disk := range xl.getLoadBalancedDisks() {
|
|
|
|
if disk == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
_, err := disk.StatFile(bucket, pathJoin(prefix, uploadsJSONFile))
|
|
|
|
if err == nil {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
// For any reason disk was deleted or goes offline, continue
|
|
|
|
if isErrIgnored(err, objMetadataOpIgnoredErrs...) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
break
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// isUploadIDExists - verify if a given uploadID exists and is valid.
|
|
|
|
func (xl xlObjects) isUploadIDExists(bucket, object, uploadID string) bool {
|
|
|
|
uploadIDPath := path.Join(bucket, object, uploadID)
|
|
|
|
return xl.isObject(minioMetaMultipartBucket, uploadIDPath)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Removes part given by partName belonging to a mulitpart upload from minioMetaBucket
|
|
|
|
func (xl xlObjects) removeObjectPart(bucket, object, uploadID, partName string) {
|
|
|
|
curpartPath := path.Join(bucket, object, uploadID, partName)
|
|
|
|
wg := sync.WaitGroup{}
|
|
|
|
for i, disk := range xl.storageDisks {
|
|
|
|
if disk == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
wg.Add(1)
|
|
|
|
go func(index int, disk StorageAPI) {
|
|
|
|
defer wg.Done()
|
|
|
|
// Ignoring failure to remove parts that weren't present in CompleteMultipartUpload
|
|
|
|
// requests. xl.json is the authoritative source of truth on which parts constitute
|
|
|
|
// the object. The presence of parts that don't belong in the object doesn't affect correctness.
|
|
|
|
_ = disk.DeleteFile(minioMetaMultipartBucket, curpartPath)
|
|
|
|
}(i, disk)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
}
|
|
|
|
|
|
|
|
// statPart - returns fileInfo structure for a successful stat on part file.
|
|
|
|
func (xl xlObjects) statPart(bucket, object, uploadID, partName string) (fileInfo FileInfo, err error) {
|
2017-04-14 04:46:16 -04:00
|
|
|
var ignoredErrs []error
|
2017-01-26 15:51:12 -05:00
|
|
|
partNamePath := path.Join(bucket, object, uploadID, partName)
|
|
|
|
for _, disk := range xl.getLoadBalancedDisks() {
|
|
|
|
if disk == nil {
|
2017-04-14 04:46:16 -04:00
|
|
|
ignoredErrs = append(ignoredErrs, errDiskNotFound)
|
2017-01-26 15:51:12 -05:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
fileInfo, err = disk.StatFile(minioMetaMultipartBucket, partNamePath)
|
|
|
|
if err == nil {
|
|
|
|
return fileInfo, nil
|
|
|
|
}
|
|
|
|
// For any reason disk was deleted or goes offline we continue to next disk.
|
|
|
|
if isErrIgnored(err, objMetadataOpIgnoredErrs...) {
|
2017-04-14 04:46:16 -04:00
|
|
|
ignoredErrs = append(ignoredErrs, err)
|
2017-01-26 15:51:12 -05:00
|
|
|
continue
|
|
|
|
}
|
2017-04-14 04:46:16 -04:00
|
|
|
// Error is not ignored, return right here.
|
|
|
|
return FileInfo{}, traceError(err)
|
2017-01-26 15:51:12 -05:00
|
|
|
}
|
2017-04-14 04:46:16 -04:00
|
|
|
// If all errors were ignored, reduce to maximal occurrence
|
|
|
|
// based on the read quorum.
|
|
|
|
return FileInfo{}, reduceReadQuorumErrs(ignoredErrs, nil, xl.readQuorum)
|
2017-01-26 15:51:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// commitXLMetadata - commit `xl.json` from source prefix to destination prefix in the given slice of disks.
|
2017-06-14 20:14:27 -04:00
|
|
|
func commitXLMetadata(disks []StorageAPI, srcBucket, srcPrefix, dstBucket, dstPrefix string, quorum int) ([]StorageAPI, error) {
|
2017-01-26 15:51:12 -05:00
|
|
|
var wg = &sync.WaitGroup{}
|
|
|
|
var mErrs = make([]error, len(disks))
|
|
|
|
|
|
|
|
srcJSONFile := path.Join(srcPrefix, xlMetaJSONFile)
|
|
|
|
dstJSONFile := path.Join(dstPrefix, xlMetaJSONFile)
|
|
|
|
|
|
|
|
// Rename `xl.json` to all disks in parallel.
|
|
|
|
for index, disk := range disks {
|
|
|
|
if disk == nil {
|
|
|
|
mErrs[index] = traceError(errDiskNotFound)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
wg.Add(1)
|
|
|
|
// Rename `xl.json` in a routine.
|
|
|
|
go func(index int, disk StorageAPI) {
|
|
|
|
defer wg.Done()
|
|
|
|
// Delete any dangling directories.
|
|
|
|
defer disk.DeleteFile(srcBucket, srcPrefix)
|
|
|
|
|
|
|
|
// Renames `xl.json` from source prefix to destination prefix.
|
|
|
|
rErr := disk.RenameFile(srcBucket, srcJSONFile, dstBucket, dstJSONFile)
|
|
|
|
if rErr != nil {
|
|
|
|
mErrs[index] = traceError(rErr)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
mErrs[index] = nil
|
|
|
|
}(index, disk)
|
|
|
|
}
|
|
|
|
// Wait for all the routines.
|
|
|
|
wg.Wait()
|
|
|
|
|
2017-02-01 14:16:17 -05:00
|
|
|
err := reduceWriteQuorumErrs(mErrs, objectOpIgnoredErrs, quorum)
|
|
|
|
if errorCause(err) == errXLWriteQuorum {
|
2017-01-26 15:51:12 -05:00
|
|
|
// Delete all `xl.json` successfully renamed.
|
|
|
|
deleteAllXLMetadata(disks, dstBucket, dstPrefix, mErrs)
|
|
|
|
}
|
2017-06-14 20:14:27 -04:00
|
|
|
return evalDisks(disks, mErrs), err
|
2017-01-26 15:51:12 -05:00
|
|
|
}
|
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// listMultipartUploads - lists all multipart uploads.
|
2017-06-21 22:53:09 -04:00
|
|
|
func (xl xlObjects) listMultipartUploads(bucket, prefix, keyMarker, uploadIDMarker, delimiter string, maxUploads int) (lmi ListMultipartsInfo, e error) {
|
2016-06-01 19:43:31 -04:00
|
|
|
result := ListMultipartsInfo{
|
|
|
|
IsTruncated: true,
|
|
|
|
MaxUploads: maxUploads,
|
|
|
|
KeyMarker: keyMarker,
|
|
|
|
Prefix: prefix,
|
|
|
|
Delimiter: delimiter,
|
|
|
|
}
|
|
|
|
|
|
|
|
recursive := true
|
|
|
|
if delimiter == slashSeparator {
|
|
|
|
recursive = false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Not using path.Join() as it strips off the trailing '/'.
|
2016-11-22 16:15:06 -05:00
|
|
|
multipartPrefixPath := pathJoin(bucket, prefix)
|
2016-06-01 19:43:31 -04:00
|
|
|
if prefix == "" {
|
|
|
|
// Should have a trailing "/" if prefix is ""
|
|
|
|
// For ex. multipartPrefixPath should be "multipart/bucket/" if prefix is ""
|
|
|
|
multipartPrefixPath += slashSeparator
|
|
|
|
}
|
|
|
|
multipartMarkerPath := ""
|
|
|
|
if keyMarker != "" {
|
2016-11-22 16:15:06 -05:00
|
|
|
multipartMarkerPath = pathJoin(bucket, keyMarker)
|
2016-06-01 19:43:31 -04:00
|
|
|
}
|
2017-11-14 03:25:10 -05:00
|
|
|
var uploads []MultipartInfo
|
2016-06-01 19:43:31 -04:00
|
|
|
var err error
|
|
|
|
var eof bool
|
|
|
|
// List all upload ids for the keyMarker starting from
|
|
|
|
// uploadIDMarker first.
|
|
|
|
if uploadIDMarker != "" {
|
2016-11-09 13:58:41 -05:00
|
|
|
// hold lock on keyMarker path
|
2016-12-10 19:15:12 -05:00
|
|
|
keyMarkerLock := globalNSMutex.NewNSLock(minioMetaMultipartBucket,
|
2016-11-22 16:15:06 -05:00
|
|
|
pathJoin(bucket, keyMarker))
|
2017-08-31 14:29:22 -04:00
|
|
|
if err = keyMarkerLock.GetRLock(globalListingTimeout); err != nil {
|
|
|
|
return lmi, err
|
|
|
|
}
|
2016-07-21 03:27:08 -04:00
|
|
|
for _, disk := range xl.getLoadBalancedDisks() {
|
2016-06-02 19:34:15 -04:00
|
|
|
if disk == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
uploads, _, err = listMultipartUploadIDs(bucket, keyMarker, uploadIDMarker, maxUploads, disk)
|
2016-07-08 01:10:27 -04:00
|
|
|
if err == nil {
|
|
|
|
break
|
|
|
|
}
|
2016-11-23 23:05:04 -05:00
|
|
|
if isErrIgnored(err, objMetadataOpIgnoredErrs...) {
|
2016-06-03 01:49:27 -04:00
|
|
|
continue
|
|
|
|
}
|
2016-06-02 19:34:15 -04:00
|
|
|
break
|
|
|
|
}
|
2016-11-09 13:58:41 -05:00
|
|
|
keyMarkerLock.RUnlock()
|
2016-06-01 19:43:31 -04:00
|
|
|
if err != nil {
|
2017-06-21 22:53:09 -04:00
|
|
|
return lmi, err
|
2016-06-01 19:43:31 -04:00
|
|
|
}
|
|
|
|
maxUploads = maxUploads - len(uploads)
|
|
|
|
}
|
2016-07-07 12:06:35 -04:00
|
|
|
var walkerCh chan treeWalkResult
|
|
|
|
var walkerDoneCh chan struct{}
|
2016-08-17 14:36:33 -04:00
|
|
|
heal := false // true only for xl.ListObjectsHeal
|
2016-06-01 19:43:31 -04:00
|
|
|
// Validate if we need to list further depending on maxUploads.
|
|
|
|
if maxUploads > 0 {
|
2016-11-22 16:15:06 -05:00
|
|
|
walkerCh, walkerDoneCh = xl.listPool.Release(listParams{minioMetaMultipartBucket, recursive, multipartMarkerPath, multipartPrefixPath, heal})
|
2016-05-30 00:05:00 -04:00
|
|
|
if walkerCh == nil {
|
|
|
|
walkerDoneCh = make(chan struct{})
|
2016-07-17 18:16:52 -04:00
|
|
|
isLeaf := xl.isMultipartUpload
|
2016-09-15 16:43:40 -04:00
|
|
|
listDir := listDirFactory(isLeaf, xlTreeWalkIgnoredErrs, xl.getLoadBalancedDisks()...)
|
2016-11-22 16:15:06 -05:00
|
|
|
walkerCh = startTreeWalk(minioMetaMultipartBucket, multipartPrefixPath, multipartMarkerPath, recursive, listDir, isLeaf, walkerDoneCh)
|
2016-06-01 19:43:31 -04:00
|
|
|
}
|
|
|
|
// Collect uploads until we have reached maxUploads count to 0.
|
|
|
|
for maxUploads > 0 {
|
2016-05-30 00:05:00 -04:00
|
|
|
walkResult, ok := <-walkerCh
|
2016-06-01 19:43:31 -04:00
|
|
|
if !ok {
|
|
|
|
// Closed channel.
|
|
|
|
eof = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
// For any walk error return right away.
|
|
|
|
if walkResult.err != nil {
|
2017-06-21 22:53:09 -04:00
|
|
|
return lmi, walkResult.err
|
2016-06-01 19:43:31 -04:00
|
|
|
}
|
2016-11-22 16:15:06 -05:00
|
|
|
entry := strings.TrimPrefix(walkResult.entry, retainSlash(bucket))
|
2016-06-01 19:43:31 -04:00
|
|
|
// For an entry looking like a directory, store and
|
|
|
|
// continue the loop not need to fetch uploads.
|
2017-02-16 17:52:14 -05:00
|
|
|
if hasSuffix(walkResult.entry, slashSeparator) {
|
2017-11-14 03:25:10 -05:00
|
|
|
uploads = append(uploads, MultipartInfo{
|
2016-06-01 19:43:31 -04:00
|
|
|
Object: entry,
|
|
|
|
})
|
|
|
|
maxUploads--
|
|
|
|
if maxUploads == 0 {
|
2016-05-30 00:05:00 -04:00
|
|
|
eof = true
|
|
|
|
break
|
2016-06-01 19:43:31 -04:00
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
2017-11-14 03:25:10 -05:00
|
|
|
var newUploads []MultipartInfo
|
2016-06-01 19:43:31 -04:00
|
|
|
var end bool
|
|
|
|
uploadIDMarker = ""
|
2016-08-31 14:39:08 -04:00
|
|
|
|
2016-11-09 13:58:41 -05:00
|
|
|
// For the new object entry we get all its
|
|
|
|
// pending uploadIDs.
|
2016-12-10 19:15:12 -05:00
|
|
|
entryLock := globalNSMutex.NewNSLock(minioMetaMultipartBucket,
|
2016-11-22 16:15:06 -05:00
|
|
|
pathJoin(bucket, entry))
|
2017-08-31 14:29:22 -04:00
|
|
|
if err = entryLock.GetRLock(globalListingTimeout); err != nil {
|
|
|
|
return lmi, err
|
|
|
|
}
|
2016-06-02 19:34:15 -04:00
|
|
|
var disk StorageAPI
|
2016-07-21 03:27:08 -04:00
|
|
|
for _, disk = range xl.getLoadBalancedDisks() {
|
2016-06-02 19:34:15 -04:00
|
|
|
if disk == nil {
|
|
|
|
continue
|
|
|
|
}
|
2016-06-03 01:49:27 -04:00
|
|
|
newUploads, end, err = listMultipartUploadIDs(bucket, entry, uploadIDMarker, maxUploads, disk)
|
2016-07-08 01:10:27 -04:00
|
|
|
if err == nil {
|
|
|
|
break
|
|
|
|
}
|
2016-11-23 23:05:04 -05:00
|
|
|
if isErrIgnored(err, objMetadataOpIgnoredErrs...) {
|
2016-06-03 01:49:27 -04:00
|
|
|
continue
|
|
|
|
}
|
2016-06-02 19:34:15 -04:00
|
|
|
break
|
|
|
|
}
|
2016-11-09 13:58:41 -05:00
|
|
|
entryLock.RUnlock()
|
2016-06-01 19:43:31 -04:00
|
|
|
if err != nil {
|
2016-11-23 23:05:04 -05:00
|
|
|
if isErrIgnored(err, xlTreeWalkIgnoredErrs...) {
|
2016-06-01 19:43:31 -04:00
|
|
|
continue
|
|
|
|
}
|
2017-06-21 22:53:09 -04:00
|
|
|
return lmi, err
|
2016-06-01 19:43:31 -04:00
|
|
|
}
|
|
|
|
uploads = append(uploads, newUploads...)
|
|
|
|
maxUploads -= len(newUploads)
|
2016-05-30 00:05:00 -04:00
|
|
|
if end && walkResult.end {
|
2016-06-01 19:43:31 -04:00
|
|
|
eof = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// For all received uploads fill in the multiparts result.
|
|
|
|
for _, upload := range uploads {
|
|
|
|
var objectName string
|
|
|
|
var uploadID string
|
2017-02-16 17:52:14 -05:00
|
|
|
if hasSuffix(upload.Object, slashSeparator) {
|
2016-06-01 19:43:31 -04:00
|
|
|
// All directory entries are common prefixes.
|
|
|
|
uploadID = "" // For common prefixes, upload ids are empty.
|
|
|
|
objectName = upload.Object
|
|
|
|
result.CommonPrefixes = append(result.CommonPrefixes, objectName)
|
|
|
|
} else {
|
|
|
|
uploadID = upload.UploadID
|
|
|
|
objectName = upload.Object
|
|
|
|
result.Uploads = append(result.Uploads, upload)
|
|
|
|
}
|
|
|
|
result.NextKeyMarker = objectName
|
|
|
|
result.NextUploadIDMarker = uploadID
|
|
|
|
}
|
2016-07-07 12:06:35 -04:00
|
|
|
|
|
|
|
if !eof {
|
|
|
|
// Save the go-routine state in the pool so that it can continue from where it left off on
|
|
|
|
// the next request.
|
2016-08-17 14:36:33 -04:00
|
|
|
xl.listPool.Set(listParams{bucket, recursive, result.NextKeyMarker, prefix, heal}, walkerCh, walkerDoneCh)
|
2016-07-07 12:06:35 -04:00
|
|
|
}
|
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
result.IsTruncated = !eof
|
|
|
|
// Result is not truncated, reset the markers.
|
|
|
|
if !result.IsTruncated {
|
|
|
|
result.NextKeyMarker = ""
|
|
|
|
result.NextUploadIDMarker = ""
|
|
|
|
}
|
|
|
|
return result, nil
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// ListMultipartUploads - lists all the pending multipart uploads on a
|
|
|
|
// bucket. Additionally takes 'prefix, keyMarker, uploadIDmarker and a
|
|
|
|
// delimiter' which allows us to list uploads match a particular
|
|
|
|
// prefix or lexically starting from 'keyMarker' or delimiting the
|
|
|
|
// output to get a directory like listing.
|
|
|
|
//
|
|
|
|
// Implements S3 compatible ListMultipartUploads API. The resulting
|
|
|
|
// ListMultipartsInfo structure is unmarshalled directly into XML and
|
|
|
|
// replied back to the client.
|
2017-06-21 22:53:09 -04:00
|
|
|
func (xl xlObjects) ListMultipartUploads(bucket, prefix, keyMarker, uploadIDMarker, delimiter string, maxUploads int) (lmi ListMultipartsInfo, e error) {
|
2016-12-02 02:15:17 -05:00
|
|
|
if err := checkListMultipartArgs(bucket, prefix, keyMarker, uploadIDMarker, delimiter, xl); err != nil {
|
2017-06-21 22:53:09 -04:00
|
|
|
return lmi, err
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-12-02 02:15:17 -05:00
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
return xl.listMultipartUploads(bucket, prefix, keyMarker, uploadIDMarker, delimiter, maxUploads)
|
|
|
|
}
|
2016-05-20 23:48:47 -04:00
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// newMultipartUpload - wrapper for initializing a new multipart
|
2016-10-24 20:37:18 -04:00
|
|
|
// request; returns a unique upload id.
|
2016-06-01 19:43:31 -04:00
|
|
|
//
|
|
|
|
// Internally this function creates 'uploads.json' associated for the
|
2016-10-24 20:37:18 -04:00
|
|
|
// incoming object at
|
|
|
|
// '.minio.sys/multipart/bucket/object/uploads.json' on all the
|
|
|
|
// disks. `uploads.json` carries metadata regarding on-going multipart
|
|
|
|
// operation(s) on the object.
|
|
|
|
func (xl xlObjects) newMultipartUpload(bucket string, object string, meta map[string]string) (string, error) {
|
2016-07-08 18:28:09 -04:00
|
|
|
xlMeta := newXLMetaV1(object, xl.dataBlocks, xl.parityBlocks)
|
2016-05-20 23:48:47 -04:00
|
|
|
// If not set default to "application/octet-stream"
|
|
|
|
if meta["content-type"] == "" {
|
2016-05-24 16:35:43 -04:00
|
|
|
contentType := "application/octet-stream"
|
2016-08-17 16:26:08 -04:00
|
|
|
if objectExt := path.Ext(object); objectExt != "" {
|
2016-05-24 16:35:43 -04:00
|
|
|
content, ok := mimedb.DB[strings.ToLower(strings.TrimPrefix(objectExt, "."))]
|
|
|
|
if ok {
|
|
|
|
contentType = content.ContentType
|
|
|
|
}
|
|
|
|
}
|
|
|
|
meta["content-type"] = contentType
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2017-03-18 14:28:41 -04:00
|
|
|
xlMeta.Stat.ModTime = UTCNow()
|
2016-05-20 23:48:47 -04:00
|
|
|
xlMeta.Meta = meta
|
|
|
|
|
2016-11-09 13:58:41 -05:00
|
|
|
// This lock needs to be held for any changes to the directory
|
|
|
|
// contents of ".minio.sys/multipart/object/"
|
2016-12-10 19:15:12 -05:00
|
|
|
objectMPartPathLock := globalNSMutex.NewNSLock(minioMetaMultipartBucket,
|
2016-11-22 16:15:06 -05:00
|
|
|
pathJoin(bucket, object))
|
2017-08-31 14:29:22 -04:00
|
|
|
if err := objectMPartPathLock.GetLock(globalOperationTimeout); err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2016-11-09 13:58:41 -05:00
|
|
|
defer objectMPartPathLock.Unlock()
|
2016-05-20 23:48:47 -04:00
|
|
|
|
2016-11-22 19:52:37 -05:00
|
|
|
uploadID := mustGetUUID()
|
2016-11-22 16:15:06 -05:00
|
|
|
uploadIDPath := path.Join(bucket, object, uploadID)
|
2016-11-20 17:25:43 -05:00
|
|
|
tempUploadIDPath := uploadID
|
2017-08-14 21:08:42 -04:00
|
|
|
|
2016-06-02 19:34:15 -04:00
|
|
|
// Write updated `xl.json` to all disks.
|
2017-06-14 20:14:27 -04:00
|
|
|
disks, err := writeSameXLMetadata(xl.storageDisks, minioMetaTmpBucket, tempUploadIDPath, xlMeta, xl.writeQuorum, xl.readQuorum)
|
2017-01-31 12:38:34 -05:00
|
|
|
if err != nil {
|
2016-11-20 17:25:43 -05:00
|
|
|
return "", toObjectErr(err, minioMetaTmpBucket, tempUploadIDPath)
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-10-24 20:37:18 -04:00
|
|
|
// delete the tmp path later in case we fail to rename (ignore
|
|
|
|
// returned errors) - this will be a no-op in case of a rename
|
|
|
|
// success.
|
2016-11-20 17:25:43 -05:00
|
|
|
defer xl.deleteObject(minioMetaTmpBucket, tempUploadIDPath)
|
2016-10-24 20:37:18 -04:00
|
|
|
|
2017-02-21 22:43:44 -05:00
|
|
|
// Attempt to rename temp upload object to actual upload path object
|
2017-06-14 20:14:27 -04:00
|
|
|
_, rErr := renameObject(disks, minioMetaTmpBucket, tempUploadIDPath, minioMetaMultipartBucket, uploadIDPath, xl.writeQuorum)
|
2017-02-21 22:43:44 -05:00
|
|
|
if rErr != nil {
|
2016-11-22 16:15:06 -05:00
|
|
|
return "", toObjectErr(rErr, minioMetaMultipartBucket, uploadIDPath)
|
2016-10-24 20:37:18 -04:00
|
|
|
}
|
|
|
|
|
2017-03-18 14:28:41 -04:00
|
|
|
initiated := UTCNow()
|
2016-10-24 20:37:18 -04:00
|
|
|
// Create or update 'uploads.json'
|
2017-02-21 22:43:44 -05:00
|
|
|
if err = xl.addUploadID(bucket, object, uploadID, initiated); err != nil {
|
2016-10-24 20:37:18 -04:00
|
|
|
return "", err
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-10-24 20:37:18 -04:00
|
|
|
// Return success.
|
|
|
|
return uploadID, nil
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// NewMultipartUpload - initialize a new multipart upload, returns a
|
|
|
|
// unique id. The unique id returned here is of UUID form, for each
|
|
|
|
// subsequent request each UUID is unique.
|
|
|
|
//
|
|
|
|
// Implements S3 compatible initiate multipart API.
|
2016-05-20 23:48:47 -04:00
|
|
|
func (xl xlObjects) NewMultipartUpload(bucket, object string, meta map[string]string) (string, error) {
|
2016-12-02 02:15:17 -05:00
|
|
|
if err := checkNewMultipartArgs(bucket, object, xl); err != nil {
|
|
|
|
return "", err
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-06-01 19:43:31 -04:00
|
|
|
// No metadata is set, allocate a new one.
|
|
|
|
if meta == nil {
|
|
|
|
meta = make(map[string]string)
|
|
|
|
}
|
|
|
|
return xl.newMultipartUpload(bucket, object, meta)
|
|
|
|
}
|
|
|
|
|
2017-01-31 12:38:34 -05:00
|
|
|
// CopyObjectPart - reads incoming stream and internally erasure codes
|
|
|
|
// them. This call is similar to put object part operation but the source
|
|
|
|
// data is read from an existing object.
|
|
|
|
//
|
|
|
|
// Implements S3 compatible Upload Part Copy API.
|
2017-06-21 22:53:09 -04:00
|
|
|
func (xl xlObjects) CopyObjectPart(srcBucket, srcObject, dstBucket, dstObject, uploadID string, partID int, startOffset int64, length int64) (pi PartInfo, e error) {
|
2017-01-31 12:38:34 -05:00
|
|
|
if err := checkNewMultipartArgs(srcBucket, srcObject, xl); err != nil {
|
2017-06-21 22:53:09 -04:00
|
|
|
return pi, err
|
2017-01-31 12:38:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize pipe.
|
|
|
|
pipeReader, pipeWriter := io.Pipe()
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
if gerr := xl.GetObject(srcBucket, srcObject, startOffset, length, pipeWriter); gerr != nil {
|
|
|
|
errorIf(gerr, "Unable to read %s of the object `%s/%s`.", srcBucket, srcObject)
|
|
|
|
pipeWriter.CloseWithError(toObjectErr(gerr, srcBucket, srcObject))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
pipeWriter.Close() // Close writer explicitly signalling we wrote all data.
|
|
|
|
}()
|
|
|
|
|
2017-10-22 01:30:34 -04:00
|
|
|
hashReader, err := hash.NewReader(pipeReader, length, "", "")
|
|
|
|
if err != nil {
|
|
|
|
return pi, toObjectErr(err, dstBucket, dstObject)
|
|
|
|
}
|
|
|
|
|
|
|
|
partInfo, err := xl.PutObjectPart(dstBucket, dstObject, uploadID, partID, hashReader)
|
2017-01-31 12:38:34 -05:00
|
|
|
if err != nil {
|
2017-06-21 22:53:09 -04:00
|
|
|
return pi, toObjectErr(err, dstBucket, dstObject)
|
2017-01-31 12:38:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Explicitly close the reader.
|
|
|
|
pipeReader.Close()
|
|
|
|
|
|
|
|
// Success.
|
|
|
|
return partInfo, nil
|
|
|
|
}
|
|
|
|
|
2016-07-05 04:04:50 -04:00
|
|
|
// PutObjectPart - reads incoming stream and internally erasure codes
|
|
|
|
// them. This call is similar to single put operation but it is part
|
2016-08-05 01:01:58 -04:00
|
|
|
// of the multipart transaction.
|
2016-07-05 04:04:50 -04:00
|
|
|
//
|
|
|
|
// Implements S3 compatible Upload Part API.
|
2017-10-22 01:30:34 -04:00
|
|
|
func (xl xlObjects) PutObjectPart(bucket, object, uploadID string, partID int, data *hash.Reader) (pi PartInfo, e error) {
|
2016-12-02 02:15:17 -05:00
|
|
|
if err := checkPutObjectPartArgs(bucket, object, xl); err != nil {
|
2017-06-21 22:53:09 -04:00
|
|
|
return pi, err
|
2016-07-05 04:04:50 -04:00
|
|
|
}
|
2016-05-27 04:12:44 -04:00
|
|
|
|
2017-10-06 12:38:01 -04:00
|
|
|
// Validate input data size and it can never be less than zero.
|
|
|
|
if data.Size() < 0 {
|
|
|
|
return pi, toObjectErr(traceError(errInvalidArgument))
|
|
|
|
}
|
|
|
|
|
2016-07-11 20:24:49 -04:00
|
|
|
var partsMetadata []xlMetaV1
|
|
|
|
var errs []error
|
2016-11-22 16:15:06 -05:00
|
|
|
uploadIDPath := pathJoin(bucket, object, uploadID)
|
2016-08-31 14:39:08 -04:00
|
|
|
|
2016-11-09 13:58:41 -05:00
|
|
|
// pre-check upload id lock.
|
2016-12-10 19:15:12 -05:00
|
|
|
preUploadIDLock := globalNSMutex.NewNSLock(minioMetaMultipartBucket, uploadIDPath)
|
2017-08-31 14:29:22 -04:00
|
|
|
if err := preUploadIDLock.GetRLock(globalOperationTimeout); err != nil {
|
|
|
|
return pi, err
|
|
|
|
}
|
2017-10-06 12:38:01 -04:00
|
|
|
|
2016-07-11 20:24:49 -04:00
|
|
|
// Validates if upload ID exists.
|
2016-05-20 23:48:47 -04:00
|
|
|
if !xl.isUploadIDExists(bucket, object, uploadID) {
|
2016-11-09 13:58:41 -05:00
|
|
|
preUploadIDLock.RUnlock()
|
2017-06-21 22:53:09 -04:00
|
|
|
return pi, traceError(InvalidUploadID{UploadID: uploadID})
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2017-01-31 12:38:34 -05:00
|
|
|
|
2016-05-31 23:23:31 -04:00
|
|
|
// Read metadata associated with the object from all disks.
|
2016-11-22 16:15:06 -05:00
|
|
|
partsMetadata, errs = readAllXLMetadata(xl.storageDisks, minioMetaMultipartBucket,
|
2016-07-11 20:24:49 -04:00
|
|
|
uploadIDPath)
|
2017-02-01 14:16:17 -05:00
|
|
|
reducedErr := reduceWriteQuorumErrs(errs, objectOpIgnoredErrs, xl.writeQuorum)
|
|
|
|
if errorCause(reducedErr) == errXLWriteQuorum {
|
2016-11-09 13:58:41 -05:00
|
|
|
preUploadIDLock.RUnlock()
|
2017-06-21 22:53:09 -04:00
|
|
|
return pi, toObjectErr(reducedErr, bucket, object)
|
2016-06-27 13:01:09 -04:00
|
|
|
}
|
2016-11-09 13:58:41 -05:00
|
|
|
preUploadIDLock.RUnlock()
|
2016-05-30 14:26:10 -04:00
|
|
|
|
2016-05-25 19:42:31 -04:00
|
|
|
// List all online disks.
|
2016-07-14 17:59:01 -04:00
|
|
|
onlineDisks, modTime := listOnlineDisks(xl.storageDisks, partsMetadata, errs)
|
2016-07-12 18:20:31 -04:00
|
|
|
|
|
|
|
// Pick one from the first valid metadata.
|
2016-11-20 23:56:44 -05:00
|
|
|
xlMeta, err := pickValidXLMeta(partsMetadata, modTime)
|
|
|
|
if err != nil {
|
2017-06-21 22:53:09 -04:00
|
|
|
return pi, err
|
2016-11-20 23:56:44 -05:00
|
|
|
}
|
2016-07-14 17:59:01 -04:00
|
|
|
|
2017-02-24 12:20:40 -05:00
|
|
|
onlineDisks = shuffleDisks(onlineDisks, xlMeta.Erasure.Distribution)
|
2016-05-26 22:55:48 -04:00
|
|
|
|
2016-07-11 20:24:49 -04:00
|
|
|
// Need a unique name for the part being written in minioMetaBucket to
|
|
|
|
// accommodate concurrent PutObjectPart requests
|
2016-07-12 18:20:31 -04:00
|
|
|
|
2016-06-28 00:42:33 -04:00
|
|
|
partSuffix := fmt.Sprintf("part.%d", partID)
|
2016-11-22 19:52:37 -05:00
|
|
|
tmpPart := mustGetUUID()
|
|
|
|
tmpPartPath := path.Join(tmpPart, partSuffix)
|
2016-05-20 23:48:47 -04:00
|
|
|
|
2016-10-20 01:52:03 -04:00
|
|
|
// Delete the temporary object part. If PutObjectPart succeeds there would be nothing to delete.
|
2016-11-21 19:34:57 -05:00
|
|
|
defer xl.deleteObject(minioMetaTmpBucket, tmpPart)
|
2017-09-19 15:40:27 -04:00
|
|
|
if data.Size() > 0 {
|
|
|
|
if pErr := xl.prepareFile(minioMetaTmpBucket, tmpPartPath, data.Size(), onlineDisks, xlMeta.Erasure.BlockSize, xlMeta.Erasure.DataBlocks); err != nil {
|
2017-06-21 22:53:09 -04:00
|
|
|
return pi, toObjectErr(pErr, bucket, object)
|
2017-03-07 17:48:56 -05:00
|
|
|
|
2016-10-29 15:44:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-14 21:08:42 -04:00
|
|
|
storage, err := NewErasureStorage(onlineDisks, xlMeta.Erasure.DataBlocks, xlMeta.Erasure.ParityBlocks)
|
|
|
|
if err != nil {
|
|
|
|
return pi, toObjectErr(err, bucket, object)
|
|
|
|
}
|
|
|
|
buffer := make([]byte, xlMeta.Erasure.BlockSize, 2*xlMeta.Erasure.BlockSize) // alloc additional space for parity blocks created while erasure coding
|
2017-09-19 15:40:27 -04:00
|
|
|
file, err := storage.CreateFile(data, minioMetaTmpBucket, tmpPartPath, buffer, DefaultBitrotAlgorithm, xl.writeQuorum)
|
2016-07-18 22:06:48 -04:00
|
|
|
if err != nil {
|
2017-06-21 22:53:09 -04:00
|
|
|
return pi, toObjectErr(err, bucket, object)
|
2016-07-18 22:06:48 -04:00
|
|
|
}
|
2016-10-20 01:52:03 -04:00
|
|
|
|
2016-07-18 22:06:48 -04:00
|
|
|
// Should return IncompleteBody{} error when reader has fewer bytes
|
|
|
|
// than specified in request header.
|
2017-09-19 15:40:27 -04:00
|
|
|
if file.Size < data.Size() {
|
2017-06-21 22:53:09 -04:00
|
|
|
return pi, traceError(IncompleteBody{})
|
2016-07-18 22:06:48 -04:00
|
|
|
}
|
2016-07-01 17:33:28 -04:00
|
|
|
|
2016-11-09 13:58:41 -05:00
|
|
|
// post-upload check (write) lock
|
2016-12-10 19:15:12 -05:00
|
|
|
postUploadIDLock := globalNSMutex.NewNSLock(minioMetaMultipartBucket, uploadIDPath)
|
2017-08-31 14:29:22 -04:00
|
|
|
if err = postUploadIDLock.GetLock(globalOperationTimeout); err != nil {
|
|
|
|
return pi, err
|
|
|
|
}
|
2016-11-09 13:58:41 -05:00
|
|
|
defer postUploadIDLock.Unlock()
|
2016-07-11 20:24:49 -04:00
|
|
|
|
2016-07-14 17:59:01 -04:00
|
|
|
// Validate again if upload ID still exists.
|
2016-05-30 14:26:10 -04:00
|
|
|
if !xl.isUploadIDExists(bucket, object, uploadID) {
|
2017-06-21 22:53:09 -04:00
|
|
|
return pi, traceError(InvalidUploadID{UploadID: uploadID})
|
2016-05-30 14:26:10 -04:00
|
|
|
}
|
|
|
|
|
2016-05-29 18:38:14 -04:00
|
|
|
// Rename temporary part file to its final location.
|
2016-05-31 23:23:31 -04:00
|
|
|
partPath := path.Join(uploadIDPath, partSuffix)
|
2017-06-14 20:14:27 -04:00
|
|
|
onlineDisks, err = renamePart(onlineDisks, minioMetaTmpBucket, tmpPartPath, minioMetaMultipartBucket, partPath, xl.writeQuorum)
|
2016-05-20 23:48:47 -04:00
|
|
|
if err != nil {
|
2017-06-21 22:53:09 -04:00
|
|
|
return pi, toObjectErr(err, minioMetaMultipartBucket, partPath)
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-05-26 06:15:01 -04:00
|
|
|
|
2016-07-14 17:59:01 -04:00
|
|
|
// Read metadata again because it might be updated with parallel upload of another part.
|
2016-11-22 16:15:06 -05:00
|
|
|
partsMetadata, errs = readAllXLMetadata(onlineDisks, minioMetaMultipartBucket, uploadIDPath)
|
2017-02-01 14:16:17 -05:00
|
|
|
reducedErr = reduceWriteQuorumErrs(errs, objectOpIgnoredErrs, xl.writeQuorum)
|
|
|
|
if errorCause(reducedErr) == errXLWriteQuorum {
|
2017-06-21 22:53:09 -04:00
|
|
|
return pi, toObjectErr(reducedErr, bucket, object)
|
2016-07-11 20:24:49 -04:00
|
|
|
}
|
|
|
|
|
2016-07-14 17:59:01 -04:00
|
|
|
// Get current highest version based on re-read partsMetadata.
|
|
|
|
onlineDisks, modTime = listOnlineDisks(onlineDisks, partsMetadata, errs)
|
2016-07-11 20:24:49 -04:00
|
|
|
|
|
|
|
// Pick one from the first valid metadata.
|
2016-11-20 23:56:44 -05:00
|
|
|
xlMeta, err = pickValidXLMeta(partsMetadata, modTime)
|
|
|
|
if err != nil {
|
2017-06-21 22:53:09 -04:00
|
|
|
return pi, err
|
2016-11-20 23:56:44 -05:00
|
|
|
}
|
2016-07-11 20:24:49 -04:00
|
|
|
|
2016-05-26 06:15:01 -04:00
|
|
|
// Once part is successfully committed, proceed with updating XL metadata.
|
2017-03-18 14:28:41 -04:00
|
|
|
xlMeta.Stat.ModTime = UTCNow()
|
2016-06-17 14:57:51 -04:00
|
|
|
|
2017-10-24 15:25:42 -04:00
|
|
|
md5hex := hex.EncodeToString(data.MD5Current())
|
2017-10-22 01:30:34 -04:00
|
|
|
|
2016-05-31 23:23:31 -04:00
|
|
|
// Add the current part.
|
2017-10-22 01:30:34 -04:00
|
|
|
xlMeta.AddObjectPart(partID, partSuffix, md5hex, file.Size)
|
2016-05-26 06:15:01 -04:00
|
|
|
|
2017-08-14 21:08:42 -04:00
|
|
|
for i, disk := range onlineDisks {
|
|
|
|
if disk == OfflineDisk {
|
2016-07-14 17:59:01 -04:00
|
|
|
continue
|
|
|
|
}
|
2017-08-14 21:08:42 -04:00
|
|
|
partsMetadata[i].Parts = xlMeta.Parts
|
|
|
|
partsMetadata[i].Erasure.AddChecksumInfo(ChecksumInfo{partSuffix, file.Algorithm, file.Checksums[i]})
|
2016-05-31 23:23:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Write all the checksum metadata.
|
2016-11-22 19:52:37 -05:00
|
|
|
newUUID := mustGetUUID()
|
2016-11-20 17:25:43 -05:00
|
|
|
tempXLMetaPath := newUUID
|
2016-05-31 23:23:31 -04:00
|
|
|
|
2016-07-19 22:24:32 -04:00
|
|
|
// Writes a unique `xl.json` each disk carrying new checksum related information.
|
2017-06-14 20:14:27 -04:00
|
|
|
if onlineDisks, err = writeUniqueXLMetadata(onlineDisks, minioMetaTmpBucket, tempXLMetaPath, partsMetadata, xl.writeQuorum); err != nil {
|
2017-06-21 22:53:09 -04:00
|
|
|
return pi, toObjectErr(err, minioMetaTmpBucket, tempXLMetaPath)
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2017-08-23 20:58:52 -04:00
|
|
|
|
|
|
|
if _, err = commitXLMetadata(onlineDisks, minioMetaTmpBucket, tempXLMetaPath, minioMetaMultipartBucket, uploadIDPath, xl.writeQuorum); err != nil {
|
|
|
|
return pi, toObjectErr(err, minioMetaMultipartBucket, uploadIDPath)
|
2017-01-31 12:38:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fi, err := xl.statPart(bucket, object, uploadID, partSuffix)
|
|
|
|
if err != nil {
|
2017-08-23 20:58:52 -04:00
|
|
|
return pi, toObjectErr(err, minioMetaMultipartBucket, partSuffix)
|
2016-05-28 18:13:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return success.
|
2017-01-31 12:38:34 -05:00
|
|
|
return PartInfo{
|
|
|
|
PartNumber: partID,
|
|
|
|
LastModified: fi.ModTime,
|
2017-10-22 01:30:34 -04:00
|
|
|
ETag: md5hex,
|
2017-01-31 12:38:34 -05:00
|
|
|
Size: fi.Size,
|
|
|
|
}, nil
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// listObjectParts - wrapper reading `xl.json` for a given object and
|
|
|
|
// uploadID. Lists all the parts captured inside `xl.json` content.
|
2017-06-21 22:53:09 -04:00
|
|
|
func (xl xlObjects) listObjectParts(bucket, object, uploadID string, partNumberMarker, maxParts int) (lpi ListPartsInfo, e error) {
|
2016-05-20 23:48:47 -04:00
|
|
|
result := ListPartsInfo{}
|
|
|
|
|
2016-11-22 16:15:06 -05:00
|
|
|
uploadIDPath := path.Join(bucket, object, uploadID)
|
2016-05-31 23:23:31 -04:00
|
|
|
|
2016-11-22 16:15:06 -05:00
|
|
|
xlParts, err := xl.readXLMetaParts(minioMetaMultipartBucket, uploadIDPath)
|
2016-05-20 23:48:47 -04:00
|
|
|
if err != nil {
|
2017-06-21 22:53:09 -04:00
|
|
|
return lpi, toObjectErr(err, minioMetaMultipartBucket, uploadIDPath)
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-05-25 00:24:20 -04:00
|
|
|
|
|
|
|
// Populate the result stub.
|
|
|
|
result.Bucket = bucket
|
|
|
|
result.Object = object
|
|
|
|
result.UploadID = uploadID
|
|
|
|
result.MaxParts = maxParts
|
|
|
|
|
|
|
|
// For empty number of parts or maxParts as zero, return right here.
|
2016-09-09 01:38:18 -04:00
|
|
|
if len(xlParts) == 0 || maxParts == 0 {
|
2016-05-25 00:24:20 -04:00
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Limit output to maxPartsList.
|
|
|
|
if maxParts > maxPartsList {
|
|
|
|
maxParts = maxPartsList
|
|
|
|
}
|
|
|
|
|
2016-05-20 23:48:47 -04:00
|
|
|
// Only parts with higher part numbers will be listed.
|
2016-09-09 01:38:18 -04:00
|
|
|
partIdx := objectPartIndex(xlParts, partNumberMarker)
|
|
|
|
parts := xlParts
|
2016-05-25 00:24:20 -04:00
|
|
|
if partIdx != -1 {
|
2016-09-09 01:38:18 -04:00
|
|
|
parts = xlParts[partIdx+1:]
|
2016-05-25 00:24:20 -04:00
|
|
|
}
|
2016-05-20 23:48:47 -04:00
|
|
|
count := maxParts
|
2016-05-25 00:24:20 -04:00
|
|
|
for _, part := range parts {
|
2016-05-25 04:33:39 -04:00
|
|
|
var fi FileInfo
|
2016-06-07 21:15:04 -04:00
|
|
|
fi, err = xl.statPart(bucket, object, uploadID, part.Name)
|
2016-05-20 23:48:47 -04:00
|
|
|
if err != nil {
|
2017-06-21 22:53:09 -04:00
|
|
|
return lpi, toObjectErr(err, minioMetaBucket, path.Join(uploadID, part.Name))
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2017-01-31 12:38:34 -05:00
|
|
|
result.Parts = append(result.Parts, PartInfo{
|
2016-05-25 00:24:20 -04:00
|
|
|
PartNumber: part.Number,
|
2016-05-20 23:48:47 -04:00
|
|
|
ETag: part.ETag,
|
|
|
|
LastModified: fi.ModTime,
|
2016-05-28 03:18:58 -04:00
|
|
|
Size: part.Size,
|
2016-05-20 23:48:47 -04:00
|
|
|
})
|
|
|
|
count--
|
|
|
|
if count == 0 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If listed entries are more than maxParts, we set IsTruncated as true.
|
|
|
|
if len(parts) > len(result.Parts) {
|
|
|
|
result.IsTruncated = true
|
|
|
|
// Make sure to fill next part number marker if IsTruncated is
|
|
|
|
// true for subsequent listing.
|
|
|
|
nextPartNumberMarker := result.Parts[len(result.Parts)-1].PartNumber
|
|
|
|
result.NextPartNumberMarker = nextPartNumberMarker
|
|
|
|
}
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// ListObjectParts - lists all previously uploaded parts for a given
|
|
|
|
// object and uploadID. Takes additional input of part-number-marker
|
|
|
|
// to indicate where the listing should begin from.
|
|
|
|
//
|
|
|
|
// Implements S3 compatible ListObjectParts API. The resulting
|
|
|
|
// ListPartsInfo structure is unmarshalled directly into XML and
|
|
|
|
// replied back to the client.
|
2017-06-21 22:53:09 -04:00
|
|
|
func (xl xlObjects) ListObjectParts(bucket, object, uploadID string, partNumberMarker, maxParts int) (lpi ListPartsInfo, e error) {
|
2016-12-02 02:15:17 -05:00
|
|
|
if err := checkListPartsArgs(bucket, object, xl); err != nil {
|
2017-06-21 22:53:09 -04:00
|
|
|
return lpi, err
|
2016-06-01 19:43:31 -04:00
|
|
|
}
|
2016-08-31 14:39:08 -04:00
|
|
|
|
2016-11-09 13:58:41 -05:00
|
|
|
// Hold lock so that there is no competing
|
|
|
|
// abort-multipart-upload or complete-multipart-upload.
|
2016-12-10 19:15:12 -05:00
|
|
|
uploadIDLock := globalNSMutex.NewNSLock(minioMetaMultipartBucket,
|
2016-11-22 16:15:06 -05:00
|
|
|
pathJoin(bucket, object, uploadID))
|
2017-08-31 14:29:22 -04:00
|
|
|
if err := uploadIDLock.GetLock(globalListingTimeout); err != nil {
|
|
|
|
return lpi, err
|
|
|
|
}
|
2016-11-09 13:58:41 -05:00
|
|
|
defer uploadIDLock.Unlock()
|
2016-06-01 19:43:31 -04:00
|
|
|
|
|
|
|
if !xl.isUploadIDExists(bucket, object, uploadID) {
|
2017-06-21 22:53:09 -04:00
|
|
|
return lpi, traceError(InvalidUploadID{UploadID: uploadID})
|
2016-06-01 19:43:31 -04:00
|
|
|
}
|
|
|
|
result, err := xl.listObjectParts(bucket, object, uploadID, partNumberMarker, maxParts)
|
|
|
|
return result, err
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// CompleteMultipartUpload - completes an ongoing multipart
|
|
|
|
// transaction after receiving all the parts indicated by the client.
|
|
|
|
// Returns an md5sum calculated by concatenating all the individual
|
|
|
|
// md5sums of all the parts.
|
|
|
|
//
|
|
|
|
// Implements S3 compatible Complete multipart API.
|
2017-11-14 03:25:10 -05:00
|
|
|
func (xl xlObjects) CompleteMultipartUpload(bucket string, object string, uploadID string, parts []CompletePart) (oi ObjectInfo, e error) {
|
2016-12-02 02:15:17 -05:00
|
|
|
if err := checkCompleteMultipartArgs(bucket, object, xl); err != nil {
|
2017-06-21 22:53:09 -04:00
|
|
|
return oi, err
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-08-31 14:39:08 -04:00
|
|
|
|
2016-05-20 23:48:47 -04:00
|
|
|
// Hold lock so that
|
2016-11-09 13:58:41 -05:00
|
|
|
//
|
2016-05-20 23:48:47 -04:00
|
|
|
// 1) no one aborts this multipart upload
|
2016-11-09 13:58:41 -05:00
|
|
|
//
|
|
|
|
// 2) no one does a parallel complete-multipart-upload on this
|
|
|
|
// multipart upload
|
2016-12-10 19:15:12 -05:00
|
|
|
uploadIDLock := globalNSMutex.NewNSLock(minioMetaMultipartBucket,
|
2016-11-22 16:15:06 -05:00
|
|
|
pathJoin(bucket, object, uploadID))
|
2017-08-31 14:29:22 -04:00
|
|
|
if err := uploadIDLock.GetLock(globalOperationTimeout); err != nil {
|
|
|
|
return oi, err
|
|
|
|
}
|
2016-11-09 13:58:41 -05:00
|
|
|
defer uploadIDLock.Unlock()
|
2016-05-20 23:48:47 -04:00
|
|
|
|
2016-05-28 00:50:09 -04:00
|
|
|
if !xl.isUploadIDExists(bucket, object, uploadID) {
|
2017-06-21 22:53:09 -04:00
|
|
|
return oi, traceError(InvalidUploadID{UploadID: uploadID})
|
2016-05-28 00:50:09 -04:00
|
|
|
}
|
2017-02-21 22:43:44 -05:00
|
|
|
|
|
|
|
// Check if an object is present as one of the parent dir.
|
|
|
|
// -- FIXME. (needs a new kind of lock).
|
|
|
|
if xl.parentDirIsObject(bucket, path.Dir(object)) {
|
2017-06-21 22:53:09 -04:00
|
|
|
return oi, toObjectErr(traceError(errFileAccessDenied), bucket, object)
|
2017-02-21 22:43:44 -05:00
|
|
|
}
|
|
|
|
|
2016-05-20 23:48:47 -04:00
|
|
|
// Calculate s3 compatible md5sum for complete multipart.
|
2016-11-10 10:41:02 -05:00
|
|
|
s3MD5, err := getCompleteMultipartMD5(parts)
|
2016-05-20 23:48:47 -04:00
|
|
|
if err != nil {
|
2017-06-21 22:53:09 -04:00
|
|
|
return oi, err
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2016-11-22 16:15:06 -05:00
|
|
|
uploadIDPath := pathJoin(bucket, object, uploadID)
|
2016-05-25 00:24:20 -04:00
|
|
|
|
2016-05-31 23:23:31 -04:00
|
|
|
// Read metadata associated with the object from all disks.
|
2016-11-22 16:15:06 -05:00
|
|
|
partsMetadata, errs := readAllXLMetadata(xl.storageDisks, minioMetaMultipartBucket, uploadIDPath)
|
2017-02-01 14:16:17 -05:00
|
|
|
reducedErr := reduceWriteQuorumErrs(errs, objectOpIgnoredErrs, xl.writeQuorum)
|
|
|
|
if errorCause(reducedErr) == errXLWriteQuorum {
|
2017-06-21 22:53:09 -04:00
|
|
|
return oi, toObjectErr(reducedErr, bucket, object)
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2016-07-27 14:57:08 -04:00
|
|
|
onlineDisks, modTime := listOnlineDisks(xl.storageDisks, partsMetadata, errs)
|
2016-07-14 17:59:01 -04:00
|
|
|
|
2016-05-31 23:23:31 -04:00
|
|
|
// Calculate full object size.
|
2016-05-20 23:48:47 -04:00
|
|
|
var objectSize int64
|
2016-05-25 00:24:20 -04:00
|
|
|
|
2016-05-31 23:23:31 -04:00
|
|
|
// Pick one from the first valid metadata.
|
2016-11-20 23:56:44 -05:00
|
|
|
xlMeta, err := pickValidXLMeta(partsMetadata, modTime)
|
|
|
|
if err != nil {
|
2017-06-21 22:53:09 -04:00
|
|
|
return oi, err
|
2016-11-20 23:56:44 -05:00
|
|
|
}
|
2016-05-31 23:23:31 -04:00
|
|
|
|
2016-07-27 14:57:08 -04:00
|
|
|
// Order online disks in accordance with distribution order.
|
2017-02-24 12:20:40 -05:00
|
|
|
onlineDisks = shuffleDisks(onlineDisks, xlMeta.Erasure.Distribution)
|
2016-07-27 14:57:08 -04:00
|
|
|
|
|
|
|
// Order parts metadata in accordance with distribution order.
|
2017-02-24 12:20:40 -05:00
|
|
|
partsMetadata = shufflePartsMetadata(partsMetadata, xlMeta.Erasure.Distribution)
|
2016-07-27 14:57:08 -04:00
|
|
|
|
2016-05-25 00:24:20 -04:00
|
|
|
// Save current xl meta for validation.
|
|
|
|
var currentXLMeta = xlMeta
|
|
|
|
|
|
|
|
// Allocate parts similar to incoming slice.
|
|
|
|
xlMeta.Parts = make([]objectPartInfo, len(parts))
|
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// Validate each part and then commit to disk.
|
2016-05-20 23:48:47 -04:00
|
|
|
for i, part := range parts {
|
2016-09-09 01:38:18 -04:00
|
|
|
partIdx := objectPartIndex(currentXLMeta.Parts, part.PartNumber)
|
2016-06-19 17:51:20 -04:00
|
|
|
// All parts should have same part number.
|
2016-05-25 00:24:20 -04:00
|
|
|
if partIdx == -1 {
|
2017-06-21 22:53:09 -04:00
|
|
|
return oi, traceError(InvalidPart{})
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-06-19 17:51:20 -04:00
|
|
|
|
|
|
|
// All parts should have same ETag as previously generated.
|
2016-05-25 00:24:20 -04:00
|
|
|
if currentXLMeta.Parts[partIdx].ETag != part.ETag {
|
2017-06-21 22:53:09 -04:00
|
|
|
return oi, traceError(InvalidPart{})
|
2016-05-25 00:24:20 -04:00
|
|
|
}
|
2016-06-19 17:51:20 -04:00
|
|
|
|
2016-05-20 23:48:47 -04:00
|
|
|
// All parts except the last part has to be atleast 5MB.
|
2016-05-25 00:24:20 -04:00
|
|
|
if (i < len(parts)-1) && !isMinAllowedPartSize(currentXLMeta.Parts[partIdx].Size) {
|
2017-06-21 22:53:09 -04:00
|
|
|
return oi, traceError(PartTooSmall{
|
2016-06-28 17:51:49 -04:00
|
|
|
PartNumber: part.PartNumber,
|
|
|
|
PartSize: currentXLMeta.Parts[partIdx].Size,
|
|
|
|
PartETag: part.ETag,
|
2016-08-25 12:39:01 -04:00
|
|
|
})
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-05-25 00:24:20 -04:00
|
|
|
|
2016-06-19 17:51:20 -04:00
|
|
|
// Last part could have been uploaded as 0bytes, do not need
|
|
|
|
// to save it in final `xl.json`.
|
|
|
|
if (i == len(parts)-1) && currentXLMeta.Parts[partIdx].Size == 0 {
|
|
|
|
xlMeta.Parts = xlMeta.Parts[:i] // Skip the part.
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2016-05-25 00:24:20 -04:00
|
|
|
// Save for total object size.
|
|
|
|
objectSize += currentXLMeta.Parts[partIdx].Size
|
|
|
|
|
|
|
|
// Add incoming parts.
|
|
|
|
xlMeta.Parts[i] = objectPartInfo{
|
|
|
|
Number: part.PartNumber,
|
|
|
|
ETag: part.ETag,
|
|
|
|
Size: currentXLMeta.Parts[partIdx].Size,
|
2016-06-28 00:42:33 -04:00
|
|
|
Name: fmt.Sprintf("part.%d", part.PartNumber),
|
2016-05-25 00:24:20 -04:00
|
|
|
}
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Save the final object size and modtime.
|
|
|
|
xlMeta.Stat.Size = objectSize
|
2017-03-18 14:28:41 -04:00
|
|
|
xlMeta.Stat.ModTime = UTCNow()
|
2016-05-20 23:48:47 -04:00
|
|
|
|
|
|
|
// Save successfully calculated md5sum.
|
2017-05-14 15:05:51 -04:00
|
|
|
xlMeta.Meta["etag"] = s3MD5
|
2017-10-22 01:30:34 -04:00
|
|
|
|
2016-11-22 16:15:06 -05:00
|
|
|
uploadIDPath = path.Join(bucket, object, uploadID)
|
2016-11-20 17:25:43 -05:00
|
|
|
tempUploadIDPath := uploadID
|
2016-05-31 23:23:31 -04:00
|
|
|
|
|
|
|
// Update all xl metadata, make sure to not modify fields like
|
|
|
|
// checksum which are different on each disks.
|
|
|
|
for index := range partsMetadata {
|
|
|
|
partsMetadata[index].Stat = xlMeta.Stat
|
|
|
|
partsMetadata[index].Meta = xlMeta.Meta
|
|
|
|
partsMetadata[index].Parts = xlMeta.Parts
|
|
|
|
}
|
2016-06-01 19:43:31 -04:00
|
|
|
|
2016-05-31 23:23:31 -04:00
|
|
|
// Write unique `xl.json` for each disk.
|
2017-06-14 20:14:27 -04:00
|
|
|
if onlineDisks, err = writeUniqueXLMetadata(onlineDisks, minioMetaTmpBucket, tempUploadIDPath, partsMetadata, xl.writeQuorum); err != nil {
|
2017-06-21 22:53:09 -04:00
|
|
|
return oi, toObjectErr(err, minioMetaTmpBucket, tempUploadIDPath)
|
2016-05-28 18:13:15 -04:00
|
|
|
}
|
2017-02-21 22:43:44 -05:00
|
|
|
|
2017-06-14 20:14:27 -04:00
|
|
|
var rErr error
|
|
|
|
onlineDisks, rErr = commitXLMetadata(onlineDisks, minioMetaTmpBucket, tempUploadIDPath, minioMetaMultipartBucket, uploadIDPath, xl.writeQuorum)
|
2016-05-28 18:13:15 -04:00
|
|
|
if rErr != nil {
|
2017-06-21 22:53:09 -04:00
|
|
|
return oi, toObjectErr(rErr, minioMetaMultipartBucket, uploadIDPath)
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-08-31 14:39:08 -04:00
|
|
|
|
2016-11-09 13:58:41 -05:00
|
|
|
defer func() {
|
2016-12-08 23:35:07 -05:00
|
|
|
if xl.objCacheEnabled {
|
|
|
|
// A new complete multipart upload invalidates any
|
|
|
|
// previously cached object in memory.
|
|
|
|
xl.objCache.Delete(path.Join(bucket, object))
|
2016-07-08 23:34:27 -04:00
|
|
|
|
2016-12-08 23:35:07 -05:00
|
|
|
// Prefetch the object from disk by triggering a fake GetObject call
|
|
|
|
// Unlike a regular single PutObject, multipart PutObject is comes in
|
|
|
|
// stages and it is harder to cache.
|
|
|
|
go xl.GetObject(bucket, object, 0, objectSize, ioutil.Discard)
|
|
|
|
}
|
2016-11-09 13:58:41 -05:00
|
|
|
}()
|
2016-05-20 23:48:47 -04:00
|
|
|
|
2016-06-20 09:18:47 -04:00
|
|
|
if xl.isObject(bucket, object) {
|
2017-02-21 22:43:44 -05:00
|
|
|
// Rename if an object already exists to temporary location.
|
|
|
|
newUniqueID := mustGetUUID()
|
|
|
|
|
|
|
|
// Delete success renamed object.
|
|
|
|
defer xl.deleteObject(minioMetaTmpBucket, newUniqueID)
|
|
|
|
|
2016-07-27 14:57:08 -04:00
|
|
|
// NOTE: Do not use online disks slice here.
|
|
|
|
// The reason is that existing object should be purged
|
|
|
|
// regardless of `xl.json` status and rolled back in case of errors.
|
2017-06-14 20:14:27 -04:00
|
|
|
_, err = renameObject(xl.storageDisks, bucket, object, minioMetaTmpBucket, newUniqueID, xl.writeQuorum)
|
2016-06-20 09:18:47 -04:00
|
|
|
if err != nil {
|
2017-06-21 22:53:09 -04:00
|
|
|
return oi, toObjectErr(err, bucket, object)
|
2016-06-20 09:18:47 -04:00
|
|
|
}
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2016-06-10 09:13:16 -04:00
|
|
|
// Remove parts that weren't present in CompleteMultipartUpload request.
|
2016-05-28 16:23:08 -04:00
|
|
|
for _, curpart := range currentXLMeta.Parts {
|
2016-09-09 01:38:18 -04:00
|
|
|
if objectPartIndex(xlMeta.Parts, curpart.Number) == -1 {
|
2016-05-28 16:23:08 -04:00
|
|
|
// Delete the missing part files. e.g,
|
|
|
|
// Request 1: NewMultipart
|
|
|
|
// Request 2: PutObjectPart 1
|
|
|
|
// Request 3: PutObjectPart 2
|
|
|
|
// Request 4: CompleteMultipartUpload --part 2
|
|
|
|
// N.B. 1st part is not present. This part should be removed from the storage.
|
|
|
|
xl.removeObjectPart(bucket, object, uploadID, curpart.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-29 03:42:09 -04:00
|
|
|
// Rename the multipart object to final location.
|
2017-08-23 20:58:52 -04:00
|
|
|
if _, err = renameObject(onlineDisks, minioMetaMultipartBucket, uploadIDPath, bucket, object, xl.writeQuorum); err != nil {
|
2017-06-21 22:53:09 -04:00
|
|
|
return oi, toObjectErr(err, bucket, object)
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2016-11-09 13:58:41 -05:00
|
|
|
// Hold the lock so that two parallel
|
|
|
|
// complete-multipart-uploads do not leave a stale
|
|
|
|
// uploads.json behind.
|
2016-12-10 19:15:12 -05:00
|
|
|
objectMPartPathLock := globalNSMutex.NewNSLock(minioMetaMultipartBucket,
|
2016-11-22 16:15:06 -05:00
|
|
|
pathJoin(bucket, object))
|
2017-08-31 14:29:22 -04:00
|
|
|
if err = objectMPartPathLock.GetLock(globalOperationTimeout); err != nil {
|
|
|
|
return oi, toObjectErr(err, bucket, object)
|
|
|
|
}
|
2016-11-09 13:58:41 -05:00
|
|
|
defer objectMPartPathLock.Unlock()
|
2016-05-20 23:48:47 -04:00
|
|
|
|
2016-10-30 12:27:29 -04:00
|
|
|
// remove entry from uploads.json with quorum
|
2016-11-22 18:29:39 -05:00
|
|
|
if err = xl.removeUploadID(bucket, object, uploadID); err != nil {
|
2017-06-21 22:53:09 -04:00
|
|
|
return oi, toObjectErr(err, minioMetaMultipartBucket, path.Join(bucket, object))
|
2017-01-16 22:23:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
objInfo := ObjectInfo{
|
|
|
|
IsDir: false,
|
|
|
|
Bucket: bucket,
|
|
|
|
Name: object,
|
|
|
|
Size: xlMeta.Stat.Size,
|
|
|
|
ModTime: xlMeta.Stat.ModTime,
|
2017-05-14 15:05:51 -04:00
|
|
|
ETag: xlMeta.Meta["etag"],
|
2017-01-16 22:23:43 -05:00
|
|
|
ContentType: xlMeta.Meta["content-type"],
|
|
|
|
ContentEncoding: xlMeta.Meta["content-encoding"],
|
|
|
|
UserDefined: xlMeta.Meta,
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2017-01-16 22:23:43 -05:00
|
|
|
// Success, return object info.
|
|
|
|
return objInfo, nil
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2017-02-01 14:16:17 -05:00
|
|
|
// Wrapper which removes all the uploaded parts.
|
|
|
|
func (xl xlObjects) cleanupUploadedParts(bucket, object, uploadID string) error {
|
|
|
|
var errs = make([]error, len(xl.storageDisks))
|
|
|
|
var wg = &sync.WaitGroup{}
|
|
|
|
|
|
|
|
// Construct uploadIDPath.
|
|
|
|
uploadIDPath := path.Join(bucket, object, uploadID)
|
|
|
|
|
|
|
|
// Cleanup uploadID for all disks.
|
|
|
|
for index, disk := range xl.storageDisks {
|
|
|
|
if disk == nil {
|
|
|
|
errs[index] = traceError(errDiskNotFound)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
wg.Add(1)
|
|
|
|
// Cleanup each uploadID in a routine.
|
|
|
|
go func(index int, disk StorageAPI) {
|
|
|
|
defer wg.Done()
|
|
|
|
err := cleanupDir(disk, minioMetaMultipartBucket, uploadIDPath)
|
|
|
|
if err != nil {
|
|
|
|
errs[index] = err
|
|
|
|
}
|
|
|
|
}(index, disk)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait for all the cleanups to finish.
|
|
|
|
wg.Wait()
|
|
|
|
|
|
|
|
return reduceWriteQuorumErrs(errs, objectOpIgnoredErrs, xl.writeQuorum)
|
|
|
|
}
|
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// abortMultipartUpload - wrapper for purging an ongoing multipart
|
|
|
|
// transaction, deletes uploadID entry from `uploads.json` and purges
|
2016-09-06 23:31:50 -04:00
|
|
|
// the directory at '.minio.sys/multipart/bucket/object/uploadID' holding
|
2016-06-01 19:43:31 -04:00
|
|
|
// all the upload parts.
|
|
|
|
func (xl xlObjects) abortMultipartUpload(bucket, object, uploadID string) (err error) {
|
|
|
|
// Cleanup all uploaded parts.
|
2017-02-01 14:16:17 -05:00
|
|
|
if err = xl.cleanupUploadedParts(bucket, object, uploadID); err != nil {
|
2016-06-01 19:43:31 -04:00
|
|
|
return toObjectErr(err, bucket, object)
|
|
|
|
}
|
|
|
|
|
2016-11-09 13:58:41 -05:00
|
|
|
// hold lock so we don't compete with a complete, or abort
|
|
|
|
// multipart request.
|
2016-12-10 19:15:12 -05:00
|
|
|
objectMPartPathLock := globalNSMutex.NewNSLock(minioMetaMultipartBucket,
|
2016-11-22 16:15:06 -05:00
|
|
|
pathJoin(bucket, object))
|
2017-08-31 14:29:22 -04:00
|
|
|
if err = objectMPartPathLock.GetLock(globalOperationTimeout); err != nil {
|
|
|
|
return toObjectErr(err, bucket, object)
|
|
|
|
}
|
2016-11-09 13:58:41 -05:00
|
|
|
defer objectMPartPathLock.Unlock()
|
2016-10-30 12:27:29 -04:00
|
|
|
|
|
|
|
// remove entry from uploads.json with quorum
|
2016-11-22 18:29:39 -05:00
|
|
|
if err = xl.removeUploadID(bucket, object, uploadID); err != nil {
|
2016-06-01 19:43:31 -04:00
|
|
|
return toObjectErr(err, bucket, object)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Successfully purged.
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// AbortMultipartUpload - aborts an ongoing multipart operation
|
|
|
|
// signified by the input uploadID. This is an atomic operation
|
|
|
|
// doesn't require clients to initiate multiple such requests.
|
|
|
|
//
|
|
|
|
// All parts are purged from all disks and reference to the uploadID
|
|
|
|
// would be removed from the system, rollback is not possible on this
|
|
|
|
// operation.
|
|
|
|
//
|
|
|
|
// Implements S3 compatible Abort multipart API, slight difference is
|
|
|
|
// that this is an atomic idempotent operation. Subsequent calls have
|
|
|
|
// no affect and further requests to the same uploadID would not be honored.
|
|
|
|
func (xl xlObjects) AbortMultipartUpload(bucket, object, uploadID string) error {
|
2016-12-02 02:15:17 -05:00
|
|
|
if err := checkAbortMultipartArgs(bucket, object, xl); err != nil {
|
|
|
|
return err
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2016-11-09 13:58:41 -05:00
|
|
|
// Hold lock so that there is no competing
|
|
|
|
// complete-multipart-upload or put-object-part.
|
2016-12-10 19:15:12 -05:00
|
|
|
uploadIDLock := globalNSMutex.NewNSLock(minioMetaMultipartBucket,
|
2016-11-22 16:15:06 -05:00
|
|
|
pathJoin(bucket, object, uploadID))
|
2017-08-31 14:29:22 -04:00
|
|
|
if err := uploadIDLock.GetLock(globalOperationTimeout); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-11-09 13:58:41 -05:00
|
|
|
defer uploadIDLock.Unlock()
|
2016-05-20 23:48:47 -04:00
|
|
|
|
2016-05-28 16:23:08 -04:00
|
|
|
if !xl.isUploadIDExists(bucket, object, uploadID) {
|
2016-08-25 12:39:01 -04:00
|
|
|
return traceError(InvalidUploadID{UploadID: uploadID})
|
2016-05-28 16:23:08 -04:00
|
|
|
}
|
2017-02-01 14:16:17 -05:00
|
|
|
return xl.abortMultipartUpload(bucket, object, uploadID)
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|