[fix](cooldown)Check cooldown ttl and datetime when alter storage policy (#17779)
* Check cooldown ttl and datetime when alter storage policy
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
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);
|
||||
// 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));
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user