Skip to content

Commit

Permalink
statistics: add recover to protect background task (#58739) (#58765)
Browse files Browse the repository at this point in the history
close #58738
  • Loading branch information
ti-chi-bot authored Feb 14, 2025
1 parent eaf7090 commit bf811e4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const (
LabelGCWorker = "gcworker"
LabelAnalyze = "analyze"
LabelWorkerPool = "worker-pool"
LabelStats = "stats"

LabelBatchRecvLoop = "batch-recv-loop"
LabelBatchSendLoop = "batch-send-loop"
Expand Down
2 changes: 2 additions & 0 deletions pkg/statistics/handle/usage/session_stats_collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func (s *statsUsageImpl) needDumpStatsDelta(is infoschema.InfoSchema, dumpAll bo
// DumpStatsDeltaToKV sweeps the whole list and updates the global map, then we dumps every table that held in map to KV.
// If the mode is `DumpDelta`, it will only dump that delta info that `Modify Count / Table Count` greater than a ratio.
func (s *statsUsageImpl) DumpStatsDeltaToKV(dumpAll bool) error {
defer util.Recover(metrics.LabelStats, "DumpStatsDeltaToKV", nil, false)
start := time.Now()
defer func() {
dur := time.Since(start)
Expand Down Expand Up @@ -219,6 +220,7 @@ func (s *statsUsageImpl) dumpTableStatCountToKV(is infoschema.InfoSchema, physic

// DumpColStatsUsageToKV sweeps the whole list, updates the column stats usage map and dumps it to KV.
func (s *statsUsageImpl) DumpColStatsUsageToKV() error {
defer util.Recover(metrics.LabelStats, "DumpColStatsUsageToKV", nil, false)
if !variable.EnableColumnTracking.Load() {
return nil
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/statistics/handle/util/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ go_library(
deps = [
"//pkg/infoschema",
"//pkg/kv",
"//pkg/metrics",
"//pkg/parser/ast",
"//pkg/parser/model",
"//pkg/parser/terror",
Expand All @@ -20,6 +21,7 @@ go_library(
"//pkg/statistics",
"//pkg/table",
"//pkg/types",
"//pkg/util",
"//pkg/util/chunk",
"//pkg/util/intest",
"//pkg/util/sqlexec",
Expand Down
3 changes: 3 additions & 0 deletions pkg/statistics/handle/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ import (
"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
"github.com/pingcap/tidb/pkg/kv"
"github.com/pingcap/tidb/pkg/metrics"
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pingcap/tidb/pkg/parser/terror"
"github.com/pingcap/tidb/pkg/sessionctx"
"github.com/pingcap/tidb/pkg/sessionctx/variable"
"github.com/pingcap/tidb/pkg/util"
"github.com/pingcap/tidb/pkg/util/chunk"
"github.com/pingcap/tidb/pkg/util/intest"
"github.com/pingcap/tidb/pkg/util/sqlexec"
Expand Down Expand Up @@ -83,6 +85,7 @@ var (

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

0 comments on commit bf811e4

Please sign in to comment.