Search in sources :

Example 1 with HazelcastException

use of com.hazelcast.core.HazelcastException in project neo4j by neo4j.

the class HazelcastCoreTopologyService method createHazelcastInstance.

private HazelcastInstance createHazelcastInstance() {
    System.setProperty(WAIT_SECONDS_BEFORE_JOIN.getName(), "1");
    JoinConfig joinConfig = new JoinConfig();
    joinConfig.getMulticastConfig().setEnabled(false);
    joinConfig.getAwsConfig().setEnabled(false);
    TcpIpConfig tcpIpConfig = joinConfig.getTcpIpConfig();
    tcpIpConfig.setEnabled(true);
    List<AdvertisedSocketAddress> initialMembers = config.get(CausalClusteringSettings.initial_discovery_members);
    for (AdvertisedSocketAddress address : initialMembers) {
        tcpIpConfig.addMember(address.toString());
    }
    Setting<ListenSocketAddress> discovery_listen_address = CausalClusteringSettings.discovery_listen_address;
    ListenSocketAddress hazelcastAddress = config.get(discovery_listen_address);
    InterfacesConfig interfaces = new InterfacesConfig();
    interfaces.addInterface(hazelcastAddress.getHostname());
    NetworkConfig networkConfig = new NetworkConfig();
    networkConfig.setInterfaces(interfaces);
    networkConfig.setPort(hazelcastAddress.getPort());
    networkConfig.setJoin(joinConfig);
    networkConfig.setPortAutoIncrement(false);
    com.hazelcast.config.Config c = new com.hazelcast.config.Config();
    c.setProperty(OPERATION_CALL_TIMEOUT_MILLIS.getName(), String.valueOf(10_000));
    c.setProperty(MERGE_NEXT_RUN_DELAY_SECONDS.getName(), "10");
    c.setProperty(MERGE_FIRST_RUN_DELAY_SECONDS.getName(), "10");
    c.setProperty(INITIAL_MIN_CLUSTER_SIZE.getName(), String.valueOf(minimumClusterSizeThatCanTolerateOneFaultForExpectedClusterSize()));
    c.setProperty(LOGGING_TYPE.getName(), "none");
    c.setNetworkConfig(networkConfig);
    MemberAttributeConfig memberAttributeConfig = HazelcastClusterTopology.buildMemberAttributesForCore(myself, config);
    c.setMemberAttributeConfig(memberAttributeConfig);
    logConnectionInfo(initialMembers);
    JobScheduler.JobHandle logJob = scheduler.schedule("HazelcastHealth", HAZELCAST_IS_HEALTHY_TIMEOUT_MS, () -> log.warn("The server has not been able to connect in a timely fashion to the " + "cluster. Please consult the logs for more details. Rebooting the server may " + "solve the problem."));
    try {
        hazelcastInstance = Hazelcast.newHazelcastInstance(c);
        logJob.cancel(true);
    } catch (HazelcastException e) {
        String errorMessage = String.format("Hazelcast was unable to start with setting: %s = %s", discovery_listen_address.name(), config.get(discovery_listen_address));
        userLog.error(errorMessage);
        log.error(errorMessage, e);
        throw new RuntimeException(e);
    }
    List<String> groups = config.get(CausalClusteringSettings.server_groups);
    refreshGroups(hazelcastInstance, myself.getUuid().toString(), groups);
    return hazelcastInstance;
}
Also used : JobScheduler(org.neo4j.kernel.impl.util.JobScheduler) InterfacesConfig(com.hazelcast.config.InterfacesConfig) HazelcastException(com.hazelcast.core.HazelcastException) JoinConfig(com.hazelcast.config.JoinConfig) MemberAttributeConfig(com.hazelcast.config.MemberAttributeConfig) Config(org.neo4j.kernel.configuration.Config) NetworkConfig(com.hazelcast.config.NetworkConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig) InterfacesConfig(com.hazelcast.config.InterfacesConfig) NetworkConfig(com.hazelcast.config.NetworkConfig) AdvertisedSocketAddress(org.neo4j.helpers.AdvertisedSocketAddress) ListenSocketAddress(org.neo4j.helpers.ListenSocketAddress) JoinConfig(com.hazelcast.config.JoinConfig) MemberAttributeConfig(com.hazelcast.config.MemberAttributeConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig)

