Fix several bugs

This commit is contained in:
leventov
2015-09-28 22:13:03 +03:00
parent 440b075f9d
commit c88340f842
18 changed files with 340 additions and 148 deletions
@@ -21,6 +21,7 @@ import net.openhft.chronicle.algo.bitset.ConcurrentFlatBitSetFrame;
import net.openhft.chronicle.algo.bitset.SingleThreadedFlatBitSetFrame;
import net.openhft.chronicle.hash.impl.TierData;
import net.openhft.chronicle.hash.impl.VanillaChronicleHash;
import net.openhft.chronicle.hash.impl.stage.hash.ChainingInterface;
import net.openhft.chronicle.hash.replication.AbstractReplication;
import net.openhft.chronicle.hash.replication.ReplicableEntry;
import net.openhft.chronicle.hash.replication.TimeProvider;
@@ -139,30 +140,6 @@ public class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? sup
}
}
@Override
void initQueryContext() {
queryCxt = new ThreadLocal<
CompiledReplicatedMapQueryContext<K, KI, MKI, V, VI, MVI, R>>() {
@Override
protected CompiledReplicatedMapQueryContext<K, KI, MKI, V, VI, MVI, R>
initialValue() {
return new CompiledReplicatedMapQueryContext<>(ReplicatedChronicleMap.this);
}
};
}
@Override
void initIterationContext() {
iterCxt = new ThreadLocal<
CompiledReplicatedMapIterationContext<K, KI, MKI, V, VI, MVI, R>>() {
@Override
protected CompiledReplicatedMapIterationContext<K, KI, MKI, V, VI, MVI, R>
initialValue() {
return new CompiledReplicatedMapIterationContext<>(ReplicatedChronicleMap.this);
}
};
}
private int assignedModIterBitSetSizeInBytes() {
return (int) CACHE_LINES.align(BYTES.alignAndConvert(127 + RESERVED_MOD_ITER, BITS), BYTES);
}
@@ -471,14 +448,22 @@ public class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? sup
}
}
private CompiledReplicatedMapQueryContext<K, KI, MKI, V, VI, MVI, R> q() {
//noinspection unchecked
return (CompiledReplicatedMapQueryContext<K, KI, MKI, V, VI, MVI, R>) queryCxt.get();
private ChainingInterface q() {
ChainingInterface queryContext;
queryContext = cxt.get();
if (queryContext == null) {
queryContext = new CompiledReplicatedMapQueryContext<>(ReplicatedChronicleMap.this);
cxt.set(queryContext);
}
return queryContext;
}
@Override
public CompiledReplicatedMapQueryContext<K, KI, MKI, V, VI, MVI, R> mapContext() {
CompiledReplicatedMapQueryContext<K, KI, MKI, V, VI, MVI, R> q = q().getContext();
CompiledReplicatedMapQueryContext<K, KI, MKI, V, VI, MVI, R> q =
q().getContext(CompiledReplicatedMapQueryContext.class,
ci -> new CompiledReplicatedMapQueryContext<>(ci,
ReplicatedChronicleMap.this));
q.initUsed(true);
return q;
}
@@ -489,7 +474,7 @@ public class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? sup
*/
private CompiledReplicatedMapQueryContext<K, KI, MKI, V, VI, MVI, R> remoteOpContext() {
if (remoteOpContext == null) {
remoteOpContext = q();
remoteOpContext = (CompiledReplicatedMapQueryContext<K, KI, MKI, V, VI, MVI, R>) q();
}
assert !remoteOpContext.usedInit();
remoteOpContext.initUsed(true);
@@ -498,7 +483,8 @@ public class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? sup
private CompiledReplicatedMapIterationContext<K, KI, MKI, V, VI, MVI, R> remoteItContext() {
if (remoteItContext == null) {
remoteItContext = i();
remoteItContext =
(CompiledReplicatedMapIterationContext<K, KI, MKI, V, VI, MVI, R>) i();
}
assert !remoteItContext.usedInit();
remoteItContext.initUsed(true);
@@ -518,13 +504,21 @@ public class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? sup
}
}
private CompiledReplicatedMapIterationContext<K, KI, MKI, V, VI, MVI, R> i() {
//noinspection unchecked
return (CompiledReplicatedMapIterationContext<K, KI, MKI, V, VI, MVI, R>) iterCxt.get();
private ChainingInterface i() {
ChainingInterface iterContext;
iterContext = cxt.get();
if (iterContext == null) {
iterContext = new CompiledReplicatedMapIterationContext<>(ReplicatedChronicleMap.this);
cxt.set(iterContext);
}
return iterContext;
}
public CompiledReplicatedMapIterationContext<K, KI, MKI, V, VI, MVI, R> iterationContext() {
CompiledReplicatedMapIterationContext<K, KI, MKI, V, VI, MVI, R> c = i().getContext();
CompiledReplicatedMapIterationContext<K, KI, MKI, V, VI, MVI, R> c =
i().getContext(CompiledReplicatedMapIterationContext.class,
ci -> new CompiledReplicatedMapIterationContext<>(ci,
ReplicatedChronicleMap.this));
c.initUsed(true);
return c;
}
@@ -19,6 +19,7 @@ package net.openhft.chronicle.map;
import net.openhft.chronicle.core.io.Closeable;
import net.openhft.chronicle.hash.Data;
import net.openhft.chronicle.hash.impl.VanillaChronicleHash;
import net.openhft.chronicle.hash.impl.stage.hash.ChainingInterface;
import net.openhft.chronicle.hash.serialization.BytesReader;
import net.openhft.chronicle.hash.serialization.SizeMarshaller;
import net.openhft.chronicle.hash.serialization.internal.MetaBytesInterop;
@@ -92,9 +93,8 @@ public class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super
public transient MapMethods<K, V, R> methods;
public transient DefaultValueProvider<K, V> defaultValueProvider;
transient ThreadLocal<?> queryCxt;
transient ThreadLocal<?> iterCxt;
transient ThreadLocal<ChainingInterface> cxt = new ThreadLocal<>();
public VanillaChronicleMap(ChronicleMapBuilder<K, V> builder) throws IOException {
super(builder);
@@ -162,27 +162,6 @@ public class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super
BytesReader<V> valueReader = valueReaderProvider.get(copies, originalValueReader);
constantValueProvider.initTransients(valueReader);
}
initQueryContext();
initIterationContext();
}
void initQueryContext() {
queryCxt = new ThreadLocal<CompiledMapQueryContext<K, KI, MKI, V, VI, MVI, R>>() {
@Override
protected CompiledMapQueryContext<K, KI, MKI, V, VI, MVI, R> initialValue() {
return new CompiledMapQueryContext<>(VanillaChronicleMap.this);
}
};
}
void initIterationContext() {
iterCxt = new ThreadLocal<CompiledMapIterationContext<K, KI, MKI, V, VI, MVI, R>>() {
@Override
protected CompiledMapIterationContext<K, KI, MKI, V, VI, MVI, R> initialValue() {
return new CompiledMapIterationContext<>(VanillaChronicleMap.this);
}
};
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
@@ -314,22 +293,38 @@ public class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super
return valueSize;
}
private CompiledMapQueryContext<K, KI, MKI, V, VI, MVI, R> q() {
return (CompiledMapQueryContext<K, KI, MKI, V, VI, MVI, R>) queryCxt.get();
private ChainingInterface q() {
ChainingInterface queryContext;
queryContext = cxt.get();
if (queryContext == null) {
queryContext = new CompiledMapQueryContext<>(VanillaChronicleMap.this);
cxt.set(queryContext);
}
return queryContext;
}
public QueryContextInterface<K, V, R> mapContext() {
CompiledMapQueryContext<K, KI, MKI, V, VI, MVI, R> q = q().getContext();
CompiledMapQueryContext<K, KI, MKI, V, VI, MVI, R> q =
q().getContext(CompiledMapQueryContext.class,
ci -> new CompiledMapQueryContext<>(ci, VanillaChronicleMap.this));
q.initUsed(true);
return q;
}
private CompiledMapIterationContext<K, KI, MKI, V, VI, MVI, R> i() {
return (CompiledMapIterationContext<K, KI, MKI, V, VI, MVI, R>) iterCxt.get();
private ChainingInterface i() {
ChainingInterface iterContext;
iterContext = cxt.get();
if (iterContext == null) {
iterContext = new CompiledMapIterationContext<>(VanillaChronicleMap.this);
cxt.set(iterContext);
}
return iterContext;
}
public IterationContextInterface<K, V, ?> iterationContext() {
CompiledMapIterationContext<K, KI, MKI, V, VI, MVI, R> c = i().getContext();
CompiledMapIterationContext<K, KI, MKI, V, VI, MVI, R> c =
i().getContext(CompiledMapIterationContext.class,
ci -> new CompiledMapIterationContext<>(ci, VanillaChronicleMap.this));
c.initUsed(true);
return c;
}
@@ -19,6 +19,7 @@ package net.openhft.chronicle.map.impl;
import net.openhft.chronicle.hash.impl.stage.data.bytes.EntryKeyBytesData;
import net.openhft.chronicle.hash.impl.stage.entry.*;
import net.openhft.chronicle.hash.impl.stage.hash.KeyBytesInterop;
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.iter.IterationKeyHashCode;
@@ -43,6 +44,8 @@ import net.openhft.sg.Staged;
ThreadLocalCopiesHolder.class,
VanillaChronicleMapHolderImpl.class,
LogHolder.class,
MapSegmentIteration.class,
KeyBytesInterop.class,
@@ -21,6 +21,7 @@ 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.*;
import net.openhft.chronicle.hash.impl.stage.hash.KeyBytesInterop;
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;
@@ -44,6 +45,8 @@ import net.openhft.sg.Staged;
OwnerThreadHolder.class,
ThreadLocalCopiesHolder.class,
LogHolder.class,
VanillaChronicleMapHolderImpl.class,
KeyBytesInterop.class,
@@ -19,6 +19,7 @@ package net.openhft.chronicle.map.impl;
import net.openhft.chronicle.hash.impl.stage.data.bytes.EntryKeyBytesData;
import net.openhft.chronicle.hash.impl.stage.entry.*;
import net.openhft.chronicle.hash.impl.stage.hash.KeyBytesInterop;
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.iter.IterationKeyHashCode;
@@ -44,6 +45,8 @@ import net.openhft.sg.Staged;
ThreadLocalCopiesHolder.class,
ReplicatedChronicleMapHolderImpl.class,
LogHolder.class,
ReplicatedMapSegmentIteration.class,
KeyBytesInterop.class,
@@ -17,6 +17,7 @@
package net.openhft.chronicle.map.impl.stage.map;
import net.openhft.chronicle.hash.impl.stage.hash.Chaining;
import net.openhft.chronicle.hash.impl.stage.hash.ChainingInterface;
import net.openhft.chronicle.hash.serialization.internal.MetaBytesInterop;
import net.openhft.chronicle.map.ChronicleMap;
import net.openhft.chronicle.map.ReplicatedChronicleMap;
@@ -38,14 +39,10 @@ public class ReplicatedChronicleMapHolderImpl<
this.m = m;
}
public ReplicatedChronicleMapHolderImpl(ReplicatedChronicleMapHolderImpl c) {
public ReplicatedChronicleMapHolderImpl(
ChainingInterface c, ReplicatedChronicleMap<K, KI, MKI, V, VI, MVI, R> m) {
super(c);
this.m = (ReplicatedChronicleMap<K, KI, MKI, V, VI, MVI, R>) c.m;
}
@Override
public Chaining createChaining() {
return new ReplicatedChronicleMapHolderImpl(this);
this.m = m;
}
@Override
@@ -17,6 +17,7 @@
package net.openhft.chronicle.map.impl.stage.map;
import net.openhft.chronicle.hash.impl.stage.hash.Chaining;
import net.openhft.chronicle.hash.impl.stage.hash.ChainingInterface;
import net.openhft.chronicle.hash.serialization.internal.MetaBytesInterop;
import net.openhft.chronicle.map.ChronicleMap;
import net.openhft.chronicle.map.VanillaChronicleMap;
@@ -38,14 +39,10 @@ public class VanillaChronicleMapHolderImpl<
this.m = m;
}
public VanillaChronicleMapHolderImpl(VanillaChronicleMapHolderImpl c) {
public VanillaChronicleMapHolderImpl(
ChainingInterface c, VanillaChronicleMap<K, KI, MKI, V, VI, MVI, R> m) {
super(c);
this.m = (VanillaChronicleMap<K, KI, MKI, V, VI, MVI, R>) c.m;
}
@Override
public Chaining createChaining() {
return new VanillaChronicleMapHolderImpl(this);
this.m = m;
}
@Override
@@ -51,9 +51,10 @@ public abstract class ReplicatedQuerySegmentStages extends QuerySegmentStages {
return ret;
} else {
ReplicatedChronicleMap<?, ?, ?, ?, ?, ?, ?> map = mh.m();
MapSegmentContext<?, ?, ?> sc = map.segmentContext(segmentIndex);
((ReplicatedHashSegmentContext<?, ?>) sc)
.forEachSegmentReplicableEntry(cleanupAction);
try (MapSegmentContext<?, ?, ?> sc = map.segmentContext(segmentIndex)) {
((ReplicatedHashSegmentContext<?, ?>) sc)
.forEachSegmentReplicableEntry(cleanupAction);
}
ret = allocReturnCode(chunks);
if (ret >= 0) {
return ret;