From c0550f78c38e21e6494d0f24fbb51533be03faa9 Mon Sep 17 00:00:00 2001 From: "Maxim.Mossienko" Date: Fri, 18 Apr 2014 23:56:29 +0200 Subject: [PATCH] save keys of particular snapshot before and out of index update optimistically load keys of particular snapshot before and out of index update --- .../util/indexing/MapReduceIndex.java | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 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 1405551207a5..77fded840d3d 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/MapReduceIndex.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/MapReduceIndex.java @@ -277,7 +277,7 @@ public class MapReduceIndex implements UpdatableIndex update(final int inputId, @Nullable final Input content) { + public final Computable update(final int inputId, @Nullable Input content) { final Map data = content != null ? myIndexer.map(content) : Collections.emptyMap(); @@ -287,23 +287,36 @@ public class MapReduceIndex implements UpdatableIndex>() { + try { // optimistically (out of index update write section) read current snapshot keys for file + final Integer hashId = myInputsSnapshotMapping.get(inputId); + final Collection keys = hashId != null ? mySnapshotMapping.get(hashId): null; + + oldKeysGetter = new NotNullComputable>() { @NotNull @Override public Collection compute() { - try { - Integer hashId = myInputsSnapshotMapping.get(inputId); - Collection keys = hashId != null ? mySnapshotMapping.get(hashId): null; - return keys == null ? Collections.emptyList() : keys; - } catch (IOException e) { - throw new RuntimeException(e); + try { + Integer currentHashId = myInputsSnapshotMapping.get(inputId); + Collection currentKeys; + if ((currentHashId == null && hashId == null) || (currentHashId != null && currentHashId.equals(hashId))) { + currentKeys = keys; + } else { // optimistic reading file's current keys failed + currentKeys = currentHashId != null ? mySnapshotMapping.get(currentHashId): null; + } + + return currentKeys == null ? Collections.emptyList() : currentKeys; + } catch (IOException e) { + throw new RuntimeException(e); + } } - } - }; - try { + }; + if (content instanceof FileContent) { FileContent fileContent = (FileContent)content; savedInputId = ContentHashesSupport.calcContentHashIdWithFileType(fileContent.getContent(), fileContent.getFileType()); + if (!mySnapshotMapping.containsMapping(savedInputId)) { // save current snapshot keys out of index update write section + mySnapshotMapping.put(savedInputId, data.keySet()); + } } else { savedInputId = NULL_MAPPING; } @@ -395,9 +408,6 @@ public class MapReduceIndex implements UpdatableIndex newKeys = newData.keySet();