Skip to content

Commit 1d198e6

Browse files
authored
statistics: add recover to protect background task (#58739) (#58767)
close #58738
1 parent ea99941 commit 1d198e6

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)
@@ -224,6 +225,7 @@ func (s *statsUsageImpl) dumpTableStatCountToKV(is infoschema.InfoSchema, physic
224225

225226
// DumpColStatsUsageToKV sweeps the whole list, updates the column stats usage map and dumps it to KV.
226227
func (s *statsUsageImpl) DumpColStatsUsageToKV() error {
228+
defer util.Recover(metrics.LabelStats, "DumpColStatsUsageToKV", nil, false)
227229
s.SweepSessionStatsList()
228230
colMap := s.SessionStatsUsage().GetUsageAndReset()
229231
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
@@ -25,6 +25,7 @@ import (
2525
"github.com/pingcap/failpoint"
2626
"github.com/pingcap/tidb/pkg/kv"
2727
"github.com/pingcap/tidb/pkg/meta/model"
28+
"github.com/pingcap/tidb/pkg/metrics"
2829
"github.com/pingcap/tidb/pkg/parser/terror"
2930
"github.com/pingcap/tidb/pkg/planner/core/resolve"
3031
"github.com/pingcap/tidb/pkg/sessionctx"
@@ -81,6 +82,7 @@ var (
8182

8283
// CallWithSCtx allocates a sctx from the pool and call the f().
8384
func CallWithSCtx(pool util.SessionPool, f func(sctx sessionctx.Context) error, flags ...int) (err error) {
85+
defer util.Recover(metrics.LabelStats, "CallWithSCtx", nil, false)
8486
se, err := pool.Get()
8587
if err != nil {
8688
return err

0 commit comments

Comments
 (0)