diff --git a/java/execution/impl/src/com/intellij/execution/testDiscovery/indices/DiscoveredTestDataHolder.java b/java/execution/impl/src/com/intellij/execution/testDiscovery/indices/DiscoveredTestDataHolder.java index 3839a0d0a649..7fd99220078a 100644 --- a/java/execution/impl/src/com/intellij/execution/testDiscovery/indices/DiscoveredTestDataHolder.java +++ b/java/execution/impl/src/com/intellij/execution/testDiscovery/indices/DiscoveredTestDataHolder.java @@ -162,7 +162,7 @@ public final class DiscoveredTestDataHolder { public void removeTestTrace(@NotNull String testClassName, @NotNull String testMethodName, byte frameworkId) throws IOException { int testId = myTestEnumerator.tryEnumerate(createTestId(testClassName, testMethodName, frameworkId)); if (testId != 0) { - myDiscoveredTestsIndex.updateImmediately(testId, null); + myDiscoveredTestsIndex.update(testId, null); myTestModuleIndex.removeTest(testId); } } @@ -202,8 +202,8 @@ public final class DiscoveredTestDataHolder { } UsedSources usedSources = new UsedSources(result, usedVirtualFileIds); - myDiscoveredTestsIndex.updateImmediately(testNameId, usedSources); - myTestFilesIndex.updateImmediately(testNameId, usedSources); + myDiscoveredTestsIndex.update(testNameId, usedSources); + myTestFilesIndex.update(testNameId, usedSources); myTestModuleIndex.appendModuleData(testNameId, moduleName); } diff --git a/java/java-tests/testSrc/com/intellij/java/index/StringIndex.java b/java/java-tests/testSrc/com/intellij/java/index/StringIndex.java index c404bc9bd4f9..3bf2129a3657 100644 --- a/java/java-tests/testSrc/com/intellij/java/index/StringIndex.java +++ b/java/java-tests/testSrc/com/intellij/java/index/StringIndex.java @@ -130,7 +130,7 @@ public class StringIndex { } public boolean update(final String path, @Nullable String content, @Nullable String oldContent) { - return myIndex.updateImmediately(MathUtil.nonNegativeAbs(path.hashCode()), toInput(path, content)); + return myIndex.update(MathUtil.nonNegativeAbs(path.hashCode()), toInput(path, content)); } public long getModificationStamp() { diff --git a/jps/jps-builders/src/org/jetbrains/jps/backwardRefs/CompilerReferenceWriter.java b/jps/jps-builders/src/org/jetbrains/jps/backwardRefs/CompilerReferenceWriter.java index c3ebb23632bd..7b7d60c1f472 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/backwardRefs/CompilerReferenceWriter.java +++ b/jps/jps-builders/src/org/jetbrains/jps/backwardRefs/CompilerReferenceWriter.java @@ -17,7 +17,7 @@ public class CompilerReferenceWriter { public void writeData(int id, Input d) { for (InvertedIndex index : myIndex.getIndices()) { - index.updateImmediately(id, d); + index.update(id, d); } } diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java index d20fedd7b1e5..6b9d2ee251da 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java @@ -804,14 +804,7 @@ public final class FileBasedIndexImpl extends FileBasedIndexEx { // avoid rebuilding index in tests since we do it synchronously in requestRebuild and we can have readAction at hand return null; } - if (e instanceof ProcessCanceledException) { - return null; - } - if (e instanceof MapReduceIndex.MapInputException) { - // If exception has happened on input mapping (DataIndexer.map), - // it is handled as the indexer exception and must not lead to index rebuild. - return null; - } + if (e instanceof ProcessCanceledException) return null; if (e instanceof IndexOutOfBoundsException) return e; // something wrong with direct byte buffer Throwable cause = e.getCause(); if (cause instanceof StorageException @@ -981,7 +974,7 @@ public final class FileBasedIndexImpl extends FileBasedIndexEx { markFileIndexed(vFile); try { - getIndex(requestedIndexId).updateImmediately(inputId, newFc); + getIndex(requestedIndexId).update(inputId, newFc); } finally { unmarkBeingIndexed(); @@ -989,7 +982,7 @@ public final class FileBasedIndexImpl extends FileBasedIndexEx { } } else { // effectively wipe the data from the indices - getIndex(requestedIndexId).updateImmediately(inputId, null); + getIndex(requestedIndexId).update(inputId, null); } } @@ -1290,12 +1283,9 @@ public final class FileBasedIndexImpl extends FileBasedIndexEx { final UpdatableIndex index = getIndex(indexId); assert index != null; - // Propagate MapReduceIndex.MapInputException and ProcessCancelledException happening on input mapping. - Computable finalUpdate = index.mapInputAndThenUpdate(inputId, currentFC); - markFileIndexed(file); try { - if (myStorageBufferingHandler.runUpdate(false, finalUpdate)) { + if (myStorageBufferingHandler.runUpdate(false, () -> index.update(inputId, currentFC))) { ConcurrencyUtil.withLock(myReadLock, () -> { if (currentFC != null) { index.setIndexedStateForFile(inputId, currentFC); @@ -1306,6 +1296,11 @@ public final class FileBasedIndexImpl extends FileBasedIndexEx { }); } } + catch (MapReduceIndex.MapInputException e) { + // If exception has happened on input mapping (DataIndexer.map), + // it is handled as indexer exception and does not lead to index rebuild. + throw e; + } catch (RuntimeException exception) { Throwable causeToRebuildIndex = getCauseToRebuildIndex(exception); if (causeToRebuildIndex != null) { diff --git a/platform/util/src/com/intellij/util/indexing/InvertedIndex.java b/platform/util/src/com/intellij/util/indexing/InvertedIndex.java index cbd4352cd33f..db1ec2f019db 100644 --- a/platform/util/src/com/intellij/util/indexing/InvertedIndex.java +++ b/platform/util/src/com/intellij/util/indexing/InvertedIndex.java @@ -16,7 +16,6 @@ package com.intellij.util.indexing; -import com.intellij.openapi.util.Computable; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -28,18 +27,12 @@ public interface InvertedIndex { ValueContainer getData(@NotNull Key key) throws StorageException; /** - * Calls {@link #mapInputAndThenUpdate(int, Object)} and updates immediately. + * Update the current index with the given content. + * + * @param inputId *positive* id of content. + * @return true if success, false if error occurred. */ - default boolean updateImmediately(int inputId, @Nullable Input content) { - return mapInputAndThenUpdate(inputId, content).compute(); - } - - /** - * Maps input as the first stage and returns a computation that does actual index data structure update. - * It may be used to separate long-running input mapping from update IO writing. - */ - @NotNull - Computable mapInputAndThenUpdate(int inputId, @Nullable Input content); + boolean update(int inputId, @Nullable Input content); void flush() throws StorageException; diff --git a/platform/util/src/com/intellij/util/indexing/impl/MapReduceIndex.java b/platform/util/src/com/intellij/util/indexing/impl/MapReduceIndex.java index 781189c2aa6c..c344d7f7409c 100644 --- a/platform/util/src/com/intellij/util/indexing/impl/MapReduceIndex.java +++ b/platform/util/src/com/intellij/util/indexing/impl/MapReduceIndex.java @@ -18,7 +18,6 @@ package com.intellij.util.indexing.impl; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.util.Comparing; -import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.LowMemoryWatcher; import com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream; import com.intellij.util.indexing.*; @@ -219,34 +218,38 @@ public abstract class MapReduceIndex implements InvertedIndex< } @Override - public final @NotNull Computable mapInputAndThenUpdate(int inputId, @Nullable Input content) throws MapInputException, ProcessCanceledException { - InputData data = mapInput(inputId, content); + public final boolean update(int inputId, @Nullable Input content) { + final InputData data; + try { + data = mapInput(inputId, content); + } + catch (ProcessCanceledException e) { + throw e; + } + catch (Exception e) { + throw new MapInputException("Failed to map data for input " + inputId, e); + } - UpdateData updateData = new UpdateData<>( - inputId, - data.getKeyValues(), - () -> getKeysDiffBuilder(inputId), - myIndexId, - () -> updateForwardIndex(inputId, data) - ); - - return () -> { - try { - updateWithMap(updateData); + try { + updateWithMap(new UpdateData<>( + inputId, + data.getKeyValues(), + () -> getKeysDiffBuilder(inputId), + myIndexId, () -> updateForwardIndex(inputId, data)) + ); + } + catch (StorageException | ProcessCanceledException ex) { + String message = "An exception during updateWithMap(). Index " + myIndexId.getName() + " will be rebuilt."; + //noinspection InstanceofCatchParameter + if (ex instanceof ProcessCanceledException) { + LOG.error(message, ex); + } else { + LOG.info(message, ex); } - catch (StorageException | ProcessCanceledException ex) { - String message = "An exception during updateWithMap(). Index " + myIndexId.getName() + " will be rebuilt."; - //noinspection InstanceofCatchParameter - if (ex instanceof ProcessCanceledException) { - LOG.error(message, ex); - } else { - LOG.info(message, ex); - } - requestRebuild(ex); - return false; - } - return true; - }; + requestRebuild(ex); + return false; + } + return true; } public static final class MapInputException extends RuntimeException { @@ -290,15 +293,7 @@ public abstract class MapReduceIndex implements InvertedIndex< @NotNull protected Map mapByIndexer(int inputId, @NotNull Input content) { - try { - return myIndexer.map(content); - } - catch (ProcessCanceledException e) { - throw e; - } - catch (Exception e) { - throw new MapInputException("Failed to map data for input " + inputId, e); - } + return myIndexer.map(content); } public abstract void checkCanceled(); diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogFullDetailsIndex.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogFullDetailsIndex.java index 7cd335a5cdef..d54c5435e806 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogFullDetailsIndex.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogFullDetailsIndex.java @@ -129,7 +129,7 @@ public class VcsLogFullDetailsIndex implements Disposable { public void update(int commitId, @NotNull D details) { checkDisposed(); - myMapReduceIndex.updateImmediately(commitId, details); + myMapReduceIndex.update(commitId, details); } public void flush() throws StorageException {