diff --git a/pkg/metrics/metrics.go b/pkg/metrics/metrics.go index 66057f49785d6..4338b186de0d8 100644 --- a/pkg/metrics/metrics.go +++ b/pkg/metrics/metrics.go @@ -45,6 +45,7 @@ const ( LabelGCWorker = "gcworker" LabelAnalyze = "analyze" LabelWorkerPool = "worker-pool" + LabelStats = "stats" LabelBatchRecvLoop = "batch-recv-loop" LabelBatchSendLoop = "batch-send-loop" diff --git a/pkg/statistics/handle/usage/session_stats_collect.go b/pkg/statistics/handle/usage/session_stats_collect.go index d5a7b74650adc..648c9b5ccbc5c 100644 --- a/pkg/statistics/handle/usage/session_stats_collect.go +++ b/pkg/statistics/handle/usage/session_stats_collect.go @@ -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) @@ -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 } diff --git a/pkg/statistics/handle/util/BUILD.bazel b/pkg/statistics/handle/util/BUILD.bazel index a44568c1ee099..bd94c41418cd5 100644 --- a/pkg/statistics/handle/util/BUILD.bazel +++ b/pkg/statistics/handle/util/BUILD.bazel @@ -12,6 +12,7 @@ go_library( deps = [ "//pkg/infoschema", "//pkg/kv", + "//pkg/metrics", "//pkg/parser/ast", "//pkg/parser/model", "//pkg/parser/terror", @@ -20,6 +21,7 @@ go_library( "//pkg/statistics", "//pkg/table", "//pkg/types", + "//pkg/util", "//pkg/util/chunk", "//pkg/util/intest", "//pkg/util/sqlexec", diff --git a/pkg/statistics/handle/util/util.go b/pkg/statistics/handle/util/util.go index f76d963359ac0..f85710420f515 100644 --- a/pkg/statistics/handle/util/util.go +++ b/pkg/statistics/handle/util/util.go @@ -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" @@ -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