mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Fix test for replication
This commit is contained in:
@@ -59,8 +59,9 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
implements ChronicleMap<K, V>, Serializable, ReadValue<V>, InstanceOrBytesToInstance,
|
||||
GetValueInterops<V, VI, MVI> {
|
||||
|
||||
static final boolean checkSegmentMultiMapsAndBitSetsConsistencyOnBootstrap = Boolean.getBoolean(
|
||||
"chronicleMap.checkSegmentMultiMapsAndBitSetsConsistencyOnBootstrap");
|
||||
private static final Logger LOG = LoggerFactory.getLogger(VanillaChronicleMap.class);
|
||||
|
||||
private static final long serialVersionUID = 2L;
|
||||
final Class<K> kClass;
|
||||
final String dataFileVersion;
|
||||
@@ -93,14 +94,13 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
// rather than as returning the Object can be expensive for something you probably don't use.
|
||||
final boolean putReturnsNull;
|
||||
final boolean removeReturnsNull;
|
||||
final Class nativeValueClass;
|
||||
final MultiMapFactory multiMapFactory;
|
||||
final int maxChunksPerEntry;
|
||||
private final long lockTimeOutNS;
|
||||
private final ChronicleHashErrorListener errorListener;
|
||||
private final int segmentHeaderSize;
|
||||
private final HashSplitting hashSplitting;
|
||||
final Class nativeValueClass;
|
||||
final MultiMapFactory multiMapFactory;
|
||||
final int maxChunksPerEntry;
|
||||
|
||||
transient Provider<BytesReader<K>> keyReaderProvider;
|
||||
transient Provider<KI> keyInteropProvider;
|
||||
transient Provider<BytesReader<V>> valueReaderProvider;
|
||||
@@ -110,6 +110,30 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
transient BytesStore ms;
|
||||
transient long headerSize;
|
||||
transient Set<Map.Entry<K, V>> entrySet;
|
||||
transient InstanceOrBytesToInstance<Bytes, K> keyBytesToInstance =
|
||||
new InstanceOrBytesToInstance<Bytes, K>() {
|
||||
@Override
|
||||
public K toInstance(@NotNull ThreadLocalCopies copies, Bytes keyBytes, long size) {
|
||||
assertNotNull(copies);
|
||||
BytesReader<K> keyReader = keyReaderProvider.get(copies, originalKeyReader);
|
||||
return keyReader.read(keyBytes, size);
|
||||
}
|
||||
};
|
||||
transient InstanceOrBytesToInstance<Bytes, V> valueBytesToInstance =
|
||||
new InstanceOrBytesToInstance<Bytes, V>() {
|
||||
@Override
|
||||
public V toInstance(@NotNull ThreadLocalCopies copies, Bytes valueBytes, long size) {
|
||||
return readValue(copies, valueBytes, null, size);
|
||||
}
|
||||
};
|
||||
transient InstanceOrBytesToInstance<Bytes, V> outputValueBytesToInstance =
|
||||
new InstanceOrBytesToInstance<Bytes, V>() {
|
||||
@Override
|
||||
public V toInstance(@NotNull ThreadLocalCopies copies, Bytes outputBytes, long size) {
|
||||
outputBytes.position(outputBytes.position() - size);
|
||||
return readValue(copies, outputBytes, null, size);
|
||||
}
|
||||
};
|
||||
|
||||
public VanillaChronicleMap(ChronicleMapBuilder<K, V> builder) throws IOException {
|
||||
|
||||
@@ -178,6 +202,48 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
initTransients();
|
||||
}
|
||||
|
||||
static <T> T newInstance(Class<T> aClass, boolean isKey) {
|
||||
try {
|
||||
return isKey ? DataValueClasses.newInstance(aClass) :
|
||||
DataValueClasses.newDirectInstance(aClass);
|
||||
|
||||
} catch (Exception e) {
|
||||
if (e.getCause() instanceof IllegalStateException)
|
||||
throw e;
|
||||
|
||||
if (aClass.isInterface())
|
||||
throw new IllegalStateException("It not possible to create a instance from " +
|
||||
"interface=" + aClass.getSimpleName() + " we recommend you create an " +
|
||||
"instance in the usual way.", e);
|
||||
|
||||
try {
|
||||
return aClass.newInstance();
|
||||
} catch (Exception e1) {
|
||||
throw new IllegalStateException("It has not been possible to create a instance " +
|
||||
"of class=" + aClass.getSimpleName() +
|
||||
", Note : its more efficient if your chronicle map is configured with " +
|
||||
"interface key " +
|
||||
"and value types rather than classes, as this method is able to use " +
|
||||
"interfaces to generate off heap proxies that point straight at your data. " +
|
||||
"In this case you have used a class and chronicle is unable to create an " +
|
||||
"instance of this class has it does not have a default constructor. " +
|
||||
"If your class is mutable, we " +
|
||||
"recommend you create and instance of your class=" + aClass.getSimpleName() +
|
||||
" in the usual way, rather than using this method.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void segmentStateNotNullImpliesCopiesNotNull(
|
||||
@Nullable ThreadLocalCopies copies, @Nullable SegmentState segmentState) {
|
||||
assert copies != null || segmentState == null; // segmentState != null -> copies != null
|
||||
}
|
||||
|
||||
static void expectedValueNotNullImpliesBooleanResult(
|
||||
@Nullable Object expectedValue, boolean booleanResult) {
|
||||
assert booleanResult || expectedValue == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the version of Chronicle Map that was used to create the current data file
|
||||
*/
|
||||
@@ -192,7 +258,6 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
return BuildVersion.version();
|
||||
}
|
||||
|
||||
|
||||
final long segmentHash(long hash) {
|
||||
return hashSplitting.segmentHash(hash);
|
||||
}
|
||||
@@ -250,37 +315,6 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
return offset;
|
||||
}
|
||||
|
||||
void warnOnWindows() {
|
||||
if (!Jvm.isWindows())
|
||||
return;
|
||||
long offHeapMapSize = sizeInBytes();
|
||||
long oneGb = GIGABYTES.toBytes(1L);
|
||||
double offHeapMapSizeInGb = offHeapMapSize * 1.0 / oneGb;
|
||||
if (offHeapMapSize > GIGABYTES.toBytes(4L)) {
|
||||
System.out.printf(
|
||||
"WARNING: On Windows, you probably cannot create a ChronicleMap\n" +
|
||||
"of more than 4 GB. The configured map requires %.2f GB of off-heap memory.\n",
|
||||
offHeapMapSizeInGb);
|
||||
}
|
||||
if (Boolean.getBoolean("win.check"))
|
||||
try {
|
||||
long freePhysicalMemory = Jvm.freePhysicalMemoryOnWindowsInBytes();
|
||||
if (offHeapMapSize > freePhysicalMemory * 0.9) {
|
||||
double freePhysicalMemoryInGb = freePhysicalMemory * 1.0 / oneGb;
|
||||
System.out.printf(
|
||||
"WARNING: On Windows, you probably cannot create a ChronicleMap\n" +
|
||||
"of more than 90%% of available free memory in the system.\n" +
|
||||
"The configured map requires %.2f GB of off-heap memory.\n" +
|
||||
"There is only %.2f GB of free physical memory in the system.\n",
|
||||
offHeapMapSizeInGb, freePhysicalMemoryInGb);
|
||||
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// ignore -- anyway we just warn the user
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void warnOnWindows() {
|
||||
if (!Jvm.isWindows())
|
||||
return;
|
||||
@@ -673,38 +707,6 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
return newInstance(kClass, true);
|
||||
}
|
||||
|
||||
static <T> T newInstance(Class<T> aClass, boolean isKey) {
|
||||
try {
|
||||
return isKey ? DataValueClasses.newInstance(aClass) :
|
||||
DataValueClasses.newDirectInstance(aClass);
|
||||
|
||||
} catch (Exception e) {
|
||||
if (e.getCause() instanceof IllegalStateException)
|
||||
throw e;
|
||||
|
||||
if (aClass.isInterface())
|
||||
throw new IllegalStateException("It not possible to create a instance from " +
|
||||
"interface=" + aClass.getSimpleName() + " we recommend you create an " +
|
||||
"instance in the usual way.", e);
|
||||
|
||||
try {
|
||||
return aClass.newInstance();
|
||||
} catch (Exception e1) {
|
||||
throw new IllegalStateException("It has not been possible to create a instance " +
|
||||
"of class=" + aClass.getSimpleName() +
|
||||
", Note : its more efficient if your chronicle map is configured with " +
|
||||
"interface key " +
|
||||
"and value types rather than classes, as this method is able to use " +
|
||||
"interfaces to generate off heap proxies that point straight at your data. " +
|
||||
"In this case you have used a class and chronicle is unable to create an " +
|
||||
"instance of this class has it does not have a default constructor. " +
|
||||
"If your class is mutable, we " +
|
||||
"recommend you create and instance of your class=" + aClass.getSimpleName() +
|
||||
" in the usual way, rather than using this method.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<K> keyClass() {
|
||||
return kClass;
|
||||
@@ -791,29 +793,11 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
return this;
|
||||
}
|
||||
|
||||
transient InstanceOrBytesToInstance<Bytes, K> keyBytesToInstance =
|
||||
new InstanceOrBytesToInstance<Bytes, K>() {
|
||||
@Override
|
||||
public K toInstance(@NotNull ThreadLocalCopies copies, Bytes keyBytes, long size) {
|
||||
assertNotNull(copies);
|
||||
BytesReader<K> keyReader = keyReaderProvider.get(copies, originalKeyReader);
|
||||
return keyReader.read(keyBytes, size);
|
||||
}
|
||||
};
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
final InstanceOrBytesToInstance<V, V> valueIdentity() {
|
||||
return this;
|
||||
}
|
||||
|
||||
transient InstanceOrBytesToInstance<Bytes, V> valueBytesToInstance =
|
||||
new InstanceOrBytesToInstance<Bytes, V>() {
|
||||
@Override
|
||||
public V toInstance(@NotNull ThreadLocalCopies copies, Bytes valueBytes, long size) {
|
||||
return readValue(copies, valueBytes, null, size);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public final boolean containsKey(final Object k) {
|
||||
checkKey(k);
|
||||
@@ -832,15 +816,6 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
}
|
||||
}
|
||||
|
||||
transient InstanceOrBytesToInstance<Bytes, V> outputValueBytesToInstance =
|
||||
new InstanceOrBytesToInstance<Bytes, V>() {
|
||||
@Override
|
||||
public V toInstance(@NotNull ThreadLocalCopies copies, Bytes outputBytes, long size) {
|
||||
outputBytes.position(outputBytes.position() - size);
|
||||
return readValue(copies, outputBytes, null, size);
|
||||
}
|
||||
};
|
||||
|
||||
final boolean containsBytesKey(Bytes key) throws InterruptedException {
|
||||
return containsKey(null,
|
||||
DelegatingMetaBytesInterop.<Bytes, BytesInterop<Bytes>>instance(),
|
||||
@@ -1286,11 +1261,6 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
}
|
||||
}
|
||||
|
||||
static void segmentStateNotNullImpliesCopiesNotNull(
|
||||
@Nullable ThreadLocalCopies copies, @Nullable SegmentState segmentState) {
|
||||
assert copies != null || segmentState == null; // segmentState != null -> copies != null
|
||||
}
|
||||
|
||||
private static class ReadValueToLazyBytes extends ReadValueToBytes {
|
||||
DirectBytes lazyBytes;
|
||||
|
||||
@@ -1315,11 +1285,6 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
}
|
||||
}
|
||||
|
||||
static void expectedValueNotNullImpliesBooleanResult(
|
||||
@Nullable Object expectedValue, boolean booleanResult) {
|
||||
assert booleanResult || expectedValue == null;
|
||||
}
|
||||
|
||||
static class GetRemoteBytesValueInterops
|
||||
implements GetValueInterops<MultiStoreBytes, Void, GetRemoteBytesValueInterops>,
|
||||
MetaBytesInterop<Bytes, Void> {
|
||||
@@ -1384,9 +1349,6 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
}
|
||||
}
|
||||
|
||||
static final boolean checkSegmentMultiMapsAndBitSetsConsistencyOnBootstrap = Boolean.getBoolean(
|
||||
"chronicleMap.checkSegmentMultiMapsAndBitSetsConsistencyOnBootstrap");
|
||||
|
||||
public static final class SegmentState implements StatefulCopyable<SegmentState>,
|
||||
AutoCloseable {
|
||||
private static final Provider<SegmentState> segmentStateProvider =
|
||||
|
||||
Reference in New Issue
Block a user