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: add recover mechanism for index lookup reader workers #5913

Merged
merged 4 commits into from
Feb 28, 2018
Merged
Changes from 1 commit
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
25 changes: 22 additions & 3 deletions executor/distsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,20 @@ type indexWorker struct {
// fetchHandles fetches a batch of handles from index data and builds the index lookup tasks.
// The tasks are sent to workCh to be further processed by tableWorker, and sent to e.resultCh
// at the same time to keep data ordered.
func (w *indexWorker) fetchHandles(ctx context.Context, result distsql.SelectResult) error {
func (w *indexWorker) fetchHandles(ctx context.Context, result distsql.SelectResult) (err error) {
defer func() {
if r := recover(); r != nil {
err4Panic := errors.Errorf("%v", r)
doneCh := make(chan error, 1)
doneCh <- err4Panic
w.resultCh <- &lookupTableTask{
doneCh: doneCh,
}
if err != nil {
err = errors.Trace(err4Panic)
}
}
}()
chk := chunk.NewChunk([]*types.FieldType{types.NewFieldType(mysql.TypeLonglong)})
for {
handles, err := w.extractTaskHandles(ctx, chk, result)
Expand Down Expand Up @@ -804,12 +817,18 @@ type tableWorker struct {

// pickAndExecTask picks tasks from workCh, and execute them.
func (w *tableWorker) pickAndExecTask(ctx context.Context) {
for {
var task *lookupTableTask
defer func() {
if r := recover(); r != nil {
task.doneCh <- errors.Errorf("%v", r)
}
}()
for ok := true; ok; {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If ok is false, it will return at line 833.

// Don't check ctx.Done() on purpose. If background worker get the signal and all
// exit immediately, session's goroutine doesn't know this and still calling Next(),
// it may block reading task.doneCh forever.
select {
case task, ok := <-w.workCh:
case task, ok = <-w.workCh:
if !ok {
return
}
Expand Down