Skip to content

Commit a78b54e

Browse files
ti-chi-bothawkingrei
authored andcommitted
statistics: upgrade stats timeout checkpoint after it timeouts (pingcap#52424) (pingcap#52438)
close pingcap#52425
1 parent b43ce36 commit a78b54e

File tree

4 files changed

+6
-4
lines changed

4 files changed

+6
-4
lines changed

planner/core/plan_stats.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (collectPredicateColumnsPoint) optimize(_ context.Context, plan LogicalPlan
3636
return plan, nil
3737
}
3838
predicateNeeded := variable.EnableColumnTracking.Load()
39-
syncWait := plan.SCtx().GetSessionVars().StatsLoadSyncWait * time.Millisecond.Nanoseconds()
39+
syncWait := plan.SCtx().GetSessionVars().StatsLoadSyncWait.Load() * time.Millisecond.Nanoseconds()
4040
histNeeded := syncWait > 0
4141
predicateColumns, histNeededColumns := CollectColumnStatsUsage(plan, predicateNeeded, histNeeded)
4242
if len(predicateColumns) > 0 {

sessionctx/variable/session.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1196,7 +1196,7 @@ type SessionVars struct {
11961196
ReadConsistency ReadConsistencyLevel
11971197

11981198
// StatsLoadSyncWait indicates how long to wait for stats load before timeout.
1199-
StatsLoadSyncWait int64
1199+
StatsLoadSyncWait atomic.Int64
12001200

12011201
// SysdateIsNow indicates whether Sysdate is an alias of Now function
12021202
SysdateIsNow bool
@@ -1710,7 +1710,6 @@ func NewSessionVars(hctx HookContext) *SessionVars {
17101710
TMPTableSize: DefTiDBTmpTableMaxSize,
17111711
MPPStoreFailTTL: DefTiDBMPPStoreFailTTL,
17121712
Rng: mathutil.NewWithTime(),
1713-
StatsLoadSyncWait: StatsLoadSyncWait.Load(),
17141713
EnableLegacyInstanceScope: DefEnableLegacyInstanceScope,
17151714
RemoveOrderbyInSubquery: DefTiDBRemoveOrderbyInSubquery,
17161715
EnableSkewDistinctAgg: DefTiDBSkewDistinctAgg,
@@ -1762,6 +1761,7 @@ func NewSessionVars(hctx HookContext) *SessionVars {
17621761
vars.DiskTracker = disk.NewTracker(memory.LabelForSession, -1)
17631762
vars.MemTracker = memory.NewTracker(memory.LabelForSession, vars.MemQuotaQuery)
17641763
vars.MemTracker.IsRootTrackerOfSess = true
1764+
vars.StatsLoadSyncWait.Store(StatsLoadSyncWait.Load())
17651765

17661766
for _, engine := range config.GetGlobalConfig().IsolationRead.Engines {
17671767
switch engine {

sessionctx/variable/sysvar.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1941,7 +1941,7 @@ var defaultSysVars = []*SysVar{
19411941
}},
19421942
{Scope: ScopeGlobal | ScopeSession, Name: TiDBStatsLoadSyncWait, Value: strconv.Itoa(DefTiDBStatsLoadSyncWait), Type: TypeInt, MinValue: 0, MaxValue: math.MaxInt32,
19431943
SetSession: func(s *SessionVars, val string) error {
1944-
s.StatsLoadSyncWait = TidbOptInt64(val, DefTiDBStatsLoadSyncWait)
1944+
s.StatsLoadSyncWait.Store(TidbOptInt64(val, DefTiDBStatsLoadSyncWait))
19451945
return nil
19461946
},
19471947
GetGlobal: func(_ context.Context, s *SessionVars) (string, error) {

statistics/handle/handle_hist.go

+2
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ func (h *Handle) HandleOneTask(lastTask *NeededItemTask, readerCtx *StatsReaderC
259259
}
260260
return task, sr.Err
261261
case <-time.After(timeout):
262+
task.ToTimeout.Add(time.Duration(h.mu.ctx.GetSessionVars().StatsLoadSyncWait.Load()) * time.Microsecond)
262263
return task, nil
263264
}
264265
}
@@ -445,6 +446,7 @@ func (h *Handle) drainColTask(exit chan struct{}) (*NeededItemTask, error) {
445446
// if the task has already timeout, no sql is sync-waiting for it,
446447
// so do not handle it just now, put it to another channel with lower priority
447448
if time.Now().After(task.ToTimeout) {
449+
task.ToTimeout.Add(time.Duration(h.mu.ctx.GetSessionVars().StatsLoadSyncWait.Load()) * time.Microsecond)
448450
h.writeToTimeoutChan(h.StatsLoad.TimeoutItemsCh, task)
449451
continue
450452
}

0 commit comments

Comments
 (0)