Skip to content

Commit

Permalink
IGNITE-20601 Support custom location for cache dumps (#10990)
Browse files Browse the repository at this point in the history
  • Loading branch information
nizhikov authored Oct 11, 2023
1 parent 56e6144 commit 8aed3c6
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,7 @@ private IgniteInternalFuture<SnapshotOperationResponse> initLocalFullSnapshot(
Collection<Integer> comprGrpIds,
boolean withMetaStorage
) {
if (!isPersistenceEnabled(cctx.gridConfig()))
if (!isPersistenceEnabled(cctx.gridConfig()) && req.snapshotPath() == null)
initLocalSnapshotDirectory(true);

Map<Integer, Set<Integer>> parts = new HashMap<>();
Expand Down Expand Up @@ -1185,6 +1185,7 @@ private IgniteInternalFuture<SnapshotOperationResponse> initLocalFullSnapshot(
task0 = new GridFinishedFuture<>(Collections.emptySet());
else {
task0 = registerSnapshotTask(req.snapshotName(),
req.snapshotPath(),
req.operationalNodeId(),
req.requestId(),
parts,
Expand Down Expand Up @@ -2719,6 +2720,7 @@ public GridCloseableIterator<CacheDataRow> partitionRowIterator(String snpName,

/**
* @param snpName Unique snapshot name.
* @param snpPath Snapshot path.
* @param srcNodeId Node id which cause snapshot operation.
* @param requestId Snapshot operation request ID.
* @param parts Collection of pairs group and appropriate cache partition to be snapshot.
Expand All @@ -2729,6 +2731,7 @@ public GridCloseableIterator<CacheDataRow> partitionRowIterator(String snpName,
*/
AbstractSnapshotFutureTask<?> registerSnapshotTask(
String snpName,
@Nullable String snpPath,
UUID srcNodeId,
UUID requestId,
Map<Integer, Set<Integer>> parts,
Expand All @@ -2737,7 +2740,7 @@ AbstractSnapshotFutureTask<?> registerSnapshotTask(
SnapshotSender snpSndr
) {
AbstractSnapshotFutureTask<?> task = registerTask(snpName, dump
? new CreateDumpFutureTask(cctx, srcNodeId, requestId, snpName, snapshotLocalDir(snpName, null), ioFactory, snpSndr, parts)
? new CreateDumpFutureTask(cctx, srcNodeId, requestId, snpName, snapshotLocalDir(snpName, snpPath), ioFactory, snpSndr, parts)
: new SnapshotFutureTask(cctx, srcNodeId, requestId, snpName, tmpWorkDir, ioFactory, snpSndr, parts, withMetaStorage, locBuff));

if (!withMetaStorage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ protected static IgniteInternalFuture<?> startLocalSnapshotTask(
boolean withMetaStorage,
SnapshotSender snpSndr
) throws IgniteCheckedException {
AbstractSnapshotFutureTask<?> task = cctx.snapshotMgr().registerSnapshotTask(snpName, cctx.localNodeId(), null,
AbstractSnapshotFutureTask<?> task = cctx.snapshotMgr().registerSnapshotTask(snpName, null, cctx.localNodeId(), null,
parts, withMetaStorage, false, snpSndr);

if (!(task instanceof SnapshotFutureTask))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public void testSnapshotTaskIsBlockedWithoutMetastore() throws Exception {
IgniteEx ig = startGridsWithCache(1, CACHE_KEYS_RANGE, valueBuilder(), dfltCacheCfg);

GridTestUtils.assertThrowsAnyCause(log,
() -> snp(ig).registerSnapshotTask(SNAPSHOT_NAME, ig.localNode().id(),
() -> snp(ig).registerSnapshotTask(SNAPSHOT_NAME, null, ig.localNode().id(),
null, F.asMap(CU.cacheId(dfltCacheCfg.getName()), null), false, false,
snp(ig).localSnapshotSenderFactory().apply(SNAPSHOT_NAME, null)).get(TIMEOUT),
IgniteCheckedException.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public void testSnapshotLocalPartitionMultiCpWithLoad() throws Exception {

// Register task but not schedule it on the checkpoint.
SnapshotFutureTask snpFutTask = (SnapshotFutureTask)mgr.registerSnapshotTask(SNAPSHOT_NAME,
null,
cctx.localNodeId(),
null,
F.asMap(CU.cacheId(DEFAULT_CACHE_NAME), null),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,14 @@ public static void checkDumpWithCommand(IgniteEx ign, String name, int backups)

/** */
public static String invokeCheckCommand(IgniteEx ign, String name) throws IgniteCheckedException {
return invokeCheckCommand(ign, name, null);
}

/** */
public static String invokeCheckCommand(IgniteEx ign, String name, String snpPath) throws IgniteCheckedException {
StringBuffer buf = new StringBuffer();

ign.context().cache().context().snapshotMgr().checkSnapshot(name, null).get(60_000)
ign.context().cache().context().snapshotMgr().checkSnapshot(name, snpPath).get(60_000)
.print(line -> buf.append(line).append(System.lineSeparator()));

return buf.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,52 @@ public void testCheckFailOnCorruptedData() throws Exception {
);
}

/** */
@Test
public void testCustomLocation() throws Exception {
try (IgniteEx ign = startGrid()) {
IgniteCache<Integer, Integer> cache = ign.createCache(new CacheConfiguration<Integer, Integer>()
.setName("test-cache-0")
.setBackups(1)
.setAtomicityMode(CacheAtomicityMode.ATOMIC));

IntStream.range(0, KEYS_CNT).forEach(i -> cache.put(i, i));

File snpDir = U.resolveWorkDirectory(U.defaultWorkDirectory(), "ex_snapshots", true);

assertTrue(U.delete(snpDir));

ign.context().cache().context().snapshotMgr().createSnapshot(
DMP_NAME,
snpDir.getAbsolutePath(),
null,
false,
false,
true
).get();

assertFalse(
"Standard snapshot directory must created lazily for in-memory node",
new File(U.defaultWorkDirectory(), DFLT_SNAPSHOT_DIRECTORY).exists()
);

assertFalse(
"Temporary snapshot directory must created lazily for in-memory node",
new File(
ign.context().pdsFolderResolver().resolveFolders().persistentStoreNodePath().getAbsolutePath(),
DFLT_SNAPSHOT_TMP_DIR
).exists()
);

assertTrue(snpDir.exists());

assertEquals(
"The check procedure has finished, no conflicts have been found.\n\n",
invokeCheckCommand(ign, DMP_NAME, snpDir.getAbsolutePath())
);
}
}

/** */
@Test
public void testCheckOnEmptyNode() throws Exception {
Expand Down

0 comments on commit 8aed3c6

Please sign in to comment.