Skip to content

Commit 6a6df40

Browse files
authored
executor: replace Call with CallWithRecover in the close of hash join v1 (#61868) (#62341)
close #60926
1 parent 9cf87ba commit 6a6df40

File tree

4 files changed

+42
-4
lines changed

4 files changed

+42
-4
lines changed

pkg/executor/hash_table.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"unsafe"
2424

2525
"github.com/pingcap/errors"
26+
"github.com/pingcap/failpoint"
2627
"github.com/pingcap/tidb/pkg/sessionctx"
2728
"github.com/pingcap/tidb/pkg/sessionctx/stmtctx"
2829
"github.com/pingcap/tidb/pkg/types"
@@ -546,6 +547,8 @@ func (c *hashRowContainer) Len() uint64 {
546547
}
547548

548549
func (c *hashRowContainer) Close() error {
550+
failpoint.Inject("issue60926", nil)
551+
549552
defer c.memTracker.Detach()
550553
c.chkBuf = nil
551554
return c.rowContainer.Close()

pkg/executor/join.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,14 @@ import (
4242
"github.com/pingcap/tidb/pkg/util/dbterror/exeerrors"
4343
"github.com/pingcap/tidb/pkg/util/disk"
4444
"github.com/pingcap/tidb/pkg/util/execdetails"
45+
"github.com/pingcap/tidb/pkg/util/logutil"
4546
"github.com/pingcap/tidb/pkg/util/memory"
47+
"go.uber.org/zap"
4648
)
4749

50+
// IsChildCloseCalledForTest is used for test
51+
var IsChildCloseCalledForTest atomic.Bool
52+
4853
var (
4954
_ exec.Executor = &HashJoinExec{}
5055
_ exec.Executor = &NestedLoopApplyExec{}
@@ -175,7 +180,14 @@ func (e *HashJoinExec) Close() error {
175180
channel.Clear(e.probeWorkers[i].joinChkResourceCh)
176181
}
177182
e.probeSideTupleFetcher.probeChkResourceCh = nil
178-
terror.Call(e.rowContainer.Close)
183+
util.WithRecovery(func() {
184+
err := e.rowContainer.Close()
185+
if err != nil {
186+
logutil.BgLogger().Error("RowContainer encounters error",
187+
zap.Error(err),
188+
zap.Stack("stack trace"))
189+
}
190+
}, nil)
179191
e.hashJoinCtx.sessCtx.GetSessionVars().MemTracker.UnbindActionFromHardLimit(e.rowContainer.ActionSpill())
180192
e.waiterWg.Wait()
181193
}
@@ -196,8 +208,9 @@ func (e *HashJoinExec) Close() error {
196208
if e.stats != nil {
197209
defer e.Ctx().GetSessionVars().StmtCtx.RuntimeStatsColl.RegisterStats(e.ID(), e.stats)
198210
}
199-
err := e.BaseExecutor.Close()
200-
return err
211+
212+
IsChildCloseCalledForTest.Store(true)
213+
return e.BaseExecutor.Close()
201214
}
202215

203216
// Open implements the Executor Open interface.

pkg/executor/test/issuetest/BUILD.bazel

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@ go_test(
88
"main_test.go",
99
],
1010
flaky = True,
11-
shard_count = 22,
11+
shard_count = 23,
1212
deps = [
1313
"//pkg/autoid_service",
1414
"//pkg/config",
15+
"//pkg/executor",
1516
"//pkg/kv",
1617
"//pkg/meta/autoid",
1718
"//pkg/parser/auth",
1819
"//pkg/parser/charset",
1920
"//pkg/parser/mysql",
2021
"//pkg/session/types",
2122
"//pkg/testkit",
23+
"//pkg/testkit/testfailpoint",
2224
"//pkg/util",
2325
"//pkg/util/dbterror/exeerrors",
2426
"//pkg/util/memory",

pkg/executor/test/issuetest/executor_issue_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ import (
2424
"github.com/pingcap/failpoint"
2525
_ "github.com/pingcap/tidb/pkg/autoid_service"
2626
"github.com/pingcap/tidb/pkg/config"
27+
"github.com/pingcap/tidb/pkg/executor"
2728
"github.com/pingcap/tidb/pkg/kv"
2829
"github.com/pingcap/tidb/pkg/parser/auth"
2930
"github.com/pingcap/tidb/pkg/parser/charset"
3031
"github.com/pingcap/tidb/pkg/parser/mysql"
3132
sessiontypes "github.com/pingcap/tidb/pkg/session/types"
3233
"github.com/pingcap/tidb/pkg/testkit"
34+
"github.com/pingcap/tidb/pkg/testkit/testfailpoint"
3335
"github.com/pingcap/tidb/pkg/util"
3436
"github.com/pingcap/tidb/pkg/util/dbterror/exeerrors"
3537
"github.com/pingcap/tidb/pkg/util/memory"
@@ -712,3 +714,21 @@ func TestIssue55881(t *testing.T) {
712714
"(select max(value) from (select * from cte union all select * from cte union all select * from aaa where aaa.id > bbb.id)) from bbb;")
713715
}
714716
}
717+
718+
func TestIssue60926(t *testing.T) {
719+
store := testkit.CreateMockStore(t)
720+
tk := testkit.NewTestKit(t, store)
721+
722+
tk.MustExec("use test")
723+
tk.MustExec("drop table if exists t1")
724+
tk.MustExec("drop table if exists t2")
725+
tk.MustExec("create table t1 (col0 int, col1 int);")
726+
tk.MustExec("create table t2 (col0 int, col1 int);")
727+
tk.MustExec("insert into t1 values (0, 10), (1, 10), (2, 10), (3, 10), (4, 10), (5, 10), (6, 10), (7, 10), (8, 10), (9, 10), (10, 10);")
728+
tk.MustExec("insert into t2 values (0, 5), (0, 5), (1, 5), (2, 5), (2, 5), (3, 5), (4, 5), (5, 5), (5, 5), (6, 5), (7, 5), (8, 5), (8, 5), (9, 5), (9, 5), (10, 5);")
729+
730+
testfailpoint.Enable(t, "github.com/pingcap/tidb/pkg/executor/join/issue60926", "panic")
731+
executor.IsChildCloseCalledForTest.Store(false)
732+
tk.MustQuery("select * from t1 join (select col0, sum(col1) from t2 group by col0) as r on t1.col0 = r.col0;")
733+
require.True(t, executor.IsChildCloseCalledForTest.Load())
734+
}

0 commit comments

Comments
 (0)