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: filter resource group in br full restore #42267

Merged
merged 1 commit into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions br/pkg/restore/systable_restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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');",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When restoring from older backup archives, this SQL may fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this sql will fail, it's noop if the user_attributes contains no resoure_group field

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[BR:Common:ErrUnknown]failed to execute UPDATE `__tidb_br_temporary_mysql`.`user` SET User_attributes = JSON_REMOVE(User_attributes, '$.resource_group');: [planner:1054]Unknown column 'User_attributes' in 'field list'

I'm not sure, perhaps earlier backups may not contain the user_attributes row?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

em.. User Attributes is added in #38201, I supposed it had existed longer. Maybe we shoulud check the tidb version here.

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] != "" {
Expand Down
4 changes: 4 additions & 0 deletions br/tests/br_full_cluster_restore/full_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
6 changes: 6 additions & 0 deletions br/tests/br_full_cluster_restore/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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');"
Expand Down Expand Up @@ -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
Expand Down