From 91c9364f3c135bd7a0842a58fb1fcd719c9b622e Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 21 Oct 2020 13:42:18 -0700 Subject: [PATCH] add context for mirror failures (#3464) --- cmd/config.go | 4 ++-- cmd/config_test.go | 19 +++++++++++++++++-- cmd/difference.go | 15 ++++++++------- cmd/mirror-main.go | 7 ++++++- cmd/mirror-url.go | 10 +++++++--- cmd/urls.go | 1 + 6 files changed, 41 insertions(+), 15 deletions(-) diff --git a/cmd/config.go b/cmd/config.go index 602de4b1..ca583070 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -209,8 +209,8 @@ func mustGetHostConfig(alias string) *aliasConfigV10 { } var ( - hostKeys = regexp.MustCompile("^(https?://)(.*?):(.*?)@(.*?)$") - hostKeyTokens = regexp.MustCompile("^(https?://)(.*?):(.*?):(.*?)@(.*?)$") + hostKeys = regexp.MustCompile("^(https?://)(.*?):(.*)@(.*?)$") + hostKeyTokens = regexp.MustCompile("^(https?://)(.*?):(.*?):(.*)@(.*?)$") ) // parse url usually obtained from env. diff --git a/cmd/config_test.go b/cmd/config_test.go index e774f267..67683e03 100644 --- a/cmd/config_test.go +++ b/cmd/config_test.go @@ -36,9 +36,16 @@ func TestParseEnvURLStr(t *testing.T) { port: "9000", }, { - hostURL: "https://minio:minio123@localhost:9000", + hostURL: "https://minio:minio123@@localhost:9000", accessKey: "minio", - secretKey: "minio123", + secretKey: "minio123@", + hostname: "localhost", + port: "9000", + }, + { + hostURL: "https://minio:minio@123@@localhost:9000", + accessKey: "minio", + secretKey: "minio@123@", hostname: "localhost", port: "9000", }, @@ -57,6 +64,14 @@ func TestParseEnvURLStr(t *testing.T) { hostname: "localhost", port: "9000", }, + { + hostURL: "https://minio:minio@123:token@@localhost:9000", + accessKey: "minio", + secretKey: "minio@123", + sessionToken: "token@", + hostname: "localhost", + port: "9000", + }, { hostURL: "https://minio@localhost:9000", accessKey: "minio", diff --git a/cmd/difference.go b/cmd/difference.go index e3ef9234..dab4a725 100644 --- a/cmd/difference.go +++ b/cmd/difference.go @@ -33,13 +33,14 @@ import ( type differType int const ( - differInNone differType = iota // does not differ - differInSize // differs in size - differInMetadata // differs in metadata - differInType // differs in type, exfile/directory - differInFirst // only in source (FIRST) - differInSecond // only in target (SECOND) - differInAASourceMTime // differs in active-active source modtime + differInUnknown differType = iota + differInNone // does not differ + differInSize // differs in size + differInMetadata // differs in metadata + differInType // differs in type, exfile/directory + differInFirst // only in source (FIRST) + differInSecond // only in target (SECOND) + differInAASourceMTime // differs in active-active source modtime ) func (d differType) String() string { diff --git a/cmd/mirror-main.go b/cmd/mirror-main.go index 15daeaf6..a3d12c67 100644 --- a/cmd/mirror-main.go +++ b/cmd/mirror-main.go @@ -384,7 +384,12 @@ func (mj *mirrorJob) monitorMirrorStatus() (errDuringMirror bool) { fmt.Sprintf("Failed to remove `%s`.", sURLs.TargetContent.URL.String())) errDuringMirror = true default: - errorIf(sURLs.Error.Trace(), "Failed to perform mirroring.") + if sURLs.ErrorCond == differInUnknown { + errorIf(sURLs.Error.Trace(), "Failed to perform mirroring") + } else { + errorIf(sURLs.Error.Trace(), + "Failed to perform mirroring, with error condition (%s)", sURLs.ErrorCond) + } errDuringMirror = true } if mj.opts.activeActive { diff --git a/cmd/mirror-url.go b/cmd/mirror-url.go index 16188044..1c9a5678 100644 --- a/cmd/mirror-url.go +++ b/cmd/mirror-url.go @@ -130,7 +130,7 @@ func deltaSourceTarget(ctx context.Context, sourceURL, targetURL string, opts mi for diffMsg := range objectDifference(ctx, sourceClnt, targetClnt, sourceURL, targetURL, opts.isMetadata) { if diffMsg.Error != nil { // Send all errors through the channel - URLsCh <- URLs{Error: diffMsg.Error} + URLsCh <- URLs{Error: diffMsg.Error, ErrorCond: differInUnknown} continue } @@ -154,7 +154,10 @@ func deltaSourceTarget(ctx context.Context, sourceURL, targetURL string, opts mi case differInSize, differInMetadata, differInAASourceMTime: if !opts.isOverwrite && !opts.isFake && !opts.activeActive { // Size or time or etag differs but --overwrite not set. - URLsCh <- URLs{Error: errOverWriteNotAllowed(diffMsg.SecondURL)} + URLsCh <- URLs{ + Error: errOverWriteNotAllowed(diffMsg.SecondURL), + ErrorCond: diffMsg.Diff, + } continue } @@ -191,7 +194,8 @@ func deltaSourceTarget(ctx context.Context, sourceURL, targetURL string, opts mi } default: URLsCh <- URLs{ - Error: errUnrecognizedDiffType(diffMsg.Diff).Trace(diffMsg.FirstURL, diffMsg.SecondURL), + Error: errUnrecognizedDiffType(diffMsg.Diff).Trace(diffMsg.FirstURL, diffMsg.SecondURL), + ErrorCond: diffMsg.Diff, } } } diff --git a/cmd/urls.go b/cmd/urls.go index 9e21bae6..888b5d49 100644 --- a/cmd/urls.go +++ b/cmd/urls.go @@ -32,6 +32,7 @@ type URLs struct { DisableMultipart bool encKeyDB map[string][]prefixSSEPair Error *probe.Error `json:"-"` + ErrorCond differType `json:"-"` } // WithError sets the error and returns object