diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/FileSystemRepository.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/FileSystemRepository.java index 9fec793442..497e630062 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/FileSystemRepository.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/FileSystemRepository.java @@ -1196,7 +1196,7 @@ public class FileSystemRepository implements ContentRepository { private long destroyExpiredArchives(final String containerName, final Path container) throws IOException { archiveExpirationLog.debug("Destroying Expired Archives for Container {}", containerName); final List notYetExceedingThreshold = new ArrayList<>(); - final long removalTimeThreshold = System.currentTimeMillis() - maxArchiveMillis; + long removalTimeThreshold = System.currentTimeMillis() - maxArchiveMillis; long oldestArchiveDateFound = System.currentTimeMillis(); // determine how much space we must have in order to stop deleting old data @@ -1230,6 +1230,8 @@ public class FileSystemRepository implements ContentRepository { try { final long fileSize = toDelete.getSize(); + removalTimeThreshold = System.currentTimeMillis() - maxArchiveMillis; + // we use fileQueue.peek above instead of fileQueue.poll() because we don't always want to // remove the head of the queue. Instead, we want to remove it only if we plan to delete it. // In order to accomplish this, we just peek at the head and check if it should be deleted. @@ -1287,6 +1289,7 @@ public class FileSystemRepository implements ContentRepository { } try { + final long timestampThreshold = removalTimeThreshold; Files.walkFileTree(archive, new SimpleFileVisitor() { @Override public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { @@ -1295,7 +1298,7 @@ public class FileSystemRepository implements ContentRepository { } final long lastModTime = getLastModTime(file); - if (lastModTime < removalTimeThreshold) { + if (lastModTime < timestampThreshold) { try { Files.deleteIfExists(file); containerState.decrementArchiveCount();