Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executor: fix data race in the sortexec #52417

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 5 additions & 10 deletions pkg/executor/sortexec/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,11 +440,6 @@ func (e *SortExec) generateResult(waitGroups ...*util.WaitGroupWrapper) {
for i := range e.Parallel.sortedRowsIters {
e.Parallel.sortedRowsIters[i].Reset(nil)
}
if e.Parallel.spillHelper.isSpillTriggered() {
for _, disk := range e.Parallel.spillHelper.sortedRowsInDisk {
disk.Close()
}
}
e.Parallel.merger = nil
close(e.Parallel.resultChannel)
}()
Expand Down Expand Up @@ -669,11 +664,6 @@ func (e *SortExec) fetchChunksParallel(ctx context.Context) error {
// Wait for the finish of chunk fetcher
fetcherWaiter := util.WaitGroupWrapper{}

// Fetch chunks from child and put chunks into chunkChannel
fetcherWaiter.Run(func() {
e.fetchChunksFromChild(ctx)
})

for i := range e.Parallel.workers {
e.Parallel.workers[i] = newParallelSortWorker(i, e.lessRow, e.Parallel.chunkChannel, e.Parallel.fetcherAndWorkerSyncer, e.Parallel.resultChannel, e.finishCh, e.memTracker, e.Parallel.sortedRowsIters[i], e.MaxChunkSize(), e.Parallel.spillHelper)
worker := e.Parallel.workers[i]
Expand All @@ -682,6 +672,11 @@ func (e *SortExec) fetchChunksParallel(ctx context.Context) error {
})
}

// Fetch chunks from child and put chunks into chunkChannel
fetcherWaiter.Run(func() {
e.fetchChunksFromChild(ctx)
})

go e.generateResult(&workersWaiter, &fetcherWaiter)
return nil
}
Expand Down