2016-06-01 19:43:31 -04:00
|
|
|
/*
|
|
|
|
* Minio Cloud Storage, (C) 2016 Minio, Inc.
|
|
|
|
*
|
|
|
|
* 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 (
|
|
|
|
"crypto/md5"
|
|
|
|
"encoding/hex"
|
2016-10-02 18:51:49 -04:00
|
|
|
"hash"
|
2016-05-20 23:48:47 -04:00
|
|
|
"io"
|
|
|
|
"path"
|
2017-01-30 18:44:42 -05:00
|
|
|
"strconv"
|
2016-05-20 23:48:47 -04:00
|
|
|
"strings"
|
|
|
|
"sync"
|
|
|
|
"time"
|
|
|
|
|
2016-07-25 17:17:01 -04:00
|
|
|
"github.com/minio/minio/pkg/bpool"
|
2016-05-20 23:48:47 -04:00
|
|
|
"github.com/minio/minio/pkg/mimedb"
|
2016-07-03 19:58:21 -04:00
|
|
|
"github.com/minio/minio/pkg/objcache"
|
2016-12-19 22:32:55 -05:00
|
|
|
"github.com/minio/sha256-simd"
|
2016-05-20 23:48:47 -04:00
|
|
|
)
|
|
|
|
|
2016-11-20 19:57:12 -05:00
|
|
|
// list all errors which can be ignored in object operations.
|
2017-02-01 14:16:17 -05:00
|
|
|
var objectOpIgnoredErrs = append(baseIgnoredErrs, errDiskAccessDenied)
|
2016-11-20 19:57:12 -05:00
|
|
|
|
2016-05-20 23:48:47 -04:00
|
|
|
/// Object Operations
|
|
|
|
|
2016-12-26 19:29:26 -05:00
|
|
|
// CopyObject - copy object source object to destination object.
|
|
|
|
// if source object and destination object are same we only
|
|
|
|
// update metadata.
|
|
|
|
func (xl xlObjects) CopyObject(srcBucket, srcObject, dstBucket, dstObject string, metadata map[string]string) (ObjectInfo, error) {
|
|
|
|
// Read metadata associated with the object from all disks.
|
|
|
|
metaArr, errs := readAllXLMetadata(xl.storageDisks, srcBucket, srcObject)
|
|
|
|
if reducedErr := reduceReadQuorumErrs(errs, objectOpIgnoredErrs, xl.readQuorum); reducedErr != nil {
|
|
|
|
return ObjectInfo{}, toObjectErr(reducedErr, srcBucket, srcObject)
|
|
|
|
}
|
|
|
|
|
|
|
|
// List all online disks.
|
|
|
|
onlineDisks, modTime := listOnlineDisks(xl.storageDisks, metaArr, errs)
|
|
|
|
|
|
|
|
// Pick latest valid metadata.
|
|
|
|
xlMeta, err := pickValidXLMeta(metaArr, modTime)
|
|
|
|
if err != nil {
|
|
|
|
return ObjectInfo{}, toObjectErr(err, srcBucket, srcObject)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reorder online disks based on erasure distribution order.
|
|
|
|
onlineDisks = getOrderedDisks(xlMeta.Erasure.Distribution, onlineDisks)
|
|
|
|
|
|
|
|
// Length of the file to read.
|
|
|
|
length := xlMeta.Stat.Size
|
|
|
|
|
|
|
|
// Check if this request is only metadata update.
|
|
|
|
cpMetadataOnly := strings.EqualFold(pathJoin(srcBucket, srcObject), pathJoin(dstBucket, dstObject))
|
|
|
|
if cpMetadataOnly {
|
|
|
|
xlMeta.Meta = metadata
|
|
|
|
partsMetadata := make([]xlMetaV1, len(xl.storageDisks))
|
|
|
|
// Update `xl.json` content on each disks.
|
|
|
|
for index := range partsMetadata {
|
|
|
|
partsMetadata[index] = xlMeta
|
|
|
|
}
|
|
|
|
|
|
|
|
tempObj := mustGetUUID()
|
|
|
|
|
|
|
|
// Write unique `xl.json` for each disk.
|
|
|
|
if err = writeUniqueXLMetadata(onlineDisks, minioMetaTmpBucket, tempObj, partsMetadata, xl.writeQuorum); err != nil {
|
|
|
|
return ObjectInfo{}, toObjectErr(err, srcBucket, srcObject)
|
|
|
|
}
|
|
|
|
// Rename atomically `xl.json` from tmp location to destination for each disk.
|
|
|
|
if err = renameXLMetadata(onlineDisks, minioMetaTmpBucket, tempObj, srcBucket, srcObject, xl.writeQuorum); err != nil {
|
|
|
|
return ObjectInfo{}, toObjectErr(err, srcBucket, srcObject)
|
|
|
|
}
|
|
|
|
|
|
|
|
objInfo := ObjectInfo{
|
|
|
|
IsDir: false,
|
|
|
|
Bucket: srcBucket,
|
|
|
|
Name: srcObject,
|
|
|
|
Size: xlMeta.Stat.Size,
|
|
|
|
ModTime: xlMeta.Stat.ModTime,
|
|
|
|
MD5Sum: xlMeta.Meta["md5Sum"],
|
|
|
|
ContentType: xlMeta.Meta["content-type"],
|
|
|
|
ContentEncoding: xlMeta.Meta["content-encoding"],
|
|
|
|
}
|
|
|
|
// md5Sum has already been extracted into objInfo.MD5Sum. We
|
|
|
|
// need to remove it from xlMetaMap to avoid it from appearing as
|
|
|
|
// part of response headers. e.g, X-Minio-* or X-Amz-*.
|
|
|
|
delete(xlMeta.Meta, "md5Sum")
|
|
|
|
objInfo.UserDefined = xlMeta.Meta
|
|
|
|
return objInfo, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize pipe.
|
|
|
|
pipeReader, pipeWriter := io.Pipe()
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
startOffset := int64(0) // Read the whole file.
|
|
|
|
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.
|
|
|
|
}()
|
|
|
|
|
|
|
|
objInfo, err := xl.PutObject(dstBucket, dstObject, length, pipeReader, metadata, "")
|
|
|
|
if err != nil {
|
|
|
|
return ObjectInfo{}, toObjectErr(err, dstBucket, dstObject)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Explicitly close the reader.
|
|
|
|
pipeReader.Close()
|
|
|
|
|
|
|
|
return objInfo, nil
|
|
|
|
}
|
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// GetObject - reads an object erasured coded across multiple
|
|
|
|
// disks. Supports additional parameters like offset and length
|
2016-12-26 19:29:26 -05:00
|
|
|
// which are synonymous with HTTP Range requests.
|
2016-06-01 19:43:31 -04:00
|
|
|
//
|
2016-12-26 19:29:26 -05:00
|
|
|
// startOffset indicates the starting read location of the object.
|
|
|
|
// length indicates the total length of the object.
|
2016-05-28 18:13:15 -04:00
|
|
|
func (xl xlObjects) GetObject(bucket, object string, startOffset int64, length int64, writer io.Writer) error {
|
2016-12-02 02:15:17 -05:00
|
|
|
if err := checkGetObjArgs(bucket, object); err != nil {
|
|
|
|
return err
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-12-21 14:29:32 -05:00
|
|
|
|
|
|
|
// Start offset cannot be negative.
|
|
|
|
if startOffset < 0 {
|
2016-08-25 12:39:01 -04:00
|
|
|
return traceError(errUnexpected)
|
2016-07-07 04:30:34 -04:00
|
|
|
}
|
2016-12-21 14:29:32 -05:00
|
|
|
|
2016-07-08 10:46:49 -04:00
|
|
|
// Writer cannot be nil.
|
|
|
|
if writer == nil {
|
2016-08-25 12:39:01 -04:00
|
|
|
return traceError(errUnexpected)
|
2016-07-08 10:46:49 -04:00
|
|
|
}
|
2016-08-31 14:39:08 -04:00
|
|
|
|
2016-05-31 23:23:31 -04:00
|
|
|
// Read metadata associated with the object from all disks.
|
2016-07-11 20:24:49 -04:00
|
|
|
metaArr, errs := readAllXLMetadata(xl.storageDisks, bucket, object)
|
2016-11-21 04:47:26 -05:00
|
|
|
if reducedErr := reduceReadQuorumErrs(errs, objectOpIgnoredErrs, xl.readQuorum); reducedErr != nil {
|
2016-07-19 22:24:32 -04:00
|
|
|
return toObjectErr(reducedErr, bucket, object)
|
2016-07-09 16:01:32 -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, metaArr, errs)
|
2016-05-26 22:55:48 -04:00
|
|
|
|
2016-06-17 01:26:18 -04:00
|
|
|
// Pick latest valid metadata.
|
2016-11-20 23:56:44 -05:00
|
|
|
xlMeta, err := pickValidXLMeta(metaArr, modTime)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-07-25 01:49:27 -04:00
|
|
|
|
|
|
|
// Reorder online disks based on erasure distribution order.
|
2016-07-16 11:35:30 -04:00
|
|
|
onlineDisks = getOrderedDisks(xlMeta.Erasure.Distribution, onlineDisks)
|
2016-07-25 01:49:27 -04:00
|
|
|
|
|
|
|
// Reorder parts metadata based on erasure distribution order.
|
2016-07-16 11:35:30 -04:00
|
|
|
metaArr = getOrderedPartsMetadata(xlMeta.Erasure.Distribution, metaArr)
|
2016-05-25 19:42:31 -04:00
|
|
|
|
2016-12-21 14:29:32 -05:00
|
|
|
// For negative length read everything.
|
|
|
|
if length < 0 {
|
|
|
|
length = xlMeta.Stat.Size - startOffset
|
2016-07-08 10:46:49 -04:00
|
|
|
}
|
|
|
|
|
2016-12-21 14:29:32 -05:00
|
|
|
// Reply back invalid range if the input offset and length fall out of range.
|
|
|
|
if startOffset > xlMeta.Stat.Size || startOffset+length > xlMeta.Stat.Size {
|
2016-08-25 12:39:01 -04:00
|
|
|
return traceError(InvalidRange{startOffset, length, xlMeta.Stat.Size})
|
2016-07-08 10:46:49 -04:00
|
|
|
}
|
|
|
|
|
2016-06-19 16:35:26 -04:00
|
|
|
// Get start part index and offset.
|
2016-05-31 23:23:31 -04:00
|
|
|
partIndex, partOffset, err := xlMeta.ObjectToPartOffset(startOffset)
|
2016-05-20 23:48:47 -04:00
|
|
|
if err != nil {
|
2016-08-25 12:39:01 -04:00
|
|
|
return traceError(InvalidRange{startOffset, length, xlMeta.Stat.Size})
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-05-31 23:23:31 -04:00
|
|
|
|
2017-01-27 13:51:02 -05:00
|
|
|
// Calculate endOffset according to length
|
|
|
|
endOffset := startOffset
|
|
|
|
if length > 0 {
|
|
|
|
endOffset += length - 1
|
|
|
|
}
|
|
|
|
|
2016-06-19 16:35:26 -04:00
|
|
|
// Get last part index to read given length.
|
2017-01-27 13:51:02 -05:00
|
|
|
lastPartIndex, _, err := xlMeta.ObjectToPartOffset(endOffset)
|
2016-06-19 16:35:26 -04:00
|
|
|
if err != nil {
|
2016-08-25 12:39:01 -04:00
|
|
|
return traceError(InvalidRange{startOffset, length, xlMeta.Stat.Size})
|
2016-06-19 16:35:26 -04:00
|
|
|
}
|
|
|
|
|
2016-07-03 19:58:21 -04:00
|
|
|
// Save the writer.
|
|
|
|
mw := writer
|
|
|
|
|
|
|
|
// Object cache enabled block.
|
2016-07-08 23:34:27 -04:00
|
|
|
if xlMeta.Stat.Size > 0 && xl.objCacheEnabled {
|
2016-07-03 19:58:21 -04:00
|
|
|
// Validate if we have previous cache.
|
2017-02-11 20:17:58 -05:00
|
|
|
var cachedBuffer io.ReaderAt
|
2016-09-23 22:55:28 -04:00
|
|
|
cachedBuffer, err = xl.objCache.Open(path.Join(bucket, object), modTime)
|
2017-02-11 20:17:58 -05:00
|
|
|
if err == nil { // Cache hit
|
|
|
|
// Create a new section reader, starting at an offset with length.
|
|
|
|
reader := io.NewSectionReader(cachedBuffer, startOffset, length)
|
|
|
|
|
|
|
|
// Copy the data out.
|
|
|
|
if _, err = io.Copy(writer, reader); err != nil {
|
2016-08-25 12:39:01 -04:00
|
|
|
return traceError(err)
|
2016-07-03 19:58:21 -04:00
|
|
|
}
|
2017-02-11 20:17:58 -05:00
|
|
|
|
|
|
|
// Success.
|
2016-07-03 19:58:21 -04:00
|
|
|
return nil
|
2017-02-11 20:17:58 -05:00
|
|
|
|
2016-07-03 19:58:21 -04:00
|
|
|
} // Cache miss.
|
2017-02-11 20:17:58 -05:00
|
|
|
|
2016-07-03 19:58:21 -04:00
|
|
|
// For unknown error, return and error out.
|
|
|
|
if err != objcache.ErrKeyNotFoundInCache {
|
2016-08-25 12:39:01 -04:00
|
|
|
return traceError(err)
|
2016-07-03 19:58:21 -04:00
|
|
|
} // Cache has not been found, fill the cache.
|
|
|
|
|
|
|
|
// Cache is only set if whole object is being read.
|
|
|
|
if startOffset == 0 && length == xlMeta.Stat.Size {
|
2016-07-05 04:04:50 -04:00
|
|
|
// Proceed to set the cache.
|
2016-07-06 04:29:49 -04:00
|
|
|
var newBuffer io.WriteCloser
|
2016-07-03 19:58:21 -04:00
|
|
|
// Create a new entry in memory of length.
|
|
|
|
newBuffer, err = xl.objCache.Create(path.Join(bucket, object), length)
|
2016-07-05 04:04:50 -04:00
|
|
|
if err == nil {
|
|
|
|
// Create a multi writer to write to both memory and client response.
|
|
|
|
mw = io.MultiWriter(newBuffer, writer)
|
2016-07-06 04:29:49 -04:00
|
|
|
defer newBuffer.Close()
|
2016-07-05 04:04:50 -04:00
|
|
|
}
|
2016-07-08 23:34:27 -04:00
|
|
|
// Ignore error if cache is full, proceed to write the object.
|
2016-07-05 04:04:50 -04:00
|
|
|
if err != nil && err != objcache.ErrCacheFull {
|
2016-07-08 23:34:27 -04:00
|
|
|
// For any other error return here.
|
2016-08-25 12:39:01 -04:00
|
|
|
return toObjectErr(traceError(err), bucket, object)
|
2016-07-03 19:58:21 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-19 16:35:26 -04:00
|
|
|
totalBytesRead := int64(0)
|
2016-07-25 17:17:01 -04:00
|
|
|
|
|
|
|
chunkSize := getChunkSize(xlMeta.Erasure.BlockSize, xlMeta.Erasure.DataBlocks)
|
|
|
|
pool := bpool.NewBytePool(chunkSize, len(onlineDisks))
|
|
|
|
|
2016-05-31 23:23:31 -04:00
|
|
|
// Read from all parts.
|
2016-06-19 16:35:26 -04:00
|
|
|
for ; partIndex <= lastPartIndex; partIndex++ {
|
2016-06-21 17:34:11 -04:00
|
|
|
if length == totalBytesRead {
|
|
|
|
break
|
|
|
|
}
|
2016-05-31 23:23:31 -04:00
|
|
|
// Save the current part name and size.
|
|
|
|
partName := xlMeta.Parts[partIndex].Name
|
|
|
|
partSize := xlMeta.Parts[partIndex].Size
|
2016-06-22 12:05:03 -04:00
|
|
|
|
2016-06-21 17:34:11 -04:00
|
|
|
readSize := partSize - partOffset
|
2016-06-22 12:05:03 -04:00
|
|
|
// readSize should be adjusted so that we don't write more data than what was requested.
|
2016-06-21 17:34:11 -04:00
|
|
|
if readSize > (length - totalBytesRead) {
|
|
|
|
readSize = length - totalBytesRead
|
2016-06-19 16:35:26 -04:00
|
|
|
}
|
2016-05-31 23:23:31 -04:00
|
|
|
|
2016-07-16 11:35:30 -04:00
|
|
|
// Get the checksums of the current part.
|
|
|
|
checkSums := make([]string, len(onlineDisks))
|
2016-07-28 05:20:34 -04:00
|
|
|
var ckSumAlgo string
|
2016-07-25 01:49:27 -04:00
|
|
|
for index, disk := range onlineDisks {
|
|
|
|
// Disk is not found skip the checksum.
|
|
|
|
if disk == nil {
|
|
|
|
checkSums[index] = ""
|
|
|
|
continue
|
|
|
|
}
|
2016-10-18 14:13:25 -04:00
|
|
|
ckSumInfo := metaArr[index].Erasure.GetCheckSumInfo(partName)
|
2016-07-28 05:20:34 -04:00
|
|
|
checkSums[index] = ckSumInfo.Hash
|
|
|
|
// Set checksum algo only once, while it is possible to have
|
|
|
|
// different algos per block because of our `xl.json`.
|
|
|
|
// It is not a requirement, set this only once for all the disks.
|
2017-01-30 17:25:28 -05:00
|
|
|
if ckSumAlgo == "" {
|
2016-07-28 05:20:34 -04:00
|
|
|
ckSumAlgo = ckSumInfo.Algorithm
|
|
|
|
}
|
2016-07-16 11:35:30 -04:00
|
|
|
}
|
|
|
|
|
2016-07-28 05:20:34 -04:00
|
|
|
// Start erasure decoding and writing to the client.
|
|
|
|
n, err := erasureReadFile(mw, onlineDisks, bucket, pathJoin(object, partName), partOffset, readSize, partSize, xlMeta.Erasure.BlockSize, xlMeta.Erasure.DataBlocks, xlMeta.Erasure.ParityBlocks, checkSums, ckSumAlgo, pool)
|
2016-05-31 23:23:31 -04:00
|
|
|
if err != nil {
|
2016-10-18 16:09:26 -04:00
|
|
|
errorIf(err, "Unable to read %s of the object `%s/%s`.", partName, bucket, object)
|
2016-07-08 23:34:27 -04:00
|
|
|
return toObjectErr(err, bucket, object)
|
2016-05-31 23:23:31 -04:00
|
|
|
}
|
|
|
|
|
2016-07-28 05:20:34 -04:00
|
|
|
// Track total bytes read from disk and written to the client.
|
2016-06-19 16:35:26 -04:00
|
|
|
totalBytesRead += n
|
2016-05-31 23:23:31 -04:00
|
|
|
|
2016-06-22 12:05:03 -04:00
|
|
|
// partOffset will be valid only for the first part, hence reset it to 0 for
|
|
|
|
// the remaining parts.
|
2016-05-31 23:23:31 -04:00
|
|
|
partOffset = 0
|
2016-06-01 19:43:31 -04:00
|
|
|
} // End of read all parts loop.
|
2016-05-31 23:23:31 -04:00
|
|
|
|
|
|
|
// Return success.
|
2016-05-28 18:13:15 -04:00
|
|
|
return nil
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// GetObjectInfo - reads object metadata and replies back ObjectInfo.
|
2016-05-20 23:48:47 -04:00
|
|
|
func (xl xlObjects) GetObjectInfo(bucket, object string) (ObjectInfo, error) {
|
2016-12-02 02:15:17 -05:00
|
|
|
if err := checkGetObjArgs(bucket, object); err != nil {
|
|
|
|
return ObjectInfo{}, 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
|
|
|
info, err := xl.getObjectInfo(bucket, object)
|
|
|
|
if err != nil {
|
|
|
|
return ObjectInfo{}, toObjectErr(err, bucket, object)
|
|
|
|
}
|
|
|
|
return info, nil
|
|
|
|
}
|
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// getObjectInfo - wrapper for reading object metadata and constructs ObjectInfo.
|
2016-05-20 23:48:47 -04:00
|
|
|
func (xl xlObjects) getObjectInfo(bucket, object string) (objInfo ObjectInfo, err error) {
|
2016-09-09 01:38:18 -04:00
|
|
|
// returns xl meta map and stat info.
|
|
|
|
xlStat, xlMetaMap, err := xl.readXLMetaStat(bucket, object)
|
2016-05-25 04:33:39 -04:00
|
|
|
if err != nil {
|
|
|
|
// Return error.
|
|
|
|
return ObjectInfo{}, err
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-09-09 01:38:18 -04:00
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
objInfo = ObjectInfo{
|
|
|
|
IsDir: false,
|
|
|
|
Bucket: bucket,
|
|
|
|
Name: object,
|
2016-09-09 01:38:18 -04:00
|
|
|
Size: xlStat.Size,
|
|
|
|
ModTime: xlStat.ModTime,
|
|
|
|
MD5Sum: xlMetaMap["md5Sum"],
|
|
|
|
ContentType: xlMetaMap["content-type"],
|
|
|
|
ContentEncoding: xlMetaMap["content-encoding"],
|
2016-06-01 19:43:31 -04:00
|
|
|
}
|
2016-10-17 11:41:33 -04:00
|
|
|
|
|
|
|
// md5Sum has already been extracted into objInfo.MD5Sum. We
|
|
|
|
// need to remove it from xlMetaMap to avoid it from appearing as
|
|
|
|
// part of response headers. e.g, X-Minio-* or X-Amz-*.
|
|
|
|
|
|
|
|
delete(xlMetaMap, "md5Sum")
|
|
|
|
objInfo.UserDefined = xlMetaMap
|
2016-05-25 04:33:39 -04:00
|
|
|
return objInfo, nil
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2016-12-26 19:29:26 -05:00
|
|
|
func undoRename(disks []StorageAPI, srcBucket, srcEntry, dstBucket, dstEntry string, isDir bool, errs []error) {
|
2016-06-17 14:57:51 -04:00
|
|
|
var wg = &sync.WaitGroup{}
|
|
|
|
// Undo rename object on disks where RenameFile succeeded.
|
2016-06-20 22:11:55 -04:00
|
|
|
|
|
|
|
// If srcEntry/dstEntry are objects then add a trailing slash to copy
|
|
|
|
// over all the parts inside the object directory
|
2016-12-26 19:29:26 -05:00
|
|
|
if isDir {
|
2016-06-20 22:11:55 -04:00
|
|
|
srcEntry = retainSlash(srcEntry)
|
|
|
|
dstEntry = retainSlash(dstEntry)
|
|
|
|
}
|
2016-07-12 01:53:54 -04:00
|
|
|
for index, disk := range disks {
|
2016-06-17 14:57:51 -04:00
|
|
|
if disk == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
// Undo rename object in parallel.
|
|
|
|
wg.Add(1)
|
|
|
|
go func(index int, disk StorageAPI) {
|
|
|
|
defer wg.Done()
|
|
|
|
if errs[index] != nil {
|
|
|
|
return
|
|
|
|
}
|
2016-06-20 22:11:55 -04:00
|
|
|
_ = disk.RenameFile(dstBucket, dstEntry, srcBucket, srcEntry)
|
2016-06-17 14:57:51 -04:00
|
|
|
}(index, disk)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
}
|
|
|
|
|
2016-06-20 22:11:55 -04:00
|
|
|
// rename - common function that renamePart and renameObject use to rename
|
|
|
|
// the respective underlying storage layer representations.
|
2016-12-26 19:29:26 -05:00
|
|
|
func rename(disks []StorageAPI, srcBucket, srcEntry, dstBucket, dstEntry string, isDir bool, quorum int) error {
|
2016-05-20 23:48:47 -04:00
|
|
|
// Initialize sync waitgroup.
|
|
|
|
var wg = &sync.WaitGroup{}
|
|
|
|
|
|
|
|
// Initialize list of errors.
|
2016-07-12 01:53:54 -04:00
|
|
|
var errs = make([]error, len(disks))
|
2016-05-20 23:48:47 -04:00
|
|
|
|
2016-12-26 19:29:26 -05:00
|
|
|
if isDir {
|
2016-06-20 22:11:55 -04:00
|
|
|
dstEntry = retainSlash(dstEntry)
|
|
|
|
srcEntry = retainSlash(srcEntry)
|
|
|
|
}
|
|
|
|
|
2016-05-20 23:48:47 -04:00
|
|
|
// Rename file on all underlying storage disks.
|
2016-07-12 01:53:54 -04:00
|
|
|
for index, disk := range disks {
|
2016-06-02 19:34:15 -04:00
|
|
|
if disk == nil {
|
|
|
|
errs[index] = errDiskNotFound
|
|
|
|
continue
|
|
|
|
}
|
2016-05-20 23:48:47 -04:00
|
|
|
wg.Add(1)
|
|
|
|
go func(index int, disk StorageAPI) {
|
|
|
|
defer wg.Done()
|
2016-06-20 22:11:55 -04:00
|
|
|
err := disk.RenameFile(srcBucket, srcEntry, dstBucket, dstEntry)
|
2016-06-01 19:43:31 -04:00
|
|
|
if err != nil && err != errFileNotFound {
|
2016-08-25 12:39:01 -04:00
|
|
|
errs[index] = traceError(err)
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
}(index, disk)
|
|
|
|
}
|
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// Wait for all renames to finish.
|
2016-05-20 23:48:47 -04:00
|
|
|
wg.Wait()
|
|
|
|
|
|
|
|
// We can safely allow RenameFile errors up to len(xl.storageDisks) - xl.writeQuorum
|
|
|
|
// otherwise return failure. Cleanup successful renames.
|
2017-02-01 14:16:17 -05:00
|
|
|
err := reduceWriteQuorumErrs(errs, objectOpIgnoredErrs, quorum)
|
|
|
|
if errorCause(err) == errXLWriteQuorum {
|
2016-06-17 14:57:51 -04:00
|
|
|
// Undo all the partial rename operations.
|
2016-12-26 19:29:26 -05:00
|
|
|
undoRename(disks, srcBucket, srcEntry, dstBucket, dstEntry, isDir, errs)
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2017-02-01 14:16:17 -05:00
|
|
|
return err
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2016-06-20 22:11:55 -04:00
|
|
|
// renamePart - renames a part of the source object to the destination
|
|
|
|
// across all disks in parallel. Additionally if we have errors and do
|
|
|
|
// not have a readQuorum partially renamed files are renamed back to
|
|
|
|
// its proper location.
|
2016-07-19 22:24:32 -04:00
|
|
|
func renamePart(disks []StorageAPI, srcBucket, srcPart, dstBucket, dstPart string, quorum int) error {
|
2016-12-26 19:29:26 -05:00
|
|
|
isDir := false
|
|
|
|
return rename(disks, srcBucket, srcPart, dstBucket, dstPart, isDir, quorum)
|
2016-06-20 22:11:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// renameObject - renames all source objects to destination object
|
|
|
|
// across all disks in parallel. Additionally if we have errors and do
|
|
|
|
// not have a readQuorum partially renamed files are renamed back to
|
|
|
|
// its proper location.
|
2016-07-19 22:24:32 -04:00
|
|
|
func renameObject(disks []StorageAPI, srcBucket, srcObject, dstBucket, dstObject string, quorum int) error {
|
2016-12-26 19:29:26 -05:00
|
|
|
isDir := true
|
|
|
|
return rename(disks, srcBucket, srcObject, dstBucket, dstObject, isDir, quorum)
|
2016-06-20 22:11:55 -04:00
|
|
|
}
|
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// PutObject - creates an object upon reading from the input stream
|
|
|
|
// until EOF, erasure codes the data across all disk and additionally
|
|
|
|
// writes `xl.json` which carries the necessary metadata for future
|
|
|
|
// object operations.
|
2016-10-02 18:51:49 -04:00
|
|
|
func (xl xlObjects) PutObject(bucket string, object string, size int64, data io.Reader, metadata map[string]string, sha256sum string) (objInfo ObjectInfo, err error) {
|
2017-01-20 19:33:01 -05:00
|
|
|
// This is a special case with size as '0' and object ends with
|
|
|
|
// a slash separator, we treat it like a valid operation and
|
|
|
|
// return success.
|
|
|
|
if isObjectDir(object, size) {
|
|
|
|
return dirObjectInfo(bucket, object, size, metadata), nil
|
|
|
|
}
|
2016-12-02 02:15:17 -05:00
|
|
|
if err = checkPutObjectArgs(bucket, object, xl); err != nil {
|
|
|
|
return ObjectInfo{}, err
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
// No metadata is set, allocate a new one.
|
|
|
|
if metadata == nil {
|
|
|
|
metadata = make(map[string]string)
|
|
|
|
}
|
2016-08-17 16:26:08 -04:00
|
|
|
|
2016-11-22 19:52:37 -05:00
|
|
|
uniqueID := mustGetUUID()
|
2016-06-29 05:28:46 -04:00
|
|
|
tempObj := uniqueID
|
2016-05-25 19:42:31 -04:00
|
|
|
|
2016-05-20 23:48:47 -04:00
|
|
|
// Initialize md5 writer.
|
|
|
|
md5Writer := md5.New()
|
|
|
|
|
2016-10-02 18:51:49 -04:00
|
|
|
writers := []io.Writer{md5Writer}
|
|
|
|
|
|
|
|
var sha256Writer hash.Hash
|
|
|
|
if sha256sum != "" {
|
|
|
|
sha256Writer = sha256.New()
|
|
|
|
writers = append(writers, sha256Writer)
|
|
|
|
}
|
|
|
|
|
2016-07-08 23:34:27 -04:00
|
|
|
// Proceed to set the cache.
|
|
|
|
var newBuffer io.WriteCloser
|
|
|
|
|
|
|
|
// If caching is enabled, proceed to set the cache.
|
|
|
|
if size > 0 && xl.objCacheEnabled {
|
|
|
|
// PutObject invalidates any previously cached object in memory.
|
|
|
|
xl.objCache.Delete(path.Join(bucket, object))
|
|
|
|
|
|
|
|
// Create a new entry in memory of size.
|
|
|
|
newBuffer, err = xl.objCache.Create(path.Join(bucket, object), size)
|
|
|
|
if err == nil {
|
|
|
|
// Create a multi writer to write to both memory and client response.
|
2016-10-02 18:51:49 -04:00
|
|
|
writers = append(writers, newBuffer)
|
2016-07-08 23:34:27 -04:00
|
|
|
}
|
|
|
|
// Ignore error if cache is full, proceed to write the object.
|
|
|
|
if err != nil && err != objcache.ErrCacheFull {
|
|
|
|
// For any other error return here.
|
2016-09-02 15:18:35 -04:00
|
|
|
return ObjectInfo{}, toObjectErr(traceError(err), bucket, object)
|
2016-07-08 23:34:27 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-02 18:51:49 -04:00
|
|
|
mw := io.MultiWriter(writers...)
|
|
|
|
|
2016-07-01 17:33:28 -04:00
|
|
|
// Limit the reader to its provided size if specified.
|
2016-07-05 04:04:50 -04:00
|
|
|
var limitDataReader io.Reader
|
2016-07-01 17:33:28 -04:00
|
|
|
if size > 0 {
|
|
|
|
// This is done so that we can avoid erroneous clients sending
|
|
|
|
// more data than the set content size.
|
2016-07-05 04:04:50 -04:00
|
|
|
limitDataReader = io.LimitReader(data, size)
|
|
|
|
} else {
|
|
|
|
// else we read till EOF.
|
|
|
|
limitDataReader = data
|
|
|
|
}
|
2016-07-01 17:33:28 -04:00
|
|
|
|
2016-07-05 04:04:50 -04:00
|
|
|
// Tee reader combines incoming data stream and md5, data read from input stream is written to md5.
|
2016-07-08 23:34:27 -04:00
|
|
|
teeReader := io.TeeReader(limitDataReader, mw)
|
2016-06-01 19:43:31 -04:00
|
|
|
|
2017-01-30 18:44:42 -05:00
|
|
|
// Initialize parts metadata
|
|
|
|
partsMetadata := make([]xlMetaV1, len(xl.storageDisks))
|
|
|
|
|
2016-07-13 14:56:25 -04:00
|
|
|
xlMeta := newXLMetaV1(object, xl.dataBlocks, xl.parityBlocks)
|
|
|
|
|
2017-01-30 18:44:42 -05:00
|
|
|
// Initialize xl meta.
|
|
|
|
for index := range partsMetadata {
|
|
|
|
partsMetadata[index] = xlMeta
|
|
|
|
}
|
|
|
|
|
|
|
|
// Order disks according to erasure distribution
|
|
|
|
onlineDisks := getOrderedDisks(partsMetadata[0].Erasure.Distribution, xl.storageDisks)
|
2016-06-01 19:43:31 -04:00
|
|
|
|
2017-01-16 20:05:00 -05:00
|
|
|
// Delete temporary object in the event of failure.
|
|
|
|
// If PutObject succeeded there would be no temporary
|
|
|
|
// object to delete.
|
2016-10-20 01:52:03 -04:00
|
|
|
defer xl.deleteObject(minioMetaTmpBucket, tempObj)
|
|
|
|
|
2017-01-30 18:44:42 -05:00
|
|
|
// Total size of the written object
|
|
|
|
sizeWritten := int64(0)
|
|
|
|
|
|
|
|
// Read data and split into parts - similar to multipart mechanism
|
|
|
|
for partIdx := 1; ; partIdx++ {
|
|
|
|
// Compute part name
|
|
|
|
partName := "part." + strconv.Itoa(partIdx)
|
|
|
|
// Compute the path of current part
|
|
|
|
tempErasureObj := path.Join(uniqueID, partName)
|
|
|
|
|
|
|
|
// Calculate the size of the current part, if size is unknown, curPartSize wil be unknown too.
|
|
|
|
// allowEmptyPart will always be true if this is the first part and false otherwise.
|
2017-01-31 18:34:49 -05:00
|
|
|
var curPartSize int64
|
|
|
|
curPartSize, err = getPartSizeFromIdx(size, globalPutPartSize, partIdx)
|
|
|
|
if err != nil {
|
|
|
|
return ObjectInfo{}, toObjectErr(err, bucket, object)
|
|
|
|
}
|
2017-01-30 18:44:42 -05:00
|
|
|
|
|
|
|
// Prepare file for eventual optimization in the disk
|
|
|
|
if curPartSize > 0 {
|
|
|
|
// Calculate the real size of the part in the disk and prepare it for eventual optimization
|
|
|
|
actualSize := xl.sizeOnDisk(curPartSize, xlMeta.Erasure.BlockSize, xlMeta.Erasure.DataBlocks)
|
|
|
|
for _, disk := range onlineDisks {
|
|
|
|
if disk != nil {
|
|
|
|
disk.PrepareFile(minioMetaTmpBucket, tempErasureObj, actualSize)
|
|
|
|
}
|
2016-10-29 15:44:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-30 18:44:42 -05:00
|
|
|
// partReader streams at most maximum part size
|
|
|
|
partReader := io.LimitReader(teeReader, globalPutPartSize)
|
|
|
|
|
|
|
|
// Allow creating empty earsure file only when this is the first part. This flag is useful
|
|
|
|
// when size == -1 because in this case, we are not able to predict how many parts we will have.
|
|
|
|
allowEmptyPart := partIdx == 1
|
|
|
|
|
|
|
|
// Erasure code data and write across all disks.
|
|
|
|
partSizeWritten, checkSums, erasureErr := erasureCreateFile(onlineDisks, minioMetaTmpBucket, tempErasureObj, partReader, allowEmptyPart, partsMetadata[0].Erasure.BlockSize, partsMetadata[0].Erasure.DataBlocks, partsMetadata[0].Erasure.ParityBlocks, bitRotAlgo, xl.writeQuorum)
|
|
|
|
if erasureErr != nil {
|
|
|
|
return ObjectInfo{}, toObjectErr(erasureErr, minioMetaTmpBucket, tempErasureObj)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Should return IncompleteBody{} error when reader has fewer bytes
|
|
|
|
// than specified in request header.
|
|
|
|
if partSizeWritten < int64(curPartSize) {
|
|
|
|
return ObjectInfo{}, traceError(IncompleteBody{})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the total written size
|
|
|
|
sizeWritten += partSizeWritten
|
|
|
|
|
|
|
|
// If erasure stored some data in the loop or created an empty file
|
|
|
|
if partSizeWritten > 0 || allowEmptyPart {
|
|
|
|
for index := range partsMetadata {
|
|
|
|
// Add the part to xl.json.
|
|
|
|
partsMetadata[index].AddObjectPart(partIdx, partName, "", partSizeWritten)
|
|
|
|
// Add part checksum info to xl.json.
|
|
|
|
partsMetadata[index].Erasure.AddCheckSumInfo(checkSumInfo{
|
|
|
|
Name: partName,
|
|
|
|
Hash: checkSums[index],
|
|
|
|
Algorithm: bitRotAlgo,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we didn't write anything or we know that the next part doesn't have any
|
|
|
|
// data to write, we should quit this loop immediately
|
2017-01-31 18:34:49 -05:00
|
|
|
if partSizeWritten == 0 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check part size for the next index.
|
|
|
|
var partSize int64
|
|
|
|
partSize, err = getPartSizeFromIdx(size, globalPutPartSize, partIdx+1)
|
|
|
|
if err != nil {
|
|
|
|
return ObjectInfo{}, toObjectErr(err, bucket, object)
|
|
|
|
}
|
|
|
|
if partSize == 0 {
|
2017-01-30 18:44:42 -05:00
|
|
|
break
|
|
|
|
}
|
2016-07-18 22:06:48 -04:00
|
|
|
}
|
2016-07-01 17:33:28 -04:00
|
|
|
|
|
|
|
// For size == -1, perhaps client is sending in chunked encoding
|
|
|
|
// set the size as size that was actually written.
|
2016-06-02 20:09:47 -04:00
|
|
|
if size == -1 {
|
2016-07-01 17:33:28 -04:00
|
|
|
size = sizeWritten
|
2017-01-30 18:44:42 -05:00
|
|
|
} else {
|
|
|
|
// Check if stored data satisfies what is asked
|
|
|
|
if sizeWritten < size {
|
|
|
|
return ObjectInfo{}, traceError(IncompleteBody{})
|
|
|
|
}
|
2016-06-02 20:09:47 -04:00
|
|
|
}
|
2016-07-01 17:33:28 -04:00
|
|
|
|
2016-05-20 23:48:47 -04:00
|
|
|
// Save additional erasureMetadata.
|
|
|
|
modTime := time.Now().UTC()
|
|
|
|
|
|
|
|
newMD5Hex := hex.EncodeToString(md5Writer.Sum(nil))
|
|
|
|
// Update the md5sum if not set with the newly calculated one.
|
|
|
|
if len(metadata["md5Sum"]) == 0 {
|
|
|
|
metadata["md5Sum"] = newMD5Hex
|
|
|
|
}
|
2016-06-01 19:43:31 -04:00
|
|
|
|
2016-06-17 00:42:02 -04:00
|
|
|
// Guess content-type from the extension if possible.
|
2016-05-20 23:48:47 -04:00
|
|
|
if metadata["content-type"] == "" {
|
2016-08-17 16:26:08 -04:00
|
|
|
if objectExt := path.Ext(object); objectExt != "" {
|
2016-06-17 00:42:02 -04:00
|
|
|
if content, ok := mimedb.DB[strings.ToLower(strings.TrimPrefix(objectExt, "."))]; ok {
|
|
|
|
metadata["content-type"] = content.ContentType
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// md5Hex representation.
|
|
|
|
md5Hex := metadata["md5Sum"]
|
|
|
|
if md5Hex != "" {
|
|
|
|
if newMD5Hex != md5Hex {
|
2016-06-01 19:43:31 -04:00
|
|
|
// Returns md5 mismatch.
|
2016-09-02 15:18:35 -04:00
|
|
|
return ObjectInfo{}, traceError(BadDigest{md5Hex, newMD5Hex})
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-02 18:51:49 -04:00
|
|
|
if sha256sum != "" {
|
|
|
|
newSHA256sum := hex.EncodeToString(sha256Writer.Sum(nil))
|
|
|
|
if newSHA256sum != sha256sum {
|
|
|
|
return ObjectInfo{}, traceError(SHA256Mismatch{})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-20 23:48:47 -04:00
|
|
|
// Check if an object is present as one of the parent dir.
|
2016-06-01 19:43:31 -04:00
|
|
|
// -- FIXME. (needs a new kind of lock).
|
2016-05-20 23:48:47 -04:00
|
|
|
if xl.parentDirIsObject(bucket, path.Dir(object)) {
|
2016-09-02 15:18:35 -04:00
|
|
|
return ObjectInfo{}, toObjectErr(traceError(errFileAccessDenied), bucket, object)
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2016-05-29 03:42:09 -04:00
|
|
|
// Rename if an object already exists to temporary location.
|
2016-11-22 19:52:37 -05:00
|
|
|
newUniqueID := mustGetUUID()
|
2016-06-20 09:18:47 -04:00
|
|
|
if xl.isObject(bucket, object) {
|
2016-10-20 01:52:03 -04:00
|
|
|
// Delete the temporary copy of the object that existed before this PutObject request.
|
|
|
|
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.
|
2016-07-19 22:24:32 -04:00
|
|
|
err = renameObject(xl.storageDisks, bucket, object, minioMetaTmpBucket, newUniqueID, xl.writeQuorum)
|
2016-06-20 09:18:47 -04:00
|
|
|
if err != nil {
|
2016-09-02 15:18:35 -04:00
|
|
|
return ObjectInfo{}, toObjectErr(err, bucket, object)
|
2016-06-20 09:18:47 -04:00
|
|
|
}
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2016-05-26 22:55:48 -04:00
|
|
|
// Fill all the necessary metadata.
|
2016-06-01 19:43:31 -04:00
|
|
|
// Update `xl.json` content on each disks.
|
2016-05-31 23:23:31 -04:00
|
|
|
for index := range partsMetadata {
|
2017-01-30 18:44:42 -05:00
|
|
|
partsMetadata[index].Meta = metadata
|
|
|
|
partsMetadata[index].Stat.Size = size
|
|
|
|
partsMetadata[index].Stat.ModTime = modTime
|
2016-05-31 23:23:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Write unique `xl.json` for each disk.
|
2016-07-19 22:24:32 -04:00
|
|
|
if err = writeUniqueXLMetadata(onlineDisks, minioMetaTmpBucket, tempObj, partsMetadata, xl.writeQuorum); err != nil {
|
2016-09-02 15:18:35 -04:00
|
|
|
return ObjectInfo{}, toObjectErr(err, bucket, object)
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-05-29 03:42:09 -04:00
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// Rename the successfully written temporary object to final location.
|
2016-07-19 22:24:32 -04:00
|
|
|
err = renameObject(onlineDisks, minioMetaTmpBucket, tempObj, bucket, object, xl.writeQuorum)
|
2016-05-29 03:42:09 -04:00
|
|
|
if err != nil {
|
2016-09-02 15:18:35 -04:00
|
|
|
return ObjectInfo{}, toObjectErr(err, bucket, object)
|
2016-05-28 18:13:15 -04:00
|
|
|
}
|
2016-05-29 03:42:09 -04:00
|
|
|
|
2016-07-08 23:34:27 -04:00
|
|
|
// Once we have successfully renamed the object, Close the buffer which would
|
|
|
|
// save the object on cache.
|
|
|
|
if size > 0 && xl.objCacheEnabled && newBuffer != nil {
|
|
|
|
newBuffer.Close()
|
|
|
|
}
|
|
|
|
|
2017-01-30 18:44:42 -05:00
|
|
|
// Object info is the same in all disks, so we can pick the first meta
|
|
|
|
// of the first disk
|
|
|
|
xlMeta = partsMetadata[0]
|
|
|
|
|
2016-09-02 15:18:35 -04:00
|
|
|
objInfo = ObjectInfo{
|
|
|
|
IsDir: false,
|
|
|
|
Bucket: bucket,
|
|
|
|
Name: object,
|
|
|
|
Size: xlMeta.Stat.Size,
|
|
|
|
ModTime: xlMeta.Stat.ModTime,
|
|
|
|
MD5Sum: xlMeta.Meta["md5Sum"],
|
|
|
|
ContentType: xlMeta.Meta["content-type"],
|
|
|
|
ContentEncoding: xlMeta.Meta["content-encoding"],
|
|
|
|
UserDefined: xlMeta.Meta,
|
|
|
|
}
|
2017-01-16 22:23:43 -05:00
|
|
|
|
|
|
|
// Success, return object info.
|
2016-09-02 15:18:35 -04:00
|
|
|
return objInfo, nil
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// deleteObject - wrapper for delete object, deletes an object from
|
|
|
|
// all the disks in parallel, including `xl.json` associated with the
|
|
|
|
// object.
|
2016-05-20 23:48:47 -04:00
|
|
|
func (xl xlObjects) deleteObject(bucket, object string) error {
|
|
|
|
// Initialize sync waitgroup.
|
|
|
|
var wg = &sync.WaitGroup{}
|
|
|
|
|
|
|
|
// Initialize list of errors.
|
|
|
|
var dErrs = make([]error, len(xl.storageDisks))
|
|
|
|
|
|
|
|
for index, disk := range xl.storageDisks {
|
2016-06-02 19:34:15 -04:00
|
|
|
if disk == nil {
|
2016-08-25 12:39:01 -04:00
|
|
|
dErrs[index] = traceError(errDiskNotFound)
|
2016-06-02 19:34:15 -04:00
|
|
|
continue
|
|
|
|
}
|
2016-05-20 23:48:47 -04:00
|
|
|
wg.Add(1)
|
|
|
|
go func(index int, disk StorageAPI) {
|
|
|
|
defer wg.Done()
|
2016-05-25 17:32:49 -04:00
|
|
|
err := cleanupDir(disk, bucket, object)
|
2016-08-25 12:39:01 -04:00
|
|
|
if err != nil && errorCause(err) != errVolumeNotFound {
|
2016-05-25 17:32:49 -04:00
|
|
|
dErrs[index] = err
|
|
|
|
}
|
2016-05-20 23:48:47 -04:00
|
|
|
}(index, disk)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait for all routines to finish.
|
|
|
|
wg.Wait()
|
|
|
|
|
2017-02-01 14:16:17 -05:00
|
|
|
return reduceWriteQuorumErrs(dErrs, objectOpIgnoredErrs, xl.writeQuorum)
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
|
|
|
|
2016-06-01 19:43:31 -04:00
|
|
|
// DeleteObject - deletes an object, this call doesn't necessary reply
|
|
|
|
// any error as it is not necessary for the handler to reply back a
|
|
|
|
// response to the client request.
|
2016-06-07 14:35:03 -04:00
|
|
|
func (xl xlObjects) DeleteObject(bucket, object string) (err error) {
|
2016-12-02 02:15:17 -05:00
|
|
|
if err = checkDelObjArgs(bucket, object); err != nil {
|
|
|
|
return err
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|
2016-08-31 14:39:08 -04:00
|
|
|
|
2016-06-17 14:57:51 -04:00
|
|
|
// Validate object exists.
|
2016-06-17 01:18:43 -04:00
|
|
|
if !xl.isObject(bucket, object) {
|
2016-08-25 12:39:01 -04:00
|
|
|
return traceError(ObjectNotFound{bucket, object})
|
2016-06-17 14:57:51 -04:00
|
|
|
} // else proceed to delete the object.
|
2016-06-17 01:18:43 -04:00
|
|
|
|
2016-06-17 14:57:51 -04:00
|
|
|
// Delete the object on all disks.
|
|
|
|
err = xl.deleteObject(bucket, object)
|
|
|
|
if err != nil {
|
|
|
|
return toObjectErr(err, bucket, object)
|
2016-06-07 14:35:03 -04:00
|
|
|
}
|
|
|
|
|
2016-12-08 23:35:07 -05:00
|
|
|
if xl.objCacheEnabled {
|
|
|
|
// Delete from the cache.
|
|
|
|
xl.objCache.Delete(pathJoin(bucket, object))
|
|
|
|
}
|
2016-07-06 13:25:42 -04:00
|
|
|
|
2016-06-17 14:57:51 -04:00
|
|
|
// Success.
|
|
|
|
return nil
|
2016-05-20 23:48:47 -04:00
|
|
|
}
|