mirror of https://github.com/apache/nifi.git
NIFI-1726: Addressed issue where we can run into an infinite loop if we are expiring data based on a timestamp instead of disk space usage and we have a file whose timestamp is exactly equal to our threshold for deletion
Signed-off-by: joewitt <joewitt@apache.org>
This commit is contained in:
parent
b0cc6ae7e8
commit
84b1c60d54
|
@ -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<ArchiveInfo> 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<Path>() {
|
||||
@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();
|
||||
|
|
Loading…
Reference in New Issue