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: correctly handle panic for hashjoin build phase (#14056) #14642

Merged
merged 2 commits into from
Feb 5, 2020
Merged
Show file tree
Hide file tree
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
19 changes: 18 additions & 1 deletion executor/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"unsafe"

"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
"github.com/pingcap/parser/terror"
"github.com/pingcap/tidb/expression"
plannercore "github.com/pingcap/tidb/planner/core"
Expand Down Expand Up @@ -281,6 +282,7 @@ func (e *HashJoinExec) fetchInnerRows(ctx context.Context, chkCh chan<- *chunk.C
}
chk := chunk.NewChunkWithCapacity(e.children[e.innerIdx].base().retFieldTypes, e.ctx.GetSessionVars().MaxChunkSize)
err = e.innerExec.Next(ctx, chk)
failpoint.Inject("errorFetchBuildSideRowsMockOOMPanic", nil)
if err != nil {
e.innerFinished <- errors.Trace(err)
return
Expand Down Expand Up @@ -551,7 +553,16 @@ func (e *HashJoinExec) fetchInnerAndBuildHashTable(ctx context.Context) {
// innerResultCh transfers inner chunk from inner fetch to build hash table.
innerResultCh := make(chan *chunk.Chunk, 1)
doneCh := make(chan struct{})
go util.WithRecovery(func() { e.fetchInnerRows(ctx, innerResultCh, doneCh) }, nil)
fetchBuildSideRowsOk := make(chan error, 1)
go util.WithRecovery(
func() { e.fetchInnerRows(ctx, innerResultCh, doneCh) },
func(r interface{}) {
if r != nil {
fetchBuildSideRowsOk <- errors.Errorf("%v", r)
}
close(fetchBuildSideRowsOk)
},
)

// TODO: Parallel build hash table. Currently not support because `mvmap` is not thread-safe.
err := e.buildHashTableForList(innerResultCh)
Expand All @@ -562,6 +573,12 @@ func (e *HashJoinExec) fetchInnerAndBuildHashTable(ctx context.Context) {
// wait fetchInnerRows be finished.
for range innerResultCh {
}
// Check whether err is nil to avoid sending redundant error into innerFinished.
if err == nil {
if err = <-fetchBuildSideRowsOk; err != nil {
e.innerFinished <- err
}
}
}

// buildHashTableForList builds hash table from `list`.
Expand Down
15 changes: 15 additions & 0 deletions executor/seqtest/seq_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,21 @@ func (s *seqTestSuite) TestMaxDeltaSchemaCount(c *C) {
tk.MustQuery("select @@global.tidb_max_delta_schema_count").Check(testkit.Rows("2048"))
}

func (s *seqTestSuite) TestOOMPanicInHashJoinWhenFetchBuildRows(c *C) {
fpName := "github.com/pingcap/tidb/executor/errorFetchBuildSideRowsMockOOMPanic"
c.Assert(failpoint.Enable(fpName, `panic("ERROR 1105 (HY000): Out Of Memory Quota![conn_id=1]")`), IsNil)
defer func() {
c.Assert(failpoint.Disable(fpName), IsNil)
}()
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(c1 int, c2 int)")
tk.MustExec("insert into t values(1,1),(2,2)")
err := tk.QueryToErr("select * from t as t2 join t as t1 where t1.c1=t2.c1")
c.Assert(err.Error(), Equals, "failpoint panic: ERROR 1105 (HY000): Out Of Memory Quota![conn_id=1]")
}

func (s *seqTestSuite) TestBatchDML(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand Down