reliably save persistent index stamp between IDE sessions (IDEA-194315)

In particular use saved persistent index stamp when invalidate caches was requested and vfs survives the invalidation
This commit is contained in:
Maxim.Mossienko
2018-07-06 08:54:09 +02:00
parent b9b71c6717
commit fd0d9a16f3
3 changed files with 53 additions and 1 deletions
@@ -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);
}
}
@@ -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 {
@@ -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");
}
}