From e6925ae5581c245da036b0a1c9afc6b8e095cbf0 Mon Sep 17 00:00:00 2001 From: irfan sharif Date: Tue, 21 Dec 2021 14:46:03 -0500 Subject: [PATCH] spanconfig: carve empty ranges for pseudo-table IDs This commit is similar in spirit to #73746 in that it gets rid of a benign difference between the span configs infrastructure and the system config span. Whe nnabling span configs by default (#73876), we observed a wide blast radius with respect to test failures. This was in large part due to assumptions we've baked in regarding the number of splits we should expect at cluster start, often waiting for the same number of ranges to form before executing the rest of the test. The differences between the SystemConfigSpan and the span configs infrastructure in how they handled (empty) pseudo table keyspaces makes for an annoying large list of tests to adjust manually. Instead we take the lazy route and generate empty ranges for pseudo table IDs as we did before. We can get rid of this special handling once we actually get rid of the system config span, and adjust all these tests accordingly. Doing it later is also preferable should we need to revert pieces of #73876 due to unforeseen instability. Release note: None --- .../spanconfigcomparedccl/datadriven_test.go | 3 + .../spanconfigcomparedccl/testdata/basic | 46 +----- .../testdata/multitenant | 23 ++- .../spanconfigreconcilerccl/testdata/basic | 28 +++- .../spanconfigreconcilerccl/testdata/indexes | 10 +- .../testdata/multitenant/basic | 6 +- .../testdata/named_zones | 4 +- .../testdata/partitions | 16 +- .../testdata/full_translate | 6 + .../full_translate_named_zones_deleted | 6 + .../testdata/system_database | 153 ++++++++++++++++++ pkg/spanconfig/spanconfig.go | 13 +- .../spanconfigsqltranslator/sqltranslator.go | 48 ++++++ pkg/sql/zone_config.go | 25 +++ 14 files changed, 307 insertions(+), 80 deletions(-) create mode 100644 pkg/ccl/spanconfigccl/spanconfigsqltranslatorccl/testdata/system_database diff --git a/pkg/ccl/spanconfigccl/spanconfigcomparedccl/datadriven_test.go b/pkg/ccl/spanconfigccl/spanconfigcomparedccl/datadriven_test.go index d72aec6b2719..e2eec1d5293d 100644 --- a/pkg/ccl/spanconfigccl/spanconfigcomparedccl/datadriven_test.go +++ b/pkg/ccl/spanconfigccl/spanconfigcomparedccl/datadriven_test.go @@ -240,6 +240,9 @@ func TestDataDriven(t *testing.T) { Context: 2, }) require.NoError(t, err) + if diff == "" { + return "" + } lines := strings.Split(strings.TrimSpace(diff), "\n") headerLines, diffLines := lines[:2], lines[2:] diff --git a/pkg/ccl/spanconfigccl/spanconfigcomparedccl/testdata/basic b/pkg/ccl/spanconfigccl/spanconfigcomparedccl/testdata/basic index 4eab2025cdab..74e6eb111623 100644 --- a/pkg/ccl/spanconfigccl/spanconfigcomparedccl/testdata/basic +++ b/pkg/ccl/spanconfigccl/spanconfigcomparedccl/testdata/basic @@ -37,47 +37,9 @@ configs version=current offset=4 limit=3 /Table/11 range system ... -# The gossiped system config span splits (needlessly) on pseudo table IDs; the -# new subsystem doesn't. -# -# MetaRangesID = 16 // pseudo -# SystemRangesID = 17 // pseudo -# TimeseriesRangesID = 18 // pseudo -# LivenessRangesID = 22 // pseudo -# PublicSchemaID = 29 // pseudo -# TenantsRangesID = 38 // pseudo - -diff offset=2 limit=21 ----- ---- gossiped system config span (legacy) -+++ span config infrastructure (current) -... - /Table/15 range system --/Table/16 range system --/Table/17 range system --/Table/18 range system - /Table/19 range system - /Table/20 range system - /Table/21 range system --/Table/22 range system - /Table/23 range system - /Table/24 range system -@@ -23,5 +19,4 @@ - /Table/27 ttl_seconds=600 num_replicas=5 - /Table/28 range system --/Table/29 range system - /NamespaceTable/30 range system - /NamespaceTable/Max range system -@@ -32,5 +27,4 @@ - /Table/36 range system - /Table/37 range system --/Table/38 range system - /Table/39 range system - ... - # Both subsystems observe splits for the tables created above. -configs version=current offset=35 +configs version=current offset=41 ---- ... /Table/46 range system @@ -93,4 +55,10 @@ configs version=legacy offset=41 /Table/56 num_replicas=7 num_voters=5 /Table/57 num_replicas=7 +# Both subsystems are identical with respect to exposed configs (including for +# pseudo table IDs). + +diff +---- + # vim:ft=diff diff --git a/pkg/ccl/spanconfigccl/spanconfigcomparedccl/testdata/multitenant b/pkg/ccl/spanconfigccl/spanconfigcomparedccl/testdata/multitenant index 2cd15bb7d076..3c2449d34d17 100644 --- a/pkg/ccl/spanconfigccl/spanconfigcomparedccl/testdata/multitenant +++ b/pkg/ccl/spanconfigccl/spanconfigcomparedccl/testdata/multitenant @@ -12,26 +12,23 @@ initialize tenant=11 ---- # Before kicking starting off tenant reconciliation, we should find seed -# configs for the newly initialized tenants. As yet, there are no (additional) -# differences between the subsystems. -configs version=current offset=37 +# configs for the newly initialized tenants. As yet, there are no differences +# between the subsystems. +configs version=current offset=43 ---- ... /Tenant/10 range default /Tenant/11 range default -diff offset=24 +diff ---- ---- gossiped system config span (legacy) -+++ span config infrastructure (current) -... reconcile tenant=11 ---- # As soon as tenant-11 starts reconciling, we should observe more fine-grained # span configs within its keyspan. This isn't true for the legacy system. -configs version=current offset=37 limit=5 +configs version=current offset=43 limit=5 ---- ... /Tenant/10 range default @@ -47,12 +44,11 @@ configs version=legacy offset=43 /Tenant/10 range default /Tenant/11 range default -diff offset=24 limit=10 +diff limit=10 ---- --- gossiped system config span (legacy) +++ span config infrastructure (current) -... -@@ -44,3 +38,36 @@ +@@ -44,3 +44,36 @@ /Tenant/10 range default /Tenant/11 range default +/Tenant/11/Table/4 range default @@ -73,12 +69,11 @@ CREATE TABLE db.t2(); ALTER TABLE db.t1 CONFIGURE ZONE using num_replicas = 42, gc.ttlseconds = 1000; ---- -diff offset=24 +diff ---- --- gossiped system config span (legacy) +++ span config infrastructure (current) -... -@@ -44,3 +38,38 @@ +@@ -44,3 +44,38 @@ /Tenant/10 range default /Tenant/11 range default +/Tenant/11/Table/4 range default diff --git a/pkg/ccl/spanconfigccl/spanconfigreconcilerccl/testdata/basic b/pkg/ccl/spanconfigccl/spanconfigreconcilerccl/testdata/basic index 722304a32b4a..672e67ff93f9 100644 --- a/pkg/ccl/spanconfigccl/spanconfigreconcilerccl/testdata/basic +++ b/pkg/ccl/spanconfigccl/spanconfigreconcilerccl/testdata/basic @@ -22,15 +22,20 @@ upsert /Table/1{2-3} range system upsert /Table/1{3-4} range system upsert /Table/1{4-5} range system upsert /Table/1{5-6} range system +upsert /Table/1{6-7} range system +upsert /Table/1{7-8} range system +upsert /Table/1{8-9} range system upsert /Table/{19-20} range system upsert /Table/2{0-1} range system upsert /Table/2{1-2} range system +upsert /Table/2{2-3} range system upsert /Table/2{3-4} range system upsert /Table/2{4-5} range system upsert /Table/2{5-6} ttl_seconds=600 num_replicas=5 upsert /Table/2{6-7} range system upsert /Table/2{7-8} ttl_seconds=600 num_replicas=5 upsert /Table/2{8-9} range system +upsert /{Table/29-NamespaceTable/30} range system upsert /NamespaceTable/{30-Max} range system upsert /{NamespaceTable/Max-Table/32} range system upsert /Table/3{2-3} range system @@ -39,6 +44,7 @@ upsert /Table/3{4-5} range system upsert /Table/3{5-6} range system upsert /Table/3{6-7} range system upsert /Table/3{7-8} range system +upsert /Table/3{8-9} range system upsert /Table/{39-40} range system upsert /Table/4{0-1} range system upsert /Table/4{1-2} range system @@ -74,7 +80,7 @@ upsert /Table/5{6-7} num_replicas=7 num_voters=5 delete /Table/5{7-8} upsert /Table/5{7-8} num_replicas=7 -state offset=41 +state offset=47 ---- ... /Table/5{6-7} num_replicas=7 num_voters=5 @@ -106,12 +112,20 @@ delete /Table/1{4-5} upsert /Table/1{4-5} ttl_seconds=100 num_replicas=5 delete /Table/1{5-6} upsert /Table/1{5-6} ttl_seconds=100 num_replicas=5 +delete /Table/1{6-7} +upsert /Table/1{6-7} ttl_seconds=100 num_replicas=5 +delete /Table/1{7-8} +upsert /Table/1{7-8} ttl_seconds=100 num_replicas=5 +delete /Table/1{8-9} +upsert /Table/1{8-9} ttl_seconds=100 num_replicas=5 delete /Table/{19-20} upsert /Table/{19-20} ttl_seconds=100 num_replicas=5 delete /Table/2{0-1} upsert /Table/2{0-1} ttl_seconds=100 num_replicas=5 delete /Table/2{1-2} upsert /Table/2{1-2} ttl_seconds=100 num_replicas=5 +delete /Table/2{2-3} +upsert /Table/2{2-3} ttl_seconds=100 num_replicas=5 delete /Table/2{3-4} upsert /Table/2{3-4} ttl_seconds=100 num_replicas=5 delete /Table/2{4-5} @@ -120,6 +134,8 @@ delete /Table/2{6-7} upsert /Table/2{6-7} ttl_seconds=100 num_replicas=5 delete /Table/2{8-9} upsert /Table/2{8-9} ttl_seconds=100 num_replicas=5 +delete /{Table/29-NamespaceTable/30} +upsert /{Table/29-NamespaceTable/30} ttl_seconds=100 num_replicas=5 delete /NamespaceTable/{30-Max} upsert /NamespaceTable/{30-Max} ttl_seconds=100 num_replicas=5 delete /{NamespaceTable/Max-Table/32} @@ -136,6 +152,8 @@ delete /Table/3{6-7} upsert /Table/3{6-7} ttl_seconds=100 num_replicas=5 delete /Table/3{7-8} upsert /Table/3{7-8} ttl_seconds=100 num_replicas=5 +delete /Table/3{8-9} +upsert /Table/3{8-9} ttl_seconds=100 num_replicas=5 delete /Table/{39-40} upsert /Table/{39-40} ttl_seconds=100 num_replicas=5 delete /Table/4{0-1} @@ -153,7 +171,7 @@ upsert /Table/4{6-7} ttl_seconds=100 num_replicas=5 delete /Table/4{7-8} upsert /Table/4{7-8} ttl_seconds=100 num_replicas=5 -state offset=5 limit=36 +state offset=5 limit=42 ---- ... /Table/{SystemConfigSpan/Start-4} ttl_seconds=100 num_replicas=5 @@ -166,15 +184,20 @@ state offset=5 limit=36 /Table/1{3-4} ttl_seconds=100 num_replicas=5 /Table/1{4-5} ttl_seconds=100 num_replicas=5 /Table/1{5-6} ttl_seconds=100 num_replicas=5 +/Table/1{6-7} ttl_seconds=100 num_replicas=5 +/Table/1{7-8} ttl_seconds=100 num_replicas=5 +/Table/1{8-9} ttl_seconds=100 num_replicas=5 /Table/{19-20} ttl_seconds=100 num_replicas=5 /Table/2{0-1} ttl_seconds=100 num_replicas=5 /Table/2{1-2} ttl_seconds=100 num_replicas=5 +/Table/2{2-3} ttl_seconds=100 num_replicas=5 /Table/2{3-4} ttl_seconds=100 num_replicas=5 /Table/2{4-5} ttl_seconds=100 num_replicas=5 /Table/2{5-6} ttl_seconds=600 num_replicas=5 /Table/2{6-7} ttl_seconds=100 num_replicas=5 /Table/2{7-8} ttl_seconds=600 num_replicas=5 /Table/2{8-9} ttl_seconds=100 num_replicas=5 +/{Table/29-NamespaceTable/30} ttl_seconds=100 num_replicas=5 /NamespaceTable/{30-Max} ttl_seconds=100 num_replicas=5 /{NamespaceTable/Max-Table/32} ttl_seconds=100 num_replicas=5 /Table/3{2-3} ttl_seconds=100 num_replicas=5 @@ -183,6 +206,7 @@ state offset=5 limit=36 /Table/3{5-6} ttl_seconds=100 num_replicas=5 /Table/3{6-7} ttl_seconds=100 num_replicas=5 /Table/3{7-8} ttl_seconds=100 num_replicas=5 +/Table/3{8-9} ttl_seconds=100 num_replicas=5 /Table/{39-40} ttl_seconds=100 num_replicas=5 /Table/4{0-1} ttl_seconds=100 num_replicas=5 /Table/4{1-2} ttl_seconds=100 num_replicas=5 diff --git a/pkg/ccl/spanconfigccl/spanconfigreconcilerccl/testdata/indexes b/pkg/ccl/spanconfigccl/spanconfigreconcilerccl/testdata/indexes index 77dc632798dd..513185592128 100644 --- a/pkg/ccl/spanconfigccl/spanconfigreconcilerccl/testdata/indexes +++ b/pkg/ccl/spanconfigccl/spanconfigreconcilerccl/testdata/indexes @@ -18,7 +18,7 @@ mutations ---- upsert /Table/5{6-7} range default -state offset=41 +state offset=47 ---- ... /Table/5{6-7} range default @@ -39,7 +39,7 @@ upsert /Table/56{-/2} num_replicas=7 upsert /Table/56/{2-3} num_replicas=7 num_voters=5 upsert /Table/5{6/3-7} num_replicas=7 -state offset=41 +state offset=47 ---- ... /Table/56{-/2} num_replicas=7 @@ -62,7 +62,7 @@ upsert /Table/56/{2-3} ttl_seconds=25 num_replicas=7 num_vot delete /Table/5{6/3-7} upsert /Table/5{6/3-7} ttl_seconds=3600 num_replicas=7 -state offset=41 +state offset=47 ---- ... /Table/56{-/2} ttl_seconds=3600 num_replicas=7 @@ -75,7 +75,7 @@ exec-sql ALTER TABLE db.t CONFIGURE ZONE USING num_replicas = 9 ---- -state offset=41 +state offset=47 ---- ... /Table/56{-/2} ttl_seconds=3600 num_replicas=9 @@ -101,7 +101,7 @@ delete /Table/56{-/2} delete /Table/56/{2-3} delete /Table/5{6/3-7} -state offset=40 +state offset=46 ---- ... /Table/4{7-8} range system diff --git a/pkg/ccl/spanconfigccl/spanconfigreconcilerccl/testdata/multitenant/basic b/pkg/ccl/spanconfigccl/spanconfigreconcilerccl/testdata/multitenant/basic index 494b3baa348c..1c60fa191853 100644 --- a/pkg/ccl/spanconfigccl/spanconfigreconcilerccl/testdata/multitenant/basic +++ b/pkg/ccl/spanconfigccl/spanconfigreconcilerccl/testdata/multitenant/basic @@ -19,7 +19,7 @@ mutations # We should observe placeholder entries for both tenants (installed when # creating tenant records). -state offset=41 +state offset=47 ---- ... /Tenant/10{-"\x00"} range default @@ -67,7 +67,7 @@ upsert /Tenant/10/Table/4{3-4} range default upsert /Tenant/10/Table/4{4-5} range default upsert /Tenant/10/Table/4{6-7} range default -state offset=41 +state offset=47 ---- ... /Tenant/10{-/Table/4} range default @@ -117,7 +117,7 @@ mutations tenant=10 upsert /Tenant/10/Table/5{6-7} range default upsert /Tenant/10/Table/5{7-8} range default -state offset=75 +state offset=81 ---- ... /Tenant/10/Table/5{6-7} range default diff --git a/pkg/ccl/spanconfigccl/spanconfigreconcilerccl/testdata/named_zones b/pkg/ccl/spanconfigccl/spanconfigreconcilerccl/testdata/named_zones index 50d47fa30f75..bec82de1514d 100644 --- a/pkg/ccl/spanconfigccl/spanconfigreconcilerccl/testdata/named_zones +++ b/pkg/ccl/spanconfigccl/spanconfigreconcilerccl/testdata/named_zones @@ -120,7 +120,7 @@ state limit=5 /System{tse-/Max} ttl_seconds=50 ... -state offset=40 +state offset=46 ---- ... /Table/4{7-8} range system @@ -135,7 +135,7 @@ mutations ---- upsert /Table/5{7-8} ttl_seconds=50 -state offset=40 +state offset=46 ---- ... /Table/4{7-8} range system diff --git a/pkg/ccl/spanconfigccl/spanconfigreconcilerccl/testdata/partitions b/pkg/ccl/spanconfigccl/spanconfigreconcilerccl/testdata/partitions index 995716994612..52a96a86d023 100644 --- a/pkg/ccl/spanconfigccl/spanconfigreconcilerccl/testdata/partitions +++ b/pkg/ccl/spanconfigccl/spanconfigreconcilerccl/testdata/partitions @@ -10,7 +10,7 @@ reconcile mutations discard ---- -state offset=41 +state offset=47 ---- ... @@ -29,7 +29,7 @@ mutations ---- upsert /Table/5{6-7} range default -state offset=41 +state offset=47 ---- ... /Table/5{6-7} range default @@ -45,7 +45,7 @@ mutations delete /Table/5{6-7} upsert /Table/5{6-7} num_replicas=7 num_voters=5 -state offset=41 +state offset=47 ---- ... /Table/5{6-7} num_replicas=7 num_voters=5 @@ -66,7 +66,7 @@ upsert /Table/56/1/{1-2} global_reads=true num_replicas=7 num_ upsert /Table/56/1/{2-3} global_reads=true num_replicas=7 num_voters=5 upsert /Table/5{6/1/3-7} num_replicas=7 num_voters=5 -state offset=41 +state offset=47 ---- ... /Table/56{-/1/1} num_replicas=7 num_voters=5 @@ -87,7 +87,7 @@ upsert /Table/56/1/{3-4} ttl_seconds=5 num_replicas=7 num_vote upsert /Table/56/1/{4-5} ttl_seconds=5 num_replicas=7 num_voters=5 upsert /Table/5{6/1/5-7} num_replicas=7 num_voters=5 -state offset=41 +state offset=47 ---- ... /Table/56{-/1/1} num_replicas=7 num_voters=5 @@ -122,7 +122,7 @@ delete /Table/5{6/1/5-7} upsert /Table/56/{1/5-2} num_replicas=7 num_voters=6 upsert /Table/5{6/2-7} num_replicas=7 num_voters=5 -state offset=41 +state offset=47 ---- ... /Table/56{-/1} num_replicas=7 num_voters=5 @@ -155,7 +155,7 @@ upsert /Table/56/1/{4-5} ttl_seconds=5 num_replicas=7 delete /Table/5{6/2-7} upsert /Table/5{6/2-7} num_replicas=7 -state offset=41 +state offset=47 ---- ... /Table/56{-/1} num_replicas=7 @@ -182,6 +182,6 @@ delete /Table/56/1/{4-5} delete /Table/56/{1/5-2} delete /Table/5{6/2-7} -state offset=41 +state offset=47 ---- ... diff --git a/pkg/ccl/spanconfigccl/spanconfigsqltranslatorccl/testdata/full_translate b/pkg/ccl/spanconfigccl/spanconfigsqltranslatorccl/testdata/full_translate index f20888f2468a..73eaf701863c 100644 --- a/pkg/ccl/spanconfigccl/spanconfigsqltranslatorccl/testdata/full_translate +++ b/pkg/ccl/spanconfigccl/spanconfigsqltranslatorccl/testdata/full_translate @@ -35,15 +35,20 @@ full-translate /Table/1{3-4} range system /Table/1{4-5} range system /Table/1{5-6} range system +/Table/1{6-7} range system +/Table/1{7-8} range system +/Table/1{8-9} range system /Table/{19-20} range system /Table/2{0-1} range system /Table/2{1-2} range system +/Table/2{2-3} range system /Table/2{3-4} range system /Table/2{4-5} range system /Table/2{5-6} ttl_seconds=600 num_replicas=5 /Table/2{6-7} range system /Table/2{7-8} ttl_seconds=600 num_replicas=5 /Table/2{8-9} range system +/{Table/29-NamespaceTable/30} range system /NamespaceTable/{30-Max} range system /{NamespaceTable/Max-Table/32} range system /Table/3{2-3} range system @@ -52,6 +57,7 @@ full-translate /Table/3{5-6} range system /Table/3{6-7} range system /Table/3{7-8} range system +/Table/3{8-9} range system /Table/{39-40} range system /Table/4{0-1} range system /Table/4{1-2} range system diff --git a/pkg/ccl/spanconfigccl/spanconfigsqltranslatorccl/testdata/full_translate_named_zones_deleted b/pkg/ccl/spanconfigccl/spanconfigsqltranslatorccl/testdata/full_translate_named_zones_deleted index 9c860c8d88a6..ff7fea1c70af 100644 --- a/pkg/ccl/spanconfigccl/spanconfigsqltranslatorccl/testdata/full_translate_named_zones_deleted +++ b/pkg/ccl/spanconfigccl/spanconfigsqltranslatorccl/testdata/full_translate_named_zones_deleted @@ -51,15 +51,20 @@ full-translate /Table/1{3-4} range system /Table/1{4-5} range system /Table/1{5-6} range system +/Table/1{6-7} range system +/Table/1{7-8} range system +/Table/1{8-9} range system /Table/{19-20} range system /Table/2{0-1} range system /Table/2{1-2} range system +/Table/2{2-3} range system /Table/2{3-4} range system /Table/2{4-5} range system /Table/2{5-6} ttl_seconds=600 num_replicas=5 /Table/2{6-7} range system /Table/2{7-8} ttl_seconds=600 num_replicas=5 /Table/2{8-9} range system +/{Table/29-NamespaceTable/30} range system /NamespaceTable/{30-Max} range system /{NamespaceTable/Max-Table/32} range system /Table/3{2-3} range system @@ -68,6 +73,7 @@ full-translate /Table/3{5-6} range system /Table/3{6-7} range system /Table/3{7-8} range system +/Table/3{8-9} range system /Table/{39-40} range system /Table/4{0-1} range system /Table/4{1-2} range system diff --git a/pkg/ccl/spanconfigccl/spanconfigsqltranslatorccl/testdata/system_database b/pkg/ccl/spanconfigccl/spanconfigsqltranslatorccl/testdata/system_database new file mode 100644 index 000000000000..0522dd09cf23 --- /dev/null +++ b/pkg/ccl/spanconfigccl/spanconfigsqltranslatorccl/testdata/system_database @@ -0,0 +1,153 @@ +# Translating the system database itself should surface entries for all system +# tables (including pseudo table IDs). + +translate database=system +---- +/Table/{SystemConfigSpan/Start-4} range system +/Table/{4-5} range system +/Table/{5-6} range system +/Table/{6-7} range system +/Table/{8-9} range system +/Table/1{1-2} range system +/Table/1{2-3} range system +/Table/1{3-4} range system +/Table/1{4-5} range system +/Table/1{5-6} range system +/Table/1{6-7} range system +/Table/1{7-8} range system +/Table/1{8-9} range system +/Table/{19-20} range system +/Table/2{0-1} range system +/Table/2{1-2} range system +/Table/2{2-3} range system +/Table/2{3-4} range system +/Table/2{4-5} range system +/Table/2{5-6} ttl_seconds=600 num_replicas=5 +/Table/2{6-7} range system +/Table/2{7-8} ttl_seconds=600 num_replicas=5 +/Table/2{8-9} range system +/{Table/29-NamespaceTable/30} range system +/NamespaceTable/{30-Max} range system +/{NamespaceTable/Max-Table/32} range system +/Table/3{2-3} range system +/Table/3{3-4} range system +/Table/3{4-5} range system +/Table/3{5-6} range system +/Table/3{6-7} range system +/Table/3{7-8} range system +/Table/3{8-9} range system +/Table/{39-40} range system +/Table/4{0-1} range system +/Table/4{1-2} range system +/Table/4{2-3} range system +/Table/4{3-4} range system +/Table/4{4-5} range system +/Table/4{5-6} ttl_seconds=7200 num_replicas=5 +/Table/4{6-7} range system +/Table/4{7-8} range system + +# Alter zone config fields on the database to ensure the effects cascade. +exec-sql +ALTER DATABASE system CONFIGURE ZONE USING num_replicas = 7 +---- + +translate database=system +---- +/Table/{SystemConfigSpan/Start-4} num_replicas=7 +/Table/{4-5} num_replicas=7 +/Table/{5-6} num_replicas=7 +/Table/{6-7} num_replicas=7 +/Table/{8-9} num_replicas=7 +/Table/1{1-2} num_replicas=7 +/Table/1{2-3} num_replicas=7 +/Table/1{3-4} num_replicas=7 +/Table/1{4-5} num_replicas=7 +/Table/1{5-6} num_replicas=7 +/Table/1{6-7} num_replicas=7 +/Table/1{7-8} num_replicas=7 +/Table/1{8-9} num_replicas=7 +/Table/{19-20} num_replicas=7 +/Table/2{0-1} num_replicas=7 +/Table/2{1-2} num_replicas=7 +/Table/2{2-3} num_replicas=7 +/Table/2{3-4} num_replicas=7 +/Table/2{4-5} num_replicas=7 +/Table/2{5-6} ttl_seconds=600 num_replicas=7 +/Table/2{6-7} num_replicas=7 +/Table/2{7-8} ttl_seconds=600 num_replicas=7 +/Table/2{8-9} num_replicas=7 +/{Table/29-NamespaceTable/30} num_replicas=7 +/NamespaceTable/{30-Max} num_replicas=7 +/{NamespaceTable/Max-Table/32} num_replicas=7 +/Table/3{2-3} num_replicas=7 +/Table/3{3-4} num_replicas=7 +/Table/3{4-5} num_replicas=7 +/Table/3{5-6} num_replicas=7 +/Table/3{6-7} num_replicas=7 +/Table/3{7-8} num_replicas=7 +/Table/3{8-9} num_replicas=7 +/Table/{39-40} num_replicas=7 +/Table/4{0-1} num_replicas=7 +/Table/4{1-2} num_replicas=7 +/Table/4{2-3} num_replicas=7 +/Table/4{3-4} num_replicas=7 +/Table/4{4-5} num_replicas=7 +/Table/4{5-6} ttl_seconds=7200 num_replicas=7 +/Table/4{6-7} num_replicas=7 +/Table/4{7-8} num_replicas=7 + +# Alter a named range that maps to a pseudo table ID, ensuring that its effects +# are independent. +exec-sql +ALTER RANGE liveness CONFIGURE ZONE USING num_replicas = 5 +---- + +full-translate +---- +/{Min-System/NodeLiveness} ttl_seconds=3600 num_replicas=5 +/System/NodeLiveness{-Max} ttl_seconds=600 num_replicas=5 +/System/{NodeLivenessMax-tsd} range system +/System{/tsd-tse} range default +/System{tse-/Max} range system +/Table/{SystemConfigSpan/Start-4} num_replicas=7 +/Table/{4-5} num_replicas=7 +/Table/{5-6} num_replicas=7 +/Table/{6-7} num_replicas=7 +/Table/{8-9} num_replicas=7 +/Table/1{1-2} num_replicas=7 +/Table/1{2-3} num_replicas=7 +/Table/1{3-4} num_replicas=7 +/Table/1{4-5} num_replicas=7 +/Table/1{5-6} num_replicas=7 +/Table/1{6-7} num_replicas=7 +/Table/1{7-8} num_replicas=7 +/Table/1{8-9} num_replicas=7 +/Table/{19-20} num_replicas=7 +/Table/2{0-1} num_replicas=7 +/Table/2{1-2} num_replicas=7 +/Table/2{2-3} num_replicas=7 +/Table/2{3-4} num_replicas=7 +/Table/2{4-5} num_replicas=7 +/Table/2{5-6} ttl_seconds=600 num_replicas=7 +/Table/2{6-7} num_replicas=7 +/Table/2{7-8} ttl_seconds=600 num_replicas=7 +/Table/2{8-9} num_replicas=7 +/{Table/29-NamespaceTable/30} num_replicas=7 +/NamespaceTable/{30-Max} num_replicas=7 +/{NamespaceTable/Max-Table/32} num_replicas=7 +/Table/3{2-3} num_replicas=7 +/Table/3{3-4} num_replicas=7 +/Table/3{4-5} num_replicas=7 +/Table/3{5-6} num_replicas=7 +/Table/3{6-7} num_replicas=7 +/Table/3{7-8} num_replicas=7 +/Table/3{8-9} num_replicas=7 +/Table/{39-40} num_replicas=7 +/Table/4{0-1} num_replicas=7 +/Table/4{1-2} num_replicas=7 +/Table/4{2-3} num_replicas=7 +/Table/4{3-4} num_replicas=7 +/Table/4{4-5} num_replicas=7 +/Table/4{5-6} ttl_seconds=7200 num_replicas=7 +/Table/4{6-7} num_replicas=7 +/Table/4{7-8} num_replicas=7 diff --git a/pkg/spanconfig/spanconfig.go b/pkg/spanconfig/spanconfig.go index eb69173ee61f..111956cb98ba 100644 --- a/pkg/spanconfig/spanconfig.go +++ b/pkg/spanconfig/spanconfig.go @@ -99,19 +99,18 @@ type KVSubscriber interface { // Table/5{3-4} num_replicas=7 num_voters=5 type SQLTranslator interface { // Translate generates the span configuration state given a list of - // {descriptor, named zone} IDs. No entry is returned for an ID if it - // doesn't exist or if it's dropped. The timestamp at which the translation - // is valid is also returned. + // {descriptor, named zone} IDs. Entries are unique, and are omitted for IDs + // that don't exist. The timestamp at which the translation is valid is also + // returned. // // For every ID we first descend the zone configuration hierarchy with the // ID as the root to accumulate IDs of all leaf objects. Leaf objects are // tables and named zones (other than RANGE DEFAULT) which have actual span // configurations associated with them (as opposed to non-leaf nodes that // only serve to hold zone configurations for inheritance purposes). Then, - // for each one of these accumulated IDs, we generate tuples by following up the inheritance chain to fully hydrate the - // span configuration. Translate also accounts for and negotiates subzone - // spans. + // for each one of these accumulated IDs, we generate tuples + // by following up the inheritance chain to fully hydrate the span + // configuration. Translate also accounts for and negotiates subzone spans. Translate(ctx context.Context, ids descpb.IDs) ([]roachpb.SpanConfigEntry, hlc.Timestamp, error) } diff --git a/pkg/spanconfig/spanconfigsqltranslator/sqltranslator.go b/pkg/spanconfig/spanconfigsqltranslator/sqltranslator.go index d3ddfea8cd43..68eefb31afd3 100644 --- a/pkg/spanconfig/spanconfigsqltranslator/sqltranslator.go +++ b/pkg/spanconfig/spanconfigsqltranslator/sqltranslator.go @@ -73,6 +73,7 @@ func (s *SQLTranslator) Translate( // IDs that have span configurations associated for them. We also // de-duplicate leaf IDs to not generate redundant entries. seen := make(map[descpb.ID]struct{}) + addedPseudoTableSpans := false var leafIDs descpb.IDs for _, id := range ids { descendantLeafIDs, err := s.findDescendantLeafIDs(ctx, id, txn, descsCol) @@ -85,6 +86,53 @@ func (s *SQLTranslator) Translate( leafIDs = append(leafIDs, descendantLeafID) } } + + if (id == keys.SystemDatabaseID || id == keys.RootNamespaceID) && s.codec.ForSystemTenant() { + // We have special handling for the system database (and RANGE + // DEFAULT, which the system database inherits from). The system + // config span infrastructure generates splits along (empty) + // pseudo table boundaries[1] -- we do the same. Not doing so is + // safe, but this helps reduce the differences between the two + // subsystems which has practical implications for our bootstrap + // code and tests that bake in assumptions about these splits. + // While the two systems exist side-by-side, it's easier to just + // minimize these differences (it also removes the tiny + // re-splitting costs when switching between them). We can get + // rid of this special handling once the system config span is + // removed (#70560). + // + // [2]: Consider the liveness range [/System/NodeLiveness, + // /System/NodeLivenessMax). It's identified using the + // pseudo ID 22 (i.e. keys.LivenessRangesID). Because we're + // using a pseudo ID, what of [/Table/22-/Table/23)? This + // is a keyspan with no contents, yet one the system config + // span splits along to create an empty range. It's + // precisely this "feature" we're looking to emulate. As + // for what config to apply over said range -- we do as the + // system config span does, applying the config for the + // system database. + if addedPseudoTableSpans { + continue // nothing to do + } + for _, pseudoTableID := range keys.PseudoTableIDs { + zone, err := sql.GetHydratedZoneConfigForDatabase(ctx, txn, s.codec, keys.SystemDatabaseID) + if err != nil { + return err + } + + tableStartKey := s.codec.TablePrefix(pseudoTableID) + tableEndKey := tableStartKey.PrefixEnd() + tableSpanConfig := zone.AsSpanConfig() + entries = append(entries, roachpb.SpanConfigEntry{ + Span: roachpb.Span{ + Key: tableStartKey, + EndKey: tableEndKey, + }, + Config: tableSpanConfig, + }) + } + addedPseudoTableSpans = true + } } // For every unique leaf ID, generate span configurations. diff --git a/pkg/sql/zone_config.go b/pkg/sql/zone_config.go index 0d19e2e94ca0..4c874a7cadeb 100644 --- a/pkg/sql/zone_config.go +++ b/pkg/sql/zone_config.go @@ -348,6 +348,31 @@ func GetHydratedZoneConfigForTable( return zone, nil } +// GetHydratedZoneConfigForDatabase returns a fully hydrated zone config for a +// given database ID. +func GetHydratedZoneConfigForDatabase( + ctx context.Context, txn *kv.Txn, codec keys.SQLCodec, id descpb.ID, +) (*zonepb.ZoneConfig, error) { + getKey := func(key roachpb.Key) (*roachpb.Value, error) { + kv, err := txn.Get(ctx, key) + if err != nil { + return nil, err + } + return kv.Value, nil + } + zoneID, zone, _, _, err := getZoneConfig( + codec, id, getKey, false /* getInheritedDefault */, true, /* mayBeTable */ + ) + if err != nil { + return nil, err + } + if err := completeZoneConfig(zone, codec, zoneID, getKey); err != nil { + return nil, err + } + + return zone, nil +} + func zoneSpecifierNotFoundError(zs tree.ZoneSpecifier) error { if zs.NamedZone != "" { return pgerror.Newf(