mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Revert "Indexes: revert "first — map, second — update data structure" for MapReduceIndex."
This reverts commit 83350764 GitOrigin-RevId: 249bf20b15f69102d835c5351001983d98806d34
This commit is contained in:
committed by
intellij-monorepo-bot
parent
ded42d0313
commit
882a041682
+3
-3
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -17,7 +17,7 @@ public class CompilerReferenceWriter<Input> {
|
||||
|
||||
public void writeData(int id, Input d) {
|
||||
for (InvertedIndex<?, ?, Input> index : myIndex.getIndices()) {
|
||||
index.updateImmediately(id, d);
|
||||
index.update(id, d);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<?, ?, FileContent> index = getIndex(indexId);
|
||||
assert index != null;
|
||||
|
||||
// Propagate MapReduceIndex.MapInputException and ProcessCancelledException happening on input mapping.
|
||||
Computable<Boolean> 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) {
|
||||
|
||||
@@ -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<Key, Value, Input> {
|
||||
ValueContainer<Value> 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<Boolean> mapInputAndThenUpdate(int inputId, @Nullable Input content);
|
||||
boolean update(int inputId, @Nullable Input content);
|
||||
|
||||
void flush() throws StorageException;
|
||||
|
||||
|
||||
@@ -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<Key,Value, Input> implements InvertedIndex<
|
||||
}
|
||||
|
||||
@Override
|
||||
public final @NotNull Computable<Boolean> mapInputAndThenUpdate(int inputId, @Nullable Input content) throws MapInputException, ProcessCanceledException {
|
||||
InputData<Key, Value> data = mapInput(inputId, content);
|
||||
public final boolean update(int inputId, @Nullable Input content) {
|
||||
final InputData<Key, Value> 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<Key, Value> 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<Key,Value, Input> implements InvertedIndex<
|
||||
|
||||
@NotNull
|
||||
protected Map<Key, Value> 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();
|
||||
|
||||
+1
-1
@@ -129,7 +129,7 @@ public class VcsLogFullDetailsIndex<T, D> implements Disposable {
|
||||
|
||||
public void update(int commitId, @NotNull D details) {
|
||||
checkDisposed();
|
||||
myMapReduceIndex.updateImmediately(commitId, details);
|
||||
myMapReduceIndex.update(commitId, details);
|
||||
}
|
||||
|
||||
public void flush() throws StorageException {
|
||||
|
||||
Reference in New Issue
Block a user