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

br: skip template system table __TiDB_BR_Temporary_mysql when backup #41000

Merged
merged 23 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
20f12c9
skip temporary system database(__TiDB_BR_Temporary_mysql) when backup
joccau Feb 2, 2023
119762c
add integration case for skip __TiDB_BR_Temporary_mysql when backup
joccau Feb 2, 2023
21e72c4
Merge branch 'master' into backup-template-sys
joccau Feb 6, 2023
e3a6d1e
Merge branch 'master' into backup-template-sys
joccau Feb 6, 2023
8181fca
Merge branch 'master' into backup-template-sys
3pointer Feb 7, 2023
a67baa8
Merge branch 'master' into backup-template-sys
joccau Feb 7, 2023
4bef559
Merge branch 'master' into backup-template-sys
joccau Feb 8, 2023
9b95beb
Merge branch 'master' into backup-template-sys
joccau Feb 8, 2023
9c6d5e4
Merge branch 'master' into backup-template-sys
joccau Feb 8, 2023
54df48f
Merge branch 'master' into backup-template-sys
joccau Feb 8, 2023
288b73b
Merge branch 'master' into backup-template-sys
ti-chi-bot Feb 8, 2023
b2799c6
Merge branch 'master' into backup-template-sys
ti-chi-bot Feb 8, 2023
c3e06fb
Merge branch 'master' into backup-template-sys
joccau Feb 8, 2023
02625d9
Merge branch 'master' into backup-template-sys
joccau Feb 8, 2023
7ce3f92
Merge branch 'master' into backup-template-sys
ti-chi-bot Feb 8, 2023
e7a942c
Merge branch 'master' into backup-template-sys
ti-chi-bot Feb 8, 2023
8224a8f
Merge branch 'master' into backup-template-sys
ti-chi-bot Feb 8, 2023
f11edfe
Merge branch 'master' into backup-template-sys
hawkingrei Feb 8, 2023
507e8ae
Merge branch 'master' into backup-template-sys
ti-chi-bot Feb 9, 2023
91b78ed
Merge branch 'master' into backup-template-sys
ti-chi-bot Feb 9, 2023
15f8ecc
Merge branch 'master' into backup-template-sys
ti-chi-bot Feb 9, 2023
1a0e9c8
Merge branch 'master' into backup-template-sys
purelind Feb 9, 2023
01cc329
Merge branch 'master' into backup-template-sys
joccau Feb 9, 2023
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
2 changes: 1 addition & 1 deletion br/pkg/backup/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ func BuildBackupRangeAndSchema(

for _, dbInfo := range dbs {
// skip system databases
if !tableFilter.MatchSchema(dbInfo.Name.O) || util.IsMemDB(dbInfo.Name.L) {
if !tableFilter.MatchSchema(dbInfo.Name.O) || util.IsMemDB(dbInfo.Name.L) || utils.IsTemplateSysDB(dbInfo.Name) {
continue
}

Expand Down
6 changes: 6 additions & 0 deletions br/pkg/utils/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

// temporaryDBNamePrefix is the prefix name of system db, e.g. mysql system db will be rename to __TiDB_BR_Temporary_mysql
const temporaryDBNamePrefix = "__TiDB_BR_Temporary_"
const temporarySysDB = temporaryDBNamePrefix + "mysql"

// NeedAutoID checks whether the table needs backing up with an autoid.
func NeedAutoID(tblInfo *model.TableInfo) bool {
Expand Down Expand Up @@ -96,6 +97,11 @@ func EncloseDBAndTable(database, table string) string {
return fmt.Sprintf("%s.%s", EncloseName(database), EncloseName(table))
}

// IsTemplateSysDB checks wheterh the dbname is temporary system database(__TiDB_BR_Temporary_mysql).
func IsTemplateSysDB(dbname model.CIStr) bool {
return dbname.O == temporarySysDB
}

// IsSysDB tests whether the database is system DB.
// Currently, the only system DB is mysql.
func IsSysDB(dbLowerName string) bool {
Expand Down
14 changes: 14 additions & 0 deletions br/tests/br_backup_empty/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ run_sql "CREATE TABLE ${DB}1.usertable1 ( \
PRIMARY KEY (YCSB_KEY) \
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;"

# backup empty table
echo "backup empty table start..."
run_br --pd $PD_ADDR backup full -s "local://$TEST_DIR/empty_table"

Expand All @@ -75,6 +76,7 @@ while [ $i -le $DB_COUNT ]; do
i=$(($i+1))
done

# restore empty table.
echo "restore empty table start..."
run_br --pd $PD_ADDR restore full -s "local://$TEST_DIR/empty_table"

Expand All @@ -85,3 +87,15 @@ while [ $i -le $DB_COUNT ]; do
run_sql "DROP DATABASE $DB$i;"
i=$(($i+1))
done


# backup, skip temporary system database(__TiDB_BR_Temporary_mysql) when backup
run_sql "CREATE DATABASE __TiDB_BR_Temporary_mysql";
run_sql "CREATE TABLE __TiDB_BR_Temporary_mysql.tables_priv(id int);";
echo "backup and skip __TiDB_BR_Temporary_mysql start..."
run_br --pd $PD_ADDR backup full -s "local://$TEST_DIR/skip_temporary_mysql"

# restore successfully without panic.
run_sql "DROP DATABASE __TiDB_BR_Temporary_mysql";
echo "restore the data start..."
run_br restore full -s "local://$TEST_DIR/skip_temporary_mysql" --pd $PD_ADDR --ratelimit 1024
Leavrth marked this conversation as resolved.
Show resolved Hide resolved