Skip to content

Commit

Permalink
*: make table id in metrics_schema stable (#56839)
Browse files Browse the repository at this point in the history
close #56775
  • Loading branch information
lcwangchao authored Oct 29, 2024
1 parent 11f86a8 commit da14ce7
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pkg/infoschema/metrics_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,27 @@ const (
func init() {
// Initialize the metric schema database and register the driver to `drivers`.
dbID := autoid.MetricSchemaDBID
tableID := dbID + 1
metricTables := make([]*model.TableInfo, 0, len(MetricTableMap))
for name, def := range MetricTableMap {
cols := def.genColumnInfos()
tableInfo := buildTableMeta(name, cols)
tableInfo.ID = tableID
tableInfo.Comment = def.Comment
tableInfo.DBID = dbID
tableID++
metricTables = append(metricTables, tableInfo)
tableInfo.MaxColumnID = int64(len(tableInfo.Columns))
tableInfo.MaxIndexID = int64(len(tableInfo.Indices))
}

// assign table IDs, sort by table name first to make the id stable across different TiDB instances.
slices.SortFunc(metricTables, func(a, b *model.TableInfo) int {
return strings.Compare(a.Name.L, b.Name.L)
})
tableID := dbID + 1
for _, tableInfo := range metricTables {
tableInfo.ID = tableID
tableID++
}

dbInfo := &model.DBInfo{
ID: dbID,
Name: pmodel.NewCIStr(util.MetricSchemaName.O),
Expand Down

0 comments on commit da14ce7

Please sign in to comment.