From b5d9848a02cc796bf833685041e16a0f09100993 Mon Sep 17 00:00:00 2001 From: Adam Storm Date: Wed, 17 Feb 2021 22:15:13 -0500 Subject: [PATCH] sql: Block table-level restore into multi-region databases Block table-level restore into multi-region databases Release note: None --- pkg/ccl/backupccl/restore_planning.go | 31 +++++++++++++------ .../testdata/logic_test/multi_region_backup | 13 ++++++++ 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/pkg/ccl/backupccl/restore_planning.go b/pkg/ccl/backupccl/restore_planning.go index e70644201a5f..49544afd1285 100644 --- a/pkg/ccl/backupccl/restore_planning.go +++ b/pkg/ccl/backupccl/restore_planning.go @@ -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} diff --git a/pkg/ccl/logictestccl/testdata/logic_test/multi_region_backup b/pkg/ccl/logictestccl/testdata/logic_test/multi_region_backup index f9a5f80e5561..31d03aff6741 100644 --- a/pkg/ccl/logictestccl/testdata/logic_test/multi_region_backup +++ b/pkg/ccl/logictestccl/testdata/logic_test/multi_region_backup @@ -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'