Cody tidy and optimise the tracing code.

This commit is contained in:
Peter Lawrey
2020-06-18 13:17:58 +01:00
parent b167ec59eb
commit 8dfc91b1eb
15 changed files with 260 additions and 145 deletions
@@ -239,7 +239,8 @@ public abstract class VanillaChronicleHash<K,
public Runnable getPreShutdownAction() {
throwExceptionIfClosed();
return preShutdownAction;
return preShutdownAction;
}
protected void readMarshallableFields(@NotNull WireIn wireIn) {
@@ -341,7 +342,8 @@ public abstract class VanillaChronicleHash<K,
public VanillaGlobalMutableState globalMutableState() {
throwExceptionIfClosed();
return globalMutableState;
return globalMutableState;
}
private long tierSize() {
@@ -383,7 +385,8 @@ public abstract class VanillaChronicleHash<K,
public void initTransients() {
throwExceptionIfClosed();
initOwnTransients();
initOwnTransients();
}
private void initOwnTransients() {
@@ -477,17 +480,20 @@ public abstract class VanillaChronicleHash<K,
public void setResourcesName() {
throwExceptionIfClosed();
resources.setChronicleHashIdentityString(toIdentityString());
resources.setChronicleHashIdentityString(toIdentityString());
}
public void registerCleaner() {
throwExceptionIfClosed();
this.cleaner = CleanerUtils.createCleaner(this, resources);
this.cleaner = CleanerUtils.createCleaner(this, resources);
}
public void addToOnExitHook() {
throwExceptionIfClosed();
if (!skipCloseOnExitHook) {
if (!skipCloseOnExitHook) {
ChronicleHashCloseOnExitHook.add(this);
}
}
@@ -619,14 +625,16 @@ public abstract class VanillaChronicleHash<K,
public void onHeaderCreated() {
throwExceptionIfClosed();
}
}
/**
* @return the version of Chronicle Map that was used to create the current data file
*/
public String persistedDataVersion() {
throwExceptionIfClosed();
return dataFileVersion;
return dataFileVersion;
}
private long segmentHeadersOffset() {
@@ -646,7 +654,8 @@ public abstract class VanillaChronicleHash<K,
public long mapHeaderInnerSize() {
throwExceptionIfClosed();
return headerSize + globalMutableStateTotalUsedSize();
return headerSize + globalMutableStateTotalUsedSize();
}
@Override
@@ -691,7 +700,8 @@ public abstract class VanillaChronicleHash<K,
@Override
public boolean isOpen() {
throwExceptionIfClosed();
return !resources.closed();
return !resources.closed();
}
public final void checkKey(Object key) {
@@ -710,7 +720,8 @@ public abstract class VanillaChronicleHash<K,
public long bsAddress() {
throwExceptionIfClosed();
return bs.addressForRead(0);
return bs.addressForRead(0);
}
public final long segmentBaseAddr(int segmentIndex) {
@@ -742,7 +753,8 @@ public abstract class VanillaChronicleHash<K,
@Override
public int segments() {
throwExceptionIfClosed();
return actualSegments;
return actualSegments;
}
private long globalMutableStateAddress() {
@@ -751,7 +763,8 @@ public abstract class VanillaChronicleHash<K,
public void globalMutableStateLock() {
throwExceptionIfClosed();
globalMutableStateLockAcquisitionStrategy.acquire(
globalMutableStateLockAcquisitionStrategy.acquire(
globalMutableStateLockTryAcquireOperation, globalMutableStateLockingStrategy,
nativeAccess(), null,
globalMutableStateAddress() + GLOBAL_MUTABLE_STATE_LOCK_OFFSET);
@@ -759,7 +772,8 @@ public abstract class VanillaChronicleHash<K,
public void globalMutableStateUnlock() {
throwExceptionIfClosed();
globalMutableStateLockingStrategy.unlock(nativeAccess(), null,
globalMutableStateLockingStrategy.unlock(nativeAccess(), null,
globalMutableStateAddress() + GLOBAL_MUTABLE_STATE_LOCK_OFFSET);
}
@@ -768,18 +782,21 @@ public abstract class VanillaChronicleHash<K,
*/
public boolean hasExtraTierBulks() {
throwExceptionIfClosed();
return globalMutableState.getAllocatedExtraTierBulks() > 0;
return globalMutableState.getAllocatedExtraTierBulks() > 0;
}
@Override
public long offHeapMemoryUsed() {
throwExceptionIfClosed();
return resources.totalMemory();
return resources.totalMemory();
}
public long allocateTier() {
throwExceptionIfClosed();
globalMutableStateLock();
globalMutableStateLock();
try {
long tiersInUse = globalMutableState.getExtraTiersInUse();
if (tiersInUse >= maxExtraTiers) {
@@ -856,7 +873,8 @@ public abstract class VanillaChronicleHash<K,
public void msync() throws IOException {
throwExceptionIfClosed();
if (persisted()) {
if (persisted()) {
msync(bsAddress(), bs.capacity());
}
}
@@ -877,7 +895,8 @@ public abstract class VanillaChronicleHash<K,
public void linkAndZeroOutFreeTiers(long firstTierIndex, long lastTierIndex) {
throwExceptionIfClosed();
for (long tierIndex = firstTierIndex; tierIndex <= lastTierIndex; tierIndex++) {
for (long tierIndex = firstTierIndex; tierIndex <= lastTierIndex; tierIndex++) {
long tierOffset = tierBytesOffset(tierIndex);
BytesStore tierBytesStore = tierBytesStore(tierIndex);
zeroOutNewlyMappedTier(tierBytesStore, tierOffset);
@@ -891,12 +910,14 @@ public abstract class VanillaChronicleHash<K,
public long extraTierIndexToTierIndex(long extraTierIndex) {
throwExceptionIfClosed();
return actualSegments + extraTierIndex + 1;
return actualSegments + extraTierIndex + 1;
}
public long tierIndexToBaseAddr(long tierIndex) {
throwExceptionIfClosed();
// tiers are 1-counted, to allow tierIndex = 0 to be un-initialized in off-heap memory,
// tiers are 1-counted, to allow tierIndex = 0 to be un-initialized in off-heap memory,
// convert into 0-based form
long tierIndexMinusOne = tierIndex - 1;
if (tierIndexMinusOne < actualSegments)
@@ -906,7 +927,8 @@ public abstract class VanillaChronicleHash<K,
public BytesStore tierBytesStore(long tierIndex) {
throwExceptionIfClosed();
long tierIndexMinusOne = tierIndex - 1;
long tierIndexMinusOne = tierIndex - 1;
if (tierIndexMinusOne < actualSegments)
return bs;
return tierBulkData(tierIndexMinusOne).bytesStore;
@@ -914,7 +936,8 @@ public abstract class VanillaChronicleHash<K,
public long tierBytesOffset(long tierIndex) {
throwExceptionIfClosed();
long tierIndexMinusOne = tierIndex - 1;
long tierIndexMinusOne = tierIndex - 1;
if (tierIndexMinusOne < actualSegments)
return segmentOffset(tierIndexMinusOne);
long extraTierIndex = tierIndexMinusOne - actualSegments;
@@ -1050,7 +1073,8 @@ public abstract class VanillaChronicleHash<K,
public void addCloseable(Closeable closeable) {
throwExceptionIfClosed();
resources.addCloseable(closeable);
resources.addCloseable(closeable);
}
/**
@@ -1058,7 +1082,8 @@ public abstract class VanillaChronicleHash<K,
*/
public List<WeakReference<ContextHolder>> allContexts() {
throwExceptionIfClosed();
return Collections.unmodifiableList(resources.contexts());
return Collections.unmodifiableList(resources.contexts());
}
public static class TierBulkData {
@@ -1083,7 +1108,8 @@ public abstract class VanillaChronicleHash<K,
public class Identity {
public VanillaChronicleHash hash() {
throwExceptionIfClosed();
return VanillaChronicleHash.this;
return VanillaChronicleHash.this;
}
}
}
@@ -56,7 +56,8 @@ public abstract class HashSegmentIteration<K, E extends HashEntry<K>>
public long tierEntriesForIteration() {
throwExceptionIfClosed();
return s.tierEntries();
return s.tierEntries();
}
abstract boolean entryRemovedOnThisIterationInit();
@@ -69,7 +70,8 @@ public abstract class HashSegmentIteration<K, E extends HashEntry<K>>
public void initHashLookupEntry(long entry) {
throwExceptionIfClosed();
hashLookupEntry = entry;
hashLookupEntry = entry;
}
abstract void closeHashLookupEntry();
@@ -77,7 +79,8 @@ public abstract class HashSegmentIteration<K, E extends HashEntry<K>>
@Override
public boolean forEachSegmentEntryWhile(Predicate<? super E> predicate) {
throwExceptionIfClosed();
checkOnEachPublicOperation.checkOnEachPublicOperation();
checkOnEachPublicOperation.checkOnEachPublicOperation();
s.innerUpdateLock.lock();
return innerForEachSegmentEntryWhile(predicate);
}
@@ -178,12 +181,14 @@ public abstract class HashSegmentIteration<K, E extends HashEntry<K>>
public void hookAfterEachIteration() {
throwExceptionIfClosed();
}
}
@Override
public void forEachSegmentEntry(Consumer<? super E> action) {
throwExceptionIfClosed();
forEachSegmentEntryWhile(e -> {
forEachSegmentEntryWhile(e -> {
action.accept(e);
return true;
});
@@ -191,7 +196,8 @@ public abstract class HashSegmentIteration<K, E extends HashEntry<K>>
public void checkEntryNotRemovedOnThisIteration() {
throwExceptionIfClosed();
if (entryRemovedOnThisIterationInit()) {
if (entryRemovedOnThisIterationInit()) {
throw new IllegalStateException(
hh.h().toIdentityString() + ": Entry was already removed on this iteration");
}
@@ -200,7 +206,8 @@ public abstract class HashSegmentIteration<K, E extends HashEntry<K>>
@Override
public void doRemove() {
throwExceptionIfClosed();
checkOnEachPublicOperation.checkOnEachPublicOperation();
checkOnEachPublicOperation.checkOnEachPublicOperation();
s.innerWriteLock.lock();
try {
iterationRemove();
@@ -212,7 +219,8 @@ public abstract class HashSegmentIteration<K, E extends HashEntry<K>>
public void iterationRemove() {
throwExceptionIfClosed();
// this condition mean -- some other entry taken place of the removed one
// this condition mean -- some other entry taken place of the removed one
if (hh.h().hashLookup.remove(s.tierBaseAddr, hlp.hashLookupPos) != hlp.hashLookupPos) {
// if so, should make step back, to compensate step forward on the next iteration,
// to consume the shifted entry
@@ -45,7 +45,8 @@ public abstract class SegmentsRecovery implements IterationContext {
ChronicleHashCorruption.Listener corruptionListener,
ChronicleHashCorruptionImpl corruption) {
throwExceptionIfClosed();
VanillaChronicleHash<?, ?, ?, ?> h = hh.h();
VanillaChronicleHash<?, ?, ?, ?> h = hh.h();
for (int segmentIndex = 0; segmentIndex < h.actualSegments; segmentIndex++) {
s.initSegmentIndex(segmentIndex);
resetSegmentLock(corruptionListener, corruption);
@@ -330,8 +330,7 @@ public final class ChronicleMapBuilder<K, V> implements
return valueBuilder.sizeIsStaticallyKnown;
}
private static void checkSegments(long segments) {
private static void checkSegments(long segments) {
if (segments <= 0) {
throw new IllegalArgumentException("segments should be positive, " +
segments + " given");
@@ -115,7 +115,8 @@ class OldDeletedEntriesCleanupThread extends Thread
@Override
public void run() {
throwExceptionIfClosed();
if (System.currentTimeMillis() - startTime < 1_000)
if (System.currentTimeMillis() - startTime < 1_000)
return;
while (!shutdown) {
@@ -177,7 +178,8 @@ class OldDeletedEntriesCleanupThread extends Thread
@Override
public boolean test(ReplicableEntry e) {
throwExceptionIfClosed();
if (shutdown)
if (shutdown)
return false;
if (e instanceof MapAbsentEntry) {
long deleteTimeout = systemTimeIntervalBetween(
@@ -173,13 +173,15 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
@Override
public ReplicatedGlobalMutableState globalMutableState() {
throwExceptionIfClosed();
return (ReplicatedGlobalMutableState) super.globalMutableState();
return (ReplicatedGlobalMutableState) super.globalMutableState();
}
@Override
public void initTransients() {
throwExceptionIfClosed();
super.initTransients();
super.initTransients();
initOwnTransients();
}
@@ -236,25 +238,29 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
@Override
public long mapHeaderInnerSize() {
throwExceptionIfClosed();
return super.mapHeaderInnerSize() + (segmentModIterBitSetsForIdentifierOuterSize * 128);
return super.mapHeaderInnerSize() + (segmentModIterBitSetsForIdentifierOuterSize * 128);
}
@Override
public void setRemoteNodeCouldBootstrapFrom(byte remoteIdentifier, long bootstrapTimestamp) {
throwExceptionIfClosed();
remoteNodeCouldBootstrapFrom[remoteIdentifier] = bootstrapTimestamp;
remoteNodeCouldBootstrapFrom[remoteIdentifier] = bootstrapTimestamp;
}
@Override
public long remoteNodeCouldBootstrapFrom(byte remoteIdentifier) {
throwExceptionIfClosed();
return remoteNodeCouldBootstrapFrom[remoteIdentifier];
return remoteNodeCouldBootstrapFrom[remoteIdentifier];
}
@Override
public void onHeaderCreated() {
throwExceptionIfClosed();
// Pad modification iterators at 3 cache lines from the end of the map header,
// Pad modification iterators at 3 cache lines from the end of the map header,
// to avoid false sharing with the header of the first segment
startOfModificationIterators = super.mapHeaderInnerSize() +
RESERVED_GLOBAL_MUTABLE_STATE_BYTES - BYTES.convert(3, CACHE_LINES);
@@ -269,7 +275,8 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
@Override
public byte identifier() {
throwExceptionIfClosed();
byte id = localIdentifier;
byte id = localIdentifier;
if (id == 0) {
throw new IllegalStateException("Replication identifier is not set for this\n" +
"replicated Chronicle Map. This should only be possible if persisted\n" +
@@ -291,7 +298,8 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
@Override
public ModificationIterator acquireModificationIterator(byte remoteIdentifier) {
throwExceptionIfClosed();
ModificationIterator modificationIterator = modificationIterators.get(remoteIdentifier);
ModificationIterator modificationIterator = modificationIterators.get(remoteIdentifier);
if (modificationIterator != null)
return modificationIterator;
@@ -334,7 +342,8 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
public ModificationIterator[] acquireAllModificationIterators() {
throwExceptionIfClosed();
for (int remoteIdentifier = 0; remoteIdentifier < 128; remoteIdentifier++) {
for (int remoteIdentifier = 0; remoteIdentifier < 128; remoteIdentifier++) {
if (globalMutableState().getModificationIteratorInitAt(remoteIdentifier)) {
acquireModificationIterator((byte) remoteIdentifier);
}
@@ -351,24 +360,28 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
public long changeCount() {
throwExceptionIfClosed();
return changeCount.get();
return changeCount.get();
}
public void raiseChange(long tierIndex, long pos) {
throwExceptionIfClosed();
// -1 is invalid remoteIdentifier => raise change for all
// -1 is invalid remoteIdentifier => raise change for all
changeCount.incrementAndGet();
raiseChangeForAllExcept(tierIndex, pos, (byte) -1);
}
public void raiseChangeFor(long tierIndex, long pos, byte remoteIdentifier) {
throwExceptionIfClosed();
acquireModificationIterator(remoteIdentifier).raiseChange0(tierIndex, pos);
acquireModificationIterator(remoteIdentifier).raiseChange0(tierIndex, pos);
}
public void raiseChangeForAllExcept(long tierIndex, long pos, byte remoteIdentifier) {
throwExceptionIfClosed();
updateModificationIteratorsArray();
updateModificationIteratorsArray();
if (tierIndex <= actualSegments) {
long segmentIndex = tierIndex - 1;
long offsetToTierBitSet = segmentIndex * tierModIterBitSetOuterSize;
@@ -390,7 +403,8 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
public void dropChange(long tierIndex, long pos) {
throwExceptionIfClosed();
updateModificationIteratorsArray();
updateModificationIteratorsArray();
if (tierIndex <= actualSegments) {
long segmentIndex = tierIndex - 1;
long offsetToTierBitSet = segmentIndex * tierModIterBitSetOuterSize;
@@ -410,12 +424,14 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
public void dropChangeFor(long tierIndex, long pos, byte remoteIdentifier) {
throwExceptionIfClosed();
acquireModificationIterator(remoteIdentifier).dropChange0(tierIndex, pos);
acquireModificationIterator(remoteIdentifier).dropChange0(tierIndex, pos);
}
public void moveChange(long oldTierIndex, long oldPos, long newTierIndex, long newPos) {
throwExceptionIfClosed();
updateModificationIteratorsArray();
updateModificationIteratorsArray();
if (oldTierIndex <= actualSegments) {
long oldSegmentIndex = oldTierIndex - 1;
long oldOffsetToTierBitSet = oldSegmentIndex * tierModIterBitSetOuterSize;
@@ -470,7 +486,8 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
public boolean isChanged(long tierIndex, long pos) {
throwExceptionIfClosed();
updateModificationIteratorsArray();
updateModificationIteratorsArray();
if (tierIndex <= actualSegments) {
long segmentIndex = tierIndex - 1;
long offsetToTierBitSet = segmentIndex * tierModIterBitSetOuterSize;
@@ -494,14 +511,16 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
@Override
public boolean identifierCheck(@NotNull ReplicableEntry entry, int chronicleId) {
throwExceptionIfClosed();
return entry.originIdentifier() == identifier();
return entry.originIdentifier() == identifier();
}
@Override
public void writeExternalEntry(
ReplicableEntry entry, Bytes payload, @NotNull Bytes destination, int chronicleId, ArrayList<String> keys) {
throwExceptionIfClosed();
if (payload != null)
if (payload != null)
writePayload(payload, destination);
if (entry != null)
writeExternalEntry0(entry, destination, keys);
@@ -594,7 +613,8 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
@Override
public void readExternalEntry(@NotNull Bytes source, byte remoteNodeIdentifier) {
throwExceptionIfClosed();
byte hunk = source.readByte();
byte hunk = source.readByte();
if (hunk == BOOTSTRAP_TIME_HUNK) {
setRemoteNodeCouldBootstrapFrom(remoteNodeIdentifier, source.readLong());
} else {
@@ -619,8 +639,7 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
CompiledReplicatedMapIterationContext::new, this);
}
@Override
@Override
public final V get(Object key) {
return defaultGet(key);
}
@@ -630,8 +649,7 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
return defaultGetUsing(key, usingValue);
}
/**
/**
* <p>
* Once a change occurs to a map, map replication requires that these changes are picked up
* by another thread, this class provides an iterator like interface to poll for such changes.
@@ -705,7 +723,8 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
public void setModificationNotifier(@NotNull ModificationNotifier modificationNotifier) {
throwExceptionIfClosed();
this.modificationNotifier = modificationNotifier;
this.modificationNotifier = modificationNotifier;
}
void raiseChangeInSegment(long offsetToTierBitSet, long pos) {
@@ -760,7 +779,8 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
@Override
public boolean hasNext() {
throwExceptionIfClosed();
return nextEntryPos(null, 0) != NOT_FOUND;
return nextEntryPos(null, 0) != NOT_FOUND;
}
private long nextEntryPos(Callback callback, int chronicleId) {
@@ -849,7 +869,8 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
@Override
public boolean nextEntry(@NotNull Callback callback, int chronicleId) {
throwExceptionIfClosed();
while (true) {
while (true) {
long nextEntryPos = nextEntryPos(callback, chronicleId);
if (nextEntryPos == NOT_FOUND)
return false;
@@ -900,7 +921,8 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
@Override
public void dirtyEntries(long fromTimeStamp) {
throwExceptionIfClosed();
try (CompiledReplicatedMapIterationContext<K, V, R> c = iterationContext()) {
try (CompiledReplicatedMapIterationContext<K, V, R> c = iterationContext()) {
// iterate over all the segments and mark bit in the modification iterator
// that correspond to entries with an older timestamp
boolean debugEnabled = LOG.isDebugEnabled();
@@ -962,7 +984,8 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
public void clearRange0(long tierIndex, long pos, long endPosExclusive) {
throwExceptionIfClosed();
if (tierIndex <= actualSegments) {
if (tierIndex <= actualSegments) {
long segmentIndex = tierIndex - 1;
long offsetToTierBitSet = segmentIndex * tierModIterBitSetOuterSize;
tierModIterFrame.clearRange(nativeAccess(), null,
@@ -163,7 +163,8 @@ public class VanillaChronicleMap<K, V, R>
@Override
public void initTransients() {
throwExceptionIfClosed();
super.initTransients();
super.initTransients();
initOwnTransients();
}
@@ -171,7 +172,8 @@ public class VanillaChronicleMap<K, V, R>
ChronicleHashResources resources, ChronicleHashCorruption.Listener corruptionListener,
ChronicleHashCorruptionImpl corruption) throws IOException {
throwExceptionIfClosed();
basicRecover(resources, corruptionListener, corruption);
basicRecover(resources, corruptionListener, corruption);
try (IterationContext<K, V, ?> iterationContext = iterationContext()) {
iterationContext.recoverSegments(corruptionListener, corruption);
}
@@ -216,25 +218,29 @@ public class VanillaChronicleMap<K, V, R>
@Override
public Class<K> keyClass() {
throwExceptionIfClosed();
return (Class<K>) keyClass;
return (Class<K>) keyClass;
}
@Override
public Type keyType() {
throwExceptionIfClosed();
return keyClass;
return keyClass;
}
@Override
public Class<V> valueClass() {
throwExceptionIfClosed();
return (Class<V>) valueClass;
return (Class<V>) valueClass;
}
@Override
public Type valueType() {
throwExceptionIfClosed();
return valueClass;
return valueClass;
}
private long tiersUsed() {
@@ -248,14 +254,15 @@ public class VanillaChronicleMap<K, V, R>
@Override
public int remainingAutoResizes() {
throwExceptionIfClosed();
return (int) (maxTiers() - tiersUsed());
return (int) (maxTiers() - tiersUsed());
}
@Override
public short percentageFreeSpace() {
throwExceptionIfClosed();
double totalUsed = 0;
double totalUsed = 0;
double totalSize = 0;
try (IterationContext<K, V, ?> c = iterationContext()) {
@@ -320,13 +327,15 @@ public class VanillaChronicleMap<K, V, R>
@Override
public int hashCode() {
throwExceptionIfClosed();
return mapHashCode();
return mapHashCode();
}
@Override
public boolean equals(Object obj) {
throwExceptionIfClosed();
return mapEquals(obj);
return mapEquals(obj);
}
@Override
@@ -342,7 +351,8 @@ public class VanillaChronicleMap<K, V, R>
@Override
public String toIdentityString() {
throwExceptionIfClosed();
if (identityString == null)
if (identityString == null)
identityString = makeIdentityString();
return identityString;
}
@@ -360,7 +370,8 @@ public class VanillaChronicleMap<K, V, R>
@Override
public void clear() {
throwExceptionIfClosed();
forEachEntry(c -> c.context().remove(c));
forEachEntry(c -> c.context().remove(c));
}
public final long readValueSize(Bytes entry) {
@@ -371,7 +382,8 @@ public class VanillaChronicleMap<K, V, R>
public void alignReadPosition(Bytes entry) {
throwExceptionIfClosed();
long positionAddr = entry.addressForRead(entry.readPosition());
long positionAddr = entry.addressForRead(entry.readPosition());
long skip = alignAddr(positionAddr, alignment) - positionAddr;
if (skip > 0)
entry.readSkip(skip);
@@ -535,7 +547,8 @@ public class VanillaChronicleMap<K, V, R>
@Override
public V get(Object key) {
throwExceptionIfClosed();
return defaultEntryOperationsAndMethods ? optimizedGet(key, null) : defaultGet(key);
return defaultEntryOperationsAndMethods ? optimizedGet(key, null) : defaultGet(key);
}
final V defaultGet(Object key) {
@@ -709,7 +722,8 @@ public class VanillaChronicleMap<K, V, R>
@Override
public V getUsing(K key, V usingValue) {
throwExceptionIfClosed();
return defaultEntryOperationsAndMethods ? optimizedGet(key, usingValue) :
return defaultEntryOperationsAndMethods ? optimizedGet(key, usingValue) :
defaultGetUsing(key, usingValue);
}
@@ -724,7 +738,8 @@ public class VanillaChronicleMap<K, V, R>
@Override
public V acquireUsing(K key, V usingValue) {
throwExceptionIfClosed();
try (QueryContextInterface<K, V, R> q = queryContext(key)) {
try (QueryContextInterface<K, V, R> q = queryContext(key)) {
return acquireUsingBody(q, usingValue);
}
}
@@ -738,7 +753,8 @@ public class VanillaChronicleMap<K, V, R>
@Override
public V putIfAbsent(K key, V value) {
throwExceptionIfClosed();
checkValue(value);
checkValue(value);
try (QueryContextInterface<K, V, R> q = queryContext(key)) {
methods.putIfAbsent(q, q.inputValueDataAccess().getData(value), q.defaultReturnValue());
return q.defaultReturnValue().returnValue();
@@ -748,7 +764,8 @@ public class VanillaChronicleMap<K, V, R>
@Override
public boolean remove(Object key, Object value) {
throwExceptionIfClosed();
if (value == null)
if (value == null)
return false; // ConcurrentHashMap compatibility
V v = checkValue(value);
try (QueryContextInterface<K, V, R> q = queryContext(key)) {
@@ -759,7 +776,8 @@ public class VanillaChronicleMap<K, V, R>
@Override
public boolean replace(K key, V oldValue, V newValue) {
throwExceptionIfClosed();
checkValue(oldValue);
checkValue(oldValue);
checkValue(newValue);
try (QueryContextInterface<K, V, R> q = queryContext(key)) {
return methods.replace(
@@ -770,7 +788,8 @@ public class VanillaChronicleMap<K, V, R>
@Override
public V replace(K key, V value) {
throwExceptionIfClosed();
checkValue(value);
checkValue(value);
try (QueryContextInterface<K, V, R> q = queryContext(key)) {
methods.replace(q, q.inputValueDataAccess().getData(value), q.defaultReturnValue());
return q.defaultReturnValue().returnValue();
@@ -780,7 +799,8 @@ public class VanillaChronicleMap<K, V, R>
@Override
public boolean containsKey(Object key) {
throwExceptionIfClosed();
try (QueryContextInterface<K, V, R> q = queryContext(key)) {
try (QueryContextInterface<K, V, R> q = queryContext(key)) {
return methods.containsKey(q);
}
}
@@ -788,7 +808,8 @@ public class VanillaChronicleMap<K, V, R>
@Override
public V put(K key, V value) {
throwExceptionIfClosed();
checkValue(value);
checkValue(value);
try (QueryContextInterface<K, V, R> q = queryContext(key)) {
Data<V> valueData = q.inputValueDataAccess().getData(value);
InstanceReturnValue<V> returnValue =
@@ -801,7 +822,8 @@ public class VanillaChronicleMap<K, V, R>
@Override
public V remove(Object key) {
throwExceptionIfClosed();
try (QueryContextInterface<K, V, R> q = queryContext(key)) {
try (QueryContextInterface<K, V, R> q = queryContext(key)) {
InstanceReturnValue<V> returnValue =
removeReturnsNull ? NullReturnValue.get() : q.defaultReturnValue();
methods.remove(q, returnValue);
@@ -813,7 +835,8 @@ public class VanillaChronicleMap<K, V, R>
public V merge(K key, V value,
BiFunction<? super V, ? super V, ? extends V> remappingFunction) {
throwExceptionIfClosed();
try (QueryContextInterface<K, V, R> q = queryContext(key)) {
try (QueryContextInterface<K, V, R> q = queryContext(key)) {
methods.merge(q, q.inputValueDataAccess().getData(value), remappingFunction,
q.defaultReturnValue());
return q.defaultReturnValue().returnValue();
@@ -823,7 +846,8 @@ public class VanillaChronicleMap<K, V, R>
@Override
public V compute(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
throwExceptionIfClosed();
try (QueryContextInterface<K, V, R> q = queryContext(key)) {
try (QueryContextInterface<K, V, R> q = queryContext(key)) {
methods.compute(q, remappingFunction, q.defaultReturnValue());
return q.defaultReturnValue().returnValue();
}
@@ -832,7 +856,8 @@ public class VanillaChronicleMap<K, V, R>
@Override
public V computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) {
throwExceptionIfClosed();
try (QueryContextInterface<K, V, R> q = queryContext(key)) {
try (QueryContextInterface<K, V, R> q = queryContext(key)) {
methods.computeIfAbsent(q, mappingFunction, q.defaultReturnValue());
return q.defaultReturnValue().returnValue();
}
@@ -842,7 +867,8 @@ public class VanillaChronicleMap<K, V, R>
public V computeIfPresent(K key,
BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
throwExceptionIfClosed();
try (QueryContextInterface<K, V, R> q = queryContext(key)) {
try (QueryContextInterface<K, V, R> q = queryContext(key)) {
methods.computeIfPresent(q, remappingFunction, q.defaultReturnValue());
return q.defaultReturnValue().returnValue();
}
@@ -850,7 +876,8 @@ public class VanillaChronicleMap<K, V, R>
public void verifyTierCountersAreaData() {
throwExceptionIfClosed();
for (int i = 0; i < actualSegments; i++) {
for (int i = 0; i < actualSegments; i++) {
try (MapSegmentContext<K, V, ?> c = segmentContext(i)) {
Method verifyTierCountersAreaData =
c.getClass().getMethod("verifyTierCountersAreaData");
@@ -38,8 +38,7 @@ public enum ZeroBytesStore implements BytesStore<ZeroBytesStore, Void> {
throw new UnsupportedOperationException("Cannot get the address of nothing");
}
@Override
@Override
public int peekUnsignedByte(long offset) {
return 0;
}
@@ -157,8 +156,7 @@ public enum ZeroBytesStore implements BytesStore<ZeroBytesStore, Void> {
return true;
}
@Override
@Override
public void reserve(ReferenceOwner id) throws IllegalStateException {
}
@@ -41,13 +41,15 @@ public abstract class MapSegmentIteration<K, V, R> extends HashSegmentIteration<
@Override
public void hookAfterEachIteration() {
throwExceptionIfClosed();
wrappedValueInstanceDataHolder.closeValue();
wrappedValueInstanceDataHolder.closeValue();
}
@Override
public void doReplaceValue(Data<V> newValue) {
throwExceptionIfClosed();
checkOnEachPublicOperation.checkOnEachPublicOperation();
checkOnEachPublicOperation.checkOnEachPublicOperation();
try {
entry.innerDefaultReplaceValue(newValue);
} finally {
@@ -61,25 +61,29 @@ public abstract class ReplicatedMapSegmentIteration<K, V, R> extends MapSegmentI
@Override
public boolean shouldTestEntry() {
throwExceptionIfClosed();
return entriesToTest == ALL || !e.entryDeleted();
return entriesToTest == ALL || !e.entryDeleted();
}
@Override
public Object entryForIteration() {
throwExceptionIfClosed();
return !e.entryDeleted() ? entryDelegating : absentEntryDelegating;
return !e.entryDeleted() ? entryDelegating : absentEntryDelegating;
}
@Override
public long tierEntriesForIteration() {
throwExceptionIfClosed();
return entriesToTest == ALL ? s.tierEntries() : s.tierEntries() - s.tierDeleted();
return entriesToTest == ALL ? s.tierEntries() : s.tierEntries() - s.tierDeleted();
}
@Override
public void doReplaceValue(Data<V> newValue) {
throwExceptionIfClosed();
checkOnEachPublicOperation.checkOnEachPublicOperation();
checkOnEachPublicOperation.checkOnEachPublicOperation();
try {
entry.innerDefaultReplaceValue(newValue);
e.updatedReplicationStateOnPresentEntry();
@@ -92,7 +96,8 @@ public abstract class ReplicatedMapSegmentIteration<K, V, R> extends MapSegmentI
@Override
public boolean forEachSegmentEntryWhile(Predicate<? super MapEntry<K, V>> predicate) {
throwExceptionIfClosed();
checkOnEachPublicOperation.checkOnEachPublicOperation();
checkOnEachPublicOperation.checkOnEachPublicOperation();
initEntriesToTest(PRESENT);
s.innerUpdateLock.lock();
return innerForEachSegmentEntryWhile(predicate);
@@ -102,7 +107,8 @@ public abstract class ReplicatedMapSegmentIteration<K, V, R> extends MapSegmentI
public boolean forEachSegmentReplicableEntryWhile(
Predicate<? super ReplicableEntry> predicate) {
throwExceptionIfClosed();
checkOnEachPublicOperation.checkOnEachPublicOperation();
checkOnEachPublicOperation.checkOnEachPublicOperation();
initEntriesToTest(ALL);
s.innerUpdateLock.lock();
return innerForEachSegmentEntryWhile(predicate);
@@ -111,7 +117,8 @@ public abstract class ReplicatedMapSegmentIteration<K, V, R> extends MapSegmentI
@Override
public void forEachSegmentReplicableEntry(Consumer<? super ReplicableEntry> action) {
throwExceptionIfClosed();
forEachSegmentReplicableEntryWhile(e -> {
forEachSegmentReplicableEntryWhile(e -> {
action.accept(e);
return true;
});
@@ -120,7 +127,8 @@ public abstract class ReplicatedMapSegmentIteration<K, V, R> extends MapSegmentI
@Override
public void doRemove() {
throwExceptionIfClosed();
checkOnEachPublicOperation.checkOnEachPublicOperation();
checkOnEachPublicOperation.checkOnEachPublicOperation();
try {
if (e.valueSize > dummyValue.size())
e.innerDefaultReplaceValue(dummyValue);
@@ -137,7 +145,8 @@ public abstract class ReplicatedMapSegmentIteration<K, V, R> extends MapSegmentI
@Override
public void doRemoveCompletely() {
throwExceptionIfClosed();
boolean wasDeleted = e.entryDeleted();
boolean wasDeleted = e.entryDeleted();
super.doRemove();
ru.dropChange();
if (wasDeleted)
@@ -146,7 +155,8 @@ public abstract class ReplicatedMapSegmentIteration<K, V, R> extends MapSegmentI
public void doInsert(Data<V> value) {
throwExceptionIfClosed();
checkOnEachPublicOperation.checkOnEachPublicOperation();
checkOnEachPublicOperation.checkOnEachPublicOperation();
if (e.entryDeleted()) {
try {
s.tierDeleted(s.tierDeleted() - 1);
@@ -166,7 +176,8 @@ public abstract class ReplicatedMapSegmentIteration<K, V, R> extends MapSegmentI
public void doInsert() {
throwExceptionIfClosed();
if (mh.set() == null)
if (mh.set() == null)
throw new IllegalStateException(mh.h().toIdentityString() +
": Called SetAbsentEntry.doInsert() from Map context");
doInsert((Data<V>) DummyValueData.INSTANCE);
@@ -52,42 +52,50 @@ class SetFromMap<E> extends AbstractSet<E> implements ChronicleSet<E> {
public void clear() {
throwExceptionIfClosed();
m.clear();
m.clear();
}
public int size() {
throwExceptionIfClosed();
return m.size();
return m.size();
}
public boolean isEmpty() {
throwExceptionIfClosed();
return m.isEmpty();
return m.isEmpty();
}
public boolean contains(Object o) {
throwExceptionIfClosed();
return m.containsKey(o);
return m.containsKey(o);
}
public boolean remove(Object o) {
throwExceptionIfClosed();
return m.remove(o, DUMMY_VALUE);
return m.remove(o, DUMMY_VALUE);
}
public boolean add(E e) {
throwExceptionIfClosed();
return m.putIfAbsent(e, DUMMY_VALUE) == null;
return m.putIfAbsent(e, DUMMY_VALUE) == null;
}
public Iterator<E> iterator() {
throwExceptionIfClosed();
return s.iterator();
return s.iterator();
}
public Object[] toArray() {
throwExceptionIfClosed();
return s.toArray();
return s.toArray();
}
public <T> T[] toArray(T[] a) {
@@ -101,7 +109,8 @@ class SetFromMap<E> extends AbstractSet<E> implements ChronicleSet<E> {
@Override
public String toIdentityString() {
throwExceptionIfClosed();
return "ChronicleSet{" +
return "ChronicleSet{" +
"name=" + name() +
", file=" + file() +
", identityHashCode=" + System.identityHashCode(this) +
@@ -110,52 +119,61 @@ class SetFromMap<E> extends AbstractSet<E> implements ChronicleSet<E> {
public int hashCode() {
throwExceptionIfClosed();
return s.hashCode();
return s.hashCode();
}
public boolean equals(Object o) {
throwExceptionIfClosed();
return o == this || s.equals(o);
return o == this || s.equals(o);
}
public boolean containsAll(Collection<?> c) {
throwExceptionIfClosed();
return s.containsAll(c);
return s.containsAll(c);
}
public boolean removeAll(Collection<?> c) {
throwExceptionIfClosed();
return s.removeAll(c);
return s.removeAll(c);
}
public boolean retainAll(Collection<?> c) {
throwExceptionIfClosed();
return s.retainAll(c);
return s.retainAll(c);
}
// addAll is the only inherited implementation
@Override
public long longSize() {
throwExceptionIfClosed();
return m.longSize();
return m.longSize();
}
@Override
public long offHeapMemoryUsed() {
throwExceptionIfClosed();
return m.offHeapMemoryUsed();
return m.offHeapMemoryUsed();
}
@Override
public Class<E> keyClass() {
throwExceptionIfClosed();
return m.keyClass();
return m.keyClass();
}
@Override
public Type keyType() {
throwExceptionIfClosed();
return m.keyType();
return m.keyType();
}
// TODO test queryContext methods
@@ -190,7 +208,8 @@ class SetFromMap<E> extends AbstractSet<E> implements ChronicleSet<E> {
@Override
public int segments() {
throwExceptionIfClosed();
return m.segments();
return m.segments();
}
// TODO test forEach methods
@@ -198,27 +217,31 @@ class SetFromMap<E> extends AbstractSet<E> implements ChronicleSet<E> {
@Override
public boolean forEachEntryWhile(Predicate<? super SetEntry<E>> predicate) {
throwExceptionIfClosed();
Objects.requireNonNull(predicate);
Objects.requireNonNull(predicate);
return m.forEachEntryWhile(e -> predicate.test(((SetEntry<E>) e)));
}
@Override
public void forEachEntry(Consumer<? super SetEntry<E>> action) {
throwExceptionIfClosed();
Objects.requireNonNull(action);
Objects.requireNonNull(action);
m.forEachEntry(e -> action.accept(((SetEntry<E>) e)));
}
@Override
public File file() {
throwExceptionIfClosed();
return m.file();
return m.file();
}
@Override
public String name() {
throwExceptionIfClosed();
return m.name();
return m.name();
}
@Override
@@ -229,6 +252,7 @@ class SetFromMap<E> extends AbstractSet<E> implements ChronicleSet<E> {
@Override
public boolean isOpen() {
throwExceptionIfClosed();
return m.isOpen();
return m.isOpen();
}
}