ObjectLayer/GetObject: Should return the right error value. Fix done in FS and XL. (#2133)

fixes #2117
This commit is contained in:
Krishna Srinivas
2016-07-10 01:31:32 +05:30
committed by Harshavardhana
parent 5102a5877e
commit ae80f8ca35
4 changed files with 105 additions and 1 deletions
+53
View File
@@ -23,6 +23,59 @@ import (
"path"
)
// Returns nil even if one of the slice elements is nil.
// Else returns the error which occours the most.
func reduceErrs(errs []error) error {
// In case the error type is not in the known error list.
var unknownErr = errors.New("unknown error")
var errTypes = []struct {
err error // error type
count int // occurance count
}{
// List of known error types. Any new type that can be returned from StorageAPI should
// be added to this list. Most common errors are listed here.
{errDiskNotFound, 0}, {errFaultyDisk, 0}, {errFileAccessDenied, 0},
{errFileNotFound, 0}, {errFileNameTooLong, 0}, {errVolumeNotFound, 0},
{errDiskFull, 0},
// unknownErr count - count of the number of unknown errors.
{unknownErr, 0},
}
// In case unknownErr count occours maximum number of times, unknownErrType is used to
// to store it so that it can be used for the return error type.
var unknownErrType error
// For each err in []errs increment the corresponding count value.
for _, err := range errs {
if err == nil {
// Return nil even if one of the elements is nil.
return nil
}
for i := range errTypes {
if errTypes[i].err == err {
errTypes[i].count++
break
}
if errTypes[i].err == unknownErr {
errTypes[i].count++
unknownErrType = err
break
}
}
}
max := 0
// Get the error type which has the maximum count.
for i, errType := range errTypes {
if errType.count > errTypes[max].count {
max = i
}
}
if errTypes[max].err == unknownErr {
// Return the unknown error.
return unknownErrType
}
return errTypes[max].err
}
// Validates if we have quorum based on the errors with errDiskNotFound.
func isQuorum(errs []error, minQuorumCount int) bool {
var diskFoundCount int