Example 2 with HazelcastException

use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.

the class DefaultAddressPicker method getPublicAddressByPortSearch.

private AddressDefinition getPublicAddressByPortSearch() throws IOException {
    NetworkConfig networkConfig = config.getNetworkConfig();
    boolean bindAny = hazelcastProperties.getBoolean(GroupProperty.SOCKET_SERVER_BIND_ANY);
    Throwable error = null;
    ServerSocket serverSocket = null;
    InetSocketAddress inetSocketAddress;
    boolean reuseAddress = networkConfig.isReuseAddress();
    logger.finest("inet reuseAddress:" + reuseAddress);
    int port = networkConfig.getPort();
    // port = 0 means system will pick up an ephemeral port.
    int portTrialCount = port > 0 && networkConfig.isPortAutoIncrement() ? networkConfig.getPortCount() : 1;
    AddressDefinition bindAddressDef = pickAddressDef();
    if (port == 0) {
        logger.info("No explicit port is given, system will pick up an ephemeral port.");
    }
    for (int i = 0; i < portTrialCount; i++) {
        /*
             * Instead of reusing the ServerSocket/ServerSocketChannel, we are going to close and replace them on
             * every attempt to find a free port. The reason to do this is because in some cases, when concurrent
             * threads/processes try to acquire the same port, the ServerSocket gets corrupted and isn't able to
             * find any free port at all (no matter if there are more than enough free ports available). We have
             * seen this happening on Linux and Windows environments.
             */
        serverSocketChannel = ServerSocketChannel.open();
        serverSocket = serverSocketChannel.socket();
        serverSocket.setReuseAddress(reuseAddress);
        serverSocket.setSoTimeout(SOCKET_TIMEOUT_MILLIS);
        try {
            if (bindAny) {
                inetSocketAddress = new InetSocketAddress(port + i);
            } else {
                inetSocketAddress = new InetSocketAddress(bindAddressDef.inetAddress, port + i);
            }
            logger.fine("Trying to bind inet socket address: " + inetSocketAddress);
            serverSocket.bind(inetSocketAddress, SOCKET_BACKLOG_LENGTH);
            logger.fine("Bind successful to inet socket address: " + serverSocket.getLocalSocketAddress());
            break;
        } catch (Exception e) {
            serverSocket.close();
            serverSocketChannel.close();
            error = e;
        }
    }
    if (serverSocket == null || !serverSocket.isBound()) {
        String message;
        if (networkConfig.isPortAutoIncrement()) {
            message = "ServerSocket bind has failed. Hazelcast cannot start. config-port: " + networkConfig.getPort() + ", latest-port: " + (port + portTrialCount);
        } else {
            message = "Port [" + port + "] is already in use and auto-increment is disabled." + " Hazelcast cannot start.";
        }
        throw new HazelcastException(message, error);
    }
    // get the actual port that's bound by server socket
    port = serverSocket.getLocalPort();
    serverSocketChannel.configureBlocking(false);
    bindAddress = createAddress(bindAddressDef, port);
    logger.info("Picked " + bindAddress + ", using socket " + serverSocket + ", bind any local is " + bindAny);
    return getPublicAddress(port);
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) InetSocketAddress(java.net.InetSocketAddress) NetworkConfig(com.hazelcast.config.NetworkConfig) ServerSocket(java.net.ServerSocket) SocketException(java.net.SocketException) HazelcastException(com.hazelcast.core.HazelcastException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 3 with HazelcastException

use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.

the class ClientConnectionManagerImpl method createSocketConnection.

protected ClientConnection createSocketConnection(final Address address) throws IOException {
    if (!alive) {
        throw new HazelcastException("ConnectionManager is not active!");
    }
    SocketChannel socketChannel = null;
    try {
        socketChannel = SocketChannel.open();
        Socket socket = socketChannel.socket();
        socket.setKeepAlive(socketOptions.isKeepAlive());
        socket.setTcpNoDelay(socketOptions.isTcpNoDelay());
        socket.setReuseAddress(socketOptions.isReuseAddress());
        if (socketOptions.getLingerSeconds() > 0) {
            socket.setSoLinger(true, socketOptions.getLingerSeconds());
        }
        int bufferSize = getBufferSize();
        socket.setSendBufferSize(bufferSize);
        socket.setReceiveBufferSize(bufferSize);
        InetSocketAddress inetSocketAddress = address.getInetSocketAddress();
        socketChannel.socket().connect(inetSocketAddress, connectionTimeout);
        SocketChannelWrapper socketChannelWrapper = socketChannelWrapperFactory.wrapSocketChannel(socketChannel, true);
        final ClientConnection clientConnection = new ClientConnection(client, ioThreadingModel, connectionIdGen.incrementAndGet(), socketChannelWrapper);
        socketChannel.configureBlocking(true);
        if (socketInterceptor != null) {
            socketInterceptor.onConnect(socket);
        }
        socketChannel.configureBlocking(ioThreadingModel.isBlocking());
        socket.setSoTimeout(0);
        clientConnection.start();
        return clientConnection;
    } catch (Exception e) {
        if (socketChannel != null) {
            socketChannel.close();
        }
        throw ExceptionUtil.rethrow(e, IOException.class);
    }
}
Also used : SocketChannel(java.nio.channels.SocketChannel) HazelcastException(com.hazelcast.core.HazelcastException) SocketChannelWrapper(com.hazelcast.internal.networking.SocketChannelWrapper) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) Socket(java.net.Socket) TimeoutException(java.util.concurrent.TimeoutException) HazelcastException(com.hazelcast.core.HazelcastException) IOException(java.io.IOException) AuthenticationException(com.hazelcast.client.AuthenticationException)

