Browse Source

Cluster UNREACHABLE_GARBAGE packs at the end of the search list

Garbage is unlikely to be used by a reader. Ensure they always
cluster at the end of the search list, no matter what timestamp
was used on the pack files.

Change-Id: I3bed89e9569ee3363c36bb3f73fcd34057a3883f
stable-3.0
Shawn Pearce 12 years ago
parent
commit
ea5eef912a
  1. 16
      org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsObjDatabase.java
  2. 9
      org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackDescription.java

16
org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsObjDatabase.java

@ -65,7 +65,7 @@ public abstract class DfsObjDatabase extends ObjectDatabase {
/** Sources for a pack file. */ /** Sources for a pack file. */
public static enum PackSource { public static enum PackSource {
/** The pack is created by ObjectInserter due to local activity. */ /** The pack is created by ObjectInserter due to local activity. */
INSERT, INSERT(0),
/** /**
* The pack is created by PackParser due to a network event. * The pack is created by PackParser due to a network event.
@ -76,7 +76,7 @@ public abstract class DfsObjDatabase extends ObjectDatabase {
* storage layout preferred by this version. Received packs are likely * storage layout preferred by this version. Received packs are likely
* to be either compacted or garbage collected in the future. * to be either compacted or garbage collected in the future.
*/ */
RECEIVE, RECEIVE(0),
/** /**
* Pack was created by Git garbage collection by this implementation. * Pack was created by Git garbage collection by this implementation.
@ -87,7 +87,7 @@ public abstract class DfsObjDatabase extends ObjectDatabase {
* *
* @see DfsGarbageCollector * @see DfsGarbageCollector
*/ */
GC, GC(1),
/** /**
* The pack was created by compacting multiple packs together. * The pack was created by compacting multiple packs together.
@ -98,7 +98,7 @@ public abstract class DfsObjDatabase extends ObjectDatabase {
* *
* @see DfsPackCompactor * @see DfsPackCompactor
*/ */
COMPACT, COMPACT(1),
/** /**
* Pack was created by Git garbage collection. * Pack was created by Git garbage collection.
@ -107,7 +107,13 @@ public abstract class DfsObjDatabase extends ObjectDatabase {
* last GC pass. It is retained in a new pack until it is safe to prune * last GC pass. It is retained in a new pack until it is safe to prune
* these objects from the repository. * these objects from the repository.
*/ */
UNREACHABLE_GARBAGE; UNREACHABLE_GARBAGE(2);
final int category;
PackSource(int category) {
this.category = category;
}
} }
private final AtomicReference<PackList> packList; private final AtomicReference<PackList> packList;

9
org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackDescription.java

@ -303,6 +303,15 @@ public class DfsPackDescription implements Comparable<DfsPackDescription> {
* the other pack. * the other pack.
*/ */
public int compareTo(DfsPackDescription b) { public int compareTo(DfsPackDescription b) {
// Cluster by PackSource, pushing UNREACHABLE_GARBAGE to the end.
PackSource as = getPackSource();
PackSource bs = b.getPackSource();
if (as != null && bs != null) {
int cmp = as.category - bs.category;
if (cmp != 0)
return cmp;
}
// Newer packs should sort first. // Newer packs should sort first.
int cmp = Long.signum(b.getLastModified() - getLastModified()); int cmp = Long.signum(b.getLastModified() - getLastModified());
if (cmp != 0) if (cmp != 0)

Loading…
Cancel
Save