This is an automated email from the ASF dual-hosted git repository.
zstan 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 69e3a7c042a IGNITE-29056 Introduce snapshot lists command to
control.sh (#13666)
69e3a7c042a is described below
commit 69e3a7c042a7116a865aac878ee6eb437eb67a75
Author: Vladimir Steshin <[email protected]>
AuthorDate: Tue Oct 27 10:23:05 2026 +0300
IGNITE-29056 Introduce snapshot lists command to control.sh (#13666)
---
docs/_docs/snapshots/snapshots.adoc | 40 +-
.../testsuites/IgniteControlUtilityTestSuite6.java | 4 +-
.../util/GridCommandHandlerAbstractTest.java | 23 +-
.../util/GridCommandHandlerListSnapshotTest.java | 529 +++++++++++++
.../snapshot/SnapshotCheckCommandArg.java | 4 +-
.../management/snapshot/SnapshotCommand.java | 1 +
.../snapshot/SnapshotDeleteCommandArg.java | 3 +-
.../management/snapshot/SnapshotListCommand.java | 236 ++++++
...CommandArg.java => SnapshotListCommandArg.java} | 22 +-
.../management/snapshot/SnapshotListTask.java | 415 ++++++++++
.../snapshot/SnapshotRestoreCommandArg.java | 8 +-
.../snapshot/IgniteSnapshotManager.java | 6 +-
.../snapshot/SnapshotListJobResult.java | 140 ++++
.../snapshot/SnapshotListTaskResult.java | 84 ++
.../feature/CoreFeatureRegistry.java | 3 +
.../ignite/internal/util/io/GridFileUtils.java | 35 +
...gniteClusterSnapshotListRollingUpgradeTest.java | 227 ++++++
.../snapshot/IgniteClusterSnapshotListTest.java | 849 +++++++++++++++++++++
.../testsuites/IgniteSnapshotTestSuite9.java | 4 +
...ridCommandHandlerClusterByClassTest_help.output | 8 +-
...andHandlerClusterByClassWithSSLTest_help.output | 8 +-
21 files changed, 2607 insertions(+), 42 deletions(-)
diff --git a/docs/_docs/snapshots/snapshots.adoc
b/docs/_docs/snapshots/snapshots.adoc
index 3f5255a798f..8a18cc5cbdb 100644
--- a/docs/_docs/snapshots/snapshots.adoc
+++ b/docs/_docs/snapshots/snapshots.adoc
@@ -287,6 +287,44 @@ control.(sh|bat) --snapshot restore snapshot_09062021
--groups cache-group1,cach
control.(sh|bat) --snapshot restore snapshot_09062021 --increment 1
----
+== Listing Snapshots
+
+To list snapshots created on the cluster, use the following command.
+
+[tabs]
+--
+tab:Unix[]
+[source,shell]
+----
+# List all snapshots in the default snapshot directory.
+control.sh --snapshot list
+
+# List all snapshots in the "/tmp/ignite/snapshots" folder.
+control.sh --snapshot list --src /tmp/ignite/snapshots
+----
+
+tab:Windows[]
+[source,shell]
+----
+# List all snapshots in the default snapshot directory.
+control.bat --snapshot list
+
+# List all snapshots in the "C:\tmp\ignite\snapshots" folder.
+control.bat --snapshot list --src C:\tmp\ignite\snapshots
+----
+--
+
+=== List operation notes
+
+* The list operation is read-only. It does not modify any snapshot data.
+* A snapshot is detected by its metadata. If the metadata is missing or cannot
be read, the snapshot is ignored.
+* The operation reads snapshot metadata and incremental snapshot metadata. On
most platforms, this does not interfere
+with concurrent modification or deletion of snapshots. On Windows, if a
snapshot is deleted at the exact moment its metadata is being read, the
deletion may end up incomplete; repeat the command or check the results
manually. The probability of this is low.
+* Listing and size calculation do not validate snapshots or verify checksums.
+* If a snapshot is being created or deleted, or is corrupted, it might be
skipped or reported partially
+(for example, with an underestimated size). The operation reads what it can
and ignores most errors.
+* The list operation is expected to be fast, so, unlike snapshot creation or
restoration, it cannot be canceled and has no status.
+
== Deleting Snapshot
You can delete a snapshot using the `control.sh|bat` script.
@@ -333,7 +371,7 @@ If the metadata isn't found or cannot be read, snapshot
isn't deleted.
== Getting Snapshot Operation Status
-The status of the current snapshot operation in the cluster can be obtained
using the `control.sh|bat` script or JMX interface:
+The status of the create/restore snapshot operations in the cluster can be
obtained using the `control.sh|bat` script or JMX interface:
[tabs]
--
diff --git
a/modules/control-utility/src/test/java/org/apache/ignite/testsuites/IgniteControlUtilityTestSuite6.java
b/modules/control-utility/src/test/java/org/apache/ignite/testsuites/IgniteControlUtilityTestSuite6.java
index 3719e8d887d..b5b39c31c2a 100644
---
a/modules/control-utility/src/test/java/org/apache/ignite/testsuites/IgniteControlUtilityTestSuite6.java
+++
b/modules/control-utility/src/test/java/org/apache/ignite/testsuites/IgniteControlUtilityTestSuite6.java
@@ -18,6 +18,7 @@
package org.apache.ignite.testsuites;
import org.apache.ignite.util.GridCommandHandlerDeleteSnapshotTest;
+import org.apache.ignite.util.GridCommandHandlerListSnapshotTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@@ -26,7 +27,8 @@ import org.junit.runners.Suite;
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({
- GridCommandHandlerDeleteSnapshotTest.class
+ GridCommandHandlerDeleteSnapshotTest.class,
+ GridCommandHandlerListSnapshotTest.class
})
public class IgniteControlUtilityTestSuite6 {
}
diff --git
a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerAbstractTest.java
b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerAbstractTest.java
index 092fe789032..7d5f2e14c28 100644
---
a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerAbstractTest.java
+++
b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerAbstractTest.java
@@ -499,6 +499,22 @@ public abstract class GridCommandHandlerAbstractTest
extends GridCommandHandlerF
) {
assert nonNull(ignite);
+ CacheConfiguration<?, ?> ccfg = testCacheConfiguration(cacheName,
partitions, filter);
+
+ ignite.createCache(ccfg);
+
+ try (IgniteDataStreamer<Object, Object> streamer =
ignite.dataStreamer(cacheName)) {
+ for (int i = 0; i < countEntries; i++)
+ streamer.addData(i, i);
+ }
+ }
+
+ /** */
+ protected CacheConfiguration<?, ?> testCacheConfiguration(
+ String cacheName,
+ int partitions,
+ @Nullable IgnitePredicate<ClusterNode> filter
+ ) {
CacheConfiguration<?, ?> ccfg = new CacheConfiguration<>(cacheName)
.setAffinity(new RendezvousAffinityFunction(false, partitions))
.setBackups(1)
@@ -507,12 +523,7 @@ public abstract class GridCommandHandlerAbstractTest
extends GridCommandHandlerF
if (filter != null)
ccfg.setNodeFilter(filter);
- ignite.createCache(ccfg);
-
- try (IgniteDataStreamer<Object, Object> streamer =
ignite.dataStreamer(cacheName)) {
- for (int i = 0; i < countEntries; i++)
- streamer.addData(i, i);
- }
+ return ccfg;
}
/**
diff --git
a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerListSnapshotTest.java
b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerListSnapshotTest.java
new file mode 100644
index 00000000000..858f9dbe0de
--- /dev/null
+++
b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerListSnapshotTest.java
@@ -0,0 +1,529 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.util;
+
+import java.io.File;
+import java.nio.file.DirectoryStream;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Collection;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.TimeUnit;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteDataStreamer;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.management.snapshot.SnapshotListCommand;
+import org.apache.ignite.internal.management.snapshot.SnapshotListTask;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.G;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgnitePredicate;
+import org.apache.ignite.spi.systemview.view.ComputeJobView;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.jetbrains.annotations.Nullable;
+import org.junit.Test;
+import org.junit.runners.Parameterized.Parameter;
+import org.junit.runners.Parameterized.Parameters;
+
+import static java.nio.file.Files.newDirectoryStream;
+import static org.apache.ignite.cluster.ClusterState.ACTIVE;
+import static
org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK;
+import static
org.apache.ignite.internal.processors.cache.persistence.snapshot.AbstractSnapshotSelfTest.snp;
+import static
org.apache.ignite.internal.processors.job.GridJobProcessor.JOBS_VIEW;
+import static org.apache.ignite.testframework.GridTestUtils.runAsync;
+import static org.apache.ignite.testframework.GridTestUtils.waitForCondition;
+import static org.junit.Assume.assumeFalse;
+import static org.junit.Assume.assumeTrue;
+
+/** Test for the command '--snapshot list'. */
+public class GridCommandHandlerListSnapshotTest extends
GridCommandHandlerAbstractTest {
+ /** */
+ private static final int GRIDS_CNT = 3;
+
+ /** External storage path. */
+ private static final String EXT_STORAGE_PATH = "extStorage";
+
+ /** Flag to use {@link
DataStorageConfiguration#setExtraSnapshotPaths(String...)}. */
+ private boolean extStorage;
+
+ /** Resolved external storage paths. {@code null} if {@code extStorage} is
{@code false}. */
+ private @Nullable String[] extStoragePaths;
+
+ /** Node consistent id postfix if required. */
+ private String cstIdPostfix = "";
+
+ /** Flag to use the custom paths for the test snapshots. */
+ @Parameter(1)
+ public boolean customPath;
+
+ /** Flag to use separated node working directories. */
+ @Parameter(2)
+ public boolean separatedWorkDir;
+
+ /** Number of incremental snapshots to add to the main test snapshots. */
+ @Parameter(3)
+ public int incrementalsCnt;
+
+ /** */
+ @Parameters(name = "cmdHnd={0}, customPath={1}, separatedWorkDir={2},
incrementalsCnt={3}")
+ public static Collection<?> parameters() {
+ return GridTestUtils.cartesianProduct(
+ commandHandlers(),
+ F.asList(false, true), // Custom test snapshots paths.
+ F.asList(false, true), // Separated nodes' work directories.
+ F.asList(0, 2) // Number of incremental snapshots to add to the
main test snapshots.
+ );
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ super.afterTest();
+
+ stopAllGrids();
+
+ cleanPersistenceDir();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ super.beforeTest();
+
+ /** Handy if the test run is interrupted and {@link #afterTest()}
isn't invoked. */
+ cleanPersistenceDir();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void cleanPersistenceDir() throws Exception {
+ // Cleans everything: separated working directories and snapshots with
custom paths.
+ try (DirectoryStream<Path> files =
newDirectoryStream(Paths.get(U.defaultWorkDirectory()))) {
+ for (Path path : files)
+ U.delete(path);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String
igniteInstanceName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+ String workDir = separatedWorkDir
+ ? new File(U.defaultWorkDirectory(),
igniteInstanceName).getAbsolutePath()
+ : U.defaultWorkDirectory();
+
+ cfg.setWorkDirectory(workDir);
+
+ cfg.getDataStorageConfiguration().setWalCompactionEnabled(true);
+
+ if (extStorage) {
+ cfg.getDataStorageConfiguration().setExtraStoragePaths(
+ workDir + File.separator,
+ workDir + File.separator + EXT_STORAGE_PATH
+ );
+
+ extStoragePaths =
cfg.getDataStorageConfiguration().getExtraStoragePaths();
+
+ cfg.getDataStorageConfiguration().setExtraSnapshotPaths("",
EXT_STORAGE_PATH);
+ }
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String getTestIgniteInstanceName() {
+ return super.getTestIgniteInstanceName() + cstIdPostfix;
+ }
+
+ /** Tests the main scenario when there are no snapshots at all. */
+ @Test
+ public void testNoSnapshots() throws Exception {
+ // Incremental snapshots do not matter here. Speeds up the tests.
+ assumeTrue(incrementalsCnt == 0);
+
+ doTestSnapshotsLists(0);
+ }
+
+ /** Tests the main scenario for a single snapshot. */
+ @Test
+ public void testSingleSnapshot() throws Exception {
+ doTestSnapshotsLists(1);
+ }
+
+ /** Tests the main scenario for several snapshots. */
+ @Test
+ public void testSeveralSnapshots() throws Exception {
+ doTestSnapshotsLists(3);
+ }
+
+ /** Tests the main scenario with an external storage added to the test
snapshots. */
+ @Test
+ public void testExternalStorage() throws Exception {
+ // External storage paths must match those configured in the node PDS
storages, so the cases with different work
+ // directories are skipped. Also, extra snapshot storages aren't used
if snapshot is created with a custom path.
+ assumeFalse(separatedWorkDir || customPath);
+
+ extStorage = true;
+
+ doTestSnapshotsLists(2);
+ }
+
+ /** Tests listing the snapshots created before the cluster restart changed
the node consistent IDs. */
+ @Test
+ public void testChangedConsistentId() throws Exception {
+ // Newly created work directories obviously contain no snapshots.
+ assumeFalse(separatedWorkDir);
+
+ Runnable snapshotsCreatedLsnr = () -> {
+ stopAllGrids();
+
+ cstIdPostfix = "_changed";
+
+ try {
+ startGridsMultiThreaded(GRIDS_CNT);
+
+ startGrid(CLIENT_NODE_NAME_PREFIX);
+ }
+ catch (Exception e) {
+ throw new RuntimeException("Failed to restart the cluster", e);
+ }
+ };
+
+ doTestSnapshotsLists(1, snapshotsCreatedLsnr);
+ }
+
+ /** Test scenario for snapshots list order. */
+ @Test
+ public void testSnapshotsOrder() throws Exception {
+ // Is not so important here, speeds up the tests.
+ assumeFalse(customPath);
+ // We process incremental snapshots manually here.
+ assumeTrue(incrementalsCnt == 0);
+
+ IgniteEx ig = (IgniteEx)startGridsMultiThreaded(GRIDS_CNT);
+ ig.cluster().state(ACTIVE);
+
+ int partitions = 4;
+ int entriesCnt = partitions * 3;
+
+ createCacheAndPreload(ig, DEFAULT_CACHE_NAME, entriesCnt, partitions,
null);
+
+ // Create the snapshots in an order by their names. The sorting order
should differ from the alphabetical order.
+ // 'testSnapshot0' is created first (earliest date).
+ snp(ig).createSnapshot("testSnapshot0", null, false,
false).get(getTestTimeout());
+
+ try (IgniteDataStreamer<Integer, Integer> ds =
ig.dataStreamer(DEFAULT_CACHE_NAME)) {
+ for (int val = entriesCnt; val < entriesCnt * 2; val++)
+ ds.addData(val, val);
+ }
+
+ // Ensures a noticeable difference in the creation times.
+ U.sleep(50L);
+
+ // Next snapshot has the latest date.
+ snp(ig).createSnapshot("testSnapshot1", null, false,
false).get(getTestTimeout());
+
+ injectTestSystemOut();
+
+ assertEquals(EXIT_CODE_OK,
execute(newCommandHandler(createTestLogger()), "--snapshot", "list"));
+
+ String out = testOut.toString();
+
+ int fromIdx = 0;
+
+ // In descending date order testSnapshot1 (later) must appear before
testSnapshot0 (earlier).
+ // The checking is for every node, so n times.
+ for (int n = 0; n < GRIDS_CNT; ++n) {
+ int idx1 = out.indexOf("testSnapshot1", fromIdx);
+ int idx0 = out.indexOf("testSnapshot0", fromIdx);
+
+ assertTrue(idx1 < idx0);
+
+ fromIdx = idx0 + "testSnapshot0".length();
+ }
+
+ // Ensures a noticeable difference in the times.
+ U.sleep(50L);
+
+ // Let's add an incremental part to 'testSnapshot0'. That will change
its modification date.
+ try (IgniteDataStreamer<Integer, Integer> ds =
ig.dataStreamer(DEFAULT_CACHE_NAME)) {
+ for (int val = entriesCnt * 2; val < entriesCnt * 3; val++)
+ ds.addData(val, val);
+ }
+
+ snp(ig).createSnapshot("testSnapshot0", null, true,
false).get(getTestTimeout());
+
+ testOut.reset();
+ fromIdx = 0;
+
+ assertEquals(EXIT_CODE_OK,
execute(newCommandHandler(createTestLogger()), "--snapshot", "list"));
+
+ out = testOut.toString();
+
+ // Now, 'testSnapshot0' is expected to be first.
+ for (int n = 0; n < GRIDS_CNT; ++n) {
+ int idx0 = out.indexOf("testSnapshot0", fromIdx);
+ int idx1 = out.indexOf("testSnapshot1", fromIdx);
+
+ assertTrue(idx0 < idx1);
+
+ fromIdx = idx1 + "testSnapshot1".length();
+ }
+ }
+
+ /** Tests that a node stopping during the snapshots list is reported as a
per-node error only. */
+ @Test
+ public void testNodeStoppedDuringSnapshotsList() throws Exception {
+ // Is not important here, speeds up the tests.
+ assumeTrue(incrementalsCnt == 0 && !customPath);
+
+ IgniteEx ig = (IgniteEx)startGridsMultiThreaded(GRIDS_CNT);
+
+ ig.cluster().state(ACTIVE);
+
+ createCacheAndPreload(ig, DEFAULT_CACHE_NAME, 410, 4, null);
+
+ snp(ig).createSnapshot("testSnapshot0", null, false,
false).get(getTestTimeout());
+
+ // The node to stop concurrently with the list command.
+ int stoppedNodeIdx = GRIDS_CNT - 1;
+
+ IgniteEx stoppedIg = grid(stoppedNodeIdx);
+
+ String stoppedConsId =
stoppedIg.cluster().localNode().consistentId().toString();
+
+ // Blocks the snapshot executor of the node to be stopped, so that its
list job cannot complete
+ // before the node stops.
+ CountDownLatch blockedLatch = new
CountDownLatch(stoppedIg.configuration().getSnapshotThreadPoolSize());
+ CountDownLatch unblockLatch = new CountDownLatch(1);
+
+ ExecutorService snpExec =
stoppedIg.context().pools().getSnapshotExecutorService();
+
+ for (int i = 0; i <
stoppedIg.configuration().getSnapshotThreadPoolSize(); i++) {
+ snpExec.execute(() -> {
+ blockedLatch.countDown();
+
+ try {
+ unblockLatch.await();
+ }
+ catch (InterruptedException ignored) {
+ // No-op: the node is stopping.
+ }
+ });
+ }
+
+ assertTrue(blockedLatch.await(getTestTimeout(),
TimeUnit.MILLISECONDS));
+
+ injectTestSystemOut();
+
+ IgniteInternalFuture<Integer> listFut = GridTestUtils.runAsync(() ->
+ execute(newCommandHandler(createTestLogger()), "--snapshot",
"list"));
+
+ // Waits until the list job hangs on the blocked node. From this
moment on, the node is guaranteed
+ // to report an error instead of a result, whatever happens to the job.
+ assertTrue(waitForCondition(() -> {
+ for (ComputeJobView job :
stoppedIg.context().systemView().<ComputeJobView>view(JOBS_VIEW)) {
+ if
(SnapshotListTask.class.getName().equals(job.taskClassName()))
+ return true;
+ }
+
+ return false;
+ }, getTestTimeout()));
+
+ // The kernal stopping waits for all the jobs to finish. We've blocked
one so that we have to use a future and
+ // wait for the flag.
+ IgniteInternalFuture<?> stopFut = runAsync(() ->
stopGrid(stoppedNodeIdx));
+
+ assertTrue(waitForCondition(() ->
grid(stoppedNodeIdx).context().isStopping(), getTestTimeout()));
+
+ unblockLatch.countDown();
+
+ // The command succeeds despite the failed node.
+ assertEquals(EXIT_CODE_OK, (int)listFut.get());
+
+ stopFut.get(getTestTimeout());
+
+ // Ensure the test node is stopped.
+ assertTrue(waitForCondition(() -> grid(0).cluster().nodes().size() ==
GRIDS_CNT - 1, getTestTimeout()));
+
+ String out = testOut.toString();
+
+ // The stopped node is reported with an error in the standard per-node
format.
+ assertEquals(GRIDS_CNT, countEntries(out, "Node '"));
+ assertEquals(1, countEntries(out, "Node '" + stoppedConsId + "'"));
+
+ // The other nodes still list their snapshots.
+ assertEquals(0, countEntries(out, SnapshotListCommand.NO_SNAPSHOTS));
+
+ assertEquals(GRIDS_CNT - 1, countEntries(out, "testSnapshot0"));
+ assertEquals(GRIDS_CNT - 1, countEntries(out, "Total size"));
+
+ assertEquals(1, countEntries(out, SnapshotListCommand.EXCEPTION_PREF +
+ "Local node is stopping.
[errorType=NodeStoppingException.class]"));
+ }
+
+ /**
+ * The main test scenario:
+ * <ul>
+ * <li>Step 1: Starts cluster</li>
+ * <li>
+ * Step 2: If {@code snapshotsCnt} > 0, creates a cache, fills
it and creates this number of the test snapshots.
+ * <p>If {@link #incrementalsCnt} > 0, adds this number of
incrementals to each snapshot.</p>
+ * <p>If {@link #customPath} is set, uses it as the snapshot path
to create each test snapshot.</p>
+ * <p>If {@code snapshotsCnt} == 0, doesn't create any test
snapshot.</p>
+ * </li>
+ * <li>Step 3: If {@code snapshotsCreatedLsnr} is not null, calls
it.</li>
+ * <li>Step 4: Requests the snapshots list and parses the command's
output.</li>
+ * <li>Step 5: Ensures that all the nodes are present in the
output.</li>
+ * <li>Step 6: If {@code snapshotsCnt} == 0, ensures that the output
says there are no snapshots on any node and quits.</li>
+ * <li>
+ * Step 7: If {@code snapshotsCnt} > 0, checks the snapshots
list of each node in the output.
+ * <p>If {@link #extStorage} is set, also verifies that external
storages are noted in the output.</p>
+ * <p>If {@link #incrementalsCnt} > 0, also verifies that the
incremental snapshots are noted in the output.</p>
+ * </li>
+ * </ul>
+ *
+ * @param snapshotsCnt Number of the test snapshots to create before
calling the snapshots list command.
+ * @param snapshotsCreatedLsnr Optional listener. Is called after the test
snapshots creation.
+ */
+ private void doTestSnapshotsLists(int snapshotsCnt, @Nullable Runnable
snapshotsCreatedLsnr) throws Exception {
+ // A custom snapshot path actually puts snapshots in a shared
directory. This skews the results when dedicated
+ // work directories are set.
+ assumeFalse(customPath && separatedWorkDir);
+
+ // Step 1: Starting the cluster.
+ IgniteEx ig = (IgniteEx)startGridsMultiThreaded(GRIDS_CNT);
+
+ startGrid(CLIENT_NODE_NAME_PREFIX);
+
+ ig.cluster().state(ACTIVE);
+
+ File snpsRootFile = customPath
+ ? new
File(ig.context().pdsFolderResolver().fileTree().snapshotsRoot(),
"ex_snapshots")
+ : null;
+
+ // Step 2: Cache and snapshot creation, if any.
+ if (snapshotsCnt > 0) {
+ int partitions = 4;
+ int entriesCnt = partitions * 3;
+
+ // Create cache.
+ createCacheAndPreload(ig, DEFAULT_CACHE_NAME, entriesCnt,
partitions, null);
+
+ String absPathStr;
+
+ // Create the test snapshots.
+ for (int snpIdx = 0; snpIdx < snapshotsCnt; snpIdx++) {
+ absPathStr = customPath ? snpsRootFile.getAbsolutePath() :
null;
+
+ snp(ig).createSnapshot("testSnapshot" + snpIdx, absPathStr,
false, false).get(getTestTimeout());
+
+ // Create the optional incremental snapshots.
+ for (int incIdx = 0; incIdx < incrementalsCnt; incIdx++) {
+ try (IgniteDataStreamer<Integer, Integer> ds =
ig.dataStreamer(DEFAULT_CACHE_NAME)) {
+ for (int val = (snpIdx + incIdx + 1) * entriesCnt; val
< (snpIdx + incIdx + 2) * entriesCnt; val++)
+ ds.addData(val, val);
+ }
+
+ snp(ig).createSnapshot("testSnapshot" + snpIdx,
absPathStr, true, false).get(getTestTimeout());
+ }
+ }
+ }
+
+ // Step 3: After the test snapshots are created, invoke optional test
listener.
+ if (snapshotsCreatedLsnr != null)
+ snapshotsCreatedLsnr.run();
+
+ // Step 4: Prepare and invoke the snapshots list command.
+ injectTestSystemOut();
+
+ if (customPath) {
+ assertEquals(EXIT_CODE_OK,
execute(newCommandHandler(createTestLogger()), "--snapshot", "list", "--src",
+ snpsRootFile.getAbsolutePath()));
+ }
+ else
+ assertEquals(EXIT_CODE_OK,
execute(newCommandHandler(createTestLogger()), "--snapshot", "list"));
+
+ String out = testOut.toString();
+
+ // Step 5: Find the nodes in the output.
+ for (Ignite g : G.allGrids()) {
+ ClusterNode n = g.cluster().localNode();
+
+ assertEquals(n.isClient() ? 0 : 1, countEntries(out, "Node
'%s'".formatted(n.consistentId().toString())));
+ }
+
+ // Step 6: Ensure that there are no snapshots if none are expected and
exit.
+ if (snapshotsCnt == 0) {
+ assertFalse(out.contains("Total size"));
+ assertFalse(out.contains("Creation date"));
+
+ assertEquals(GRIDS_CNT, countEntries(out,
SnapshotListCommand.NO_SNAPSHOTS));
+
+ return;
+ }
+
+ // Step 7: Find the test snapshots in the output.
+ assertEquals(0, countEntries(out, SnapshotListCommand.NO_SNAPSHOTS));
+
+ for (int snpIdx = 0; snpIdx < snapshotsCnt; snpIdx++) {
+ assertEquals(GRIDS_CNT, countEntries(out, "testSnapshot" +
snpIdx));
+
+ // If the external storage is configured, find their titles.
+ if (extStorage)
+ assertEquals(GRIDS_CNT, countEntries(out, "External storages
size"));
+ }
+
+ // If the incremental snapshots are configured, find their titles.
+ if (incrementalsCnt > 0) {
+ assertEquals(GRIDS_CNT, countEntries(out, "Last incremental
date"));
+ assertEquals(GRIDS_CNT, countEntries(out, "Incremental parts
size"));
+ }
+ }
+
+ /** {@link #doTestSnapshotsLists(int, Runnable)} with {@code
snapshotsCreatedLsnr}. */
+ private void doTestSnapshotsLists(int snapshotsCnt) throws Exception {
+ doTestSnapshotsLists(snapshotsCnt, null);
+ }
+
+ /** @return Number of the test entries in the original text. */
+ private static int countEntries(String txt, String entry) {
+ String prev = txt;
+
+ txt = txt.replace(entry, "");
+
+ return (prev.length() - txt.length()) / entry.length();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected CacheConfiguration<?, ?> testCacheConfiguration(
+ String cacheName,
+ int partitions,
+ @Nullable IgnitePredicate<ClusterNode> filter
+ ) {
+ CacheConfiguration<?, ?> ccfg =
super.testCacheConfiguration(cacheName, partitions, filter);
+
+ if (extStorage)
+ ccfg.setStoragePaths(extStoragePaths);
+
+ return ccfg;
+ }
+}
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/management/snapshot/SnapshotCheckCommandArg.java
b/modules/core/src/main/java/org/apache/ignite/internal/management/snapshot/SnapshotCheckCommandArg.java
index 27d59eab504..ba518d586df 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/management/snapshot/SnapshotCheckCommandArg.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/management/snapshot/SnapshotCheckCommandArg.java
@@ -36,9 +36,7 @@ public class SnapshotCheckCommandArg extends
IgniteDataTransferObject {
/** */
@Order(1)
- @Argument(example = "path", optional = true,
- description = "Path to the directory where the snapshot files are
located. " +
- "If not specified, the default configured snapshot directory will
be used")
+ @Argument(example = "path", optional = true, description =
SnapshotRestoreCommandArg.SRC_PATH_DESCRIPTION)
String src;
/** */
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/management/snapshot/SnapshotCommand.java
b/modules/core/src/main/java/org/apache/ignite/internal/management/snapshot/SnapshotCommand.java
index 8979958bd8f..8078a319948 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/management/snapshot/SnapshotCommand.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/management/snapshot/SnapshotCommand.java
@@ -29,6 +29,7 @@ public class SnapshotCommand extends CommandRegistryImpl {
new SnapshotCheckCommand(),
new SnapshotRestoreCommand(),
new SnapshotStatusCommand(),
+ new SnapshotListCommand(),
new SnapshotDeleteCommand()
);
}
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/management/snapshot/SnapshotDeleteCommandArg.java
b/modules/core/src/main/java/org/apache/ignite/internal/management/snapshot/SnapshotDeleteCommandArg.java
index afe1afef7d4..0d6903a7098 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/management/snapshot/SnapshotDeleteCommandArg.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/management/snapshot/SnapshotDeleteCommandArg.java
@@ -36,8 +36,7 @@ public class SnapshotDeleteCommandArg extends
IgniteDataTransferObject {
/** */
@Order(1)
- @Argument(example = "path/to/snapshots", optional = true, description =
"Path to snapshot location directory. " +
- "If not specified, the default snapshot configuration directory will
be used")
+ @Argument(example = "path/to/snapshots", optional = true, description =
SnapshotRestoreCommandArg.SRC_PATH_DESCRIPTION)
@Nullable String src;
/** */
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/management/snapshot/SnapshotListCommand.java
b/modules/core/src/main/java/org/apache/ignite/internal/management/snapshot/SnapshotListCommand.java
new file mode 100644
index 00000000000..1b7949f5be5
--- /dev/null
+++
b/modules/core/src/main/java/org/apache/ignite/internal/management/snapshot/SnapshotListCommand.java
@@ -0,0 +1,236 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.management.snapshot;
+
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.internal.management.SystemViewCommand;
+import org.apache.ignite.internal.management.SystemViewTask;
+import
org.apache.ignite.internal.processors.cache.persistence.snapshot.SnapshotListJobResult;
+import
org.apache.ignite.internal.processors.cache.persistence.snapshot.SnapshotListTaskResult;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.T2;
+import org.apache.ignite.internal.util.typedef.X;
+import org.apache.ignite.internal.util.typedef.internal.U;
+
+import static
org.apache.ignite.internal.management.SystemViewTask.SimpleType.DATE;
+import static
org.apache.ignite.internal.management.SystemViewTask.SimpleType.NUMBER;
+import static
org.apache.ignite.internal.management.SystemViewTask.SimpleType.STRING;
+
+/** Snapshot list command. */
+public class SnapshotListCommand extends
AbstractSnapshotCommand<SnapshotListCommandArg, SnapshotListTaskResult> {
+ /** */
+ public static final String HEADER = "Snapshots were found on the following
nodes:";
+
+ /** */
+ public static final String DESC = "Lists all snapshots on all online
server nodes, including their sizes";
+
+ /** */
+ public static final String NO_SNAPSHOTS = "No snapshots found.";
+
+ /** */
+ public static final String EXCEPTION_PREF = "ERROR: ";
+
+ /** {@inheritDoc} */
+ @Override public String description() {
+ return DESC;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Class<SnapshotListCommandArg> argClass() {
+ return SnapshotListCommandArg.class;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Class<SnapshotListTask> taskClass() {
+ return SnapshotListTask.class;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void printResult(SnapshotListCommandArg arg,
SnapshotListTaskResult res, Consumer<String> printer) {
+ printer.accept(HEADER);
+
+ // Sorting the results by consistent id for better reading.
+ Integer[] nodesOrder = IntStream.range(0,
res.nodesIds().length).boxed()
+ .sorted(Comparator.comparing(idx -> res.consistentIds()[idx]))
+ .toArray(Integer[]::new);
+
+ // Flag whether the node's result has at least one incremental
snapshot and one external storage.
+ T2<Boolean, Boolean> incsAndExtStors = new T2<>();
+
+ for (int nodeIdx : nodesOrder) {
+ printer.accept("");
+
+ printer.accept("Node '%s'
[uuid=%s]:".formatted(res.consistentIds()[nodeIdx], res.nodesIds()[nodeIdx]));
+
+ IgniteException nodeErr = res.errors() == null ||
res.errors()[nodeIdx] == null ? null : res.errors()[nodeIdx];
+
+ if (nodeErr != null) {
+ Throwable cause = X.cause(nodeErr,
IgniteCheckedException.class);
+
+ if (cause == null)
+ cause = nodeErr;
+
+ printer.accept(EXCEPTION_PREF + "%s [errorType=%s.class]"
+ .formatted(cause.getMessage(),
cause.getClass().getSimpleName()));
+
+ continue;
+ }
+
+ SnapshotListJobResult nodeResult = res.nodesSnapshots()[nodeIdx];
+
+ if (nodeResult.snapshots().isEmpty()) {
+ printer.accept(NO_SNAPSHOTS);
+
+ continue;
+ }
+
+ Map<String, SnapshotListJobResult.SnapshotInfo> perNodeResults =
prepareResults(nodeResult.snapshots(), incsAndExtStors);
+
+ SystemViewCommand.printTable(
+ perNodeTableTitles(incsAndExtStors.get1(),
incsAndExtStors.get2()),
+ perNodeTableTypes(incsAndExtStors.get1(),
incsAndExtStors.get2()),
+ perNodeTableRows(perNodeResults, incsAndExtStors.get1(),
incsAndExtStors.get2()),
+ printer
+ );
+ }
+
+ printer.accept("");
+ }
+
+ /** */
+ private static List<String> perNodeTableTitles(boolean hasIncrementals,
boolean hasExtStorages) {
+ List<String> res = new ArrayList<>(7);
+
+ res.addAll(F.asList("Name", "Total size", "Creation date"));
+
+ if (hasIncrementals)
+ res.addAll(F.asList("Last incremental date", "Incremental parts",
"Incremental parts size"));
+
+ if (hasExtStorages)
+ res.addAll(F.asList("External storages size"));
+
+ return res;
+ }
+
+ /** */
+ private static List<SystemViewTask.SimpleType> perNodeTableTypes(boolean
hasIncrementals, boolean hasExtStorages) {
+ List<SystemViewTask.SimpleType> res = new ArrayList<>(7);
+
+ // Main columns: name, size (formatted string), creation date
(formatted string).
+ res.addAll(F.asList(STRING, STRING, DATE));
+
+ // Optional columns of incremental parts: last modification date,
number of incremental parts, total size (formatted string).
+ if (hasIncrementals)
+ res.addAll(F.asList(DATE, NUMBER, STRING));
+
+ // Optional column of external storages: total size (formatted string).
+ if (hasExtStorages)
+ res.add(STRING);
+
+ return res;
+ }
+
+ /** */
+ private static List<List<?>> perNodeTableRows(
+ Map<String, SnapshotListJobResult.SnapshotInfo> results,
+ boolean includeIncrementals,
+ boolean includeExtStorages
+ ) {
+ List<List<?>> table = new ArrayList<>(results.size());
+
+ results.forEach((name, s) -> {
+ List<Object> row = new ArrayList<>(7);
+
+ // Main columns: name, size (formatted string), creation date
(formatted string).
+ row.addAll(F.asList(name, U.humanReadableByteCount(s.size()),
Date.from(Instant.ofEpochMilli(s.date()))));
+
+ if (includeIncrementals) {
+ // Optional columns of incremental parts: last modification
date, count, total size (formatted string).
+ SnapshotListJobResult.SnapshotInfo inc = s.incrementals();
+
+ // Empty strings instead of nulls to avoid 'null' in empty
table cells.
+ row.addAll(F.asList(
+ inc == null ? "" :
Date.from(Instant.ofEpochMilli(inc.date())), // Modification date.
+ inc == null ? "" : inc.number(), // Count.
+ inc == null ? "" : U.humanReadableByteCount(inc.size()) //
Total size.
+ ));
+ }
+
+ if (includeExtStorages) {
+ // Optional column of external storages size.
+ SnapshotListJobResult.SnapshotInfo ext = s.externalStorages();
+
+ row.add(ext == null ? "" :
U.humanReadableByteCount(ext.size())); // Total size of all external storages.
+ }
+
+ table.add(row);
+ });
+
+ return table;
+ }
+
+ /** Prepares the results: sorts, finds optional data to hide if it doesn't
present. */
+ private static Map<String, SnapshotListJobResult.SnapshotInfo>
prepareResults(
+ Map<String, SnapshotListJobResult.SnapshotInfo> rawResults,
+ T2<Boolean, Boolean> hasIncsAndExtStrs
+ ) {
+ Comparator<SnapshotListJobResult.SnapshotInfo> cmp = new
Comparator<>() {
+ @Override public int compare(SnapshotListJobResult.SnapshotInfo
s1, SnapshotListJobResult.SnapshotInfo s2) {
+ long date1 = s1.incrementals() == null ? s1.date() :
s1.incrementals().date();
+ long date2 = s2.incrementals() == null ? s2.date() :
s2.incrementals().date();
+
+ return Long.compare(date2, date1);
+ }
+ };
+
+ hasIncsAndExtStrs.set1(false);
+ hasIncsAndExtStrs.set2(false);
+
+ // Sorted by the creation or modification date.
+ return rawResults.entrySet()
+ .stream()
+ .sorted(Map.Entry.comparingByValue(cmp))
+ // Always-accepting filter: sets the optional-column flags while
collecting, in one pass.
+ .filter(e -> {
+ if (e.getValue().incrementals() != null)
+ hasIncsAndExtStrs.set1(true);
+
+ if (e.getValue().externalStorages() != null)
+ hasIncsAndExtStrs.set2(true);
+
+ return true;
+ })
+ .collect(Collectors.toMap(
+ Map.Entry::getKey,
+ Map.Entry::getValue,
+ (e1, e2) -> e1,
+ LinkedHashMap::new
+ ));
+ }
+}
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/management/snapshot/SnapshotDeleteCommandArg.java
b/modules/core/src/main/java/org/apache/ignite/internal/management/snapshot/SnapshotListCommandArg.java
similarity index 69%
copy from
modules/core/src/main/java/org/apache/ignite/internal/management/snapshot/SnapshotDeleteCommandArg.java
copy to
modules/core/src/main/java/org/apache/ignite/internal/management/snapshot/SnapshotListCommandArg.java
index afe1afef7d4..95a0048b349 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/management/snapshot/SnapshotDeleteCommandArg.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/management/snapshot/SnapshotListCommandArg.java
@@ -20,36 +20,18 @@ package org.apache.ignite.internal.management.snapshot;
import org.apache.ignite.internal.Order;
import org.apache.ignite.internal.dto.IgniteDataTransferObject;
import org.apache.ignite.internal.management.api.Argument;
-import org.apache.ignite.internal.management.api.Positional;
import org.jetbrains.annotations.Nullable;
/** */
-public class SnapshotDeleteCommandArg extends IgniteDataTransferObject {
+public class SnapshotListCommandArg extends IgniteDataTransferObject {
/** */
private static final long serialVersionUID = 0;
/** */
@Order(0)
- @Positional
- @Argument(description = "Snapshot name")
- @Nullable String snapshotName;
-
- /** */
- @Order(1)
- @Argument(example = "path/to/snapshots", optional = true, description =
"Path to snapshot location directory. " +
- "If not specified, the default snapshot configuration directory will
be used")
+ @Argument(example = "path/to/snapshots", optional = true, description =
SnapshotRestoreCommandArg.SRC_PATH_DESCRIPTION)
@Nullable String src;
- /** */
- public @Nullable String snapshotName() {
- return snapshotName;
- }
-
- /** */
- public void snapshotName(@Nullable String snapshotName) {
- this.snapshotName = snapshotName;
- }
-
/** */
public @Nullable String src() {
return src;
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/management/snapshot/SnapshotListTask.java
b/modules/core/src/main/java/org/apache/ignite/internal/management/snapshot/SnapshotListTask.java
new file mode 100644
index 00000000000..226845508fa
--- /dev/null
+++
b/modules/core/src/main/java/org/apache/ignite/internal/management/snapshot/SnapshotListTask.java
@@ -0,0 +1,415 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.management.snapshot;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.compute.ComputeJobResult;
+import org.apache.ignite.internal.NodeStoppingException;
+import
org.apache.ignite.internal.processors.cache.persistence.filename.SnapshotFileTree;
+import
org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager;
+import
org.apache.ignite.internal.processors.cache.persistence.snapshot.IncrementalSnapshotMetadata;
+import
org.apache.ignite.internal.processors.cache.persistence.snapshot.SnapshotListJobResult;
+import
org.apache.ignite.internal.processors.cache.persistence.snapshot.SnapshotListTaskResult;
+import
org.apache.ignite.internal.processors.cache.persistence.snapshot.SnapshotMetadata;
+import
org.apache.ignite.internal.processors.rollingupgrade.feature.CoreFeatureRegistry;
+import org.apache.ignite.internal.processors.task.GridInternal;
+import org.apache.ignite.internal.thread.pool.IgniteThreadPoolExecutor;
+import org.apache.ignite.internal.util.io.GridFileUtils;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.T2;
+import org.apache.ignite.internal.util.typedef.X;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.internal.visor.VisorJob;
+import org.apache.ignite.internal.visor.VisorMultiNodeTask;
+import org.apache.ignite.internal.visor.VisorTaskArgument;
+import org.apache.ignite.resources.LoggerResource;
+import org.jetbrains.annotations.Nullable;
+
+import static org.apache.ignite.internal.util.lang.ClusterNodeFunc.nodeIds;
+
+/** */
+@GridInternal
+public class SnapshotListTask extends
VisorMultiNodeTask<SnapshotListCommandArg, SnapshotListTaskResult,
SnapshotListJobResult> {
+ /** Serial version uid. */
+ private static final long serialVersionUID = 0L;
+
+ /** */
+ public static final String FEATURE_NOT_ACTIVE_ERR_MSG = "Won't search for
local snapshots. " +
+ "The snapshot list feature isn't activated yet. The Rolling Upgrade
has to be finished.";
+
+ /** {@inheritDoc} */
+ @Override protected VisorJob<SnapshotListCommandArg,
SnapshotListJobResult> job(SnapshotListCommandArg arg) {
+ return new SnapshotListJob(arg, debug);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected Collection<UUID>
jobNodes(VisorTaskArgument<SnapshotListCommandArg> arg) {
+ if
(!ignite.context().rollingUpgrade().features().isActive(CoreFeatureRegistry.SNAPSHOT_LIST_FEATURE))
+ throw new IgniteException(FEATURE_NOT_ACTIVE_ERR_MSG);
+
+ /** Allows {@link #map0(List, VisorTaskArgument)} to use the entire
grid. */
+ return nodeIds(ignite.cluster().forServers().nodes());
+ }
+
+ /** {@inheritDoc} */
+ @Override protected SnapshotListTaskResult reduce0(List<ComputeJobResult>
nodesJobsResults) throws IgniteException {
+ String[] consistentIds = new String[nodesJobsResults.size()];
+ UUID[] nodesIds = new UUID[nodesJobsResults.size()];
+ SnapshotListJobResult[] nodesResults = new
SnapshotListJobResult[nodesJobsResults.size()];
+ // Errors aren't expected by default.
+ IgniteException[] errors = null;
+
+ for (int i = 0; i < nodesJobsResults.size(); i++) {
+ ComputeJobResult nodeJobRes = nodesJobsResults.get(i);
+
+ consistentIds[i] = nodeJobRes.getNode().consistentId().toString();
+ nodesIds[i] = nodeJobRes.getNode().id();
+
+ if (nodeJobRes.getException() != null) {
+ if (errors == null)
+ errors = new IgniteException[nodesJobsResults.size()];
+
+ errors[i] = nodeJobRes.getException();
+
+ continue;
+ }
+
+ assert nodeJobRes.getData() != null;
+
+ nodesResults[i] = nodeJobRes.getData();
+ }
+
+ return new SnapshotListTaskResult(consistentIds, nodesIds,
nodesResults, errors);
+ }
+
+ /** */
+ private static class SnapshotListJob extends
SnapshotJob<SnapshotListCommandArg, SnapshotListJobResult> {
+ /** Serial version uid. */
+ private static final long serialVersionUID = 0L;
+
+ /** */
+ @LoggerResource
+ private IgniteLogger log;
+
+ /**
+ * @param arg Snapshot list task argument.
+ * @param debug Flag indicating whether debug information should be
printed into node log.
+ */
+ protected SnapshotListJob(SnapshotListCommandArg arg, boolean debug) {
+ super(arg, debug);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected SnapshotListJobResult run(SnapshotListCommandArg
arg) {
+ assert !ignite.localNode().isClient();
+
+ if (ignite.context().isStopping())
+ throw new IgniteException("Won't search for local snapshots.",
new NodeStoppingException("Local node is stopping."));
+
+ // Read local snapshots.
+ List<T2<SnapshotFileTree, Long>> locSnps =
findLocalSnapshots(arg.src());
+
+ if (locSnps.isEmpty())
+ return new SnapshotListJobResult(Collections.emptyMap());
+
+ // Main sizes of the local snapshots (per snapshot name).
+ Map<String, Long> sizes = new ConcurrentHashMap<>(locSnps.size(),
1.0f);
+ // Optional incremental parts descriptions (per snapshot name).
+ Map<String, SnapshotListJobResult.SnapshotInfo> incs = new
ConcurrentHashMap<>(locSnps.size(), 1.0f);
+ // Optional external storages descriptions (per snapshot name).
+ Map<String, SnapshotListJobResult.SnapshotInfo> extStors = new
ConcurrentHashMap<>(locSnps.size(), 1.0f);
+
+ // Snapshot sizes, incremental parts and external storages futures.
+ List<Future<?>> futs = new ArrayList<>(locSnps.size() * 3);
+ // Names of snapshots with read failures.
+ Set<String> failedSnps =
ConcurrentHashMap.newKeySet(locSnps.size() / 2);
+
+ IgniteThreadPoolExecutor exec =
ignite.context().pools().getSnapshotExecutorService();
+
+ // Descriptions of the local snapshots: main sizes, external
storages and incremental parts.
+ for (T2<SnapshotFileTree, Long> snpPair : locSnps) {
+ SnapshotFileTree sft = snpPair.get1();
+ String snpName = sft.name();
+
+ // Future for the snapshot main size. It is the largest part
of the job, thus it goes first.
+ Future<?> fut = exec.submit(() -> {
+ checkNodeIsStopping();
+
+ if (failedSnps.contains(snpName))
+ return;
+
+ try {
+ sizes.put(snpName,
GridFileUtils.sizeOfDirectory(sft.root()));
+ }
+ catch (Exception e) {
+ failedSnps.add(snpName);
+
+ log.warning("Failed to calculate snapshot's size,
snapshot ignored [snpName='" + snpName + "']", e);
+ }
+ });
+
+ futs.add(fut);
+
+ // Future for optional incremental parts.
+ fut = exec.submit(() -> {
+ checkNodeIsStopping();
+
+ if (failedSnps.contains(snpName))
+ return;
+
+ try {
+ SnapshotListJobResult.SnapshotInfo incDesc =
incrementals(sft);
+
+ if (incDesc != null)
+ incs.put(snpName, incDesc);
+ }
+ catch (Exception e) {
+ failedSnps.add(snpName);
+
+ log.warning("Failed to read snapshot's incremental
parts, snapshot ignored [snpName='" + snpName + "']", e);
+ }
+ });
+
+ futs.add(fut);
+
+ // Future for optional external storages.
+ fut = exec.submit(() -> {
+ checkNodeIsStopping();
+
+ if (failedSnps.contains(snpName))
+ return;
+
+ try {
+ SnapshotListJobResult.SnapshotInfo extDesc =
externalStorages(sft);
+
+ if (extDesc != null)
+ extStors.put(snpName, extDesc);
+ }
+ catch (Exception e) {
+ failedSnps.add(snpName);
+
+ log.warning("Failed to read snapshot's external
storages, snapshot ignored [snpName='" + snpName + "']", e);
+ }
+ });
+
+ futs.add(fut);
+ }
+
+ // Wait for the futures.
+ for (Future<?> fut : futs) {
+ try {
+ fut.get();
+ }
+ catch (ExecutionException e) {
+ throw new IgniteException("Failed to read local node's
snapshots.", e);
+ }
+ catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+
+ throw new IgniteException("Interrupted while reading local
snapshots.", e);
+ }
+ }
+
+ // Result snapshot descriptions.
+ Map<String, SnapshotListJobResult.SnapshotInfo> resMap =
U.newHashMap(locSnps.size() - failedSnps.size());
+
+ // Reduce results.
+ for (T2<SnapshotFileTree, Long> snpPair : locSnps) {
+ String snpName = snpPair.get1().name();
+
+ if (failedSnps.contains(snpName))
+ continue;
+
+ Long size = sizes.get(snpName);
+
+ // The size must be calculated unless the snapshot has failed.
+ assert size != null;
+
+ SnapshotListJobResult.SnapshotInfo snpDesc = new
SnapshotListJobResult.SnapshotInfo(
+ size,
+ snpPair.get2(),
+ extStors.get(snpName),
+ incs.get(snpName)
+ );
+
+ resMap.put(snpName, snpDesc);
+ }
+
+ return new SnapshotListJobResult(resMap);
+ }
+
+ /** */
+ private void checkNodeIsStopping() {
+ if (ignite.context().isStopping()) {
+ throw new IgniteException(
+ "Won't search for local snapshots due to the local node
stopping.",
+ new NodeStoppingException("Local node is stopping.")
+ );
+ }
+ }
+
+ /** */
+ private @Nullable SnapshotListJobResult.SnapshotInfo
externalStorages(SnapshotFileTree sft) {
+ int extStoragesCnt = 0;
+ long extStoragesSize = 0;
+
+ for (File extStorage : sft.allStorages().toList()) {
+ if (sft.nodeStorage().equals(extStorage))
+ continue;
+
+ try {
+ extStoragesSize +=
GridFileUtils.sizeOfDirectory(extStorage);
+ }
+ catch (Exception e) {
+ log.warning("Failed to calculate snapshot's external
storage size, storage ignored [externalStorage='" +
+ extStorage + "']", e);
+
+ continue;
+ }
+
+ extStoragesCnt++;
+ }
+
+ return extStoragesCnt == 0 ? null : new
SnapshotListJobResult.SnapshotInfo(extStoragesCnt, extStoragesSize);
+ }
+
+ /** @return Snapshot file trees and related snapshots' creation times
from the snapshot metadata. */
+ private List<T2<SnapshotFileTree, Long>> findLocalSnapshots(@Nullable
String snpPath) {
+ // The tree is used only to obtain the snapshots root directory.
The snapshot name is irrelevant here.
+ File[] dirsToParse = new SnapshotFileTree(ignite.context(), "snp",
snpPath).root().getParentFile().listFiles();
+
+ if (F.isEmpty(dirsToParse))
+ return Collections.emptyList();
+
+ List<Future<T2<SnapshotFileTree, Long>>> futs = new
ArrayList<>(dirsToParse.length);
+
+ IgniteThreadPoolExecutor exec =
ignite.context().pools().getSnapshotExecutorService();
+
+ for (File snpDir : dirsToParse) {
+ Future<T2<SnapshotFileTree, Long>> snpDirFut = exec.submit(()
-> {
+ checkNodeIsStopping();
+
+ String snpName = snpDir.getName();
+
+ // The tree is used only as a path for reading the
snapshot metadata.
+ SnapshotFileTree sft = new
SnapshotFileTree(ignite.context(), snpName, snpPath);
+
+ List<SnapshotMetadata> metas =
ignite.context().cache().context().snapshotMgr().readSnapshotMetadatas(sft,
false);
+
+ if (metas.isEmpty())
+ return null;
+
+ // Get the metadata of the most recently created snapshot.
+ SnapshotMetadata snpMeta =
metas.stream().max(Comparator.comparingLong(SnapshotMetadata::snapshotTime)).get();
+
+ // Snapshot file tree based on its metadata. Holds the
real snapshot consistent ID and corresponding
+ // snapshot directory name.
+ sft = new SnapshotFileTree(
+ ignite.configuration(),
+ ignite.context().pdsFolderResolver().fileTree(),
+ snpName,
+ snpPath,
+ snpMeta.folderName(),
+ snpMeta.consistentId()
+ );
+
+ return new T2<>(sft, snpMeta.snapshotTime());
+ });
+
+ futs.add(snpDirFut);
+ }
+
+ List<T2<SnapshotFileTree, Long>> res = new
ArrayList<>(dirsToParse.length);
+
+ futs.forEach(f -> {
+ try {
+ T2<SnapshotFileTree, Long> snpDirRes = f.get();
+
+ if (snpDirRes != null)
+ res.add(snpDirRes);
+ }
+ catch (ExecutionException e) {
+ if (X.hasCause(e, NodeStoppingException.class))
+ throw new IgniteException("Won't search for local
snapshots.", e.getCause());
+
+ log.warning("Failed to read snapshot, snapshot ignored.",
e);
+ }
+ catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+
+ throw new IgniteException("Interrupted while reading local
snapshots.", e);
+ }
+ });
+
+ return res;
+ }
+
+ /** @return Number, total size and last creation time of incremental
snapshots, or {@code null} if there are none. */
+ private @Nullable SnapshotListJobResult.SnapshotInfo
incrementals(SnapshotFileTree sft) {
+ File[] incs = sft.incrementsRoot().listFiles();
+
+ if (F.isEmpty(incs))
+ return null;
+
+ int cnt = 0;
+ long size = 0L;
+ long createTime = 0L;
+
+ IgniteSnapshotManager snpMgr =
ignite.context().cache().context().snapshotMgr();
+
+ int incIdx;
+
+ for (File incDir : incs) {
+ if (!SnapshotFileTree.incrementSnapshotDir(incDir) ||
!incDir.exists())
+ continue;
+
+ try {
+ incIdx = Integer.parseInt(incDir.getName());
+
+ SnapshotFileTree.IncrementalSnapshotFileTree incTree =
sft.incrementalSnapshotFileTree(incIdx);
+
+ IncrementalSnapshotMetadata incMeta =
snpMgr.readIncrementalSnapshotMetadata(incTree.meta());
+
+ size += GridFileUtils.sizeOfDirectory(incDir);
+
+ createTime = Math.max(createTime, incMeta.snapshotTime());
+
+ cnt++;
+ }
+ catch (Exception e) {
+ log.warning("Failed to read incremental snapshot,
incremental part ignored [dir='" + incDir + "']", e);
+ }
+ }
+
+ return cnt == 0 ? null : new
SnapshotListJobResult.SnapshotInfo(cnt, size, createTime);
+ }
+ }
+}
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/management/snapshot/SnapshotRestoreCommandArg.java
b/modules/core/src/main/java/org/apache/ignite/internal/management/snapshot/SnapshotRestoreCommandArg.java
index 1c053bca73a..0d0fa423f7a 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/management/snapshot/SnapshotRestoreCommandArg.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/management/snapshot/SnapshotRestoreCommandArg.java
@@ -30,6 +30,10 @@ public class SnapshotRestoreCommandArg extends
IgniteDataTransferObject {
/** */
private static final long serialVersionUID = 0;
+ /** Common description of the snapshot source path argument. */
+ public static final String SRC_PATH_DESCRIPTION = "Path to the directory
where the snapshot files are located. " +
+ "If not specified, the default configured snapshot directory will be
used";
+
/** */
@Order(0)
@Positional
@@ -50,9 +54,7 @@ public class SnapshotRestoreCommandArg extends
IgniteDataTransferObject {
/** */
@Order(3)
- @Argument(example = "path", optional = true,
- description = "Path to the directory where the snapshot files are
located. " +
- "If not specified, the default configured snapshot directory will
be used")
+ @Argument(example = "path", optional = true, description =
SRC_PATH_DESCRIPTION)
String src;
/** */
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteSnapshotManager.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteSnapshotManager.java
index d3b19b65f0f..11afe3182fb 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteSnapshotManager.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteSnapshotManager.java
@@ -2011,12 +2011,10 @@ public class IgniteSnapshotManager extends
GridCacheSharedManagerAdapter
prev = curr;
}
catch (Exception e) {
- String err = "Fail to read snapshot metadata [meta=" + smf +
']';
-
if (failIfCantRead)
- throw new IgniteException(err, e);
+ throw new IgniteException("Failed to read snapshot
metadata [meta=" + smf + ']', e);
else
- log.error(err, e);
+ log.warning("Failed to read snapshot metadata, the file is
skipped [meta=" + smf + ']', e);
}
}
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotListJobResult.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotListJobResult.java
new file mode 100644
index 00000000000..cf920286cbb
--- /dev/null
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotListJobResult.java
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.persistence.snapshot;
+
+import java.util.Map;
+import org.apache.ignite.internal.Order;
+import org.apache.ignite.internal.dto.IgniteDataTransferObject;
+import org.jetbrains.annotations.Nullable;
+
+/** Per-node result of the snapshot list task. Contains information about the
snapshots found on the node. */
+public final class SnapshotListJobResult extends IgniteDataTransferObject {
+ /** Serial version uid. */
+ private static final long serialVersionUID = 0L;
+
+ /** Local node's snapshot descriptions. */
+ @Order(0)
+ Map<String, SnapshotInfo> snapshots;
+
+ /** Default constructor for serialization purposes. */
+ public SnapshotListJobResult() {
+ // No-op.
+ }
+
+ /** */
+ public SnapshotListJobResult(Map<String, SnapshotInfo> snapshots) {
+ this.snapshots = snapshots;
+ }
+
+ /** @return Snapshot descriptions by snapshot name. */
+ public Map<String, SnapshotInfo> snapshots() {
+ return snapshots;
+ }
+
+ /** Holds information about a snapshot or its parts: size, creation time,
number of incremental parts or external storages. */
+ public static class SnapshotInfo extends IgniteDataTransferObject {
+ /** Serial version uid. */
+ private static final long serialVersionUID = 0L;
+
+ /** Total size of a snapshot. Or size of its external storages or
incremental parts. */
+ @Order(0)
+ long size;
+
+ /** Creation date of the snapshot or of its incremental parts. */
+ @Order(1)
+ @Nullable Long date;
+
+ /** Snapshot external storages description if it exists. */
+ @Order(2)
+ @Nullable SnapshotInfo extStors;
+
+ /** Snapshot incremental parts description if it exists. */
+ @Order(3)
+ @Nullable SnapshotInfo incs;
+
+ /** Number of snapshot external storages or incremental parts. */
+ @Order(4)
+ @Nullable Integer cnt;
+
+ /** Empty constructor for serialization purposes. */
+ public SnapshotInfo() {
+ // No-op.
+ }
+
+ /** Creates the snapshot main description. */
+ public SnapshotInfo(
+ long mainSize,
+ long date,
+ @Nullable SnapshotInfo extStors,
+ @Nullable SnapshotInfo incs
+ ) {
+ // Incremental snapshots are inside the main snapshot directory,
so their size is already counted in the main size.
+ size = mainSize + (extStors == null ? 0L : extStors.size());
+ this.date = date;
+ this.extStors = extStors;
+ this.incs = incs;
+ }
+
+ /** Creates the description of snapshot external storages. */
+ public SnapshotInfo(int cnt, long size) {
+ this.cnt = cnt;
+ this.size = size;
+ }
+
+ /** Creates the description of incremental snapshot parts. */
+ public SnapshotInfo(int cnt, long size, long date) {
+ this(cnt, size);
+
+ this.date = date;
+ }
+
+ /** @return Total size of a snapshot. Or size of its external storages
or incremental parts. */
+ public long size() {
+ return size;
+ }
+
+ /**
+ * @return Creation date of a snapshot or of its incremental parts.
{@code Null} for snapshot
+ * external storages description.
+ */
+ public @Nullable Long date() {
+ return date;
+ }
+
+ /**
+ * @return Snapshot external storages description if it exists. Is
always {@code null} for anything other than
+ * the main snapshot description.
+ */
+ public @Nullable SnapshotInfo externalStorages() {
+ return extStors;
+ }
+
+ /**
+ * @return Snapshot incremental parts description if it exists. Is
always {@code null} for anything other than
+ * the main snapshot description.
+ */
+ public @Nullable SnapshotInfo incrementals() {
+ return incs;
+ }
+
+ /** @return Number of snapshot external storages or incremental parts.
Or {@code null} for the main snapshot data. */
+ public @Nullable Integer number() {
+ return cnt;
+ }
+ }
+}
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotListTaskResult.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotListTaskResult.java
new file mode 100644
index 00000000000..ffa9998a583
--- /dev/null
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotListTaskResult.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.persistence.snapshot;
+
+import java.util.UUID;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.internal.Order;
+import org.apache.ignite.internal.dto.IgniteDataTransferObject;
+import org.jetbrains.annotations.Nullable;
+
+/** Accumulated result of the snapshot list task. */
+public final class SnapshotListTaskResult extends IgniteDataTransferObject {
+ /** Serial version uid. */
+ private static final long serialVersionUID = 0L;
+
+ /** Node consistent IDs. */
+ @Order(0)
+ String[] consistentIds;
+
+ /** Node UUIDs. */
+ @Order(1)
+ UUID[] nodesIds;
+
+ /** Per-node results. */
+ @Order(2)
+ SnapshotListJobResult[] nodesSnapshots;
+
+ /** Per-node errors. */
+ @Order(3)
+ @Nullable IgniteException[] errors;
+
+ /** Default constructor for serialization purposes. */
+ public SnapshotListTaskResult() {
+ // No-op.
+ }
+
+ /** */
+ public SnapshotListTaskResult(
+ String[] consistentIds,
+ UUID[] nodesIds,
+ SnapshotListJobResult[] nodesSnapshots,
+ @Nullable IgniteException[] errors
+ ) {
+ this.consistentIds = consistentIds;
+ this.nodesIds = nodesIds;
+ this.nodesSnapshots = nodesSnapshots;
+ this.errors = errors;
+ }
+
+ /** @return Nodes consistent IDs. */
+ public String[] consistentIds() {
+ return consistentIds;
+ }
+
+ /** @return Nodes UUIDs. */
+ public UUID[] nodesIds() {
+ return nodesIds;
+ }
+
+ /** @return Per-node results. */
+ public SnapshotListJobResult[] nodesSnapshots() {
+ return nodesSnapshots;
+ }
+
+ /** @return Per-node errors. */
+ public @Nullable IgniteException[] errors() {
+ return errors;
+ }
+}
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/rollingupgrade/feature/CoreFeatureRegistry.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rollingupgrade/feature/CoreFeatureRegistry.java
index 6952606d1d5..4d00489327f 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/rollingupgrade/feature/CoreFeatureRegistry.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rollingupgrade/feature/CoreFeatureRegistry.java
@@ -108,4 +108,7 @@ public class CoreFeatureRegistry {
/** Feature that introduces the snapshot deletion command. */
public static final IgniteFeature SNAPSHOT_DELETE_FEATURE = new
IgniteCoreFeature(3);
+
+ /** Feature that introduces the snapshot list command. */
+ public static final IgniteFeature SNAPSHOT_LIST_FEATURE = new
IgniteCoreFeature(4);
}
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/util/io/GridFileUtils.java
b/modules/core/src/main/java/org/apache/ignite/internal/util/io/GridFileUtils.java
index 3e752140a9a..d84ec565a63 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/util/io/GridFileUtils.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/util/io/GridFileUtils.java
@@ -20,9 +20,13 @@ package org.apache.ignite.internal.util.io;
import java.io.File;
import java.io.IOException;
import java.nio.file.FileStore;
+import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.attribute.BasicFileAttributes;
import java.util.Objects;
+import java.util.concurrent.atomic.AtomicLong;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.internal.processors.cache.persistence.file.FileIO;
import
org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory;
@@ -112,4 +116,35 @@ public class GridFileUtils {
throw new IgniteCheckedException("Unable to check file stores.",
e);
}
}
+
+ /**
+ * Calculates the total size of all regular files in the given directory
(recursively).
+ * Tolerates and skips concurrent modification errors (e.g. file deleted
during walk).
+ *
+ * @param path Root directory.
+ * @return Total size in bytes.
+ * @throws IOException If the root directory cannot be entered.
+ */
+ public static long sizeOfDirectory(File path) throws IOException {
+ AtomicLong size = new AtomicLong(0);
+
+ Files.walkFileTree(path.toPath(), new SimpleFileVisitor<>() {
+ @Override public FileVisitResult visitFile(Path file,
BasicFileAttributes attrs) {
+ if (attrs.isRegularFile())
+ size.addAndGet(attrs.size());
+
+ return FileVisitResult.CONTINUE;
+ }
+
+ @Override public FileVisitResult visitFileFailed(Path file,
IOException err) throws IOException {
+ // Cannot enter directory at all.
+ if (file.toFile().equals(path))
+ throw err;
+
+ return FileVisitResult.CONTINUE;
+ }
+ });
+
+ return size.get();
+ }
}
diff --git
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteClusterSnapshotListRollingUpgradeTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteClusterSnapshotListRollingUpgradeTest.java
new file mode 100644
index 00000000000..815162f0644
--- /dev/null
+++
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteClusterSnapshotListRollingUpgradeTest.java
@@ -0,0 +1,227 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.persistence.snapshot;
+
+import java.io.File;
+import java.nio.file.DirectoryStream;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.UUID;
+import org.apache.ignite.IgniteDataStreamer;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.management.snapshot.SnapshotListCommandArg;
+import org.apache.ignite.internal.management.snapshot.SnapshotListTask;
+import
org.apache.ignite.internal.processors.rollingupgrade.AbstractRollingUpgradeTest;
+import org.apache.ignite.internal.util.distributed.SingleNodeMessage;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.internal.visor.VisorTaskArgument;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.junit.Test;
+
+import static java.nio.file.Files.newDirectoryStream;
+import static org.apache.ignite.internal.TestRecordingCommunicationSpi.spi;
+import static
org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.RU_PREPARE_VERSION_FINALIZATION;
+import static
org.apache.ignite.testframework.GridTestUtils.assertThrowsAnyCause;
+import static org.apache.ignite.testframework.GridTestUtils.waitForCondition;
+
+/** */
+public class IgniteClusterSnapshotListRollingUpgradeTest extends
AbstractRollingUpgradeTest {
+ /** */
+ private static final int ALL_GRIDS = 4;
+
+ /** */
+ private static final int CLIENTS = 1;
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ super.afterTest();
+
+ // Clean everything, including the separated working directories.
+ try (DirectoryStream<Path> files =
newDirectoryStream(Paths.get(U.defaultWorkDirectory()))) {
+ for (Path path : files)
+ U.delete(path);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String
igniteInstanceName, String ver) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName,
ver);
+
+ DataRegionConfiguration dataRegionCfg = new DataRegionConfiguration()
+ .setPersistenceEnabled(true)
+
.setMaxSize(DataStorageConfiguration.DFLT_DATA_REGION_INITIAL_SIZE);
+
+ cfg.setDataStorageConfiguration(new
DataStorageConfiguration().setDefaultDataRegionConfiguration(dataRegionCfg));
+
+ cfg.setWorkDirectory(new File(U.defaultWorkDirectory(),
igniteInstanceName).getAbsolutePath());
+
+ return cfg;
+ }
+
+ /** */
+ @Test
+ public void testParallelRollingUpgradeInProgress() throws Exception {
+ for (int i = 0; i < ALL_GRIDS; i++)
+ startGrid(i, "2.18.0", i >= ALL_GRIDS - CLIENTS);
+
+ grid(0).cluster().active(true);
+
+ int testNodeIx = ALL_GRIDS - CLIENTS - 1;
+
+ createCacheAndSnapshot(testNodeIx);
+
+ ru(grid(testNodeIx)).enableVersionUpgrade();
+
+ for (int i = 0; i < ALL_GRIDS; i++) {
+ assertTrue(ru(grid(i)).isVersionUpgradeEnabled());
+
+ upgradeNodeVersion(i, "2.18.0", MASTER_VER_REF);
+ }
+
+ spi(grid(testNodeIx)).blockMessages((node, msg) -> msg instanceof
SingleNodeMessage<?> snm &&
+ snm.type() == RU_PREPARE_VERSION_FINALIZATION.ordinal());
+
+ IgniteInternalFuture<?> finalizeFut = GridTestUtils.runAsync(() ->
ru(testNodeIx).finalizeClusterVersion());
+
+ assertTrue(spi(grid(testNodeIx)).waitForBlocked(1, getTestTimeout()));
+
+ ensureSnapshotListCommandFails();
+
+ spi(grid(testNodeIx)).stopBlock();
+
+ assertFalse(spi(grid(testNodeIx)).hasBlockedMessages());
+
+ finalizeFut.get(getTestTimeout());
+
+ for (int i = 0; i < ALL_GRIDS; i++) {
+ int i0 = i;
+
+ assertTrue(waitForCondition(() ->
!ru(grid(i0)).isVersionUpgradeEnabled(), getTestTimeout()));
+ }
+
+ ensureSnapshotListSucceeds();
+ }
+
+ /** */
+ @Test
+ public void testSnapshotListFeature() throws Exception {
+ for (int i = 0; i < ALL_GRIDS; i++)
+ startGrid(i, "2.18.0", i >= ALL_GRIDS - CLIENTS);
+
+ grid(0).cluster().active(true);
+
+ createCacheAndSnapshot(1);
+
+ ensureSnapshotListCommandFails();
+
+ ru(grid(0)).enableVersionUpgrade();
+
+ for (int i = 0; i < ALL_GRIDS; i++) {
+ assertTrue(ru(grid(i)).isVersionUpgradeEnabled());
+
+ upgradeNodeVersion(i, "2.18.0", MASTER_VER_REF);
+
+ ensureSnapshotListCommandFails();
+ }
+
+ ru(grid(1)).finalizeClusterVersion();
+
+ for (int i = 0; i < ALL_GRIDS; i++) {
+ int i0 = i;
+
+ assertTrue(waitForCondition(() ->
!ru(grid(i0)).isVersionUpgradeEnabled(), getTestTimeout()));
+ }
+
+ ensureSnapshotListSucceeds();
+ }
+
+ /** */
+ private void ensureSnapshotListSucceeds() throws Exception {
+ for (int i = 0; i < ALL_GRIDS; i++) {
+ for (int k = 0; k < ALL_GRIDS; k++) {
+ SnapshotListTaskResult listOpRes =
launchSnapshotsListCommand(i, grid(k).localNode().id());
+
+ assertEquals(3, listOpRes.nodesSnapshots().length);
+
+ // Tests client exclusion.
+ if (CLIENTS > 0) {
+ UUID cliId = grid(ALL_GRIDS -
CLIENTS).cluster().localNode().id();
+
+ assertFalse(new
HashSet<>(Arrays.asList(listOpRes.nodesIds())).contains(cliId));
+ }
+
+ for (SnapshotListJobResult nodeRes :
listOpRes.nodesSnapshots())
+ assertEquals(1, nodeRes.snapshots().size());
+ }
+ }
+ }
+
+ /** */
+ private void createCacheAndSnapshot(int gridIdx) {
+ int partsCnt = 4;
+ int keysCnt = partsCnt * 5;
+
+ grid(gridIdx).createCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME)
+ .setCacheMode(CacheMode.REPLICATED)
+ .setAffinity(new
RendezvousAffinityFunction().setPartitions(partsCnt))
+ .setAtomicityMode(CacheAtomicityMode.ATOMIC));
+
+ try (IgniteDataStreamer<Integer, Integer> ds =
grid(gridIdx).dataStreamer(DEFAULT_CACHE_NAME)) {
+ for (int i = 0; i < keysCnt; i++)
+ ds.addData(i, i);
+ }
+
+
grid(gridIdx).context().cache().context().snapshotMgr().createSnapshot("testSnapshot").get(getTestTimeout());
+ }
+
+ /** */
+ private void ensureSnapshotListCommandFails() {
+ for (int i = 0; i < ALL_GRIDS; i++) {
+ for (int k = 0; k < ALL_GRIDS; k++) {
+ int i0 = i;
+ int k0 = k;
+
+ assertThrowsAnyCause(
+ null,
+ () -> launchSnapshotsListCommand(i0,
grid(k0).localNode().id()),
+ IgniteException.class,
+ SnapshotListTask.FEATURE_NOT_ACTIVE_ERR_MSG
+ );
+ }
+ }
+ }
+
+ /** */
+ private SnapshotListTaskResult launchSnapshotsListCommand(int gridFromIdx,
UUID targetGrid) throws Exception {
+ return grid(gridFromIdx).compute().execute(
+ SnapshotListTask.class,
+ new VisorTaskArgument<>(Collections.singleton(targetGrid), new
SnapshotListCommandArg(), false)
+ ).result();
+ }
+}
diff --git
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteClusterSnapshotListTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteClusterSnapshotListTest.java
new file mode 100644
index 00000000000..14ac338a327
--- /dev/null
+++
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteClusterSnapshotListTest.java
@@ -0,0 +1,849 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.persistence.snapshot;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.io.Serializable;
+import java.nio.file.DirectoryStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.attribute.PosixFilePermission;
+import java.nio.file.attribute.PosixFilePermissions;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.stream.Stream;
+import org.apache.ignite.IgniteDataStreamer;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.management.snapshot.SnapshotListCommandArg;
+import org.apache.ignite.internal.management.snapshot.SnapshotListTask;
+import
org.apache.ignite.internal.processors.cache.persistence.filename.SnapshotFileTree;
+import org.apache.ignite.internal.util.io.GridFileUtils;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.internal.visor.VisorTaskArgument;
+import org.apache.ignite.lang.IgniteFuture;
+import org.apache.ignite.plugin.AbstractTestPluginProvider;
+import org.apache.ignite.plugin.PluginConfiguration;
+import org.apache.ignite.plugin.PluginContext;
+import org.apache.ignite.plugin.PluginProvider;
+import org.jetbrains.annotations.Nullable;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runners.Parameterized;
+
+import static java.nio.file.Files.newDirectoryStream;
+import static
org.apache.ignite.configuration.IgniteConfiguration.DFLT_SNAPSHOT_THREAD_POOL_SIZE;
+import static org.apache.ignite.testframework.GridTestUtils.cartesianProduct;
+import static org.apache.ignite.testframework.GridTestUtils.runAsync;
+import static org.junit.Assume.assumeFalse;
+import static org.junit.Assume.assumeTrue;
+
+/** Cluster-wide snapshot list procedure tests. */
+public class IgniteClusterSnapshotListTest extends AbstractSnapshotSelfTest {
+ /** Number of cache keys to pre-create at node startup. */
+ private static final int CACHE_KEYS_RANGE = 15;
+
+ /** Number of partitions of the test cache. */
+ private static final int CACHE_PARTITIONS_COUNT = 4;
+
+ /** Flag showing that the filesystem supports POSIX permissions. */
+ private static boolean posixPermissions;
+
+ /** Size of the snapshot utility thread pool. */
+ @Parameterized.Parameter(2)
+ public int snpThrdPoolSz;
+
+ /** */
+ private PluginProvider<PluginConfiguration> pluginProvider;
+
+ /** Flag to spread the test cache data over external storages. */
+ private boolean extStorages;
+
+ /** Resolved external storage paths. {@code null} if {@link #extStorages}
is {@code false}. */
+ private @Nullable String[] extStoragePaths;
+
+ /** Parameters. */
+ @Parameterized.Parameters(name = "encryption={0}, onlyPrimary={1},
snpThrdPoolSz={2}")
+ public static Collection<Object[]> params() {
+ return cartesianProduct(
+ encryptionParameters(), // Encryption.
+ F.asList(false, true), // Only primary.
+ F.asList(DFLT_SNAPSHOT_THREAD_POOL_SIZE, 1) // Snapshots thread
pool size.
+ );
+ }
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String
igniteInstanceName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName)
+ .setWorkDirectory(new File(U.defaultWorkDirectory(),
igniteInstanceName).getAbsolutePath());
+
+ if (pluginProvider != null)
+ cfg.setPluginProviders(pluginProvider);
+
+ if (extStorages) {
+ // External storage paths must be identical on all nodes (a cache
has a single storage path setting).
+ // Thus, a shared work directory is used, like in
GridCommandHandlerListSnapshotTest.
+ cfg.setWorkDirectory(U.defaultWorkDirectory());
+
+ cfg.getDataStorageConfiguration().setExtraStoragePaths(
+ U.defaultWorkDirectory() + File.separator,
+ U.defaultWorkDirectory() + File.separator + "extStorage"
+ );
+
+ extStoragePaths =
cfg.getDataStorageConfiguration().getExtraStoragePaths();
+
+ cfg.getDataStorageConfiguration().setExtraSnapshotPaths("",
"extStorage");
+ }
+
+ cfg.setSnapshotThreadPoolSize(snpThrdPoolSz);
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void cleanPersistenceDir() throws Exception {
+ super.cleanPersistenceDir();
+
+ // Also cleans separated snapshot working directories and custom
snapshot paths.
+ try (DirectoryStream<Path> files =
newDirectoryStream(Paths.get(U.defaultWorkDirectory()))) {
+ for (Path path : files)
+ U.delete(path);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ super.beforeTestsStarted();
+
+ File workDir = new File(U.defaultWorkDirectory());
+
+ assertTrue(workDir.exists());
+
+ try {
+ Files.getPosixFilePermissions(workDir.toPath());
+
+ posixPermissions = true;
+ }
+ catch (UnsupportedOperationException ignored) {
+ // No-op.
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override protected <K, V> CacheConfiguration<K, V>
txCacheConfig(CacheConfiguration<K, V> ccfg) {
+ // Speeds up the tests.
+ ccfg = super.txCacheConfig(ccfg)
+ .setAffinity(new RendezvousAffinityFunction(false,
CACHE_PARTITIONS_COUNT))
+ .setBackups(1);
+
+ if (extStorages) {
+ assert !F.isEmpty(extStoragePaths);
+
+ ccfg.setStoragePaths(extStoragePaths);
+ }
+
+ return ccfg;
+ }
+
+ /** */
+ @Test
+ public void testConcurrentCreation() throws Exception {
+ // The test relies on thread blocking and conditional waiting, so it
does not run with a single thread.
+ assumeTrue(snpThrdPoolSz > 1);
+
+ int grids = 3;
+ int testNodeIdx = 1;
+ int testNodeOrder = testNodeIdx + 1;
+
+ CountDownLatch beginSnpCreation = new CountDownLatch(grids);
+ CountDownLatch proceedSnpCreation = new CountDownLatch(1);
+
+ // Delays snapshot creation after its metadata is written.
+ pluginProvider = new AbstractTestPluginProvider() {
+ @Override public String name() {
+ return "TestSnpMgrProvider";
+ }
+
+ @Override public <T> T createComponent(PluginContext ctx, Class<T>
cls) {
+ if (IgniteSnapshotManager.class.isAssignableFrom(cls)) {
+ return (T)new
IgniteSnapshotManager(((IgniteEx)ctx.grid()).context()) {
+ @Override public <M extends Serializable> void
storeSnapshotMeta(M meta, File smf) {
+ super.storeSnapshotMeta(meta, smf);
+
+ beginSnpCreation.countDown();
+
+ if (((IgniteEx)ctx.grid()).localNode().order() ==
testNodeOrder) {
+ try {
+
assertTrue(proceedSnpCreation.await(getTestTimeout(), TimeUnit.MILLISECONDS));
+ }
+ catch (InterruptedException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ }
+ };
+ }
+
+ return super.createComponent(ctx, cls);
+ }
+ };
+
+ startGridsWithCache(grids, txCacheConfig(defaultCacheConfiguration()),
CACHE_KEYS_RANGE);
+
+ IgniteFuture<Void> createSnpFut =
snp(grid(0)).createSnapshot(SNAPSHOT_NAME, null, false, onlyPrimary);
+
+ assertTrue(beginSnpCreation.await(getTestTimeout(),
TimeUnit.MILLISECONDS));
+
+ SnapshotListTaskResult lstOpRes = listSnapshots(grid(0));
+
+ int snpsCnt = Stream.of(lstOpRes.nodesSnapshots()).mapToInt(jr ->
jr.snapshots().size()).sum();
+
+ assertEquals(grids, snpsCnt);
+
+ SnapshotFileTree testSft = new
SnapshotFileTree(grid(testNodeIdx).context(), SNAPSHOT_NAME, null);
+
+ assertTrue(GridFileUtils.sizeOfDirectory(testSft.root()) > 0L);
+
+ proceedSnpCreation.countDown();
+
+ createSnpFut.get(getTestTimeout());
+ }
+
+ /** */
+ @Test
+ public void testCompletelyDeletedAfterMetaRead() throws Exception {
+ doTestDeletionAfterMetaRead(true);
+ }
+
+ /** */
+ @Test
+ public void testPartlyDeletedAfterMetaRead() throws Exception {
+ doTestDeletionAfterMetaRead(false);
+ }
+
+ /** */
+ private void doTestDeletionAfterMetaRead(boolean completeDeletion) throws
Exception {
+ int grids = 3;
+ int testGridIdx = 1;
+
+ CountDownLatch metaReadBeginLatch = new CountDownLatch(grids);
+ CountDownLatch metaReadProceedLatch = new CountDownLatch(1);
+
+ pluginProvider = new AbstractTestPluginProvider() {
+ @Override public String name() {
+ return "TestSnpMgrProvider";
+ }
+
+ @Override public <T> T createComponent(PluginContext ctx, Class<T>
cls) {
+ if (IgniteSnapshotManager.class.isAssignableFrom(cls)) {
+ return (T)new
IgniteSnapshotManager(((IgniteEx)ctx.grid()).context()) {
+ @Override public List<SnapshotMetadata>
readSnapshotMetadatas(SnapshotFileTree sft, boolean failIfCantRead) {
+ metaReadBeginLatch.countDown();
+
+ if (cctx.localNode().order() == testGridIdx + 1) {
+ try {
+
assertTrue(metaReadProceedLatch.await(getTestTimeout(), TimeUnit.MILLISECONDS));
+ }
+ catch (InterruptedException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ return super.readSnapshotMetadatas(sft,
failIfCantRead);
+ }
+ };
+ }
+
+ return super.createComponent(ctx, cls);
+ }
+ };
+
+ startGridsWithSnapshot(grids, CACHE_KEYS_RANGE, true, false);
+
+ SnapshotFileTree testSnpFt = new
SnapshotFileTree(grid(testGridIdx).context(), SNAPSHOT_NAME, null);
+
+ long testSnpSz = GridFileUtils.sizeOfDirectory(testSnpFt.root());
+
+ assertTrue(testSnpSz > 0);
+
+ IgniteInternalFuture<SnapshotListTaskResult> lstOpFut = runAsync(() ->
listSnapshots(grid(0)));
+
+ assertTrue(metaReadBeginLatch.await(getTestTimeout(),
TimeUnit.MILLISECONDS));
+
+ if (completeDeletion)
+ assertTrue(testSnpFt.root().exists() && U.delete(testSnpFt.root())
&& !testSnpFt.root().exists());
+ else
+ assertTrue(testSnpFt.nodeStorage().exists() &&
U.delete(testSnpFt.nodeStorage()) && !testSnpFt.nodeStorage().exists());
+
+ metaReadProceedLatch.countDown();
+
+ SnapshotListTaskResult lstOpRes = lstOpFut.get();
+
+ if (completeDeletion) {
+ int snpsCnt = Stream.of(lstOpRes.nodesSnapshots()).mapToInt(jr ->
jr.snapshots().size()).sum();
+
+ assertEquals(grids - 1, snpsCnt);
+ }
+ else {
+ int snpsCnt = 0;
+ boolean victimNodeFound = false;
+
+ for (int i = 0; i < lstOpRes.nodesIds().length; i++) {
+ UUID nid = lstOpRes.nodesIds()[i];
+
+ Map<String, SnapshotListJobResult.SnapshotInfo> nodeSnps =
lstOpRes.nodesSnapshots()[i].snapshots();
+
+ snpsCnt += nodeSnps.size();
+
+ if (nid.equals(grid(testGridIdx).localNode().id())) {
+ victimNodeFound = true;
+
+ assertEquals(1, nodeSnps.size());
+
+ long curSnpSz =
GridFileUtils.sizeOfDirectory(testSnpFt.root());
+
+ assertTrue(curSnpSz < testSnpSz);
+ }
+ }
+
+ assertTrue(victimNodeFound);
+ assertEquals(grids, snpsCnt);
+ }
+ }
+
+ /** */
+ @Test
+ public void testEmptySnapshotPath() throws Exception {
+ startGrids(3);
+
+ File path = new File(U.defaultWorkDirectory(), "not_snapshots");
+
+ SnapshotListJobResult[] listOperationRes = listSnapshots(grid(0),
path.getAbsolutePath()).nodesSnapshots();
+
+ int cnt = Stream.of(listOperationRes).mapToInt(nodeRes ->
nodeRes.snapshots().size()).sum();
+
+ assertEquals(0, cnt);
+ }
+
+ /** */
+ @Test
+ public void testDefaultSnapshotPath() throws Exception {
+ doTestSnapshotPath(null);
+ }
+
+ /** */
+ @Test
+ @Ignore("https://issues.apache.org/jira/browse/IGNITE-29126")
+ public void testRelativeSnapshotPath() throws Exception {
+ doTestSnapshotPath("ex_snapshots");
+ }
+
+ /** */
+ @Test
+ public void testAbsoluteSnapshotPath() throws Exception {
+ doTestSnapshotPath(new File(U.defaultWorkDirectory(),
"ex_snapshots").getAbsolutePath());
+ }
+
+ /** */
+ private void doTestSnapshotPath(@Nullable String path) throws Exception {
+ int grids = 3;
+
+ startGridsWithCache(grids, txCacheConfig(defaultCacheConfiguration()),
CACHE_KEYS_RANGE);
+
+ snp(grid(0)).createSnapshot(SNAPSHOT_NAME, path, false,
onlyPrimary).get(getTestTimeout());
+
+ SnapshotListJobResult[] lstOpRes = listSnapshots(grid(0),
path).nodesSnapshots();
+
+ int cnt = Stream.of(lstOpRes).mapToInt(nodeRes ->
nodeRes.snapshots().size()).sum();
+
+ assertEquals(grids, cnt);
+ }
+
+ /** */
+ @Test
+ public void testMissingMeta() throws Exception {
+ doTestWithWrongMeta(false);
+ }
+
+ /** */
+ @Test
+ public void testCorruptedMeta() throws Exception {
+ doTestWithWrongMeta(true);
+ }
+
+ /**
+ * Tests snapshot lists when one snapshot metadata cannot be read.
+ *
+ * @param corruptFile If {@code true}, corrupts metadata. Otherwise,
deletes metadata.
+ */
+ private void doTestWithWrongMeta(boolean corruptFile) throws Exception {
+ int grids = 3;
+ int testGridIdx = 1;
+
+ startGridsWithSnapshot(grids, CACHE_KEYS_RANGE, true, false);
+
+ SnapshotFileTree testSnpFt = new
SnapshotFileTree(grid(testGridIdx).context(), SNAPSHOT_NAME, null);
+
+ assertTrue(testSnpFt.meta().exists());
+
+ if (corruptFile) {
+ try (RandomAccessFile raf = new RandomAccessFile(testSnpFt.meta(),
"rw")) {
+ raf.write(UUID.randomUUID().toString().getBytes());
+ }
+ }
+ else
+ assertTrue(testSnpFt.meta().delete() &&
!testSnpFt.meta().exists());
+
+ SnapshotListTaskResult res = listSnapshots(grid(0));
+
+ int foundSnpsCnt = 0;
+ boolean victimNodeFound = false;
+
+ for (int i = 0; i < res.nodesIds().length; i++) {
+ UUID nid = res.nodesIds()[i];
+
+ foundSnpsCnt += res.nodesSnapshots()[i].snapshots().size();
+
+ if (nid.equals(grid(testGridIdx).localNode().id())) {
+ victimNodeFound = true;
+
+ assertTrue(res.nodesSnapshots()[i].snapshots().isEmpty());
+ }
+ }
+
+ assertTrue(victimNodeFound);
+ assertEquals(grids - 1, foundSnpsCnt);
+ }
+
+ /** */
+ @Test
+ public void testMissingIncrementalMeta() throws Exception {
+ doTestWithWrongIncrementalMeta(false);
+ }
+
+ /** */
+ @Test
+ public void testCorruptedIncrementalMeta() throws Exception {
+ doTestWithWrongIncrementalMeta(true);
+ }
+
+ /**
+ * Tests snapshot list when incremental snapshot metadata cannot be read.
+ * The main snapshot should still be listed, but without incremental info
on the affected node.
+ *
+ * @param corruptFile If {@code true}, corrupts metadata. Otherwise,
deletes metadata.
+ */
+ private void doTestWithWrongIncrementalMeta(boolean corruptFile) throws
Exception {
+ // Incremental snapshots do not support the only-primary mode or
encryption.
+ assumeFalse(onlyPrimary || encryption);
+
+ int grids = 3;
+ int testGridIdx = 1;
+ int incsCnt = 3;
+
+ IgniteEx ig = startGridsWithCache(grids,
txCacheConfig(defaultCacheConfiguration()), CACHE_KEYS_RANGE);
+
+ snp(ig).createSnapshot(SNAPSHOT_NAME, null, false,
onlyPrimary).get(getTestTimeout());
+
+ for (int i = 0; i < incsCnt; ++i) {
+ try (IgniteDataStreamer<Integer, Integer> ds =
grid(0).dataStreamer(DEFAULT_CACHE_NAME)) {
+ for (int kv = (i + 1) * CACHE_KEYS_RANGE; kv < (i + 1) *
CACHE_KEYS_RANGE * 2; ++kv)
+ ds.addData(kv, kv);
+ }
+
+ snp(ig).createSnapshot(SNAPSHOT_NAME, null, true,
onlyPrimary).get(getTestTimeout());
+ }
+
+ SnapshotFileTree testSnpFt = new
SnapshotFileTree(grid(testGridIdx).context(), SNAPSHOT_NAME, null);
+ SnapshotFileTree.IncrementalSnapshotFileTree incFt =
testSnpFt.incrementalSnapshotFileTree(1);
+ File incMeta = incFt.meta();
+
+ assertTrue(incMeta.exists());
+
+ if (corruptFile) {
+ try (RandomAccessFile raf = new RandomAccessFile(incMeta, "rw")) {
+ raf.write(UUID.randomUUID().toString().getBytes());
+ }
+ }
+ else
+ assertTrue(incMeta.delete() && !incMeta.exists());
+
+ SnapshotListTaskResult res = listSnapshots(grid(0));
+
+ for (int i = 0; i < res.nodesIds().length; i++) {
+ UUID nid = res.nodesIds()[i];
+
+ Map<String, SnapshotListJobResult.SnapshotInfo> snps =
res.nodesSnapshots()[i].snapshots();
+
+ assertEquals(1, snps.size());
+
+ SnapshotListJobResult.SnapshotInfo info = snps.get(SNAPSHOT_NAME);
+
+ assertNotNull(info);
+ assertNotNull(info.incrementals());
+
+ if (nid.equals(grid(testGridIdx).localNode().id()))
+ assertEquals(incsCnt - 1,
info.incrementals().number().intValue());
+ else
+ assertEquals(incsCnt, info.incrementals().number().intValue());
+ }
+ }
+
+ /**
+ * Test snapshot list operation when a node can't read some snapshot part
due to insufficient permissions.
+ * That is, a test node can read the snapshot metadata but cannot read
some of the snapshot data.
+ */
+ @Test
+ public void testDeniedPermissions() throws Exception {
+ assumeTrue(posixPermissions);
+ // We rely on the snapshot sizes here. Better to avoid empty data
nodes not to become flaky.
+ assumeFalse(onlyPrimary);
+
+ int grids = 3;
+ int testGridIdx = 1;
+
+ // Permissions to restore.
+ Map<Path, Set<PosixFilePermission>> oldPerms = new
ConcurrentHashMap<>();
+ // The 'change permissions' flag.
+ AtomicBoolean changePermissions = new AtomicBoolean(true);
+
+ // Deny reading the whole snapshot part of one node.
+ pluginProvider = new AbstractTestPluginProvider() {
+ @Override public String name() {
+ return "TestSnpMgrProvider";
+ }
+
+ @Override public <T> T createComponent(PluginContext ctx, Class<T>
cls) {
+ if (IgniteSnapshotManager.class.isAssignableFrom(cls)) {
+ return (T)new
IgniteSnapshotManager(((IgniteEx)ctx.grid()).context()) {
+ @Override public List<SnapshotMetadata>
readSnapshotMetadatas(SnapshotFileTree sft,
+ boolean failIfCantRead) {
+ if (changePermissions.get() &&
ctx.localNode().order() == testGridIdx + 1) {
+ File victimDir = sft.nodeStorage();
+
+ assertTrue(victimDir.exists());
+ assertTrue(victimDir.isDirectory());
+
+ // Ensure the blocked snapshot part has a
non-zero size; the sizes are compared later.
+ try {
+
assertTrue(GridFileUtils.sizeOfDirectory(victimDir) > 0L);
+ }
+ catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+
+ Path victimDirPath = victimDir.toPath();
+
+ try {
+ Set<PosixFilePermission> perms =
Files.getPosixFilePermissions(victimDirPath);
+
+ assertFalse(perms.isEmpty());
+
+ // Deny reading.
+
Files.setPosixFilePermissions(victimDirPath,
PosixFilePermissions.fromString("---------"));
+
+ // Save actual permissions to restore.
+ oldPerms.put(victimDirPath, perms);
+ }
+ catch (Exception e) {
+ throw new IgniteException("Unable to set
the test POSIX permissions.", e);
+ }
+ }
+
+ return super.readSnapshotMetadatas(sft,
failIfCantRead);
+ }
+ };
+ }
+
+ return super.createComponent(ctx, cls);
+ }
+ };
+
+ startGridsWithSnapshot(grids, CACHE_KEYS_RANGE, true, true);
+
+ UUID testNodeId = grid(testGridIdx).localNode().id();
+
+ // Snapshot size with restricted permissions.
+ long testSize0 = 0L;
+ // Snapshot size with normal permissions.
+ long testSize1 = 0L;
+
+ SnapshotListTaskResult listTaskRes;
+
+ try {
+ // First run.
+ listTaskRes = listSnapshots(grid(0));
+
+ assertFalse(oldPerms.isEmpty());
+
+ for (int i = 0; i < listTaskRes.nodesIds().length; i++) {
+ UUID nodeId = listTaskRes.nodesIds()[i];
+
+ // Store the partly read snapshot size.
+ if (nodeId.equals(testNodeId)) {
+ Map<String, SnapshotListJobResult.SnapshotInfo> snps =
listTaskRes.nodesSnapshots()[i].snapshots();
+
+ assertEquals(1, snps.size());
+
+ testSize0 = snps.get(SNAPSHOT_NAME).size();
+ }
+ }
+
+ // Ensure that we've found and read the snapshot on the test node.
+ assertTrue(testSize0 > 0L);
+ }
+ finally {
+ // Restore the permissions in any case.
+ oldPerms.forEach((path, perms) -> {
+ try {
+ Files.setPosixFilePermissions(path, perms);
+ }
+ catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+ });
+ }
+
+ // Relaunch the operation.
+ changePermissions.set(false);
+
+ listTaskRes = listSnapshots(grid(0));
+
+ for (int i = 0; i < listTaskRes.nodesIds().length; i++) {
+ UUID nodeId = listTaskRes.nodesIds()[i];
+
+ // Store the fully read snapshot size.
+ if (nodeId.equals(testNodeId)) {
+ Map<String, SnapshotListJobResult.SnapshotInfo> snps =
listTaskRes.nodesSnapshots()[i].snapshots();
+
+ assertEquals(1, snps.size());
+
+ testSize1 = snps.get(SNAPSHOT_NAME).size();
+ }
+ }
+
+ // Ensure that the newly calculated size is greater than in the
previous run.
+ assertTrue(testSize1 > 0L);
+ assertTrue(testSize1 > testSize0);
+ }
+
+ /** */
+ @Test
+ public void testSnapshotListsDates() throws Exception {
+ // Incremental snapshots do not support the only-primary mode or
encryption.
+ assumeFalse(onlyPrimary || encryption);
+
+ int grids = 3;
+
+ IgniteEx ig = startGridsWithCache(grids,
txCacheConfig(defaultCacheConfiguration()), CACHE_KEYS_RANGE);
+
+ long beforeSnpCreationTime = U.currentTimeMillis();
+
+ snp(ig).createSnapshot(SNAPSHOT_NAME, null, false,
onlyPrimary).get(getTestTimeout());
+
+ SnapshotListTaskResult res = listSnapshots(grid(0));
+
+ for (int i = 0; i < res.nodesIds().length; i++) {
+ Map<String, SnapshotListJobResult.SnapshotInfo> snps =
res.nodesSnapshots()[i].snapshots();
+
+ assertEquals(1, snps.size());
+
+ SnapshotListJobResult.SnapshotInfo info = snps.get(SNAPSHOT_NAME);
+
+ assertTrue(info.date() >= beforeSnpCreationTime);
+ }
+
+ long beforeIncrementalCreationTime = U.currentTimeMillis();
+
+ try (IgniteDataStreamer<Integer, Integer> ds =
ig.dataStreamer(DEFAULT_CACHE_NAME)) {
+ for (int kv = CACHE_KEYS_RANGE; kv < CACHE_KEYS_RANGE * 2; kv++)
+ ds.addData(kv, kv);
+ }
+
+ snp(ig).createSnapshot(SNAPSHOT_NAME, null, true,
onlyPrimary).get(getTestTimeout());
+
+ SnapshotListTaskResult res2 = listSnapshots(grid(0));
+
+ for (int i = 0; i < res2.nodesIds().length; i++) {
+ Map<String, SnapshotListJobResult.SnapshotInfo> snps =
res2.nodesSnapshots()[i].snapshots();
+
+ assertEquals(1, snps.size());
+
+ SnapshotListJobResult.SnapshotInfo info = snps.get(SNAPSHOT_NAME);
+
+ assertNotNull(info.incrementals());
+
+ assertTrue(info.date() >= beforeSnpCreationTime);
+ assertTrue(info.date() <= beforeIncrementalCreationTime);
+ assertTrue(info.date() <= info.incrementals().date());
+ assertTrue(info.incrementals().date() >=
beforeIncrementalCreationTime);
+ }
+ }
+
+ /** */
+ @Test
+ public void testSnapshotListsSizes() throws Exception {
+ // Incremental snapshots do not support the only-primary mode or
encryption.
+ assumeFalse(onlyPrimary || encryption);
+
+ int grids = 3;
+
+ IgniteEx ig = startGridsWithCache(grids,
txCacheConfig(defaultCacheConfiguration()), CACHE_KEYS_RANGE);
+
+ snp(ig).createSnapshot(SNAPSHOT_NAME, null, false,
onlyPrimary).get(getTestTimeout());
+
+ SnapshotListTaskResult res = listSnapshots(grid(0));
+
+ Map<UUID, Long> sizes0 = collectSizes(res);
+
+ // Check the sizes.
+ for (int g = 0; g < grids; g++) {
+ long sz = GridFileUtils.sizeOfDirectory(new
SnapshotFileTree(grid(g).context(), SNAPSHOT_NAME, null).root());
+
+ assertEquals(sz, sizes0.get(grid(g).localNode().id()).longValue());
+
+ assertNull(snapshotInfo(res, grid(g)).externalStorages());
+ assertNull(snapshotInfo(res, grid(g)).incrementals());
+ }
+
+ // Add some data and create an incremental snapshot.
+ try (IgniteDataStreamer<Integer, Integer> ds =
ig.dataStreamer(DEFAULT_CACHE_NAME)) {
+ for (int kv = CACHE_KEYS_RANGE; kv < CACHE_KEYS_RANGE * 2; ++kv)
+ ds.addData(kv, kv);
+ }
+
+ snp(ig).createSnapshot(SNAPSHOT_NAME, null, true,
onlyPrimary).get(getTestTimeout());
+
+ // Repeat the operation.
+ res = listSnapshots(grid(0));
+
+ Map<UUID, Long> sizes1 = collectSizes(res);
+
+ for (int g = 0; g < grids; g++) {
+ UUID nodeId = grid(g).localNode().id();
+
+ SnapshotListJobResult.SnapshotInfo info = snapshotInfo(res,
grid(g));
+
+ assertNotNull(info.incrementals());
+ assertEquals(1, info.incrementals().number().intValue());
+
+ // The size must grow and equal the actual directory size.
Incremental part is placed inside the snapshot
+ // root and must not be counted twice.
+ assertTrue(sizes1.get(nodeId) > sizes0.get(nodeId));
+
+ long sz = GridFileUtils.sizeOfDirectory(new
SnapshotFileTree(grid(g).context(), SNAPSHOT_NAME, null).root());
+
+ assertEquals(sz, sizes1.get(nodeId).longValue());
+ }
+ }
+
+ /** */
+ @Test
+ public void testSnapshotListsSizesExternalStorages() throws Exception {
+ int grids = 3;
+
+ extStorages = true;
+
+ // Prevents the default test cache from being created with the
external storages configured.
+ dfltCacheCfg = null;
+
+ startGridsMultiThreaded(grids);
+
+ grid(0).createCache(txCacheConfig(defaultCacheConfiguration()));
+
+ try (IgniteDataStreamer<Integer, Integer> ds =
grid(0).dataStreamer(DEFAULT_CACHE_NAME)) {
+ for (int i = 0; i < CACHE_KEYS_RANGE; i++)
+ ds.addData(i, i);
+ }
+
+ snp(grid(0)).createSnapshot(SNAPSHOT_NAME, null, false,
onlyPrimary).get(getTestTimeout());
+
+ SnapshotListTaskResult res = listSnapshots(grid(0));
+
+ for (int g = 0; g < grids; g++) {
+ SnapshotListJobResult.SnapshotInfo info = snapshotInfo(res,
grid(g));
+
+ assertNotNull(info);
+ assertNotNull(info.externalStorages());
+
+ long rootSize = GridFileUtils.sizeOfDirectory(new
SnapshotFileTree(grid(g).context(), SNAPSHOT_NAME, null).root());
+
+ // If there is data within the snapshot's external storage, its
size must be added to the total size.
+ assertTrue(info.externalStorages().size() > 0L ? info.size() >
rootSize : info.size() == rootSize);
+ assertEquals(rootSize + info.externalStorages().size(),
info.size());
+ }
+ }
+
+ /** */
+ private static SnapshotListTaskResult listSnapshots(IgniteEx grid,
@Nullable String src) throws Exception {
+ SnapshotListCommandArg arg = new SnapshotListCommandArg();
+
+ arg.src(src);
+
+ Collection<UUID> nodes =
grid.cluster().forServers().nodes().stream().map(ClusterNode::id).toList();
+
+ return grid.compute().execute(SnapshotListTask.class, new
VisorTaskArgument<>(nodes, arg, false)).result();
+ }
+
+ /** */
+ private static SnapshotListTaskResult listSnapshots(IgniteEx grid) throws
Exception {
+ return listSnapshots(grid, null);
+ }
+
+ /** @return The test snapshot info reported for the node. */
+ private static @Nullable SnapshotListJobResult.SnapshotInfo
snapshotInfo(SnapshotListTaskResult res, IgniteEx node) {
+ for (int i = 0; i < res.nodesIds().length; i++) {
+ if (res.nodesIds()[i].equals(node.localNode().id()))
+ return res.nodesSnapshots()[i].snapshots().get(SNAPSHOT_NAME);
+ }
+
+ return null;
+ }
+
+ /** @return The test snapshot sizes reported by the list operation per
node id. */
+ private static Map<UUID, Long> collectSizes(SnapshotListTaskResult res) {
+ Map<UUID, Long> sizes = new HashMap<>();
+
+ for (int i = 0; i < res.nodesIds().length; i++) {
+ SnapshotListJobResult.SnapshotInfo info =
res.nodesSnapshots()[i].snapshots().get(SNAPSHOT_NAME);
+
+ assertNotNull(info);
+
+ sizes.put(res.nodesIds()[i], info.size());
+ }
+
+ return sizes;
+ }
+}
diff --git
a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteSnapshotTestSuite9.java
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteSnapshotTestSuite9.java
index b584171fc03..86802121999 100644
---
a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteSnapshotTestSuite9.java
+++
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteSnapshotTestSuite9.java
@@ -22,6 +22,8 @@ import java.util.Collection;
import java.util.List;
import
org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteClusterSnapshotDeleteRollingUpgradeTest;
import
org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteClusterSnapshotDeleteTest;
+import
org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteClusterSnapshotListRollingUpgradeTest;
+import
org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteClusterSnapshotListTest;
import org.apache.ignite.testframework.GridTestUtils;
import org.apache.ignite.testframework.junits.DynamicSuite;
import org.junit.runner.RunWith;
@@ -43,6 +45,8 @@ public class IgniteSnapshotTestSuite9 {
GridTestUtils.addTestIfNeeded(suite,
IgniteClusterSnapshotDeleteRollingUpgradeTest.class, ignoredTests);
GridTestUtils.addTestIfNeeded(suite,
IgniteClusterSnapshotDeleteTest.class, ignoredTests);
+ GridTestUtils.addTestIfNeeded(suite,
IgniteClusterSnapshotListTest.class, ignoredTests);
+ GridTestUtils.addTestIfNeeded(suite,
IgniteClusterSnapshotListRollingUpgradeTest.class, ignoredTests);
return suite;
}
diff --git
a/modules/core/src/test/resources/org.apache.ignite.util/GridCommandHandlerClusterByClassTest_help.output
b/modules/core/src/test/resources/org.apache.ignite.util/GridCommandHandlerClusterByClassTest_help.output
index 62c99c348b4..ed26dbae2db 100644
---
a/modules/core/src/test/resources/org.apache.ignite.util/GridCommandHandlerClusterByClassTest_help.output
+++
b/modules/core/src/test/resources/org.apache.ignite.util/GridCommandHandlerClusterByClassTest_help.output
@@ -269,12 +269,18 @@ This utility can do the following commands:
Get the status of the current snapshot operation:
control.(sh|bat) --snapshot status
+ Lists all snapshots on all online server nodes, including their sizes:
+ control.(sh|bat) --snapshot list [--src path/to/snapshots]
+
+ Parameters:
+ --src path/to/snapshots - Path to the directory where the snapshot
files are located. If not specified, the default configured snapshot directory
will be used.
+
Deletes the snapshot and all its incremental snapshots from all online
server nodes:
control.(sh|bat) --snapshot delete snapshot_name [--src path/to/snapshots]
Parameters:
snapshot_name - Snapshot name.
- --src path/to/snapshots - Path to snapshot location directory. If
not specified, the default snapshot configuration directory will be used.
+ --src path/to/snapshots - Path to the directory where the snapshot
files are located. If not specified, the default configured snapshot directory
will be used.
Change cluster tag to new value:
control.(sh|bat) --change-tag newTagValue [--yes]
diff --git
a/modules/core/src/test/resources/org.apache.ignite.util/GridCommandHandlerClusterByClassWithSSLTest_help.output
b/modules/core/src/test/resources/org.apache.ignite.util/GridCommandHandlerClusterByClassWithSSLTest_help.output
index d2755b6b269..1173917caff 100644
---
a/modules/core/src/test/resources/org.apache.ignite.util/GridCommandHandlerClusterByClassWithSSLTest_help.output
+++
b/modules/core/src/test/resources/org.apache.ignite.util/GridCommandHandlerClusterByClassWithSSLTest_help.output
@@ -269,12 +269,18 @@ This utility can do the following commands:
Get the status of the current snapshot operation:
control.(sh|bat) --snapshot status
+ Lists all snapshots on all online server nodes, including their sizes:
+ control.(sh|bat) --snapshot list [--src path/to/snapshots]
+
+ Parameters:
+ --src path/to/snapshots - Path to the directory where the snapshot
files are located. If not specified, the default configured snapshot directory
will be used.
+
Deletes the snapshot and all its incremental snapshots from all online
server nodes:
control.(sh|bat) --snapshot delete snapshot_name [--src path/to/snapshots]
Parameters:
snapshot_name - Snapshot name.
- --src path/to/snapshots - Path to snapshot location directory. If
not specified, the default snapshot configuration directory will be used.
+ --src path/to/snapshots - Path to the directory where the snapshot
files are located. If not specified, the default configured snapshot directory
will be used.
Change cluster tag to new value:
control.(sh|bat) --change-tag newTagValue [--yes]