Skip to content

Commit c0f0059

Browse files
craig[bot]fqazi
craig[bot]
andcommitted
Merge #110083
110083: sql: return pgerror for duplicate regions in super region r=fqazi a=fqazi Previously, when duplicate regions would exist within a super region an internal assertion would be generated. This was inadequate since an assertion failure would lead to a stack dump. To address this, this patch will generate a proper pgerror. Fixes: #108556 Release note: None Co-authored-by: Faizan Qazi <[email protected]>
2 parents 8b47bf4 + 0ebc0ce commit c0f0059

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

pkg/ccl/logictestccl/testdata/logic_test/secondary_region

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,9 @@ ALTER DATABASE mr3 ADD SUPER REGION "test1" VALUES "us-east-1", "us-west-1"
469469
statement ok
470470
ALTER DATABASE mr3 ADD SUPER REGION "test2" VALUES "us-central-1", "ca-central-1"
471471

472+
statement error pgcode 42710 pq: duplicate region us-central-1 found in super region test3
473+
ALTER DATABASE mr3 ADD SUPER REGION "test3" VALUES "us-central-1", "ca-central-1", "us-central-1"
474+
472475
statement error pq: the secondary region must be in the same super region as the current primary region
473476
ALTER DATABASE mr3 SET SECONDARY REGION "us-east-1"
474477

pkg/sql/alter_database.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,6 +1548,16 @@ func (p *planner) AlterDatabaseAddSuperRegion(
15481548
return nil, err
15491549
}
15501550

1551+
// Validate no duplicate regions exist.
1552+
existingRegionNames := make(map[tree.Name]struct{})
1553+
for _, region := range n.Regions {
1554+
if _, found := existingRegionNames[region]; found {
1555+
return nil, pgerror.Newf(pgcode.DuplicateObject,
1556+
"duplicate region %s found in super region %s", region, n.SuperRegionName)
1557+
}
1558+
existingRegionNames[region] = struct{}{}
1559+
}
1560+
15511561
dbDesc, err := p.Descriptors().MutableByName(p.txn).Database(ctx, string(n.DatabaseName))
15521562
if err != nil {
15531563
return nil, err

0 commit comments

Comments
 (0)