Skip to content

Commit

Permalink
fix modify partition storage policy
Browse files Browse the repository at this point in the history
  • Loading branch information
DarvenDuan committed Sep 13, 2024
1 parent fe62277 commit db09887
Showing 1 changed file with 30 additions and 28 deletions.
58 changes: 30 additions & 28 deletions fe/fe-core/src/main/java/org/apache/doris/alter/Alter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit db09887

Please sign in to comment.