From 13d2a109474a9f8b0df5f0a68a563ed59f84aeb7 Mon Sep 17 00:00:00 2001 From: Julia Beliaeva Date: Tue, 6 Sep 2016 19:27:48 +0300 Subject: [PATCH] [vcs-log] do not tolerate io errors from data indexer --- .../vcs/log/data/index/VcsLogPathsIndex.java | 16 ++++++++++++++-- .../log/data/index/VcsLogPersistentIndex.java | 4 ++-- .../vcs/log/data/index/VcsLogUserIndex.java | 14 +++++++++++++- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogPathsIndex.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogPathsIndex.java index 10967dd21d9c..b1ecd4f1ed67 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogPathsIndex.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogPathsIndex.java @@ -21,12 +21,14 @@ import com.intellij.openapi.util.Couple; import com.intellij.openapi.vcs.FilePath; import com.intellij.openapi.vcs.changes.Change; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.Consumer; import com.intellij.util.PathUtil; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.indexing.DataIndexer; import com.intellij.util.indexing.StorageException; import com.intellij.util.io.*; import com.intellij.vcs.log.VcsFullCommitDetails; +import com.intellij.vcs.log.impl.FatalErrorConsumer; import com.intellij.vcs.log.impl.VcsChangesLazilyParsedDetails; import com.intellij.vcs.log.util.PersistentUtil; import gnu.trove.THashMap; @@ -52,6 +54,7 @@ public class VcsLogPathsIndex extends VcsLogFullDetailsIndex { public VcsLogPathsIndex(@NotNull String logId, @NotNull Set roots, + @NotNull FatalErrorConsumer fatalErrorConsumer, @NotNull Disposable disposableParent) throws IOException { super(logId, NAME, VcsLogPersistentIndex.getVersion(), new PathsIndexer(createPathsEnumerator(logId), roots), new NullableIntKeyDescriptor(), disposableParent); @@ -59,6 +62,10 @@ public class VcsLogPathsIndex extends VcsLogFullDetailsIndex { myEmptyCommits = PersistentUtil.createPersistentHashMap(EnumeratorIntegerDescriptor.INSTANCE, "index-no-" + NAME, logId, VcsLogPersistentIndex.getVersion()); myPathsIndexer = (PathsIndexer)myIndexer; + myPathsIndexer.setFatalErrorConsumer(e -> { + fatalErrorConsumer.consume(this, e); + markCorrupted(); + }); } @NotNull @@ -158,12 +165,17 @@ public class VcsLogPathsIndex extends VcsLogFullDetailsIndex { private static class PathsIndexer implements DataIndexer { @NotNull private final PersistentEnumeratorBase myPathsEnumerator; @NotNull private final Set myRoots; + @NotNull private Consumer myFatalErrorConsumer = LOG::error; private PathsIndexer(@NotNull PersistentEnumeratorBase enumerator, @NotNull Set roots) { myPathsEnumerator = enumerator; myRoots = roots.stream().map(VirtualFile::getPath).collect(Collectors.toSet()); } + public void setFatalErrorConsumer(@NotNull Consumer fatalErrorConsumer) { + myFatalErrorConsumer = fatalErrorConsumer; + } + @NotNull @Override public Map map(@NotNull VcsFullCommitDetails inputData) { @@ -193,7 +205,7 @@ public class VcsLogPathsIndex extends VcsLogFullDetailsIndex { result.put(myPathsEnumerator.enumerate(changedPath), null); } catch (IOException e) { - LOG.error(e); + myFatalErrorConsumer.consume(e); } }); moves.forEach(renamedPaths -> { @@ -205,7 +217,7 @@ public class VcsLogPathsIndex extends VcsLogFullDetailsIndex { result.put(afterId, beforeId); } catch (IOException e) { - LOG.error(e); + myFatalErrorConsumer.consume(e); } }); diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogPersistentIndex.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogPersistentIndex.java index 8df25373bbc3..e9f2d678966b 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogPersistentIndex.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogPersistentIndex.java @@ -101,8 +101,8 @@ public class VcsLogPersistentIndex implements VcsLogIndex, Disposable { myMessagesIndex = createMap(EnumeratorStringDescriptor.INSTANCE, "messages", logId, 0); myTrigramIndex = createIndex(() -> new VcsLogMessagesTrigramIndex(logId, this)); - myUserIndex = createIndex(() -> new VcsLogUserIndex(logId, myUserRegistry, this)); - myPathsIndex = createIndex(() -> new VcsLogPathsIndex(logId, myRoots, this)); + myUserIndex = createIndex(() -> new VcsLogUserIndex(logId, myUserRegistry, fatalErrorsConsumer, this)); + myPathsIndex = createIndex(() -> new VcsLogPathsIndex(logId, myRoots, fatalErrorsConsumer, this)); for (VirtualFile root : myRoots) { myNumberOfTasks.put(root, new AtomicInteger()); diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogUserIndex.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogUserIndex.java index b249ab614d03..f7ed31cc5cd3 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogUserIndex.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogUserIndex.java @@ -17,6 +17,7 @@ package com.intellij.vcs.log.data.index; import com.intellij.openapi.Disposable; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.util.Consumer; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.indexing.DataIndexer; import com.intellij.util.indexing.ScalarIndexExtension; @@ -24,6 +25,7 @@ import com.intellij.util.indexing.StorageException; import com.intellij.vcs.log.VcsFullCommitDetails; import com.intellij.vcs.log.VcsUser; import com.intellij.vcs.log.data.VcsUserRegistryImpl; +import com.intellij.vcs.log.impl.FatalErrorConsumer; import gnu.trove.THashMap; import gnu.trove.TIntHashSet; import org.jetbrains.annotations.NotNull; @@ -38,10 +40,15 @@ public class VcsLogUserIndex extends VcsLogFullDetailsIndex { public VcsLogUserIndex(@NotNull String logId, @NotNull VcsUserRegistryImpl userRegistry, + @NotNull FatalErrorConsumer consumer, @NotNull Disposable disposableParent) throws IOException { super(logId, "users", VcsLogPersistentIndex.getVersion(), new UserIndexer(userRegistry), ScalarIndexExtension.VOID_DATA_EXTERNALIZER, disposableParent); myUserRegistry = userRegistry; + ((UserIndexer)myIndexer).setFatalErrorConsumer(e -> { + consumer.consume(this, e); + markCorrupted(); + }); } public TIntHashSet getCommitsForUsers(@NotNull Set users) throws IOException, StorageException { @@ -54,6 +61,7 @@ public class VcsLogUserIndex extends VcsLogFullDetailsIndex { private static class UserIndexer implements DataIndexer { @NotNull private final VcsUserRegistryImpl myRegistry; + @NotNull private Consumer myFatalErrorConsumer = LOG::error; public UserIndexer(@NotNull VcsUserRegistryImpl registry) { myRegistry = registry; @@ -68,10 +76,14 @@ public class VcsLogUserIndex extends VcsLogFullDetailsIndex { result.put(myRegistry.getUserId(inputData.getAuthor()), null); } catch (IOException e) { - LOG.error(e); + myFatalErrorConsumer.consume(e); } return result; } + + public void setFatalErrorConsumer(@NotNull Consumer fatalErrorConsumer) { + myFatalErrorConsumer = fatalErrorConsumer; + } } }