Skip to content

Commit bc52b7b

Browse files
xzhangxian1008ti-chi-bot
authored andcommitted
This is an automated cherry-pick of pingcap#61868
Signed-off-by: ti-chi-bot <[email protected]>
1 parent d5856a6 commit bc52b7b

File tree

4 files changed

+65
-1
lines changed

4 files changed

+65
-1
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("issue60923", nil)
551+
549552
defer c.memTracker.Detach()
550553
c.chkBuf = nil
551554
return c.rowContainer.Close()

pkg/executor/join.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ import (
4545
"github.com/pingcap/tidb/pkg/util/memory"
4646
)
4747

48+
// IsChildCloseCalledForTest is used for test
49+
var IsChildCloseCalledForTest = false
50+
4851
var (
4952
_ exec.Executor = &HashJoinExec{}
5053
_ exec.Executor = &NestedLoopApplyExec{}
@@ -151,7 +154,11 @@ type hashjoinWorkerResult struct {
151154
}
152155

153156
// Close implements the Executor Close interface.
157+
<<<<<<< HEAD:pkg/executor/join.go
154158
func (e *HashJoinExec) Close() error {
159+
=======
160+
func (e *HashJoinV1Exec) Close() (err error) {
161+
>>>>>>> af367b8a5ae (executor: replace `Call` with `CallWithRecover` in the close of hash join v1 (#61868)):pkg/executor/join/hash_join_v1.go
155162
if e.closeCh != nil {
156163
close(e.closeCh)
157164
}
@@ -174,9 +181,19 @@ func (e *HashJoinExec) Close() error {
174181
close(e.probeWorkers[i].joinChkResourceCh)
175182
channel.Clear(e.probeWorkers[i].joinChkResourceCh)
176183
}
184+
<<<<<<< HEAD:pkg/executor/join.go
177185
e.probeSideTupleFetcher.probeChkResourceCh = nil
178186
terror.Call(e.rowContainer.Close)
179187
e.hashJoinCtx.sessCtx.GetSessionVars().MemTracker.UnbindActionFromHardLimit(e.rowContainer.ActionSpill())
188+
=======
189+
e.ProbeSideTupleFetcher.probeChkResourceCh = nil
190+
util.WithRecovery(func() { err = e.RowContainer.Close() }, func(r any) {
191+
if r != nil {
192+
err = errors.Errorf("%v", r)
193+
}
194+
})
195+
e.HashJoinCtxV1.SessCtx.GetSessionVars().MemTracker.UnbindActionFromHardLimit(e.RowContainer.ActionSpill())
196+
>>>>>>> af367b8a5ae (executor: replace `Call` with `CallWithRecover` in the close of hash join v1 (#61868)):pkg/executor/join/hash_join_v1.go
180197
e.waiterWg.Wait()
181198
}
182199
e.outerMatchedStatus = e.outerMatchedStatus[:0]
@@ -196,7 +213,12 @@ func (e *HashJoinExec) Close() error {
196213
if e.stats != nil {
197214
defer e.Ctx().GetSessionVars().StmtCtx.RuntimeStatsColl.RegisterStats(e.ID(), e.stats)
198215
}
199-
err := e.BaseExecutor.Close()
216+
217+
IsChildCloseCalledForTest = true
218+
childErr := e.BaseExecutor.Close()
219+
if childErr != nil {
220+
return childErr
221+
}
200222
return err
201223
}
202224

pkg/executor/test/issuetest/BUILD.bazel

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ go_test(
88
"main_test.go",
99
],
1010
flaky = True,
11+
<<<<<<< HEAD
1112
shard_count = 22,
13+
=======
14+
shard_count = 25,
15+
>>>>>>> af367b8a5ae (executor: replace `Call` with `CallWithRecover` in the close of hash join v1 (#61868))
1216
deps = [
1317
"//pkg/autoid_service",
1418
"//pkg/config",
@@ -19,6 +23,7 @@ go_test(
1923
"//pkg/parser/mysql",
2024
"//pkg/session/types",
2125
"//pkg/testkit",
26+
"//pkg/testkit/testfailpoint",
2227
"//pkg/util",
2328
"//pkg/util/dbterror/exeerrors",
2429
"//pkg/util/memory",

pkg/executor/test/issuetest/executor_issue_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package issuetest_test
1616

1717
import (
18+
"context"
1819
"fmt"
1920
"math/rand"
2021
"strings"
@@ -30,6 +31,7 @@ import (
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,35 @@ 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 TestIssue60923(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/issue60923", "panic")
731+
tk.MustExec("set tidb_hash_join_version=legacy")
732+
733+
ctx := context.Background()
734+
join.IsChildCloseCalledForTest = false
735+
rs, _ := tk.ExecWithContext(context.Background(), "select * from t1 join (select col0, sum(col1) from t2 group by col0) as r on t1.col0 = r.col0;")
736+
req := rs.NewChunk(nil)
737+
for {
738+
err := rs.Next(ctx, req)
739+
require.NoError(t, err)
740+
if req.NumRows() == 0 {
741+
break
742+
}
743+
}
744+
if rs != nil {
745+
require.Error(t, rs.Close())
746+
}
747+
require.True(t, join.IsChildCloseCalledForTest)
748+
}

0 commit comments

Comments
 (0)