Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: fix dangling zone config on REGIONAL BY ROW -> REGIONAL BY TABLE #60659

Merged
merged 1 commit into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 36 additions & 36 deletions pkg/ccl/logictestccl/testdata/logic_test/alter_table_locality
Original file line number Diff line number Diff line change
Expand Up @@ -1465,15 +1465,15 @@ regional_by_row CREATE TABLE public.regional_by_
query TT
SHOW ZONE CONFIGURATION FOR TABLE regional_by_row
----
TABLE regional_by_row ALTER TABLE regional_by_row 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]]'
DATABASE alter_locality_test ALTER DATABASE alter_locality_test 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
DROP TABLE regional_by_row;
Expand Down Expand Up @@ -1537,15 +1537,15 @@ regional_by_row CREATE TABLE public.regional_by_
query TT
SHOW ZONE CONFIGURATION FOR TABLE regional_by_row
----
TABLE regional_by_row ALTER TABLE regional_by_row 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]]'
DATABASE alter_locality_test ALTER DATABASE alter_locality_test 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
DROP TABLE regional_by_row;
Expand Down Expand Up @@ -1792,15 +1792,15 @@ regional_by_row_as CREATE TABLE public.regional_by_
query TT
SHOW ZONE CONFIGURATION FOR TABLE regional_by_row_as
----
TABLE regional_by_row_as ALTER TABLE regional_by_row_as 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]]'
DATABASE alter_locality_test ALTER DATABASE alter_locality_test 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
DROP TABLE regional_by_row_as;
Expand Down Expand Up @@ -1866,15 +1866,15 @@ regional_by_row_as CREATE TABLE public.regional_by_
query TT
SHOW ZONE CONFIGURATION FOR TABLE regional_by_row_as
----
TABLE regional_by_row_as ALTER TABLE regional_by_row_as 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]]'
DATABASE alter_locality_test ALTER DATABASE alter_locality_test 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
DROP TABLE regional_by_row_as;
Expand Down
24 changes: 11 additions & 13 deletions pkg/sql/region_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,11 +454,10 @@ func applyZoneConfigForMultiRegionTableOptionNewIndexes(
}
}

// isRegionalByRowPlaceholderZoneConfig returns whether a given zone config
// should be marked as a placeholder config if the zone config belongs to
// a REGIONAL BY ROW table.
// isPlaceholderZoneConfigForMultiRegion returns whether a given zone config
// should be marked as a placeholder config for a multi-region object.
// See zonepb.IsSubzonePlaceholder for why this is necessary.
func isRegionalByRowPlaceholderZoneConfig(zc zonepb.ZoneConfig) bool {
func isPlaceholderZoneConfigForMultiRegion(zc zonepb.ZoneConfig) bool {
// Strip Subzones / SubzoneSpans, as these may contain items if migrating
// from one REGIONAL BY ROW table to another.
strippedZC := zc
Expand All @@ -484,11 +483,6 @@ func applyZoneConfigForMultiRegionTableOptionTableNewConfig(
return false, zonepb.ZoneConfig{}, err
}
zc.CopyFromZone(*localityZoneConfig, multiRegionZoneConfigFields)
if newConfig.GetRegionalByRow() != nil {
if isRegionalByRowPlaceholderZoneConfig(zc) {
zc.NumReplicas = proto.Int32(0)
}
}
return false, zc, nil
}
}
Expand All @@ -513,10 +507,6 @@ var ApplyZoneConfigForMultiRegionTableOptionTableAndIndexes = func(

hasNewSubzones := table.IsLocalityRegionalByRow()
if hasNewSubzones {
if isRegionalByRowPlaceholderZoneConfig(zc) {
zc.NumReplicas = proto.Int32(0)
}

for _, region := range regionConfig.Regions {
subzoneConfig, err := zoneConfigForMultiRegionPartition(region, regionConfig)
if err != nil {
Expand Down Expand Up @@ -568,6 +558,14 @@ func ApplyZoneConfigForMultiRegionTable(
zoneConfig = newZoneConfig
}

// Mark the NumReplicas as 0 if we have subzones but no other features
// in the zone config. This signifies a placeholder.
// Note we do not use hasNewSubzones here as there may be existing subzones
// on the zone config which may still be a placeholder.
if len(zoneConfig.Subzones) > 0 && isPlaceholderZoneConfigForMultiRegion(zoneConfig) {
zoneConfig.NumReplicas = proto.Int32(0)
}

if !zoneConfig.Equal(zonepb.NewZoneConfig()) {
if err := zoneConfig.Validate(); err != nil {
return pgerror.Newf(
Expand Down