From f894d9b78f68a478c279316959dd93d8b00279f5 Mon Sep 17 00:00:00 2001 From: Yifan Xu <30385241+xuyifangreeneyes@users.noreply.github.com> Date: Tue, 22 Nov 2022 09:33:57 +0800 Subject: [PATCH] domain, executor: refine error log and error handling for statistics and analyze (#39284) --- domain/domain.go | 4 ++-- executor/analyze_global_stats.go | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/domain/domain.go b/domain/domain.go index b900cf3eb8d3a..8c63484730107 100644 --- a/domain/domain.go +++ b/domain/domain.go @@ -1777,7 +1777,7 @@ func (do *Domain) loadStatsWorker() { t := time.Now() err := statsHandle.InitStats(do.InfoSchema()) if err != nil { - logutil.BgLogger().Debug("init stats info failed", zap.Error(err)) + logutil.BgLogger().Error("init stats info failed", zap.Duration("take time", time.Since(t)), zap.Error(err)) } else { logutil.BgLogger().Info("init stats info time", zap.Duration("take time", time.Since(t))) } @@ -1863,7 +1863,7 @@ func (do *Domain) updateStatsWorker(ctx sessionctx.Context, owner owner.Manager) case t := <-statsHandle.DDLEventCh(): err := statsHandle.HandleDDLEvent(t) if err != nil { - logutil.BgLogger().Debug("handle ddl event failed", zap.Error(err)) + logutil.BgLogger().Error("handle ddl event failed", zap.String("event", t.String()), zap.Error(err)) } case <-deltaUpdateTicker.C: err := statsHandle.DumpStatsDeltaToKV(handle.DumpDelta) diff --git a/executor/analyze_global_stats.go b/executor/analyze_global_stats.go index 82c2678953285..961d41dea059d 100644 --- a/executor/analyze_global_stats.go +++ b/executor/analyze_global_stats.go @@ -73,10 +73,10 @@ func (e *AnalyzeExec) handleGlobalStats(ctx context.Context, needGlobalStats boo globalStatsID.tableID, info.isIndex, info.histIDs, tableAllPartitionStats) if err != nil { + logutil.BgLogger().Error("merge global stats failed", zap.String("info", job.JobInfo), zap.Error(err)) if types.ErrPartitionStatsMissing.Equal(err) || types.ErrPartitionColumnStatsMissing.Equal(err) { // When we find some partition-level stats are missing, we need to report warning. e.ctx.GetSessionVars().StmtCtx.AppendWarning(err) - return nil } return err } @@ -95,14 +95,14 @@ func (e *AnalyzeExec) handleGlobalStats(ctx context.Context, needGlobalStats boo true, ) if err != nil { - logutil.Logger(ctx).Error("save global-level stats to storage failed", zap.Error(err)) + logutil.Logger(ctx).Error("save global-level stats to storage failed", zap.String("info", job.JobInfo), zap.Int64("histID", hg.ID), zap.Error(err)) } // Dump stats to historical storage. - if err := recordHistoricalStats(e.ctx, globalStatsID.tableID); err != nil { - logutil.BgLogger().Error("record historical stats failed", zap.Error(err)) + if err1 := recordHistoricalStats(e.ctx, globalStatsID.tableID); err1 != nil { + logutil.BgLogger().Error("record historical stats failed", zap.String("info", job.JobInfo), zap.Int64("histID", hg.ID), zap.Error(err1)) } } - return nil + return err }() FinishAnalyzeMergeJob(e.ctx, job, mergeStatsErr) }