Skip to content

Commit

Permalink
kvclient(ticdc): fix the workerpool data race (#10195)
Browse files Browse the repository at this point in the history
close #10095
  • Loading branch information
3AceShowHand authored Nov 30, 2023
1 parent 197057b commit 6c1515c
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cdc/kv/region_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
var (
regionWorkerPool workerpool.WorkerPool
workerPoolOnce sync.Once
workerPoolLock sync.Mutex
// The magic number here is keep the same with some magic numbers in some
// other components in TiCDC, including worker pool task chan size, mounter
// chan size etc.
Expand Down Expand Up @@ -402,6 +403,8 @@ func (w *regionWorker) processEvent(ctx context.Context, event *regionStatefulEv

func (w *regionWorker) initPoolHandles() {
handles := make([]workerpool.EventHandle, 0, w.concurrency)
workerPoolLock.Lock()
defer workerPoolLock.Unlock()
for i := 0; i < w.concurrency; i++ {
poolHandle := regionWorkerPool.RegisterEvent(func(ctx context.Context, eventI interface{}) error {
event := eventI.(*regionStatefulEvent)
Expand Down Expand Up @@ -858,6 +861,8 @@ func getWorkerPoolSize() (size int) {
func InitWorkerPool() {
workerPoolOnce.Do(func() {
size := getWorkerPoolSize()
workerPoolLock.Lock()
defer workerPoolLock.Unlock()
regionWorkerPool = workerpool.NewDefaultWorkerPool(size)
})
}
Expand Down

0 comments on commit 6c1515c

Please sign in to comment.