Skip to content

Commit

Permalink
kv: increasing the minimal max_range_size to 64MiB
Browse files Browse the repository at this point in the history
We've seen that small range sizes can be detrimental to various
components. This PR makes it so users can't lower max_range_size
below 64MiB (half of the default min_range_size), instead of 64KiB previously.

Epic: https://cockroachlabs.atlassian.net/browse/CRDB-24182
Fixes: cockroachdb#96549
  • Loading branch information
shralex committed Feb 7, 2023
1 parent f640acb commit 9b206f7
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 27 deletions.
2 changes: 1 addition & 1 deletion pkg/base/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ const (
InflightTraceDir = "inflight_trace_dump"

// MinRangeMaxBytes is the minimum value for range max bytes.
MinRangeMaxBytes = 64 << 10 // 64 KB
MinRangeMaxBytes = 64 << 20 // 64 MiB, half of the default range_min_bytes
)
36 changes: 18 additions & 18 deletions pkg/ccl/logictestccl/testdata/logic_test/multi_region_zone_configs
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ statement ok
ALTER DATABASE "mr-zone-configs" CONFIGURE ZONE USING gc.ttlseconds = 5

statement ok
ALTER DATABASE "mr-zone-configs" CONFIGURE ZONE USING range_min_bytes = 1000, range_max_bytes = 100000
ALTER DATABASE "mr-zone-configs" CONFIGURE ZONE USING range_min_bytes = 1000, range_max_bytes = 100000000

