From d3443e5f2b529bb6b4ccb69cd6bf1cab41fbadec Mon Sep 17 00:00:00 2001 From: Dmitry Batkovich Date: Fri, 29 Jan 2021 11:11:11 +0300 Subject: [PATCH] another attempt to enable stale index recovery IDEA-260427 GitOrigin-RevId: a1dd9e081502ecd9bbd28c4543d3d65302324ca8 --- .../FileBasedIndexDataInitialization.java | 4 +-- .../util/indexing/FileBasedIndexImpl.java | 28 +++++++++++++++++-- .../util/indexing/RegisteredIndexes.java | 1 + 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexDataInitialization.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexDataInitialization.java index ce0ec195dcef..544ed13bae42 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexDataInitialization.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexDataInitialization.java @@ -153,12 +153,10 @@ class FileBasedIndexDataInitialization extends IndexDataInitializer myProjectsBeingUpdated = ContainerUtil.newConcurrentSet(); + private final IntSet myStaleIds = new IntOpenHashSet(); private final Lock myReadLock; public final Lock myWriteLock; @@ -310,6 +309,12 @@ public final class FileBasedIndexImpl extends FileBasedIndexEx { } } + void addStaleIds(@NotNull IntSet staleIds) { + synchronized (myStaleIds) { + myStaleIds.addAll(staleIds); + } + } + static class MyShutDownTask implements Runnable { @Override public void run() { @@ -748,11 +753,28 @@ public final class FileBasedIndexImpl extends FileBasedIndexEx { } void filesUpdateStarted(Project project) { + ensureStaleIdsDeleted(); getChangedFilesCollector().ensureUpToDate(); myProjectsBeingUpdated.add(project); incrementFilesModCount(); } + void ensureStaleIdsDeleted() { + waitUntilIndicesAreInitialized(); + synchronized (myStaleIds) { + if (myStaleIds.isEmpty()) return; + try { + StaleIndexesChecker.clearStaleIndexes(myStaleIds); + } + catch (Exception e) { + LOG.error(e); + } + finally { + myStaleIds.clear(); + } + } + } + void filesUpdateFinished(@NotNull Project project) { myProjectsBeingUpdated.remove(project); incrementFilesModCount(); diff --git a/platform/lang-impl/src/com/intellij/util/indexing/RegisteredIndexes.java b/platform/lang-impl/src/com/intellij/util/indexing/RegisteredIndexes.java index c283be3dd21e..d07675e52fdd 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/RegisteredIndexes.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/RegisteredIndexes.java @@ -104,6 +104,7 @@ public final class RegisteredIndexes { void ensureLoadedIndexesUpToDate() { myAllIndicesInitializedFuture = IndexDataInitializer.submitGenesisTask(() -> { if (!myShutdownPerformed.get()) { + myFileBasedIndex.ensureStaleIdsDeleted(); myFileBasedIndex.getChangedFilesCollector().ensureUpToDateAsync(); } return null;