On the way to HCOLL-360: Rename HashLookup to CompactOffHeapLinearHashTable and make it not a stage; extracted KeySearch from HashQuery

This commit is contained in:
leventov
2015-08-03 20:20:14 +03:00
parent 7c10ea41ab
commit ff99f5cccd
23 changed files with 255 additions and 259 deletions
@@ -42,7 +42,6 @@ import net.openhft.sg.Staged;
MapSegmentIteration.class,
HashLookup.class,
KeyBytesInterop.class,
SegmentStages.class,
HashLookupPos.class,
@@ -19,7 +19,6 @@ package net.openhft.chronicle.map.impl;
import net.openhft.chronicle.hash.impl.stage.data.bytes.EntryKeyBytesData;
import net.openhft.chronicle.hash.impl.stage.data.bytes.InputKeyBytesData;
import net.openhft.chronicle.hash.impl.stage.data.instance.InputKeyInstanceData;
import net.openhft.chronicle.hash.impl.stage.entry.HashLookup;
import net.openhft.chronicle.hash.impl.stage.entry.ReadLock;
import net.openhft.chronicle.hash.impl.stage.entry.UpdateLock;
import net.openhft.chronicle.hash.impl.stage.entry.WriteLock;
@@ -27,10 +26,7 @@ import net.openhft.chronicle.hash.impl.stage.hash.KeyBytesInterop;
import net.openhft.chronicle.hash.impl.stage.hash.OwnerThreadHolder;
import net.openhft.chronicle.hash.impl.stage.hash.ThreadLocalCopiesHolder;
import net.openhft.chronicle.hash.impl.stage.input.HashInputBytes;
import net.openhft.chronicle.hash.impl.stage.query.HashLookupSearch;
import net.openhft.chronicle.hash.impl.stage.query.QueryHashLookupPos;
import net.openhft.chronicle.hash.impl.stage.query.QuerySegmentStages;
import net.openhft.chronicle.hash.impl.stage.query.SearchAllocatedChunks;
import net.openhft.chronicle.hash.impl.stage.query.*;
import net.openhft.chronicle.map.impl.stage.data.bytes.EntryValueBytesData;
import net.openhft.chronicle.map.impl.stage.data.bytes.InputFirstValueBytesData;
import net.openhft.chronicle.map.impl.stage.data.bytes.InputSecondValueBytesData;
@@ -55,10 +51,9 @@ import net.openhft.sg.Staged;
VanillaChronicleMapHolderImpl.class,
HashLookup.class,
KeyBytesInterop.class,
QuerySegmentStages.class,
KeySearch.class,
HashLookupSearch.class,
QueryHashLookupPos.class,
@@ -44,7 +44,6 @@ import net.openhft.sg.Staged;
ReplicatedMapSegmentIteration.class,
HashLookup.class,
KeyBytesInterop.class,
SegmentStages.class,
HashLookupPos.class,
@@ -19,7 +19,6 @@ package net.openhft.chronicle.map.impl;
import net.openhft.chronicle.hash.impl.stage.data.bytes.EntryKeyBytesData;
import net.openhft.chronicle.hash.impl.stage.data.bytes.InputKeyBytesData;
import net.openhft.chronicle.hash.impl.stage.data.instance.InputKeyInstanceData;
import net.openhft.chronicle.hash.impl.stage.entry.HashLookup;
import net.openhft.chronicle.hash.impl.stage.entry.ReadLock;
import net.openhft.chronicle.hash.impl.stage.entry.UpdateLock;
import net.openhft.chronicle.hash.impl.stage.entry.WriteLock;
@@ -28,10 +27,7 @@ import net.openhft.chronicle.hash.impl.stage.hash.LogHolder;
import net.openhft.chronicle.hash.impl.stage.hash.OwnerThreadHolder;
import net.openhft.chronicle.hash.impl.stage.hash.ThreadLocalCopiesHolder;
import net.openhft.chronicle.hash.impl.stage.input.HashInputBytes;
import net.openhft.chronicle.hash.impl.stage.query.HashLookupSearch;
import net.openhft.chronicle.hash.impl.stage.query.QueryHashLookupPos;
import net.openhft.chronicle.hash.impl.stage.query.QuerySegmentStages;
import net.openhft.chronicle.hash.impl.stage.query.SearchAllocatedChunks;
import net.openhft.chronicle.hash.impl.stage.query.*;
import net.openhft.chronicle.map.impl.stage.data.DummyValueZeroData;
import net.openhft.chronicle.map.impl.stage.data.bytes.*;
import net.openhft.chronicle.map.impl.stage.data.instance.InputValueInstanceData;
@@ -61,10 +57,9 @@ import net.openhft.sg.Staged;
ReplicatedChronicleMapHolderImpl.class,
HashLookup.class,
KeyBytesInterop.class,
QuerySegmentStages.class,
KeySearch.class,
HashLookupSearch.class,
QueryHashLookupPos.class,
@@ -19,7 +19,8 @@ package net.openhft.chronicle.map.impl.stage.entry;
import net.openhft.chronicle.hash.Data;
import net.openhft.chronicle.hash.impl.stage.entry.AllocatedChunks;
import net.openhft.chronicle.hash.impl.stage.entry.HashEntryStages;
import net.openhft.chronicle.hash.impl.stage.entry.HashLookup;
import net.openhft.chronicle.hash.impl.stage.query.HashLookupSearch;
import net.openhft.chronicle.hash.impl.stage.query.KeySearch;
import net.openhft.chronicle.map.MapEntry;
import net.openhft.chronicle.map.VanillaChronicleMap;
import net.openhft.chronicle.map.impl.VanillaChronicleMapHolder;
@@ -35,8 +36,6 @@ public abstract class MapEntryStages<K, V> extends HashEntryStages<K>
@StageRef public VanillaChronicleMapHolder<?, ?, ?, ?, ?, ?, ?> mh;
@StageRef public AllocatedChunks allocatedChunks;
@StageRef HashLookup hashLookup;
long countValueSizeOffset() {
return keyEnd();
@@ -114,9 +113,9 @@ public abstract class MapEntryStages<K, V> extends HashEntryStages<K>
public void writeValueAndPutPos(Data<V> value) {
initValue(value);
freeExtraAllocatedChunks();
hashLookup.putValueVolatile(hlp.hashLookupPos, pos);
hlp.putValueVolatile(pos);
}
public long newSizeOfEverythingBeforeValue(Data<V> newValue) {
return valueSizeOffset + mh.m().valueSizeMarshaller.sizeEncodingSize(newValue.size()) -
keySizeOffset;
@@ -184,7 +183,7 @@ public abstract class MapEntryStages<K, V> extends HashEntryStages<K>
} else {
writeValue(newValue);
}
hashLookup.putValueVolatile(hlp.hashLookupPos, pos);
hlp.putValueVolatile(pos);
}
protected void relocation(Data<V> newValue, long newSizeOfEverythingBeforeValue) {
@@ -20,6 +20,7 @@ import net.openhft.chronicle.hash.Data;
import net.openhft.chronicle.hash.impl.JavaLangBytesReusableBytesStore;
import net.openhft.chronicle.hash.impl.stage.entry.SegmentStages;
import net.openhft.chronicle.hash.impl.stage.hash.LogHolder;
import net.openhft.chronicle.hash.impl.stage.query.KeySearch;
import net.openhft.chronicle.hash.replication.RemoteOperationContext;
import net.openhft.chronicle.map.impl.ReplicatedChronicleMapHolder;
import net.openhft.chronicle.map.impl.stage.data.DummyValueZeroData;
@@ -44,6 +45,7 @@ public abstract class ReplicatedInput<K, V, R>
@StageRef LogHolder lh;
@StageRef ReplicatedInputKeyBytesData<K> replicatedInputKeyBytesValue;
@StageRef ReplicatedInputValueBytesData<V> replicatedInputValueBytesValue;
@StageRef KeySearch<?> ks;
@StageRef ReplicatedMapQuery<K, V, ?> q;
@StageRef SegmentStages s;
@StageRef ReplicatedMapEntryStages<K, V, ?> e;
@@ -107,7 +109,7 @@ public abstract class ReplicatedInput<K, V, R>
if (isDeleted) {
if (debugEnabled) {
lh.LOG.debug("READING FROM SOURCE - into local-id={}, remote={}, remove(key={})",
mh.m().identifier(), riId, q.inputKey);
mh.m().identifier(), riId, ks.inputKey);
}
mh.m().remoteOperations.remove(this);
return;
@@ -117,7 +119,7 @@ public abstract class ReplicatedInput<K, V, R>
if (debugEnabled) {
message = String.format(
"READING FROM SOURCE - into local-id=%d, remote-id=%d, put(key=%s,",
mh.m().identifier(), riId, q.inputKey);
mh.m().identifier(), riId, ks.inputKey);
}
@@ -17,6 +17,8 @@
package net.openhft.chronicle.map.impl.stage.iter;
import net.openhft.chronicle.hash.Data;
import net.openhft.chronicle.hash.impl.CompactOffHeapLinearHashTable;
import net.openhft.chronicle.hash.impl.VanillaChronicleHashHolder;
import net.openhft.chronicle.hash.replication.ReplicableEntry;
import net.openhft.chronicle.map.impl.ReplicatedIterationContextInterface;
import net.openhft.chronicle.map.impl.stage.data.DummyValueZeroData;
@@ -31,6 +33,7 @@ import java.util.function.Consumer;
public abstract class ReplicatedMapSegmentIteration<K, V, R> extends MapSegmentIteration<K, V, R>
implements ReplicatedIterationContextInterface<K, V, R>, ReplicableEntry {
@StageRef VanillaChronicleHashHolder<?, ?, ?> hh;
@StageRef ReplicatedMapEntryStages<K, V, ?> e;
@StageRef ReplicationUpdate<K> ru;
@StageRef DummyValueZeroData<V> dummyValue;
@@ -60,13 +63,14 @@ public abstract class ReplicatedMapSegmentIteration<K, V, R> extends MapSegmentI
if (entries == 0)
return;
long startPos = 0L;
while (!hashLookup.empty(hashLookup.readEntry(startPos))) {
CompactOffHeapLinearHashTable hashLookup = hh.h().hashLookup;
while (!hashLookup.empty(hashLookup.readEntry(s.segmentBase, startPos))) {
startPos = hashLookup.step(startPos);
}
hlp.initHashLookupPos(startPos);
do {
hlp.setHashLookupPos(hashLookup.step(hlp.hashLookupPos));
long entry = hashLookup.readEntry(hlp.hashLookupPos);
long entry = hashLookup.readEntry(s.segmentBase, hlp.hashLookupPos);
if (!hashLookup.empty(entry)) {
e.readExistingEntry(hashLookup.value(entry));
action.accept(this);
@@ -20,6 +20,7 @@ import net.openhft.chronicle.hash.Data;
import net.openhft.chronicle.hash.impl.stage.entry.SegmentStages;
import net.openhft.chronicle.hash.impl.stage.hash.CheckOnEachPublicOperation;
import net.openhft.chronicle.hash.impl.stage.query.HashLookupSearch;
import net.openhft.chronicle.hash.impl.stage.query.KeySearch;
import net.openhft.chronicle.map.MapAbsentEntry;
import net.openhft.chronicle.map.MapContext;
import net.openhft.chronicle.map.impl.VanillaChronicleMapHolder;
@@ -28,11 +29,12 @@ import net.openhft.sg.StageRef;
import net.openhft.sg.Staged;
import org.jetbrains.annotations.NotNull;
import static net.openhft.chronicle.hash.impl.stage.query.HashQuery.SearchState.PRESENT;
import static net.openhft.chronicle.hash.impl.stage.query.KeySearch.SearchState.PRESENT;
@Staged
public class MapAbsent<K, V> implements MapAbsentEntry<K, V> {
@StageRef public KeySearch<K> ks;
@StageRef MapQuery<K, V, ?> q;
@StageRef MapEntryStages<K, V> e;
@StageRef public HashLookupSearch hashLookupSearch;
@@ -41,8 +43,8 @@ public class MapAbsent<K, V> implements MapAbsentEntry<K, V> {
@StageRef VanillaChronicleMapHolder<K, ?, ?, V, ?, ?, ?> mh;
void putEntry(Data<V> value) {
assert q.searchStateAbsent();
long entrySize = e.entrySize(q.inputKey.size(), value.size());
assert ks.searchStateAbsent();
long entrySize = e.entrySize(ks.inputKey.size(), value.size());
q.allocatedChunks.initEntryAndKey(entrySize);
e.initValue(value);
e.freeExtraAllocatedChunks();
@@ -60,20 +62,20 @@ public class MapAbsent<K, V> implements MapAbsentEntry<K, V> {
@Override
public Data<K> absentKey() {
checkOnEachPublicOperation.checkOnEachPublicOperation();
return q.inputKey;
return ks.inputKey;
}
@Override
public void doInsert(Data<V> value) {
q.putPrefix();
if (!q.searchStatePresent()) {
if (q.searchStateDeleted()) {
if (!q.entryPresent()) {
if (ks.searchStateDeleted()) {
e.putValueDeletedEntry(value);
} else {
putEntry(value);
}
s.incrementModCount();
q.setSearchState(PRESENT);
ks.setSearchState(PRESENT);
} else {
throw new IllegalStateException(
"Entry is present in the map when doInsert() is called");
@@ -18,6 +18,7 @@ package net.openhft.chronicle.map.impl.stage.query;
import net.openhft.chronicle.hash.Data;
import net.openhft.chronicle.hash.impl.stage.query.HashQuery;
import net.openhft.chronicle.hash.impl.stage.query.KeySearch;
import net.openhft.chronicle.hash.impl.stage.query.SearchAllocatedChunks;
import net.openhft.chronicle.map.ExternalMapQueryContext;
import net.openhft.chronicle.map.MapAbsentEntry;
@@ -37,7 +38,7 @@ import net.openhft.sg.Staged;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import static net.openhft.chronicle.hash.impl.stage.query.HashQuery.SearchState.PRESENT;
import static net.openhft.chronicle.hash.impl.stage.query.KeySearch.SearchState.PRESENT;
@Staged
public abstract class MapQuery<K, V, R> extends HashQuery<K>
@@ -47,6 +48,7 @@ public abstract class MapQuery<K, V, R> extends HashQuery<K>
@StageRef VanillaChronicleMapHolder<K, ?, ?, V, ?, ?, R> mh;
@StageRef MapEntryStages<K, V> e;
@StageRef SearchAllocatedChunks allocatedChunks;
@StageRef KeySearch<K> ks;
@StageRef public AcquireHandle<K, V> acquireHandle;
@StageRef public InputValueInstanceData<V, ?, ?> inputValueInstanceValue;
@@ -79,17 +81,17 @@ public abstract class MapQuery<K, V, R> extends HashQuery<K>
s.innerUpdateLock.lock();
boolean searchResultsNotTrusted = underUpdatedLockIsHeld ||
s.concurrentSameThreadContexts;
if (hlp.hashLookupPosInit() && searchStateAbsent() && searchResultsNotTrusted)
if (hlp.hashLookupPosInit() && ks.searchStateAbsent() && searchResultsNotTrusted)
hlp.closeHashLookupPos();
}
@Override
public void doReplaceValue(Data<V> newValue) {
putPrefix();
if (searchStatePresent()) {
if (entryPresent()) {
e.innerDefaultReplaceValue(newValue);
s.incrementModCount();
setSearchState(PRESENT);
ks.setSearchState(PRESENT);
} else {
throw new IllegalStateException(
"Entry is absent in the map when doReplaceValue() is called");
@@ -62,7 +62,8 @@ public abstract class QueryMapEntryStages<K, V> extends MapEntryStages<K, V> {
}
long entrySize = innerEntrySize(newSizeOfEverythingBeforeValue, newValue.size());
if (newValueSizeIsDifferent) {
allocatedChunks.initEntryAndKeyCopying(entrySize, valueSizeOffset - entryStartOffset);
allocatedChunks.initEntryAndKeyCopying(
entrySize, valueSizeOffset - entryStartOffset);
initValue(newValue);
} else {
long oldValueSizeOffset = valueSizeOffset;
@@ -17,12 +17,13 @@
package net.openhft.chronicle.map.impl.stage.query;
import net.openhft.chronicle.hash.Data;
import net.openhft.chronicle.hash.impl.stage.query.HashQuery;
import net.openhft.chronicle.map.impl.stage.entry.ReplicatedMapEntryStages;
import net.openhft.chronicle.map.impl.stage.replication.ReplicationUpdate;
import net.openhft.sg.StageRef;
import net.openhft.sg.Staged;
import static net.openhft.chronicle.hash.impl.stage.query.KeySearch.SearchState.PRESENT;
@Staged
public class ReplicatedMapAbsent<K, V> extends MapAbsent<K, V> {
@@ -34,9 +35,9 @@ public class ReplicatedMapAbsent<K, V> extends MapAbsent<K, V> {
public void doInsert(Data<V> value) {
q.putPrefix();
if (!q.entryPresent()) {
if (!q.searchStatePresent()) {
if (!ks.searchStatePresent()) {
putEntry(value);
q.setSearchState(HashQuery.SearchState.PRESENT);
ks.setSearchState(PRESENT);
} else {
e.innerDefaultReplaceValue(value);
s.deleted(s.deleted() - 1);
@@ -46,7 +46,7 @@ public abstract class ReplicatedMapQuery<K, V, R> extends MapQuery<K, V, R>
if (entryPresent()) {
return null;
} else {
if (!searchStatePresent()) {
if (!ks.searchStatePresent()) {
return absentDelegating;
} else {
assert e.entryDeleted();