Skip to content

Commit

Permalink
ddl: implement backoff strategy for async event notification in tests (
Browse files Browse the repository at this point in the history
  • Loading branch information
Rustin170506 committed Dec 20, 2024
1 parent 06f72a4 commit 1a1b1a9
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/ddl/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,19 @@ func asyncNotifyEvent(jobCtx *jobContext, e *notifier.SchemaChangeEvent, job *mo
if intest.InTest {
ch := jobCtx.oldDDLCtx.ddlEventCh
if ch != nil {
ch <- e
forLoop:
// Try sending the event to the channel with a backoff strategy to avoid blocking indefinitely.
// Since most unit tests don't consume events, we make a few attempts and then give up rather
// than blocking the DDL job forever on a full channel.
for i := 0; i < 10; i++ {
select {
case ch <- e:
break forLoop
default:
time.Sleep(time.Microsecond * 10)
}
}
logutil.DDLLogger().Warn("fail to notify DDL event", zap.Stringer("event", e))
}
}

Expand Down

0 comments on commit 1a1b1a9

Please sign in to comment.