Skip to content

Commit

Permalink
better reports in TimeBasedArchiveRemover
Browse files Browse the repository at this point in the history
Signed-off-by: Ceki Gulcu <[email protected]>
  • Loading branch information
ceki committed Mar 16, 2024
1 parent 89e4504 commit f8f0ed9
Showing 1 changed file with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private boolean checkAndDeleteFile(File f) {
addWarn("Cannot delete non existent file");
return false;
}

boolean result = f.delete();
if (!result) {
addWarn("Failed to delete file " + f.toString());
Expand All @@ -125,23 +125,37 @@ private boolean checkAndDeleteFile(File f) {
void capTotalSize(Instant now) {
long totalSize = 0;
long totalRemoved = 0;
int successfulDeletions = 0;
int failedDeletions = 0;

for (int offset = 0; offset < maxHistory; offset++) {
Instant instant = rc.getEndOfNextNthPeriod(now, -offset);
File[] matchingFileArray = getFilesInPeriod(instant);
descendingSort(matchingFileArray, instant);
for (File f : matchingFileArray) {
long size = f.length();
if (totalSize + size > totalSizeCap) {
totalSize += size;
if (totalSize > totalSizeCap) {
addInfo("Deleting [" + f + "]" + " of size " + new FileSize(size));
// assume that deletion attempt will succeed.
totalRemoved += size;

checkAndDeleteFile(f);
boolean success = checkAndDeleteFile(f);
if (success) {
successfulDeletions++;
totalRemoved += size;
} else {
failedDeletions++;
}
}
totalSize += size;
}
}
addInfo("Removed " + new FileSize(totalRemoved) + " of files");
if ((successfulDeletions + failedDeletions) == 0) {
addInfo("No removal attempts were made.");
} else {
addInfo("Removed " + new FileSize(totalRemoved) + " of files in " + successfulDeletions + " files.");
if (failedDeletions != 0) {
addInfo("There were " + failedDeletions + " failed deletion attempts.");
}
}
}

protected void descendingSort(File[] matchingFileArray, Instant instant) {
Expand Down Expand Up @@ -245,8 +259,6 @@ public String toString() {
return "c.q.l.core.rolling.helper.TimeBasedArchiveRemover";
}



public class ArchiveRemoverRunnable implements Runnable {
Instant now;

Expand Down

0 comments on commit f8f0ed9

Please sign in to comment.