Skip to content

Commit aa81bbc

Browse files
authored
Avoid a data race when dealing with the lowwatermark (#1530)
* Remove error return value since we don't use it. * Lock the mutex whenever we plan to update the low watermark to avoid a race condition. * Check for data races in our unit tests. * Still return an error from ProcessEventsUntilDrained but actually check it in our code. * Make coordinator_test.go to check the err from ProcessEventsUntilDrained again * Remove unreachable return in ProcessEventsUntilDrained
1 parent 5c349ab commit aa81bbc

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

go/logic/coordinator.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,11 @@ func (c *Coordinator) ProcessEventsUntilDrained() error {
377377

378378
switch binlogEvent := ev.Event.(type) {
379379
case *replication.GTIDEvent:
380+
c.mu.Lock()
380381
if c.lowWaterMark == 0 && binlogEvent.SequenceNumber > 0 {
381382
c.lowWaterMark = binlogEvent.SequenceNumber - 1
382383
}
384+
c.mu.Unlock()
383385
case *replication.RotateEvent:
384386
c.currentCoordinatesMutex.Lock()
385387
c.currentCoordinates.LogFile = string(binlogEvent.NextLogName)

go/logic/migrator.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,9 @@ func (this *Migrator) executeWriteFuncs() error {
13191319

13201320
// We give higher priority to event processing.
13211321
// ProcessEventsUntilDrained will process all events in the queue, and then return once no more events are available.
1322-
this.trxCoordinator.ProcessEventsUntilDrained()
1322+
if err := this.trxCoordinator.ProcessEventsUntilDrained(); err != nil {
1323+
return this.migrationContext.Log.Errore(err)
1324+
}
13231325

13241326
this.throttler.throttle(nil)
13251327

script/test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ script/build
1414
cd .gopath/src/github.com/github/gh-ost
1515

1616
echo "Running unit tests"
17-
go test -v -p 1 -covermode=atomic ./go/...
17+
go test -v -p 1 -covermode=atomic -race ./go/...

0 commit comments

Comments
 (0)