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 33c69a7b6b36..4f9e9bcb0d88 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java @@ -502,6 +502,8 @@ public class FileBasedIndexImpl extends FileBasedIndex implements BaseComponent, finally { LOG.info("START INDEX SHUTDOWN"); try { + PersistentIndicesConfiguration.saveConfiguration(); + for(VirtualFile file:myChangedFilesCollector.getAllFilesToUpdate()) { if (!file.isValid()) { removeDataFromIndicesForFile(Math.abs(getIdMaskingNonIdBasedFile(file)), file); @@ -2381,6 +2383,9 @@ public class FileBasedIndexImpl extends FileBasedIndex implements BaseComponent, protected void prepare() { mySerializationManagerEx = SerializationManagerEx.getInstanceEx(); File indexRoot = PathManager.getIndexRoot(); + + PersistentIndicesConfiguration.loadConfiguration(); + final File corruptionMarker = new File(indexRoot, CORRUPTION_MARKER_NAME); currentVersionCorrupted = IndexInfrastructure.hasIndices() && corruptionMarker.exists(); if (currentVersionCorrupted) { @@ -2389,6 +2394,7 @@ public class FileBasedIndexImpl extends FileBasedIndex implements BaseComponent, // serialization manager is initialized before and use removed index root so we need to reinitialize it mySerializationManagerEx.reinitializeNameStorage(); ID.reinitializeDiskStorage(); + PersistentIndicesConfiguration.saveConfiguration(); FileUtil.delete(corruptionMarker); } } diff --git a/platform/lang-impl/src/com/intellij/util/indexing/IndexingStamp.java b/platform/lang-impl/src/com/intellij/util/indexing/IndexingStamp.java index bb74b845118f..edd2fea2941f 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/IndexingStamp.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/IndexingStamp.java @@ -63,6 +63,14 @@ public class IndexingStamp { private IndexingStamp() {} + public static void initPersistentIndexStamp(DataInput in) throws IOException { + IndexVersion.advanceIndexStamp(DataInputOutputUtil.readTIME(in)); + } + + public static void savePersistentIndexStamp(DataOutput out) throws IOException { + DataInputOutputUtil.writeTIME(out, IndexVersion.ourLastStamp); + } + static class IndexVersion { private static volatile long ourLastStamp; // ensure any file index stamp increases final long myModificationCount; @@ -73,12 +81,16 @@ public class IndexingStamp { private IndexVersion(long modificationCount) { myModificationCount = modificationCount; + advanceIndexStamp(modificationCount); + } + + private static void advanceIndexStamp(long modificationCount) { ourLastStamp = Math.max(modificationCount, ourLastStamp); } public IndexVersion(DataInput in) throws IOException { myModificationCount = DataInputOutputUtil.readTIME(in); - ourLastStamp = Math.max(ourLastStamp, myModificationCount); + advanceIndexStamp(myModificationCount); } public void write(DataOutput os) throws IOException { diff --git a/platform/lang-impl/src/com/intellij/util/indexing/PersistentIndicesConfiguration.java b/platform/lang-impl/src/com/intellij/util/indexing/PersistentIndicesConfiguration.java new file mode 100644 index 000000000000..6bf1f1260631 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/util/indexing/PersistentIndicesConfiguration.java @@ -0,0 +1,34 @@ +// Copyright 2000-2018 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; + +import com.intellij.openapi.application.PathManager; +import com.intellij.util.io.DataInputOutputUtil; + +import java.io.*; + +class PersistentIndicesConfiguration { + private static final int INDICES_CONFIGURATION_VERSION = 1; + + static void saveConfiguration() { + try (DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(indicesConfigurationFile())))) { + DataInputOutputUtil.writeINT(out, INDICES_CONFIGURATION_VERSION); + IndexingStamp.savePersistentIndexStamp(out); + } + catch (IOException ignored) { + } + } + + static void loadConfiguration() { + try (DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(indicesConfigurationFile())))) { + if (DataInputOutputUtil.readINT(in) == INDICES_CONFIGURATION_VERSION) { + IndexingStamp.initPersistentIndexStamp(in); + } + } + catch (IOException ignored) { + } + } + + private static File indicesConfigurationFile() { + return new File(PathManager.getIndexRoot(), "indices.config"); + } +}