Skip to content

Commit

Permalink
IGNITE-18463 Fixed snapshot cancel if one path is configured for seve…
Browse files Browse the repository at this point in the history
…ral nodes (apache#10462)
  • Loading branch information
NSAmelchev authored Dec 28, 2022
1 parent 4ef3889 commit 220f59f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -669,54 +669,57 @@ public void deleteSnapshot(File snpDir, String folderName) {
try {
File binDir = binaryWorkDir(snpDir.getAbsolutePath(), folderName);
File nodeDbDir = new File(snpDir.getAbsolutePath(), databaseRelativePath(folderName));
File smf = new File(snpDir, snapshotMetaFileName(folderName));

U.delete(binDir);
U.delete(nodeDbDir);
U.delete(smf);

File marshDir = mappingFileStoreWorkDir(snpDir.getAbsolutePath());

// Concurrently traverse the snapshot marshaller directory and delete all files.
Files.walkFileTree(marshDir.toPath(), new SimpleFileVisitor<Path>() {
@Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
U.delete(file);

return FileVisitResult.CONTINUE;
}

@Override public FileVisitResult visitFileFailed(Path file, IOException exc) {
// Skip files which can be concurrently removed from FileTree.
return FileVisitResult.CONTINUE;
}

@Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
dir.toFile().delete();

if (log.isInfoEnabled() && exc != null)
log.info("Marshaller directory cleaned with an exception: " + exc.getMessage());

return FileVisitResult.CONTINUE;
}
});
deleteDirectory(marshDir);

File binMetadataDfltDir = new File(snpDir, DFLT_BINARY_METADATA_PATH);
File marshallerDfltDir = new File(snpDir, DFLT_MARSHALLER_PATH);

U.delete(binMetadataDfltDir);
U.delete(marshallerDfltDir);
deleteDirectory(binMetadataDfltDir);
deleteDirectory(marshallerDfltDir);

File db = new File(snpDir, DB_DEFAULT_FOLDER);

if (!db.exists() || F.isEmpty(db.list())) {
marshDir.delete();
db.delete();
U.delete(snpDir);
}
db.delete();
snpDir.delete();
}
catch (IOException e) {
throw new IgniteException(e);
}
}

/** Concurrently traverse the directory and delete all files. */
private void deleteDirectory(File dir) throws IOException {
Files.walkFileTree(dir.toPath(), new SimpleFileVisitor<Path>() {
@Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
U.delete(file);

return FileVisitResult.CONTINUE;
}

@Override public FileVisitResult visitFileFailed(Path file, IOException exc) {
// Skip files which can be concurrently removed from FileTree.
return FileVisitResult.CONTINUE;
}

@Override public FileVisitResult postVisitDirectory(Path dir, IOException e) {
dir.toFile().delete();

if (log.isInfoEnabled() && e != null)
log.info("Snapshot directory cleaned with an exception [dir=" + dir + ", e=" + e.getMessage() + ']');

return FileVisitResult.CONTINUE;
}
});
}

/**
* @param snpName Snapshot name.
* @return Local snapshot directory for snapshot with given name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3735,7 +3735,7 @@ public static <E extends Throwable> E withCause(E e, @Nullable Throwable cause)
}

/**
* Deletes file or directory with all sub-directories and files.
* Deletes file or directory with all sub-directories and files. Not thread-safe.
*
* @param file File or directory to delete.
* @return {@code true} if and only if the file or directory is successfully deleted,
Expand All @@ -3756,7 +3756,7 @@ public static int sizeInMegabytes(long sizeInBytes) {
}

/**
* Deletes file or directory with all sub-directories and files.
* Deletes file or directory with all sub-directories and files. Not thread-safe.
*
* @param path File or directory to delete.
* @return {@code true} if and only if the file or directory is successfully deleted,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1200,9 +1200,9 @@ public void testClusterSnapshotFromClientDisconnected() throws Exception {
/** @throws Exception If fails. */
@Test
public void testClusterSnapshotInProgressCancelled() throws Exception {
IgniteEx srv = startGridsWithCache(1, dfltCacheCfg, CACHE_KEYS_RANGE);
IgniteEx startCli = startClientGrid(1);
IgniteEx killCli = startClientGrid(2);
IgniteEx srv = startGridsWithCache(3, dfltCacheCfg, CACHE_KEYS_RANGE);
IgniteEx startCli = startClientGrid(3);
IgniteEx killCli = startClientGrid(4);

doSnapshotCancellationTest(startCli, Collections.singletonList(srv), srv.cache(dfltCacheCfg.getName()),
snpName -> killCli.snapshot().cancelSnapshot(snpName).get());
Expand Down

0 comments on commit 220f59f

Please sign in to comment.