Skip to content

Commit

Permalink
sql: update database zone configurations after region drop finalization
Browse files Browse the repository at this point in the history
Previously, database level zone configurations weren't updated when the
region drop was finalized. This patch adds that support.

This patch also moves setting zone configurations on ADD REGION from
the user txn to the type schema changer. This ensures that zone
configurations are added transactionally -- if the ADD REGION fails for
whatever reason, we no longer leave behind dangling zone config.

Lastly, I've refactored some test setup code that was being duplicated
and improved the tests around rollback to test additional scenarios.

Closes cockroachdb#60435
Closes cockroachdb#60750

Release note: None

Release justification: bug fixes and low-risk updates to new
functionality
  • Loading branch information
arulajmani committed Feb 25, 2021
1 parent 2d16ce1 commit 3d27f71
Show file tree
Hide file tree
Showing 8 changed files with 237 additions and 173 deletions.
32 changes: 32 additions & 0 deletions pkg/ccl/logictestccl/testdata/logic_test/multi_region
Original file line number Diff line number Diff line change
Expand Up @@ -1083,3 +1083,35 @@ ALTER TABLE drop_primary_regions_db.primary SET LOCALITY REGIONAL BY TABLE IN PR

statement ok
ALTER DATABASE drop_primary_regions_db DROP REGION "ca-central-1"

statement ok
CREATE DATABASE zone_config_drop_region PRIMARY REGION "ca-central-1" REGIONS "us-east-1", "ap-southeast-2"

query TT
SHOW ZONE CONFIGURATION FOR DATABASE zone_config_drop_region
----
DATABASE zone_config_drop_region ALTER DATABASE zone_config_drop_region CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 5,
num_voters = 3,
constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}',
voter_constraints = '[+region=ca-central-1]',
lease_preferences = '[[+region=ca-central-1]]'

statement ok
ALTER DATABASE zone_config_drop_region DROP REGION "us-east-1"

query TT
SHOW ZONE CONFIGURATION FOR DATABASE zone_config_drop_region
----
DATABASE zone_config_drop_region ALTER DATABASE zone_config_drop_region CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 4,
num_voters = 3,
constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1}',
voter_constraints = '[+region=ca-central-1]',
lease_preferences = '[[+region=ca-central-1]]'
24 changes: 12 additions & 12 deletions pkg/ccl/logictestccl/testdata/logic_test/regional_by_row
Original file line number Diff line number Diff line change
Expand Up @@ -1768,9 +1768,9 @@ DATABASE drop_regions ALTER DATABASE drop_regions CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 5,
num_replicas = 4,
num_voters = 3,
constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}',
constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1}',
voter_constraints = '[+region=ca-central-1]',
lease_preferences = '[[+region=ca-central-1]]'

Expand Down Expand Up @@ -1810,9 +1810,9 @@ DATABASE drop_regions ALTER DATABASE drop_regions CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 5,
num_replicas = 4,
num_voters = 3,
constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}',
constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1}',
voter_constraints = '[+region=ca-central-1]',
lease_preferences = '[[+region=ca-central-1]]'

Expand Down Expand Up @@ -1860,9 +1860,9 @@ DATABASE drop_regions ALTER DATABASE drop_regions CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 5,
num_replicas = 4,
num_voters = 3,
constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}',
constraints = '{+region=ca-central-1: 1, +region=us-east-1: 1}',
voter_constraints = '[+region=ca-central-1]',
lease_preferences = '[[+region=ca-central-1]]'

Expand Down Expand Up @@ -1902,9 +1902,9 @@ DATABASE drop_regions ALTER DATABASE drop_regions CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 5,
num_replicas = 4,
num_voters = 3,
constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}',
constraints = '{+region=ca-central-1: 1, +region=us-east-1: 1}',
voter_constraints = '[+region=ca-central-1]',
lease_preferences = '[[+region=ca-central-1]]'

Expand Down Expand Up @@ -1942,9 +1942,9 @@ DATABASE drop_regions ALTER DATABASE drop_regions CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 5,
num_replicas = 3,
num_voters = 3,
constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}',
constraints = '{+region=ca-central-1: 1}',
voter_constraints = '[+region=ca-central-1]',
lease_preferences = '[[+region=ca-central-1]]'

Expand All @@ -1955,9 +1955,9 @@ DATABASE drop_regions ALTER DATABASE drop_regions CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 90000,
num_replicas = 5,
num_replicas = 3,
num_voters = 3,
constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}',
constraints = '{+region=ca-central-1: 1}',
voter_constraints = '[+region=ca-central-1]',
lease_preferences = '[[+region=ca-central-1]]'

Expand Down
9 changes: 8 additions & 1 deletion pkg/ccl/multiregionccl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "multiregionccl",
srcs = ["multiregion.go"],
srcs = [
"multiregion.go",
"testutils.go",
],
importpath = "github.com/cockroachdb/cockroach/pkg/ccl/multiregionccl",
visibility = ["//visibility:public"],
deps = [
"//pkg/base",
"//pkg/clusterversion",
"//pkg/roachpb",
"//pkg/sql",
"//pkg/sql/catalog/catalogkv",
"//pkg/sql/catalog/descpb",
"//pkg/sql/pgwire/pgcode",
"//pkg/sql/pgwire/pgerror",
"//pkg/sql/sem/tree",
"//pkg/testutils/serverutils",
],
)

Expand All @@ -25,6 +31,7 @@ go_test(
"show_test.go",
],
deps = [
":multiregionccl",
"//pkg/base",
"//pkg/ccl/partitionccl",
"//pkg/ccl/utilccl",
Expand Down
Loading

0 comments on commit 3d27f71

Please sign in to comment.