Skip to content

Commit 199a469

Browse files
craig[bot]msbutler
andcommitted
Merge #155281
155281: backup: fix mr show backup for table level backup r=kev-cao a=msbutler Previously, if a user took a table level backup of an MR database, show backup would fail. This occured because SHOW BACKUP will display the database object, and for MR databases, show backup expects to have access to the MR enum; however table level backups do not back up the enum. This patch relaxes the SHOW BACKUP MR DB requirement, allowing show backup for the table to succeed. Epic: none Release note: none Co-authored-by: Michael Butler <butler@cockroachlabs.com>
2 parents 195de37 + 2543cc2 commit 199a469

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

pkg/backup/show.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -736,11 +736,16 @@ func backupShowerDefault(
736736
case catalog.DatabaseDescriptor:
737737
descriptorType = "database"
738738
if desc.IsMultiRegion() {
739-
regions, err := showRegions(typeIDToTypeDescriptor[desc.GetRegionConfig().RegionEnumID], desc.GetName())
740-
if err != nil {
741-
return nil, errors.Wrapf(err, "cannot generate regions column")
739+
if mrEnum := typeIDToTypeDescriptor[desc.GetRegionConfig().RegionEnumID]; mrEnum != nil {
740+
// The enum may not be in the backup, for example in a table
741+
// level backup. Jury is out for whether databases should be
742+
// shown in table level backups.
743+
regions, err := showRegions(mrEnum, desc.GetName())
744+
if err != nil {
745+
return nil, errors.Wrapf(err, "cannot generate regions column")
746+
}
747+
regionsDatum = nullIfEmpty(regions)
742748
}
743-
regionsDatum = nullIfEmpty(regions)
744749
}
745750
case catalog.SchemaDescriptor:
746751
descriptorType = "schema"

pkg/backup/testdata/backup-restore/show-backup-multiregion

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,33 @@ d database incremental
6161
public schema incremental
6262
crdb_internal_region type incremental
6363
_crdb_internal_region type incremental
64+
65+
66+
query-sql
67+
SELECT object_name, regions FROM [SHOW BACKUP LATEST IN ('nodelocal://1/database_backup_locality_aware_default?COCKROACH_LOCALITY=default', 'nodelocal://1/database_backup_locality_aware_west?COCKROACH_LOCALITY=region=us-west-1', 'nodelocal://1/database_backup_locality_aware_central?COCKROACH_LOCALITY=region=eu-central-1')] where object_type='database' limit 1;
68+
----
69+
d ALTER DATABASE d SET PRIMARY REGION "us-east-1"; ALTER DATABASE d ADD REGION "eu-central-1"; ALTER DATABASE d ADD REGION "us-west-1";
70+
71+
# Try backing up a table in the database
72+
exec-sql
73+
CREATE TABLE d.t (x INT);
74+
----
75+
76+
exec-sql
77+
BACKUP TABLE d.t INTO ('nodelocal://1/database_backup_locality_aware_default?COCKROACH_LOCALITY=default', 'nodelocal://1/database_backup_locality_aware_west?COCKROACH_LOCALITY=region=us-west-1', 'nodelocal://1/database_backup_locality_aware_central?COCKROACH_LOCALITY=region=eu-central-1');
78+
----
79+
80+
query-sql
81+
SELECT object_name, object_type, backup_type FROM [SHOW BACKUP LATEST IN ('nodelocal://1/database_backup_locality_aware_default?COCKROACH_LOCALITY=default', 'nodelocal://1/database_backup_locality_aware_west?COCKROACH_LOCALITY=region=us-west-1', 'nodelocal://1/database_backup_locality_aware_central?COCKROACH_LOCALITY=region=eu-central-1')];
82+
----
83+
d database full
84+
public schema full
85+
t table full
86+
87+
exec-sql
88+
drop table d.t
89+
----
90+
91+
exec-sql
92+
RESTORE TABLE d.t FROM LATEST IN ('nodelocal://1/database_backup_locality_aware_default?COCKROACH_LOCALITY=default', 'nodelocal://1/database_backup_locality_aware_west?COCKROACH_LOCALITY=region=us-west-1', 'nodelocal://1/database_backup_locality_aware_central?COCKROACH_LOCALITY=region=eu-central-1');
93+
----

0 commit comments

Comments
 (0)