Skip to content

Commit 3d62e03

Browse files
authored
CNDB-15990: Avoid varargs allocations in atomicMoveWithFallback (#2124)
### What is the issue riptano/cndb#15990 ### What does this PR fix and why was it fixed - What: Eliminates unnecessary array allocations in PathUtils.atomicMoveWithFallback() by pre-allocating CopyOption[] arrays as static constants. - Why: JFR profiling showed this method was a memory allocation hotspot during RemoteFileCache preloading. Each call to Files.move() with varargs parameters created new arrays, causing excessive GC pressure.
1 parent 97eaa52 commit 3d62e03

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/java/org/apache/cassandra/io/util/PathUtils.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ public final class PathUtils
7474

7575
private static volatile boolean DAEMON_SETUP_COMPLETED = false;
7676

77+
private static final CopyOption[] ATOMIC_MOVE_OPTIONS = {
78+
StandardCopyOption.REPLACE_EXISTING,
79+
StandardCopyOption.ATOMIC_MOVE
80+
};
81+
82+
private static final CopyOption[] REPLACE_EXISTING_OPTIONS = {
83+
StandardCopyOption.REPLACE_EXISTING
84+
};
85+
7786
private static Consumer<Path> onDeletion = path -> {
7887
if (DAEMON_SETUP_COMPLETED)
7988
setDeletionListener(ignore -> {});
@@ -394,7 +403,7 @@ private static void deleteRecursive(Path path, RateLimiter rateLimiter, Consumer
394403

395404
/**
396405
* Recursively delete the content of the directory, but not the directory itself.
397-
* @param dirPath directory for which content should be deleted
406+
* @param dirPath directory for which content should be deleted
398407
*/
399408
public static void deleteContent(Path dirPath)
400409
{
@@ -496,12 +505,12 @@ private static void atomicMoveWithFallback(Path from, Path to) throws IOExceptio
496505
{
497506
try
498507
{
499-
Files.move(from, to, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE);
508+
Files.move(from, to, ATOMIC_MOVE_OPTIONS);
500509
}
501510
catch (AtomicMoveNotSupportedException e)
502511
{
503512
logger.trace("Could not do an atomic move", e);
504-
Files.move(from, to, StandardCopyOption.REPLACE_EXISTING);
513+
Files.move(from, to, REPLACE_EXISTING_OPTIONS);
505514
}
506515
}
507516

0 commit comments

Comments
 (0)