This is an automated email from the ASF dual-hosted git repository. lide pushed a commit to branch branch-2.1 in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push: new af31e96c4e5 [fix](storage_policy) fix cannot cancel a partition's storage policy (#35890) af31e96c4e5 is described below commit af31e96c4e583c3df95de5be378c94d8a29d4ea0 Author: Yulei-Yang <yulei.yang0...@gmail.com> AuthorDate: Wed Jun 5 15:53:26 2024 +0800 [fix](storage_policy) fix cannot cancel a partition's storage policy (#35890) --- .../main/java/org/apache/doris/alter/Alter.java | 6 +++++ .../apache/doris/common/util/PropertyAnalyzer.java | 10 ++++----- .../test_show_storage_policy_using.groovy | 26 ++++++++++++++++++++++ 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/alter/Alter.java b/fe/fe-core/src/main/java/org/apache/doris/alter/Alter.java index 1d408b6799f..68ac144de1a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/alter/Alter.java +++ b/fe/fe-core/src/main/java/org/apache/doris/alter/Alter.java @@ -779,6 +779,12 @@ public class Alter { // check currentStoragePolicy resource exist. Env.getCurrentEnv().getPolicyMgr().checkStoragePolicyExist(currentStoragePolicy); partitionInfo.setStoragePolicy(partition.getId(), currentStoragePolicy); + } else { + if (partition.getRemoteDataSize() > 0) { + throw new AnalysisException( + "Cannot cancel storage policy for partition which is already on code storage."); + } + partitionInfo.setStoragePolicy(partition.getId(), ""); } // 4.4 analyze new properties diff --git a/fe/fe-core/src/main/java/org/apache/doris/common/util/PropertyAnalyzer.java b/fe/fe-core/src/main/java/org/apache/doris/common/util/PropertyAnalyzer.java index 07236da2ee3..d9eae228739 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/common/util/PropertyAnalyzer.java +++ b/fe/fe-core/src/main/java/org/apache/doris/common/util/PropertyAnalyzer.java @@ -244,11 +244,9 @@ public class PropertyAnalyzer { } else if (key.equalsIgnoreCase(PROPERTIES_STORAGE_COOLDOWN_TIME)) { DateLiteral dateLiteral = new DateLiteral(value, ScalarType.getDefaultDateType(Type.DATETIME)); cooldownTimestamp = dateLiteral.unixTimestamp(TimeUtils.getTimeZone()); - } else if (!hasStoragePolicy && key.equalsIgnoreCase(PROPERTIES_STORAGE_POLICY)) { - if (!Strings.isNullOrEmpty(value)) { - hasStoragePolicy = true; - newStoragePolicy = value; - } + } else if (key.equalsIgnoreCase(PROPERTIES_STORAGE_POLICY)) { + hasStoragePolicy = true; + newStoragePolicy = value; } } // end for properties @@ -277,7 +275,7 @@ public class PropertyAnalyzer { cooldownTimestamp = DataProperty.MAX_COOLDOWN_TIME_MS; } - if (hasStoragePolicy) { + if (hasStoragePolicy && !"".equals(newStoragePolicy)) { // check remote storage policy StoragePolicy checkedPolicy = StoragePolicy.ofCheck(newStoragePolicy); Policy policy = Env.getCurrentEnv().getPolicyMgr().getPolicy(checkedPolicy); diff --git a/regression-test/suites/cold_heat_separation_p2/test_show_storage_policy_using.groovy b/regression-test/suites/cold_heat_separation_p2/test_show_storage_policy_using.groovy index ca94b09077e..6f0413f63ae 100644 --- a/regression-test/suites/cold_heat_separation_p2/test_show_storage_policy_using.groovy +++ b/regression-test/suites/cold_heat_separation_p2/test_show_storage_policy_using.groovy @@ -156,6 +156,32 @@ suite("test_show_storage_policy_using") { """ assertTrue(show_result.size() >= 4) + // test cancel a partition's storage policy + sql """ + ALTER TABLE partition_with_multiple_storage_policy MODIFY PARTITION (`p201701`) SET ("storage_policy"="") + """ + show_result = sql """ + show storage policy using for ${policy_name} + """ + assertEquals(show_result.size(), 1) + assertTrue(show_result[0][2].equals("table_with_storage_policy_1")) + + sql """ + ALTER TABLE partition_with_multiple_storage_policy MODIFY PARTITION (`p201701`) SET ("storage_policy"="${policy_name}") + """ + show_result = sql """ + show storage policy using for ${policy_name} + """ + assertEquals(show_result.size(), 2) + + sql """ + ALTER TABLE partition_with_multiple_storage_policy MODIFY PARTITION (`p201701`) SET ("replication_num"="1") + """ + show_result = sql """ + show storage policy using for ${policy_name} + """ + assertEquals(show_result.size(), 2) + // cleanup sql """ DROP TABLE IF EXISTS table_with_storage_policy_1 """ sql """ DROP TABLE IF EXISTS table_no_storage_policy_1 """ --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org