Skip to content

Commit

Permalink
IGNITE-24481 Migration to snapshot file tree
Browse files Browse the repository at this point in the history
  • Loading branch information
nizhikov committed Feb 12, 2025
1 parent a5b90f9 commit 42f4a41
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public class SnapshotFileTree extends NodeFileTree {
/** File name template for index delta pages. */
public static final String INDEX_DELTA_NAME = INDEX_FILE_NAME + DELTA_SUFFIX;

/** Lock file for dump directory. */
public static final String DUMP_LOCK = "dump.lock";

/** Snapshot name. */
private final String name;

Expand Down Expand Up @@ -85,6 +88,13 @@ public File partDeltaFile(String cacheDirName, int partId) {
return new File(tmpFt.cacheStorage(cacheDirName), partDeltaFileName(partId));
}

/**
* @return Dump lock file.
*/
public File dumpLock() {
return new File(nodeStorage(), DUMP_LOCK);
}

/**
* @param partId Partition id.
* @return File name of delta partition pages.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,6 @@ public class IgniteSnapshotManager extends GridCacheSharedManagerAdapter
/** Pattern for incremental snapshot directory names. */
public static final Pattern INC_SNP_NAME_PATTERN = U.fixedLengthNumberNamePattern(null);

/** Lock file for dump directory. */
public static final String DUMP_LOCK = "dump.lock";

/**
* Local buffer to perform copy-on-write operations with pages for {@code SnapshotFutureTask.PageStoreSerialWriter}s.
* It is important to have only one buffer per thread (instead of creating each buffer per
Expand Down Expand Up @@ -649,16 +646,14 @@ public static File partDeltaIndexFile(File delta) {
if (files != null) {
Arrays.stream(files)
.filter(File::isDirectory)
.map(dumpDir ->
Paths.get(dumpDir.getAbsolutePath(), DB_DEFAULT_FOLDER, pdsSettings.folderName(), DUMP_LOCK).toFile())
.filter(File::exists)
.map(File::getParentFile)
.forEach(lockedDumpDir -> {
.map(dumpDir -> new SnapshotFileTree(ft, dumpDir.getName(), null))
.filter(sft -> sft.dumpLock().exists())
.forEach(sft -> {
log.warning("Found locked dump dir. " +
"This means, dump creation not finished prior to node fail. " +
"Directory will be deleted: " + lockedDumpDir);
"Directory will be deleted: " + sft.nodeStorage().getAbsolutePath());

U.delete(lockedDumpDir);
U.delete(sft.nodeStorage());
});
}
}
Expand Down Expand Up @@ -2769,7 +2764,7 @@ private void removeLastMetaStorageKey() throws IgniteCheckedException {

/** */
private void removeDumpLock(String dumpName) throws IgniteCheckedException {
File lock = new File(nodeDumpDirectory(snapshotLocalDir(dumpName, null), cctx), DUMP_LOCK);
File lock = new SnapshotFileTree(ft, dumpName, null).dumpLock();

if (!lock.exists())
return;
Expand All @@ -2778,11 +2773,6 @@ private void removeDumpLock(String dumpName) throws IgniteCheckedException {
throw new IgniteCheckedException("Lock file can't be deleted: " + lock);
}

/** */
public static File nodeDumpDirectory(File dumpDir, GridCacheSharedContext<?, ?> cctx) throws IgniteCheckedException {
return new File(dumpDir, databaseRelativePath(cctx.kernalContext().pdsFolderResolver().resolveFolders().folderName()));
}

/**
* Disables creation of incremental snapshots for the given cache group.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@

import static org.apache.ignite.internal.pagemem.PageIdAllocator.INDEX_PARTITION;
import static org.apache.ignite.internal.processors.cache.persistence.filename.NodeFileTree.cacheDataFilename;
import static org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager.DUMP_LOCK;
import static org.apache.ignite.internal.processors.cache.persistence.snapshot.dump.Dump.dumpPartFileName;
import static org.apache.ignite.internal.util.IgniteUtils.toLong;

Expand Down Expand Up @@ -408,7 +407,7 @@ private void createDumpLock() throws IgniteCheckedException, IOException {
if (!nodeDumpDir.mkdirs())
throw new IgniteCheckedException("Can't create node dump directory: " + nodeDumpDir.getAbsolutePath());

File lock = new File(nodeDumpDir, DUMP_LOCK);
File lock = sft.dumpLock();

if (!lock.createNewFile())
throw new IgniteCheckedException("Lock file can't be created or already exists: " + lock.getAbsolutePath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
import org.apache.ignite.internal.processors.cache.StoredCacheData;
import org.apache.ignite.internal.processors.cache.dr.GridCacheDrInfo;
import org.apache.ignite.internal.processors.cache.persistence.filename.NodeFileTree;
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.dump.AbstractCacheDumpTest.TestDumpConsumer;
import org.apache.ignite.internal.processors.cache.version.CacheVersionConflictResolver;
Expand Down Expand Up @@ -117,9 +118,7 @@
import static org.apache.ignite.internal.processors.cache.persistence.filename.NodeFileTree.CACHE_DATA_FILENAME;
import static org.apache.ignite.internal.processors.cache.persistence.filename.NodeFileTree.PART_FILE_PREFIX;
import static org.apache.ignite.internal.processors.cache.persistence.filename.NodeFileTree.ZIP_SUFFIX;
import static org.apache.ignite.internal.processors.cache.persistence.filename.PdsFolderResolver.DB_DEFAULT_FOLDER;
import static org.apache.ignite.internal.processors.cache.persistence.snapshot.AbstractSnapshotSelfTest.doSnapshotCancellationTest;
import static org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager.DUMP_LOCK;
import static org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager.SNAPSHOT_TRANSFER_RATE_DMS_KEY;
import static org.apache.ignite.internal.processors.cache.persistence.snapshot.dump.AbstractCacheDumpTest.CACHE_0;
import static org.apache.ignite.internal.processors.cache.persistence.snapshot.dump.AbstractCacheDumpTest.DMP_NAME;
Expand All @@ -139,7 +138,7 @@
/** */
public class IgniteCacheDumpSelf2Test extends GridCommonAbstractTest {
/** */
private LogListener lsnr;
private volatile LogListener lsnr;

/** */
private boolean persistence;
Expand Down Expand Up @@ -381,6 +380,8 @@ public void testUnreadyDumpCleared() throws Exception {

ign.snapshot().createDump(DMP_NAME, null).get(getTestTimeout());

NodeFileTree ft = grid(1).context().pdsFolderResolver().fileTree();

stopAllGrids();

Dump dump = dump(ign, DMP_NAME);
Expand All @@ -390,17 +391,17 @@ public void testUnreadyDumpCleared() throws Exception {
assertNotNull(nodes);
assertEquals(2, nodes.size());

File nodeDumpDir = new File(dump.dumpDirectory(), DB_DEFAULT_FOLDER + File.separator + nodes.get(0));
SnapshotFileTree sft = new SnapshotFileTree(ft, DMP_NAME, null);

assertTrue(new File(nodeDumpDir, DUMP_LOCK).createNewFile());
assertTrue(sft.dumpLock().createNewFile());

lsnr = LogListener.matches("Found locked dump dir. " +
"This means, dump creation not finished prior to node fail. " +
"Directory will be deleted: " + nodeDumpDir.getAbsolutePath()).build();
"Directory will be deleted: " + sft.nodeStorage().getAbsolutePath()).build();

startGridsMultiThreaded(2);

assertFalse(nodeDumpDir.exists());
assertFalse(sft.nodeStorage().exists());
assertTrue(lsnr.check());
}

Expand Down

0 comments on commit 42f4a41

Please sign in to comment.