Browse Source

Merge branch 'stable-4.10' into stable-4.11

* stable-4.10:
  Reduce contention on PackFile.idx() function.

Change-Id: I5dd7576018ab2e85d77d336f97c8e77ad71520c9
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-4.11
Matthias Sohn 6 years ago
parent
commit
495ecda567
  1. 37
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java

37
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java

@ -139,7 +139,7 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> {
private byte[] packChecksum; private byte[] packChecksum;
private PackIndex loadedIdx; private volatile PackIndex loadedIdx;
private PackReverseIndex reverseIdx; private PackReverseIndex reverseIdx;
@ -174,35 +174,44 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> {
length = Long.MAX_VALUE; length = Long.MAX_VALUE;
} }
private synchronized PackIndex idx() throws IOException { private PackIndex idx() throws IOException {
if (loadedIdx == null) { PackIndex idx = loadedIdx;
if (invalid) if (idx == null) {
synchronized (this) {
idx = loadedIdx;
if (idx == null) {
if (invalid) {
throw new PackInvalidException(packFile); throw new PackInvalidException(packFile);
}
try { try {
final PackIndex idx = PackIndex.open(extFile(INDEX)); idx = PackIndex.open(extFile(INDEX));
if (packChecksum == null) { if (packChecksum == null) {
packChecksum = idx.packChecksum; packChecksum = idx.packChecksum;
} else if (!Arrays.equals(packChecksum, idx.packChecksum)) { } else if (!Arrays.equals(packChecksum,
throw new PackMismatchException(MessageFormat.format( idx.packChecksum)) {
JGitText.get().packChecksumMismatch, throw new PackMismatchException(MessageFormat
.format(JGitText.get().packChecksumMismatch,
packFile.getPath(), packFile.getPath(),
ObjectId.fromRaw(packChecksum).name(), ObjectId.fromRaw(packChecksum)
ObjectId.fromRaw(idx.packChecksum).name())); .name(),
ObjectId.fromRaw(idx.packChecksum)
.name()));
} }
loadedIdx = idx; loadedIdx = idx;
} catch (InterruptedIOException e) { } catch (InterruptedIOException e) {
// don't invalidate the pack, we are interrupted from another thread // don't invalidate the pack, we are interrupted from
// another thread
throw e; throw e;
} catch (IOException e) { } catch (IOException e) {
invalid = true; invalid = true;
throw e; throw e;
} }
} }
return loadedIdx;
} }
}
return idx;
}
/** /**
* Get the File object which locates this pack on disk. * Get the File object which locates this pack on disk.
* *

Loading…
Cancel
Save