aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2010-04-26 14:42:40 -0700
committerShawn O. Pearce <spearce@spearce.org>2010-04-26 17:32:04 -0700
commita0a52897ed3fb66ff8a7e1737bf854042f77f0ce (patch)
tree0174aaffee5d27e14bb8d628f7f37730ffcc5581
parenteeed0abd1626eb972059252bdc1c68b5bb8faf78 (diff)
downloadjgit-a0a52897ed3fb66ff8a7e1737bf854042f77f0ce.tar.gz
jgit-a0a52897ed3fb66ff8a7e1737bf854042f77f0ce.zip
Favor earlier PackFile instances over later duplicates
There is a potential race condition during insertPack that can lead to us having the same pack file open twice in the same directory. A different thread can miss an object on disk, and trigger a scan of the directory, and notice the pack that was put in by IndexPack. So the pack winds up in the newly created PackList. The IndexPack thread then wakes up and finishes its insertPack by creating a new PackFile and inserting it into position 0 of the list. We now have the same pack listed twice. Readers will favor the earlier PackFile instance, because its the first one they come across as they iterate through the list. Keep that earlier one when we scan the pack directory again, as this will avoid needing to purge out all of the windows that may have been cached. Of course we should also fix that race condition, but this block was taking the wrong resolution if this error ever shows up, so lets first fix the block to use a more sane resolution. Change-Id: I0d339b9fd1dd8012e8fe5a564b893c0f69109e28 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectDirectory.java7
1 files changed, 4 insertions, 3 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectDirectory.java
index a8d6dda066..8f96ef5f06 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectDirectory.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectDirectory.java
@@ -416,10 +416,11 @@ public class ObjectDirectory extends ObjectDatabase {
// This should never occur. It should be impossible for us
// to have two pack files with the same name, as all of them
// came out of the same directory. If it does, we promised to
- // close any PackFiles we did not reuse, so close the one we
- // just evicted out of the reuse map.
+ // close any PackFiles we did not reuse, so close the second,
+ // readers are likely to be actively using the first.
//
- prior.close();
+ forReuse.put(prior.getPackFile().getName(), prior);
+ p.close();
}
}
return forReuse;