From db098873438c886cc48a09e6f8687b8e06f63713 Mon Sep 17 00:00:00 2001 From: DarvenDuan Date: Fri, 13 Sep 2024 20:29:40 +0800 Subject: [PATCH] fix modify partition storage policy --- .../java/org/apache/doris/alter/Alter.java | 58 ++++++++++--------- 1 file changed, 30 insertions(+), 28 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 672932f1877551e..31af76fa20e11b8 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 @@ -836,37 +836,39 @@ public void modifyPartitionsProperty(Database db, // 4.3 modify partition storage policy // can set multi times storage policy - String currentStoragePolicy = PropertyAnalyzer.analyzeStoragePolicy(properties); - if (!currentStoragePolicy.equals("")) { - // check currentStoragePolicy resource exist. - Env.getCurrentEnv().getPolicyMgr().checkStoragePolicyExist(currentStoragePolicy); - partitionInfo.setStoragePolicy(partition.getId(), currentStoragePolicy); - } else { - // if current partition is already in remote storage - if (partition.getRemoteDataSize() > 0) { - throw new AnalysisException( - "Cannot cancel storage policy for partition which is already on cold storage."); - } - - // if current partition will be cooldown in 20s later - StoragePolicy checkedPolicyCondition = StoragePolicy.ofCheck(dataProperty.getStoragePolicy()); - StoragePolicy policy = (StoragePolicy) Env.getCurrentEnv().getPolicyMgr() - .getPolicy(checkedPolicyCondition); - if (policy != null) { - long latestTime = policy.getCooldownTimestampMs() > 0 ? policy.getCooldownTimestampMs() - : Long.MAX_VALUE; - if (policy.getCooldownTtl() > 0) { - latestTime = Math.min(latestTime, - partition.getVisibleVersionTime() + policy.getCooldownTtl() * 1000); - } - if (latestTime < System.currentTimeMillis() + 20 * 1000) { + if (properties.containsKey(PropertyAnalyzer.PROPERTIES_STORAGE_POLICY)) { + String currentStoragePolicy = PropertyAnalyzer.analyzeStoragePolicy(properties); + if (!currentStoragePolicy.equals("")) { + // check currentStoragePolicy resource exist. + Env.getCurrentEnv().getPolicyMgr().checkStoragePolicyExist(currentStoragePolicy); + partitionInfo.setStoragePolicy(partition.getId(), currentStoragePolicy); + } else { + // if current partition is already in remote storage + if (partition.getRemoteDataSize() > 0) { throw new AnalysisException( - "Cannot cancel storage policy for partition which already be cooldown" - + " or will be cooldown soon later"); + "Cannot cancel storage policy for partition which is already on cold storage."); } - } - partitionInfo.setStoragePolicy(partition.getId(), ""); + // if current partition will be cooldown in 20s later + StoragePolicy checkedPolicyCondition = StoragePolicy.ofCheck(dataProperty.getStoragePolicy()); + StoragePolicy policy = (StoragePolicy) Env.getCurrentEnv().getPolicyMgr() + .getPolicy(checkedPolicyCondition); + if (policy != null) { + long latestTime = policy.getCooldownTimestampMs() > 0 ? policy.getCooldownTimestampMs() + : Long.MAX_VALUE; + if (policy.getCooldownTtl() > 0) { + latestTime = Math.min(latestTime, + partition.getVisibleVersionTime() + policy.getCooldownTtl() * 1000); + } + if (latestTime < System.currentTimeMillis() + 20 * 1000) { + throw new AnalysisException( + "Cannot cancel storage policy for partition which already be cooldown" + + " or will be cooldown soon later"); + } + } + + partitionInfo.setStoragePolicy(partition.getId(), ""); + } } // 4.4 analyze new properties