Skip to content

Commit b28d41b

Browse files
committed
fix
1 parent 729e4f5 commit b28d41b

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

session/bootstrap.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ const (
731731
// oom-action when upgrade from v3.0.x to v4.0.11+.
732732
tidbDefOOMAction = "default_oom_action"
733733

734-
tiDBStatsGCLastTS = "tidb_stats_gc_last_stats"
734+
tiDBStatsGCLastTS = "tidb_stats_gc_last_ts"
735735
tiDBStatsGCLastTSComment = "the previous gc timestamp for statistics"
736736
// Const for TiDB server version 2.
737737
version2 = 2
@@ -986,7 +986,7 @@ const (
986986

987987
// currentBootstrapVersion is defined as a variable, so we can modify its value for testing.
988988
// please make sure this is the largest version
989-
var currentBootstrapVersion int64 = version172
989+
var currentBootstrapVersion int64 = version173
990990

991991
// DDL owner key's expired time is ManagerSessionTTL seconds, we should wait the time and give more time to have a chance to finish it.
992992
var internalSQLTimeout = owner.ManagerSessionTTL + 15
@@ -2801,8 +2801,12 @@ func upgradeToVer173(s Session, ver int64) {
28012801
if ver >= version173 {
28022802
return
28032803
}
2804+
writeStatsGCLastPos(s)
2805+
}
2806+
2807+
func writeStatsGCLastPos(s Session) {
28042808
mustExecute(s, "INSERT HIGH_PRIORITY INTO %n.%n VALUES(%?, %?, %?) ON DUPLICATE KEY UPDATE VARIABLE_VALUE = %?",
2805-
mysql.SystemDB, mysql.TiDBTable, tiDBStatsGCLastTS, 0, tiDBStatsGCLastTSComment)
2809+
mysql.SystemDB, mysql.TiDBTable, tiDBStatsGCLastTS, 0, tiDBStatsGCLastTSComment, 0)
28062810
}
28072811

28082812
func writeOOMAction(s Session) {
@@ -3057,6 +3061,8 @@ func doDMLWorks(s Session) {
30573061

30583062
writeStmtSummaryVars(s)
30593063

3064+
writeStatsGCLastPos(s)
3065+
30603066
ctx := kv.WithInternalSourceType(context.Background(), kv.InternalTxnBootstrap)
30613067
_, err := s.ExecuteInternal(ctx, "COMMIT")
30623068
if err != nil {

statistics/handle/gc.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ import (
3535
"go.uber.org/zap"
3636
)
3737

38+
const gcLastTSVarName = "tidb_stats_gc_last_ts"
39+
3840
// GCStats will garbage collect the useless stats info. For dropped tables, we will first update their version so that
3941
// other tidb could know that table is deleted.
4042
func (h *Handle) GCStats(is infoschema.InfoSchema, ddlLease time.Duration) (err error) {
@@ -83,7 +85,7 @@ func (h *Handle) GCStats(is infoschema.InfoSchema, ddlLease time.Duration) (err
8385

8486
// GetLastGCTimestamp loads the last gc time from mysql.tidb.
8587
func (h *Handle) GetLastGCTimestamp(ctx context.Context) (uint64, error) {
86-
rows, _, err := h.execRestrictedSQL(ctx, "SELECT HIGH_PRIORITY variable_value FROM mysql.tidb WHERE variable_name=%?", "tidb_stats_gc_last_ts")
88+
rows, _, err := h.execRestrictedSQL(ctx, "SELECT HIGH_PRIORITY variable_value FROM mysql.tidb WHERE variable_name=%?", gcLastTSVarName)
8789
if err != nil {
8890
return 0, errors.Trace(err)
8991
}
@@ -102,7 +104,7 @@ func (h *Handle) writeGCTimestampToKV(ctx context.Context, newTS uint64) error {
102104
_, _, err := h.execRestrictedSQL(ctx,
103105
"update mysql.tidb set variable_value = %? where variable_name = %?",
104106
newTS,
105-
"tidb_stats_gc_last_ts",
107+
gcLastTSVarName,
106108
)
107109
return err
108110
}

0 commit comments

Comments
 (0)