index: remove nested index access exception since it's allowed for now (all indexes has their own locks)

GitOrigin-RevId: 67fc062cb0c1554a7929d36869f804edab8cd4bd
This commit is contained in:
Dmitry Batkovich
2022-11-14 23:10:52 +00:00
committed by intellij-monorepo-bot
parent c7ccd35a26
commit 1c1556d3d2
3 changed files with 7 additions and 78 deletions
@@ -17,7 +17,6 @@ import com.intellij.psi.util.CachedValueProvider;
import com.intellij.util.*;
import com.intellij.util.containers.FactoryMap;
import com.intellij.util.indexing.*;
import com.intellij.util.indexing.diagnostic.IndexAccessValidator;
import com.intellij.util.indexing.impl.AbstractUpdateData;
import com.intellij.util.indexing.impl.KeyValueUpdateProcessor;
import com.intellij.util.indexing.impl.RemovedKeyProcessor;
@@ -60,7 +59,6 @@ public abstract class StubIndexEx extends StubIndex {
}, ConcurrentHashMap::new);
private final StubProcessingHelper myStubProcessingHelper = new StubProcessingHelper();
private final IndexAccessValidator myAccessValidator = new IndexAccessValidator();
@ApiStatus.Internal
abstract void initializeStubIndexes();
@@ -312,10 +310,7 @@ public abstract class StubIndexEx extends StubIndex {
try {
@Nullable IdFilter finalIdFilter = idFilter;
return myAccessValidator.validate(StubUpdatingIndex.INDEX_ID, () -> FileBasedIndexEx.disableUpToDateCheckIn(() ->
index.processAllKeys(
processor, scope,
finalIdFilter)));
return FileBasedIndexEx.disableUpToDateCheckIn(() -> index.processAllKeys(processor, scope, finalIdFilter));
}
catch (StorageException e) {
forceRebuild(e);
@@ -413,12 +408,9 @@ public abstract class StubIndexEx extends StubIndex {
return true;
}
};
myAccessValidator.validate(stubUpdatingIndexId, () -> {
trace.totalKeysIndexed(MeasurableIndexStore.keysCountApproximatelyIfPossible(index));
// disable up-to-date check to avoid locks on attempt to acquire index write lock while holding at the same time the readLock for this index
return FileBasedIndexEx.disableUpToDateCheckIn(() -> ConcurrencyUtil.withLock(
stubUpdatingIndex.getLock().readLock(), () -> index.getData(dataKey).forEach(action)));
});
trace.totalKeysIndexed(MeasurableIndexStore.keysCountApproximatelyIfPossible(index));
// disable up-to-date check to avoid locks on attempt to acquire index write lock while holding at the same time the readLock for this index
FileBasedIndexEx.disableUpToDateCheckIn(() -> ConcurrencyUtil.withLock(stubUpdatingIndex.getLock().readLock(), () -> index.getData(dataKey).forEach(action)));
return action.result == null ? IntSets.EMPTY_SET : action.result;
}
catch (StorageException e) {
@@ -33,7 +33,6 @@ import com.intellij.psi.util.PsiModificationTracker;
import com.intellij.util.*;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.Stack;
import com.intellij.util.indexing.diagnostic.IndexAccessValidator;
import com.intellij.util.indexing.impl.IndexDebugProperties;
import com.intellij.util.indexing.impl.InvertedIndexValueIterator;
import com.intellij.util.indexing.impl.MapReduceIndexMappingException;
@@ -63,7 +62,6 @@ public abstract class FileBasedIndexEx extends FileBasedIndex {
private static final ThreadLocal<Stack<DumbModeAccessType>> ourDumbModeAccessTypeStack =
ThreadLocal.withInitial(() -> new com.intellij.util.containers.Stack<>());
private static final RecursionGuard<Object> ourIgnoranceGuard = RecursionManager.createGuard("ignoreDumbMode");
private final IndexAccessValidator myAccessValidator = new IndexAccessValidator();
private volatile boolean myTraceIndexUpdates;
private volatile boolean myTraceStubIndexUpdates;
private volatile boolean myTraceSharedIndexUpdates;
@@ -172,12 +170,8 @@ public abstract class FileBasedIndexEx extends FileBasedIndex {
trace.indexValidationFinished();
IdFilter idFilterAdjusted = idFilter == null ? extractIdFilter(scope, scope.getProject()) : idFilter;
Boolean validated = myAccessValidator.validate(indexId, () -> {
trace.totalKeysIndexed(keysCountApproximatelyIfPossible(index));
return index.processAllKeys(processor, scope, idFilterAdjusted);
});
return validated;
trace.totalKeysIndexed(keysCountApproximatelyIfPossible(index));
return index.processAllKeys(processor, scope, idFilterAdjusted);
}
catch (StorageException e) {
trace.lookupFailed();
@@ -325,12 +319,7 @@ public abstract class FileBasedIndexEx extends FileBasedIndex {
TRACE_OF_ENTRIES_LOOKUP.get()
.indexValidationFinished();
final R validated = myAccessValidator.validate(
indexId,
() -> ConcurrencyUtil.withLock(index.getLock().readLock(), () -> computable.convert(index))
);
return validated;
return ConcurrencyUtil.withLock(index.getLock().readLock(), () -> computable.convert(index));
}
catch (StorageException e) {
TRACE_OF_ENTRIES_LOOKUP.get().lookupFailed();
@@ -1,52 +0,0 @@
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.util.indexing.diagnostic;
import com.intellij.diagnostic.PluginException;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.extensions.PluginId;
import com.intellij.openapi.util.ThrowableComputable;
import com.intellij.util.indexing.FileBasedIndex;
import com.intellij.util.indexing.FileBasedIndexEx;
import com.intellij.util.indexing.ID;
import org.jetbrains.annotations.NotNull;
import java.text.MessageFormat;
public final class IndexAccessValidator {
private final ThreadLocal<ID<?, ?>> ourAlreadyProcessingIndices = new ThreadLocal<>();
private void checkAccessingIndexDuringOtherIndexProcessing(@NotNull ID<?, ?> indexKey) {
ID<?, ?> alreadyProcessingIndex = ourAlreadyProcessingIndices.get();
if (alreadyProcessingIndex == null || alreadyProcessingIndex == indexKey) {
return;
}
String message = MessageFormat.format("Accessing ''{0}'' during processing ''{1}''. Nested different indices processing may cause deadlock",
indexKey.getName(),
alreadyProcessingIndex.getName());
PluginId alreadyProcessingIndexOwner = alreadyProcessingIndex.getPluginId();
PluginException exception = new PluginException(message, alreadyProcessingIndexOwner);
if (ApplicationManager.getApplication().isUnitTestMode()) {
throw exception;
}
((FileBasedIndexEx)FileBasedIndex.getInstance()).getLogger().error(exception); // RuntimeException to skip rebuild
}
/**
* Ensures no nested index access in a current thread -- i.e. throws or logs {@link PluginException} if other index is
* already accessed now.
*/
public <T, E extends Throwable> T validate(@NotNull ID<?, ?> indexKey, @NotNull ThrowableComputable<T, E> runnable) throws E {
checkAccessingIndexDuringOtherIndexProcessing(indexKey);
ourAlreadyProcessingIndices.set(indexKey);
try {
return runnable.compute();
}
finally {
ourAlreadyProcessingIndices.set(null);
}
}
}