From f23f814764227668b66980d791564e6ec0d038c7 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sun, 19 Apr 2020 10:59:05 -0700 Subject: [PATCH] fix: allow watch to use queueCh from parallel manager (#3180) --- cmd/mirror-main.go | 55 +++++++++++++++++++++++++++------------------- cmd/utils.go | 4 +++- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/cmd/mirror-main.go b/cmd/mirror-main.go index 3146102e..f62f7bad 100644 --- a/cmd/mirror-main.go +++ b/cmd/mirror-main.go @@ -369,11 +369,12 @@ func (mj *mirrorJob) monitorMirrorStatus() (errDuringMirror bool) { } // this goroutine will watch for notifications, and add modified objects to the queue -func (mj *mirrorJob) watchMirror(ctx context.Context, cancelMirror context.CancelFunc) { +func (mj *mirrorJob) watchMirror(ctx context.Context, cancelMirror context.CancelFunc, stopParallel func()) { for { select { case event, ok := <-mj.watcher.Events(): if !ok { + stopParallel() return } @@ -460,7 +461,9 @@ func (mj *mirrorJob) watchMirror(ctx context.Context, cancelMirror context.Cance mj.status.AddCounts(1) mirrorURL.TotalSize = mj.status.Get() mirrorURL.TotalCount = mj.status.GetCounts() - mj.statusCh <- mj.doMirror(ctx, cancelMirror, mirrorURL) + mj.queueCh <- func() URLs { + return mj.doMirror(ctx, cancelMirror, mirrorURL) + } } continue } @@ -469,7 +472,9 @@ func (mj *mirrorJob) watchMirror(ctx context.Context, cancelMirror context.Cance targetClient, err := newClient(targetPath) if err != nil { // cannot create targetclient - mj.statusCh <- mirrorURL.WithError(err) + mj.queueCh <- func() URLs { + return mirrorURL.WithError(err) + } return } _, err = targetClient.Stat(false, false, tgtSSE) @@ -490,7 +495,9 @@ func (mj *mirrorJob) watchMirror(ctx context.Context, cancelMirror context.Cance mj.status.AddCounts(1) mirrorURL.TotalSize = mj.status.Get() mirrorURL.TotalCount = mj.status.GetCounts() - mj.statusCh <- mj.doMirror(ctx, cancelMirror, mirrorURL) + mj.queueCh <- func() URLs { + return mj.doMirror(ctx, cancelMirror, mirrorURL) + } } } else if event.Type == EventRemove { if strings.Contains(event.UserAgent, uaMirrorAppName) { @@ -506,7 +513,9 @@ func (mj *mirrorJob) watchMirror(ctx context.Context, cancelMirror context.Cance mirrorURL.TotalCount = mj.status.GetCounts() mirrorURL.TotalSize = mj.status.Get() if mirrorURL.TargetContent != nil && (mj.isRemove || mj.multiMasterEnable) { - mj.statusCh <- mj.doRemove(mirrorURL) + mj.queueCh <- func() URLs { + return mj.doRemove(mirrorURL) + } } } @@ -517,11 +526,11 @@ func (mj *mirrorJob) watchMirror(ctx context.Context, cancelMirror context.Cance "Unable to Watch on source, perhaps source doesn't support Watching for events") return } - mj.statusCh <- URLs{Error: err} - return + mj.queueCh <- func() URLs { + return URLs{Error: err} + } case <-globalContext.Done(): - return - case <-mj.stopCh: + stopParallel() return } } @@ -544,9 +553,7 @@ func (mj *mirrorJob) startMirror(ctx context.Context, cancelMirror context.Cance select { case sURLs, ok := <-URLsCh: if !ok { - if stopParallel != nil { - stopParallel() - } + stopParallel() return } if sURLs.Error != nil { @@ -584,16 +591,10 @@ func (mj *mirrorJob) startMirror(ctx context.Context, cancelMirror context.Cance } } case <-globalContext.Done(): - if stopParallel != nil { - stopParallel() - } - cancelMirror() + stopParallel() return case <-mj.stopCh: - if stopParallel != nil { - stopParallel() - } - cancelMirror() + stopParallel() return } } @@ -609,7 +610,12 @@ func (mj *mirrorJob) mirror(ctx context.Context, cancelMirror context.CancelFunc wg.Add(1) go func() { defer wg.Done() - mj.watchMirror(ctx, cancelMirror) + stopParallel := func() { + close(mj.queueCh) + mj.parallel.wait() + cancelMirror() + } + mj.watchMirror(ctx, cancelMirror, stopParallel) }() } @@ -618,8 +624,11 @@ func (mj *mirrorJob) mirror(ctx context.Context, cancelMirror context.CancelFunc go func() { defer wg.Done() stopParallel := func() { - close(mj.queueCh) - mj.parallel.wait() + if !mj.isWatch { + close(mj.queueCh) + mj.parallel.wait() + cancelMirror() + } } // startMirror locks and blocks itself. mj.startMirror(ctx, cancelMirror, stopParallel) diff --git a/cmd/utils.go b/cmd/utils.go index 6025eb6e..870543dd 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -39,7 +39,7 @@ import ( func isErrIgnored(err *probe.Error) (ignored bool) { // For all non critical errors we can continue for the remaining files. - switch err.ToGoError().(type) { + switch e := err.ToGoError().(type) { // Handle these specifically for filesystem related errors. case BrokenSymlink, TooManyLevelsSymlink, PathNotFound: ignored = true @@ -48,6 +48,8 @@ func isErrIgnored(err *probe.Error) (ignored bool) { ignored = true case ObjectAlreadyExistsAsDirectory, BucketDoesNotExist, BucketInvalid: ignored = true + case minio.ErrorResponse: + ignored = strings.Contains(e.Error(), "The specified key does not exist") default: ignored = false }