Skip to content

Commit

Permalink
backupccl: unblock restoring non-multi-region table into multi-region…
Browse files Browse the repository at this point in the history
… database

Previously, restoring a non-multi-region table in to multi-region database is
not allowed.

This patch unblock restoring non-multi-region table into multi-region database
and set table locality as regional by table to the primary region of the target
database.

Release note (enterprise change): We unblock restoring non-multi-region table into
multi-region database and set table locality as regional by table to the primary
region of the target database.
  • Loading branch information
Elliebababa committed May 13, 2021
1 parent 5c0b2ec commit 5772e2d
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 13 deletions.
26 changes: 14 additions & 12 deletions pkg/ccl/backupccl/restore_planning.go
Expand Up @@ -641,21 +641,23 @@ func allocateDescriptorRewrites(
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.
// We're restoring a table and not its parent database. We block restoring
// multi-region tables to multi-region databases since regions may mismatch.
// Long-term we'd want to modify the multi-region table so that it can exist in the
// multi-region database that is compatible with its locality configs.
// https://github.com/cockroachdb/cockroach/issues/59804
// https://github.com/cockroachdb/cockroach/issues/65015
if parentDB.IsMultiRegion() {
return pgerror.Newf(pgcode.FeatureNotSupported,
"cannot restore individual table %d into multi-region database %d",
table.GetID(),
parentDB.GetID(),
)
if table.GetLocalityConfig() != nil {
return pgerror.Newf(pgcode.FeatureNotSupported,
"cannot restore an individual multi-region table %q(%d) into multi-region database %q(%d)",
table.GetName(),
table.GetID(),
parentDB.GetName(),
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
69 changes: 68 additions & 1 deletion pkg/ccl/logictestccl/testdata/logic_test/multi_region_backup
Expand Up @@ -1025,8 +1025,75 @@ USE non_mr_backup
statement ok
CREATE TABLE non_mr_table (i int)

# For comparing the zone configurations before restore.
query TT
SHOW ZONE CONFIGURATION FROM TABLE non_mr_table
----
RANGE default ALTER RANGE default CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 3,
constraints = '[]',
lease_preferences = '[]'

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

statement error cannot restore individual table
statement ok
DROP TABLE non_mr_table

statement ok
RESTORE TABLE non_mr_table FROM 'nodelocal://1/non_mr_table/'

query TT
SHOW ZONE CONFIGURATION FROM TABLE non_mr_table
----
RANGE default ALTER RANGE default CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 3,
constraints = '[]',
lease_preferences = '[]'

statement ok
RESTORE TABLE non_mr_table FROM 'nodelocal://1/non_mr_table/' WITH into_db = 'mr-backup-1'

statement ok
USE 'mr-backup-1'

# Verify that the zone configurations of non_mr_table that is restored to a multi-region database are set.
query TT
SHOW ZONE CONFIGURATION FROM TABLE non_mr_table
----
DATABASE "mr-backup-1" ALTER DATABASE "mr-backup-1" CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 5,
num_voters = 3,
constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}',
voter_constraints = '[+region=ca-central-1]',
lease_preferences = '[[+region=ca-central-1]]'

statement ok
USE "mr-backup-2"

statement ok
DROP TABLE regional_by_row_table;
DROP TABLE regional_by_table_in_primary_region;
DROP TABLE regional_by_table_in_ca_central_1;
DROP TABLE global_table;

statement error cannot restore an individual multi-region table
RESTORE TABLE regional_by_row_table FROM 'nodelocal://1/mr-backup-2/'

statement error cannot restore an individual multi-region table
RESTORE TABLE regional_by_table_in_primary_region FROM 'nodelocal://1/mr-backup-2/'

statement error cannot restore an individual multi-region table
RESTORE TABLE regional_by_table_in_ca_central_1 FROM 'nodelocal://1/mr-backup-2/'

statement error cannot restore an individual multi-region table
RESTORE TABLE global_table FROM 'nodelocal://1/mr-backup-2/'

0 comments on commit 5772e2d

Please sign in to comment.