Skip to content

Commit 7013d5c

Browse files
committed
backup: re-apply SECONDARY zone config during RESTORE DATABASE
Previously during restoration of a DATABASE with a SECONDARY REGION, the region was correctly configured on the database but its *zone config* was not updated to reflect the region, so the second lease preference was not set, at least until some other schema change or operation reconcilled the descriptors config to a zone config. This updates the creation of the DB during RESTORE to also trigger the zone configuration update. Release note (bug fix): RESTORE of a database with a SECONDARY REGION now applies the lease-preference for said region. Epic: none.
1 parent b1980af commit 7013d5c

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

pkg/backup/restore_job.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,11 @@ func createImportingDescriptors(
13011301

13021302
return nil
13031303
})
1304+
1305+
var opts []multiregion.MakeRegionConfigOption
1306+
if desc.RegionConfig.SecondaryRegion != "" {
1307+
opts = append(opts, multiregion.WithSecondaryRegion(desc.RegionConfig.SecondaryRegion))
1308+
}
13041309
regionConfig := multiregion.MakeRegionConfig(
13051310
regionNames,
13061311
desc.RegionConfig.PrimaryRegion,
@@ -1309,6 +1314,7 @@ func createImportingDescriptors(
13091314
desc.RegionConfig.Placement,
13101315
regionTypeDesc.TypeDesc().RegionConfig.SuperRegions,
13111316
regionTypeDesc.TypeDesc().RegionConfig.ZoneConfigExtensions,
1317+
opts...,
13121318
)
13131319
if err := sql.ApplyZoneConfigFromDatabaseRegionConfig(
13141320
ctx,

pkg/backup/testdata/backup-restore/multiregion

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ set-cluster-setting setting=sql.multiregion.system_database_multiregion.enabled
1111

1212
exec-sql
1313
ALTER DATABASE system SET PRIMARY REGION "us-east-1";
14-
CREATE DATABASE d PRIMARY REGION "us-east-1" REGIONS "us-west-1", "eu-central-1" SURVIVE REGION FAILURE;
14+
CREATE DATABASE d PRIMARY REGION "us-east-1" REGIONS "us-west-1", "eu-central-1" SURVIVE REGION FAILURE SECONDARY REGION "us-west-1";
1515
CREATE TABLE d.t (x INT);
1616
INSERT INTO d.t VALUES (1), (2), (3);
1717
----
@@ -23,6 +23,19 @@ eu-central-1
2323
us-east-1
2424
us-west-1
2525

26+
query-sql
27+
SHOW ZONE CONFIGURATION FROM DATABASE d;
28+
----
29+
DATABASE d ALTER DATABASE d CONFIGURE ZONE USING
30+
range_min_bytes = 134217728,
31+
range_max_bytes = 536870912,
32+
gc.ttlseconds = 14400,
33+
num_replicas = 5,
34+
num_voters = 5,
35+
constraints = '{+region=eu-central-1: 1, +region=us-east-1: 1, +region=us-west-1: 1}',
36+
voter_constraints = '{+region=us-east-1: 2, +region=us-west-1: 2}',
37+
lease_preferences = '[[+region=us-east-1], [+region=us-west-1]]'
38+
2639
exec-sql
2740
BACKUP DATABASE d INTO 'nodelocal://1/database_backup/';
2841
----
@@ -50,12 +63,25 @@ RESTORE DATABASE d FROM LATEST IN 'nodelocal://1/database_backup/';
5063
query-sql
5164
SHOW DATABASES;
5265
----
53-
d root us-east-1 {eu-central-1,us-east-1,us-west-1} region
66+
d root us-east-1 us-west-1 {eu-central-1,us-east-1,us-west-1} region
5467
data root <nil> <nil> {} <nil>
5568
defaultdb root <nil> <nil> {} <nil>
5669
postgres root <nil> <nil> {} <nil>
5770
system node <nil> <nil> {} <nil>
5871

72+
query-sql
73+
SHOW ZONE CONFIGURATION FROM DATABASE d;
74+
----
75+
DATABASE d ALTER DATABASE d CONFIGURE ZONE USING
76+
range_min_bytes = 134217728,
77+
range_max_bytes = 536870912,
78+
gc.ttlseconds = 14400,
79+
num_replicas = 5,
80+
num_voters = 5,
81+
constraints = '{+region=eu-central-1: 1, +region=us-east-1: 1, +region=us-west-1: 1}',
82+
voter_constraints = '{+region=us-east-1: 2, +region=us-west-1: 2}',
83+
lease_preferences = '[[+region=us-east-1], [+region=us-west-1]]'
84+
5985
# A new cluster with different localities settings.
6086
new-cluster name=s3 share-io-dir=s1 allow-implicit-access disable-tenant localities=eu-central-1,eu-north-1
6187
----
@@ -85,6 +111,7 @@ SET enable_multiregion_placement_policy='true';
85111
ALTER DATABASE d SURVIVE ZONE FAILURE;
86112
ALTER DATABASE d PLACEMENT RESTRICTED;
87113
ALTER DATABASE d SET PRIMARY REGION 'eu-central-1';
114+
ALTER DATABASE d DROP SECONDARY REGION;
88115
ALTER DATABASE d DROP REGION 'us-east-1';
89116
ALTER DATABASE d DROP REGION 'us-west-1';
90117
ALTER DATABASE d ADD REGION 'eu-north-1';
@@ -104,6 +131,7 @@ SET enable_multiregion_placement_policy='true';
104131
ALTER DATABASE d_new SURVIVE ZONE FAILURE;
105132
ALTER DATABASE d PLACEMENT RESTRICTED;
106133
ALTER DATABASE d_new SET PRIMARY REGION 'eu-central-1';
134+
ALTER DATABASE d_new DROP SECONDARY REGION;
107135
ALTER DATABASE d_new DROP REGION 'us-east-1';
108136
ALTER DATABASE d_new DROP REGION 'us-west-1';
109137
ALTER DATABASE d_new ADD REGION 'eu-north-1';

0 commit comments

Comments
 (0)