Skip to content

Commit 4149fa0

Browse files
committed
This is an automated cherry-pick of pingcap#57282
Signed-off-by: ti-chi-bot <[email protected]> resolve conflict Signed-off-by: you06 <[email protected]> fix pr Signed-off-by: you06 <[email protected]>
1 parent c17c0df commit 4149fa0

File tree

7 files changed

+97
-11
lines changed

7 files changed

+97
-11
lines changed

DEPS.bzl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7041,13 +7041,13 @@ def go_deps():
70417041
name = "com_github_tikv_client_go_v2",
70427042
build_file_proto_mode = "disable_global",
70437043
importpath = "github.com/tikv/client-go/v2",
7044-
sha256 = "00c96385cb29901a20d4da163038eb5f5e554fca2ec9775f2b87f56a79252d47",
7045-
strip_prefix = "github.com/tikv/client-go/[email protected].20240920100427-3725b31fa3c0",
7044+
sha256 = "ec8fd9b0cdf1352758305c7bb2107d2d5a6782937853ecd2e76a561a4f054b40",
7045+
strip_prefix = "github.com/tikv/client-go/[email protected].20241125064441-5ce6bf1f099c",
70467046
urls = [
7047-
"http://bazel-cache.pingcap.net:8080/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20240920100427-3725b31fa3c0.zip",
7048-
"http://ats.apps.svc/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20240920100427-3725b31fa3c0.zip",
7049-
"https://cache.hawkingrei.com/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20240920100427-3725b31fa3c0.zip",
7050-
"https://storage.googleapis.com/pingcapmirror/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20240920100427-3725b31fa3c0.zip",
7047+
"http://bazel-cache.pingcap.net:8080/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20241125064441-5ce6bf1f099c.zip",
7048+
"http://ats.apps.svc/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20241125064441-5ce6bf1f099c.zip",
7049+
"https://cache.hawkingrei.com/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20241125064441-5ce6bf1f099c.zip",
7050+
"https://storage.googleapis.com/pingcapmirror/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20241125064441-5ce6bf1f099c.zip",
70517051
],
70527052
)
70537053
go_repository(

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ require (
104104
github.com/stretchr/testify v1.9.0
105105
github.com/tdakkota/asciicheck v0.2.0
106106
github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2
107-
github.com/tikv/client-go/v2 v2.0.8-0.20240920100427-3725b31fa3c0
107+
github.com/tikv/client-go/v2 v2.0.8-0.20241125064441-5ce6bf1f099c
108108
github.com/tikv/pd/client v0.0.0-20240724132535-fcb34c90790c
109109
github.com/timakin/bodyclose v0.0.0-20230421092635-574207250966
110110
github.com/twmb/murmur3 v1.1.6

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -997,8 +997,8 @@ github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2 h1:mbAskLJ0oJf
997997
github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2/go.mod h1:2PfKggNGDuadAa0LElHrByyrz4JPZ9fFx6Gs7nx7ZZU=
998998
github.com/tiancaiamao/gp v0.0.0-20221230034425-4025bc8a4d4a h1:J/YdBZ46WKpXsxsW93SG+q0F8KI+yFrcIDT4c/RNoc4=
999999
github.com/tiancaiamao/gp v0.0.0-20221230034425-4025bc8a4d4a/go.mod h1:h4xBhSNtOeEosLJ4P7JyKXX7Cabg7AVkWCK5gV2vOrM=
1000-
github.com/tikv/client-go/v2 v2.0.8-0.20240920100427-3725b31fa3c0 h1:fRrgcL5JMtirxL+gp2/+pB6x1CkAb3kbaI7lnQU7NGI=
1001-
github.com/tikv/client-go/v2 v2.0.8-0.20240920100427-3725b31fa3c0/go.mod h1:37p0ryKaieJbBpVDWnaPi2ZS6UFqkgpsemBLkGX2FvM=
1000+
github.com/tikv/client-go/v2 v2.0.8-0.20241125064441-5ce6bf1f099c h1:c5/4ODu6lcuueN7lUtIyHrGeWLCHVZpAbrfFoNfP+UI=
1001+
github.com/tikv/client-go/v2 v2.0.8-0.20241125064441-5ce6bf1f099c/go.mod h1:37p0ryKaieJbBpVDWnaPi2ZS6UFqkgpsemBLkGX2FvM=
10021002
github.com/tikv/pd/client v0.0.0-20240724132535-fcb34c90790c h1:oZygf/SCdTUhjoHuZRE85EBgK0oA6LjikpWuJqqjM8U=
10031003
github.com/tikv/pd/client v0.0.0-20240724132535-fcb34c90790c/go.mod h1:NW6Af689Jw1FDxjq+WL0nqOdmQ1XT0ly2R1SIKfQuUw=
10041004
github.com/timakin/bodyclose v0.0.0-20230421092635-574207250966 h1:quvGphlmUVU+nhpFa4gg4yJyTRJ13reZMDHrKwYw53M=

pkg/executor/adapter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ func (a *ExecStmt) handleStmtForeignKeyTrigger(ctx context.Context, e exec.Execu
612612
if stmtCtx.ForeignKeyTriggerCtx.HasFKCascades {
613613
// If the ExecStmt has foreign key cascade to be executed, we need call `StmtCommit` to commit the ExecStmt itself
614614
// change first.
615-
// Since `UnionScanExec` use `SnapshotIter` and `SnapshotGetter` to read txn mem-buffer, if we don't do `StmtCommit`,
615+
// Since `UnionScanExec` use `SnapshotIter` and `SnapshotGetter` to read txn mem-buffer, if we don't do `StmtCommit`,
616616
// then the fk cascade executor can't read the mem-buffer changed by the ExecStmt.
617617
a.Ctx.StmtCommit(ctx)
618618
}

pkg/executor/union_scan_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,21 @@ func TestIssue32422(t *testing.T) {
343343
tk.MustExec("rollback")
344344
}
345345

346+
func TestSnapshotWithConcurrentWrite(t *testing.T) {
347+
store := testkit.CreateMockStore(t)
348+
tk := testkit.NewTestKit(t, store)
349+
tk.MustExec("use test")
350+
tk.MustExec("create table t1 (id int auto_increment key, b int, index(b));")
351+
352+
tk.MustExec("begin")
353+
tk.MustExec("insert into t1 (b) values (1),(2),(3),(4),(5),(6),(7),(8);")
354+
for j := 0; j < 16; j++ {
355+
tk.MustExec("insert into t1 (b) select /*+ use_index(t1, b) */ id from t1;")
356+
}
357+
tk.MustQuery("select count(1) from t1").Check(testkit.Rows("524288")) // 8 * 2^16 rows
358+
tk.MustExec("rollback")
359+
}
360+
346361
func BenchmarkUnionScanRead(b *testing.B) {
347362
store := testkit.CreateMockStore(b)
348363

pkg/session/test/txn/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ go_test(
99
],
1010
flaky = True,
1111
race = "on",
12-
shard_count = 11,
12+
shard_count = 13,
1313
deps = [
1414
"//pkg/config",
1515
"//pkg/kv",

pkg/session/test/txn/txn_test.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,3 +629,74 @@ func TestCommitRetryCount(t *testing.T) {
629629
// No auto retry because retry limit is set to 0.
630630
require.Error(t, tk1.ExecToErr("commit"))
631631
}
632+
633+
func TestMemBufferSnapshotRead(t *testing.T) {
634+
store := testkit.CreateMockStore(t)
635+
636+
tk := testkit.NewTestKit(t, store)
637+
tk.MustExec("use test")
638+
639+
tk.MustExec("drop table if exists t;")
640+
tk.MustExec("create table t(a int primary key, b int, index i(b));")
641+
642+
tk.MustExec("set session tidb_distsql_scan_concurrency = 1;")
643+
tk.MustExec("set session tidb_index_lookup_join_concurrency = 1;")
644+
tk.MustExec("set session tidb_projection_concurrency=1;")
645+
tk.MustExec("set session tidb_init_chunk_size=1;")
646+
tk.MustExec("set session tidb_max_chunk_size=40;")
647+
tk.MustExec("set session tidb_index_join_batch_size = 10")
648+
649+
tk.MustExec("begin;")
650+
// write (0, 0), (1, 1), ... ,(100, 100) into membuffer
651+
var sb strings.Builder
652+
sb.WriteString("insert into t values ")
653+
for i := 0; i <= 100; i++ {
654+
if i > 0 {
655+
sb.WriteString(", ")
656+
}
657+
sb.WriteString(fmt.Sprintf("(%d, %d)", i, i))
658+
}
659+
tk.MustExec(sb.String())
660+
661+
// insert on duplicate key statement should update the table to (0, 100), (1, 99), ... (100, 0)
662+
// This statement will create UnionScan dynamically during execution, and some UnionScan will see staging data(should be bypassed),
663+
// so it relies on correct snapshot read to get the expected result.
664+
tk.MustExec("insert into t (select /*+ INL_JOIN(t1) */ 100 - t1.a as a, t1.b from t t1, (select a, b from t) t2 where t1.b = t2.b) on duplicate key update b = values(b)")
665+
666+
require.Empty(t, tk.MustQuery("select a, b from t where a + b != 100;").Rows())
667+
tk.MustExec("commit;")
668+
require.Empty(t, tk.MustQuery("select a, b from t where a + b != 100;").Rows())
669+
670+
tk.MustExec("set session tidb_distsql_scan_concurrency = default;")
671+
tk.MustExec("set session tidb_index_lookup_join_concurrency = default;")
672+
tk.MustExec("set session tidb_projection_concurrency=default;")
673+
tk.MustExec("set session tidb_init_chunk_size=default;")
674+
tk.MustExec("set session tidb_max_chunk_size=default;")
675+
tk.MustExec("set session tidb_index_join_batch_size = default")
676+
}
677+
678+
func TestMemBufferCleanupMemoryLeak(t *testing.T) {
679+
// Test if cleanup memory will cause a memory leak.
680+
// When an in-txn statement fails, TiDB cleans up the mutations from this statement.
681+
// If there's a memory leak, the memory usage could increase uncontrollably with retries.
682+
store := testkit.CreateMockStore(t)
683+
tk := testkit.NewTestKit(t, store)
684+
tk.MustExec("use test")
685+
tk.MustExec("create table t(a varchar(255) primary key)")
686+
key1 := strings.Repeat("a", 255)
687+
key2 := strings.Repeat("b", 255)
688+
tk.MustExec(`set global tidb_mem_oom_action='cancel'`)
689+
tk.MustExec("set session tidb_mem_quota_query=10240")
690+
tk.MustExec("begin")
691+
tk.MustExec("insert into t values(?)", key2)
692+
for i := 0; i < 100; i++ {
693+
// The insert statement will fail because of the duplicate key error.
694+
err := tk.ExecToErr("insert into t values(?), (?)", key1, key2)
695+
require.Error(t, err)
696+
if strings.Contains(err.Error(), "Duplicate") {
697+
continue
698+
}
699+
require.NoError(t, err)
700+
}
701+
tk.MustExec("commit")
702+
}

0 commit comments

Comments
 (0)