[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
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 hang in hash agg when exceeding memory limit leads to panic (#57641) #57696

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions pkg/executor/aggregate/agg_hash_partial_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,16 @@ type HashAggPartialWorker struct {
inflightChunkSync *sync.WaitGroup
}

func (w *HashAggPartialWorker) getChildInput() bool {
func (w *HashAggPartialWorker) getChildInput() (*chunk.Chunk, bool) {
select {
case <-w.finishCh:
return false
return nil, false
case chk, ok := <-w.inputCh:
if !ok {
return false
}

sizeBefore := w.chk.MemoryUsage()
w.chk.SwapColumns(chk)
w.memTracker.Consume(w.chk.MemoryUsage() - sizeBefore)

w.giveBackCh <- &HashAggInput{
chk: chk,
giveBackCh: w.inputCh,
return nil, false
}
return chk, true
}
return true
}

func (w *HashAggPartialWorker) fetchChunkAndProcess(ctx sessionctx.Context, hasError *bool, needShuffle *bool) bool {
Expand All @@ -99,14 +90,24 @@ func (w *HashAggPartialWorker) fetchChunkAndProcess(ctx sessionctx.Context, hasE
}

waitStart := time.Now()
ok := w.getChildInput()
updateWaitTime(w.stats, waitStart)

chk, ok := w.getChildInput()
if !ok {
return false
}

defer w.inflightChunkSync.Done()
updateWaitTime(w.stats, waitStart)

w.intestDuringPartialWorkerRun()

sizeBefore := w.chk.MemoryUsage()
w.chk.SwapColumns(chk)
w.memTracker.Consume(w.chk.MemoryUsage() - sizeBefore)

w.giveBackCh <- &HashAggInput{
chk: chk,
giveBackCh: w.inputCh,
}

execStart := time.Now()
if err := w.updatePartialResult(ctx, w.chk, len(w.partialResultsMap)); err != nil {
Expand Down