Skip to content

Commit 1203ea2

Browse files
authored
executor: fix index_hash_join hang when context canceled (#54855) (#55006)
close #54688
1 parent 006254b commit 1203ea2

File tree

5 files changed

+49
-5
lines changed

5 files changed

+49
-5
lines changed

DEPS.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2952,8 +2952,8 @@ def go_deps():
29522952
name = "com_github_pingcap_failpoint",
29532953
build_file_proto_mode = "disable_global",
29542954
importpath = "github.com/pingcap/failpoint",
2955-
sum = "h1:kJolJWbyadVeL8RKBlqmXQR7FRKPsIeU85TUYyhbhiQ=",
2956-
version = "v0.0.0-20220423142525-ae43b7f4e5c3",
2955+
sum = "h1:UgrcL8INjEbPRKE2h8yVgZvjOn2OGkxK9CFvoBWzgbk=",
2956+
version = "v0.0.0-20240527053858-9b3b6e34194a",
29572957
)
29582958
go_repository(
29592959
name = "com_github_pingcap_fn",

executor/index_lookup_hash_join.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ func (iw *indexHashJoinInnerWorker) getNewJoinResult(ctx context.Context) (*inde
561561
select {
562562
case joinResult.chk, ok = <-iw.joinChkResourceCh:
563563
case <-ctx.Done():
564+
joinResult.err = ctx.Err()
564565
return joinResult, false
565566
}
566567
return joinResult, ok
@@ -779,7 +780,10 @@ func (iw *indexHashJoinInnerWorker) joinMatchedInnerRow2Chunk(ctx context.Contex
779780
select {
780781
case iw.resultCh <- joinResult:
781782
case <-ctx.Done():
783+
joinResult.err = ctx.Err()
784+
return false, joinResult
782785
}
786+
failpoint.InjectCall("joinMatchedInnerRow2Chunk")
783787
joinResult, ok = iw.getNewJoinResult(ctx)
784788
if !ok {
785789
return false, joinResult

executor/index_lookup_join_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ import (
1818
"context"
1919
"fmt"
2020
"math/rand"
21+
"runtime"
2122
"strings"
2223
"testing"
2324

2425
"github.com/pingcap/failpoint"
26+
"github.com/pingcap/tidb/session"
2527
"github.com/pingcap/tidb/testkit"
2628
"github.com/stretchr/testify/require"
2729
)
@@ -521,3 +523,41 @@ func TestIssue45716(t *testing.T) {
521523
err := tk.QueryToErr("select /*+ inl_join(t2) */ * from t1 join t2 on t1.a = t2.a;")
522524
tk.MustContainErrMsg(err.Error(), "test inlNewInnerPanic")
523525
}
526+
527+
func TestIssue54688(t *testing.T) {
528+
val := runtime.GOMAXPROCS(1)
529+
defer func() {
530+
runtime.GOMAXPROCS(val)
531+
}()
532+
store := testkit.CreateMockStore(t)
533+
tk := testkit.NewTestKit(t, store)
534+
tk.MustExec("use test;")
535+
tk.MustExec("drop table if exists t, s;")
536+
tk.MustExec("create table t(a int, index(a));")
537+
tk.MustExec("create table s(a int, index(a));")
538+
tk.MustExec("insert into t values(1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11), (12), (13), (14), (15), (16);")
539+
tk.MustExec("insert into s values(1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11), (12), (13), (14), (15), (16);")
540+
tk.MustExec("insert into s select * from s")
541+
tk.MustExec("insert into s select * from s")
542+
tk.MustExec("insert into s select * from s")
543+
tk.MustExec("insert into s select * from s")
544+
tk.MustExec("insert into s select * from s")
545+
tk.MustExec("insert into s select * from s")
546+
tk.MustExec("insert into s select * from s")
547+
tk.MustExec("insert into s select * from s")
548+
tk.MustExec("set @@tidb_index_lookup_join_concurrency=1;")
549+
tk.MustExec("set @@tidb_index_join_batch_size=1000000;")
550+
551+
for i := 0; i <= 100; i++ {
552+
rs, err := tk.Exec("select /*+ INL_HASH_JOIN(s) */ * from t join s on t.a=s.a")
553+
require.NoError(t, err)
554+
context, cancel := context.WithCancel(context.Background())
555+
require.NoError(t, failpoint.EnableCall("github.com/pingcap/tidb/executor/join/joinMatchedInnerRow2Chunk",
556+
func() {
557+
cancel()
558+
},
559+
))
560+
_, _ = session.GetRows4Test(context, nil, rs)
561+
rs.Close()
562+
}
563+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ require (
6969
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2
7070
github.com/pingcap/badger v1.5.1-0.20220314162537-ab58fbf40580
7171
github.com/pingcap/errors v0.11.5-0.20220729040631-518f63d66278
72-
github.com/pingcap/failpoint v0.0.0-20220423142525-ae43b7f4e5c3
72+
github.com/pingcap/failpoint v0.0.0-20240527053858-9b3b6e34194a
7373
github.com/pingcap/fn v0.0.0-20200306044125-d5540d389059
7474
github.com/pingcap/kvproto v0.0.0-20240112060601-a0e3fbb1eeee
7575
github.com/pingcap/log v1.1.1-0.20221116035753-734d527bc87c

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,8 +776,8 @@ github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c/go.mod h1:X2r9ue
776776
github.com/pingcap/errors v0.11.5-0.20220729040631-518f63d66278 h1:3Dm0DWeQlwV8LbpQxP2tojHhxd9aY59KI+QN0ns6bBo=
777777
github.com/pingcap/errors v0.11.5-0.20220729040631-518f63d66278/go.mod h1:X2r9ueLEUZgtx2cIogM0v4Zj5uvvzhuuiu7Pn8HzMPg=
778778
github.com/pingcap/failpoint v0.0.0-20210918120811-547c13e3eb00/go.mod h1:4qGtCB0QK0wBzKtFEGDhxXnSnbQApw1gc9siScUl8ew=
779-
github.com/pingcap/failpoint v0.0.0-20220423142525-ae43b7f4e5c3 h1:kJolJWbyadVeL8RKBlqmXQR7FRKPsIeU85TUYyhbhiQ=
780-
github.com/pingcap/failpoint v0.0.0-20220423142525-ae43b7f4e5c3/go.mod h1:4qGtCB0QK0wBzKtFEGDhxXnSnbQApw1gc9siScUl8ew=
779+
github.com/pingcap/failpoint v0.0.0-20240527053858-9b3b6e34194a h1:UgrcL8INjEbPRKE2h8yVgZvjOn2OGkxK9CFvoBWzgbk=
780+
github.com/pingcap/failpoint v0.0.0-20240527053858-9b3b6e34194a/go.mod h1:gPdo4h708R0CrwKM/DO0/6xJ64fz9vxzp2yKE2QON+s=
781781
github.com/pingcap/fn v0.0.0-20200306044125-d5540d389059 h1:Pe2LbxRmbTfAoKJ65bZLmhahmvHm7n9DUxGRQT00208=
782782
github.com/pingcap/fn v0.0.0-20200306044125-d5540d389059/go.mod h1:fMRU1BA1y+r89AxUoaAar4JjrhUkVDt0o0Np6V8XbDQ=
783783
github.com/pingcap/goleveldb v0.0.0-20191226122134-f82aafb29989 h1:surzm05a8C9dN8dIUmo4Be2+pMRb6f55i+UIYrluu2E=

0 commit comments

Comments
 (0)