Skip to content

Exit mc mirror when errors occur if retry is disabled and it's a watch operation #5163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cmd/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ type errorMessage struct {
SysInfo map[string]string `json:"sysinfo,omitempty"`
}

// errorOrFatal wrapper function to call errorIf or fatalIf based on the boolean value
func errorOrFatal(useFatal bool, err *probe.Error, msg string, data ...interface{}) {
if useFatal {
fatalIf(err, msg, data...)
}
errorIf(err, msg, data...)
}

// fatalIf wrapper function which takes error and selectively prints stack frames if available on debug
func fatalIf(err *probe.Error, msg string, data ...interface{}) {
if err == nil {
Expand Down
12 changes: 8 additions & 4 deletions cmd/mirror-main.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,10 @@ func (mj *mirrorJob) monitorMirrorStatus(cancel context.CancelFunc) (errDuringMi
mj.status.Start()
defer mj.status.Finish()

// if the operation is not retriable and is a watch operation, then
// we should exit on the first error.
useFatal := !mj.opts.isRetriable && mj.opts.isWatch

var cancelInProgress bool

defer func() {
Expand Down Expand Up @@ -595,22 +599,22 @@ func (mj *mirrorJob) monitorMirrorStatus(cancel context.CancelFunc) (errDuringMi
ignoreErr = true
}
if !ignoreErr {
errorIf(sURLs.Error.Trace(sURLs.SourceContent.URL.String()),
errorOrFatal(useFatal, sURLs.Error.Trace(sURLs.SourceContent.URL.String()),
"Failed to copy `%s`.", sURLs.SourceContent.URL)
}
}
case sURLs.TargetContent != nil:
// When sURLs.SourceContent is nil, we know that we have an error related to removing
errorIf(sURLs.Error.Trace(sURLs.TargetContent.URL.String()),
errorOrFatal(useFatal, sURLs.Error.Trace(sURLs.TargetContent.URL.String()),
"Failed to remove `%s`.", sURLs.TargetContent.URL.String())
default:
if strings.Contains(sURLs.Error.ToGoError().Error(), "Overwrite not allowed") {
ignoreErr = true
}
if sURLs.ErrorCond == differInUnknown {
errorIf(sURLs.Error.Trace(), "Failed to perform mirroring")
errorOrFatal(useFatal, sURLs.Error.Trace(), "Failed to perform mirroring")
} else {
errorIf(sURLs.Error.Trace(),
errorOrFatal(useFatal, sURLs.Error.Trace(),
"Failed to perform mirroring, with error condition (%s)", sURLs.ErrorCond)
}
}
Expand Down