This is an automated email from the ASF dual-hosted git repository.
dataroaring 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 68ced0d67ec [feat](snapshot) fix AdminCreateClusterSnapshotCommand
(#58119)
68ced0d67ec is described below
commit 68ced0d67ec6becf9c152078f02fb502202ce810
Author: meiyi <[email protected]>
AuthorDate: Fri Nov 21 03:54:09 2025 +0800
[feat](snapshot) fix AdminCreateClusterSnapshotCommand (#58119)
before, manual snapshot allow user does not set ttl and label like
`ADMIN CREATE CLUSTER SNAPSHOT`.
this pr requires that user must set ttl and label.
---
.../AdminCreateClusterSnapshotCommand.java | 13 +++++-
.../AdminCreateClusterSnapshotCommandTest.java | 48 +++++++++++++---------
2 files changed, 39 insertions(+), 22 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AdminCreateClusterSnapshotCommand.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AdminCreateClusterSnapshotCommand.java
index ab5c9460bf8..ebfb94a8768 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AdminCreateClusterSnapshotCommand.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AdminCreateClusterSnapshotCommand.java
@@ -87,15 +87,24 @@ public class AdminCreateClusterSnapshotCommand extends
Command implements Forwar
"Invalid value: " + entry.getValue() + " of
property: " + entry.getKey());
}
if (ttl <= 0) {
- throw new AnalysisException(
- "Invalid value: " + entry.getValue() + " of
property: " + entry.getKey());
+ throw new AnalysisException("Property 'ttl' must be
positive: " + entry.getValue());
}
} else if (entry.getKey().equalsIgnoreCase(PROP_LABEL)) {
label = entry.getValue();
+ if (label == null || label.isEmpty()) {
+ throw new AnalysisException("Property 'label' cannot be
empty");
+ }
} else {
throw new AnalysisException("Unknown property: " +
entry.getKey());
}
}
+
+ if (ttl <= 0) {
+ throw new AnalysisException("Property 'ttl' is required");
+ }
+ if (label == null || label.isEmpty()) {
+ throw new AnalysisException("Property 'label' is required");
+ }
}
@Override
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/AdminCreateClusterSnapshotCommandTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/AdminCreateClusterSnapshotCommandTest.java
index 31f63a5bf38..e832296dcf8 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/AdminCreateClusterSnapshotCommandTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/AdminCreateClusterSnapshotCommandTest.java
@@ -20,16 +20,20 @@ package org.apache.doris.nereids.trees.plans.commands;
import org.apache.doris.catalog.Env;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.Config;
+import org.apache.doris.common.Pair;
import org.apache.doris.mysql.privilege.AccessControllerManager;
import org.apache.doris.mysql.privilege.PrivPredicate;
import org.apache.doris.qe.ConnectContext;
+import com.google.common.collect.ImmutableMap;
import mockit.Expectations;
import mockit.Mocked;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
public class AdminCreateClusterSnapshotCommandTest {
@@ -70,30 +74,34 @@ public class AdminCreateClusterSnapshotCommandTest {
public void testValidateNormal() throws Exception {
runBefore();
Config.deploy_mode = "";
- Map<String, String> properties = new HashMap<>();
- properties.put("ttl", "3600");
- properties.put("label", "test_s_label");
- AdminCreateClusterSnapshotCommand command = new
AdminCreateClusterSnapshotCommand(properties);
+ AdminCreateClusterSnapshotCommand command = new
AdminCreateClusterSnapshotCommand(new HashMap<>());
Assertions.assertThrows(AnalysisException.class, () ->
command.validate(connectContext),
"The sql is illegal in disk mode");
Config.deploy_mode = "cloud";
- Assertions.assertDoesNotThrow(() -> command.validate(connectContext));
-
- // test invalid property
- properties.put("a", "test_s_label");
- AdminCreateClusterSnapshotCommand command1 = new
AdminCreateClusterSnapshotCommand(properties);
- Assertions.assertThrows(AnalysisException.class, () ->
command1.validate(connectContext), "Unknown property");
- properties.remove("a");
-
- // test invalid ttl
- properties.put("ttl", "a");
- AdminCreateClusterSnapshotCommand command2 = new
AdminCreateClusterSnapshotCommand(properties);
- Assertions.assertThrows(AnalysisException.class, () ->
command2.validate(connectContext), "Invalid value");
-
- properties.put("ttl", "0");
- AdminCreateClusterSnapshotCommand command3 = new
AdminCreateClusterSnapshotCommand(properties);
- Assertions.assertThrows(AnalysisException.class, () ->
command3.validate(connectContext), "Invalid value");
+ List<Pair<Map<String, String>, String>> properties = new ArrayList<>();
+ // missing property
+ properties.add(Pair.of(new HashMap<>(), "Property 'ttl' is
required."));
+ properties.add(Pair.of(ImmutableMap.of("label", "a"), "Property 'ttl'
is required"));
+ properties.add(Pair.of(ImmutableMap.of("ttl", "3600"), "Property
'label' is required."));
+ // invalid value
+ properties.add(Pair.of(ImmutableMap.of("ttl", "a", "label", "a"),
"Invalid value"));
+ properties.add(Pair.of(ImmutableMap.of("ttl", "0", "label", "a"),
"Property 'ttl' must be positive"));
+ properties.add(Pair.of(ImmutableMap.of("ttl", "3600", "label", ""),
"Property 'label' cannot be empty"));
+ // unknown property
+ properties.add(Pair.of(ImmutableMap.of("ttl", "0", "a", "b"), "Unknown
property"));
+ // normal case
+ properties.add(Pair.of(ImmutableMap.of("ttl", "3600", "label", "abc"),
""));
+
+ for (Pair<Map<String, String>, String> entry : properties) {
+ AdminCreateClusterSnapshotCommand command0 = new
AdminCreateClusterSnapshotCommand(entry.first);
+ String error = entry.second;
+ if (error.isEmpty()) {
+ command0.validate(connectContext);
+ } else {
+ Assertions.assertThrows(AnalysisException.class, () ->
command0.validate(connectContext), error);
+ }
+ }
}
@Test
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]