From 8de3ee7fc564d5831327dcd02932329df0460504 Mon Sep 17 00:00:00 2001 From: Chandra Thumuluru Date: Fri, 4 Oct 2024 21:47:58 +0530 Subject: [PATCH] keys,server: use TableSpan from SQLCodec Add TableSpan implementation to SQLCodec and use that to build table spans. This refactoring helps with migration experiment of default system tenant from tenantID {1} to {2}. Informs: https://github.com/cockroachdb/cockroach/issues/131902 Epic: CRDB-42740 Release note: None --- pkg/keys/sql.go | 6 ++++++ pkg/server/systemconfigwatcher/cache.go | 10 ++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/keys/sql.go b/pkg/keys/sql.go index 85bc0e92c15b..2fd0d87ddf0b 100644 --- a/pkg/keys/sql.go +++ b/pkg/keys/sql.go @@ -185,6 +185,12 @@ func (e sqlEncoder) TenantSpan() roachpb.Span { return roachpb.Span{Key: key, EndKey: endKey} } +// TableSpan returns a span representing the table's keyspace. +func (e sqlEncoder) TableSpan(tableID uint32) roachpb.Span { + key := e.TablePrefix(tableID) + return roachpb.Span{Key: key, EndKey: key.PrefixEnd()} +} + // TablePrefix returns the key prefix used for the table's data. func (e sqlEncoder) TablePrefix(tableID uint32) roachpb.Key { k := e.TenantPrefix() diff --git a/pkg/server/systemconfigwatcher/cache.go b/pkg/server/systemconfigwatcher/cache.go index ed0d1755fd14..ed8634ea6516 100644 --- a/pkg/server/systemconfigwatcher/cache.go +++ b/pkg/server/systemconfigwatcher/cache.go @@ -85,14 +85,8 @@ func NewWithAdditionalProvider( c.additionalKVsSource = additional spans := []roachpb.Span{ - { - Key: append(codec.TenantPrefix(), keys.SystemDescriptorTableSpan.Key...), - EndKey: append(codec.TenantPrefix(), keys.SystemDescriptorTableSpan.EndKey...), - }, - { - Key: append(codec.TenantPrefix(), keys.SystemZonesTableSpan.Key...), - EndKey: append(codec.TenantPrefix(), keys.SystemZonesTableSpan.EndKey...), - }, + codec.TableSpan(keys.DescriptorTableID), + codec.TableSpan(keys.ZonesTableID), } c.w = rangefeedcache.NewWatcher( "system-config-cache", clock, f,