Skip to content

Commit 48bcbf1

Browse files
craig[bot]ajstorm
andcommitted
Merge #60519
60519: sql: Rebuild zone configs for multi-region tables during restore r=otan,arulajmani,pbardea a=ajstorm Rebuild the zone configurations for multi-region tables on database restore. We must rebuild the zone configs manually during database restore because the zone configs are stored in the system databases, which is only restored on cluster restores. Release note (sql change): Multi-region tables will have their zone configs regenerated during database restore. Co-authored-by: Adam Storm <storm@cockroachlabs.com>
2 parents ea1ef0b + aa5362a commit 48bcbf1

7 files changed

Lines changed: 861 additions & 30 deletions

File tree

pkg/ccl/backupccl/restore_job.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,52 @@ func createImportingDescriptors(
11601160
return err
11611161
}
11621162

1163+
// Now that all of the descriptors have been written to disk, rebuild
1164+
// the zone configurations for any multi-region tables. We only do this
1165+
// in cases where this is not a full cluster restore, because in cluster
1166+
// restore cases, the zone configurations will be restored when the
1167+
// system tables are restored.
1168+
if details.DescriptorCoverage != tree.AllDescriptors {
1169+
for _, table := range tableDescs {
1170+
if lc := table.GetLocalityConfig(); lc != nil {
1171+
_, desc, err := descsCol.GetImmutableDatabaseByID(
1172+
ctx,
1173+
txn,
1174+
table.ParentID,
1175+
tree.DatabaseLookupFlags{
1176+
Required: true,
1177+
AvoidCached: true,
1178+
IncludeOffline: true,
1179+
},
1180+
)
1181+
if err != nil {
1182+
return err
1183+
}
1184+
if desc.RegionConfig == nil {
1185+
return errors.AssertionFailedf(
1186+
"found multi-region table %d in non-multi-region database %d",
1187+
table.ID, table.ParentID)
1188+
}
1189+
1190+
mutTable, err := descsCol.GetMutableTableVersionByID(ctx, table.GetID(), txn)
1191+
if err != nil {
1192+
return err
1193+
}
1194+
1195+
if err := sql.ApplyZoneConfigForMultiRegionTable(
1196+
ctx,
1197+
txn,
1198+
p.ExecCfg(),
1199+
*desc.RegionConfig,
1200+
mutTable,
1201+
sql.ApplyZoneConfigForMultiRegionTableOptionTableAndIndexes,
1202+
); err != nil {
1203+
return err
1204+
}
1205+
}
1206+
}
1207+
}
1208+
11631209
for _, tenant := range details.Tenants {
11641210
// Mark the tenant info as adding.
11651211
tenant.State = descpb.TenantInfo_ADD

0 commit comments

Comments
 (0)