Skip to content

Commit

Permalink
Reapply "bootstrap: create an explicit zoneconfig for timeseries data"
Browse files Browse the repository at this point in the history
This partially reverts commit f9d47ce.

This time, rather than copying over the full zone config for the default
range to the timeseries range, we only copy over gc.ttlseconds. This
means that other attributes, most notably the replication factor, will
be inherited from the default range.

This will make it more clear that the timeseries zone config can be
changed independently from all the other zone configs.

Release note (ops change): New clusters that are initialized for the
first time will now have a zone config defined for the `timeseries` range.
This zone config only specifies the gc.ttlseconds, so all the other
attributes are inherited from the zone config of the `default` range, as
they were before.

Clusters that are upgraded to v24.3 from a previous version will also
have this zone configuration applied to the timeseries range, as long as
that range does not already have a zone config.
  • Loading branch information
rafiss committed Aug 15, 2024
1 parent b4a9870 commit 103bd54
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 37 deletions.
3 changes: 3 additions & 0 deletions pkg/ccl/logictestccl/testdata/logic_test/crdb_internal
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ SELECT zone_id, target FROM crdb_internal.zones ORDER BY 1
0 RANGE default
16 RANGE meta
17 RANGE system
18 RANGE timeseries
22 RANGE liveness
111 TABLE test.public.t4
111 INDEX test.public.t4@myt4index
Expand Down Expand Up @@ -109,6 +110,8 @@ RANGE system ALTER RANGE system CONFIGURE ZONE USING
num_replicas = 5,
constraints = '[]',
lease_preferences = '[]'
RANGE timeseries ALTER RANGE timeseries CONFIGURE ZONE USING
gc.ttlseconds = 14400
TABLE test.public.t4 ALTER TABLE test.public.t4 CONFIGURE ZONE USING
num_replicas = 7

Expand Down
55 changes: 28 additions & 27 deletions pkg/ccl/logictestccl/testdata/logic_test/zone
Original file line number Diff line number Diff line change
Expand Up @@ -616,33 +616,34 @@ SELECT target, range_name, database_name, table_name, index_name, partition_name
FROM crdb_internal.zones
ORDER BY target
----
DATABASE "my database" NULL my database NULL NULL NULL
DATABASE system NULL system NULL NULL NULL
INDEX "my database".public."my table"@"my index" NULL my database my table my index NULL
INDEX test.public.t36642@secondary NULL test t36642 secondary NULL
INDEX test.public.t36642@tertiary NULL test t36642 tertiary NULL
INDEX test.public.t36644@secondary NULL test t36644 secondary NULL
INDEX test.public.t36644@tertiary NULL test t36644 tertiary NULL
INDEX test.public.t@secondary NULL test t secondary NULL
INDEX test.public.t@tertiary NULL test t tertiary NULL
PARTITION "my partition" OF INDEX "my database".public."my table"@"my index" NULL my database my table my index my partition
PARTITION "my partition" OF INDEX "my database".public."my table"@"my table_pkey" NULL my database my table my table_pkey my partition
PARTITION x1_idx OF INDEX test.public.t38391@foo NULL test t38391 foo x1_idx
RANGE default default NULL NULL NULL NULL
RANGE liveness liveness NULL NULL NULL NULL
RANGE meta meta NULL NULL NULL NULL
RANGE system system NULL NULL NULL NULL
TABLE "my database".public."my table" NULL my database my table NULL NULL
TABLE system.public.lease NULL system lease NULL NULL
TABLE system.public.replication_constraint_stats NULL system replication_constraint_stats NULL NULL
TABLE system.public.replication_stats NULL system replication_stats NULL NULL
TABLE system.public.span_stats_tenant_boundaries NULL system span_stats_tenant_boundaries NULL NULL
TABLE system.public.statement_activity NULL system statement_activity NULL NULL
TABLE system.public.statement_statistics NULL system statement_statistics NULL NULL
TABLE system.public.tenant_usage NULL system tenant_usage NULL NULL
TABLE system.public.transaction_activity NULL system transaction_activity NULL NULL
TABLE system.public.transaction_statistics NULL system transaction_statistics NULL NULL
TABLE test.public.t NULL test t NULL NULL
DATABASE "my database" NULL my database NULL NULL NULL
DATABASE system NULL system NULL NULL NULL
INDEX "my database".public."my table"@"my index" NULL my database my table my index NULL
INDEX test.public.t36642@secondary NULL test t36642 secondary NULL
INDEX test.public.t36642@tertiary NULL test t36642 tertiary NULL
INDEX test.public.t36644@secondary NULL test t36644 secondary NULL
INDEX test.public.t36644@tertiary NULL test t36644 tertiary NULL
INDEX test.public.t@secondary NULL test t secondary NULL
INDEX test.public.t@tertiary NULL test t tertiary NULL
PARTITION "my partition" OF INDEX "my database".public."my table"@"my index" NULL my database my table my index my partition
PARTITION "my partition" OF INDEX "my database".public."my table"@"my table_pkey" NULL my database my table my table_pkey my partition
PARTITION x1_idx OF INDEX test.public.t38391@foo NULL test t38391 foo x1_idx
RANGE default default NULL NULL NULL NULL
RANGE liveness liveness NULL NULL NULL NULL
RANGE meta meta NULL NULL NULL NULL
RANGE system system NULL NULL NULL NULL
RANGE timeseries timeseries NULL NULL NULL NULL
TABLE "my database".public."my table" NULL my database my table NULL NULL
TABLE system.public.lease NULL system lease NULL NULL
TABLE system.public.replication_constraint_stats NULL system replication_constraint_stats NULL NULL
TABLE system.public.replication_stats NULL system replication_stats NULL NULL
TABLE system.public.span_stats_tenant_boundaries NULL system span_stats_tenant_boundaries NULL NULL
TABLE system.public.statement_activity NULL system statement_activity NULL NULL
TABLE system.public.statement_statistics NULL system statement_statistics NULL NULL
TABLE system.public.tenant_usage NULL system tenant_usage NULL NULL
TABLE system.public.transaction_activity NULL system transaction_activity NULL NULL
TABLE system.public.transaction_statistics NULL system transaction_statistics NULL NULL
TABLE test.public.t NULL test t NULL NULL

