Skip to content

Commit 23ed0df

Browse files
authored
statistics: add recover to protect background task (#58739)
close #58738
1 parent c199ddf commit 23ed0df

File tree

4 files changed

+6
-0
lines changed

4 files changed

+6
-0
lines changed

pkg/metrics/metrics.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const (
4545
LabelGCWorker = "gcworker"
4646
LabelAnalyze = "analyze"
4747
LabelWorkerPool = "worker-pool"
48+
LabelStats = "stats"
4849

4950
LabelBatchRecvLoop = "batch-recv-loop"
5051
LabelBatchSendLoop = "batch-send-loop"

pkg/statistics/handle/usage/session_stats_collect.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ func (s *statsUsageImpl) needDumpStatsDelta(is infoschema.InfoSchema, dumpAll bo
8585
// DumpStatsDeltaToKV sweeps the whole list and updates the global map, then we dumps every table that held in map to KV.
8686
// If the mode is `DumpDelta`, it will only dump that delta info that `Modify Count / Table Count` greater than a ratio.
8787
func (s *statsUsageImpl) DumpStatsDeltaToKV(dumpAll bool) error {
88+
defer util.Recover(metrics.LabelStats, "DumpStatsDeltaToKV", nil, false)
8889
start := time.Now()
8990
defer func() {
9091
dur := time.Since(start)
@@ -217,6 +218,7 @@ func (s *statsUsageImpl) dumpTableStatCountToKV(is infoschema.InfoSchema, physic
217218

218219
// DumpColStatsUsageToKV sweeps the whole list, updates the column stats usage map and dumps it to KV.
219220
func (s *statsUsageImpl) DumpColStatsUsageToKV() error {
221+
defer util.Recover(metrics.LabelStats, "DumpColStatsUsageToKV", nil, false)
220222
s.SweepSessionStatsList()
221223
colMap := s.SessionStatsUsage().GetUsageAndReset()
222224
defer func() {

pkg/statistics/handle/util/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ go_library(
1515
"//pkg/infoschema",
1616
"//pkg/kv",
1717
"//pkg/meta/model",
18+
"//pkg/metrics",
1819
"//pkg/parser/terror",
1920
"//pkg/planner/core/resolve",
2021
"//pkg/sessionctx",

pkg/statistics/handle/util/util.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/pingcap/failpoint"
2424
"github.com/pingcap/tidb/pkg/kv"
2525
"github.com/pingcap/tidb/pkg/meta/model"
26+
"github.com/pingcap/tidb/pkg/metrics"
2627
"github.com/pingcap/tidb/pkg/parser/terror"
2728
"github.com/pingcap/tidb/pkg/planner/core/resolve"
2829
"github.com/pingcap/tidb/pkg/sessionctx"
@@ -75,6 +76,7 @@ var (
7576

7677
// CallWithSCtx allocates a sctx from the pool and call the f().
7778
func CallWithSCtx(pool util.SessionPool, f func(sctx sessionctx.Context) error, flags ...int) (err error) {
79+
defer util.Recover(metrics.LabelStats, "CallWithSCtx", nil, false)
7880
se, err := pool.Get()
7981
if err != nil {
8082
return err

0 commit comments

Comments
 (0)