get rid of guava api in stub indexes update

GitOrigin-RevId: ff3a67dde9c3fbe13b70d3d778508fbfb4c02b68
This commit is contained in:
Dmitry Batkovich
2019-10-03 13:33:32 +00:00
committed by intellij-monorepo-bot
parent 03c7cd8cde
commit a33abd921b
8 changed files with 77 additions and 33 deletions
@@ -13,6 +13,7 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.extensions.impl.ExtensionPointImpl;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.ModificationTracker;
import com.intellij.openapi.util.ThrowableComputable;
import com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream;
@@ -35,9 +36,7 @@ import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.FactoryMap;
import com.intellij.util.indexing.*;
import com.intellij.util.indexing.hash.MergedInvertedIndex;
import com.intellij.util.indexing.impl.InputDataDiffBuilder;
import com.intellij.util.indexing.impl.MapInputDataDiffBuilder;
import com.intellij.util.indexing.impl.UpdateData;
import com.intellij.util.indexing.impl.*;
import com.intellij.util.indexing.provided.ProvidedIndexExtension;
import com.intellij.util.io.*;
import com.intellij.util.io.DataOutputStream;
@@ -682,13 +681,35 @@ public final class StubIndexImpl extends StubIndex implements PersistentStateCom
try {
final UpdatableIndex<K, Void, FileContent> index = getIndex(key);
if (index == null) return;
index.updateWithMap(new AbstractUpdateData<K, Void>(fileId) {
@Override
protected boolean iterateKeys(@NotNull KeyValueUpdateProcessor<? super K, ? super Void> addProcessor,
@NotNull KeyValueUpdateProcessor<? super K, ? super Void> updateProcessor,
@NotNull RemovedKeyProcessor<? super K> removeProcessor) throws StorageException {
boolean modified = false;
Map<K, Void> oldKeys = Maps.asMap(oldInputData.keySet(), x -> null);
Map<K, Void> newKeys = Maps.asMap(newInputData.keySet(), x -> null);
for (K oldKey : oldInputData.keySet()) {
if (!newInputData.containsKey(oldKey)) {
removeProcessor.process(oldKey, fileId);
if (!modified) modified = true;
}
}
final ThrowableComputable<InputDataDiffBuilder<K, Void>, IOException>
oldMapGetter = () -> new MapInputDataDiffBuilder<>(fileId, oldKeys);
index.updateWithMap(new UpdateData<K, Void>(fileId, newKeys, oldMapGetter, (IndexId)key, null));
for (K oldKey : newInputData.keySet()) {
if (!oldInputData.containsKey(oldKey)) {
addProcessor.process(oldKey, null, fileId);
if (!modified) modified = true;
}
}
return modified;
}
@Override
public boolean newDataIsEmpty() {
return newInputData.isEmpty();
}
});
}
catch (StorageException e) {
LOG.info(e);
@@ -19,6 +19,7 @@ package com.intellij.util.indexing;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.util.Processor;
import com.intellij.util.indexing.impl.AbstractUpdateData;
import com.intellij.util.indexing.impl.UpdateData;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -62,7 +63,7 @@ public interface UpdatableIndex<Key, Value, Input> extends InvertedIndex<Key,Val
@NotNull
IndexExtension<Key, Value, Input> getExtension();
void updateWithMap(@NotNull UpdateData<Key, Value> updateData) throws StorageException;
void updateWithMap(@NotNull AbstractUpdateData<Key, Value> updateData) throws StorageException;
void setBufferingEnabled(boolean enabled);
@@ -225,6 +225,7 @@ public class VfsAwareMapReduceIndex<Key, Value, Input> extends MapReduceIndex<Ke
}
}
@Override
public void setBufferingEnabled(boolean enabled) {
((MemoryIndexStorage)getStorage()).setBufferingEnabled(enabled);
@@ -4,9 +4,8 @@ package com.intellij.util.indexing.hash;
import com.intellij.openapi.util.Computable;
import com.intellij.util.IntIntFunction;
import com.intellij.util.indexing.*;
import com.intellij.util.indexing.impl.AbstractUpdateData;
import com.intellij.util.indexing.impl.IndexStorage;
import com.intellij.util.indexing.impl.MapIndexStorage;
import com.intellij.util.indexing.impl.UpdateData;
import com.intellij.util.indexing.impl.forward.MapForwardIndexAccessor;
import com.intellij.util.indexing.impl.forward.PersistentMapBasedForwardIndex;
import org.jetbrains.annotations.NotNull;
@@ -24,8 +23,8 @@ public class FileContentHashIndex extends VfsAwareMapReduceIndex<Integer, Void,
@NotNull
@Override
protected Computable<Boolean> createIndexUpdateComputation(@NotNull UpdateData<Integer, Void> updateData) {
return new HashIndexUpdateComputable(super.createIndexUpdateComputation(updateData), updateData.getNewData().isEmpty());
protected Computable<Boolean> createIndexUpdateComputation(@NotNull AbstractUpdateData<Integer, Void> updateData) {
return new HashIndexUpdateComputable(super.createIndexUpdateComputation(updateData), updateData.newDataIsEmpty());
}
public int getHashId(int fileId) throws StorageException {
@@ -6,6 +6,7 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.util.Processor;
import com.intellij.util.indexing.*;
import com.intellij.util.indexing.impl.AbstractUpdateData;
import com.intellij.util.indexing.impl.UpdateData;
import com.intellij.util.indexing.provided.ProvidedIndexExtension;
import org.jetbrains.annotations.NotNull;
@@ -64,7 +65,7 @@ public class MergedInvertedIndex<Key, Value> implements UpdatableIndex<Key, Valu
@Override
public void updateWithMap(@NotNull UpdateData<Key, Value> updateData) throws StorageException {
public void updateWithMap(@NotNull AbstractUpdateData<Key, Value> updateData) throws StorageException {
int fileId = updateData.getInputId();
if (myHashIndex.getHashId(fileId) != 0) {
return;
@@ -0,0 +1,26 @@
// Copyright 2000-2019 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.impl;
import com.intellij.util.indexing.StorageException;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
public abstract class AbstractUpdateData<Key, Value> {
private final int myInputId;
protected AbstractUpdateData(int id) {myInputId = id;}
protected abstract boolean iterateKeys(@NotNull KeyValueUpdateProcessor<? super Key, ? super Value> addProcessor,
@NotNull KeyValueUpdateProcessor<? super Key, ? super Value> updateProcessor,
@NotNull RemovedKeyProcessor<? super Key> removeProcessor) throws StorageException;
public abstract boolean newDataIsEmpty();
public int getInputId() {
return myInputId;
}
protected void updateForwardIndex() throws IOException { }
}
@@ -30,7 +30,6 @@ import com.intellij.util.indexing.impl.forward.IntForwardIndex;
import com.intellij.util.indexing.impl.forward.IntForwardIndexAccessor;
import com.intellij.util.io.DataExternalizer;
import com.intellij.util.io.DataOutputStream;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -241,7 +240,7 @@ public abstract class MapReduceIndex<Key,Value, Input> implements InvertedIndex<
}
@NotNull
protected Computable<Boolean> createIndexUpdateComputation(@NotNull UpdateData<Key, Value> updateData) {
protected Computable<Boolean> createIndexUpdateComputation(@NotNull AbstractUpdateData<Key, Value> updateData) {
return () -> {
try {
updateWithMap(updateData);
@@ -346,7 +345,7 @@ public abstract class MapReduceIndex<Key,Value, Input> implements InvertedIndex<
}
};
public void updateWithMap(@NotNull UpdateData<Key, Value> updateData) throws StorageException {
public void updateWithMap(@NotNull AbstractUpdateData<Key, Value> updateData) throws StorageException {
getWriteLock().lock();
try {
IndexId oldIndexId = DebugAssertions.DEBUG_INDEX_ID.get();
@@ -27,8 +27,7 @@ import java.io.IOException;
import java.util.Map;
@ApiStatus.Experimental
public class UpdateData<Key, Value> {
private final int myInputId;
public class UpdateData<Key, Value> extends AbstractUpdateData<Key, Value> {
private final Map<Key, Value> myNewData;
private final ThrowableComputable<InputDataDiffBuilder<Key, Value>, IOException> myCurrentDataEvaluator;
private final IndexId<Key, Value> myIndexId;
@@ -39,16 +38,16 @@ public class UpdateData<Key, Value> {
@NotNull ThrowableComputable<InputDataDiffBuilder<Key, Value>, IOException> currentDataEvaluator,
@NotNull IndexId<Key, Value> indexId,
@Nullable ThrowableRunnable<? extends IOException> forwardIndexUpdate) {
myInputId = inputId;
super(inputId);
myNewData = newData;
myCurrentDataEvaluator = currentDataEvaluator;
myIndexId = indexId;
myForwardIndexUpdate = forwardIndexUpdate;
}
boolean iterateKeys(@NotNull KeyValueUpdateProcessor<? super Key, ? super Value> addProcessor,
@NotNull KeyValueUpdateProcessor<? super Key, ? super Value> updateProcessor,
@NotNull RemovedKeyProcessor<? super Key> removeProcessor) throws StorageException {
protected boolean iterateKeys(@NotNull KeyValueUpdateProcessor<? super Key, ? super Value> addProcessor,
@NotNull KeyValueUpdateProcessor<? super Key, ? super Value> updateProcessor,
@NotNull RemovedKeyProcessor<? super Key> removeProcessor) throws StorageException {
final InputDataDiffBuilder<Key, Value> currentData;
try {
currentData = getCurrentDataEvaluator().compute();
@@ -59,26 +58,23 @@ public class UpdateData<Key, Value> {
return currentData.differentiate(myNewData, addProcessor, updateProcessor, removeProcessor);
}
@Override
public boolean newDataIsEmpty() {
return myNewData.isEmpty();
}
@NotNull
protected ThrowableComputable<InputDataDiffBuilder<Key, Value>, IOException> getCurrentDataEvaluator() {
return myCurrentDataEvaluator;
}
public int getInputId() {
return myInputId;
}
@NotNull
public Map<Key, Value> getNewData() {
return myNewData;
}
@NotNull
public IndexId<Key, Value> getIndexId() {
return myIndexId;
}
void updateForwardIndex() throws IOException {
@Override
protected void updateForwardIndex() throws IOException {
if (myForwardIndexUpdate != null) {
myForwardIndexUpdate.run();
}