Example 4 with HazelcastException

use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.

the class XmlClientConfigLocator method loadFromWorkingDirectory.

private boolean loadFromWorkingDirectory() {
    File file = new File("hazelcast-client.xml");
    if (!file.exists()) {
        LOGGER.finest("Could not find 'hazelcast-client.xml' in working directory.");
        return false;
    }
    LOGGER.info("Loading 'hazelcast-client.xml' from working directory.");
    try {
        in = new FileInputStream(file);
    } catch (FileNotFoundException e) {
        throw new HazelcastException("Failed to open file: " + file.getAbsolutePath(), e);
    }
    return true;
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 5 with HazelcastException

use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.

the class XmlClientConfigLocator method loadSystemPropertyFileResource.

private void loadSystemPropertyFileResource(String configSystemProperty) {
    //it is a file.
    File configurationFile = new File(configSystemProperty);
    LOGGER.info("Using configuration file at " + configurationFile.getAbsolutePath());
    if (!configurationFile.exists()) {
        String msg = "Config file at '" + configurationFile.getAbsolutePath() + "' doesn't exist.";
        throw new HazelcastException(msg);
    }
    try {
        in = new FileInputStream(configurationFile);
    } catch (FileNotFoundException e) {
        throw new HazelcastException("Failed to open file: " + configurationFile.getAbsolutePath(), e);
    }
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

HazelcastException (com.hazelcast.core.HazelcastException)123 IOException (java.io.IOException)43 QuickTest (com.hazelcast.test.annotation.QuickTest)19 Test (org.junit.Test)19 TxQueueItem (com.hazelcast.collection.impl.txnqueue.TxQueueItem)14 TransactionException (com.hazelcast.transaction.TransactionException)14 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)13 File (java.io.File)13 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)8 FileInputStream (java.io.FileInputStream)8 FileNotFoundException (java.io.FileNotFoundException)8 Data (com.hazelcast.internal.serialization.Data)7 OOfflineNodeException (com.orientechnologies.common.concur.OOfflineNodeException)6 Future (java.util.concurrent.Future)6 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)5 OException (com.orientechnologies.common.exception.OException)5 OIOException (com.orientechnologies.common.io.OIOException)5 ODistributedRedirectException (com.orientechnologies.orient.enterprise.channel.binary.ODistributedRedirectException)5 EOFException (java.io.EOFException)5 ArrayList (java.util.ArrayList)5