diff --git a/go/logic/migrator.go b/go/logic/migrator.go index eaddbbe..d21dccf 100644 --- a/go/logic/migrator.go +++ b/go/logic/migrator.go @@ -1087,24 +1087,30 @@ func (this *Migrator) iterateChunks() error { log.Debugf("No rows found in table. Rowcopy will be implicitly empty") return terminateRowIteration(nil) } + + var hasNoFurtherRangeFlag int64 // Iterate per chunk: for { - if atomic.LoadInt64(&this.rowCopyCompleteFlag) == 1 { + if atomic.LoadInt64(&this.rowCopyCompleteFlag) == 1 || atomic.LoadInt64(&hasNoFurtherRangeFlag) == 1 { // Done // There's another such check down the line return nil } copyRowsFunc := func() error { - if atomic.LoadInt64(&this.rowCopyCompleteFlag) == 1 { + if atomic.LoadInt64(&this.rowCopyCompleteFlag) == 1 || atomic.LoadInt64(&hasNoFurtherRangeFlag) == 1 { // Done. // There's another such check down the line return nil } + + // When hasFurtherRange is false, original table might be write locked and CalculateNextIterationRangeEndValues would hangs forever + hasFurtherRange, err := this.applier.CalculateNextIterationRangeEndValues() if err != nil { return terminateRowIteration(err) } if !hasFurtherRange { + atomic.StoreInt64(&hasNoFurtherRangeFlag, 1) return terminateRowIteration(nil) } // Copy task: