Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
winoros committed Aug 16, 2023
1 parent 729e4f5 commit b28d41b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 9 additions & 3 deletions session/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ const (
// oom-action when upgrade from v3.0.x to v4.0.11+.
tidbDefOOMAction = "default_oom_action"

tiDBStatsGCLastTS = "tidb_stats_gc_last_stats"
tiDBStatsGCLastTS = "tidb_stats_gc_last_ts"
tiDBStatsGCLastTSComment = "the previous gc timestamp for statistics"
// Const for TiDB server version 2.
version2 = 2
Expand Down Expand Up @@ -986,7 +986,7 @@ const (

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

// 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.
var internalSQLTimeout = owner.ManagerSessionTTL + 15
Expand Down Expand Up @@ -2801,8 +2801,12 @@ func upgradeToVer173(s Session, ver int64) {
if ver >= version173 {
return
}
writeStatsGCLastPos(s)
}

func writeStatsGCLastPos(s Session) {
mustExecute(s, "INSERT HIGH_PRIORITY INTO %n.%n VALUES(%?, %?, %?) ON DUPLICATE KEY UPDATE VARIABLE_VALUE = %?",
mysql.SystemDB, mysql.TiDBTable, tiDBStatsGCLastTS, 0, tiDBStatsGCLastTSComment)
mysql.SystemDB, mysql.TiDBTable, tiDBStatsGCLastTS, 0, tiDBStatsGCLastTSComment, 0)
}

func writeOOMAction(s Session) {
Expand Down Expand Up @@ -3057,6 +3061,8 @@ func doDMLWorks(s Session) {

writeStmtSummaryVars(s)

writeStatsGCLastPos(s)

ctx := kv.WithInternalSourceType(context.Background(), kv.InternalTxnBootstrap)
_, err := s.ExecuteInternal(ctx, "COMMIT")
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions statistics/handle/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import (
"go.uber.org/zap"
)

const gcLastTSVarName = "tidb_stats_gc_last_ts"

// GCStats will garbage collect the useless stats info. For dropped tables, we will first update their version so that
// other tidb could know that table is deleted.
func (h *Handle) GCStats(is infoschema.InfoSchema, ddlLease time.Duration) (err error) {
Expand Down Expand Up @@ -83,7 +85,7 @@ func (h *Handle) GCStats(is infoschema.InfoSchema, ddlLease time.Duration) (err

// GetLastGCTimestamp loads the last gc time from mysql.tidb.
func (h *Handle) GetLastGCTimestamp(ctx context.Context) (uint64, error) {
rows, _, err := h.execRestrictedSQL(ctx, "SELECT HIGH_PRIORITY variable_value FROM mysql.tidb WHERE variable_name=%?", "tidb_stats_gc_last_ts")
rows, _, err := h.execRestrictedSQL(ctx, "SELECT HIGH_PRIORITY variable_value FROM mysql.tidb WHERE variable_name=%?", gcLastTSVarName)
if err != nil {
return 0, errors.Trace(err)
}
Expand All @@ -102,7 +104,7 @@ func (h *Handle) writeGCTimestampToKV(ctx context.Context, newTS uint64) error {
_, _, err := h.execRestrictedSQL(ctx,
"update mysql.tidb set variable_value = %? where variable_name = %?",
newTS,
"tidb_stats_gc_last_ts",
gcLastTSVarName,
)
return err
}
Expand Down

0 comments on commit b28d41b

Please sign in to comment.