Skip to content

Commit 911125b

Browse files
committed
This is an automated cherry-pick of pingcap#57712
Signed-off-by: ti-chi-bot <[email protected]>
1 parent 7da37ba commit 911125b

File tree

3 files changed

+111
-1
lines changed

3 files changed

+111
-1
lines changed

pkg/statistics/handle/handle_hist.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import (
4141
)
4242

4343
// RetryCount is the max retry count for a sync load task.
44-
const RetryCount = 3
44+
const RetryCount = 2
4545

4646
var globalStatsSyncLoadSingleFlight singleflight.Group
4747

@@ -97,10 +97,22 @@ func (h *Handle) SendLoadRequests(sc *stmtctx.StatementContext, neededHistItems
9797
ResultCh: make(chan stmtctx.StatsLoadResult, 1),
9898
}
9999
select {
100+
<<<<<<< HEAD:pkg/statistics/handle/handle_hist.go
100101
case h.StatsLoad.NeededItemsCh <- task:
101102
result, ok := <-task.ResultCh
102103
intest.Assert(ok, "task.ResultCh cannot be closed")
103104
return result, nil
105+
=======
106+
case s.StatsLoad.NeededItemsCh <- task:
107+
metrics.SyncLoadDedupCounter.Inc()
108+
select {
109+
case <-timer.C:
110+
return nil, errors.New("sync load took too long to return")
111+
case result, ok := <-task.ResultCh:
112+
intest.Assert(ok, "task.ResultCh cannot be closed")
113+
return result, nil
114+
}
115+
>>>>>>> d0de86be941 (statistics: rightly deal with timout when to send sync load (#57712)):pkg/statistics/handle/syncload/stats_syncload.go
104116
case <-timer.C:
105117
return nil, errors.New("sync load stats channel is full and timeout sending task to channel")
106118
}

pkg/statistics/handle/handle_hist_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,3 +343,47 @@ func TestRetry(t *testing.T) {
343343
}
344344
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/statistics/handle/mockReadStatsForOneFail"))
345345
}
346+
347+
func TestSendLoadRequestsWaitTooLong(t *testing.T) {
348+
originConfig := config.GetGlobalConfig()
349+
newConfig := config.NewConfig()
350+
newConfig.Performance.StatsLoadConcurrency = -1 // no worker to consume channel
351+
newConfig.Performance.StatsLoadQueueSize = 10000
352+
config.StoreGlobalConfig(newConfig)
353+
defer config.StoreGlobalConfig(originConfig)
354+
store, dom := testkit.CreateMockStoreAndDomain(t)
355+
356+
tk := testkit.NewTestKit(t, store)
357+
tk.MustExec("use test")
358+
tk.MustExec("create table t(a int, b int, c int, primary key(a), key idx(b,c))")
359+
tk.MustExec("insert into t values (1,1,1),(2,2,2),(3,3,3)")
360+
361+
oriLease := dom.StatsHandle().Lease()
362+
dom.StatsHandle().SetLease(1)
363+
defer func() {
364+
dom.StatsHandle().SetLease(oriLease)
365+
}()
366+
tk.MustExec("analyze table t all columns")
367+
h := dom.StatsHandle()
368+
is := dom.InfoSchema()
369+
tbl, err := is.TableByName(context.Background(), pmodel.NewCIStr("test"), pmodel.NewCIStr("t"))
370+
require.NoError(t, err)
371+
tableInfo := tbl.Meta()
372+
neededColumns := make([]model.StatsLoadItem, 0, len(tableInfo.Columns))
373+
for _, col := range tableInfo.Columns {
374+
neededColumns = append(neededColumns, model.StatsLoadItem{TableItemID: model.TableItemID{TableID: tableInfo.ID, ID: col.ID, IsIndex: false}, FullLoad: true})
375+
}
376+
stmtCtx := stmtctx.NewStmtCtx()
377+
timeout := time.Nanosecond * 100
378+
require.NoError(t, h.SendLoadRequests(stmtCtx, neededColumns, timeout))
379+
for _, resultCh := range stmtCtx.StatsLoad.ResultCh {
380+
rs1 := <-resultCh
381+
require.Error(t, rs1.Err)
382+
}
383+
stmtCtx1 := stmtctx.NewStmtCtx()
384+
require.NoError(t, h.SendLoadRequests(stmtCtx1, neededColumns, timeout))
385+
for _, resultCh := range stmtCtx1.StatsLoad.ResultCh {
386+
rs1 := <-resultCh
387+
require.Error(t, rs1.Err)
388+
}
389+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
2+
3+
go_library(
4+
name = "syncload",
5+
srcs = ["stats_syncload.go"],
6+
importpath = "github.com/pingcap/tidb/pkg/statistics/handle/syncload",
7+
visibility = ["//visibility:public"],
8+
deps = [
9+
"//pkg/config",
10+
"//pkg/infoschema",
11+
"//pkg/kv",
12+
"//pkg/meta/model",
13+
"//pkg/metrics",
14+
"//pkg/parser/mysql",
15+
"//pkg/sessionctx",
16+
"//pkg/sessionctx/stmtctx",
17+
"//pkg/sessionctx/variable",
18+
"//pkg/statistics",
19+
"//pkg/statistics/handle/storage",
20+
"//pkg/statistics/handle/types",
21+
"//pkg/table",
22+
"//pkg/types",
23+
"//pkg/util",
24+
"//pkg/util/intest",
25+
"//pkg/util/logutil",
26+
"@com_github_pingcap_errors//:errors",
27+
"@com_github_pingcap_failpoint//:failpoint",
28+
"@org_golang_x_sync//singleflight",
29+
"@org_uber_go_zap//:zap",
30+
],
31+
)
32+
33+
go_test(
34+
name = "syncload_test",
35+
timeout = "short",
36+
srcs = ["stats_syncload_test.go"],
37+
flaky = True,
38+
race = "on",
39+
shard_count = 7,
40+
deps = [
41+
":syncload",
42+
"//pkg/config",
43+
"//pkg/meta/model",
44+
"//pkg/parser/model",
45+
"//pkg/sessionctx",
46+
"//pkg/sessionctx/stmtctx",
47+
"//pkg/statistics/handle/types",
48+
"//pkg/testkit",
49+
"//pkg/testkit/analyzehelper",
50+
"//pkg/util/mathutil",
51+
"@com_github_pingcap_failpoint//:failpoint",
52+
"@com_github_stretchr_testify//require",
53+
],
54+
)

0 commit comments

Comments
 (0)