Skip to content

Commit c73ae58

Browse files
authored
workloadrepo: make sure WORKLOAD_SCHEMA is ignored by BR (#58878)
close #58768
1 parent af93fff commit c73ae58

File tree

16 files changed

+57
-27
lines changed

16 files changed

+57
-27
lines changed

br/pkg/restore/snap_client/client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import (
5555
"github.com/pingcap/tidb/pkg/meta"
5656
"github.com/pingcap/tidb/pkg/meta/model"
5757
"github.com/pingcap/tidb/pkg/metrics"
58+
"github.com/pingcap/tidb/pkg/parser/mysql"
5859
tidbutil "github.com/pingcap/tidb/pkg/util"
5960
"github.com/pingcap/tidb/pkg/util/redact"
6061
kvutil "github.com/tikv/client-go/v2/util"
@@ -755,7 +756,7 @@ func (rc *SnapClient) GetDatabaseMap() map[int64]*metautil.Database {
755756
// HasBackedUpSysDB whether we have backed up system tables
756757
// br backs system tables up since 5.1.0
757758
func (rc *SnapClient) HasBackedUpSysDB() bool {
758-
sysDBs := []string{"mysql", "sys"}
759+
sysDBs := []string{mysql.SystemDB, mysql.SysDB, mysql.WorkloadSchema}
759760
for _, db := range sysDBs {
760761
temporaryDB := utils.TemporaryDBName(db)
761762
_, backedUp := rc.databases[temporaryDB.O]

br/pkg/restore/snap_client/systable_restore.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,14 @@ var unRecoverableTable = map[string]map[string]struct{}{
129129
},
130130
}
131131

132+
var unRecoverableSchema = map[string]struct{}{
133+
mysql.WorkloadSchema: {},
134+
}
135+
132136
func isUnrecoverableTable(schemaName string, tableName string) bool {
137+
if _, ok := unRecoverableSchema[schemaName]; ok {
138+
return true
139+
}
133140
tableMap, ok := unRecoverableTable[schemaName]
134141
if !ok {
135142
return false
@@ -159,7 +166,7 @@ func isPlanReplayerTables(schemaName string, tableName string) bool {
159166
// RestoreSystemSchemas restores the system schema(i.e. the `mysql` schema).
160167
// Detail see https://github.com/pingcap/br/issues/679#issuecomment-762592254.
161168
func (rc *SnapClient) RestoreSystemSchemas(ctx context.Context, f filter.Filter) (rerr error) {
162-
sysDBs := []string{mysql.SystemDB, mysql.SysDB}
169+
sysDBs := []string{mysql.SystemDB, mysql.SysDB, mysql.WorkloadSchema}
163170
for _, sysDB := range sysDBs {
164171
err := rc.restoreSystemSchema(ctx, f, sysDB)
165172
if err != nil {

br/pkg/utils/schema.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,8 @@ func IsTemplateSysDB(dbname ast.CIStr) bool {
3838

3939
// IsSysDB tests whether the database is system DB.
4040
// Currently, both `mysql` and `sys` are system DB.
41-
func IsSysDB(dbName string) bool {
42-
// just in case
43-
dbLowerName := strings.ToLower(dbName)
44-
return dbLowerName == mysql.SystemDB || dbLowerName == mysql.SysDB
41+
func IsSysDB(dbLowerName string) bool {
42+
return dbLowerName == mysql.SystemDB || dbLowerName == mysql.SysDB || dbLowerName == mysql.WorkloadSchema
4543
}
4644

4745
// TemporaryDBName makes a 'private' database name.

br/tests/br_systables/run.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ modify_systables() {
2424
-p mysql.db=mysql
2525

2626
run_sql "ANALYZE TABLE mysql.usertable;"
27+
28+
# enable workload schema
29+
run_sql "SET GLOBAL tidb_workload_repository_dest = 'table';"
30+
sleep 5
31+
run_sql "ADMIN CREATE WORKLOAD SNAPSHOT;"
32+
# disable workload schema
33+
run_sql "SET GLOBAL tidb_workload_repository_dest = '';"
2734
}
2835

2936
add_user() {
@@ -53,6 +60,8 @@ rollback_modify() {
5360
# FIXME don't check the user table until we support restore user correctly.
5461
# run_sql "DROP USER 'Alyssa P. Hacker';"
5562
run_sql "DROP TABLE mysql.usertable;"
63+
64+
run_sql "DROP DATABASE IF EXISTS workload_schema;"
5665
}
5766

5867
check() {
@@ -62,6 +71,10 @@ check() {
6271
# we cannot let user overwrite `mysql.tidb` through br in any time.
6372
run_sql "SELECT VARIABLE_VALUE FROM mysql.tidb WHERE VARIABLE_NAME = 'tikv_gc_life_time'" | awk '/1h/{exit 1}'
6473

74+
run_sql "SELECT SCHEMA_NAME FROM information_schema.schemata;"
75+
# workload_schema schema should not be recovered
76+
check_not_contains "workload_schema"
77+
6578
# FIXME don't check the user table until we support restore user correctly.
6679
# TODO remove this after supporting auto flush.
6780
# run_sql "FLUSH PRIVILEGES;"

pkg/ddl/executor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4067,7 +4067,7 @@ var systemTables = map[string]struct{}{
40674067
}
40684068

40694069
func isUndroppableTable(schema, table string) bool {
4070-
if schema == "workload_schema" {
4070+
if schema == mysql.WorkloadSchema {
40714071
return true
40724072
}
40734073
if schema != mysql.SystemDB {

pkg/parser/mysql/const.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ const (
196196
AuthLDAPSASL = "authentication_ldap_sasl"
197197
)
198198

199-
// MySQL database and tables.
199+
// System database and tables that mostly inherited from MySQL.
200200
const (
201201
// SystemDB is the name of system database.
202202
SystemDB = "mysql"
@@ -225,6 +225,8 @@ const (
225225
DefaultRoleTable = "default_roles"
226226
// PasswordHistoryTable is the table in system db contains password history.
227227
PasswordHistoryTable = "password_history"
228+
// WorkloadSchema is the name of workload repository database.
229+
WorkloadSchema = "workload_schema"
228230
)
229231

230232
// MySQL type maximum length.

pkg/util/filter/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ go_library(
99
importpath = "github.com/pingcap/tidb/pkg/util/filter",
1010
visibility = ["//visibility:public"],
1111
deps = [
12+
"//pkg/parser/mysql",
1213
"//pkg/util/table-filter",
1314
"//pkg/util/table-rule-selector",
1415
"@com_github_pingcap_errors//:errors",

pkg/util/filter/schema.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ package filter
1616

1717
import (
1818
"strings"
19+
20+
"github.com/pingcap/tidb/pkg/parser/mysql"
1921
)
2022

2123
var (
@@ -29,6 +31,8 @@ var (
2931
MetricSchemaName = "METRICS_SCHEMA"
3032
// InspectionSchemaName is the `INSPECTION_SCHEMA` database name
3133
InspectionSchemaName = "INSPECTION_SCHEMA"
34+
// WorkloadSchemaName is the `WORKLOAD_SCHEMA` database name
35+
WorkloadSchemaName = strings.ToUpper(mysql.WorkloadSchema)
3236
)
3337

3438
// IsSystemSchema checks whether schema is system schema or not.
@@ -39,6 +43,7 @@ func IsSystemSchema(schema string) bool {
3943
case DMHeartbeatSchema, // do not create table in it manually
4044
"SYS", // https://dev.mysql.com/doc/refman/8.0/en/sys-schema.html
4145
"MYSQL", // the name of system database.
46+
WorkloadSchemaName,
4247
InformationSchemaName,
4348
InspectionSchemaName,
4449
PerformanceSchemaName,

pkg/util/misc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func IsMemDB(dbLowerName string) bool {
208208

209209
// IsSysDB checks whether dbLowerName is system database.
210210
func IsSysDB(dbLowerName string) bool {
211-
return dbLowerName == mysql.SystemDB || dbLowerName == mysql.SysDB
211+
return dbLowerName == mysql.SystemDB || dbLowerName == mysql.SysDB || dbLowerName == mysql.WorkloadSchema
212212
}
213213

214214
// IsSystemView is similar to IsMemOrSyDB, but does not include the mysql schema

pkg/util/workloadrepo/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ go_test(
5757
"//pkg/kv",
5858
"//pkg/owner",
5959
"//pkg/parser/ast",
60+
"//pkg/parser/mysql",
6061
"//pkg/sessionctx",
6162
"//pkg/sessionctx/variable",
6263
"//pkg/testkit",

0 commit comments

Comments
 (0)