From 12e0b266480813077d4581366faa81dbf5558be9 Mon Sep 17 00:00:00 2001 From: glorv Date: Wed, 15 Mar 2023 17:37:21 +0800 Subject: [PATCH] filter resource group in br full restore --- br/pkg/restore/systable_restore.go | 12 ++++++++++++ br/tests/br_full_cluster_restore/full_data.sql | 4 ++++ br/tests/br_full_cluster_restore/run.sh | 6 ++++++ 3 files changed, 22 insertions(+) diff --git a/br/pkg/restore/systable_restore.go b/br/pkg/restore/systable_restore.go index ac21b0dba7e42..2599085a242bb 100644 --- a/br/pkg/restore/systable_restore.go +++ b/br/pkg/restore/systable_restore.go @@ -278,6 +278,18 @@ func (rc *Client) replaceTemporaryTableToSystable(ctx context.Context, ti *model return berrors.ErrUnsupportedSystemTable.GenWithStack("restoring unsupported `mysql` schema table") } + // Currently, we don't support restore resource group metadata, so we need to + // remove the resource group related metadata in mysql.user. + // TODO: this function should be removed when we support backup and restore + // resource group. + if tableName == sysUserTableName { + sql := fmt.Sprintf("UPDATE %s SET User_attributes = JSON_REMOVE(User_attributes, '$.resource_group');", + utils.EncloseDBAndTable(db.TemporaryName.L, sysUserTableName)) + if err := execSQL(sql); err != nil { + return err + } + } + if db.ExistingTables[tableName] != nil { whereNotClause := "" if rc.fullClusterRestore && sysPrivilegeTableMap[tableName] != "" { diff --git a/br/tests/br_full_cluster_restore/full_data.sql b/br/tests/br_full_cluster_restore/full_data.sql index 36d2c6ea086e4..4aafd32b5ff4f 100644 --- a/br/tests/br_full_cluster_restore/full_data.sql +++ b/br/tests/br_full_cluster_restore/full_data.sql @@ -37,3 +37,7 @@ grant ROLE_ADMIN on *.* to cloud_admin; -- mysql.global_grants grant select on db1.* to cloud_admin; -- mysql.db grant select on db2.t1 to cloud_admin; -- mysql.tables_priv grant select, update(val) on db2.t2 to cloud_admin; -- mysql.tables_priv mysql.columns_priv + +-- resource group +create resource group rg1 ru_per_sec = 100; +alter user user1 resource group rg1; diff --git a/br/tests/br_full_cluster_restore/run.sh b/br/tests/br_full_cluster_restore/run.sh index 14074e61f3825..d707c1fc5b4a9 100644 --- a/br/tests/br_full_cluster_restore/run.sh +++ b/br/tests/br_full_cluster_restore/run.sh @@ -28,6 +28,9 @@ unset BR_LOG_TO_TERM run_sql_file tests/${TEST_NAME}/full_data.sql run_br backup full --log-file $br_log_file -s "local://$backup_dir" +run_sql "SELECT user FROM mysql.user WHERE JSON_EXTRACT(user_attributes, '$.resource_group') != '';" +check_contains 'user: user1' + # br.test will add coverage output, so we use head here LAST_BACKUP_TS=$(run_br validate decode --log-file $br_log_file --field="end-version" -s "local://$backup_dir" 2>/dev/null | head -n1) run_sql "insert into db2.t1 values(3, 'c'), (4, 'd'), (5, 'e');" @@ -57,6 +60,9 @@ run_sql "alter table mysql.user add column xx int;" run_br restore full --with-sys-table --log-file $br_log_file -s "local://$backup_dir" > $res_file 2>&1 || true run_sql "select count(*) from mysql.user" check_contains "count(*): 6" +# check resource group user_attributes is cleaned. +run_sql "SELECT user FROM mysql.user WHERE JSON_EXTRACT(user_attributes, '$.resource_group') != '';" +check_not_contains 'user: user1' echo "--> incompatible system table: less column on target cluster" restart_services