mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Revert "Extract appendDataWithoutCache method to the JPS specific collection"
This reverts commit 312ebc40 GitOrigin-RevId: 0f8b960da79d9edc0ad36b0179cdd861721b0a44
This commit is contained in:
committed by
intellij-monorepo-bot
parent
3fc5b36229
commit
4eebe5efca
+3
-3
@@ -6,11 +6,11 @@ import com.intellij.util.containers.SLRUCache;
|
||||
import com.intellij.util.io.DataExternalizer;
|
||||
import com.intellij.util.io.DataInputOutputUtil;
|
||||
import com.intellij.util.io.KeyDescriptor;
|
||||
import com.intellij.util.io.PersistentHashMap;
|
||||
import gnu.trove.TIntHashSet;
|
||||
import gnu.trove.TIntObjectProcedure;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.builders.storage.BuildDataCorruptedException;
|
||||
import org.jetbrains.jps.incremental.storage.JpsPersistentHashMap;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
@@ -20,11 +20,11 @@ import java.io.*;
|
||||
public class IntIntPersistentMultiMaplet extends IntIntMultiMaplet {
|
||||
private static final TIntHashSet NULL_COLLECTION = new TIntHashSet();
|
||||
private static final int CACHE_SIZE = 128;
|
||||
private final JpsPersistentHashMap<Integer, TIntHashSet> myMap;
|
||||
private final PersistentHashMap<Integer, TIntHashSet> myMap;
|
||||
private final SLRUCache<Integer, TIntHashSet> myCache;
|
||||
|
||||
public IntIntPersistentMultiMaplet(final File file, final KeyDescriptor<Integer> keyExternalizer) throws IOException {
|
||||
myMap = new JpsPersistentHashMap<>(file, keyExternalizer, new IntSetExternalizer());
|
||||
myMap = new PersistentHashMap<>(file, keyExternalizer, new IntSetExternalizer());
|
||||
myCache = new SLRUCache<Integer, TIntHashSet>(CACHE_SIZE, CACHE_SIZE) {
|
||||
@NotNull
|
||||
@Override
|
||||
|
||||
+11
-4
@@ -4,10 +4,10 @@ package org.jetbrains.jps.builders.java.dependencyView;
|
||||
import com.intellij.util.containers.SLRUCache;
|
||||
import com.intellij.util.io.DataExternalizer;
|
||||
import com.intellij.util.io.KeyDescriptor;
|
||||
import com.intellij.util.io.PersistentHashMap;
|
||||
import gnu.trove.TIntObjectProcedure;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.builders.storage.BuildDataCorruptedException;
|
||||
import org.jetbrains.jps.incremental.storage.JpsPersistentHashMap;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Collection;
|
||||
@@ -19,7 +19,7 @@ import java.util.Collections;
|
||||
public class IntObjectPersistentMultiMaplet<V> extends IntObjectMultiMaplet<V> {
|
||||
private static final Collection NULL_COLLECTION = Collections.emptySet();
|
||||
private static final int CACHE_SIZE = 128;
|
||||
private final JpsPersistentHashMap<Integer, Collection<V>> myMap;
|
||||
private final PersistentHashMap<Integer, Collection<V>> myMap;
|
||||
private final DataExternalizer<V> myValueExternalizer;
|
||||
private final SLRUCache<Integer, Collection> myCache;
|
||||
|
||||
@@ -28,7 +28,7 @@ public class IntObjectPersistentMultiMaplet<V> extends IntObjectMultiMaplet<V> {
|
||||
final DataExternalizer<V> valueExternalizer,
|
||||
final CollectionFactory<V> collectionFactory) throws IOException {
|
||||
myValueExternalizer = valueExternalizer;
|
||||
myMap = new JpsPersistentHashMap<>(file, keyExternalizer,
|
||||
myMap = new PersistentHashMap<>(file, keyExternalizer,
|
||||
new CollectionDataExternalizer<>(valueExternalizer, collectionFactory));
|
||||
myCache = new SLRUCache<Integer, Collection>(CACHE_SIZE, CACHE_SIZE) {
|
||||
@NotNull
|
||||
@@ -82,7 +82,14 @@ public class IntObjectPersistentMultiMaplet<V> extends IntObjectMultiMaplet<V> {
|
||||
public void put(final int key, final Collection<V> value) {
|
||||
try {
|
||||
myCache.remove(key);
|
||||
myMap.appendDataWithoutCache(key, value);
|
||||
myMap.appendData(key, new PersistentHashMap.ValueDataAppender() {
|
||||
@Override
|
||||
public void append(DataOutput out) throws IOException {
|
||||
for (V v : value) {
|
||||
myValueExternalizer.save(out, v);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new BuildDataCorruptedException(e);
|
||||
|
||||
+4
-4
@@ -4,10 +4,10 @@ package org.jetbrains.jps.builders.java.dependencyView;
|
||||
import com.intellij.util.containers.SLRUCache;
|
||||
import com.intellij.util.io.DataExternalizer;
|
||||
import com.intellij.util.io.KeyDescriptor;
|
||||
import com.intellij.util.io.PersistentHashMap;
|
||||
import gnu.trove.TObjectObjectProcedure;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.builders.storage.BuildDataCorruptedException;
|
||||
import org.jetbrains.jps.incremental.storage.JpsPersistentHashMap;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Collection;
|
||||
@@ -19,15 +19,15 @@ import java.util.Collections;
|
||||
public class ObjectObjectPersistentMultiMaplet<K, V> extends ObjectObjectMultiMaplet<K, V>{
|
||||
private static final Collection NULL_COLLECTION = Collections.emptySet();
|
||||
private static final int CACHE_SIZE = 128;
|
||||
private final JpsPersistentHashMap<K, Collection<V>> myMap;
|
||||
private final PersistentHashMap<K, Collection<V>> myMap;
|
||||
private final SLRUCache<K, Collection> myCache;
|
||||
|
||||
public ObjectObjectPersistentMultiMaplet(final File file,
|
||||
final KeyDescriptor<K> keyExternalizer,
|
||||
final DataExternalizer<V> valueExternalizer,
|
||||
final CollectionFactory<V> collectionFactory) throws IOException {
|
||||
myMap = new JpsPersistentHashMap<>(file, keyExternalizer,
|
||||
new CollectionDataExternalizer<>(valueExternalizer, collectionFactory));
|
||||
myMap = new PersistentHashMap<>(file, keyExternalizer,
|
||||
new CollectionDataExternalizer<>(valueExternalizer, collectionFactory));
|
||||
myCache = new SLRUCache<K, Collection>(CACHE_SIZE, CACHE_SIZE, keyExternalizer) {
|
||||
@NotNull
|
||||
@Override
|
||||
|
||||
+21
-4
@@ -7,13 +7,14 @@ import com.intellij.util.io.KeyDescriptor;
|
||||
import com.intellij.util.io.PersistentHashMap;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.DataOutput;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
public abstract class AbstractStateStorage<Key, T> implements StorageOwner {
|
||||
private JpsPersistentHashMap<Key, T> myMap;
|
||||
private PersistentHashMap<Key, T> myMap;
|
||||
private final File myBaseFile;
|
||||
private final KeyDescriptor<Key> myKeyDescriptor;
|
||||
private final DataExternalizer<T> myStateExternalizer;
|
||||
@@ -83,7 +84,23 @@ public abstract class AbstractStateStorage<Key, T> implements StorageOwner {
|
||||
|
||||
public void appendData(final Key key, final T data) throws IOException {
|
||||
synchronized (myDataLock) {
|
||||
myMap.appendDataWithoutCache(key, data);
|
||||
myMap.appendData(key, new PersistentHashMap.ValueDataAppender() {
|
||||
@Override
|
||||
public void append(DataOutput out) throws IOException {
|
||||
myStateExternalizer.save(out, data);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void appendDataWithoutCache(final Key key, final T data) throws IOException {
|
||||
if (data != null) {
|
||||
synchronized (myDataLock) {
|
||||
myMap.appendDataWithoutCache(key, data);
|
||||
}
|
||||
}
|
||||
else {
|
||||
remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,9 +130,9 @@ public abstract class AbstractStateStorage<Key, T> implements StorageOwner {
|
||||
}
|
||||
|
||||
|
||||
private JpsPersistentHashMap<Key, T> createMap(final File file) throws IOException {
|
||||
private PersistentHashMap<Key, T> createMap(final File file) throws IOException {
|
||||
FileUtil.createIfDoesntExist(file);
|
||||
return new JpsPersistentHashMap<>(file, myKeyDescriptor, myStateExternalizer);
|
||||
return new PersistentHashMap<>(file, myKeyDescriptor, myStateExternalizer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
// 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 org.jetbrains.jps.incremental.storage;
|
||||
|
||||
import com.intellij.openapi.util.ThreadLocalCachedValue;
|
||||
import com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream;
|
||||
import com.intellij.util.io.DataExternalizer;
|
||||
import com.intellij.util.io.DataOutputStream;
|
||||
import com.intellij.util.io.KeyDescriptor;
|
||||
import com.intellij.util.io.PersistentHashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class JpsPersistentHashMap<Key, Value> extends PersistentHashMap<Key, Value> {
|
||||
public JpsPersistentHashMap(@NotNull File file,
|
||||
@NotNull KeyDescriptor<Key> keyDescriptor,
|
||||
@NotNull DataExternalizer<Value> valueExternalizer)
|
||||
throws IOException {
|
||||
super(file, keyDescriptor, valueExternalizer);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to append value directly into the chunk without saving to cache.
|
||||
* It can be used in case of non changed appended data like in JSP. The main goal for now
|
||||
* is to avoid binary data changes in saving during JPS builds because of flushing cache.
|
||||
*/
|
||||
public final void appendDataWithoutCache(Key key, Value value) throws IOException {
|
||||
synchronized (myEnumerator) {
|
||||
try {
|
||||
final BufferExposingByteArrayOutputStream bytes = new BufferExposingByteArrayOutputStream();
|
||||
AppendStream appenderStream = ourFlyweightAppenderStream.getValue();
|
||||
appenderStream.setOut(bytes);
|
||||
myValueExternalizer.save(appenderStream, value);
|
||||
appenderStream.setOut(null);
|
||||
appendDataWithoutCache(key, bytes);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
markCorrupted();
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class AppendStream extends DataOutputStream {
|
||||
private AppendStream() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
private void setOut(BufferExposingByteArrayOutputStream stream) {
|
||||
out = stream;
|
||||
}
|
||||
}
|
||||
|
||||
private static final ThreadLocalCachedValue<AppendStream> ourFlyweightAppenderStream = new ThreadLocalCachedValue<AppendStream>() {
|
||||
@NotNull
|
||||
@Override
|
||||
protected AppendStream create() {
|
||||
return new AppendStream();
|
||||
}
|
||||
};
|
||||
}
|
||||
+2
-2
@@ -37,12 +37,12 @@ public class OneToManyPathsMapping extends AbstractStateStorage<String, Collecti
|
||||
}
|
||||
|
||||
public final void appendData(@NotNull String keyPath, @NotNull String boundPath) throws IOException {
|
||||
super.appendData(normalizePath(keyPath), Collections.singleton(normalizePath(boundPath)));
|
||||
super.appendDataWithoutCache(normalizePath(keyPath), Collections.singleton(normalizePath(boundPath)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendData(@NotNull String keyPath, @NotNull Collection<String> boundPaths) throws IOException {
|
||||
super.appendData(normalizePath(keyPath), normalizePaths(boundPaths));
|
||||
super.appendDataWithoutCache(normalizePath(keyPath), normalizePaths(boundPaths));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
+1
-1
@@ -64,7 +64,7 @@ public class OutputToTargetRegistry extends AbstractStateStorage<Integer, TIntHa
|
||||
final TIntHashSet set = new TIntHashSet();
|
||||
set.add(buildTargetId);
|
||||
for (String outputPath : outputPaths) {
|
||||
appendData(FileUtil.pathHashCode(relativePath(outputPath)), set);
|
||||
appendDataWithoutCache(FileUtil.pathHashCode(relativePath(outputPath)), set);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -433,7 +433,30 @@ public class PersistentHashMap<Key, Value> extends PersistentEnumeratorDelegate<
|
||||
}
|
||||
}
|
||||
|
||||
protected void appendDataWithoutCache(Key key, @NotNull final BufferExposingByteArrayOutputStream bytes) {
|
||||
/**
|
||||
* This method is used to append value directly into the chunk without saving to cache.
|
||||
* It can be used in case of non changed appended data like in JSP. The main goal for now
|
||||
* is to avoid binary data changes in saving during JPS builds because of flushing cache.
|
||||
*/
|
||||
public final void appendDataWithoutCache(Key key, @NotNull Value value) throws IOException {
|
||||
if (myIsReadOnly) throw new IncorrectOperationException();
|
||||
synchronized (myEnumerator) {
|
||||
try {
|
||||
final BufferExposingByteArrayOutputStream bytes = new BufferExposingByteArrayOutputStream();
|
||||
AppendStream appenderStream = ourFlyweightAppenderStream.getValue();
|
||||
appenderStream.setOut(bytes);
|
||||
myValueExternalizer.save(appenderStream, value);
|
||||
appenderStream.setOut(null);
|
||||
appendDataWithoutCache(key, bytes);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
myEnumerator.markCorrupted();
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void appendDataWithoutCache(Key key, @NotNull final BufferExposingByteArrayOutputStream bytes) {
|
||||
myEnumerator.lockStorage();
|
||||
try {
|
||||
long previousRecord;
|
||||
|
||||
Reference in New Issue
Block a user