Skip to content

Commit

Permalink
revert to 2724b75
Browse files Browse the repository at this point in the history
  • Loading branch information
penemue committed Aug 16, 2018
1 parent f5454ca commit 0d22eab
Showing 1 changed file with 14 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
import jetbrains.exodus.ByteIterable;
import jetbrains.exodus.bindings.IntegerBinding;
import jetbrains.exodus.bindings.StringBinding;
import jetbrains.exodus.core.dataStructures.LongObjectCacheBase;
import jetbrains.exodus.core.dataStructures.NonAdjustableConcurrentLongObjectCache;
import jetbrains.exodus.core.dataStructures.NonAdjustableConcurrentObjectCache;
import jetbrains.exodus.core.dataStructures.ObjectCacheBase;
import jetbrains.exodus.core.dataStructures.hash.HashSet;
import jetbrains.exodus.entitystore.tables.TwoColumnTable;
import jetbrains.exodus.env.Transaction;
Expand All @@ -30,19 +26,19 @@
import org.jetbrains.annotations.Nullable;

import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

class PersistentSequentialDictionary implements FlushLog.Member {

private static final int CACHE_CAPACITY = 2000;

@NotNull
private final PersistentSequence sequence;
@NotNull
private final TwoColumnTable table;
@NotNull
private final ObjectCacheBase<String, Integer> cache = new NonAdjustableConcurrentObjectCache<>(CACHE_CAPACITY, 2);
private final Map<String, Integer> cache = new ConcurrentHashMap<>();
@NotNull
private final LongObjectCacheBase<String> reverseCache = new NonAdjustableConcurrentLongObjectCache<>(CACHE_CAPACITY, 2);
private final Map<Integer, String> reverseCache = new ConcurrentHashMap<>();
@NotNull
private final Collection<DictionaryOperation> operationsLog = new HashSet<>();
private final Object lock = new Object();
Expand All @@ -66,12 +62,12 @@ public int getId(@NotNull final PersistentStoreTransaction txn, @NotNull final S
}

public int getId(@NotNull final TxnProvider txnProvider, @NotNull final String name) {
Integer result = cache.getObject(name);
Integer result = cache.get(name);
if (result != null) {
return result;
}
synchronized (lock) {
result = cache.getObject(name);
result = cache.get(name);
if (result != null) {
return result;
}
Expand All @@ -91,12 +87,12 @@ public int getOrAllocateId(@NotNull final PersistentStoreTransaction txn, @NotNu
}

public int getOrAllocateId(@NotNull final TxnProvider txnProvider, @NotNull final String name) {
Integer result = cache.getObject(name);
Integer result = cache.get(name);
if (result != null && result >= 0) {
return result;
}
synchronized (lock) {
result = cache.getObject(name);
result = cache.get(name);
if (result != null && result >= 0) {
return result;
}
Expand Down Expand Up @@ -125,19 +121,15 @@ public String getName(@NotNull final PersistentStoreTransaction txn, final int i

@Nullable
public String getName(@NotNull final TxnProvider txnProvider, final int id) {
String result = reverseCache.getObject(id);
String result = reverseCache.get(id);
if (result == null) {
synchronized (lock) {
result = reverseCache.getObject(id);
if (result != null) {
return result;
}
final ByteIterable idEntry = IntegerBinding.intToCompressedEntry(id);
final ByteIterable typeEntry = table.get2(txnProvider.getTransaction().getEnvironmentTransaction(), idEntry);
if (typeEntry != null) {
result = StringBinding.entryToString(typeEntry);
if (result != null) {
reverseCache.cacheObject(id, StringInterner.intern(result));
reverseCache.put(id, result);
}
}
}
Expand Down Expand Up @@ -183,7 +175,7 @@ void persist(final Transaction txn) {
}
});
cache.remove(oldName);
cache.cacheObject(newName, id);
cache.put(newName, id);
reverseCache.remove(id);
if (newId >= 0) {
reverseCache.remove(newId);
Expand All @@ -206,12 +198,12 @@ public void logOperations(final Transaction txn, final FlushLog flushLog) {

private void putIdUnsafe(@NotNull final String name, final int id) {
final String nameInterned = StringInterner.intern(name);
cache.cacheObject(nameInterned, id);
reverseCache.cacheObject(id, nameInterned);
cache.put(nameInterned, id);
reverseCache.put(id, nameInterned);
}

private void putNoIdUnsafe(@NotNull final String name) {
cache.cacheObject(StringInterner.intern(name), -1);
cache.put(StringInterner.intern(name), -1);
}

private abstract class DictionaryOperation implements FlushLog.Operation {
Expand Down

0 comments on commit 0d22eab

Please sign in to comment.