query TT
SHOW ZONE CONFIGURATION FOR DATABASE "mr-zone-configs"
----
DATABASE "mr-zone-configs" ALTER DATABASE "mr-zone-configs" CONFIGURE ZONE USING
range_min_bytes = 1000,
range_max_bytes = 100000,
range_max_bytes = 100000000,
gc.ttlseconds = 5,
num_replicas = 5,
num_voters = 3,
Expand All @@ -149,7 +149,7 @@ SHOW ZONE CONFIGURATION FOR DATABASE "mr-zone-configs"
----
DATABASE "mr-zone-configs" ALTER DATABASE "mr-zone-configs" CONFIGURE ZONE USING
range_min_bytes = 1000,
range_max_bytes = 100000,
range_max_bytes = 100000000,
gc.ttlseconds = 5,
num_replicas = 5,
num_voters = 3,
Expand All @@ -170,7 +170,7 @@ SHOW ZONE CONFIGURATION FOR DATABASE "mr-zone-configs"
----
DATABASE "mr-zone-configs" ALTER DATABASE "mr-zone-configs" CONFIGURE ZONE USING
range_min_bytes = 1000,
range_max_bytes = 100000,
range_max_bytes = 100000000,
gc.ttlseconds = 5,
num_replicas = 5,
num_voters = 5,
Expand Down Expand Up @@ -243,7 +243,7 @@ SHOW ZONE CONFIGURATION FOR DATABASE "mr-zone-configs"
----
DATABASE "mr-zone-configs" ALTER DATABASE "mr-zone-configs" CONFIGURE ZONE USING
range_min_bytes = 1000,
range_max_bytes = 100000,
range_max_bytes = 100000000,
gc.ttlseconds = 5,
num_replicas = 5,
num_voters = 3,
Expand Down Expand Up @@ -302,7 +302,7 @@ SHOW ZONE CONFIGURATION FOR DATABASE "mr-zone-configs"
----
DATABASE "mr-zone-configs" ALTER DATABASE "mr-zone-configs" CONFIGURE ZONE USING
range_min_bytes = 1000,
range_max_bytes = 100000,
range_max_bytes = 100000000,
gc.ttlseconds = 100000,
num_replicas = 4,
num_voters = 3,
Expand All @@ -323,7 +323,7 @@ SHOW ZONE CONFIGURATION FOR DATABASE "mr-zone-configs"
----
DATABASE "mr-zone-configs" ALTER DATABASE "mr-zone-configs" CONFIGURE ZONE USING
range_min_bytes = 1000,
range_max_bytes = 100000,
range_max_bytes = 100000000,
gc.ttlseconds = 100000,
num_replicas = 3,
num_voters = 3,
Expand All @@ -344,7 +344,7 @@ SHOW ZONE CONFIGURATION FOR DATABASE "mr-zone-configs"
----
DATABASE "mr-zone-configs" ALTER DATABASE "mr-zone-configs" CONFIGURE ZONE USING
range_min_bytes = 1000,
range_max_bytes = 100000,
range_max_bytes = 100000000,
gc.ttlseconds = 100000,
num_replicas = 3,
num_voters = 3,
Expand All @@ -365,7 +365,7 @@ SHOW ZONE CONFIGURATION FOR DATABASE "mr-zone-configs"
----
DATABASE "mr-zone-configs" ALTER DATABASE "mr-zone-configs" CONFIGURE ZONE USING
range_min_bytes = 1000,
range_max_bytes = 100000,
range_max_bytes = 100000000,
gc.ttlseconds = 100000,
num_replicas = 3,
constraints = '[]',
Expand Down Expand Up @@ -443,7 +443,7 @@ SHOW ZONE CONFIGURATION FOR TABLE regional_by_row
----
TABLE regional_by_row ALTER TABLE regional_by_row CONFIGURE ZONE USING
range_min_bytes = 1000,
range_max_bytes = 100000,
range_max_bytes = 100000000,
gc.ttlseconds = 10,
num_replicas = 10,
num_voters = 3,
Expand Down Expand Up @@ -504,7 +504,7 @@ SHOW ZONE CONFIGURATION FOR INDEX regional_by_row@regional_by_row_pkey
----
TABLE regional_by_row ALTER TABLE regional_by_row CONFIGURE ZONE USING
range_min_bytes = 1000,
range_max_bytes = 100000,
range_max_bytes = 100000000,
gc.ttlseconds = 10,
num_replicas = 5,
num_voters = 3,
Expand All @@ -517,7 +517,7 @@ SHOW ZONE CONFIGURATION FOR INDEX regional_by_row@regional_by_row_i_idx
----
TABLE regional_by_row ALTER TABLE regional_by_row CONFIGURE ZONE USING
range_min_bytes = 1000,
range_max_bytes = 100000,
range_max_bytes = 100000000,
gc.ttlseconds = 10,
num_replicas = 5,
num_voters = 3,
Expand All @@ -530,7 +530,7 @@ SHOW ZONE CONFIGURATION FOR TABLE regional_by_row
----
TABLE regional_by_row ALTER TABLE regional_by_row CONFIGURE ZONE USING
range_min_bytes = 1000,
range_max_bytes = 100000,
range_max_bytes = 100000000,
gc.ttlseconds = 10,
num_replicas = 5,
num_voters = 3,
Expand Down Expand Up @@ -598,7 +598,7 @@ SHOW ZONE CONFIGURATION FOR TABLE regional_by_row
----
TABLE regional_by_row ALTER TABLE regional_by_row CONFIGURE ZONE USING
range_min_bytes = 1000,
range_max_bytes = 100000,
range_max_bytes = 100000000,
gc.ttlseconds = 100000,
global_reads = false,
num_replicas = 5,
Expand All @@ -617,7 +617,7 @@ SHOW ZONE CONFIGURATION FOR TABLE regional_by_row
----
TABLE regional_by_row ALTER TABLE regional_by_row CONFIGURE ZONE USING
range_min_bytes = 1000,
range_max_bytes = 100000,
range_max_bytes = 100000000,
gc.ttlseconds = 100000,
global_reads = true,
num_replicas = 5,
Expand Down Expand Up @@ -667,7 +667,7 @@ SHOW ZONE CONFIGURATION FOR INDEX regional_by_row_as@regional_by_row_as_pkey
----
INDEX regional_by_row_as@regional_by_row_as_pkey ALTER INDEX regional_by_row_as@regional_by_row_as_pkey CONFIGURE ZONE USING
range_min_bytes = 1000,
range_max_bytes = 100000,
range_max_bytes = 100000000,
gc.ttlseconds = 100000,
num_replicas = 10,
num_voters = 3,
Expand All @@ -688,7 +688,7 @@ SHOW ZONE CONFIGURATION FOR INDEX regional_by_row_as@regional_by_row_as_pkey
----
DATABASE "mr-zone-configs" ALTER DATABASE "mr-zone-configs" CONFIGURE ZONE USING
range_min_bytes = 1000,
range_max_bytes = 100000,
range_max_bytes = 100000000,
gc.ttlseconds = 100000,
num_replicas = 5,
num_voters = 3,
Expand Down Expand Up @@ -737,7 +737,7 @@ SHOW ZONE CONFIGURATION FOR DATABASE "mr-zone-configs"
----
DATABASE "mr-zone-configs" ALTER DATABASE "mr-zone-configs" CONFIGURE ZONE USING
range_min_bytes = 1000,
range_max_bytes = 100000,
range_max_bytes = 100000000,
gc.ttlseconds = 100000,
num_replicas = 5,
num_voters = 3,
Expand Down
7 changes: 7 additions & 0 deletions pkg/config/zonepb/zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ func TestZoneConfigValidate(t *testing.T) {
},
"RangeMaxBytes 0 less than minimum allowed",
},
{
ZoneConfig{
NumReplicas: proto.Int32(1),
RangeMaxBytes: proto.Int64(60 << 20),
},
"RangeMaxBytes 62914560 less than minimum allowed",
},
{
ZoneConfig{
NumReplicas: proto.Int32(1),
Expand Down
12 changes: 6 additions & 6 deletions pkg/sql/logictest/testdata/logic_test/zone_config
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ SELECT zone_id, raw_config_sql FROM [SHOW ZONE CONFIGURATION FOR TABLE a]
statement ok
ALTER TABLE a CONFIGURE ZONE USING
range_min_bytes = 200000 + 1,
range_max_bytes = 300000 + 1,
range_max_bytes = 100000000 + 1,
gc.ttlseconds = 3000 + 600,
num_replicas = floor(1.2)::int,
constraints = '[+region=test]',
Expand Down Expand Up @@ -103,22 +103,22 @@ SELECT zone_id, raw_config_sql FROM [SHOW ZONE CONFIGURATION FOR TABLE a]
----
106 ALTER TABLE a CONFIGURE ZONE USING
range_min_bytes = 200001,
range_max_bytes = 300001,
range_max_bytes = 100000001,
gc.ttlseconds = 3600,
num_replicas = 1,
constraints = '[+region=test]',
lease_preferences = '[[+region=test]]'

# Check that we can set just one value without altering the others.
statement ok
ALTER TABLE a CONFIGURE ZONE USING range_max_bytes = 400000
ALTER TABLE a CONFIGURE ZONE USING range_max_bytes = 400000000

query IT
SELECT zone_id, raw_config_sql FROM [SHOW ZONE CONFIGURATION FOR TABLE a]
----
106 ALTER TABLE a CONFIGURE ZONE USING
range_min_bytes = 200001,
range_max_bytes = 400000,
range_max_bytes = 400000000,
gc.ttlseconds = 3600,
num_replicas = 1,
constraints = '[+region=test]',
Expand Down Expand Up @@ -154,7 +154,7 @@ SELECT zone_id, raw_config_sql FROM [SHOW ZONE CONFIGURATION FOR TABLE a]
----
106 ALTER TABLE a CONFIGURE ZONE USING
range_min_bytes = 200001,
range_max_bytes = 400000,
range_max_bytes = 400000000,
gc.ttlseconds = 3600,
num_replicas = 1,
constraints = '[+region=test]',
Expand All @@ -170,7 +170,7 @@ a CREATE TABLE public.a (
);
ALTER TABLE test.public.a CONFIGURE ZONE USING
range_min_bytes = 200001,
range_max_bytes = 400000,
range_max_bytes = 400000000,
gc.ttlseconds = 3600,
num_replicas = 1,
constraints = '[+region=test]',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ SELECT 'db2.t'::REGCLASS::INT
# in either of these tables for id = $t_id.
statement ok
BEGIN;
ALTER TABLE db2.t CONFIGURE ZONE USING range_max_bytes = 1<<24, range_min_bytes = 1<<20;
ALTER TABLE db2.t CONFIGURE ZONE USING range_max_bytes = 64<<20, range_min_bytes = 1<<20;
DROP TABLE db2.t;
COMMIT;

Expand All @@ -105,6 +105,7 @@ SELECT crdb_internal.pb_to_json('cockroach.roachpb.SpanConfig', config)
FROM system.span_configurations
WHERE end_key > (SELECT crdb_internal.table_span($t_id)[1])
----
{"gcPolicy": {"ttlSeconds": 14400}, "numReplicas": 3, "rangeMaxBytes": "67108864", "rangeMinBytes": "1048576"}

statement ok
CREATE TABLE db2.t2 (i INT PRIMARY KEY);
Expand All @@ -122,7 +123,7 @@ SELECT crdb_internal.pb_to_json('cockroach.roachpb.SpanConfig', config)
FROM system.span_configurations
WHERE end_key > (SELECT crdb_internal.table_span($t_id)[1])
----
{"gcPolicy": {"ttlSeconds": 90001}, "numReplicas": 3, "rangeMaxBytes": "16777216", "rangeMinBytes": "1048576"}
{"gcPolicy": {"ttlSeconds": 90001}, "numReplicas": 3, "rangeMaxBytes": "67108864", "rangeMinBytes": "1048576"}
{"gcPolicy": {"ttlSeconds": 90001}, "numReplicas": 3, "rangeMaxBytes": "1073741824", "rangeMinBytes": "67108864"}

# Check that dropped relations can have their GC TTLs altered.
Expand Down

0 comments on commit 9b206f7

Please sign in to comment.