This is an automated email from the ASF dual-hosted git repository.

pengxiangyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new ceff7e851d [fix](cooldown)Check cooldown ttl and datetime when alter 
storage policy (#17779)
ceff7e851d is described below

commit ceff7e851d50dadcf2a0e7f4c2edf82c45b68359
Author: pengxiangyu <diablo...@163.com>
AuthorDate: Wed Mar 15 12:19:30 2023 +0800

    [fix](cooldown)Check cooldown ttl and datetime when alter storage policy 
(#17779)
    
    * Check cooldown ttl and datetime when alter storage policy
---
 .../org/apache/doris/analysis/AlterPolicyStmt.java | 56 ----------------------
 .../org/apache/doris/policy/StoragePolicy.java     | 50 +++++++++++--------
 2 files changed, 30 insertions(+), 76 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterPolicyStmt.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterPolicyStmt.java
index 67f9ab6bed..91a5f14375 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterPolicyStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterPolicyStmt.java
@@ -31,8 +31,6 @@ import org.apache.doris.qe.ConnectContext;
 
 import lombok.Data;
 
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
@@ -83,60 +81,6 @@ public class AlterPolicyStmt extends DdlStmt {
                     + ", you can change s3 properties by alter resource");
         }
 
-        boolean hasCooldownDatetime = false;
-        boolean hasCooldownTtl = false;
-
-        if (properties.containsKey(StoragePolicy.COOLDOWN_DATETIME)) {
-            hasCooldownDatetime = true;
-            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-            try {
-                df.parse(properties.get(StoragePolicy.COOLDOWN_DATETIME));
-            } catch (ParseException e) {
-                throw new AnalysisException(String.format("cooldown_datetime 
format error: %s",
-                    properties.get(StoragePolicy.COOLDOWN_DATETIME)), e);
-            }
-        }
-
-        if (properties.containsKey(StoragePolicy.COOLDOWN_TTL)) {
-            hasCooldownTtl = true;
-            // support 1h, 1hour to 3600s
-            properties.put(StoragePolicy.COOLDOWN_TTL, String.valueOf(
-                    
StoragePolicy.getSecondsByCooldownTtl(properties.get(StoragePolicy.COOLDOWN_TTL))));
-        }
-
-        if (hasCooldownDatetime && hasCooldownTtl) {
-            throw new AnalysisException(StoragePolicy.COOLDOWN_DATETIME + " 
and "
-                + StoragePolicy.COOLDOWN_TTL + " can't be set together.");
-        }
-        if (!hasCooldownDatetime && !hasCooldownTtl) {
-            throw new AnalysisException(StoragePolicy.COOLDOWN_DATETIME + " or 
"
-                + StoragePolicy.COOLDOWN_TTL + " must be set");
-        }
-
-        do {
-            if 
(policyName.equalsIgnoreCase(StoragePolicy.DEFAULT_STORAGE_POLICY_NAME)) {
-                // default storage policy
-                if (storagePolicy.getStorageResource() != null && 
hasCooldownDatetime) {
-                    // alter cooldown datetime, can do
-                    break;
-                }
-
-                if (storagePolicy.getStorageResource() != null && 
hasCooldownTtl) {
-                    // alter cooldown ttl, can do
-                    break;
-                }
-
-                if (storagePolicy.getStorageResource() == null) {
-                    // alter add s3 resource, can do, check must have ttl or 
datetime.
-                    if (hasCooldownTtl == false && hasCooldownDatetime == 
false) {
-                        throw new AnalysisException("please alter default 
policy to add s3 , ttl or datetime.");
-                    }
-                    break;
-                }
-                throw new AnalysisException("default storage policy has been 
set s3 Resource.");
-            }
-        } while (false);
-
         // check properties
         storagePolicy.checkProperties(properties);
     }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/policy/StoragePolicy.java 
b/fe/fe-core/src/main/java/org/apache/doris/policy/StoragePolicy.java
index 9474861dcf..b60a029e97 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/policy/StoragePolicy.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/policy/StoragePolicy.java
@@ -100,7 +100,7 @@ public class StoragePolicy extends Policy {
 
     // time unit: seconds
     @SerializedName(value = "cooldownTtl")
-    private long cooldownTtl = 0;
+    private long cooldownTtl = -1;
 
     // for Gson fromJson
     public StoragePolicy() {
@@ -311,22 +311,36 @@ public class StoragePolicy extends Policy {
 
     public void modifyProperties(Map<String, String> properties) throws 
DdlException, AnalysisException {
         this.toString();
-        // some check
-        long cooldownTtlMs = -1;
-        String cooldownTtl = properties.get(COOLDOWN_TTL);
-        if (cooldownTtl != null) {
-            cooldownTtlMs = getSecondsByCooldownTtl(cooldownTtl);
+        // check cooldown date time and ttl.
+        long cooldownTtlMs = this.cooldownTtl;
+        long cooldownTimestampMs = this.cooldownTimestampMs;
+        if (properties.containsKey(COOLDOWN_TTL)) {
+            if (properties.get(COOLDOWN_TTL).isEmpty()) {
+                cooldownTtlMs = -1;
+            } else {
+                cooldownTtlMs = 
getSecondsByCooldownTtl(properties.get(COOLDOWN_TTL));
+            }
         }
-        long cooldownTimestampMs = -1;
-        String cooldownDatetime = properties.get(COOLDOWN_DATETIME);
-        if (cooldownDatetime != null) {
-            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-            try {
-                cooldownTimestampMs = df.parse(cooldownDatetime).getTime();
-            } catch (ParseException e) {
-                throw new RuntimeException(e);
+        if (properties.containsKey(COOLDOWN_DATETIME)) {
+            if (properties.get(COOLDOWN_DATETIME).isEmpty()) {
+                cooldownTimestampMs = -1;
+            } else {
+                SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd 
HH:mm:ss");
+                try {
+                    cooldownTimestampMs = 
df.parse(properties.get(COOLDOWN_DATETIME)).getTime();
+                } catch (ParseException e) {
+                    throw new RuntimeException(e);
+                }
             }
         }
+
+        if (cooldownTtlMs > 0 && cooldownTimestampMs > 0) {
+            throw new AnalysisException(COOLDOWN_DATETIME + " and " + 
COOLDOWN_TTL + " can't be set together.");
+        }
+        if (cooldownTtlMs <= 0 && cooldownTimestampMs <= 0) {
+            throw new AnalysisException(COOLDOWN_DATETIME + " or " + 
COOLDOWN_TTL + " must be set");
+        }
+
         String storageResource = properties.get(STORAGE_RESOURCE);
         if (storageResource != null) {
             checkIsS3ResourceAndExist(storageResource);
@@ -337,12 +351,8 @@ public class StoragePolicy extends Policy {
         }
         // modify properties
         writeLock();
-        if (cooldownTtlMs > 0) {
-            this.cooldownTtl = cooldownTtlMs;
-        }
-        if (cooldownTimestampMs > 0) {
-            this.cooldownTimestampMs = cooldownTimestampMs;
-        }
+        this.cooldownTtl = cooldownTtlMs;
+        this.cooldownTimestampMs = cooldownTimestampMs;
         if (storageResource != null) {
             this.storageResource = storageResource;
         }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to