fix copyRowsFunc hangs bug

This commit is contained in:
wangfei 2018-07-23 09:29:21 +08:00
parent d2726c77f8
commit c7dff99a19

View File

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