-
Notifications
You must be signed in to change notification settings - Fork 1.9k
IGNITE-29050 Introduce snapshot deletion command #13577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
eb6273c
d9aa470
7042aec
682a21c
bcc72c4
3ab443a
9171c7e
de68328
f0996e9
80c7644
c8d1c25
fc11a5f
8a007e3
97ab26c
fbb2cf8
2ed26ad
9b0e5ff
b09e0b3
71717c2
7148da6
d36c642
9a658df
35a4c9d
d715c66
e6aa330
4233322
b11f389
37cb071
f00d266
57909f4
edd86d7
7e82295
ed9cc3a
bb1dfec
129b090
4249205
b7c182d
a67c484
a0425cb
d30d4f9
852904f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -287,6 +287,48 @@ control.(sh|bat) --snapshot restore snapshot_09062021 --groups cache-group1,cach | |||||
| control.(sh|bat) --snapshot restore snapshot_09062021 --increment 1 | ||||||
| ---- | ||||||
|
|
||||||
| == Deleting Snapshot | ||||||
|
|
||||||
| You can delete a snapshot using the `control.sh|bat` script. | ||||||
|
|
||||||
| The deletion is performed on all *online* server nodes of the cluster. | ||||||
| [NOTE] | ||||||
| ==== | ||||||
| The snapshot integrity, topology and correctness aren't checked. Snapshot data on offline server nodes aren't deleted. | ||||||
| ==== | ||||||
|
|
||||||
| [tabs] | ||||||
| -- | ||||||
| tab:Unix[] | ||||||
| [source,shell] | ||||||
| ---- | ||||||
| # Delete the snapshot "snapshot_09062021". | ||||||
| control.sh --snapshot delete snapshot_09062021 | ||||||
| # Delete the snapshot "snapshot_09062021" located in the "/tmp/ignite/snapshots" folder. | ||||||
| control.sh --snapshot delete snapshot_09062021 --src /tmp/ignite/snapshots | ||||||
| ---- | ||||||
|
|
||||||
| tab:Windows[] | ||||||
| [source,shell] | ||||||
| ---- | ||||||
| # Delete the snapshot "snapshot_09062021". | ||||||
| control.bat --snapshot delete snapshot_09062021 | ||||||
| # Delete the snapshot "snapshot_09062021" located in the "/tmp/ignite/snapshots" folder. | ||||||
| control.bat --snapshot delete snapshot_09062021 --src /tmp/ignite/snapshots | ||||||
| ---- | ||||||
| -- | ||||||
|
|
||||||
| === Delete operation limitations | ||||||
|
|
||||||
| The delete operation is subject to the following limitations: | ||||||
|
|
||||||
| * The deletion is rejected if any concurrent snapshot operation (create, restore, check, or a delete with the same name) is | ||||||
| active for the snapshot. | ||||||
| * The operation is irreversible. It cannot be undone, and the deleted snapshot cannot be restored. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| * The command prompts for a confirmation before the deletion because the operation is irreversible and cannot be undone. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| == 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: | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,235 @@ | ||
| /* | ||
| * 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 org.apache.ignite.IgniteDataStreamer; | ||
| import org.apache.ignite.configuration.IgniteConfiguration; | ||
| import org.apache.ignite.internal.IgniteEx; | ||
| import org.apache.ignite.internal.util.typedef.F; | ||
| import org.apache.ignite.internal.util.typedef.internal.U; | ||
| import org.apache.ignite.testframework.GridTestUtils; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.junit.runners.Parameterized; | ||
| 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.testframework.GridTestUtils.waitForCondition; | ||
| import static org.junit.Assume.assumeTrue; | ||
|
|
||
| /** Test for the command '--snapshot delete'. */ | ||
| @RunWith(Parameterized.class) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. redundant |
||
| public class GridCommandHandlerDeleteSnapshotTest extends GridCommandHandlerAbstractTest { | ||
| /** Value: -1 - do not use, 1 - server node, 0 - client node. */ | ||
| @Parameter(1) | ||
| public int extraNodeIsServer = -1; | ||
|
|
||
| /** */ | ||
| @Parameter(2) | ||
| public boolean addIncrements; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please remove all such notation |
||
|
|
||
| /** */ | ||
| @Parameter(3) | ||
| public boolean changeBaseline; | ||
|
|
||
| /** */ | ||
| @Parameter(4) | ||
| public boolean customPath; | ||
|
|
||
| /** */ | ||
| @Parameter(5) | ||
| public boolean separatedWorkDir; | ||
|
|
||
| /** */ | ||
| @Parameters(name = "client={0},useExtraNode={1},inc={2},chBaseln={3},cstSnpPath={4},ownWorkDir={5}") | ||
| public static Collection<?> parameters() { | ||
| return GridTestUtils.cartesianProduct( | ||
| commandHandlers(), | ||
| F.asList(-1, 1, 0), // Use extra node (do not use at all, server node, client node); | ||
| F.asList(false, true), // Add increments to the test snapshot; | ||
| F.asList(false, true), // Change baseline; | ||
| F.asList(false, true), // Use custom snapshot path; | ||
| F.asList(true, false) // Separated (own) work directory. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just 4 fun )) all previous : false, true, but only this in different order ) |
||
| ); | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override protected void afterTest() throws Exception { | ||
| super.afterTest(); | ||
|
|
||
| stopAllGrids(); | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override protected void beforeTest() throws Exception { | ||
| super.beforeTest(); | ||
|
|
||
| /** Handy if test running is interrupted and {@link #afterTest()} isn't invoked. */ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. afterTest not cleans the directory - why we need such a line here ? |
||
| cleanPersistenceDir(); | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override protected void cleanPersistenceDir() throws Exception { | ||
| super.cleanPersistenceDir(); | ||
|
|
||
| // Also cleans separated snapshot working directories and custom snapshot pacthes. | ||
| 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); | ||
|
|
||
| if (separatedWorkDir) | ||
| cfg.setWorkDirectory(new File(U.defaultWorkDirectory(), igniteInstanceName).getAbsolutePath()); | ||
|
|
||
| return cfg; | ||
| } | ||
|
|
||
| /** */ | ||
| @Test | ||
| public void testSnapshotDelete() throws Exception { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test failed, fix it plz |
||
| // A custom snapshot path actually puts snapshots in a shared directory. This skews the results when dedicated | ||
| // work directories are set. | ||
| assumeTrue(!customPath || !separatedWorkDir); | ||
|
|
||
| int entriesCnt = 4000; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it really need ? I mean why 10, 100 is not enough ? |
||
| int initNodes = 3; | ||
|
|
||
| walCompactionEnabled(addIncrements); | ||
|
|
||
| IgniteEx ig = (IgniteEx)startGridsMultiThreaded(initNodes); | ||
|
|
||
| if (changeBaseline) { | ||
| ig.cluster().baselineAutoAdjustEnabled(false); | ||
|
|
||
| ig.cluster().setBaselineTopology(ig.cluster().topologyVersion()); | ||
| } | ||
|
|
||
| ig.cluster().state(ACTIVE); | ||
|
|
||
| createCacheAndPreload(ig, entriesCnt); | ||
|
|
||
| File cstSnpsRoot = customPath ? new File(U.defaultWorkDirectory(), "ex_snapshots") : null; | ||
| File snpDir = new File(customPath ? cstSnpsRoot : ig.context().pdsFolderResolver().fileTree().snapshotsRoot(), "testSnapshot"); | ||
|
|
||
| snp(ig).createSnapshot("testSnapshot", customPath ? cstSnpsRoot.getAbsolutePath() : null, false, false) | ||
| .get(getTestTimeout()); | ||
|
|
||
| if (addIncrements) { | ||
| for (int i = 0; i < 3; ++i) { | ||
| int dataIdx = entriesCnt + entriesCnt / 4 * i; | ||
|
|
||
| try (IgniteDataStreamer<Object, Object> streamer = ig.dataStreamer(DEFAULT_CACHE_NAME)) { | ||
| for (int d = dataIdx; d < dataIdx + entriesCnt / 4; ++d) | ||
| streamer.addData(i, i); | ||
| } | ||
|
|
||
| snp(ig).createSnapshot("testSnapshot", customPath ? cstSnpsRoot.getAbsolutePath() : null, true, false) | ||
| .get(getTestTimeout()); | ||
| } | ||
| } | ||
|
|
||
| // Optionally restarts with the same servers number, but changed baseline. The snapshot is kept on the same | ||
| // previous nodes independently of the baseline. | ||
| if (changeBaseline) { | ||
| ig.destroyCache(DEFAULT_CACHE_NAME); | ||
| awaitPartitionMapExchange(); | ||
|
|
||
| stopAllGrids(); | ||
|
|
||
| ig = (IgniteEx)startGridsMultiThreaded(initNodes - 1); | ||
|
|
||
| ig.cluster().setBaselineTopology(ig.cluster().topologyVersion()); | ||
|
|
||
| startGrid(initNodes - 1); | ||
|
|
||
| assertEquals(initNodes - 1, ig.cluster().currentBaselineTopology().size()); | ||
| assertEquals(initNodes, ig.cluster().nodes().size()); | ||
| } | ||
|
|
||
| // Optionally adds extra server or client node. | ||
| if (extraNodeIsServer == 1) | ||
| startGrid(initNodes); | ||
| else if (extraNodeIsServer == 0) | ||
| startGrid(CLIENT_NODE_NAME_PREFIX); | ||
|
|
||
| injectTestSystemOut(); | ||
|
|
||
| // Tests missing snapshot deletion. | ||
| if (customPath) { | ||
| assertEquals(EXIT_CODE_OK, execute(newCommandHandler(), "--snapshot", "delete", "--src", | ||
| cstSnpsRoot.getAbsolutePath(), "wrongSnapshot")); | ||
|
|
||
| assertEquals(EXIT_CODE_OK, execute(newCommandHandler(), "--snapshot", "delete", "--src", | ||
| cstSnpsRoot.getAbsolutePath() + "_wrongPath", "testSnapshot")); | ||
| } | ||
| else | ||
| assertEquals(EXIT_CODE_OK, execute(newCommandHandler(), "--snapshot", "delete", "wrongSnapshot")); | ||
|
|
||
| String out = testOut.toString(); | ||
|
|
||
| assertFalse(out.contains("Snapshot removed on the following nodes")); | ||
| assertFalse(out.contains("the following nodes didn't find any snapshot data, nothing to delete")); | ||
| assertTrue(out.contains("Snapshot not found on current server nodes")); | ||
|
|
||
| testOut.reset(); | ||
| assertTrue(testOut.toString().isEmpty()); | ||
|
|
||
| if (customPath) { | ||
| assertEquals(EXIT_CODE_OK, execute(newCommandHandler(), "--snapshot", "delete", "--src", | ||
| cstSnpsRoot.getAbsolutePath(), "testSnapshot")); | ||
| } | ||
| else | ||
| assertEquals(EXIT_CODE_OK, execute(newCommandHandler(), "--snapshot", "delete", "testSnapshot")); | ||
|
|
||
| out = testOut.toString(); | ||
|
|
||
| if (separatedWorkDir) { | ||
| // When the nodes use own separated work directory, we expect a strict result. | ||
| assertTrue(out.contains("Snapshot removed on the following nodes [cnt=%d]:".formatted(initNodes))); | ||
|
|
||
| if (extraNodeIsServer == 1) | ||
| assertTrue(out.contains("the following nodes didn't find any snapshot data, nothing to delete [cnt=1]:")); | ||
| else if (extraNodeIsServer == 0) | ||
| assertFalse(out.contains("the following nodes didn't find any snapshot data, nothing to delete")); | ||
| } | ||
| else { | ||
| // When nodes use a shared work directory, there is a race for the delete operation. One node can get faster | ||
| // than others and remove snapshot completely quickly. The others might not find snapshot files. We can be | ||
| // only sure that at least one node removes snapshot. | ||
| assertTrue(out.contains("Snapshot removed on the following nodes [cnt=")); | ||
| } | ||
|
|
||
| assertFalse(out.contains("Snapshot not found on current server nodes")); | ||
|
|
||
| assertTrue(waitForCondition(() -> !snpDir.exists(), getTestTimeout())); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if any concurrent - "concurrent_" is sounds like our working term it clear for you and me but for common people you need to re-phrase it like : "The deletion is rejected if any snapshot operation with the same snapshot path\name" smth like this. Concurrent may be treated like JUST one more snapshot operation no matter with this name\path or another.