Skip to content

Commit 9d551f9

Browse files
authored
IGNITE-28591 Validate cache existence before destroy command execution (#13064)
1 parent 013e1fe commit 9d551f9

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerClusterByClassTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,9 +1464,10 @@ public void testCacheDestroy() throws IgniteCheckedException {
14641464
String expConfirmation = String.format(CacheDestroyCommand.CONFIRM_MSG,
14651465
cacheNames.size(), S.joinToString(cacheNames, ", ", "..", 80, 0));
14661466

1467-
// Ensure we cannot delete a cache groups.
1467+
// Ensure we cannot delete a cache groups or not existed cache.
14681468
injectTestSystemIn(CONFIRM_MSG);
1469-
assertEquals(EXIT_CODE_OK, execute("--cache", DESTROY, CACHES, "shared1,shared2"));
1469+
assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute("--cache", DESTROY, CACHES, "shared1,shared2"));
1470+
assertContains(log, testOut.toString(), "Caches do not exist: shared1, shared2");
14701471
assertTrue(crd.cacheNames().containsAll(cacheNames));
14711472

14721473
// Destroy all user-created caches.

modules/core/src/main/java/org/apache/ignite/internal/management/cache/CacheDestroyCommand.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.ignite.internal.management.cache;
1919

2020
import java.util.Arrays;
21+
import java.util.Collection;
2122
import java.util.Set;
2223
import java.util.TreeSet;
2324
import java.util.function.Consumer;
@@ -55,17 +56,18 @@ public class CacheDestroyCommand
5556
CacheDestroyCommandArg arg,
5657
Consumer<String> printer
5758
) {
58-
if (arg.destroyAllCaches()) {
59-
Set<String> caches = new TreeSet<>();
59+
Set<String> caches = new TreeSet<>(client != null ? client.cacheNames() : ignite.cacheNames());
6060

61-
if (client != null)
62-
caches.addAll(client.cacheNames());
63-
else
64-
caches.addAll(ignite.cacheNames());
61+
if (!F.isEmpty(arg.caches())) {
62+
Collection<String> notExisted = F.view(F.asList(arg.caches()), F.not(caches::contains));
6563

66-
arg.caches(caches.toArray(U.EMPTY_STRS));
64+
if (!notExisted.isEmpty())
65+
throw new IllegalArgumentException("Caches do not exist: " + String.join(", ", notExisted));
6766
}
6867

68+
if (arg.destroyAllCaches())
69+
arg.caches(caches.toArray(U.EMPTY_STRS));
70+
6971
if (F.isEmpty(arg.caches())) {
7072
printer.accept(NOOP_MSG);
7173

0 commit comments

Comments
 (0)