mirror of
https://github.com/minio/minio.git
synced 2025-11-20 09:56:07 -05:00
Create logger package and rename errorIf to LogIf (#5678)
Removing message from error logging Replace errors.Trace with LogIf
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"hash/crc32"
|
||||
@@ -24,6 +25,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/minio/minio/cmd/logger"
|
||||
errors2 "github.com/minio/minio/pkg/errors"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
@@ -36,7 +38,6 @@ import (
|
||||
// maximal values would occur quorum or more number of times.
|
||||
func reduceErrs(errs []error, ignoredErrs []error) (maxCount int, maxErr error) {
|
||||
errorCounts := make(map[error]int)
|
||||
errs = errors2.Causes(errs)
|
||||
for _, err := range errs {
|
||||
if errors2.IsErrIgnored(err, ignoredErrs...) {
|
||||
continue
|
||||
@@ -63,34 +64,26 @@ func reduceErrs(errs []error, ignoredErrs []error) (maxCount int, maxErr error)
|
||||
// reduceQuorumErrs behaves like reduceErrs by only for returning
|
||||
// values of maximally occurring errors validated against a generic
|
||||
// quorum number that can be read or write quorum depending on usage.
|
||||
// Additionally a special error is provided to be returned in case
|
||||
// quorum is not satisfied.
|
||||
func reduceQuorumErrs(errs []error, ignoredErrs []error, quorum int, quorumErr error) (maxErr error) {
|
||||
var maxCount int
|
||||
maxCount, maxErr = reduceErrs(errs, ignoredErrs)
|
||||
switch {
|
||||
case maxErr == nil && maxCount >= quorum:
|
||||
// Success in quorum.
|
||||
case maxErr != nil && maxCount >= quorum:
|
||||
// Errors in quorum.
|
||||
maxErr = errors2.Trace(maxErr, errs...)
|
||||
default:
|
||||
// No quorum satisfied.
|
||||
maxErr = errors2.Trace(quorumErr, errs...)
|
||||
func reduceQuorumErrs(ctx context.Context, errs []error, ignoredErrs []error, quorum int, quorumErr error) error {
|
||||
maxCount, maxErr := reduceErrs(errs, ignoredErrs)
|
||||
if maxCount >= quorum {
|
||||
logger.LogIf(ctx, maxErr)
|
||||
return maxErr
|
||||
}
|
||||
return
|
||||
logger.LogIf(ctx, quorumErr)
|
||||
return quorumErr
|
||||
}
|
||||
|
||||
// reduceReadQuorumErrs behaves like reduceErrs but only for returning
|
||||
// values of maximally occurring errors validated against readQuorum.
|
||||
func reduceReadQuorumErrs(errs []error, ignoredErrs []error, readQuorum int) (maxErr error) {
|
||||
return reduceQuorumErrs(errs, ignoredErrs, readQuorum, errXLReadQuorum)
|
||||
func reduceReadQuorumErrs(ctx context.Context, errs []error, ignoredErrs []error, readQuorum int) (maxErr error) {
|
||||
return reduceQuorumErrs(ctx, errs, ignoredErrs, readQuorum, errXLReadQuorum)
|
||||
}
|
||||
|
||||
// reduceWriteQuorumErrs behaves like reduceErrs but only for returning
|
||||
// values of maximally occurring errors validated against writeQuorum.
|
||||
func reduceWriteQuorumErrs(errs []error, ignoredErrs []error, writeQuorum int) (maxErr error) {
|
||||
return reduceQuorumErrs(errs, ignoredErrs, writeQuorum, errXLWriteQuorum)
|
||||
func reduceWriteQuorumErrs(ctx context.Context, errs []error, ignoredErrs []error, writeQuorum int) (maxErr error) {
|
||||
return reduceQuorumErrs(ctx, errs, ignoredErrs, writeQuorum, errXLWriteQuorum)
|
||||
}
|
||||
|
||||
// Similar to 'len(slice)' but returns the actual elements count
|
||||
@@ -153,7 +146,7 @@ func parseXLRelease(xlMetaBuf []byte) string {
|
||||
return gjson.GetBytes(xlMetaBuf, "minio.release").String()
|
||||
}
|
||||
|
||||
func parseXLErasureInfo(xlMetaBuf []byte) (ErasureInfo, error) {
|
||||
func parseXLErasureInfo(ctx context.Context, xlMetaBuf []byte) (ErasureInfo, error) {
|
||||
erasure := ErasureInfo{}
|
||||
erasureResult := gjson.GetBytes(xlMetaBuf, "erasure")
|
||||
// parse the xlV1Meta.Erasure.Distribution.
|
||||
@@ -177,11 +170,13 @@ func parseXLErasureInfo(xlMetaBuf []byte) (ErasureInfo, error) {
|
||||
for i, v := range checkSumsResult {
|
||||
algorithm := BitrotAlgorithmFromString(v.Get("algorithm").String())
|
||||
if !algorithm.Available() {
|
||||
return erasure, errors2.Trace(errBitrotHashAlgoInvalid)
|
||||
logger.LogIf(ctx, errBitrotHashAlgoInvalid)
|
||||
return erasure, errBitrotHashAlgoInvalid
|
||||
}
|
||||
hash, err := hex.DecodeString(v.Get("hash").String())
|
||||
if err != nil {
|
||||
return erasure, errors2.Trace(err)
|
||||
logger.LogIf(ctx, err)
|
||||
return erasure, err
|
||||
}
|
||||
checkSums[i] = ChecksumInfo{Name: v.Get("name").String(), Algorithm: algorithm, Hash: hash}
|
||||
}
|
||||
@@ -215,7 +210,7 @@ func parseXLMetaMap(xlMetaBuf []byte) map[string]string {
|
||||
}
|
||||
|
||||
// Constructs XLMetaV1 using `gjson` lib to retrieve each field.
|
||||
func xlMetaV1UnmarshalJSON(xlMetaBuf []byte) (xlMeta xlMetaV1, e error) {
|
||||
func xlMetaV1UnmarshalJSON(ctx context.Context, xlMetaBuf []byte) (xlMeta xlMetaV1, e error) {
|
||||
// obtain version.
|
||||
xlMeta.Version = parseXLVersion(xlMetaBuf)
|
||||
// obtain format.
|
||||
@@ -223,12 +218,13 @@ func xlMetaV1UnmarshalJSON(xlMetaBuf []byte) (xlMeta xlMetaV1, e error) {
|
||||
// Parse xlMetaV1.Stat .
|
||||
stat, err := parseXLStat(xlMetaBuf)
|
||||
if err != nil {
|
||||
logger.LogIf(ctx, err)
|
||||
return xlMeta, err
|
||||
}
|
||||
|
||||
xlMeta.Stat = stat
|
||||
// parse the xlV1Meta.Erasure fields.
|
||||
xlMeta.Erasure, err = parseXLErasureInfo(xlMetaBuf)
|
||||
xlMeta.Erasure, err = parseXLErasureInfo(ctx, xlMetaBuf)
|
||||
if err != nil {
|
||||
return xlMeta, err
|
||||
}
|
||||
@@ -244,11 +240,12 @@ func xlMetaV1UnmarshalJSON(xlMetaBuf []byte) (xlMeta xlMetaV1, e error) {
|
||||
}
|
||||
|
||||
// read xl.json from the given disk, parse and return xlV1MetaV1.Parts.
|
||||
func readXLMetaParts(disk StorageAPI, bucket string, object string) ([]objectPartInfo, map[string]string, error) {
|
||||
func readXLMetaParts(ctx context.Context, disk StorageAPI, bucket string, object string) ([]objectPartInfo, map[string]string, error) {
|
||||
// Reads entire `xl.json`.
|
||||
xlMetaBuf, err := disk.ReadAll(bucket, path.Join(object, xlMetaJSONFile))
|
||||
if err != nil {
|
||||
return nil, nil, errors2.Trace(err)
|
||||
logger.LogIf(ctx, err)
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
// obtain xlMetaV1{}.Partsusing `github.com/tidwall/gjson`.
|
||||
@@ -259,11 +256,12 @@ func readXLMetaParts(disk StorageAPI, bucket string, object string) ([]objectPar
|
||||
}
|
||||
|
||||
// read xl.json from the given disk and parse xlV1Meta.Stat and xlV1Meta.Meta using gjson.
|
||||
func readXLMetaStat(disk StorageAPI, bucket string, object string) (si statInfo, mp map[string]string, e error) {
|
||||
func readXLMetaStat(ctx context.Context, disk StorageAPI, bucket string, object string) (si statInfo, mp map[string]string, e error) {
|
||||
// Reads entire `xl.json`.
|
||||
xlMetaBuf, err := disk.ReadAll(bucket, path.Join(object, xlMetaJSONFile))
|
||||
if err != nil {
|
||||
return si, nil, errors2.Trace(err)
|
||||
logger.LogIf(ctx, err)
|
||||
return si, nil, err
|
||||
}
|
||||
|
||||
// obtain version.
|
||||
@@ -275,7 +273,8 @@ func readXLMetaStat(disk StorageAPI, bucket string, object string) (si statInfo,
|
||||
// Validate if the xl.json we read is sane, return corrupted format.
|
||||
if !isXLMetaFormatValid(xlVersion, xlFormat) {
|
||||
// For version mismatchs and unrecognized format, return corrupted format.
|
||||
return si, nil, errors2.Trace(errCorruptedFormat)
|
||||
logger.LogIf(ctx, errCorruptedFormat)
|
||||
return si, nil, errCorruptedFormat
|
||||
}
|
||||
|
||||
// obtain xlMetaV1{}.Meta using `github.com/tidwall/gjson`.
|
||||
@@ -284,7 +283,8 @@ func readXLMetaStat(disk StorageAPI, bucket string, object string) (si statInfo,
|
||||
// obtain xlMetaV1{}.Stat using `github.com/tidwall/gjson`.
|
||||
xlStat, err := parseXLStat(xlMetaBuf)
|
||||
if err != nil {
|
||||
return si, nil, errors2.Trace(err)
|
||||
logger.LogIf(ctx, err)
|
||||
return si, nil, err
|
||||
}
|
||||
|
||||
// Return structured `xl.json`.
|
||||
@@ -292,16 +292,17 @@ func readXLMetaStat(disk StorageAPI, bucket string, object string) (si statInfo,
|
||||
}
|
||||
|
||||
// readXLMeta reads `xl.json` and returns back XL metadata structure.
|
||||
func readXLMeta(disk StorageAPI, bucket string, object string) (xlMeta xlMetaV1, err error) {
|
||||
func readXLMeta(ctx context.Context, disk StorageAPI, bucket string, object string) (xlMeta xlMetaV1, err error) {
|
||||
// Reads entire `xl.json`.
|
||||
xlMetaBuf, err := disk.ReadAll(bucket, path.Join(object, xlMetaJSONFile))
|
||||
if err != nil {
|
||||
return xlMetaV1{}, errors2.Trace(err)
|
||||
logger.LogIf(ctx, err)
|
||||
return xlMetaV1{}, err
|
||||
}
|
||||
// obtain xlMetaV1{} using `github.com/tidwall/gjson`.
|
||||
xlMeta, err = xlMetaV1UnmarshalJSON(xlMetaBuf)
|
||||
xlMeta, err = xlMetaV1UnmarshalJSON(ctx, xlMetaBuf)
|
||||
if err != nil {
|
||||
return xlMetaV1{}, errors2.Trace(err)
|
||||
return xlMetaV1{}, err
|
||||
}
|
||||
// Return structured `xl.json`.
|
||||
return xlMeta, nil
|
||||
@@ -309,7 +310,7 @@ func readXLMeta(disk StorageAPI, bucket string, object string) (xlMeta xlMetaV1,
|
||||
|
||||
// Reads all `xl.json` metadata as a xlMetaV1 slice.
|
||||
// Returns error slice indicating the failed metadata reads.
|
||||
func readAllXLMetadata(disks []StorageAPI, bucket, object string) ([]xlMetaV1, []error) {
|
||||
func readAllXLMetadata(ctx context.Context, disks []StorageAPI, bucket, object string) ([]xlMetaV1, []error) {
|
||||
errs := make([]error, len(disks))
|
||||
metadataArray := make([]xlMetaV1, len(disks))
|
||||
var wg = &sync.WaitGroup{}
|
||||
@@ -324,7 +325,7 @@ func readAllXLMetadata(disks []StorageAPI, bucket, object string) ([]xlMetaV1, [
|
||||
go func(index int, disk StorageAPI) {
|
||||
defer wg.Done()
|
||||
var err error
|
||||
metadataArray[index], err = readXLMeta(disk, bucket, object)
|
||||
metadataArray[index], err = readXLMeta(ctx, disk, bucket, object)
|
||||
if err != nil {
|
||||
errs[index] = err
|
||||
return
|
||||
@@ -384,7 +385,7 @@ func unshuffleIndex(n int, distribution []int) int {
|
||||
// the corresponding error in errs slice is not nil
|
||||
func evalDisks(disks []StorageAPI, errs []error) []StorageAPI {
|
||||
if len(errs) != len(disks) {
|
||||
errorIf(errors.New("unexpected disks/errors slice length"), "unable to evaluate internal disks")
|
||||
logger.LogIf(context.Background(), errors.New("unexpected disks/errors slice length"))
|
||||
return nil
|
||||
}
|
||||
newDisks := make([]StorageAPI, len(disks))
|
||||
@@ -406,15 +407,18 @@ var (
|
||||
|
||||
// calculatePartSizeFromIdx calculates the part size according to input index.
|
||||
// returns error if totalSize is -1, partSize is 0, partIndex is 0.
|
||||
func calculatePartSizeFromIdx(totalSize int64, partSize int64, partIndex int) (currPartSize int64, err error) {
|
||||
func calculatePartSizeFromIdx(ctx context.Context, totalSize int64, partSize int64, partIndex int) (currPartSize int64, err error) {
|
||||
if totalSize < 0 {
|
||||
return 0, errors2.Trace(errInvalidArgument)
|
||||
logger.LogIf(ctx, errInvalidArgument)
|
||||
return 0, errInvalidArgument
|
||||
}
|
||||
if partSize == 0 {
|
||||
return 0, errors2.Trace(errPartSizeZero)
|
||||
logger.LogIf(ctx, errPartSizeZero)
|
||||
return 0, errPartSizeZero
|
||||
}
|
||||
if partIndex < 1 {
|
||||
return 0, errors2.Trace(errPartSizeIndex)
|
||||
logger.LogIf(ctx, errPartSizeIndex)
|
||||
return 0, errPartSizeIndex
|
||||
}
|
||||
if totalSize > 0 {
|
||||
// Compute the total count of parts
|
||||
|
||||
Reference in New Issue
Block a user