Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
59487: sql: Block adding a primary region to the system database r=otan a=ajstorm

Prevent users from adding a primary region to the system database, thus
preventing the system database from becoming a multi-region database.

Release note: None

Resolves cockroachdb#57760.

Co-authored-by: Adam Storm <[email protected]>
  • Loading branch information
craig[bot] and ajstorm committed Jan 28, 2021
2 parents 15369c8 + cec90eb commit bfe532e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/sql/alter_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"fmt"
"sort"

"github.com/cockroachdb/cockroach/pkg/keys"
"github.com/cockroachdb/cockroach/pkg/security"
"github.com/cockroachdb/cockroach/pkg/sql/catalog"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkv"
Expand Down Expand Up @@ -423,6 +424,15 @@ func (n *alterDatabasePrimaryRegionNode) startExec(params runParams) error {
return err
}

// Block adding a primary region to the system database. This ensures that the system
// database can never be made into a multi-region database.
if n.desc.GetID() == keys.SystemDatabaseID {
return pgerror.Newf(
pgcode.FeatureNotSupported,
"adding a primary region to the system database is not supported",
)
}

// There are two paths to consider here: either this is the first setting of the
// primary region, OR we're updating the primary region. In the case where this
// is the first setting of the primary region, the call will turn the database into
Expand Down
4 changes: 4 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/multiregion
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ USE new_db
statement error database new_db is not multi-region enabled, but table cannot_create_table_no_multiregion has locality GLOBAL set
CREATE TABLE cannot_create_table_no_multiregion (a int) LOCALITY GLOBAL

# Test adding a primary region to the system database.
statement error adding a primary region to the system database is not supported
ALTER DATABASE system PRIMARY REGION "ap-southeast-2"

statement ok
CREATE DATABASE alter_test_db primary region "ca-central-1"

Expand Down

0 comments on commit bfe532e

Please sign in to comment.