This is an automated email from the ASF dual-hosted git repository.
lide pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.0 by this push:
new 18fd1cfb489 [fix](coldhot) fix cannot cancel storage policy of
partition (#35885)
18fd1cfb489 is described below
commit 18fd1cfb489e8af570f4fe9db9258ad5a6272363
Author: Yulei-Yang <[email protected]>
AuthorDate: Wed Jun 5 15:53:39 2024 +0800
[fix](coldhot) fix cannot cancel storage policy of partition (#35885)
---
.../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 4e0fe1bbfcd..bcfcfad81c1 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
@@ -830,6 +830,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 686495ef73d..b922ae84984 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
@@ -220,11 +220,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
@@ -253,7 +251,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: [email protected]
For additional commands, e-mail: [email protected]