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 f85f279801b5..401ff0bae1f1 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java @@ -487,15 +487,16 @@ public final class FileBasedIndexImpl extends FileBasedIndexEx { @NotNull IndexConfiguration state, @NotNull IndexVersionRegistrationSink registrationStatusSink, @NotNull IntSet dirtyFiles) throws Exception { - ID name = extension.getName(); + ID indexId = extension.getName(); InputFilter inputFilter = extension.getInputFilter(); UpdatableIndex index = null; + VfsAwareIndexStorageLayout layout = null; int attemptCount = 2; for (int attempt = 0; attempt < attemptCount; attempt++) { try { - VfsAwareIndexStorageLayout layout = IndexStorageLayoutLocator.getLayout(extension); + layout = IndexStorageLayoutLocator.getLayout(extension); index = createIndex(extension, layout); for (FileBasedIndexInfrastructureExtension infrastructureExtension : FileBasedIndexInfrastructureExtension.EP_NAME.getExtensionList()) { @@ -505,38 +506,48 @@ public final class FileBasedIndexImpl extends FileBasedIndexEx { } } - state.registerIndex(name, + state.registerIndex(indexId, index, inputFilter, - version + GlobalIndexFilter.getFiltersVersion(name)); + version + GlobalIndexFilter.getFiltersVersion(indexId)); break; } catch (Exception e) { - boolean lastAttempt = attempt == attemptCount - 1; - + //close the (half-)opened index first: + if (index != null) { + try { + index.dispose(); + } + catch (Throwable t) { + LOG.error(t); + } + } try { - VfsAwareIndexStorageLayout layout = IndexStorageLayoutLocator.getLayout(extension); + if (layout == null) { + layout = IndexStorageLayoutLocator.getLayout(extension); + } layout.clearIndexData(); } - catch (Exception layoutEx) { - LOG.error(layoutEx); + catch (Throwable t) { + LOG.error(t); } for (FileBasedIndexInfrastructureExtension ext : FileBasedIndexInfrastructureExtension.EP_NAME.getExtensionList()) { try { - ext.resetPersistentState(name); + ext.resetPersistentState(indexId); } catch (Exception extEx) { LOG.error(extEx); } } - registrationStatusSink.setIndexVersionDiff(name, new IndexVersion.IndexVersionDiff.CorruptedRebuild(version)); - IndexVersion.rewriteVersion(name, version); - IndexStatisticGroup.reportIndexRebuild(name, e, true); + registrationStatusSink.setIndexVersionDiff(indexId, new IndexVersion.IndexVersionDiff.CorruptedRebuild(version)); + IndexVersion.rewriteVersion(indexId, version); + IndexStatisticGroup.reportIndexRebuild(indexId, e, true); + boolean lastAttempt = (attempt == attemptCount - 1); if (lastAttempt) { - state.registerIndexInitializationProblem(name, e); + state.registerIndexInitializationProblem(indexId, e); if (extension instanceof CustomImplementationFileBasedIndexExtension) { ((CustomImplementationFileBasedIndexExtension)extension).handleInitializationError(e); } @@ -1261,7 +1272,7 @@ public final class FileBasedIndexImpl extends FileBasedIndexEx { try { FileBasedIndex fileBasedIndex = app.getServiceIfCreated(FileBasedIndex.class); if (fileBasedIndex instanceof FileBasedIndexImpl fileBasedIndexImpl) { - if(calledByShutdownHook) { + if (calledByShutdownHook) { //prevent unregistering the task from ShutDownTracker if we're already called from ShutDownTracker: // (unregister fails if ShutDownTracker's executing is already triggered) fileBasedIndexImpl.myShutDownTask = null; diff --git a/platform/lang-impl/src/com/intellij/util/indexing/impl/storage/TransientFileContentIndex.java b/platform/lang-impl/src/com/intellij/util/indexing/impl/storage/TransientFileContentIndex.java index f2c4e7c2efa5..b56870b14839 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/impl/storage/TransientFileContentIndex.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/impl/storage/TransientFileContentIndex.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; +/** In-memory index, with persistent index as a 'backend' storage -- so it is not really 'transient' */ @Internal public class TransientFileContentIndex extends VfsAwareMapReduceIndex { @@ -44,6 +45,7 @@ public class TransientFileContentIndex { void clear() throws StorageException; + /** + * TODO RC: the interface doesn't extend {@link com.intellij.openapi.Disposable}, so the name is misleading -- the method is + * better renamed to .close() with interface extending (Auto){@link java.io.Closeable} + */ void dispose(); }