Merge branch 'stable-5.1' into stable-5.2
* stable-5.1: Reduce contention on PackFile.idx() function. Change-Id: I3f981dd923209e4d2d23f3b10db9fda1e9e68104 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
commit
17e9ec4544
|
@ -139,7 +139,7 @@ public int compare(PackFile a, PackFile b) {
|
||||||
|
|
||||||
private byte[] packChecksum;
|
private byte[] packChecksum;
|
||||||
|
|
||||||
private PackIndex loadedIdx;
|
private volatile PackIndex loadedIdx;
|
||||||
|
|
||||||
private PackReverseIndex reverseIdx;
|
private PackReverseIndex reverseIdx;
|
||||||
|
|
||||||
|
@ -174,35 +174,44 @@ public PackFile(File packFile, int extensions) {
|
||||||
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) {
|
||||||
throw new PackInvalidException(packFile);
|
synchronized (this) {
|
||||||
|
idx = loadedIdx;
|
||||||
|
if (idx == null) {
|
||||||
|
if (invalid) {
|
||||||
|
throw new PackInvalidException(packFile);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
idx = PackIndex.open(extFile(INDEX));
|
||||||
|
|
||||||
try {
|
if (packChecksum == null) {
|
||||||
final PackIndex idx = PackIndex.open(extFile(INDEX));
|
packChecksum = idx.packChecksum;
|
||||||
|
} else if (!Arrays.equals(packChecksum,
|
||||||
if (packChecksum == null) {
|
idx.packChecksum)) {
|
||||||
packChecksum = idx.packChecksum;
|
throw new PackMismatchException(MessageFormat
|
||||||
} else if (!Arrays.equals(packChecksum, idx.packChecksum)) {
|
.format(JGitText.get().packChecksumMismatch,
|
||||||
throw new PackMismatchException(MessageFormat.format(
|
packFile.getPath(),
|
||||||
JGitText.get().packChecksumMismatch,
|
ObjectId.fromRaw(packChecksum)
|
||||||
packFile.getPath(),
|
.name(),
|
||||||
ObjectId.fromRaw(packChecksum).name(),
|
ObjectId.fromRaw(idx.packChecksum)
|
||||||
ObjectId.fromRaw(idx.packChecksum).name()));
|
.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.
|
* Get the File object which locates this pack on disk.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue