Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

statistics: add recover to protect background task (#58739) #58767

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -85,6 +85,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 @@ -224,6 +225,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)
s.SweepSessionStatsList()
colMap := s.SessionStatsUsage().GetUsageAndReset()
defer func() {
Expand Down
1 change: 1 addition & 0 deletions pkg/statistics/handle/util/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ go_library(
"//pkg/infoschema",
"//pkg/kv",
"//pkg/meta/model",
"//pkg/metrics",
"//pkg/parser/terror",
"//pkg/planner/core/resolve",
"//pkg/sessionctx",
Expand Down
2 changes: 2 additions & 0 deletions pkg/statistics/handle/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/pingcap/failpoint"
"github.com/pingcap/tidb/pkg/kv"
"github.com/pingcap/tidb/pkg/meta/model"
"github.com/pingcap/tidb/pkg/metrics"
"github.com/pingcap/tidb/pkg/parser/terror"
"github.com/pingcap/tidb/pkg/planner/core/resolve"
"github.com/pingcap/tidb/pkg/sessionctx"
Expand Down Expand Up @@ -81,6 +82,7 @@ var (

// CallWithSCtx allocates a sctx from the pool and call the f().
func CallWithSCtx(pool util.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