Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: make table id in metrics_schema stable #56839

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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