From 91fbbcaa7aff337cdd4e634f8b5cfa4244322771 Mon Sep 17 00:00:00 2001 From: Nathan VanBenschoten Date: Fri, 22 Jan 2021 12:32:26 -0500 Subject: [PATCH] sql: use global_reads for GLOBAL tables This commit enables global_reads for tables with the GLOBAL locality config. global_reads are not yet hooked up in KV because we don't yet have per-range closed timestamp tracking, but this completes the SQL-level work for GLOBAL tables, with the exception of #57663, which will add non-voting replicas (at the database zone config level) for all database regions that don't already have a voting replica. Release note: None --- .../logictestccl/testdata/logic_test/alter_table_locality | 5 +++++ pkg/sql/logictest/testdata/logic_test/multiregion | 4 ++++ pkg/sql/region_util.go | 4 +++- pkg/sql/region_util_test.go | 4 +++- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/pkg/ccl/logictestccl/testdata/logic_test/alter_table_locality b/pkg/ccl/logictestccl/testdata/logic_test/alter_table_locality index 09330ef79091..5947267f270f 100644 --- a/pkg/ccl/logictestccl/testdata/logic_test/alter_table_locality +++ b/pkg/ccl/logictestccl/testdata/logic_test/alter_table_locality @@ -140,6 +140,7 @@ TABLE global ALTER TABLE global CONFIGURE ZONE USING range_min_bytes = 134217728, range_max_bytes = 536870912, gc.ttlseconds = 90000, + global_reads = true, num_replicas = 3, constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}', lease_preferences = '[[+region=ca-central-1]]' @@ -219,6 +220,7 @@ TABLE global ALTER TABLE global CONFIGURE ZONE USING range_min_bytes = 134217728, range_max_bytes = 536870912, gc.ttlseconds = 90000, + global_reads = true, num_replicas = 3, constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}', lease_preferences = '[[+region=ca-central-1]]' @@ -337,6 +339,7 @@ TABLE regional_by_table_in_primary_region ALTER TABLE regional_by_table_in_prim range_min_bytes = 134217728, range_max_bytes = 536870912, gc.ttlseconds = 90000, + global_reads = true, num_replicas = 3, constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}', lease_preferences = '[[+region=ca-central-1]]' @@ -450,6 +453,7 @@ TABLE regional_by_table_no_region ALTER TABLE regional_by_table_no_region CONFI range_min_bytes = 134217728, range_max_bytes = 536870912, gc.ttlseconds = 90000, + global_reads = true, num_replicas = 3, constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}', lease_preferences = '[[+region=ca-central-1]]' @@ -555,6 +559,7 @@ TABLE regional_by_table_in_us_east ALTER TABLE regional_by_table_in_us_east CON range_min_bytes = 134217728, range_max_bytes = 536870912, gc.ttlseconds = 90000, + global_reads = true, num_replicas = 3, constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}', lease_preferences = '[[+region=ca-central-1]]' diff --git a/pkg/sql/logictest/testdata/logic_test/multiregion b/pkg/sql/logictest/testdata/logic_test/multiregion index a6530ed77b49..e23600f4da7d 100644 --- a/pkg/sql/logictest/testdata/logic_test/multiregion +++ b/pkg/sql/logictest/testdata/logic_test/multiregion @@ -307,6 +307,7 @@ TABLE global_table ALTER TABLE global_table CONFIGURE ZONE USING range_min_bytes = 134217728, range_max_bytes = 536870912, gc.ttlseconds = 90000, + global_reads = true, num_replicas = 3, constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}', lease_preferences = '[[+region=ca-central-1]]' @@ -582,6 +583,7 @@ TABLE t_global ALTER TABLE t_global CONFIGURE ZONE USING range_min_bytes = 134217728, range_max_bytes = 536870912, gc.ttlseconds = 90000, + global_reads = true, num_replicas = 3, constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}', lease_preferences = '[[+region=ca-central-1]]' @@ -663,6 +665,7 @@ TABLE t_global ALTER TABLE t_global CONFIGURE ZONE USING range_min_bytes = 134217728, range_max_bytes = 536870912, gc.ttlseconds = 90000, + global_reads = true, num_replicas = 3, constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}', lease_preferences = '[[+region=ca-central-1]]' @@ -716,6 +719,7 @@ TABLE t_global ALTER TABLE t_global CONFIGURE ZONE USING range_min_bytes = 134217728, range_max_bytes = 536870912, gc.ttlseconds = 90000, + global_reads = true, num_replicas = 3, constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}', lease_preferences = '[[+region=ca-central-1]]' diff --git a/pkg/sql/region_util.go b/pkg/sql/region_util.go index d5ad4b9976d3..63b13ef038c5 100644 --- a/pkg/sql/region_util.go +++ b/pkg/sql/region_util.go @@ -214,7 +214,9 @@ func zoneConfigFromTableLocalityConfig( switch l := localityConfig.Locality.(type) { case *descpb.TableDescriptor_LocalityConfig_Global_: - // Inherit everything from the database. + // Enable non-blocking transactions. + ret.GlobalReads = proto.Bool(true) + // Inherit constraints and leaseholders from the database. ret.InheritedConstraints = true ret.InheritedLeasePreferences = true case *descpb.TableDescriptor_LocalityConfig_RegionalByTable_: diff --git a/pkg/sql/region_util_test.go b/pkg/sql/region_util_test.go index 8778c88645a7..9d67daee9c30 100644 --- a/pkg/sql/region_util_test.go +++ b/pkg/sql/region_util_test.go @@ -205,6 +205,7 @@ func TestZoneConfigFromTableLocalityConfig(t *testing.T) { SurvivalGoal: descpb.SurvivalGoal_ZONE_FAILURE, }, expected: &zonepb.ZoneConfig{ + GlobalReads: proto.Bool(true), NumReplicas: proto.Int32(4), InheritedConstraints: true, InheritedLeasePreferences: true, @@ -228,6 +229,7 @@ func TestZoneConfigFromTableLocalityConfig(t *testing.T) { SurvivalGoal: descpb.SurvivalGoal_REGION_FAILURE, }, expected: &zonepb.ZoneConfig{ + GlobalReads: proto.Bool(true), NumReplicas: proto.Int32(4), InheritedConstraints: true, InheritedLeasePreferences: true, @@ -434,7 +436,7 @@ func TestZoneConfigFromRegionConfigForPartition(t *testing.T) { }, }, { - desc: "4-region global table with region survivability", + desc: "4-region table with region survivability", region: descpb.DatabaseDescriptor_RegionConfig_Region{ Name: "region_a", },