Skip to content

Commit

Permalink
add log and add a threshold for it
Browse files Browse the repository at this point in the history
  • Loading branch information
winoros committed Jan 8, 2025
1 parent 6ed37c0 commit 1b1cbad
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions pkg/statistics/handle/cache/statscache.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ func (s *StatsCacheImpl) Update(ctx context.Context, is infoschema.InfoSchema, t
onlyMetaUpdate := 0
histAlsoUpdate := 0
histUpdatedNum := 0
skipped := 0
errorContinued := 0
deleted := 0
tblToUpdateOrDelete := newCacheOfBatchUpdate(batchSizeOfUpdateBatch, func(toUpdate []*statistics.Table, toDelete []int64) {
s.UpdateStatsCache(types.CacheUpdate{
Updated: toUpdate,
Expand Down Expand Up @@ -198,6 +201,7 @@ func (s *StatsCacheImpl) Update(ctx context.Context, is infoschema.InfoSchema, t
)
noTableMetaNum++
tblToUpdateOrDelete.addToDelete(physicalID)
deleted++
continue
}
tableInfo := table.Meta()
Expand All @@ -206,6 +210,7 @@ func (s *StatsCacheImpl) Update(ctx context.Context, is infoschema.InfoSchema, t
if ok &&
oldTbl.Version >= version &&
tableInfo.UpdateTS == oldTbl.TblInfoUpdateTS {
skipped++
continue
}
if !ok {
Expand All @@ -224,6 +229,7 @@ func (s *StatsCacheImpl) Update(ctx context.Context, is infoschema.InfoSchema, t
if tbl.LastAnalyzeVersion == 0 && snapshot != 0 {
tbl.LastAnalyzeVersion = snapshot
}
errorContinued++
continue
}
var tbl *statistics.Table
Expand Down Expand Up @@ -253,10 +259,12 @@ func (s *StatsCacheImpl) Update(ctx context.Context, is infoschema.InfoSchema, t
zap.String("table", tableInfo.Name.O),
zap.Error(err),
)
errorContinued++
continue
}
if tbl == nil {
tblToUpdateOrDelete.addToDelete(physicalID)
deleted++
continue
}
histAlsoUpdate++
Expand All @@ -283,18 +291,23 @@ func (s *StatsCacheImpl) Update(ctx context.Context, is infoschema.InfoSchema, t
tblToUpdateOrDelete.flush()
dur := time.Since(start)
tidbmetrics.StatsDeltaLoadHistogram.Observe(dur.Seconds())
logutil.BgLogger().Info("update stats cache",
zap.Float64("total time used", dur.Seconds()),
zap.Float64("read stats meta", execDur.Seconds()),
zap.Float64("total hist update time", histUpdateSeconds),
zap.Int("rows read from stats_meta", len(rows)),
zap.Int("only meta update", onlyMetaUpdate),
zap.Int("hist also update", histAlsoUpdate),
zap.Int("hist updated num", histUpdatedNum),
zap.Float64("update internal cache cost", tblToUpdateOrDelete.opCost),
zap.Float64("get meta cost", getMetaCost),
zap.Int("tables missing meta", noTableMetaNum),
)
if onlyMetaUpdate+histAlsoUpdate > 1000 {
logutil.BgLogger().Info("update stats cache",
zap.Float64("total time used", dur.Seconds()),
zap.Float64("read stats meta", execDur.Seconds()),
zap.Float64("total hist update time", histUpdateSeconds),
zap.Int("rows read from stats_meta", len(rows)),
zap.Int("only meta update", onlyMetaUpdate),
zap.Int("hist also update", histAlsoUpdate),
zap.Int("hist updated num", histUpdatedNum),
zap.Int("tables missing meta", noTableMetaNum),
zap.Int("tables deleted", deleted),
zap.Int("tables skipped", skipped),
zap.Int("tables error continued", errorContinued),
zap.Float64("update internal cache cost", tblToUpdateOrDelete.opCost),
zap.Float64("get meta cost", getMetaCost),
)
}
return nil
}

Expand Down

0 comments on commit 1b1cbad

Please sign in to comment.