# Test the zone information being displayed in SHOW CREATE
statement ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ SELECT id FROM system.zones
11
16
17
18
22
25
27
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
# RANGE DEFAULT is akin to a full reconciliation.


# ID 18 is for the time series range which is the only named zone that doesn't
# have an entry in `system.zones` at bootstrap. It should inherit from RANGE
# DEFAULT.
# ID 18 is for the time series range. At bootstrap, it has an explicit zone
# config which should inherit from RANGE DEFAULT.
query-sql
SELECT count(*) FROM system.zones WHERE id=18
----
0
1

translate named-zone=timeseries
----
Expand Down
7 changes: 7 additions & 0 deletions pkg/sql/catalog/bootstrap/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,12 @@ func InitialZoneConfigKVs(
metaRangeZoneConf := protoutil.Clone(defaultSystemZoneConfig).(*zonepb.ZoneConfig)
livenessZoneConf := protoutil.Clone(defaultSystemZoneConfig).(*zonepb.ZoneConfig)

// The timeseries zone should inherit everything except for gc.ttlseconds from
// the default zone. We create it explicitly here so it's clearly visible
// when using SHOW ALL ZONE CONFIGURATIONS.
timeseriesZoneConf := zonepb.NewZoneConfig()
timeseriesZoneConf.GC = &zonepb.GCPolicy{TTLSeconds: defaultZoneConfig.GC.TTLSeconds}

// .meta zone config entry with a shorter GC time.
metaRangeZoneConf.GC.TTLSeconds = 60 * 60 // 1h

Expand All @@ -534,6 +540,7 @@ func InitialZoneConfigKVs(
add(keys.MetaRangesID, metaRangeZoneConf)
add(keys.LivenessRangesID, livenessZoneConf)
add(keys.SystemRangesID, systemZoneConf)
add(keys.TimeseriesRangesID, timeseriesZoneConf)
add(keys.SystemDatabaseID, systemZoneConf)
add(keys.ReplicationConstraintStatsTableID, replicationConstraintStatsZoneConf)
add(keys.ReplicationStatsTableID, replicationStatsZoneConf)
Expand Down
3 changes: 2 additions & 1 deletion pkg/sql/catalog/bootstrap/testdata/testdata
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
system hash=3d3210258c9ec86c5b1aa619be83379f5a23b5da269ec9f90fa68c5c6f87fc4f
system hash=6e9fc47c42475875a43765bbe4cff5d87f646b078e8d6bc69f239a8ae2dbb77b
----
[{"key":"8b"}
,{"key":"8b89898a89","value":"0312450a0673797374656d10011a250a0d0a0561646d696e1080101880100a0c0a04726f6f7410801018801012046e6f646518032200280140004a006a0a08d8843d100218002002"}
Expand Down Expand Up @@ -65,6 +65,7 @@ system hash=3d3210258c9ec86c5b1aa619be83379f5a23b5da269ec9f90fa68c5c6f87fc4f
,{"key":"8d89938a89","value":"03220308d804500158017800"}
,{"key":"8d89988a89","value":"031080808040188080808002220308901c2805500058007801"}
,{"key":"8d89998a89","value":"031080808040188080808002220308c0702805500058007801"}
,{"key":"8d899a8a89","value":"03220308c070500058007800"}
,{"key":"8d899e8a89","value":"031080808040188080808002220308d8042805500058007801"}
,{"key":"8d89a18a89","value":"03220308d804500158017800"}
,{"key":"8d89a38a89","value":"03220308d804500158017800"}
Expand Down
2 changes: 2 additions & 0 deletions pkg/sql/catalog/internal/catkv/testdata/testdata_system
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ catalog:
zone: gc.ttlseconds=3600
"017":
zone: gc.ttlseconds=14400
"018":
zone: gc.ttlseconds=14400
"019":
descriptor: relation
namespace: (1, 29, "web_sessions")
Expand Down
1 change: 0 additions & 1 deletion pkg/sql/logictest/testdata/logic_test/crdb_internal
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,6 @@ SELECT 'schema.bar'::regclass::int

statement ok
INSERT INTO system.zones (id, config) VALUES
(18, (SELECT raw_config_protobuf FROM crdb_internal.zones WHERE zone_id = 0)),
($testdb_id, (SELECT raw_config_protobuf FROM crdb_internal.zones WHERE zone_id = 0)),
($testdb_foo_id, (SELECT raw_config_protobuf FROM crdb_internal.zones WHERE zone_id = 0)),
($schema_bar_id, (SELECT raw_config_protobuf FROM crdb_internal.zones WHERE zone_id = 0))
Expand Down
14 changes: 12 additions & 2 deletions pkg/sql/logictest/testdata/logic_test/zone_config_system_tenant
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# LogicTest: !3node-tenant-default-configs
# Zone config logic tests that are only meant to work for the system tenant.

# Verify that the timeseries range has a zone config after bootstrap. It should
# only specify gc.ttlseconds, and everything should be implicitly inherited
# from the default range zone config.
query TT
SELECT target, raw_config_sql FROM [SHOW ZONE CONFIGURATIONS] WHERE target = 'RANGE timeseries'
----
RANGE timeseries ALTER RANGE timeseries CONFIGURE ZONE USING
gc.ttlseconds = 14400

statement ok
CREATE TABLE t();

Expand Down Expand Up @@ -29,6 +38,7 @@ SELECT zone_id, target FROM crdb_internal.zones ORDER BY 1
11 TABLE system.public.lease
16 RANGE meta
17 RANGE system
18 RANGE timeseries
22 RANGE liveness
25 TABLE system.public.replication_constraint_stats
27 TABLE system.public.replication_stats
Expand Down Expand Up @@ -194,8 +204,8 @@ ORDER BY start_key
/Table/106 14400
/Table/107 14400
/Table/110 90001
/Table/111 1
/Table/112 1
/Table/111 90001
/Table/112 14400

subtest transactional_schemachanges

Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/tests/system_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestInitialKeys(t *testing.T) {
var nonDescKeys int
if systemTenant {
codec = keys.SystemSQLCodec
nonDescKeys = 16
nonDescKeys = 17
} else {
codec = keys.MakeSQLCodec(roachpb.MustMakeTenantID(5))
nonDescKeys = 8
Expand Down
3 changes: 2 additions & 1 deletion pkg/sql/tests/testdata/initial_keys
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
initial-keys tenant=system
----
130 keys:
131 keys:
/Table/3/1/1/2/1
/Table/3/1/3/2/1
/Table/3/1/4/2/1
Expand Down Expand Up @@ -63,6 +63,7 @@ initial-keys tenant=system
/Table/5/1/11/2/1
/Table/5/1/16/2/1
/Table/5/1/17/2/1
/Table/5/1/18/2/1
/Table/5/1/22/2/1
/Table/5/1/25/2/1
/Table/5/1/27/2/1
Expand Down

0 comments on commit 103bd54

Please sign in to comment.