mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
HCOLL-143 print a warning on attempt of creation too large ChronicleMap or ChronicleSet on Windows
This commit is contained in:
@@ -1172,6 +1172,7 @@ public final class ChronicleMapBuilder<K, V> implements Cloneable,
|
||||
try {
|
||||
pushingToMapEventListener();
|
||||
VanillaChronicleMap<K, ?, ?, V, ?, ?> map = newMap(singleHashReplication, channel);
|
||||
map.warnOnWindows();
|
||||
BytesStore bytesStore = new DirectStore(JDKObjectSerializer.INSTANCE,
|
||||
map.sizeInBytes(), true);
|
||||
map.createMappedStoreAndSegments(bytesStore);
|
||||
@@ -1209,7 +1210,8 @@ public final class ChronicleMapBuilder<K, V> implements Cloneable,
|
||||
}
|
||||
|
||||
private VanillaChronicleMap<K, ?, ?, V, ?, ?> newMap(
|
||||
SingleChronicleHashReplication singleHashReplication, ReplicationChannel channel) throws IOException {
|
||||
SingleChronicleHashReplication singleHashReplication, ReplicationChannel channel)
|
||||
throws IOException {
|
||||
boolean replicated = singleHashReplication != null || channel != null;
|
||||
preMapConstruction(replicated);
|
||||
if (replicated) {
|
||||
|
||||
@@ -32,6 +32,7 @@ import net.openhft.chronicle.hash.serialization.BytesInterop;
|
||||
import net.openhft.chronicle.hash.serialization.BytesReader;
|
||||
import net.openhft.chronicle.hash.serialization.SizeMarshaller;
|
||||
import net.openhft.chronicle.hash.serialization.internal.*;
|
||||
import net.openhft.lang.Jvm;
|
||||
import net.openhft.lang.collection.DirectBitSet;
|
||||
import net.openhft.lang.collection.SingleThreadedDirectBitSet;
|
||||
import net.openhft.lang.io.*;
|
||||
@@ -237,7 +238,37 @@ 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);
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
final long createMappedStoreAndSegments(File file) throws IOException {
|
||||
warnOnWindows();
|
||||
return createMappedStoreAndSegments(new MappedStore(file, FileChannel.MapMode.READ_WRITE,
|
||||
sizeInBytes(), JDKObjectSerializer.INSTANCE));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user