aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src
diff options
context:
space:
mode:
authorHector Caballero <hector.caballero@ericsson.com>2017-11-03 14:39:37 -0400
committerHector Oswaldo Caballero <hector.caballero@ericsson.com>2017-11-24 05:13:24 -0500
commitbac4d32d39abc6fb9af61628adbed139ea442ee9 (patch)
tree7788a3a2fe8143cefe2e179046228f05348f4ba2 /org.eclipse.jgit/src
parent03abd1dff21263a92ccf02e4178daef299398be2 (diff)
downloadjgit-bac4d32d39abc6fb9af61628adbed139ea442ee9.tar.gz
jgit-bac4d32d39abc6fb9af61628adbed139ea442ee9.zip
GC: Delete stale temporary packs and indexes
When a GC operation is interrupted, temporary packs and indexes can be left on the pack folder. In big, busy repositories this can lead to significant amounts of wasted disk space if this interruption is done with a certain frequency. Remove stale temporary packs and indexes at the end of the GC process so they do not accumulate. To avoid interfering with a possible concurrent JGit GC process in the same repository, only delete temporary files that are older than one day. Change-Id: If9b6c1e57fac8a6a0ecc0a703089634caba4caae Signed-off-by: Hector Caballero <hector.caballero@ericsson.com>
Diffstat (limited to 'org.eclipse.jgit/src')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java25
1 files changed, 25 insertions, 0 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
index f992a33408..928e52d6b4 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
@@ -61,6 +61,8 @@ import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.text.MessageFormat;
import java.text.ParseException;
+import java.time.Instant;
+import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -903,6 +905,7 @@ public class GC {
}
prunePacked();
deleteOrphans();
+ deleteTempPacksIdx();
lastPackedRefs = refsBefore;
lastRepackTime = time;
@@ -959,6 +962,28 @@ public class GC {
}
}
+ private void deleteTempPacksIdx() {
+ Path packDir = Paths.get(repo.getObjectsDirectory().getAbsolutePath(),
+ "pack"); //$NON-NLS-1$
+ Instant threshold = Instant.now().minus(1, ChronoUnit.DAYS);
+ try {
+ Files.newDirectoryStream(packDir, "gc_*_tmp") //$NON-NLS-1$
+ .forEach(t -> {
+ try {
+ Instant lastModified = Files.getLastModifiedTime(t)
+ .toInstant();
+ if (lastModified.isBefore(threshold)) {
+ Files.deleteIfExists(t);
+ }
+ } catch (IOException e) {
+ LOG.error(e.getMessage(), e);
+ }
+ });
+ } catch (IOException e) {
+ LOG.error(e.getMessage(), e);
+ }
+ }
+
/**
* @param ref
* the ref which log should be inspected