From 4e540d44c8440f3c201a8fccd89e1a2efda11095 Mon Sep 17 00:00:00 2001 From: "Maxim.Mossienko" Date: Fri, 16 May 2014 22:46:00 +0200 Subject: [PATCH] use previously calculated data from PHM if no read right now is performed: calculate the value instead of wait for IO to complete --- .../intellij/util/indexing/MapReduceIndex.java | 18 ++++++++++++------ .../intellij/util/io/PersistentHashMap.java | 13 +++++++++++-- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/util/indexing/MapReduceIndex.java b/platform/lang-impl/src/com/intellij/util/indexing/MapReduceIndex.java index 2c0e5f69aed6..6b04a8113bbe 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/MapReduceIndex.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/MapReduceIndex.java @@ -311,15 +311,20 @@ public class MapReduceIndex implements UpdatableIndex data = null; boolean havePersistentData = false; Integer hashId = null; + boolean skippedReadingPersistentDataButMayHaveIt = false; if (myContents != null && weProcessPhysicalContent && content != null) { try { hashId = getHashOfContent((FileContent)content); if (doReadSavedPersistentData) { - ByteSequence bytes = myContents.get(hashId); - if (bytes != null) { - data = deserializeSavedPersistentData(bytes); - havePersistentData = true; + if (!myContents.isBusyReading()) { + ByteSequence bytes = myContents.get(hashId); + if (bytes != null) { + data = deserializeSavedPersistentData(bytes); + havePersistentData = true; + } + } else { + skippedReadingPersistentDataButMayHaveIt = true; } } else { havePersistentData = myContents.containsMapping(hashId); @@ -333,7 +338,7 @@ public class MapReduceIndex implements UpdatableIndexemptyMap(); if (hashId != null && !havePersistentData) { - savePersistentData(data, hashId); + savePersistentData(data, hashId, skippedReadingPersistentDataButMayHaveIt); } ProgressManager.checkCanceled(); @@ -448,8 +453,9 @@ public class MapReduceIndex implements UpdatableIndex data, int id) { + private void savePersistentData(Map data, int id, boolean delayedReading) { try { + if (delayedReading && myContents.containsMapping(id)) return; BufferExposingByteArrayOutputStream out = new BufferExposingByteArrayOutputStream(ourSpareByteArray.getBuffer(4 * data.size())); DataOutputStream stream = new DataOutputStream(out); int size = data.size(); diff --git a/platform/util/src/com/intellij/util/io/PersistentHashMap.java b/platform/util/src/com/intellij/util/io/PersistentHashMap.java index 39370d336192..de43fbd11b1b 100644 --- a/platform/util/src/com/intellij/util/io/PersistentHashMap.java +++ b/platform/util/src/com/intellij/util/io/PersistentHashMap.java @@ -81,6 +81,7 @@ public class PersistentHashMap extends PersistentEnumeratorDelegate< private int myLargeIndexWatermarkId; // starting with this id we store offset in adjacent file in long format private boolean myIntAddressForNewRecord; private static final boolean doHardConsistencyChecks = true; + private volatile boolean myBusyReading; private static class AppendStream extends DataOutputStream { private AppendStream() { @@ -445,10 +446,19 @@ public class PersistentHashMap extends PersistentEnumeratorDelegate< @Override public final Value get(Key key) throws IOException { synchronized (myEnumerator) { - return doGet(key); + myBusyReading = true; + try { + return doGet(key); + } finally { + myBusyReading = false; + } } } + public boolean isBusyReading() { + return myBusyReading; + } + @Nullable protected Value doGet(Key key) throws IOException { final long valueOffset; @@ -523,7 +533,6 @@ public class PersistentHashMap extends PersistentEnumeratorDelegate< try { myAppendCache.remove(key); if (myDirectlyStoreLongFileOffsetMode) { - if (myIntMapping) return true; return ((PersistentBTreeEnumerator)myEnumerator).getNonnegativeValue(key) != NULL_ADDR; } else { final int id = tryEnumerate(key);