mirror of https://github.com/minio/minio.git
XL: Refactor usage of reduceErrs and consistent behavior. (#2240)
This refactor is also needed in lieu of our quorum requirement change for the newly understood logic behind klauspost/reedsolom implementation.
This commit is contained in:
parent
f67c930731
commit
cef26fd6ea
|
@ -129,7 +129,7 @@ func testPutObjectPartDiskNotFound(obj ObjectLayer, instanceType string, disks [
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove some random disk.
|
// Remove some random disk.
|
||||||
for _, disk := range disks[:7] {
|
for _, disk := range disks[:6] {
|
||||||
removeAll(disk)
|
removeAll(disk)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +165,10 @@ func testPutObjectPartDiskNotFound(obj ObjectLayer, instanceType string, disks [
|
||||||
}
|
}
|
||||||
|
|
||||||
// This causes quorum failure verify.
|
// This causes quorum failure verify.
|
||||||
removeAll(disks[len(disks)-1])
|
disks = disks[len(disks)-3:]
|
||||||
|
for _, disk := range disks {
|
||||||
|
removeAll(disk)
|
||||||
|
}
|
||||||
|
|
||||||
// Object part upload should fail with quorum not available.
|
// Object part upload should fail with quorum not available.
|
||||||
testCase := createPartCases[len(createPartCases)-1]
|
testCase := createPartCases[len(createPartCases)-1]
|
||||||
|
|
|
@ -25,7 +25,7 @@ import (
|
||||||
// randomized quorum disk slice.
|
// randomized quorum disk slice.
|
||||||
func (xl xlObjects) getLoadBalancedQuorumDisks() (disks []StorageAPI) {
|
func (xl xlObjects) getLoadBalancedQuorumDisks() (disks []StorageAPI) {
|
||||||
// It is okay to have readQuorum disks.
|
// It is okay to have readQuorum disks.
|
||||||
return xl.getLoadBalancedDisks()[:xl.readQuorum-1]
|
return xl.getLoadBalancedDisks()[0 : xl.readQuorum-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
// getLoadBalancedDisks - fetches load balanced (sufficiently
|
// getLoadBalancedDisks - fetches load balanced (sufficiently
|
||||||
|
|
|
@ -314,7 +314,7 @@ func deleteAllXLMetadata(disks []StorageAPI, bucket, prefix string, errs []error
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeUniqueXLMetadata - writes unique `xl.json` content for each disk in order.
|
// writeUniqueXLMetadata - writes unique `xl.json` content for each disk in order.
|
||||||
func writeUniqueXLMetadata(disks []StorageAPI, bucket, prefix string, xlMetas []xlMetaV1, writeQuorum, readQuorum int) error {
|
func writeUniqueXLMetadata(disks []StorageAPI, bucket, prefix string, xlMetas []xlMetaV1, quorum int) error {
|
||||||
var wg = &sync.WaitGroup{}
|
var wg = &sync.WaitGroup{}
|
||||||
var mErrs = make([]error, len(disks))
|
var mErrs = make([]error, len(disks))
|
||||||
|
|
||||||
|
@ -344,38 +344,17 @@ func writeUniqueXLMetadata(disks []StorageAPI, bucket, prefix string, xlMetas []
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
// Do we have write quorum?.
|
// Do we have write quorum?.
|
||||||
if !isDiskQuorum(mErrs, writeQuorum) {
|
if !isDiskQuorum(mErrs, quorum) {
|
||||||
// Validate if we have read quorum.
|
|
||||||
if isDiskQuorum(mErrs, readQuorum) {
|
|
||||||
// Return success.
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
// Delete all `xl.json` successfully renamed.
|
// Delete all `xl.json` successfully renamed.
|
||||||
deleteAllXLMetadata(disks, bucket, prefix, mErrs)
|
deleteAllXLMetadata(disks, bucket, prefix, mErrs)
|
||||||
return errXLWriteQuorum
|
return errXLWriteQuorum
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reduce errors and verify quourm and return.
|
return reduceErrs(mErrs, []error{
|
||||||
if errCount, reducedErr := reduceErrs(mErrs); reducedErr != nil {
|
errDiskNotFound,
|
||||||
if errCount < writeQuorum {
|
errFaultyDisk,
|
||||||
// Delete all `xl.json` successfully renamed.
|
errDiskAccessDenied,
|
||||||
deleteAllXLMetadata(disks, bucket, prefix, mErrs)
|
})
|
||||||
return errXLWriteQuorum
|
|
||||||
}
|
|
||||||
if isErrIgnored(reducedErr, []error{
|
|
||||||
errDiskNotFound,
|
|
||||||
errDiskAccessDenied,
|
|
||||||
errFaultyDisk,
|
|
||||||
errVolumeNotFound,
|
|
||||||
}) {
|
|
||||||
// Success.
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return reducedErr
|
|
||||||
}
|
|
||||||
|
|
||||||
// Success.
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeSameXLMetadata - write `xl.json` on all disks in order.
|
// writeSameXLMetadata - write `xl.json` on all disks in order.
|
||||||
|
@ -410,36 +389,14 @@ func writeSameXLMetadata(disks []StorageAPI, bucket, prefix string, xlMeta xlMet
|
||||||
|
|
||||||
// Do we have write Quorum?.
|
// Do we have write Quorum?.
|
||||||
if !isDiskQuorum(mErrs, writeQuorum) {
|
if !isDiskQuorum(mErrs, writeQuorum) {
|
||||||
// Do we have readQuorum?.
|
|
||||||
if isDiskQuorum(mErrs, readQuorum) {
|
|
||||||
// Return success.
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
// Delete all `xl.json` successfully renamed.
|
// Delete all `xl.json` successfully renamed.
|
||||||
deleteAllXLMetadata(disks, bucket, prefix, mErrs)
|
deleteAllXLMetadata(disks, bucket, prefix, mErrs)
|
||||||
return errXLWriteQuorum
|
return errXLWriteQuorum
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reduce errors and verify quourm and return.
|
return reduceErrs(mErrs, []error{
|
||||||
if errCount, reducedErr := reduceErrs(mErrs); reducedErr != nil {
|
errDiskNotFound,
|
||||||
if errCount < writeQuorum {
|
errFaultyDisk,
|
||||||
// Delete all `xl.json` successfully renamed.
|
errDiskAccessDenied,
|
||||||
deleteAllXLMetadata(disks, bucket, prefix, mErrs)
|
})
|
||||||
return errXLWriteQuorum
|
|
||||||
}
|
|
||||||
// Ignore specific errors if we are under write quorum.
|
|
||||||
if isErrIgnored(reducedErr, []error{
|
|
||||||
errDiskNotFound,
|
|
||||||
errDiskAccessDenied,
|
|
||||||
errFaultyDisk,
|
|
||||||
errVolumeNotFound,
|
|
||||||
}) {
|
|
||||||
// Success.
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return reducedErr
|
|
||||||
}
|
|
||||||
|
|
||||||
// Success.
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -270,7 +270,7 @@ func (xl xlObjects) statPart(bucket, object, uploadID, partName string) (fileInf
|
||||||
}
|
}
|
||||||
|
|
||||||
// commitXLMetadata - commit `xl.json` from source prefix to destination prefix in the given slice of disks.
|
// commitXLMetadata - commit `xl.json` from source prefix to destination prefix in the given slice of disks.
|
||||||
func commitXLMetadata(disks []StorageAPI, srcPrefix, dstPrefix string, writeQuorum, readQuorum int) error {
|
func commitXLMetadata(disks []StorageAPI, srcPrefix, dstPrefix string, quorum int) error {
|
||||||
var wg = &sync.WaitGroup{}
|
var wg = &sync.WaitGroup{}
|
||||||
var mErrs = make([]error, len(disks))
|
var mErrs = make([]error, len(disks))
|
||||||
|
|
||||||
|
@ -303,35 +303,16 @@ func commitXLMetadata(disks []StorageAPI, srcPrefix, dstPrefix string, writeQuor
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
// Do we have write Quorum?.
|
// Do we have write Quorum?.
|
||||||
if !isDiskQuorum(mErrs, writeQuorum) {
|
if !isDiskQuorum(mErrs, quorum) {
|
||||||
// Do we have readQuorum?.
|
|
||||||
if isDiskQuorum(mErrs, readQuorum) {
|
|
||||||
// Return success.
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
// Delete all `xl.json` successfully renamed.
|
// Delete all `xl.json` successfully renamed.
|
||||||
deleteAllXLMetadata(disks, minioMetaBucket, dstPrefix, mErrs)
|
deleteAllXLMetadata(disks, minioMetaBucket, dstPrefix, mErrs)
|
||||||
return errXLWriteQuorum
|
return errXLWriteQuorum
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reduce errors and verify quourm and return.
|
return reduceErrs(mErrs, []error{
|
||||||
if errCount, reducedErr := reduceErrs(mErrs); reducedErr != nil {
|
errDiskNotFound,
|
||||||
if errCount < writeQuorum {
|
errDiskAccessDenied,
|
||||||
// Delete all `xl.json` successfully renamed.
|
errFaultyDisk,
|
||||||
deleteAllXLMetadata(disks, minioMetaBucket, dstPrefix, mErrs)
|
errVolumeNotFound,
|
||||||
return errXLWriteQuorum
|
})
|
||||||
}
|
|
||||||
if isErrIgnored(reducedErr, []error{
|
|
||||||
errDiskNotFound,
|
|
||||||
errDiskAccessDenied,
|
|
||||||
errFaultyDisk,
|
|
||||||
errVolumeNotFound,
|
|
||||||
}) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return reducedErr
|
|
||||||
}
|
|
||||||
|
|
||||||
// Success.
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -285,7 +285,7 @@ func (xl xlObjects) newMultipartUpload(bucket string, object string, meta map[st
|
||||||
if err = writeSameXLMetadata(xl.storageDisks, minioMetaBucket, tempUploadIDPath, xlMeta, xl.writeQuorum, xl.readQuorum); err != nil {
|
if err = writeSameXLMetadata(xl.storageDisks, minioMetaBucket, tempUploadIDPath, xlMeta, xl.writeQuorum, xl.readQuorum); err != nil {
|
||||||
return "", toObjectErr(err, minioMetaBucket, tempUploadIDPath)
|
return "", toObjectErr(err, minioMetaBucket, tempUploadIDPath)
|
||||||
}
|
}
|
||||||
rErr := renameObject(xl.storageDisks, minioMetaBucket, tempUploadIDPath, minioMetaBucket, uploadIDPath, xl.writeQuorum, xl.readQuorum)
|
rErr := renameObject(xl.storageDisks, minioMetaBucket, tempUploadIDPath, minioMetaBucket, uploadIDPath, xl.writeQuorum)
|
||||||
if rErr == nil {
|
if rErr == nil {
|
||||||
// Return success.
|
// Return success.
|
||||||
return uploadID, nil
|
return uploadID, nil
|
||||||
|
@ -431,7 +431,7 @@ func (xl xlObjects) PutObjectPart(bucket, object, uploadID string, partID int, s
|
||||||
|
|
||||||
// Rename temporary part file to its final location.
|
// Rename temporary part file to its final location.
|
||||||
partPath := path.Join(uploadIDPath, partSuffix)
|
partPath := path.Join(uploadIDPath, partSuffix)
|
||||||
err = renamePart(onlineDisks, minioMetaBucket, tmpPartPath, minioMetaBucket, partPath, xl.writeQuorum, xl.readQuorum)
|
err = renamePart(onlineDisks, minioMetaBucket, tmpPartPath, minioMetaBucket, partPath, xl.writeQuorum)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", toObjectErr(err, minioMetaBucket, partPath)
|
return "", toObjectErr(err, minioMetaBucket, partPath)
|
||||||
}
|
}
|
||||||
|
@ -466,12 +466,11 @@ func (xl xlObjects) PutObjectPart(bucket, object, uploadID string, partID int, s
|
||||||
newUUID := getUUID()
|
newUUID := getUUID()
|
||||||
tempXLMetaPath := path.Join(tmpMetaPrefix, newUUID)
|
tempXLMetaPath := path.Join(tmpMetaPrefix, newUUID)
|
||||||
|
|
||||||
// Writes a unique `xl.json` each disk carrying new checksum
|
// Writes a unique `xl.json` each disk carrying new checksum related information.
|
||||||
// related information.
|
if err = writeUniqueXLMetadata(onlineDisks, minioMetaBucket, tempXLMetaPath, partsMetadata, xl.writeQuorum); err != nil {
|
||||||
if err = writeUniqueXLMetadata(onlineDisks, minioMetaBucket, tempXLMetaPath, partsMetadata, xl.writeQuorum, xl.readQuorum); err != nil {
|
|
||||||
return "", toObjectErr(err, minioMetaBucket, tempXLMetaPath)
|
return "", toObjectErr(err, minioMetaBucket, tempXLMetaPath)
|
||||||
}
|
}
|
||||||
rErr := commitXLMetadata(onlineDisks, tempXLMetaPath, uploadIDPath, xl.writeQuorum, xl.readQuorum)
|
rErr := commitXLMetadata(onlineDisks, tempXLMetaPath, uploadIDPath, xl.writeQuorum)
|
||||||
if rErr != nil {
|
if rErr != nil {
|
||||||
return "", toObjectErr(rErr, minioMetaBucket, uploadIDPath)
|
return "", toObjectErr(rErr, minioMetaBucket, uploadIDPath)
|
||||||
}
|
}
|
||||||
|
@ -696,10 +695,10 @@ func (xl xlObjects) CompleteMultipartUpload(bucket string, object string, upload
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write unique `xl.json` for each disk.
|
// Write unique `xl.json` for each disk.
|
||||||
if err = writeUniqueXLMetadata(xl.storageDisks, minioMetaBucket, tempUploadIDPath, partsMetadata, xl.writeQuorum, xl.readQuorum); err != nil {
|
if err = writeUniqueXLMetadata(xl.storageDisks, minioMetaBucket, tempUploadIDPath, partsMetadata, xl.writeQuorum); err != nil {
|
||||||
return "", toObjectErr(err, minioMetaBucket, tempUploadIDPath)
|
return "", toObjectErr(err, minioMetaBucket, tempUploadIDPath)
|
||||||
}
|
}
|
||||||
rErr := commitXLMetadata(xl.storageDisks, tempUploadIDPath, uploadIDPath, xl.writeQuorum, xl.readQuorum)
|
rErr := commitXLMetadata(xl.storageDisks, tempUploadIDPath, uploadIDPath, xl.writeQuorum)
|
||||||
if rErr != nil {
|
if rErr != nil {
|
||||||
return "", toObjectErr(rErr, minioMetaBucket, uploadIDPath)
|
return "", toObjectErr(rErr, minioMetaBucket, uploadIDPath)
|
||||||
}
|
}
|
||||||
|
@ -722,7 +721,7 @@ func (xl xlObjects) CompleteMultipartUpload(bucket string, object string, upload
|
||||||
// Rename if an object already exists to temporary location.
|
// Rename if an object already exists to temporary location.
|
||||||
uniqueID := getUUID()
|
uniqueID := getUUID()
|
||||||
if xl.isObject(bucket, object) {
|
if xl.isObject(bucket, object) {
|
||||||
err = renameObject(xl.storageDisks, bucket, object, minioMetaBucket, path.Join(tmpMetaPrefix, uniqueID), xl.writeQuorum, xl.readQuorum)
|
err = renameObject(xl.storageDisks, bucket, object, minioMetaBucket, path.Join(tmpMetaPrefix, uniqueID), xl.writeQuorum)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", toObjectErr(err, bucket, object)
|
return "", toObjectErr(err, bucket, object)
|
||||||
}
|
}
|
||||||
|
@ -742,7 +741,7 @@ func (xl xlObjects) CompleteMultipartUpload(bucket string, object string, upload
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rename the multipart object to final location.
|
// Rename the multipart object to final location.
|
||||||
if err = renameObject(xl.storageDisks, minioMetaBucket, uploadIDPath, bucket, object, xl.writeQuorum, xl.readQuorum); err != nil {
|
if err = renameObject(xl.storageDisks, minioMetaBucket, uploadIDPath, bucket, object, xl.writeQuorum); err != nil {
|
||||||
return "", toObjectErr(err, bucket, object)
|
return "", toObjectErr(err, bucket, object)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,12 +67,12 @@ func (xl xlObjects) GetObject(bucket, object string, startOffset int64, length i
|
||||||
return toObjectErr(errXLReadQuorum, bucket, object)
|
return toObjectErr(errXLReadQuorum, bucket, object)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If all the disks returned error, we return error.
|
if reducedErr := reduceErrs(errs, []error{
|
||||||
if errCount, err := reduceErrs(errs); err != nil {
|
errDiskNotFound,
|
||||||
if errCount < xl.readQuorum {
|
errFaultyDisk,
|
||||||
return toObjectErr(errXLReadQuorum, bucket, object)
|
errDiskAccessDenied,
|
||||||
}
|
}); reducedErr != nil {
|
||||||
return toObjectErr(err, bucket, object)
|
return toObjectErr(reducedErr, bucket, object)
|
||||||
}
|
}
|
||||||
|
|
||||||
// List all online disks.
|
// List all online disks.
|
||||||
|
@ -237,7 +237,7 @@ func (xl xlObjects) getObjectInfo(bucket, object string) (objInfo ObjectInfo, er
|
||||||
return objInfo, nil
|
return objInfo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func undoRename(disks []StorageAPI, srcBucket, srcEntry, dstBucket, dstEntry string, isPart bool, errs []error, writeQuorum, readQuorum int) {
|
func undoRename(disks []StorageAPI, srcBucket, srcEntry, dstBucket, dstEntry string, isPart bool, errs []error) {
|
||||||
var wg = &sync.WaitGroup{}
|
var wg = &sync.WaitGroup{}
|
||||||
// Undo rename object on disks where RenameFile succeeded.
|
// Undo rename object on disks where RenameFile succeeded.
|
||||||
|
|
||||||
|
@ -264,21 +264,9 @@ func undoRename(disks []StorageAPI, srcBucket, srcEntry, dstBucket, dstEntry str
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
// undoRenameObject - renames back the partially successful rename operations.
|
|
||||||
func undoRenameObject(disks []StorageAPI, srcBucket, srcObject, dstBucket, dstObject string, errs []error, writeQuorum, readQuorum int) {
|
|
||||||
isPart := false
|
|
||||||
undoRename(disks, srcBucket, srcObject, dstBucket, dstObject, isPart, errs, writeQuorum, readQuorum)
|
|
||||||
}
|
|
||||||
|
|
||||||
// undoRenamePart - renames back the partially successful rename operation.
|
|
||||||
func undoRenamePart(disks []StorageAPI, srcBucket, srcPart, dstBucket, dstPart string, errs []error, writeQuorum, readQuorum int) {
|
|
||||||
isPart := true
|
|
||||||
undoRename(disks, srcBucket, srcPart, dstBucket, dstPart, isPart, errs, writeQuorum, readQuorum)
|
|
||||||
}
|
|
||||||
|
|
||||||
// rename - common function that renamePart and renameObject use to rename
|
// rename - common function that renamePart and renameObject use to rename
|
||||||
// the respective underlying storage layer representations.
|
// the respective underlying storage layer representations.
|
||||||
func rename(disks []StorageAPI, srcBucket, srcEntry, dstBucket, dstEntry string, isPart bool, writeQuorum, readQuorum int) error {
|
func rename(disks []StorageAPI, srcBucket, srcEntry, dstBucket, dstEntry string, isPart bool, quorum int) error {
|
||||||
// Initialize sync waitgroup.
|
// Initialize sync waitgroup.
|
||||||
var wg = &sync.WaitGroup{}
|
var wg = &sync.WaitGroup{}
|
||||||
|
|
||||||
|
@ -311,52 +299,35 @@ func rename(disks []StorageAPI, srcBucket, srcEntry, dstBucket, dstEntry string,
|
||||||
|
|
||||||
// We can safely allow RenameFile errors up to len(xl.storageDisks) - xl.writeQuorum
|
// We can safely allow RenameFile errors up to len(xl.storageDisks) - xl.writeQuorum
|
||||||
// otherwise return failure. Cleanup successful renames.
|
// otherwise return failure. Cleanup successful renames.
|
||||||
if !isDiskQuorum(errs, writeQuorum) {
|
if !isDiskQuorum(errs, quorum) {
|
||||||
// Check we have successful read quorum.
|
|
||||||
if isDiskQuorum(errs, readQuorum) {
|
|
||||||
return nil // Return success.
|
|
||||||
} // else - failed to acquire read quorum.
|
|
||||||
// Undo all the partial rename operations.
|
// Undo all the partial rename operations.
|
||||||
undoRename(disks, srcBucket, srcEntry, dstBucket, dstEntry, isPart, errs, writeQuorum, readQuorum)
|
undoRename(disks, srcBucket, srcEntry, dstBucket, dstEntry, isPart, errs)
|
||||||
return errXLWriteQuorum
|
return errXLWriteQuorum
|
||||||
}
|
}
|
||||||
// Return on first error, also undo any partially successful rename operations.
|
// Return on first error, also undo any partially successful rename operations.
|
||||||
if errCount, reducedErr := reduceErrs(errs); reducedErr != nil {
|
return reduceErrs(errs, []error{
|
||||||
if errCount < writeQuorum {
|
errDiskNotFound,
|
||||||
// Undo all the partial rename operations.
|
errDiskAccessDenied,
|
||||||
undoRename(disks, srcBucket, srcEntry, dstBucket, dstEntry, isPart, errs, writeQuorum, readQuorum)
|
errFaultyDisk,
|
||||||
return errXLWriteQuorum
|
})
|
||||||
}
|
|
||||||
if isErrIgnored(reducedErr, []error{
|
|
||||||
errDiskNotFound,
|
|
||||||
errDiskAccessDenied,
|
|
||||||
errFaultyDisk,
|
|
||||||
errVolumeNotFound,
|
|
||||||
}) {
|
|
||||||
// Return success.
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return reducedErr
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// renamePart - renames a part of the source object to the destination
|
// renamePart - renames a part of the source object to the destination
|
||||||
// across all disks in parallel. Additionally if we have errors and do
|
// across all disks in parallel. Additionally if we have errors and do
|
||||||
// not have a readQuorum partially renamed files are renamed back to
|
// not have a readQuorum partially renamed files are renamed back to
|
||||||
// its proper location.
|
// its proper location.
|
||||||
func renamePart(disks []StorageAPI, srcBucket, srcPart, dstBucket, dstPart string, writeQuorum, readQuorum int) error {
|
func renamePart(disks []StorageAPI, srcBucket, srcPart, dstBucket, dstPart string, quorum int) error {
|
||||||
isPart := true
|
isPart := true
|
||||||
return rename(disks, srcBucket, srcPart, dstBucket, dstPart, isPart, writeQuorum, readQuorum)
|
return rename(disks, srcBucket, srcPart, dstBucket, dstPart, isPart, quorum)
|
||||||
}
|
}
|
||||||
|
|
||||||
// renameObject - renames all source objects to destination object
|
// renameObject - renames all source objects to destination object
|
||||||
// across all disks in parallel. Additionally if we have errors and do
|
// across all disks in parallel. Additionally if we have errors and do
|
||||||
// not have a readQuorum partially renamed files are renamed back to
|
// not have a readQuorum partially renamed files are renamed back to
|
||||||
// its proper location.
|
// its proper location.
|
||||||
func renameObject(disks []StorageAPI, srcBucket, srcObject, dstBucket, dstObject string, writeQuorum, readQuorum int) error {
|
func renameObject(disks []StorageAPI, srcBucket, srcObject, dstBucket, dstObject string, quorum int) error {
|
||||||
isPart := false
|
isPart := false
|
||||||
return rename(disks, srcBucket, srcObject, dstBucket, dstObject, isPart, writeQuorum, readQuorum)
|
return rename(disks, srcBucket, srcObject, dstBucket, dstObject, isPart, quorum)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PutObject - creates an object upon reading from the input stream
|
// PutObject - creates an object upon reading from the input stream
|
||||||
|
@ -508,7 +479,7 @@ func (xl xlObjects) PutObject(bucket string, object string, size int64, data io.
|
||||||
// Rename if an object already exists to temporary location.
|
// Rename if an object already exists to temporary location.
|
||||||
newUniqueID := getUUID()
|
newUniqueID := getUUID()
|
||||||
if xl.isObject(bucket, object) {
|
if xl.isObject(bucket, object) {
|
||||||
err = renameObject(xl.storageDisks, bucket, object, minioMetaTmpBucket, newUniqueID, xl.writeQuorum, xl.readQuorum)
|
err = renameObject(xl.storageDisks, bucket, object, minioMetaTmpBucket, newUniqueID, xl.writeQuorum)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", toObjectErr(err, bucket, object)
|
return "", toObjectErr(err, bucket, object)
|
||||||
}
|
}
|
||||||
|
@ -530,12 +501,12 @@ func (xl xlObjects) PutObject(bucket string, object string, size int64, data io.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write unique `xl.json` for each disk.
|
// Write unique `xl.json` for each disk.
|
||||||
if err = writeUniqueXLMetadata(onlineDisks, minioMetaTmpBucket, tempObj, partsMetadata, xl.writeQuorum, xl.readQuorum); err != nil {
|
if err = writeUniqueXLMetadata(onlineDisks, minioMetaTmpBucket, tempObj, partsMetadata, xl.writeQuorum); err != nil {
|
||||||
return "", toObjectErr(err, bucket, object)
|
return "", toObjectErr(err, bucket, object)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rename the successfully written temporary object to final location.
|
// Rename the successfully written temporary object to final location.
|
||||||
err = renameObject(onlineDisks, minioMetaTmpBucket, tempObj, bucket, object, xl.writeQuorum, xl.readQuorum)
|
err = renameObject(onlineDisks, minioMetaTmpBucket, tempObj, bucket, object, xl.writeQuorum)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", toObjectErr(err, bucket, object)
|
return "", toObjectErr(err, bucket, object)
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,9 +30,12 @@ import (
|
||||||
// value is greater than or equal to simple majority, since none of the equally
|
// value is greater than or equal to simple majority, since none of the equally
|
||||||
// maximal values would occur quorum or more number of times.
|
// maximal values would occur quorum or more number of times.
|
||||||
|
|
||||||
func reduceErrs(errs []error) (int, error) {
|
func reduceErrs(errs []error, ignoredErrs []error) error {
|
||||||
errorCounts := make(map[error]int)
|
errorCounts := make(map[error]int)
|
||||||
for _, err := range errs {
|
for _, err := range errs {
|
||||||
|
if isErrIgnored(err, ignoredErrs) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
errorCounts[err]++
|
errorCounts[err]++
|
||||||
}
|
}
|
||||||
max := 0
|
max := 0
|
||||||
|
@ -43,7 +46,7 @@ func reduceErrs(errs []error) (int, error) {
|
||||||
errMax = err
|
errMax = err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return max, errMax
|
return errMax
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validates if we have quorum based on the errors related to disk only.
|
// Validates if we have quorum based on the errors related to disk only.
|
||||||
|
|
|
@ -20,23 +20,40 @@ import "testing"
|
||||||
|
|
||||||
// Test for reduceErrs.
|
// Test for reduceErrs.
|
||||||
func TestReduceErrs(t *testing.T) {
|
func TestReduceErrs(t *testing.T) {
|
||||||
|
// List all of all test cases to validate various cases of reduce errors.
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
errs []error
|
errs []error
|
||||||
err error
|
ignoredErrs []error
|
||||||
count int
|
err error
|
||||||
}{
|
}{
|
||||||
{[]error{errDiskNotFound, errDiskNotFound, errDiskFull}, errDiskNotFound, 2},
|
// Validate if have reduced properly.
|
||||||
{[]error{errDiskFull, errDiskNotFound, nil, nil}, nil, 2},
|
{[]error{
|
||||||
{[]error{}, nil, 0},
|
errDiskNotFound,
|
||||||
|
errDiskNotFound,
|
||||||
|
errDiskFull,
|
||||||
|
}, []error{}, errDiskNotFound},
|
||||||
|
// Validate if have no consensus.
|
||||||
|
{[]error{
|
||||||
|
errDiskFull,
|
||||||
|
errDiskNotFound,
|
||||||
|
nil, nil,
|
||||||
|
}, []error{}, nil},
|
||||||
|
// Validate if have consensus and errors ignored.
|
||||||
|
{[]error{
|
||||||
|
errVolumeNotFound,
|
||||||
|
errVolumeNotFound,
|
||||||
|
errVolumeNotFound,
|
||||||
|
errDiskNotFound,
|
||||||
|
errDiskNotFound,
|
||||||
|
}, []error{errDiskNotFound}, errVolumeNotFound},
|
||||||
|
{[]error{}, []error{}, nil},
|
||||||
}
|
}
|
||||||
|
// Validates list of all the testcases for returning valid errors.
|
||||||
for i, testCase := range testCases {
|
for i, testCase := range testCases {
|
||||||
gotMax, gotErr := reduceErrs(testCase.errs)
|
gotErr := reduceErrs(testCase.errs, testCase.ignoredErrs)
|
||||||
if testCase.err != gotErr {
|
if testCase.err != gotErr {
|
||||||
t.Errorf("Test %d : expected %s, got %s", i+1, testCase.err, gotErr)
|
t.Errorf("Test %d : expected %s, got %s", i+1, testCase.err, gotErr)
|
||||||
}
|
}
|
||||||
if testCase.count != gotMax {
|
|
||||||
t.Errorf("Test %d : expected %d, got %d", i+1, testCase.count, gotMax)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
10
xl-v1.go
10
xl-v1.go
|
@ -45,7 +45,7 @@ const (
|
||||||
maxErasureBlocks = 16
|
maxErasureBlocks = 16
|
||||||
|
|
||||||
// Minimum erasure blocks.
|
// Minimum erasure blocks.
|
||||||
minErasureBlocks = 6
|
minErasureBlocks = 4
|
||||||
)
|
)
|
||||||
|
|
||||||
// xlObjects - Implements XL object layer.
|
// xlObjects - Implements XL object layer.
|
||||||
|
@ -84,7 +84,7 @@ func checkSufficientDisks(disks []string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify if we have even number of disks.
|
// Verify if we have even number of disks.
|
||||||
// only combination of 6, 8, 10, 12, 14, 16 are supported.
|
// only combination of 4, 6, 8, 10, 12, 14, 16 are supported.
|
||||||
if !isEven(totalDisks) {
|
if !isEven(totalDisks) {
|
||||||
return errXLNumDisks
|
return errXLNumDisks
|
||||||
}
|
}
|
||||||
|
@ -194,9 +194,9 @@ func newXLObjects(disks, ignoredDisks []string) (ObjectLayer, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Figure out read and write quorum based on number of storage disks.
|
// Figure out read and write quorum based on number of storage disks.
|
||||||
// READ and WRITE quorum is always set to (N/2 + 1) number of disks.
|
// READ and WRITE quorum is always set to (N/2) number of disks.
|
||||||
xl.readQuorum = len(xl.storageDisks)/2 + 1
|
xl.readQuorum = len(xl.storageDisks) / 2
|
||||||
xl.writeQuorum = len(xl.storageDisks)/2 + 1
|
xl.writeQuorum = len(xl.storageDisks) / 2
|
||||||
|
|
||||||
// Return successfully initialized object layer.
|
// Return successfully initialized object layer.
|
||||||
return xl, nil
|
return xl, nil
|
||||||
|
|
|
@ -73,7 +73,7 @@ func TestCheckSufficientDisks(t *testing.T) {
|
||||||
},
|
},
|
||||||
// Lesser than minimum number of disks < 6.
|
// Lesser than minimum number of disks < 6.
|
||||||
{
|
{
|
||||||
disks[0:5],
|
disks[0:3],
|
||||||
errXLMinDisks,
|
errXLMinDisks,
|
||||||
},
|
},
|
||||||
// Odd number of disks, not divisible by '2'.
|
// Odd number of disks, not divisible by '2'.
|
||||||
|
|
Loading…
Reference in New Issue