mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
HCOLL-360 Add segment tiers
This commit is contained in:
@@ -49,7 +49,6 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@@ -158,6 +157,8 @@ public final class ChronicleMapBuilder<K, V> implements
|
||||
private long lockTimeOut = 20000L;
|
||||
private TimeUnit lockTimeOutUnit = TimeUnit.MILLISECONDS;
|
||||
private int metaDataBytes = 0;
|
||||
private double maxBloatFactor = 1.0;
|
||||
|
||||
private boolean putReturnsNull = false;
|
||||
private boolean removeReturnsNull = false;
|
||||
|
||||
@@ -915,10 +916,12 @@ public final class ChronicleMapBuilder<K, V> implements
|
||||
//
|
||||
// The only problem with small segments is that due to probability theory, if there are
|
||||
// a lot of segments each of little number of entries, difference between most filled
|
||||
// and least filled segment in the Chronicle Map grows. It is critical, because we don't
|
||||
// support segment resize yet, and are required to allocate unnecessarily many entries per
|
||||
// each segment. To compensate this at least on linux, don't accept segment sizes that
|
||||
// with the given entry sizes, lead to too small total segment sizes in native memory pages,
|
||||
// and least filled segment in the Chronicle Map grows. (Number of entries in a segment is
|
||||
// Poisson-distributed with mean = average number of entries per segment.) It is meaningful,
|
||||
// because segment tiering is exceptional mechanism, only very few segments should be
|
||||
// tiered, if any, normally. So, we are required to allocate unnecessarily many entries per
|
||||
// each segment. To compensate this at least on linux, don't accept segment sizes that with
|
||||
// the given entry sizes, lead to too small total segment sizes in native memory pages,
|
||||
// see comment in tryHashLookupSlotSize()
|
||||
for (int hashLookupSlotSize = 3; hashLookupSlotSize <= 7; hashLookupSlotSize++) {
|
||||
long segments = tryHashLookupSlotSize(hashLookupSlotSize, replicated);
|
||||
@@ -1020,6 +1023,25 @@ public final class ChronicleMapBuilder<K, V> implements
|
||||
return metaDataBytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChronicleMapBuilder<K, V> maxBloatFactor(double maxBloatFactor) {
|
||||
if (Double.isNaN(maxBloatFactor) || maxBloatFactor < 1.0 || maxBloatFactor > 1_000.0) {
|
||||
throw new IllegalArgumentException("maxBloatFactor should be in [1.0, 1_000.0] " +
|
||||
"bounds, " + maxBloatFactor + " given");
|
||||
}
|
||||
this.maxBloatFactor = maxBloatFactor;
|
||||
return this;
|
||||
}
|
||||
|
||||
long maxExtraTiers(boolean replicated) {
|
||||
int actualSegments = actualSegments(replicated);
|
||||
// maxBloatFactor is scale, so we do (- 1.0) to compute _extra_ tiers
|
||||
return ((long) (maxBloatFactor - 1.0) * actualSegments)
|
||||
// but to mitigate slight misconfiguration, and uneven distribution of entries
|
||||
// between segments, add 1.0 x actualSegments
|
||||
+ actualSegments;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ChronicleMapBuilder{" +
|
||||
@@ -1414,7 +1436,7 @@ public final class ChronicleMapBuilder<K, V> implements
|
||||
(VanillaChronicleMap<K, ?, ?, V, ?, ?, ?>) m;
|
||||
map.initTransientsFromBuilder(this);
|
||||
map.headerSize = roundUpMapHeaderSize(fis.getChannel().position());
|
||||
long sizeInBytes = map.sizeInBytes();
|
||||
long sizeInBytes = map.sizeInBytesWithoutTiers();
|
||||
if (sizeInBytes != fileLength) {
|
||||
throw new IOException("The file " + file + "the map is serialized from " +
|
||||
"has unexpected length " + fileLength + ", probably corrupted. " +
|
||||
@@ -1501,11 +1523,11 @@ public final class ChronicleMapBuilder<K, V> implements
|
||||
// pushingToMapEventListener();
|
||||
VanillaChronicleMap<K, ?, ?, V, ?, ?, ?> map = newMap(singleHashReplication, channel);
|
||||
// TODO this method had been moved
|
||||
// if(OS.warnOnWindows(map.sizeInBytes())){
|
||||
// if(OS.warnOnWindows(map.sizeInBytesWithoutTiers())){
|
||||
// throw new IllegalStateException("Windows cannot support this configuration");
|
||||
// }
|
||||
BytesStore bytesStore = new DirectStore(JDKObjectSerializer.INSTANCE,
|
||||
map.sizeInBytes(), true);
|
||||
map.sizeInBytesWithoutTiers(), true);
|
||||
map.createMappedStoreAndSegments(bytesStore);
|
||||
return establishReplication(map, singleHashReplication, channel);
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -66,4 +66,9 @@ class ChronicleMapBuilderPrivateAPI<K> implements ChronicleHashBuilderPrivateAPI
|
||||
public int actualSegments(boolean replicated) {
|
||||
return b.actualSegments(replicated);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long maxExtraTiers(boolean replicated) {
|
||||
return b.maxExtraTiers(replicated);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,18 +16,21 @@
|
||||
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import net.openhft.chronicle.hash.ReplicatedHashSegmentContext;
|
||||
import net.openhft.chronicle.algo.bitset.BitSetFrame;
|
||||
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.replication.AbstractReplication;
|
||||
import net.openhft.chronicle.hash.replication.ReplicableEntry;
|
||||
import net.openhft.chronicle.hash.replication.TimeProvider;
|
||||
import net.openhft.chronicle.hash.serialization.internal.MetaBytesInterop;
|
||||
import net.openhft.chronicle.map.impl.CompiledReplicatedMapIterationContext;
|
||||
import net.openhft.chronicle.map.impl.CompiledReplicatedMapQueryContext;
|
||||
import net.openhft.chronicle.map.impl.IterationContextInterface;
|
||||
import net.openhft.chronicle.map.replication.MapRemoteOperations;
|
||||
import net.openhft.chronicle.map.replication.MapReplicableEntry;
|
||||
import net.openhft.lang.Maths;
|
||||
import net.openhft.lang.collection.ATSDirectBitSet;
|
||||
import net.openhft.lang.collection.SingleThreadedDirectBitSet;
|
||||
import net.openhft.lang.io.Bytes;
|
||||
import net.openhft.lang.model.DataValueClasses;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -39,10 +42,10 @@ import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.atomic.AtomicReferenceArray;
|
||||
|
||||
import static net.openhft.chronicle.algo.bytes.Access.nativeAccess;
|
||||
import static net.openhft.lang.MemoryUnit.*;
|
||||
import static net.openhft.lang.collection.DirectBitSet.NOT_FOUND;
|
||||
|
||||
@@ -115,6 +118,11 @@ public class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? sup
|
||||
transient CompiledReplicatedMapQueryContext<K, KI, MKI, V, VI, MVI, R, ?> remoteOpContext;
|
||||
transient CompiledReplicatedMapIterationContext<K, KI, MKI, V, VI, MVI, R, ?> remoteItContext;
|
||||
|
||||
transient BitSetFrame mainSegmentsModIterFrameForUpdates;
|
||||
transient BitSetFrame mainSegmentsModIterFrameForIteration;
|
||||
transient BitSetFrame tierBulkModIterFrameForUpdates;
|
||||
transient BitSetFrame tierBulkModIterFrameForIteration;
|
||||
|
||||
public ReplicatedChronicleMap(@NotNull ChronicleMapBuilder<K, V> builder,
|
||||
AbstractReplication replication)
|
||||
throws IOException {
|
||||
@@ -170,6 +178,16 @@ public class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? sup
|
||||
modificationIterators =
|
||||
new AtomicReferenceArray<>(127 + RESERVED_MOD_ITER);
|
||||
closeables = new CopyOnWriteArraySet<>();
|
||||
long mainSegmentsBitSetSize = BYTES.toBits(modIterBitSetSizeInBytes());
|
||||
mainSegmentsModIterFrameForUpdates =
|
||||
new SingleThreadedFlatBitSetFrame(mainSegmentsBitSetSize);
|
||||
mainSegmentsModIterFrameForIteration =
|
||||
new ConcurrentFlatBitSetFrame(mainSegmentsBitSetSize);
|
||||
|
||||
long tierBulkBitSetSize =
|
||||
BYTES.toBits(tierBulkModIterBitSetSizeInBytes(numberOfTiersInBulk));
|
||||
tierBulkModIterFrameForUpdates = new SingleThreadedFlatBitSetFrame(tierBulkBitSetSize);
|
||||
tierBulkModIterFrameForIteration = new ConcurrentFlatBitSetFrame(tierBulkBitSetSize);
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
@@ -182,6 +200,16 @@ public class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? sup
|
||||
return CACHE_LINES.align(bytes, BYTES);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected long computeTierBulkInnerOffsetToTiers(long numberOfTiersInBulk) {
|
||||
return tierBulkModIterBitSetSizeInBytes(numberOfTiersInBulk) * (128 + RESERVED_MOD_ITER);
|
||||
}
|
||||
|
||||
private long tierBulkModIterBitSetSizeInBytes(long numberOfTiersInBulk) {
|
||||
long bytes = BITS.toBytes(bitsPerSegmentInModIterBitSet() * numberOfTiersInBulk);
|
||||
return CACHE_LINES.align(bytes, BYTES);
|
||||
}
|
||||
|
||||
private long bitsPerSegmentInModIterBitSet() {
|
||||
// min 128 * 8 to prevent false sharing on updating bits from different segments
|
||||
// TODO this doesn't prevent false sharing. There should be GAPS between per-segment bits
|
||||
@@ -244,11 +272,6 @@ public class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? sup
|
||||
globalMutableStateBytes.unlockLong(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
forEachEntry(c -> c.context().remove(c));
|
||||
}
|
||||
|
||||
void addCloseable(Closeable closeable) {
|
||||
closeables.add(closeable);
|
||||
}
|
||||
@@ -284,61 +307,56 @@ public class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? sup
|
||||
if (modificationIterator != null)
|
||||
return modificationIterator;
|
||||
|
||||
final Bytes bytes = ms.bytes(startOfModificationIterators +
|
||||
(modIterBitSetSizeInBytes() * remoteIdentifier),
|
||||
modIterBitSetSizeInBytes());
|
||||
|
||||
final ModificationIterator newModificationIterator = new ModificationIterator(
|
||||
bytes);
|
||||
|
||||
modificationIterators.set(remoteIdentifier, newModificationIterator);
|
||||
final ModificationIterator modIter = new ModificationIterator(remoteIdentifier);
|
||||
modificationIterators.set(remoteIdentifier, modIter);
|
||||
modIterSet.set(remoteIdentifier);
|
||||
return newModificationIterator;
|
||||
return modIter;
|
||||
}
|
||||
}
|
||||
|
||||
public void raiseChange(long segmentIndex, long pos, long timestamp) {
|
||||
public void raiseChange(long tierIndex, long pos, long timestamp) {
|
||||
for (long next = modIterSet.nextSetBit(0L); next > 0L;
|
||||
next = modIterSet.nextSetBit(next + 1L)) {
|
||||
try {
|
||||
acquireModificationIterator((byte) next).raiseChange(segmentIndex, pos, timestamp);
|
||||
acquireModificationIterator((byte) next).raiseChange(tierIndex, pos, timestamp);
|
||||
} catch (Exception e) {
|
||||
LOG.error("", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void dropChange(long segmentIndex, long pos) {
|
||||
public void dropChange(long tierIndex, long pos) {
|
||||
for (long next = modIterSet.nextSetBit(0L); next > 0L;
|
||||
next = modIterSet.nextSetBit(next + 1L)) {
|
||||
try {
|
||||
acquireModificationIterator((byte) next).dropChange(segmentIndex, pos);
|
||||
acquireModificationIterator((byte) next).dropChange(tierIndex, pos);
|
||||
} catch (Exception e) {
|
||||
LOG.error("", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void moveChange(long segmentIndex, long oldPos, long newPos, long timestamp) {
|
||||
public void moveChange(long oldTierIndex, long oldPos, long newTierIndex, long newPos,
|
||||
long timestamp) {
|
||||
for (long next = modIterSet.nextSetBit(0L); next > 0L;
|
||||
next = modIterSet.nextSetBit(next + 1L)) {
|
||||
try {
|
||||
ModificationIterator modificationIterator =
|
||||
acquireModificationIterator((byte) next);
|
||||
if (modificationIterator.dropChange(segmentIndex, oldPos))
|
||||
modificationIterator.raiseChange(segmentIndex, newPos, timestamp);
|
||||
if (modificationIterator.dropChange(oldTierIndex, oldPos))
|
||||
modificationIterator.raiseChange(newTierIndex, newPos, timestamp);
|
||||
} catch (Exception e) {
|
||||
LOG.error("", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isChanged(long segmentIndex, long pos) {
|
||||
public boolean isChanged(long tierIndex, long pos) {
|
||||
for (long next = modIterSet.nextSetBit(0L); next > 0L;
|
||||
next = modIterSet.nextSetBit(next + 1L)) {
|
||||
ModificationIterator modificationIterator =
|
||||
acquireModificationIterator((byte) next);
|
||||
if (modificationIterator.isChanged(segmentIndex, pos))
|
||||
if (modificationIterator.isChanged(tierIndex, pos))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -527,14 +545,13 @@ public class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? sup
|
||||
*/
|
||||
class ModificationIterator implements Replica.ModificationIterator {
|
||||
private ModificationNotifier modificationNotifier;
|
||||
private final SingleThreadedDirectBitSet changesForUpdates;
|
||||
// to getVolatile when reading changes bits, because we iterate when without lock.
|
||||
// hardly this is needed on x86, probably on other architectures too.
|
||||
// Anyway getVolatile is cheap.
|
||||
private final ATSDirectBitSet changesForIteration;
|
||||
|
||||
private final long mainSegmentsChangesBitSetAddr;
|
||||
private final int segmentIndexShift;
|
||||
private final long posMask;
|
||||
|
||||
private final long offsetToBitSetWithinATierBulk;
|
||||
|
||||
// when a bootstrap is send this is the time stamp that the client will bootstrap up to
|
||||
// if it is set as ZERO then the onPut() will set it to the current time, once the
|
||||
// consumer has cycled through the bit set the timestamp will be set back to zero.
|
||||
@@ -542,18 +559,26 @@ public class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? sup
|
||||
private long lastBootStrapTimeStamp = timeProvider.currentTime();
|
||||
|
||||
// records the current position of the cursor in the bitset
|
||||
private volatile long position = -1L;
|
||||
// TODO volatile?
|
||||
private volatile long position = NOT_FOUND;
|
||||
|
||||
public ModificationIterator(@NotNull final Bytes bytes) {
|
||||
// -1 for main segments area, 0-N is tier bulk id
|
||||
private int iterationMainSegmentsAreaOrTierBulk = -1;
|
||||
private long tierBulkBitSetAddr = 0L;
|
||||
|
||||
public ModificationIterator(int identifier) {
|
||||
long bitsPerSegment = bitsPerSegmentInModIterBitSet();
|
||||
segmentIndexShift = Long.numberOfTrailingZeros(bitsPerSegment);
|
||||
posMask = bitsPerSegment - 1L;
|
||||
changesForUpdates = new SingleThreadedDirectBitSet(bytes);
|
||||
changesForIteration = new ATSDirectBitSet(bytes);
|
||||
mainSegmentsChangesBitSetAddr = ms.address() + startOfModificationIterators +
|
||||
identifier * modIterBitSetSizeInBytes();
|
||||
nativeAccess().zeroOut(null, mainSegmentsChangesBitSetAddr, modIterBitSetSizeInBytes());
|
||||
offsetToBitSetWithinATierBulk =
|
||||
identifier * tierBulkModIterBitSetSizeInBytes(numberOfTiersInBulk);
|
||||
}
|
||||
|
||||
public ModificationIterator(@NotNull final Bytes bytes, ModificationNotifier notifier) {
|
||||
this(bytes);
|
||||
public ModificationIterator(int identifier, ModificationNotifier notifier) {
|
||||
this(identifier);
|
||||
setModificationNotifier(notifier);
|
||||
}
|
||||
|
||||
@@ -564,19 +589,34 @@ public class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? sup
|
||||
/**
|
||||
* used to merge multiple segments and positions into a single index used by the bit map
|
||||
*
|
||||
* @param segmentIndex the index of the maps segment
|
||||
* @param pos the position within this {@code segmentIndex}
|
||||
* @return and index the has combined the {@code segmentIndex} and {@code pos} into a
|
||||
* @param tierIndex the index of the maps segment
|
||||
* @param pos the position within this {@code tierIndex}
|
||||
* @return and index the has combined the {@code tierIndex} and {@code pos} into a
|
||||
* single value
|
||||
*/
|
||||
private long combine(long segmentIndex, long pos) {
|
||||
return (segmentIndex << segmentIndexShift) | pos;
|
||||
private long combine(long tierIndex, long pos) {
|
||||
tierIndex -= 1;
|
||||
if (tierIndex < actualSegments)
|
||||
return (tierIndex << segmentIndexShift) | pos;
|
||||
return combineExtraTier(tierIndex, pos);
|
||||
}
|
||||
|
||||
void raiseChange(long segmentIndex, long pos, long timestamp) {
|
||||
LOG.debug("raise change: id {}, segment {}, pos {}",
|
||||
localIdentifier, segmentIndex, pos);
|
||||
changesForUpdates.set(combine(segmentIndex, pos));
|
||||
private long combineExtraTier(long tierIndex, long pos) {
|
||||
long extraTierIndex = tierIndex - actualSegments;
|
||||
long tierOffsetWithinBulk = extraTierIndex & ((1L << log2NumberOfTiersInBulk) - 1);
|
||||
return (tierOffsetWithinBulk << segmentIndexShift) | pos;
|
||||
}
|
||||
|
||||
void raiseChange(long tierIndex, long pos, long timestamp) {
|
||||
LOG.debug("raise change: id {}, tierIndex {}, pos {}",
|
||||
localIdentifier, tierIndex, pos);
|
||||
long bitIndex = combine(tierIndex, pos);
|
||||
if (tierIndex <= actualSegments) {
|
||||
mainSegmentsModIterFrameForUpdates.set(nativeAccess(), null,
|
||||
mainSegmentsChangesBitSetAddr, bitIndex);
|
||||
} else {
|
||||
raiseExtraTierChange(tierIndex, bitIndex);
|
||||
}
|
||||
// assert timestamp > timeProvider.currentTime() - TimeUnit.SECONDS.toMillis(1) &&
|
||||
// timestamp <= timeProvider.currentTime() : "timeStamp=" + timestamp + ", " +
|
||||
// "currentTime=" + timeProvider.currentTime();
|
||||
@@ -586,13 +626,53 @@ public class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? sup
|
||||
modificationNotifier.onChange();
|
||||
}
|
||||
|
||||
boolean dropChange(long segmentIndex, long pos) {
|
||||
LOG.debug("drop change: id {}, segment {}, pos {}", localIdentifier, segmentIndex, pos);
|
||||
return changesForUpdates.clearIfSet(combine(segmentIndex, pos));
|
||||
private void raiseExtraTierChange(long tierIndex, long bitIndex) {
|
||||
tierIndex = tierIndex - actualSegments - 1;
|
||||
long bulkIndex = tierIndex >> log2NumberOfTiersInBulk;
|
||||
TierBulkData tierBulkData = tierBulkOffsets.get((int) bulkIndex);
|
||||
long bitSetAddr = tierBulkData.langBytes.address() + tierBulkData.offset +
|
||||
offsetToBitSetWithinATierBulk;
|
||||
tierBulkModIterFrameForUpdates.set(nativeAccess(), null, bitSetAddr, bitIndex);
|
||||
}
|
||||
|
||||
boolean isChanged(long segmentIndex, long pos) {
|
||||
return changesForUpdates.isSet(combine(segmentIndex, pos));
|
||||
boolean dropChange(long tierIndex, long pos) {
|
||||
LOG.debug("drop change: id {}, tierIndex {}, pos {}", localIdentifier, tierIndex, pos);
|
||||
long bitIndex = combine(tierIndex, pos);
|
||||
if (tierIndex <= actualSegments) {
|
||||
return mainSegmentsModIterFrameForUpdates.clearIfSet(nativeAccess(), null,
|
||||
mainSegmentsChangesBitSetAddr, bitIndex);
|
||||
} else {
|
||||
return dropExtraTierChange(tierIndex, bitIndex);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean dropExtraTierChange(long tierIndex, long bitIndex) {
|
||||
tierIndex = tierIndex - actualSegments - 1;
|
||||
long bulkIndex = tierIndex >> log2NumberOfTiersInBulk;
|
||||
TierBulkData tierBulkData = tierBulkOffsets.get((int) bulkIndex);
|
||||
long bitSetAddr = tierBulkData.langBytes.address() + tierBulkData.offset +
|
||||
offsetToBitSetWithinATierBulk;
|
||||
return tierBulkModIterFrameForUpdates.clearIfSet(nativeAccess(), null,
|
||||
bitSetAddr, bitIndex);
|
||||
}
|
||||
|
||||
boolean isChanged(long tierIndex, long pos) {
|
||||
long bitIndex = combine(tierIndex, pos);
|
||||
if (tierIndex <= actualSegments) {
|
||||
return mainSegmentsModIterFrameForUpdates.isSet(nativeAccess(), null,
|
||||
mainSegmentsChangesBitSetAddr, bitIndex);
|
||||
} else {
|
||||
return isChangedExtraTier(tierIndex, bitIndex);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isChangedExtraTier(long tierIndex, long bitIndex) {
|
||||
tierIndex = tierIndex - actualSegments - 1;
|
||||
long bulkIndex = tierIndex >> log2NumberOfTiersInBulk;
|
||||
TierBulkData tierBulkData = tierBulkOffsets.get((int) bulkIndex);
|
||||
long bitSetAddr = tierBulkData.langBytes.address() + tierBulkData.offset +
|
||||
offsetToBitSetWithinATierBulk;
|
||||
return tierBulkModIterFrameForUpdates.isSet(nativeAccess(), null, bitSetAddr, bitIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -604,10 +684,47 @@ public class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? sup
|
||||
*/
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
final long position = this.position;
|
||||
return changesForIteration.nextSetBit(position == NOT_FOUND ? 0L : position)
|
||||
!= NOT_FOUND ||
|
||||
(position > 0L && changesForIteration.nextSetBit(0L) != NOT_FOUND);
|
||||
return nextPosition() >= 0;
|
||||
}
|
||||
|
||||
private long nextPosition() {
|
||||
long nextPos;
|
||||
long position = this.position;
|
||||
boolean allBitSetsScannedFromTheStart = false;
|
||||
// at most 2 iterations
|
||||
while (!allBitSetsScannedFromTheStart) {
|
||||
if (iterationMainSegmentsAreaOrTierBulk == -1) {
|
||||
allBitSetsScannedFromTheStart = position < 0;
|
||||
if ((nextPos = mainSegmentsModIterFrameForIteration.nextSetBit(nativeAccess(),
|
||||
null, mainSegmentsChangesBitSetAddr, position + 1)) != NOT_FOUND) {
|
||||
return nextPos;
|
||||
} else {
|
||||
this.position = position = NOT_FOUND;
|
||||
// go to the first bulk
|
||||
iterationMainSegmentsAreaOrTierBulk = 0;
|
||||
}
|
||||
}
|
||||
// for each allocated tier bulk
|
||||
while (iterationMainSegmentsAreaOrTierBulk < extraAllocatedTierBulkCount()) {
|
||||
if (true)
|
||||
throw new AssertionError("shouldn't be here yet");
|
||||
VanillaChronicleHash.TierBulkData tierBulkData =
|
||||
tierBulkOffsets.get(iterationMainSegmentsAreaOrTierBulk);
|
||||
tierBulkBitSetAddr = tierBulkData.langBytes.address() + tierBulkData.offset +
|
||||
offsetToBitSetWithinATierBulk;
|
||||
if ((nextPos = tierBulkModIterFrameForIteration.nextSetBit(nativeAccess(), null,
|
||||
tierBulkBitSetAddr, position + 1)) != NOT_FOUND) {
|
||||
return nextPos;
|
||||
}
|
||||
// go to the next bulk
|
||||
iterationMainSegmentsAreaOrTierBulk++;
|
||||
this.position = position = NOT_FOUND;
|
||||
}
|
||||
this.iterationMainSegmentsAreaOrTierBulk = -1;
|
||||
this.position = position = NOT_FOUND;
|
||||
bootStrapTimeStamp.set(0);
|
||||
}
|
||||
return NOT_FOUND;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -616,28 +733,36 @@ public class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? sup
|
||||
*/
|
||||
@Override
|
||||
public boolean nextEntry(@NotNull EntryCallback entryCallback, int chronicleId) {
|
||||
long position = this.position;
|
||||
while (true) {
|
||||
long oldPosition = position;
|
||||
position = changesForIteration.nextSetBit(oldPosition + 1L);
|
||||
long position = nextPosition();
|
||||
|
||||
if (position == NOT_FOUND) {
|
||||
if (oldPosition == NOT_FOUND) {
|
||||
this.position = NOT_FOUND;
|
||||
return false;
|
||||
}
|
||||
|
||||
bootStrapTimeStamp.set(0);
|
||||
continue;
|
||||
this.position = NOT_FOUND;
|
||||
return false;
|
||||
}
|
||||
|
||||
this.position = position;
|
||||
int segmentIndex = (int) (position >>> segmentIndexShift);
|
||||
int tierIndexMinusOne = (int) (position >>> segmentIndexShift);
|
||||
|
||||
try (CompiledReplicatedMapIterationContext<K, KI, MKI, V, VI, MVI, R, ?> context =
|
||||
iterationContext()) {
|
||||
context.initSegmentIndex(segmentIndex);
|
||||
if (iterationMainSegmentsAreaOrTierBulk < 0) {
|
||||
// if main area
|
||||
context.initSegmentIndex(tierIndexMinusOne);
|
||||
} else {
|
||||
long tierBaseAddr = tierIndexToBaseAddr(tierIndexMinusOne + 1);
|
||||
long tierDataAddr = tierBaseAddr + segmentHashLookupOuterSize;
|
||||
context.initSegmentIndex(TierData.segmentIndex(tierDataAddr));
|
||||
int tier = TierData.tier(tierDataAddr);
|
||||
long tierIndex = actualSegments +
|
||||
(iterationMainSegmentsAreaOrTierBulk << log2NumberOfTiersInBulk) +
|
||||
tierIndexMinusOne + 1;
|
||||
context.initSegmentTier(tier, tierIndex, tierBaseAddr);
|
||||
}
|
||||
|
||||
context.updateLock().lock();
|
||||
if (changesForUpdates.get(position)) {
|
||||
|
||||
if (changesForUpdatesGet(position)) {
|
||||
|
||||
entryCallback.onBeforeEntry();
|
||||
|
||||
@@ -646,20 +771,20 @@ public class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? sup
|
||||
|
||||
// if the entry should be ignored, we'll move the next entry
|
||||
if (entryCallback.shouldBeIgnored(context, chronicleId)) {
|
||||
changesForUpdates.clear(position);
|
||||
changesForUpdatesClear(position);
|
||||
continue;
|
||||
}
|
||||
|
||||
// it may not be successful if the buffer can not be re-sized so we will
|
||||
// process it later, by NOT clearing the changes.clear(position)
|
||||
context.entryBytes().limit(context.valueOffset() + context.valueSize());
|
||||
context.entryBytes().position(context.keySizeOffset());
|
||||
context.segmentBytes().limit(context.valueOffset() + context.valueSize());
|
||||
context.segmentBytes().position(context.keySizeOffset());
|
||||
boolean success = entryCallback.onEntry(
|
||||
context.entryBytes(), chronicleId, bootStrapTimeStamp());
|
||||
context.segmentBytes(), chronicleId, bootStrapTimeStamp());
|
||||
entryCallback.onAfterEntry();
|
||||
|
||||
if (success)
|
||||
changesForUpdates.clear(position);
|
||||
changesForUpdatesClear(position);
|
||||
|
||||
return success;
|
||||
}
|
||||
@@ -670,6 +795,26 @@ public class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? sup
|
||||
}
|
||||
}
|
||||
|
||||
private boolean changesForUpdatesGet(long position) {
|
||||
if (iterationMainSegmentsAreaOrTierBulk < 0) {
|
||||
return mainSegmentsModIterFrameForUpdates.get(nativeAccess(), null,
|
||||
mainSegmentsChangesBitSetAddr, position);
|
||||
} else {
|
||||
return tierBulkModIterFrameForUpdates.get(nativeAccess(), null,
|
||||
tierBulkBitSetAddr, position);
|
||||
}
|
||||
}
|
||||
|
||||
private void changesForUpdatesClear(long position) {
|
||||
if (iterationMainSegmentsAreaOrTierBulk < 0) {
|
||||
mainSegmentsModIterFrameForUpdates.clear(nativeAccess(), null,
|
||||
mainSegmentsChangesBitSetAddr, position);
|
||||
} else {
|
||||
tierBulkModIterFrameForUpdates.clear(nativeAccess(), null,
|
||||
tierBulkBitSetAddr, position);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the timestamp that the remote client should bootstrap from when there has been a
|
||||
* disconnection, this time maybe later than the message time as event are not send in
|
||||
@@ -689,8 +834,7 @@ public class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? sup
|
||||
// iterate over all the segments and mark bit in the modification iterator
|
||||
// that correspond to entries with an older timestamp
|
||||
boolean debugEnabled = LOG.isDebugEnabled();
|
||||
for (int i = 0; i < actualSegments; i++) {
|
||||
final int segmentIndex = i;
|
||||
for (int segmentIndex = 0; segmentIndex < actualSegments; segmentIndex++) {
|
||||
c.initSegmentIndex(segmentIndex);
|
||||
c.forEachSegmentReplicableEntry(e -> {
|
||||
if (debugEnabled) {
|
||||
@@ -708,7 +852,7 @@ public class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? sup
|
||||
if (e.originTimestamp() >= fromTimeStamp &&
|
||||
(!bootstrapOnlyLocalEntries ||
|
||||
e.originIdentifier() == localIdentifier)) {
|
||||
raiseChange(segmentIndex, c.pos(), c.timestamp());
|
||||
raiseChange(c.tierIndex(), c.pos(), c.timestamp());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ 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.OwnerThreadHolder;
|
||||
import net.openhft.chronicle.hash.impl.stage.hash.ThreadLocalCopiesHolder;
|
||||
import net.openhft.chronicle.hash.impl.stage.iter.IterationSegmentStages;
|
||||
import net.openhft.chronicle.hash.impl.stage.query.KeySearch;
|
||||
import net.openhft.chronicle.map.impl.stage.data.bytes.EntryValueBytesData;
|
||||
import net.openhft.chronicle.map.impl.stage.data.instance.WrappedValueInstanceData;
|
||||
import net.openhft.chronicle.map.impl.stage.entry.MapEntryStages;
|
||||
@@ -43,10 +45,12 @@ import net.openhft.sg.Staged;
|
||||
MapSegmentIteration.class,
|
||||
|
||||
KeyBytesInterop.class,
|
||||
SegmentStages.class,
|
||||
IterationSegmentStages.class,
|
||||
HashLookupPos.class,
|
||||
IterationCheckOnEachPublicOperation.class,
|
||||
AllocatedChunks.class,
|
||||
KeySearch.class,
|
||||
HashLookupSearch.class,
|
||||
|
||||
WrappedValueInstanceValueHolder.class,
|
||||
MapEntryStages.class,
|
||||
|
||||
@@ -51,7 +51,7 @@ import net.openhft.sg.Staged;
|
||||
KeyBytesInterop.class,
|
||||
QuerySegmentStages.class,
|
||||
KeySearch.class,
|
||||
HashLookupSearch.class,
|
||||
QueryHashLookupSearch.class,
|
||||
QueryHashLookupPos.class,
|
||||
|
||||
QueryCheckOnEachPublicOperation.class,
|
||||
|
||||
@@ -41,6 +41,4 @@ public interface QueryContextInterface<K, V, R> extends ExternalMapQueryContext<
|
||||
void initSegmentIndex(int segmentIndex);
|
||||
|
||||
boolean segmentIndexInit();
|
||||
|
||||
void clear();
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ 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.OwnerThreadHolder;
|
||||
import net.openhft.chronicle.hash.impl.stage.hash.ThreadLocalCopiesHolder;
|
||||
import net.openhft.chronicle.hash.impl.stage.iter.IterationSegmentStages;
|
||||
import net.openhft.chronicle.hash.impl.stage.query.KeySearch;
|
||||
import net.openhft.chronicle.map.impl.stage.data.DummyValueZeroData;
|
||||
import net.openhft.chronicle.map.impl.stage.data.bytes.EntryValueBytesData;
|
||||
import net.openhft.chronicle.map.impl.stage.data.instance.WrappedValueInstanceData;
|
||||
@@ -30,7 +32,6 @@ import net.openhft.chronicle.map.impl.stage.iter.ReplicatedMapAbsentDelegatingFo
|
||||
import net.openhft.chronicle.map.impl.stage.iter.ReplicatedMapEntryDelegating;
|
||||
import net.openhft.chronicle.map.impl.stage.iter.ReplicatedMapSegmentIteration;
|
||||
import net.openhft.chronicle.map.impl.stage.map.*;
|
||||
import net.openhft.chronicle.map.impl.stage.query.ReplicatedMapAbsent;
|
||||
import net.openhft.chronicle.map.impl.stage.replication.ReplicationUpdate;
|
||||
import net.openhft.sg.Context;
|
||||
import net.openhft.sg.Staged;
|
||||
@@ -45,10 +46,12 @@ import net.openhft.sg.Staged;
|
||||
ReplicatedMapSegmentIteration.class,
|
||||
|
||||
KeyBytesInterop.class,
|
||||
SegmentStages.class,
|
||||
IterationSegmentStages.class,
|
||||
HashLookupPos.class,
|
||||
IterationCheckOnEachPublicOperation.class,
|
||||
AllocatedChunks.class,
|
||||
KeySearch.class,
|
||||
HashLookupSearch.class,
|
||||
|
||||
WrappedValueInstanceValueHolder.class,
|
||||
ReplicatedMapEntryStages.class,
|
||||
|
||||
@@ -27,7 +27,10 @@ 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.*;
|
||||
import net.openhft.chronicle.hash.impl.stage.query.KeySearch;
|
||||
import net.openhft.chronicle.hash.impl.stage.query.QueryHashLookupPos;
|
||||
import net.openhft.chronicle.hash.impl.stage.query.QueryHashLookupSearch;
|
||||
import net.openhft.chronicle.hash.impl.stage.query.SearchAllocatedChunks;
|
||||
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;
|
||||
@@ -57,7 +60,7 @@ import net.openhft.sg.Staged;
|
||||
KeyBytesInterop.class,
|
||||
ReplicatedQuerySegmentStages.class,
|
||||
KeySearch.class,
|
||||
HashLookupSearch.class,
|
||||
QueryHashLookupSearch.class,
|
||||
QueryHashLookupPos.class,
|
||||
|
||||
QueryCheckOnEachPublicOperation.class,
|
||||
|
||||
+5
-3
@@ -18,6 +18,7 @@ package net.openhft.chronicle.map.impl.stage.data.bytes;
|
||||
|
||||
import net.openhft.chronicle.bytes.RandomDataInput;
|
||||
import net.openhft.chronicle.hash.AbstractData;
|
||||
import net.openhft.chronicle.hash.impl.stage.entry.SegmentStages;
|
||||
import net.openhft.chronicle.hash.impl.stage.hash.CheckOnEachPublicOperation;
|
||||
import net.openhft.chronicle.map.impl.stage.entry.MapEntryStages;
|
||||
import net.openhft.chronicle.map.impl.stage.map.ValueBytesInterop;
|
||||
@@ -29,6 +30,7 @@ import net.openhft.sg.Staged;
|
||||
public class EntryValueBytesData<V> extends AbstractData<V> {
|
||||
|
||||
@StageRef ValueBytesInterop<V, ?, ?> vi;
|
||||
@StageRef SegmentStages s;
|
||||
@StageRef MapEntryStages<?, V> entry;
|
||||
@StageRef CheckOnEachPublicOperation checkOnEachPublicOperation;
|
||||
|
||||
@@ -43,7 +45,7 @@ public class EntryValueBytesData<V> extends AbstractData<V> {
|
||||
@Override
|
||||
public RandomDataInput bytes() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return entry.entryBS;
|
||||
return s.segmentBS;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -71,7 +73,7 @@ public class EntryValueBytesData<V> extends AbstractData<V> {
|
||||
}
|
||||
|
||||
private V innerGetUsing(V usingValue) {
|
||||
entry.entryBytes.position(entry.valueOffset);
|
||||
return vi.valueReader.read(entry.entryBytes, size(), usingValue);
|
||||
s.segmentBytes.position(entry.valueOffset);
|
||||
return vi.valueReader.read(s.segmentBytes, size(), usingValue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,10 @@
|
||||
package net.openhft.chronicle.map.impl.stage.entry;
|
||||
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.hash.impl.CompactOffHeapLinearHashTable;
|
||||
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.query.KeySearch;
|
||||
import net.openhft.chronicle.map.MapEntry;
|
||||
import net.openhft.chronicle.map.VanillaChronicleMap;
|
||||
import net.openhft.chronicle.map.impl.VanillaChronicleMapHolder;
|
||||
@@ -34,6 +36,7 @@ public abstract class MapEntryStages<K, V> extends HashEntryStages<K>
|
||||
|
||||
@StageRef public VanillaChronicleMapHolder<?, ?, ?, ?, ?, ?, ?> mh;
|
||||
@StageRef public AllocatedChunks allocatedChunks;
|
||||
@StageRef KeySearch<?> ks;
|
||||
|
||||
long countValueSizeOffset() {
|
||||
return keyEnd();
|
||||
@@ -50,20 +53,20 @@ public abstract class MapEntryStages<K, V> extends HashEntryStages<K>
|
||||
|
||||
@Stage("ValueSize")
|
||||
private void countValueOffset() {
|
||||
mh.m().alignment.alignPositionAddr(entryBytes);
|
||||
valueOffset = entryBytes.position();
|
||||
mh.m().alignment.alignPositionAddr(s.segmentBytes);
|
||||
valueOffset = s.segmentBytes.position();
|
||||
}
|
||||
|
||||
void initValueSize(long valueSize) {
|
||||
this.valueSize = valueSize;
|
||||
entryBytes.position(valueSizeOffset);
|
||||
mh.m().valueSizeMarshaller.writeSize(entryBytes, valueSize);
|
||||
s.segmentBytes.position(valueSizeOffset);
|
||||
mh.m().valueSizeMarshaller.writeSize(s.segmentBytes, valueSize);
|
||||
countValueOffset();
|
||||
}
|
||||
|
||||
void initValueSize() {
|
||||
entryBytes.position(valueSizeOffset);
|
||||
valueSize = mh.m().readValueSize(entryBytes);
|
||||
s.segmentBytes.position(valueSizeOffset);
|
||||
valueSize = mh.m().readValueSize(s.segmentBytes);
|
||||
countValueOffset();
|
||||
}
|
||||
|
||||
@@ -73,13 +76,13 @@ public abstract class MapEntryStages<K, V> extends HashEntryStages<K>
|
||||
}
|
||||
|
||||
public void initValue(Data<?> value) {
|
||||
entryBytes.position(valueSizeOffset);
|
||||
s.segmentBytes.position(valueSizeOffset);
|
||||
initValueSize(value.size());
|
||||
writeValue(value);
|
||||
}
|
||||
|
||||
public void writeValue(Data<?> value) {
|
||||
value.writeTo(entryBS, valueOffset);
|
||||
value.writeTo(s.segmentBS, valueOffset);
|
||||
}
|
||||
|
||||
public void initValue_WithoutSize(
|
||||
@@ -138,15 +141,15 @@ public abstract class MapEntryStages<K, V> extends HashEntryStages<K>
|
||||
"entry takes " + newSizeInChunks + " chunks, " +
|
||||
m.maxChunksPerEntry + " is maximum.");
|
||||
}
|
||||
if (s.freeList.allClear(pos + entrySizeInChunks, pos + newSizeInChunks)) {
|
||||
s.freeList.set(pos + entrySizeInChunks, pos + newSizeInChunks);
|
||||
if (s.freeList.isRangeClear(pos + entrySizeInChunks, pos + newSizeInChunks)) {
|
||||
s.freeList.setRange(pos + entrySizeInChunks, pos + newSizeInChunks);
|
||||
break newValueDoesNotFit;
|
||||
}
|
||||
relocation(newValue, newSizeOfEverythingBeforeValue);
|
||||
return;
|
||||
} else if (newSizeInChunks < entrySizeInChunks) {
|
||||
// Freeing extra chunks
|
||||
s.freeList.clear(pos + newSizeInChunks, pos + entrySizeInChunks);
|
||||
s.freeList.clearRange(pos + newSizeInChunks, pos + entrySizeInChunks);
|
||||
// Do NOT reset nextPosToSearchFrom, because if value
|
||||
// once was larger it could easily became larger again,
|
||||
// But if these chunks will be taken by that time,
|
||||
@@ -188,8 +191,30 @@ public abstract class MapEntryStages<K, V> extends HashEntryStages<K>
|
||||
s.innerWriteLock.lock();
|
||||
s.free(pos, entrySizeInChunks);
|
||||
long entrySize = innerEntrySize(newSizeOfEverythingBeforeValue, newValue.size());
|
||||
allocatedChunks.initEntryAndKeyCopying(entrySize, valueSizeOffset - keySizeOffset);
|
||||
writeValueAndPutPos(newValue);
|
||||
// need to copy, because in initEntryAndKeyCopying(), in alloc(), nextTier() called ->
|
||||
// hashLookupPos cleared, as a dependant
|
||||
long oldHashLookupPos = hlp.hashLookupPos;
|
||||
long oldHashLookupAddr = s.segmentBaseAddr;
|
||||
|
||||
boolean tierHasChanged =
|
||||
allocatedChunks.initEntryAndKeyCopying(entrySize, valueSizeOffset - keySizeOffset);
|
||||
|
||||
if (tierHasChanged) {
|
||||
// implicitly inits key search, locating hashLookupPos on the empty slot
|
||||
assert ks.searchStateAbsent();
|
||||
}
|
||||
|
||||
initValue(newValue);
|
||||
|
||||
freeExtraAllocatedChunks();
|
||||
|
||||
CompactOffHeapLinearHashTable hl = hh.h().hashLookup;
|
||||
long oldEntry = hl.readEntry(oldHashLookupAddr, oldHashLookupPos);
|
||||
hl.checkValueForPut(pos);
|
||||
hl.writeEntryVolatile(s.segmentBaseAddr, hlp.hashLookupPos,
|
||||
oldEntry, hl.key(oldEntry), pos);
|
||||
if (tierHasChanged)
|
||||
hl.remove(oldHashLookupAddr, oldHashLookupPos);
|
||||
}
|
||||
|
||||
public final long entrySize(long keySize, long valueSize) {
|
||||
|
||||
+10
-9
@@ -43,9 +43,9 @@ public abstract class ReplicatedMapEntryStages<K, V, T> extends MapEntryStages<K
|
||||
}
|
||||
|
||||
void updateReplicationState(long timestamp, byte identifier) {
|
||||
entryBytes.position(replicationBytesOffset);
|
||||
entryBytes.writeLong(timestamp);
|
||||
entryBytes.writeByte(identifier);
|
||||
s.segmentBytes.position(replicationBytesOffset);
|
||||
s.segmentBytes.writeLong(timestamp);
|
||||
s.segmentBytes.writeByte(identifier);
|
||||
}
|
||||
|
||||
private long timestampOffset() {
|
||||
@@ -53,7 +53,7 @@ public abstract class ReplicatedMapEntryStages<K, V, T> extends MapEntryStages<K
|
||||
}
|
||||
|
||||
public long timestamp() {
|
||||
return entryBS.readLong(replicationBytesOffset);
|
||||
return s.segmentBS.readLong(replicationBytesOffset);
|
||||
}
|
||||
|
||||
private long identifierOffset() {
|
||||
@@ -61,7 +61,7 @@ public abstract class ReplicatedMapEntryStages<K, V, T> extends MapEntryStages<K
|
||||
}
|
||||
|
||||
byte identifier() {
|
||||
return entryBS.readByte(identifierOffset());
|
||||
return s.segmentBS.readByte(identifierOffset());
|
||||
}
|
||||
|
||||
private long entryDeletedOffset() {
|
||||
@@ -69,15 +69,15 @@ public abstract class ReplicatedMapEntryStages<K, V, T> extends MapEntryStages<K
|
||||
}
|
||||
|
||||
public boolean entryDeleted() {
|
||||
return entryBS.readBoolean(entryDeletedOffset());
|
||||
return s.segmentBS.readBoolean(entryDeletedOffset());
|
||||
}
|
||||
|
||||
public void writeEntryPresent() {
|
||||
entryBS.writeBoolean(entryDeletedOffset(), false);
|
||||
s.segmentBS.writeBoolean(entryDeletedOffset(), false);
|
||||
}
|
||||
|
||||
public void writeEntryDeleted() {
|
||||
entryBS.writeBoolean(entryDeletedOffset(), true);
|
||||
s.segmentBS.writeBoolean(entryDeletedOffset(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -148,8 +148,9 @@ public abstract class ReplicatedMapEntryStages<K, V, T> extends MapEntryStages<K
|
||||
@Override
|
||||
protected void relocation(Data<V> newValue, long newSizeOfEverythingBeforeValue) {
|
||||
long oldPos = pos;
|
||||
long oldTierIndex = s.tierIndex;
|
||||
super.relocation(newValue, newSizeOfEverythingBeforeValue);
|
||||
ru.moveChange(oldPos, pos);
|
||||
ru.moveChange(oldTierIndex, oldPos, pos);
|
||||
}
|
||||
|
||||
private boolean testTimeStampInSensibleRange() {
|
||||
|
||||
+2
-2
@@ -73,13 +73,13 @@ public abstract class ReplicatedMapSegmentIteration<K, V, R> extends MapSegmentI
|
||||
boolean interrupted = false;
|
||||
long startPos = 0L;
|
||||
CompactOffHeapLinearHashTable hashLookup = hh.h().hashLookup;
|
||||
while (!hashLookup.empty(hashLookup.readEntry(s.segmentBase, startPos))) {
|
||||
while (!hashLookup.empty(hashLookup.readEntry(s.segmentBaseAddr, startPos))) {
|
||||
startPos = hashLookup.step(startPos);
|
||||
}
|
||||
hlp.initHashLookupPos(startPos);
|
||||
do {
|
||||
hlp.setHashLookupPos(hashLookup.step(hlp.hashLookupPos));
|
||||
long entry = hashLookup.readEntry(s.segmentBase, hlp.hashLookupPos);
|
||||
long entry = hashLookup.readEntry(s.segmentBaseAddr, hlp.hashLookupPos);
|
||||
if (!hashLookup.empty(entry)) {
|
||||
e.readExistingEntry(hashLookup.value(entry));
|
||||
ReplicableEntry e = !this.e.entryDeleted() ? entryDelegating :
|
||||
|
||||
@@ -19,7 +19,8 @@ package net.openhft.chronicle.map.impl.stage.query;
|
||||
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.entry.HashLookupSearch;
|
||||
import net.openhft.chronicle.hash.impl.stage.query.HashQuery.EntryPresence;
|
||||
import net.openhft.chronicle.hash.impl.stage.query.KeySearch;
|
||||
import net.openhft.chronicle.map.MapAbsentEntry;
|
||||
import net.openhft.chronicle.map.MapContext;
|
||||
@@ -76,6 +77,7 @@ public abstract class MapAbsent<K, V> implements MapAbsentEntry<K, V> {
|
||||
}
|
||||
s.incrementModCount();
|
||||
ks.setSearchState(PRESENT);
|
||||
q.initPresenceOfEntry(EntryPresence.PRESENT);
|
||||
} else {
|
||||
throw new IllegalStateException(
|
||||
"Entry is present in the map when doInsert() is called");
|
||||
|
||||
@@ -92,6 +92,7 @@ public abstract class MapQuery<K, V, R> extends HashQuery<K>
|
||||
e.innerDefaultReplaceValue(newValue);
|
||||
s.incrementModCount();
|
||||
ks.setSearchState(PRESENT);
|
||||
initPresenceOfEntry(EntryPresence.PRESENT);
|
||||
} else {
|
||||
throw new IllegalStateException(
|
||||
"Entry is absent in the map when doReplaceValue() is called");
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package net.openhft.chronicle.map.impl.stage.query;
|
||||
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.hash.impl.stage.query.HashLookupSearch;
|
||||
import net.openhft.chronicle.hash.impl.stage.entry.HashLookupSearch;
|
||||
import net.openhft.chronicle.map.impl.stage.entry.MapEntryStages;
|
||||
import net.openhft.sg.StageRef;
|
||||
import net.openhft.sg.Staged;
|
||||
@@ -44,9 +44,9 @@ public abstract class QueryMapEntryStages<K, V> extends MapEntryStages<K, V> {
|
||||
} else {
|
||||
newSizeInChunks = entrySizeInChunks;
|
||||
}
|
||||
if (pos + newSizeInChunks < s.freeList.size() &&
|
||||
s.freeList.allClear(pos, pos + newSizeInChunks)) {
|
||||
s.freeList.set(pos, pos + newSizeInChunks);
|
||||
if (pos + newSizeInChunks < s.freeList.logicalSize() &&
|
||||
s.freeList.isRangeClear(pos, pos + newSizeInChunks)) {
|
||||
s.freeList.setRange(pos, pos + newSizeInChunks);
|
||||
s.innerWriteLock.lock();
|
||||
allocatedChunks.incrementSegmentEntriesIfNeeded();
|
||||
if (newValueSizeIsDifferent) {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package net.openhft.chronicle.map.impl.stage.query;
|
||||
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.hash.impl.stage.query.HashQuery.EntryPresence;
|
||||
import net.openhft.chronicle.map.impl.stage.entry.ReplicatedMapEntryStages;
|
||||
import net.openhft.chronicle.map.impl.stage.replication.ReplicationUpdate;
|
||||
import net.openhft.sg.StageRef;
|
||||
@@ -38,6 +39,7 @@ public abstract class ReplicatedMapAbsent<K, V> extends MapAbsent<K, V> {
|
||||
if (!ks.searchStatePresent()) {
|
||||
putEntry(value);
|
||||
ks.setSearchState(PRESENT);
|
||||
q.initPresenceOfEntry(EntryPresence.PRESENT);
|
||||
} else {
|
||||
e.innerDefaultReplaceValue(value);
|
||||
s.deleted(s.deleted() - 1);
|
||||
|
||||
+10
-15
@@ -45,25 +45,20 @@ public abstract class ReplicatedQuerySegmentStages extends QuerySegmentStages {
|
||||
|
||||
@Override
|
||||
public long alloc(int chunks) {
|
||||
long ret = allocReturnCode(chunks);
|
||||
if (ret >= 0) {
|
||||
return ret;
|
||||
} else {
|
||||
ReplicatedChronicleMap<?, ?, ?, ?, ?, ?, ?> map = mh.m();
|
||||
MapSegmentContext<?, ?, ?> sc = map.segmentContext(segmentIndex);
|
||||
((ReplicatedHashSegmentContext<?, ?>) sc).forEachSegmentReplicableEntry(cleanupAction);
|
||||
ret = allocReturnCode(chunks);
|
||||
while (true) {
|
||||
long ret = allocReturnCode(chunks);
|
||||
if (ret >= 0) {
|
||||
return ret;
|
||||
} else {
|
||||
if (chunks == 1) {
|
||||
throw new IllegalStateException(
|
||||
"Segment is full, no free entries found");
|
||||
ReplicatedChronicleMap<?, ?, ?, ?, ?, ?, ?> map = mh.m();
|
||||
MapSegmentContext<?, ?, ?> sc = map.segmentContext(segmentIndex);
|
||||
((ReplicatedHashSegmentContext<?, ?>) sc)
|
||||
.forEachSegmentReplicableEntry(cleanupAction);
|
||||
ret = allocReturnCode(chunks);
|
||||
if (ret >= 0) {
|
||||
return ret;
|
||||
} else {
|
||||
throw new IllegalStateException(
|
||||
"Segment is full or has no ranges of " + chunks
|
||||
+ " continuous free chunks"
|
||||
);
|
||||
nextTier();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -45,11 +45,11 @@ public abstract class ReplicationUpdate<K> implements RemoteOperationContext<K>
|
||||
}
|
||||
|
||||
public void dropChange() {
|
||||
mh.m().dropChange(s.segmentIndex, e.pos);
|
||||
mh.m().dropChange(s.tierIndex, e.pos);
|
||||
}
|
||||
|
||||
public void moveChange(long oldPos, long newPos) {
|
||||
mh.m().moveChange(s.segmentIndex, oldPos, newPos, e.timestamp());
|
||||
public void moveChange(long oldTierIndex, long oldPos, long newPos) {
|
||||
mh.m().moveChange(oldTierIndex, oldPos, s.tierIndex, newPos, e.timestamp());
|
||||
}
|
||||
|
||||
public void updateChange() {
|
||||
@@ -59,11 +59,11 @@ public abstract class ReplicationUpdate<K> implements RemoteOperationContext<K>
|
||||
}
|
||||
|
||||
public void raiseChange() {
|
||||
mh.m().raiseChange(s.segmentIndex, e.pos, e.timestamp());
|
||||
mh.m().raiseChange(s.tierIndex, e.pos, e.timestamp());
|
||||
}
|
||||
|
||||
public boolean changed() {
|
||||
return mh.m().isChanged(s.segmentIndex, e.pos);
|
||||
return mh.m().isChanged(s.tierIndex, e.pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user