Merge branch 'stable-4.11' into stable-5.0

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

Change-Id: Ib1be8c04c9587c595f7d95df26f7be9b237bda40
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
Matthias Sohn 2019-03-12 00:09:34 +01:00
commit 35e96348d3
1 changed files with 34 additions and 25 deletions

View File

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