From 0286e61aee78d8625fb364a1fbd80d040a72d14c Mon Sep 17 00:00:00 2001 From: kannappanr <30541348+kannappanr@users.noreply.github.com> Date: Tue, 14 Aug 2018 13:58:48 -0700 Subject: [PATCH] Log disk not found error just once (#6059) Modified the LogIf function to log only if the error passed is not on the ignored errors list. Currently, only disk not found error is added to the list. Added a new function in logger package called LogAlwaysIf, which will print on any error. Fixes #5997 --- cmd/logger/logger.go | 30 +++++++++++++++++++++++++++--- cmd/prepare-storage.go | 4 ++-- cmd/xl-v1-bucket.go | 2 -- cmd/xl-v1-healing.go | 1 - cmd/xl-v1-metadata.go | 2 -- cmd/xl-v1-multipart.go | 2 -- cmd/xl-v1-object.go | 1 - 7 files changed, 29 insertions(+), 13 deletions(-) diff --git a/cmd/logger/logger.go b/cmd/logger/logger.go index 6350d2d0d..513dd6fa7 100644 --- a/cmd/logger/logger.go +++ b/cmd/logger/logger.go @@ -47,6 +47,11 @@ const ( const loggerTimeFormat string = "15:04:05 MST 01/02/2006" +// List of error strings to be ignored by LogIf +const ( + diskNotFoundError = "disk not found" +) + var matchingFuncNames = [...]string{ "http.HandlerFunc.ServeHTTP", "cmd.serverMain", @@ -267,17 +272,36 @@ func getTrace(traceLevel int) []string { return trace } -// LogIf prints a detailed error message during +// LogAlwaysIf prints a detailed error message during // the execution of the server. -func LogIf(ctx context.Context, err error) { - if Disable { +func LogAlwaysIf(ctx context.Context, err error) { + if err == nil { return } + logIf(ctx, err) +} + +// LogIf prints a detailed error message during +// the execution of the server, if it is not an +// ignored error. +func LogIf(ctx context.Context, err error) { if err == nil { return } + if err.Error() != diskNotFoundError { + logIf(ctx, err) + } +} + +// logIf prints a detailed error message during +// the execution of the server. +func logIf(ctx context.Context, err error) { + if Disable { + return + } + req := GetReqInfo(ctx) if req == nil { diff --git a/cmd/prepare-storage.go b/cmd/prepare-storage.go index 6f310f8d2..c25f1f0e7 100644 --- a/cmd/prepare-storage.go +++ b/cmd/prepare-storage.go @@ -36,14 +36,14 @@ var printEndpointError = func() func(Endpoint, error) { m = make(map[string]bool) m[err.Error()] = true printOnce[endpoint] = m - logger.LogIf(ctx, err) + logger.LogAlwaysIf(ctx, err) return } if m[err.Error()] { return } m[err.Error()] = true - logger.LogIf(ctx, err) + logger.LogAlwaysIf(ctx, err) } }() diff --git a/cmd/xl-v1-bucket.go b/cmd/xl-v1-bucket.go index 4ced379c7..e3875560d 100644 --- a/cmd/xl-v1-bucket.go +++ b/cmd/xl-v1-bucket.go @@ -50,7 +50,6 @@ func (xl xlObjects) MakeBucketWithLocation(ctx context.Context, bucket, location // Make a volume entry on all underlying storage disks. for index, disk := range xl.getDisks() { if disk == nil { - logger.LogIf(ctx, errDiskNotFound) dErrs[index] = errDiskNotFound continue } @@ -234,7 +233,6 @@ func (xl xlObjects) DeleteBucket(ctx context.Context, bucket string) error { // Remove a volume entry on all underlying storage disks. for index, disk := range xl.getDisks() { if disk == nil { - logger.LogIf(ctx, errDiskNotFound) dErrs[index] = errDiskNotFound continue } diff --git a/cmd/xl-v1-healing.go b/cmd/xl-v1-healing.go index 757a1d3a3..d9262c0e8 100644 --- a/cmd/xl-v1-healing.go +++ b/cmd/xl-v1-healing.go @@ -108,7 +108,6 @@ func healBucket(ctx context.Context, storageDisks []StorageAPI, bucket string, w // Make a volume entry on all underlying storage disks. for index, disk := range storageDisks { if disk == nil { - logger.LogIf(ctx, errDiskNotFound) dErrs[index] = errDiskNotFound beforeState[index] = madmin.DriveStateOffline afterState[index] = madmin.DriveStateOffline diff --git a/cmd/xl-v1-metadata.go b/cmd/xl-v1-metadata.go index a7f8e3ddb..cd5032adf 100644 --- a/cmd/xl-v1-metadata.go +++ b/cmd/xl-v1-metadata.go @@ -428,7 +428,6 @@ func writeUniqueXLMetadata(ctx context.Context, disks []StorageAPI, bucket, pref // Start writing `xl.json` to all disks in parallel. for index, disk := range disks { if disk == nil { - logger.LogIf(ctx, errDiskNotFound) mErrs[index] = errDiskNotFound continue } @@ -467,7 +466,6 @@ func writeSameXLMetadata(ctx context.Context, disks []StorageAPI, bucket, prefix // Start writing `xl.json` to all disks in parallel. for index, disk := range disks { if disk == nil { - logger.LogIf(ctx, errDiskNotFound) mErrs[index] = errDiskNotFound continue } diff --git a/cmd/xl-v1-multipart.go b/cmd/xl-v1-multipart.go index 37f167b1a..8e4b8d7f4 100644 --- a/cmd/xl-v1-multipart.go +++ b/cmd/xl-v1-multipart.go @@ -103,7 +103,6 @@ func commitXLMetadata(ctx context.Context, disks []StorageAPI, srcBucket, srcPre // Rename `xl.json` to all disks in parallel. for index, disk := range disks { if disk == nil { - logger.LogIf(ctx, errDiskNotFound) mErrs[index] = errDiskNotFound continue } @@ -791,7 +790,6 @@ func (xl xlObjects) cleanupUploadedParts(ctx context.Context, uploadIDPath strin // Cleanup uploadID for all disks. for index, disk := range xl.getDisks() { if disk == nil { - logger.LogIf(ctx, errDiskNotFound) errs[index] = errDiskNotFound continue } diff --git a/cmd/xl-v1-object.go b/cmd/xl-v1-object.go index 1e007be00..0cecdfa8d 100644 --- a/cmd/xl-v1-object.go +++ b/cmd/xl-v1-object.go @@ -807,7 +807,6 @@ func (xl xlObjects) deleteObject(ctx context.Context, bucket, object string) err for index, disk := range xl.getDisks() { if disk == nil { - logger.LogIf(ctx, errDiskNotFound) dErrs[index] = errDiskNotFound continue }