You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by yi...@apache.org on 2026/04/25 01:55:06 UTC

(doris) branch branch-4.1 updated: branch-4.1: [feat](snapshot) fix AdminCreateClusterSnapshotCommand #58119 (#62785)

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

yiguolei pushed a commit to branch branch-4.1
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-4.1 by this push:
     new bd5a6368c5f branch-4.1: [feat](snapshot) fix AdminCreateClusterSnapshotCommand #58119 (#62785)
bd5a6368c5f is described below

commit bd5a6368c5f0f59dd819ae775086b83636e38e22
Author: github-actions[bot] <41...@users.noreply.github.com>
AuthorDate: Sat Apr 25 09:54:58 2026 +0800

    branch-4.1: [feat](snapshot) fix AdminCreateClusterSnapshotCommand #58119 (#62785)
    
    Cherry-picked from #58119
    
    Co-authored-by: meiyi <me...@selectdb.com>
---
 .../AdminCreateClusterSnapshotCommand.java         | 13 +++++-
 .../AdminCreateClusterSnapshotCommandTest.java     | 47 +++++++++++++---------
 2 files changed, 38 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 b62a960bede..425b6bb2176 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
@@ -99,15 +99,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 c1a3f2e523e..c0ecf74a763 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
@@ -21,6 +21,7 @@ import org.apache.doris.analysis.UserIdentity;
 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;
@@ -33,7 +34,9 @@ import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
 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 {
@@ -83,30 +86,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: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org