Merge remote-tracking branch 'origin/master'

This commit is contained in:
Rob Austin
2014-12-17 17:19:25 +00:00
7 changed files with 71 additions and 7 deletions
@@ -2,7 +2,7 @@ package net.openhft.chronicle.hash.replication;
import java.net.InetSocketAddress;
public class TcpInetSocketAddress extends InetSocketAddress {
class TcpInetSocketAddress extends InetSocketAddress {
private final String toString;
public TcpInetSocketAddress(String hostname, int port) {
@@ -102,7 +102,7 @@ public final class ChronicleMapBuilder<K, V> implements Cloneable,
private static final int MAX_SEGMENTS_TO_CHAISE_COMPACT_MULTI_MAPS = (1 << 20);
private static final Logger LOG =
LoggerFactory.getLogger(ChronicleMapBuilder.class.getName());
public static final long DEFAULT_STATELESS_CLIENT_TIMEOUT = TimeUnit.SECONDS.toMillis(10);
static final long DEFAULT_STATELESS_CLIENT_TIMEOUT = TimeUnit.SECONDS.toMillis(10);
private static final StringBuilder EMTRY_STRING_BUILDER = new StringBuilder();
@@ -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) {
@@ -1,4 +1,6 @@
package net.openhft.chronicle.hash;
package net.openhft.chronicle.map;
import net.openhft.chronicle.hash.ChronicleHash;
import java.io.IOException;
import java.util.concurrent.TimeoutException;
@@ -6,7 +8,7 @@ import java.util.concurrent.TimeoutException;
/**
* @author Rob Austin.
*/
public interface FindByName {
interface FindByName {
/**
* @param name the name of the map or set
@@ -53,7 +53,7 @@ import static net.openhft.chronicle.map.NodeDiscoveryBroadcaster.LOG;
*
* This code is in alpha, and still has to undergo refactoring
*/
public class NodeDiscovery {
class NodeDiscovery {
public static final int DEFAULT_UDP_BROADCAST_PORT = 8129;
public static final short DEFAULT_TCP_PORT = (short) 8123;
@@ -19,7 +19,6 @@ package net.openhft.chronicle.map;
import net.openhft.chronicle.hash.ChronicleHash;
import net.openhft.chronicle.hash.ChronicleHashBuilder;
import net.openhft.chronicle.hash.ChronicleHashInstanceConfig;
import net.openhft.chronicle.hash.FindByName;
import net.openhft.chronicle.hash.replication.ReplicationChannel;
import net.openhft.chronicle.hash.replication.ReplicationHub;
import org.slf4j.Logger;
@@ -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));
}
@@ -0,0 +1,30 @@
/*
* Copyright 2014 Higher Frequency Trading http://www.higherfrequencytrading.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.openhft.chronicle.map;
import org.junit.Ignore;
import org.junit.Test;
public class WarnOnWindowsTest {
@Test
@Ignore("This test results to OOM/jvm crash, run manually to verify warning output")
public void warnOnWindowsTest() {
ChronicleMapBuilder.of(Long.class, Long.class)
.entries(1_000_000_000).create();
}
}