From 8a488ba0e45ac3de4f0138370edaddd35fc85cd3 Mon Sep 17 00:00:00 2001 From: Krishna Srinivas <634494+krishnasrinivas@users.noreply.github.com> Date: Mon, 9 Dec 2019 01:32:58 -0800 Subject: [PATCH] Do full scan diff+mirror in multi-site mirror mode (#2994) --- cmd/mirror-main.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cmd/mirror-main.go b/cmd/mirror-main.go index 87f98bb5..3a25a6f4 100644 --- a/cmd/mirror-main.go +++ b/cmd/mirror-main.go @@ -178,6 +178,7 @@ type mirrorJob struct { // the channel to trap SIGKILL signals trapCh <-chan bool + stopCh chan struct{} // mutex for shutdown, this prevents the shutdown // to be initiated multiple times @@ -364,6 +365,10 @@ func (mj *mirrorJob) monitorMirrorStatus() (errDuringMirror bool) { errorIf(sURLs.Error.Trace(), "Failed to perform mirroring.") errDuringMirror = true } + if mj.multiMasterEnable { + close(mj.stopCh) + break + } } if sURLs.SourceContent != nil { @@ -542,6 +547,8 @@ func (mj *mirrorJob) watchMirror(ctx context.Context, cancelMirror context.Cance return case <-mj.trapCh: return + case <-mj.stopCh: + return } } } @@ -605,6 +612,10 @@ func (mj *mirrorJob) startMirror(ctx context.Context, cancelMirror context.Cance stopParallel() cancelMirror() return + case <-mj.stopCh: + stopParallel() + cancelMirror() + return } } } @@ -645,6 +656,7 @@ func newMirrorJob(srcURL, dstURL string, isFake, isRemove, isOverwrite, isWatch, } mj := mirrorJob{ trapCh: signalTrap(os.Interrupt, syscall.SIGTERM, syscall.SIGKILL), + stopCh: make(chan struct{}), m: new(sync.Mutex), sourceURL: srcURL, @@ -867,7 +879,7 @@ func mainMirror(ctx *cli.Context) error { srcURL := args[0] tgtURL := args[1] - if ctx.Bool("watch") { + if ctx.String("multi-master") != "" { for { runMirror(srcURL, tgtURL, ctx, encKeyDB) time.Sleep(time.Second * 2)