From 83eb79dde806249ad4662ffd6f156ef25cf67cc0 Mon Sep 17 00:00:00 2001 From: yujun Date: Sun, 18 Feb 2024 10:02:44 +0800 Subject: [PATCH] [fix](dynamic partition) fix create too many dynamic partitions (#30994) --- .../doris/common/util/DynamicPartitionUtil.java | 10 +++++----- .../doris/catalog/DynamicPartitionTableTest.java | 3 ++- .../test_dynamic_partition_with_alter.groovy | 11 +++++++++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/common/util/DynamicPartitionUtil.java b/fe/fe-core/src/main/java/org/apache/doris/common/util/DynamicPartitionUtil.java index fcd578d9bc754a..6587da5aef6891 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/common/util/DynamicPartitionUtil.java +++ b/fe/fe-core/src/main/java/org/apache/doris/common/util/DynamicPartitionUtil.java @@ -569,22 +569,22 @@ public static Map analyzeDynamicPartition(Map pr // If create_history_partition is true, will pre-create history partition according the valid value from // start and history_partition_num. // - int expectCreatePartitionNum = 0; + long expectCreatePartitionNum = 0; if (!createHistoryPartition) { start = 0; - expectCreatePartitionNum = end - start; + expectCreatePartitionNum = (long) end - start; } else { int historyPartitionNum = Integer.parseInt(analyzedProperties.getOrDefault( DynamicPartitionProperty.HISTORY_PARTITION_NUM, String.valueOf(DynamicPartitionProperty.NOT_SET_HISTORY_PARTITION_NUM))); if (historyPartitionNum != DynamicPartitionProperty.NOT_SET_HISTORY_PARTITION_NUM) { - expectCreatePartitionNum = end - Math.max(start, -historyPartitionNum); + expectCreatePartitionNum = (long) end - Math.max(start, -historyPartitionNum); } else { if (start == Integer.MIN_VALUE) { throw new DdlException("Provide start or history_partition_num property" - + " when creating history partition"); + + " when create_history_partition=true. Otherwise set create_history_partition=false"); } - expectCreatePartitionNum = end - start; + expectCreatePartitionNum = (long) end - start; } } if (hasEnd && (expectCreatePartitionNum > Config.max_dynamic_partition_num) diff --git a/fe/fe-core/src/test/java/org/apache/doris/catalog/DynamicPartitionTableTest.java b/fe/fe-core/src/test/java/org/apache/doris/catalog/DynamicPartitionTableTest.java index 22c19fb159bea4..f883f8928fc7b7 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/catalog/DynamicPartitionTableTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/catalog/DynamicPartitionTableTest.java @@ -641,7 +641,8 @@ public void testFillHistoryDynamicPartition3() throws Exception { + ");"; // start and history_partition_num are not set, can not create history partition ExceptionChecker.expectThrowsWithMsg(DdlException.class, - "Provide start or history_partition_num property when creating history partition", + "Provide start or history_partition_num property when create_history_partition=true. " + + "Otherwise set create_history_partition=false", () -> createTable(createOlapTblStmt)); String createOlapTblStmt2 = "CREATE TABLE test.`dynamic_partition3` (\n" diff --git a/regression-test/suites/partition_p0/dynamic_partition/test_dynamic_partition_with_alter.groovy b/regression-test/suites/partition_p0/dynamic_partition/test_dynamic_partition_with_alter.groovy index a88761d23c706d..a844ad7549dcc9 100644 --- a/regression-test/suites/partition_p0/dynamic_partition/test_dynamic_partition_with_alter.groovy +++ b/regression-test/suites/partition_p0/dynamic_partition/test_dynamic_partition_with_alter.groovy @@ -34,9 +34,20 @@ suite("test_dynamic_partition_with_alter") { "dynamic_partition.create_history_partition"="true", "dynamic_partition.replication_allocation" = "tag.location.default: 1") """ + result = sql "show partitions from ${tbl}" assertEquals(7, result.size()) + test { + sql "alter table ${tbl} set ('dynamic_partition.start' = '-2147483648')" + exception "Provide start or history_partition_num property" + } + + test { + sql "alter table ${tbl} set ('dynamic_partition.start' = '-2147483647')" + exception "Too many dynamic partitions" + } + // modify distributed column comment, then try to add too more dynamic partition sql """ alter table ${tbl} modify column k1 comment 'new_comment_for_k1' """ sql """ ADMIN SET FRONTEND CONFIG ('dynamic_partition_check_interval_seconds' = '1') """