mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
HCOLL-392 Add entry checksums
This commit is contained in:
@@ -20,6 +20,7 @@ import net.openhft.chronicle.core.OS;
|
||||
import net.openhft.chronicle.hash.ChronicleHashBuilder;
|
||||
import net.openhft.chronicle.hash.ChronicleHashBuilderPrivateAPI;
|
||||
import net.openhft.chronicle.hash.ChronicleHashInstanceBuilder;
|
||||
import net.openhft.chronicle.hash.impl.stage.entry.ChecksumStrategy;
|
||||
import net.openhft.chronicle.hash.impl.util.math.PoissonDistribution;
|
||||
import net.openhft.chronicle.hash.replication.*;
|
||||
import net.openhft.chronicle.hash.serialization.*;
|
||||
@@ -162,7 +163,10 @@ public final class ChronicleMapBuilder<K, V> implements
|
||||
private double maxBloatFactor = 1.0;
|
||||
private boolean allowSegmentTiering = true;
|
||||
private double nonTieredSegmentsPercentile = 0.99999;
|
||||
private boolean aligned64BitMemoryOperationsAtomic = OS.is64Bit() ? true : false;
|
||||
private boolean aligned64BitMemoryOperationsAtomic = OS.is64Bit();
|
||||
|
||||
enum ChecksumEntries {YES, NO, IF_PERSISTED}
|
||||
private ChecksumEntries checksumEntries = ChecksumEntries.IF_PERSISTED;
|
||||
|
||||
private boolean putReturnsNull = false;
|
||||
private boolean removeReturnsNull = false;
|
||||
@@ -534,6 +538,8 @@ public final class ChronicleMapBuilder<K, V> implements
|
||||
size += keySize;
|
||||
if (replicated)
|
||||
size += ReplicatedChronicleMap.ADDITIONAL_ENTRY_BYTES;
|
||||
if (checksumEntries())
|
||||
size += ChecksumStrategy.CHECKSUM_STORED_BYTES;
|
||||
double valueSize = averageValueSize();
|
||||
size += averageSizeEncodingSize(valueBuilder, valueSize);
|
||||
Alignment alignment = valueAlignment();
|
||||
@@ -1240,6 +1246,21 @@ public final class ChronicleMapBuilder<K, V> implements
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChronicleMapBuilder<K, V> checksumEntries(boolean checksumEntries) {
|
||||
this.checksumEntries = checksumEntries ? ChecksumEntries.YES : ChecksumEntries.NO;
|
||||
return this;
|
||||
}
|
||||
|
||||
boolean checksumEntries() {
|
||||
switch (checksumEntries) {
|
||||
case NO: return false;
|
||||
case YES: return true;
|
||||
case IF_PERSISTED: return persisted;
|
||||
default: throw new AssertionError();
|
||||
}
|
||||
}
|
||||
|
||||
boolean aligned64BitMemoryOperationsAtomic() {
|
||||
return aligned64BitMemoryOperationsAtomic;
|
||||
}
|
||||
|
||||
@@ -76,4 +76,9 @@ class ChronicleMapBuilderPrivateAPI<K> implements ChronicleHashBuilderPrivateAPI
|
||||
public boolean aligned64BitMemoryOperationsAtomic() {
|
||||
return b.aligned64BitMemoryOperationsAtomic();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checksumEntries() {
|
||||
return b.checksumEntries();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ 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.IterationKeyHashCode;
|
||||
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;
|
||||
@@ -46,6 +47,7 @@ import net.openhft.sg.Staged;
|
||||
|
||||
KeyBytesInterop.class,
|
||||
IterationSegmentStages.class,
|
||||
IterationKeyHashCode.class,
|
||||
HashLookupPos.class,
|
||||
IterationCheckOnEachPublicOperation.class,
|
||||
AllocatedChunks.class,
|
||||
@@ -65,6 +67,8 @@ import net.openhft.sg.Staged;
|
||||
EntryValueBytesData.class,
|
||||
|
||||
WrappedValueInstanceData.class,
|
||||
|
||||
HashKeyCrc32PayloadChecksumStrategy.class,
|
||||
})
|
||||
public class MapIterationContext {
|
||||
}
|
||||
|
||||
@@ -19,10 +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.data.bytes.InputKeyBytesData;
|
||||
import net.openhft.chronicle.hash.impl.stage.data.instance.InputKeyInstanceData;
|
||||
import net.openhft.chronicle.hash.impl.stage.entry.InputKeyHashCode;
|
||||
import net.openhft.chronicle.hash.impl.stage.entry.ReadLock;
|
||||
import net.openhft.chronicle.hash.impl.stage.entry.UpdateLock;
|
||||
import net.openhft.chronicle.hash.impl.stage.entry.WriteLock;
|
||||
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;
|
||||
@@ -90,6 +87,8 @@ nested = {
|
||||
AcquireHandle.class,
|
||||
DefaultReturnValue.class,
|
||||
UsingReturnValue.class,
|
||||
|
||||
HashKeyCrc32PayloadChecksumStrategy.class,
|
||||
})
|
||||
public class MapQueryContext {
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ 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.IterationKeyHashCode;
|
||||
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;
|
||||
@@ -47,6 +48,7 @@ import net.openhft.sg.Staged;
|
||||
|
||||
KeyBytesInterop.class,
|
||||
IterationSegmentStages.class,
|
||||
IterationKeyHashCode.class,
|
||||
HashLookupPos.class,
|
||||
IterationCheckOnEachPublicOperation.class,
|
||||
AllocatedChunks.class,
|
||||
@@ -73,7 +75,9 @@ import net.openhft.sg.Staged;
|
||||
DummyValueZeroData.class,
|
||||
|
||||
ReplicatedMapAbsentDelegatingForIteration.class,
|
||||
ReplicatedMapEntryDelegating.class
|
||||
ReplicatedMapEntryDelegating.class,
|
||||
|
||||
HashKeyCrc32PayloadChecksumStrategy.class,
|
||||
})
|
||||
public class ReplicatedMapIterationContext {
|
||||
}
|
||||
|
||||
@@ -19,10 +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.data.bytes.InputKeyBytesData;
|
||||
import net.openhft.chronicle.hash.impl.stage.data.instance.InputKeyInstanceData;
|
||||
import net.openhft.chronicle.hash.impl.stage.entry.InputKeyHashCode;
|
||||
import net.openhft.chronicle.hash.impl.stage.entry.ReadLock;
|
||||
import net.openhft.chronicle.hash.impl.stage.entry.UpdateLock;
|
||||
import net.openhft.chronicle.hash.impl.stage.entry.WriteLock;
|
||||
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;
|
||||
@@ -109,6 +106,8 @@ nested = {
|
||||
ReplicatedInputValueBytesData.class,
|
||||
|
||||
DummyValueZeroData.class,
|
||||
|
||||
HashKeyCrc32PayloadChecksumStrategy.class,
|
||||
})
|
||||
public class ReplicatedMapQueryContext {
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ public abstract class MapSegmentIteration<K, V, R> extends HashSegmentIteration<
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
try {
|
||||
entry.innerDefaultReplaceValue(newValue);
|
||||
entry.checksumStrategy.computeAndStoreChecksum();
|
||||
} finally {
|
||||
s.innerWriteLock.unlock();
|
||||
}
|
||||
|
||||
+3
@@ -57,6 +57,7 @@ public abstract class ReplicatedMapSegmentIteration<K, V, R> extends MapSegmentI
|
||||
entry.innerDefaultReplaceValue(newValue);
|
||||
ru.updateChange();
|
||||
e.updatedReplicationStateOnPresentEntry();
|
||||
e.checksumStrategy.computeAndStoreChecksum();
|
||||
} finally {
|
||||
s.innerWriteLock.unlock();
|
||||
}
|
||||
@@ -118,6 +119,7 @@ public abstract class ReplicatedMapSegmentIteration<K, V, R> extends MapSegmentI
|
||||
e.updatedReplicationStateOnPresentEntry();
|
||||
e.writeEntryDeleted();
|
||||
ru.updateChange();
|
||||
e.checksumStrategy.computeAndStoreChecksum();
|
||||
s.deleted(s.deleted() + 1);
|
||||
} finally {
|
||||
s.innerWriteLock.unlock();
|
||||
@@ -144,6 +146,7 @@ public abstract class ReplicatedMapSegmentIteration<K, V, R> extends MapSegmentI
|
||||
e.writeEntryPresent();
|
||||
ru.updateChange();
|
||||
e.updatedReplicationStateOnPresentEntry();
|
||||
e.checksumStrategy.computeAndStoreChecksum();
|
||||
} finally {
|
||||
s.innerWriteLock.unlock();
|
||||
}
|
||||
|
||||
@@ -78,6 +78,7 @@ public abstract class MapAbsent<K, V> implements MapAbsentEntry<K, V> {
|
||||
s.incrementModCount();
|
||||
ks.setSearchState(PRESENT);
|
||||
q.initPresenceOfEntry(EntryPresence.PRESENT);
|
||||
e.checksumStrategy.computeAndStoreChecksum();
|
||||
} else {
|
||||
throw new IllegalStateException(
|
||||
"Entry is present in the map when doInsert() is called");
|
||||
|
||||
@@ -87,6 +87,11 @@ public abstract class MapQuery<K, V, R> extends HashQuery<K>
|
||||
|
||||
@Override
|
||||
public void doReplaceValue(Data<V> newValue) {
|
||||
doReplaceValueWithoutChecksum(newValue);
|
||||
e.checksumStrategy.computeAndStoreChecksum();
|
||||
}
|
||||
|
||||
public void doReplaceValueWithoutChecksum(Data<V> newValue) {
|
||||
putPrefix();
|
||||
if (entryPresent()) {
|
||||
e.innerDefaultReplaceValue(newValue);
|
||||
|
||||
@@ -48,6 +48,7 @@ public abstract class ReplicatedMapAbsent<K, V> extends MapAbsent<K, V> {
|
||||
e.writeEntryPresent();
|
||||
ru.updateChange();
|
||||
e.updatedReplicationStateOnAbsentEntry();
|
||||
e.checksumStrategy.computeAndStoreChecksum();
|
||||
} else {
|
||||
throw new IllegalStateException("Entry is absent in the map when doInsert() is called");
|
||||
}
|
||||
|
||||
@@ -78,6 +78,7 @@ public abstract class ReplicatedMapQuery<K, V, R> extends MapQuery<K, V, R>
|
||||
e.updatedReplicationStateOnPresentEntry();
|
||||
e.writeEntryDeleted();
|
||||
ru.updateChange();
|
||||
e.checksumStrategy.computeAndStoreChecksum();
|
||||
s.deleted(s.deleted() + 1);
|
||||
} else {
|
||||
throw new IllegalStateException("Entry is absent in the map when doRemove() is called");
|
||||
@@ -94,8 +95,9 @@ public abstract class ReplicatedMapQuery<K, V, R> extends MapQuery<K, V, R>
|
||||
|
||||
@Override
|
||||
public void doReplaceValue(Data<V> newValue) {
|
||||
super.doReplaceValue(newValue);
|
||||
doReplaceValueWithoutChecksum(newValue);
|
||||
ru.updateChange();
|
||||
e.updatedReplicationStateOnPresentEntry();
|
||||
e.checksumStrategy.computeAndStoreChecksum();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user