Skip to content

Commit

Permalink
sql: Block table-level restore into multi-region databases
Browse files Browse the repository at this point in the history
Block table-level restore into multi-region databases

Release note: None
  • Loading branch information
ajstorm committed Feb 18, 2021
1 parent 2ba2d72 commit b5d9848
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
31 changes: 22 additions & 9 deletions pkg/ccl/backupccl/restore_planning.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,17 +546,30 @@ func allocateDescriptorRewrites(
}

// Check privileges.
{
parentDB, err := catalogkv.MustGetDatabaseDescByID(ctx, txn, p.ExecCfg().Codec, parentID)
if err != nil {
return errors.Wrapf(err,
"failed to lookup parent DB %d", errors.Safe(parentID))
}
parentDB, err := catalogkv.MustGetDatabaseDescByID(ctx, txn, p.ExecCfg().Codec, parentID)
if err != nil {
return errors.Wrapf(err,
"failed to lookup parent DB %d", errors.Safe(parentID))
}
if err := p.CheckPrivilege(ctx, parentDB, privilege.CREATE); err != nil {
return err
}

if err := p.CheckPrivilege(ctx, parentDB, privilege.CREATE); err != nil {
return err
}
// We're restoring a table and not its parent database. If the
// new database we're placing the table in is a multi-region database,
// block the restore. We do this because we currently have no way to
// modify this table and make it multi-region friendly. Long-term we'd
// want to modify the table so that it can exist in the multi-region
// database.
// https://github.com/cockroachdb/cockroach/issues/59804
if parentDB.GetRegionConfig() != nil {
return pgerror.Newf(pgcode.FeatureNotSupported,
"cannot restore individual table %d into multi-region database %d",
table.GetID(),
parentDB.GetID(),
)
}

// Create the table rewrite with the new parent ID. We've done all the
// up-front validation that we can.
descriptorRewrites[table.ID] = &jobspb.RestoreDetails_DescriptorRewrite{ParentID: parentID}
Expand Down
13 changes: 13 additions & 0 deletions pkg/ccl/logictestccl/testdata/logic_test/multi_region_backup
Original file line number Diff line number Diff line change
Expand Up @@ -969,3 +969,16 @@ BACKUP TABLE regional_by_table_in_ca_central_1 TO 'nodelocal://1/rbr_table/';

statement error cannot backup individual table
BACKUP TABLE global_table TO 'nodelocal://1/rbr_table/';

statement ok
CREATE DATABASE non_mr_backup;
USE non_mr_backup

statement ok
CREATE TABLE non_mr_table (i int)

statement ok
BACKUP TABLE non_mr_table TO 'nodelocal://1/non_mr_table/'

statement error cannot restore individual table
RESTORE TABLE non_mr_table FROM 'nodelocal://1/non_mr_table/' WITH into_db = 'mr-backup-1'

0 comments on commit b5d9848

Please sign in to comment.