From e9f46f4786bd0f933f06d6d01533353e28352594 Mon Sep 17 00:00:00 2001 From: shralex Date: Tue, 7 Feb 2023 09:11:20 -0800 Subject: [PATCH] kv: increase the minimal max_range_size to 64MiB 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. Release Note: Small ranges have been known to cause problems in various CRDB subsystems. This PR prevents setting max_range_size below COCKROACH_MIN_RANGE_MAX_BYTES, an environment variable which defaults to 64MiB (half of the default minimum range size). Epic: https://cockroachlabs.atlassian.net/browse/CRDB-24182 Fixes: https://github.com/cockroachdb/cockroach/issues/96549 --- pkg/base/constants.go | 3 -- .../rttanalysis/alter_table_bench_test.go | 2 +- pkg/ccl/backupccl/backup_test.go | 4 +-- pkg/ccl/backupccl/utils_test.go | 17 ++++----- .../testdata/logic_test/distsql_partitioning | 10 +++--- .../logic_test/multi_region_zone_configs | 36 +++++++++---------- pkg/ccl/partitionccl/drop_test.go | 9 +++-- .../testdata/indexes | 10 +++--- .../testdata/tenant/indexes | 32 ++++++++--------- pkg/config/zonepb/BUILD.bazel | 2 +- pkg/config/zonepb/zone.go | 11 ++++-- pkg/config/zonepb/zone_test.go | 7 ++++ .../client_replica_backpressure_test.go | 4 +-- pkg/kv/kvserver/client_split_test.go | 4 +-- pkg/kv/kvserver/replicate_queue_test.go | 32 ++++++++++------- pkg/server/decommission_test.go | 12 +++---- .../logictest/testdata/logic_test/zone_config | 12 +++---- .../logic_test/zone_config_system_tenant | 5 +-- pkg/sql/zone_config_test.go | 4 +-- 19 files changed, 116 insertions(+), 100 deletions(-) diff --git a/pkg/base/constants.go b/pkg/base/constants.go index aee0ff8b6763..9dfef0a68387 100644 --- a/pkg/base/constants.go +++ b/pkg/base/constants.go @@ -49,7 +49,4 @@ const ( // InflightTraceDir is the directory name where the job trace dumper stores traces // when a job opts in to dumping its execution traces. InflightTraceDir = "inflight_trace_dump" - - // MinRangeMaxBytes is the minimum value for range max bytes. - MinRangeMaxBytes = 64 << 10 // 64 KB ) diff --git a/pkg/bench/rttanalysis/alter_table_bench_test.go b/pkg/bench/rttanalysis/alter_table_bench_test.go index 8fc7581e7706..1945853c3999 100644 --- a/pkg/bench/rttanalysis/alter_table_bench_test.go +++ b/pkg/bench/rttanalysis/alter_table_bench_test.go @@ -207,7 +207,7 @@ func init() { Name: "alter table configure zone ranges", Setup: `CREATE TABLE alter_table(a INT);`, Stmt: "ALTER TABLE alter_table CONFIGURE ZONE USING " + - "range_min_bytes = 0, range_max_bytes = 90000", + "range_min_bytes = 0, range_max_bytes = 500000000", }, }) } diff --git a/pkg/ccl/backupccl/backup_test.go b/pkg/ccl/backupccl/backup_test.go index 7d61e0476a44..dacad11445f4 100644 --- a/pkg/ccl/backupccl/backup_test.go +++ b/pkg/ccl/backupccl/backup_test.go @@ -9376,7 +9376,7 @@ func TestExportRequestBelowGCThresholdOnDataExcludedFromBackup(t *testing.T) { _, err = conn.Exec("SET CLUSTER SETTING kv.closed_timestamp.target_duration = '100ms'") // speeds up the test require.NoError(t, err) - const tableRangeMaxBytes = 1 << 18 + const tableRangeMaxBytes = 100 << 20 _, err = conn.Exec("ALTER TABLE foo CONFIGURE ZONE USING "+ "gc.ttlseconds = 1, range_max_bytes = $1, range_min_bytes = 1<<10;", tableRangeMaxBytes) require.NoError(t, err) @@ -9460,7 +9460,7 @@ func TestExcludeDataFromBackupDoesNotHoldupGC(t *testing.T) { // Exclude the table from backup so that it does not hold up GC. runner.Exec(t, `ALTER TABLE test.foo SET (exclude_data_from_backup = true)`) - const tableRangeMaxBytes = 1 << 18 + const tableRangeMaxBytes = 100 << 20 runner.Exec(t, "ALTER TABLE test.foo CONFIGURE ZONE USING "+ "gc.ttlseconds = 1, range_max_bytes = $1, range_min_bytes = 1<<10;", tableRangeMaxBytes) diff --git a/pkg/ccl/backupccl/utils_test.go b/pkg/ccl/backupccl/utils_test.go index bef1fe75f8d6..c7e181c3fd05 100644 --- a/pkg/ccl/backupccl/utils_test.go +++ b/pkg/ccl/backupccl/utils_test.go @@ -53,6 +53,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/workload/workloadsql" "github.com/cockroachdb/errors" "github.com/cockroachdb/logtags" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -657,18 +658,14 @@ func upsertUntilBackpressure( t *testing.T, rRand *rand.Rand, conn *gosql.DB, database, table string, ) { t.Helper() - testutils.SucceedsSoon(t, func() error { + for i := 1; i < 50; i++ { _, err := conn.Exec(fmt.Sprintf("UPSERT INTO %s.%s VALUES (1, $1)", database, table), - randutil.RandBytes(rRand, 1<<15)) - if err == nil { - return errors.New("expected `backpressure` error") - } - - if !testutils.IsError(err, "backpressure") { - return errors.NewAssertionErrorWithWrappedErrf(err, "expected `backpressure` error") + randutil.RandBytes(rRand, 5<<20)) + if testutils.IsError(err, "backpressure") { + return } - return nil - }) + } + assert.Fail(t, "expected `backpressure` error") } // requireRecoveryEvent fetches all available log entries on disk after diff --git a/pkg/ccl/logictestccl/testdata/logic_test/distsql_partitioning b/pkg/ccl/logictestccl/testdata/logic_test/distsql_partitioning index eec2fe5d21ac..2bbbcc174922 100644 --- a/pkg/ccl/logictestccl/testdata/logic_test/distsql_partitioning +++ b/pkg/ccl/logictestccl/testdata/logic_test/distsql_partitioning @@ -345,13 +345,13 @@ statement ok ALTER INDEX partitioning.inheritance@inheritance_pkey PARTITION BY LIST (x) ( PARTITION p1 VALUES IN (1)) statement ok -ALTER DATABASE partitioning CONFIGURE ZONE USING range_min_bytes=64000, range_max_bytes=75000 +ALTER DATABASE partitioning CONFIGURE ZONE USING range_min_bytes=64000, range_max_bytes=75000000 query TTTTTTTTT SHOW PARTITIONS FROM TABLE partitioning.inheritance ---- partitioning inheritance p1 NULL x inheritance@inheritance_pkey (1) NULL range_min_bytes = 64000, - range_max_bytes = 75000, + range_max_bytes = 75000000, gc.ttlseconds = 14400, num_replicas = 3, constraints = '[]', @@ -364,7 +364,7 @@ query TTTTTTTTT SHOW PARTITIONS FROM TABLE partitioning.inheritance ---- partitioning inheritance p1 NULL x inheritance@inheritance_pkey (1) NULL range_min_bytes = 64000, -range_max_bytes = 75000, +range_max_bytes = 75000000, gc.ttlseconds = 80000, num_replicas = 3, constraints = '[]', @@ -377,7 +377,7 @@ query TTTTTTTTT SHOW PARTITIONS FROM TABLE partitioning.inheritance ---- partitioning inheritance p1 NULL x inheritance@inheritance_pkey (1) NULL range_min_bytes = 64000, -range_max_bytes = 75000, +range_max_bytes = 75000000, gc.ttlseconds = 80000, num_replicas = 5, constraints = '[]', @@ -390,7 +390,7 @@ query TTTTTTTTT SHOW PARTITIONS FROM TABLE partitioning.inheritance ---- partitioning inheritance p1 NULL x inheritance@inheritance_pkey (1) constraints = '[+dc=dc1]' range_min_bytes = 64000, -range_max_bytes = 75000, +range_max_bytes = 75000000, gc.ttlseconds = 80000, num_replicas = 5, constraints = '[+dc=dc1]', diff --git a/pkg/ccl/logictestccl/testdata/logic_test/multi_region_zone_configs b/pkg/ccl/logictestccl/testdata/logic_test/multi_region_zone_configs index 22b34483342f..bf117702fb9e 100644 --- a/pkg/ccl/logictestccl/testdata/logic_test/multi_region_zone_configs +++ b/pkg/ccl/logictestccl/testdata/logic_test/multi_region_zone_configs @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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 = '[]', @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/pkg/ccl/partitionccl/drop_test.go b/pkg/ccl/partitionccl/drop_test.go index 740e06e8c794..e3c591deaf41 100644 --- a/pkg/ccl/partitionccl/drop_test.go +++ b/pkg/ccl/partitionccl/drop_test.go @@ -217,7 +217,8 @@ SELECT job_id PARTITION c VALUES IN ('c') )`) tdb.Exec(t, `CREATE INDEX idx ON t (e)`) - tdb.Exec(t, `ALTER PARTITION a OF TABLE t CONFIGURE ZONE USING range_min_bytes = 123456, range_max_bytes = 654321`) + tdb.Exec(t, `ALTER PARTITION a OF TABLE t CONFIGURE ZONE USING range_min_bytes = 123456, +range_max_bytes = 654321000`) tdb.Exec(t, `ALTER INDEX t@idx CONFIGURE ZONE USING gc.ttlseconds = 1`) tdb.Exec(t, `DROP INDEX t@idx`) @@ -271,8 +272,10 @@ SELECT job_id PARTITION ci VALUES IN ('c') )`, ) - tdb.Exec(t, `ALTER PARTITION ai OF INDEX t@idx CONFIGURE ZONE USING range_min_bytes = 123456,range_max_bytes = 654321`) - tdb.Exec(t, `ALTER PARTITION a OF TABLE t CONFIGURE ZONE USING range_min_bytes = 123456, range_max_bytes = 654321`) + tdb.Exec(t, `ALTER PARTITION ai OF INDEX t@idx CONFIGURE ZONE USING range_min_bytes = 123456, +range_max_bytes = 654321000`) + tdb.Exec(t, `ALTER PARTITION a OF TABLE t CONFIGURE ZONE USING range_min_bytes = 123456, +range_max_bytes = 654321000`) tdb.Exec(t, `ALTER INDEX t@idx CONFIGURE ZONE USING gc.ttlseconds = 1`) tdb.Exec(t, `DROP INDEX t@idx`) tdb.Exec(t, `DROP TABLE t`) diff --git a/pkg/ccl/spanconfigccl/spanconfigsqltranslatorccl/testdata/indexes b/pkg/ccl/spanconfigccl/spanconfigsqltranslatorccl/testdata/indexes index 2b524704b882..774dd284d021 100644 --- a/pkg/ccl/spanconfigccl/spanconfigsqltranslatorccl/testdata/indexes +++ b/pkg/ccl/spanconfigccl/spanconfigsqltranslatorccl/testdata/indexes @@ -71,7 +71,7 @@ translate database=db table=t # Configure a zone config field on the table, so that it is no longer a # placeholder zone config. exec-sql -ALTER TABLE db.t CONFIGURE ZONE USING range_min_bytes = 1000, range_max_bytes=100000; +ALTER TABLE db.t CONFIGURE ZONE USING range_min_bytes = 1000, range_max_bytes=100000000; ---- query-sql @@ -79,7 +79,7 @@ SHOW ZONE CONFIGURATION FOR INDEX db.t@idx ---- INDEX db.public.t@idx ALTER INDEX db.public.t@idx CONFIGURE ZONE USING range_min_bytes = 1000, - range_max_bytes = 100000, + range_max_bytes = 100000000, gc.ttlseconds = 25, num_replicas = 7, num_voters = 5, @@ -89,6 +89,6 @@ INDEX db.public.t@idx ALTER INDEX db.public.t@idx CONFIGURE ZONE USING translate database=db table=t ---- -/Table/106{-/2} range_max_bytes=100000 range_min_bytes=1000 ttl_seconds=3600 num_replicas=7 -/Table/106/{2-3} range_max_bytes=100000 range_min_bytes=1000 ttl_seconds=25 num_replicas=7 num_voters=5 -/Table/10{6/3-7} range_max_bytes=100000 range_min_bytes=1000 ttl_seconds=3600 num_replicas=7 +/Table/106{-/2} range_max_bytes=100000000 range_min_bytes=1000 ttl_seconds=3600 num_replicas=7 +/Table/106/{2-3} range_max_bytes=100000000 range_min_bytes=1000 ttl_seconds=25 num_replicas=7 num_voters=5 +/Table/10{6/3-7} range_max_bytes=100000000 range_min_bytes=1000 ttl_seconds=3600 num_replicas=7 diff --git a/pkg/ccl/spanconfigccl/spanconfigsqltranslatorccl/testdata/tenant/indexes b/pkg/ccl/spanconfigccl/spanconfigsqltranslatorccl/testdata/tenant/indexes index 247a337dcffa..c973a2b3276a 100644 --- a/pkg/ccl/spanconfigccl/spanconfigsqltranslatorccl/testdata/tenant/indexes +++ b/pkg/ccl/spanconfigccl/spanconfigsqltranslatorccl/testdata/tenant/indexes @@ -71,7 +71,7 @@ translate database=db table=t # Configure a zone config field on the table, so that it is no longer a # placeholder zone config. exec-sql -ALTER TABLE db.t CONFIGURE ZONE USING range_min_bytes = 1000, range_max_bytes=100000; +ALTER TABLE db.t CONFIGURE ZONE USING range_min_bytes = 1000, range_max_bytes=100000000; ---- query-sql @@ -79,7 +79,7 @@ SHOW ZONE CONFIGURATION FOR INDEX db.t@idx ---- INDEX db.public.t@idx ALTER INDEX db.public.t@idx CONFIGURE ZONE USING range_min_bytes = 1000, - range_max_bytes = 100000, + range_max_bytes = 100000000, gc.ttlseconds = 25, num_replicas = 7, num_voters = 5, @@ -89,9 +89,9 @@ INDEX db.public.t@idx ALTER INDEX db.public.t@idx CONFIGURE ZONE USING translate database=db table=t ---- -/Tenant/10/Table/106{-/2} range_max_bytes=100000 range_min_bytes=1000 ttl_seconds=3600 num_replicas=7 -/Tenant/10/Table/106/{2-3} range_max_bytes=100000 range_min_bytes=1000 ttl_seconds=25 num_replicas=7 num_voters=5 -/Tenant/10/Table/10{6/3-7} range_max_bytes=100000 range_min_bytes=1000 ttl_seconds=3600 num_replicas=7 +/Tenant/10/Table/106{-/2} range_max_bytes=100000000 range_min_bytes=1000 ttl_seconds=3600 num_replicas=7 +/Tenant/10/Table/106/{2-3} range_max_bytes=100000000 range_min_bytes=1000 ttl_seconds=25 num_replicas=7 num_voters=5 +/Tenant/10/Table/10{6/3-7} range_max_bytes=100000000 range_min_bytes=1000 ttl_seconds=3600 num_replicas=7 block-gc-jobs ---- @@ -105,12 +105,12 @@ ALTER INDEX db.t@idx2 CONFIGURE ZONE USING gc.ttlseconds = 1; # Both the newly added index and the temporary index have the configured zone configuration. translate database=db table=t ---- -/Tenant/10/Table/106{-/2} range_max_bytes=100000 range_min_bytes=1000 ttl_seconds=3600 num_replicas=7 -/Tenant/10/Table/106/{2-3} range_max_bytes=100000 range_min_bytes=1000 ttl_seconds=25 num_replicas=7 num_voters=5 -/Tenant/10/Table/106/{3-4} range_max_bytes=100000 range_min_bytes=1000 ttl_seconds=3600 num_replicas=7 -/Tenant/10/Table/106/{4-5} range_max_bytes=100000 range_min_bytes=1000 ttl_seconds=1 num_replicas=7 -/Tenant/10/Table/106/{5-6} range_max_bytes=100000 range_min_bytes=1000 ttl_seconds=1 num_replicas=7 -/Tenant/10/Table/10{6/6-7} range_max_bytes=100000 range_min_bytes=1000 ttl_seconds=3600 num_replicas=7 +/Tenant/10/Table/106{-/2} range_max_bytes=100000000 range_min_bytes=1000 ttl_seconds=3600 num_replicas=7 +/Tenant/10/Table/106/{2-3} range_max_bytes=100000000 range_min_bytes=1000 ttl_seconds=25 num_replicas=7 num_voters=5 +/Tenant/10/Table/106/{3-4} range_max_bytes=100000000 range_min_bytes=1000 ttl_seconds=3600 num_replicas=7 +/Tenant/10/Table/106/{4-5} range_max_bytes=100000000 range_min_bytes=1000 ttl_seconds=1 num_replicas=7 +/Tenant/10/Table/106/{5-6} range_max_bytes=100000000 range_min_bytes=1000 ttl_seconds=1 num_replicas=7 +/Tenant/10/Table/10{6/6-7} range_max_bytes=100000000 range_min_bytes=1000 ttl_seconds=3600 num_replicas=7 unblock-gc-jobs ---- @@ -122,11 +122,11 @@ SHOW JOBS WHEN COMPLETE (SELECT job_id FROM [SHOW JOBS]) # The zone configuration for the temporary index is cleaned up translate database=db table=t ---- -/Tenant/10/Table/106{-/2} range_max_bytes=100000 range_min_bytes=1000 ttl_seconds=3600 num_replicas=7 -/Tenant/10/Table/106/{2-3} range_max_bytes=100000 range_min_bytes=1000 ttl_seconds=25 num_replicas=7 num_voters=5 -/Tenant/10/Table/106/{3-4} range_max_bytes=100000 range_min_bytes=1000 ttl_seconds=3600 num_replicas=7 -/Tenant/10/Table/106/{4-5} range_max_bytes=100000 range_min_bytes=1000 ttl_seconds=1 num_replicas=7 -/Tenant/10/Table/10{6/5-7} range_max_bytes=100000 range_min_bytes=1000 ttl_seconds=3600 num_replicas=7 +/Tenant/10/Table/106{-/2} range_max_bytes=100000000 range_min_bytes=1000 ttl_seconds=3600 num_replicas=7 +/Tenant/10/Table/106/{2-3} range_max_bytes=100000000 range_min_bytes=1000 ttl_seconds=25 num_replicas=7 num_voters=5 +/Tenant/10/Table/106/{3-4} range_max_bytes=100000000 range_min_bytes=1000 ttl_seconds=3600 num_replicas=7 +/Tenant/10/Table/106/{4-5} range_max_bytes=100000000 range_min_bytes=1000 ttl_seconds=1 num_replicas=7 +/Tenant/10/Table/10{6/5-7} range_max_bytes=100000000 range_min_bytes=1000 ttl_seconds=3600 num_replicas=7 # Create and drop an index inside the same transaction. The related # zone configuration should also be cleaned up. diff --git a/pkg/config/zonepb/BUILD.bazel b/pkg/config/zonepb/BUILD.bazel index bb3b39a137bd..27e4cb79300f 100644 --- a/pkg/config/zonepb/BUILD.bazel +++ b/pkg/config/zonepb/BUILD.bazel @@ -13,11 +13,11 @@ go_library( importpath = "github.com/cockroachdb/cockroach/pkg/config/zonepb", visibility = ["//visibility:public"], deps = [ - "//pkg/base", "//pkg/clusterversion", "//pkg/keys", "//pkg/roachpb", "//pkg/sql/sem/tree", + "//pkg/util/envutil", "//pkg/util/log", "@com_github_cockroachdb_errors//:errors", "@com_github_gogo_protobuf//proto", diff --git a/pkg/config/zonepb/zone.go b/pkg/config/zonepb/zone.go index b41ca403f1d1..91c2f71d378f 100644 --- a/pkg/config/zonepb/zone.go +++ b/pkg/config/zonepb/zone.go @@ -16,11 +16,11 @@ import ( "fmt" "strings" - "github.com/cockroachdb/cockroach/pkg/base" "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" + "github.com/cockroachdb/cockroach/pkg/util/envutil" "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/errors" "github.com/gogo/protobuf/proto" @@ -341,6 +341,11 @@ func (z *ZoneConfig) ValidateTandemFields() error { return nil } +// MinRangeMaxBytes is the minimum value for range max bytes. +// The default, 64 MiB, is half of the default range_min_bytes +var minRangeMaxBytes = envutil.EnvOrDefaultInt64("COCKROACH_MIN_RANGE_MAX_BYTES", + 64<<20 /* 64 MiB */) + // Validate returns an error if the ZoneConfig specifies a known-dangerous or // disallowed configuration. func (z *ZoneConfig) Validate() error { @@ -382,9 +387,9 @@ func (z *ZoneConfig) Validate() error { } } - if z.RangeMaxBytes != nil && *z.RangeMaxBytes < base.MinRangeMaxBytes { + if z.RangeMaxBytes != nil && *z.RangeMaxBytes < minRangeMaxBytes { return fmt.Errorf("RangeMaxBytes %d less than minimum allowed %d", - *z.RangeMaxBytes, base.MinRangeMaxBytes) + *z.RangeMaxBytes, minRangeMaxBytes) } if z.RangeMinBytes != nil && *z.RangeMinBytes < 0 { diff --git a/pkg/config/zonepb/zone_test.go b/pkg/config/zonepb/zone_test.go index 3e59516d8654..9ce80265955a 100644 --- a/pkg/config/zonepb/zone_test.go +++ b/pkg/config/zonepb/zone_test.go @@ -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), diff --git a/pkg/kv/kvserver/client_replica_backpressure_test.go b/pkg/kv/kvserver/client_replica_backpressure_test.go index a0c3b1c45a97..d89f02c64d8c 100644 --- a/pkg/kv/kvserver/client_replica_backpressure_test.go +++ b/pkg/kv/kvserver/client_replica_backpressure_test.go @@ -47,8 +47,8 @@ func TestBackpressureNotAppliedWhenReducingRangeSize(t *testing.T) { // range size parameters. We want something not too tiny but also not too big // that it takes a while to load. const ( - rowSize = 16 << 10 // 16 KiB - dataSize = 512 << 10 // 512 KiB + rowSize = 1 << 20 // 1 MiB + dataSize = 512 << 20 // 512 MiB numRows = dataSize / rowSize ) diff --git a/pkg/kv/kvserver/client_split_test.go b/pkg/kv/kvserver/client_split_test.go index 1110d441ceb2..86d60357e56e 100644 --- a/pkg/kv/kvserver/client_split_test.go +++ b/pkg/kv/kvserver/client_split_test.go @@ -1089,7 +1089,7 @@ func TestStoreZoneUpdateAndRangeSplit(t *testing.T) { tdb.Exec(t, "CREATE TABLE t ()") var descID uint32 tdb.QueryRow(t, "SELECT 't'::regclass::int").Scan(&descID) - const maxBytes, minBytes = 1 << 16, 1 << 14 + const maxBytes, minBytes = 100 << 20, 1 << 14 tdb.Exec(t, "ALTER TABLE t CONFIGURE ZONE USING range_max_bytes = $1, range_min_bytes = $2", maxBytes, minBytes) @@ -1165,7 +1165,7 @@ func TestStoreRangeSplitWithMaxBytesUpdate(t *testing.T) { tdb.Exec(t, "CREATE TABLE t ()") var descID uint32 tdb.QueryRow(t, "SELECT 't'::regclass::int").Scan(&descID) - const maxBytes, minBytes = 1 << 16, 1 << 14 + const maxBytes, minBytes = 100 << 20, 1 << 14 tdb.Exec(t, "ALTER TABLE t CONFIGURE ZONE USING range_max_bytes = $1, range_min_bytes = $2", maxBytes, minBytes) diff --git a/pkg/kv/kvserver/replicate_queue_test.go b/pkg/kv/kvserver/replicate_queue_test.go index c126aa0103ad..94fe0f1ed64a 100644 --- a/pkg/kv/kvserver/replicate_queue_test.go +++ b/pkg/kv/kvserver/replicate_queue_test.go @@ -1756,8 +1756,7 @@ func TestLargeUnsplittableRangeReplicate(t *testing.T) { skip.UnderDeadlockWithIssue(t, 38565) ctx := context.Background() - // Create a cluster with really small ranges. - const rangeMaxSize = base.MinRangeMaxBytes + const rangeMaxSize = 64 << 20 zcfg := zonepb.DefaultZoneConfig() zcfg.RangeMinBytes = proto.Int64(rangeMaxSize / 2) zcfg.RangeMaxBytes = proto.Int64(rangeMaxSize) @@ -1777,12 +1776,13 @@ func TestLargeUnsplittableRangeReplicate(t *testing.T) { ) defer tc.Stopper().Stop(ctx) - // We're going to create a table with a big row and a small row. We'll split - // the table in between the rows, to produce a large range and a small one. - // Then we'll increase the replication factor to 5 and check that both ranges - // behave the same - i.e. they both get up-replicated. For the purposes of - // this test we're only worried about the large one up-replicating, but we - // test the small one as a control so that we don't fool ourselves. + // We're going to create a table with many versions of a big row and a small + // row. We'll split the table in between the rows, to produce a large range + // and a small one. Then we'll increase the replication factor to 5 and check + // that both ranges behave the same - i.e. they both get up-replicated. For + // the purposes of this test we're only worried about the large one + // up-replicating, but we test the small one as a control so that we don't + // fool ourselves. // Disable the queues so they don't mess with our manual relocation. We'll // re-enable them later. @@ -1801,14 +1801,20 @@ func TestLargeUnsplittableRangeReplicate(t *testing.T) { toggleReplicationQueues(tc, true /* active */) toggleSplitQueues(tc, true /* active */) - // We're going to create a row that's larger than range_max_bytes, but not - // large enough that write back-pressuring kicks in and refuses it. + // We're going to create a large row, but now large enough that write + // back-pressuring kicks in and refuses it. var sb strings.Builder - for i := 0; i < 1.5*rangeMaxSize; i++ { + for i := 0; i < rangeMaxSize/8; i++ { sb.WriteRune('a') } - _, err = db.Exec("INSERT INTO t(i,s) VALUES (1, $1)", sb.String()) - require.NoError(t, err) + + // Write 16 versions of the same row. This way the range won't be able to split. + for i := 0; i < 16; i++ { + _, err = db.Exec("UPSERT INTO t(i,s) VALUES (1, $1)", sb.String()) + require.NoError(t, err) + } + + // Write a small row into the second range. _, err = db.Exec("INSERT INTO t(i,s) VALUES (2, 'b')") require.NoError(t, err) diff --git a/pkg/server/decommission_test.go b/pkg/server/decommission_test.go index 005d7769d12d..f8b37cfd7126 100644 --- a/pkg/server/decommission_test.go +++ b/pkg/server/decommission_test.go @@ -120,9 +120,9 @@ func TestDecommissionPreCheckEvaluation(t *testing.T) { runQueries(setupQueries...) alterQueries := []string{ "ALTER TABLE test.tblA CONFIGURE ZONE USING num_replicas = 3, constraints = '{+west: 1, +central: 1, +east: 1}', " + - "range_max_bytes = 500000, range_min_bytes = 100", + "range_max_bytes = 500000000, range_min_bytes = 100", "ALTER TABLE test.tblB CONFIGURE ZONE USING num_replicas = 3, constraints = '{+east}', " + - "range_max_bytes = 500000, range_min_bytes = 100", + "range_max_bytes = 500000000, range_min_bytes = 100", } runQueries(alterQueries...) tblAID, err := firstSvr.admin.queryTableID(ctx, username.RootUserName(), "test", "tblA") @@ -139,8 +139,8 @@ func TestDecommissionPreCheckEvaluation(t *testing.T) { require.NoError(t, err) // Ensure all nodes have the correct span configs for tblA and tblB. - waitForSpanConfig(t, tc, rDescA.StartKey, 500000) - waitForSpanConfig(t, tc, rDescB.StartKey, 500000) + waitForSpanConfig(t, tc, rDescA.StartKey, 500000000) + waitForSpanConfig(t, tc, rDescB.StartKey, 500000000) // Transfer tblA to [west, central, east] and tblB to [east]. tc.AddVotersOrFatal(t, startKeyTblA, tc.Target(1), tc.Target(2), tc.Target(4)) @@ -229,7 +229,7 @@ func TestDecommissionPreCheckOddToEven(t *testing.T) { runQueries(setupQueries...) alterQueries := []string{ "ALTER TABLE test.tblA CONFIGURE ZONE USING num_replicas = 5, " + - "range_max_bytes = 500000, range_min_bytes = 100", + "range_max_bytes = 500000000, range_min_bytes = 100", } runQueries(alterQueries...) tblAID, err := firstSvr.admin.queryTableID(ctx, username.RootUserName(), "test", "tblA") @@ -241,7 +241,7 @@ func TestDecommissionPreCheckOddToEven(t *testing.T) { require.NoError(t, err) // Ensure all nodes have the correct span configs for tblA. - waitForSpanConfig(t, tc, rDescA.StartKey, 500000) + waitForSpanConfig(t, tc, rDescA.StartKey, 500000000) // Transfer tblA to all nodes. tc.AddVotersOrFatal(t, startKeyTblA, tc.Target(1), tc.Target(2), tc.Target(3), tc.Target(4)) diff --git a/pkg/sql/logictest/testdata/logic_test/zone_config b/pkg/sql/logictest/testdata/logic_test/zone_config index 6e185ce456ee..5f3dce3673ad 100644 --- a/pkg/sql/logictest/testdata/logic_test/zone_config +++ b/pkg/sql/logictest/testdata/logic_test/zone_config @@ -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]', @@ -103,7 +103,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 = 300001, + range_max_bytes = 100000001, gc.ttlseconds = 3600, num_replicas = 1, constraints = '[+region=test]', @@ -111,14 +111,14 @@ SELECT zone_id, raw_config_sql FROM [SHOW ZONE CONFIGURATION FOR TABLE a] # 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]', @@ -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]', @@ -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]', diff --git a/pkg/sql/logictest/testdata/logic_test/zone_config_system_tenant b/pkg/sql/logictest/testdata/logic_test/zone_config_system_tenant index 75727a94bcec..7d09026e5155 100644 --- a/pkg/sql/logictest/testdata/logic_test/zone_config_system_tenant +++ b/pkg/sql/logictest/testdata/logic_test/zone_config_system_tenant @@ -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; @@ -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); @@ -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. diff --git a/pkg/sql/zone_config_test.go b/pkg/sql/zone_config_test.go index 521c68106684..a303f7f67006 100644 --- a/pkg/sql/zone_config_test.go +++ b/pkg/sql/zone_config_test.go @@ -95,7 +95,7 @@ func TestGetZoneConfig(t *testing.T) { defaultZoneConfig := zonepb.DefaultSystemZoneConfig() defaultZoneConfig.NumReplicas = proto.Int32(1) defaultZoneConfig.RangeMinBytes = proto.Int64(1 << 20) - defaultZoneConfig.RangeMaxBytes = proto.Int64(1 << 21) + defaultZoneConfig.RangeMaxBytes = proto.Int64(100 << 20) defaultZoneConfig.GC = &zonepb.GCPolicy{TTLSeconds: 60} require.NoError(t, defaultZoneConfig.Validate()) params.Knobs.Server = &server.TestingKnobs{ @@ -331,7 +331,7 @@ func TestCascadingZoneConfig(t *testing.T) { defaultZoneConfig := zonepb.DefaultZoneConfig() defaultZoneConfig.NumReplicas = proto.Int32(1) defaultZoneConfig.RangeMinBytes = proto.Int64(1 << 20) - defaultZoneConfig.RangeMaxBytes = proto.Int64(1 << 21) + defaultZoneConfig.RangeMaxBytes = proto.Int64(100 << 20) defaultZoneConfig.GC = &zonepb.GCPolicy{TTLSeconds: 60} require.NoError(t, defaultZoneConfig.Validate()) params.Knobs.Server = &server.TestingKnobs{