Skip to content

Commit

Permalink
mounter: fix the block in WaitPrepare function (pingcap#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
leoppro authored Apr 10, 2020
1 parent 6ef44cc commit f7f9435
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
11 changes: 9 additions & 2 deletions cdc/model/mounter.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

package model

import "context"

// PolymorphicEvent describes a event can be in multiple states
type PolymorphicEvent struct {
Ts uint64
Expand Down Expand Up @@ -52,8 +54,13 @@ func (e *PolymorphicEvent) PrepareFinished() {
}

// WaitPrepare waits for prepare process finished
func (e *PolymorphicEvent) WaitPrepare() {
func (e *PolymorphicEvent) WaitPrepare(ctx context.Context) error {
if e.finished != nil {
<-e.finished
select {
case <-ctx.Done():
return ctx.Err()
case <-e.finished:
}
}
return nil
}
7 changes: 5 additions & 2 deletions cdc/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,11 +550,14 @@ func (p *processor) syncResolved(ctx context.Context) error {
for {
select {
case row := <-p.output:
row.WaitPrepare()
err := row.WaitPrepare(ctx)
if err != nil {
return errors.Trace(err)
}
if row.Row == nil {
continue
}
err := p.sink.EmitRowChangedEvent(ctx, row.Row)
err = p.sink.EmitRowChangedEvent(ctx, row.Row)
if err != nil {
return errors.Trace(err)
}
Expand Down

0 comments on commit f7f9435

Please sign in to comment.