Stop mirror/diff when difference() sends error (#2049)
The caller of difference() now receives errors so it can stop mirroring or difference calculation.
This commit is contained in:
committed by
Harshavardhana
parent
ecee324c00
commit
8ce6f43e35
@@ -173,6 +173,10 @@ func doDiffMain(firstURL, secondURL string) error {
|
||||
|
||||
// Diff first and second urls.
|
||||
for diffMsg := range objectDifference(firstClient, secondClient, firstURL, secondURL) {
|
||||
if diffMsg.Error != nil {
|
||||
errorIf(diffMsg.Error, "Unable to calculate objects difference.")
|
||||
break
|
||||
}
|
||||
printMsg(diffMsg)
|
||||
}
|
||||
|
||||
|
||||
+6
-6
@@ -17,7 +17,6 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
@@ -81,24 +80,25 @@ func difference(sourceClnt, targetClnt Client, sourceURL, targetURL string, isRe
|
||||
srcCtnt, srcOk = <-srcCh
|
||||
tgtCtnt, tgtOk = <-tgtCh
|
||||
|
||||
defer close(diffCh)
|
||||
|
||||
for {
|
||||
srcEOF = !srcOk
|
||||
tgtEOF = !tgtOk
|
||||
|
||||
// No objects from source AND target: Finish
|
||||
if srcEOF && tgtEOF {
|
||||
close(diffCh)
|
||||
break
|
||||
}
|
||||
|
||||
if !srcEOF && srcCtnt.Err != nil {
|
||||
errorIf(srcCtnt.Err.Trace(sourceURL, targetURL), fmt.Sprintf("Failed on '%s'", sourceURL))
|
||||
diffCh <- diffMessage{Error: srcCtnt.Err.Trace(sourceURL, targetURL)}
|
||||
srcCtnt, srcOk = <-srcCh
|
||||
continue
|
||||
}
|
||||
|
||||
if !tgtEOF && tgtCtnt.Err != nil {
|
||||
errorIf(tgtCtnt.Err.Trace(sourceURL, targetURL), fmt.Sprintf("Failed on '%s'", targetURL))
|
||||
diffCh <- diffMessage{Error: tgtCtnt.Err.Trace(sourceURL, targetURL)}
|
||||
tgtCtnt, tgtOk = <-tgtCh
|
||||
continue
|
||||
}
|
||||
@@ -132,13 +132,13 @@ func difference(sourceClnt, targetClnt Client, sourceURL, targetURL string, isRe
|
||||
expected := urlJoinPath(targetURL, tgtSuffix)
|
||||
if !utf8.ValidString(srcSuffix) {
|
||||
// Error. Keys must be valid UTF-8.
|
||||
errorIf(errInvalidSource(current), fmt.Sprintf("'%s' is not valid UTF-8", srcSuffix))
|
||||
diffCh <- diffMessage{Error: errInvalidSource(current).Trace()}
|
||||
srcCtnt, srcOk = <-srcCh
|
||||
continue
|
||||
}
|
||||
if !utf8.ValidString(tgtSuffix) {
|
||||
// Error. Keys must be valid UTF-8.
|
||||
errorIf(errInvalidTarget(expected), fmt.Sprintf("'%s' is not valid UTF-8", tgtSuffix))
|
||||
diffCh <- diffMessage{Error: errInvalidTarget(expected).Trace()}
|
||||
tgtCtnt, tgtOk = <-tgtCh
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -581,6 +581,9 @@ func runMirror(srcURL, dstURL string, ctx *cli.Context) *probe.Error {
|
||||
if mirrorAllBuckets {
|
||||
// Synchronize buckets using dirDifference function
|
||||
for d := range dirDifference(srcClt, dstClt, srcURL, dstURL) {
|
||||
if d.Error != nil {
|
||||
mj.status.fatalIf(d.Error, fmt.Sprintf("Failed to start monitoring."))
|
||||
}
|
||||
if d.Diff == differInSecond {
|
||||
// Ignore buckets that only exist in target instance
|
||||
continue
|
||||
|
||||
@@ -97,6 +97,10 @@ func deltaSourceTarget(sourceURL string, targetURL string, isForce bool, isFake
|
||||
|
||||
// List both source and target, compare and return values through channel.
|
||||
for diffMsg := range objectDifference(sourceClnt, targetClnt, sourceURL, targetURL) {
|
||||
if diffMsg.Error != nil {
|
||||
errorIf(diffMsg.Error, "Unable to mirror objects.")
|
||||
break
|
||||
}
|
||||
switch diffMsg.Diff {
|
||||
case differInNone:
|
||||
// No difference, continue.
|
||||
|
||||
Reference in New Issue
Block a user