AllEventsUpToLockProcessed uses unique signature

This commit is contained in:
Shlomi Noach 2016-11-17 15:50:54 +01:00
parent ee447ad560
commit ef874b8551

View File

@ -11,6 +11,7 @@ import (
"math" "math"
"os" "os"
"os/signal" "os/signal"
"strings"
"sync/atomic" "sync/atomic"
"syscall" "syscall"
"time" "time"
@ -60,7 +61,7 @@ type Migrator struct {
firstThrottlingCollected chan bool firstThrottlingCollected chan bool
ghostTableMigrated chan bool ghostTableMigrated chan bool
rowCopyComplete chan bool rowCopyComplete chan bool
allEventsUpToLockProcessed chan bool allEventsUpToLockProcessed chan string
rowCopyCompleteFlag int64 rowCopyCompleteFlag int64
inCutOverCriticalActionFlag int64 inCutOverCriticalActionFlag int64
@ -78,8 +79,8 @@ func NewMigrator() *Migrator {
parser: sql.NewParser(), parser: sql.NewParser(),
ghostTableMigrated: make(chan bool), ghostTableMigrated: make(chan bool),
firstThrottlingCollected: make(chan bool, 1), firstThrottlingCollected: make(chan bool, 1),
rowCopyComplete: make(chan bool, 1), rowCopyComplete: make(chan bool),
allEventsUpToLockProcessed: make(chan bool, 1), allEventsUpToLockProcessed: make(chan string),
copyRowsQueue: make(chan tableWriteFunc), copyRowsQueue: make(chan tableWriteFunc),
applyEventsQueue: make(chan tableWriteFunc, applyEventsQueueBuffer), applyEventsQueue: make(chan tableWriteFunc, applyEventsQueueBuffer),
@ -180,7 +181,8 @@ func (this *Migrator) onChangelogStateEvent(dmlEvent *binlog.BinlogDMLEvent) (er
if hint := dmlEvent.NewColumnValues.StringColumn(2); hint != "state" { if hint := dmlEvent.NewColumnValues.StringColumn(2); hint != "state" {
return nil return nil
} }
changelogState := ChangelogState(dmlEvent.NewColumnValues.StringColumn(3)) changelogStateString := dmlEvent.NewColumnValues.StringColumn(3)
changelogState := ChangelogState(strings.Split(changelogStateString, ":")[0])
log.Infof("Intercepted changelog state %s", changelogState) log.Infof("Intercepted changelog state %s", changelogState)
switch changelogState { switch changelogState {
case GhostTableMigrated: case GhostTableMigrated:
@ -190,7 +192,7 @@ func (this *Migrator) onChangelogStateEvent(dmlEvent *binlog.BinlogDMLEvent) (er
case AllEventsUpToLockProcessed: case AllEventsUpToLockProcessed:
{ {
applyEventFunc := func() error { applyEventFunc := func() error {
this.allEventsUpToLockProcessed <- true this.allEventsUpToLockProcessed <- changelogStateString
return nil return nil
} }
// at this point we know all events up to lock have been read from the streamer, // at this point we know all events up to lock have been read from the streamer,
@ -451,20 +453,28 @@ func (this *Migrator) waitForEventsUpToLock() (err error) {
this.migrationContext.MarkPointOfInterest() this.migrationContext.MarkPointOfInterest()
waitForEventsUpToLockStartTime := time.Now() waitForEventsUpToLockStartTime := time.Now()
log.Infof("Writing changelog state: %+v", AllEventsUpToLockProcessed) allEventsUpToLockProcessedChallenge := fmt.Sprintf("%s:%d", string(AllEventsUpToLockProcessed), waitForEventsUpToLockStartTime.UnixNano())
if _, err := this.applier.WriteChangelogState(string(AllEventsUpToLockProcessed)); err != nil { log.Infof("Writing changelog state: %+v", allEventsUpToLockProcessedChallenge)
if _, err := this.applier.WriteChangelogState(allEventsUpToLockProcessedChallenge); err != nil {
return err return err
} }
log.Infof("Waiting for events up to lock") log.Infof("Waiting for events up to lock")
atomic.StoreInt64(&this.migrationContext.AllEventsUpToLockProcessedInjectedFlag, 1) atomic.StoreInt64(&this.migrationContext.AllEventsUpToLockProcessedInjectedFlag, 1)
select { for found := false; !found; {
case <-timeout.C: select {
{ case <-timeout.C:
return log.Errorf("Timeout while waiting for events up to lock") {
} return log.Errorf("Timeout while waiting for events up to lock")
case <-this.allEventsUpToLockProcessed: }
{ case state := <-this.allEventsUpToLockProcessed:
log.Infof("Waiting for events up to lock: got allEventsUpToLockProcessed.") {
if state == allEventsUpToLockProcessedChallenge {
log.Infof("Waiting for events up to lock: got %s", state)
found = true
} else {
log.Infof("Waiting for events up to lock: skipping %s", state)
}
}
} }
} }
waitForEventsUpToLockDuration := time.Since(waitForEventsUpToLockStartTime) waitForEventsUpToLockDuration := time.Since(waitForEventsUpToLockStartTime)