You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by na...@apache.org on 2026/04/22 16:14:32 UTC

(ignite) branch master updated: IGNITE-28591 Validate cache existence before destroy command execution (#13064)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 9d551f9d603 IGNITE-28591 Validate cache existence before destroy command execution (#13064)
9d551f9d603 is described below

commit 9d551f9d60353f172d2265f1ef2b9f60839e167d
Author: Nikita Amelchev <ns...@gmail.com>
AuthorDate: Wed Apr 22 19:14:24 2026 +0300

    IGNITE-28591 Validate cache existence before destroy command execution (#13064)
---
 .../util/GridCommandHandlerClusterByClassTest.java       |  5 +++--
 .../internal/management/cache/CacheDestroyCommand.java   | 16 +++++++++-------
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerClusterByClassTest.java b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerClusterByClassTest.java
index efc11f3cd5b..c74e88648b5 100644
--- a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerClusterByClassTest.java
+++ b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerClusterByClassTest.java
@@ -1464,9 +1464,10 @@ public class GridCommandHandlerClusterByClassTest extends GridCommandHandlerClus
         String expConfirmation = String.format(CacheDestroyCommand.CONFIRM_MSG,
             cacheNames.size(), S.joinToString(cacheNames, ", ", "..", 80, 0));
 
-        // Ensure we cannot delete a cache groups.
+        // Ensure we cannot delete a cache groups or not existed cache.
         injectTestSystemIn(CONFIRM_MSG);
-        assertEquals(EXIT_CODE_OK, execute("--cache", DESTROY, CACHES, "shared1,shared2"));
+        assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute("--cache", DESTROY, CACHES, "shared1,shared2"));
+        assertContains(log, testOut.toString(), "Caches do not exist: shared1, shared2");
         assertTrue(crd.cacheNames().containsAll(cacheNames));
 
         // Destroy all user-created caches.
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/management/cache/CacheDestroyCommand.java b/modules/core/src/main/java/org/apache/ignite/internal/management/cache/CacheDestroyCommand.java
index 6023957e19a..5e736b70c68 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/management/cache/CacheDestroyCommand.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/management/cache/CacheDestroyCommand.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.internal.management.cache;
 
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Set;
 import java.util.TreeSet;
 import java.util.function.Consumer;
@@ -55,17 +56,18 @@ public class CacheDestroyCommand
         CacheDestroyCommandArg arg,
         Consumer<String> printer
     ) {
-        if (arg.destroyAllCaches()) {
-            Set<String> caches = new TreeSet<>();
+        Set<String> caches = new TreeSet<>(client != null ? client.cacheNames() : ignite.cacheNames());
 
-            if (client != null)
-                caches.addAll(client.cacheNames());
-            else
-                caches.addAll(ignite.cacheNames());
+        if (!F.isEmpty(arg.caches())) {
+            Collection<String> notExisted = F.view(F.asList(arg.caches()), F.not(caches::contains));
 
-            arg.caches(caches.toArray(U.EMPTY_STRS));
+            if (!notExisted.isEmpty())
+                throw new IllegalArgumentException("Caches do not exist: " + String.join(", ", notExisted));
         }
 
+        if (arg.destroyAllCaches())
+            arg.caches(caches.toArray(U.EMPTY_STRS));
+
         if (F.isEmpty(arg.caches())) {
             printer.accept(NOOP_MSG);