diff --git a/platform/indexing-impl/src/com/intellij/psi/stubs/StubIndexEx.java b/platform/indexing-impl/src/com/intellij/psi/stubs/StubIndexEx.java index 7ddbaa88f5dd..45e3f8a9537c 100644 --- a/platform/indexing-impl/src/com/intellij/psi/stubs/StubIndexEx.java +++ b/platform/indexing-impl/src/com/intellij/psi/stubs/StubIndexEx.java @@ -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) { diff --git a/platform/indexing-impl/src/com/intellij/util/indexing/FileBasedIndexEx.java b/platform/indexing-impl/src/com/intellij/util/indexing/FileBasedIndexEx.java index 137c8f78567d..dbb8d5edc965 100644 --- a/platform/indexing-impl/src/com/intellij/util/indexing/FileBasedIndexEx.java +++ b/platform/indexing-impl/src/com/intellij/util/indexing/FileBasedIndexEx.java @@ -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> ourDumbModeAccessTypeStack = ThreadLocal.withInitial(() -> new com.intellij.util.containers.Stack<>()); private static final RecursionGuard 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(); diff --git a/platform/indexing-impl/src/com/intellij/util/indexing/diagnostic/IndexAccessValidator.java b/platform/indexing-impl/src/com/intellij/util/indexing/diagnostic/IndexAccessValidator.java deleted file mode 100644 index a208d354c7a5..000000000000 --- a/platform/indexing-impl/src/com/intellij/util/indexing/diagnostic/IndexAccessValidator.java +++ /dev/null @@ -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> 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 validate(@NotNull ID indexKey, @NotNull ThrowableComputable runnable) throws E { - checkAccessingIndexDuringOtherIndexProcessing(indexKey); - ourAlreadyProcessingIndices.set(indexKey); - try { - return runnable.compute(); - } - finally { - ourAlreadyProcessingIndices.set(null); - } - } -}