Skip to content

sql: Prevent primary region being same as secondary region#87024

Merged
craig[bot] merged 2 commits intocockroachdb:masterfrom
e-mbrown:eb/snd_fix
Aug 31, 2022
Merged

sql: Prevent primary region being same as secondary region#87024
craig[bot] merged 2 commits intocockroachdb:masterfrom
e-mbrown:eb/snd_fix

Conversation

@e-mbrown
Copy link
Copy Markdown
Contributor

fixes #86879

We found that the primary region could be assigned the same region as the secondary region. This commit adds an error to prevent that.

Release justification: Low risk high benefit change to existing functionality
Release note: None

@e-mbrown e-mbrown requested review from a team and rafiss August 29, 2022 13:53
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @e-mbrown and @rafiss)


pkg/ccl/logictestccl/testdata/logic_test/secondary_region line 56 at r2 (raw file):


statement error pq: region .* is currently the secondary region
ALTER DATABASE db SET PRIMARY REGION "ca-central-1"

what about ALTER DATABASE db SET SECONDARY REGION "same-as-primary"? can you add a test for that?


pkg/sql/alter_database.go line 739 at r2 (raw file):

	}

	if prevRegionConfig.HasSecondaryRegion() && catpb.RegionName(n.n.PrimaryRegion) == prevRegionConfig.SecondaryRegion() {

can you also add validation to validateMultiRegion in pkg/sql/catalog/dbdesc/database_desc.go

Copy link
Copy Markdown
Contributor Author

@e-mbrown e-mbrown left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @rafiss)


pkg/ccl/logictestccl/testdata/logic_test/secondary_region line 56 at r2 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

what about ALTER DATABASE db SET SECONDARY REGION "same-as-primary"? can you add a test for that?

We have a test like that around ln 53

# Secondary region cannot be the current primary region.
statement error the secondary region cannot be the same as the current primary region
ALTER DATABASE db SET SECONDARY REGION "ap-southeast-2"

pkg/sql/alter_database.go line 739 at r2 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

can you also add validation to validateMultiRegion in pkg/sql/catalog/dbdesc/database_desc.go

I think i've added validation

Code quote (from pkg/sql/catalog/dbdesc/database_desc.go):

	if desc.RegionConfig.PrimaryRegion == desc.RegionConfig.SecondaryRegion {
		vea.Report(errors.AssertionFailedf(
			"primary region is same as secondary region on multi-region db %d", desc.GetID()))
	}

@e-mbrown e-mbrown requested a review from rafiss August 29, 2022 17:37
We found that the primary region could be assigned the same region
as the secondary region. This commit adds an error to prevent that.

Release justification: Low risk high benefit change to existing functionality
Release note: None
Fix notice message to be make it clearer.

Release justification: low risk changes to existing functionality
Release note: None
Copy link
Copy Markdown
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! nice

Reviewed 3 of 3 files at r5, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @rafiss)

@e-mbrown
Copy link
Copy Markdown
Contributor Author

TFTR

bors r=rafiss

@craig craig bot merged commit 0bcbece into cockroachdb:master Aug 31, 2022
@craig
Copy link
Copy Markdown
Contributor

craig bot commented Aug 31, 2022

Build succeeded:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sql: Primary Region can be set to the Secondary Region

3 participants