October 20th, Q&A session: Get you issues solved and questions answered!

GitHub logo
Edit

Starting and Stopping Nodes

This chapter explains how to start server and client nodes.

There are two types of nodes: server nodes and client nodes. The client nodes are also referred as thick clients to distinguish from the thin clients. Server nodes participate in caching, compute execution, stream processing, etc. Thick clients provide the ability to connect to the servers remotely. The client nodes provide the whole set of Ignite APIs, including near caching, transactions, compute, streaming, services, etc. from the client side.

By default, all Ignite nodes are started as server nodes, and you should explicitly enable the client mode.

Starting Server Nodes

To start a regular server node, use the following command or code snippet:

ignite.sh path/to/configuration.xml
IgniteConfiguration cfg = new IgniteConfiguration();
Ignite ignite = Ignition.start(cfg);

Ignite is an AutoCloseable object. You can use the try-with-resource statement to close it automatically:

IgniteConfiguration cfg = new IgniteConfiguration();

try (Ignite ignite = Ignition.start(cfg)) {
    //
}
var cfg = new IgniteConfiguration();
IIgnite ignite = Ignition.Start(cfg);

Ignite is an IDisposable object. You can use the using statement to close it automatically:

var cfg = new IgniteConfiguration();
using (IIgnite ignite = Ignition.Start(cfg))
{
    //
}

Starting Client Nodes

To start a client node, simply enable the client mode in the node configuration:

<bean class="org.apache.ignite.configuration.IgniteConfiguration">
    <property name="clientMode" value="true"/>

</bean>
IgniteConfiguration cfg = new IgniteConfiguration();

// Enable client mode.
cfg.setClientMode(true);

// Start a client
Ignite ignite = Ignition.start(cfg);
var cfg = new IgniteConfiguration
{
    ClientMode = true
};
IIgnite ignite = Ignition.Start(cfg);

Alternatively, for convenience, you can also enable or disable the client mode though the Ignition class to allow clients and servers to reuse the same configuration.

Ignition.setClientMode(true);

// Start the node in client mode.
Ignite ignite = Ignition.start();
Ignition.ClientMode = true;
Ignition.Start();
This API is not presently available for C++.

Shutting Down Nodes

When you perform a hard (forced) shutdown on a node, it can lead to data loss or data inconsistency and can even prevent the node from restarting. Non-graceful shutdowns should be used as a last resort when the node is not responding and it cannot be shut down gracefully.

A graceful shutdown allows the node to finish critical operations and correctly complete its lifecycle. The proper procedure to perform a graceful shutdown is as follows:

  1. Stop the node using one of the following methods:

    • programmatically call Ignite.close()

    • programmatically call System.exit()

    • send a user interrupt signal. Ignite uses a JVM shutdown hook to execute custom logic before the JVM stops. If you start the node by running ignite.sh and don’t detach it from the terminal, you can stop the node by hitting Ctrl+C.

  2. Remove the node from the baseline topology. This step may not be necessary if baseline auto-adjustment is enabled.

Removing the node from the baseline topology starts the rebalancing process on the remaining nodes. If you plan to restart the node shortly after shutdown, you don’t have to do the rebalancing. In this case, do not remove the nodes from the baseline topology.

Setting JVM Options

There are several ways you can set JVM options when starting a node with the ignite.sh script. These ways are described in the following sections.

JVM_OPTS System Variable

You can set the JVM_OPTS environment variable:

export JVM_OPTS="$JVM_OPTS -Xmx6G -DIGNITE_TO_STRING_INCLUDE_SENSITIVE=false"; $IGNITE_HOME/bin/ignite.sh

Command Line Arguments

You can also pass JVM options by using the -J prefix:

./ignite.sh -J-Xmx6G -J-DIGNITE_TO_STRING_INCLUDE_SENSITIVE=false

Node Lifecycle Events

Lifecycle events give you an opportunity to execute custom code at different stages of the node lifecycle.

There are 4 lifecycle events:

Event Type Description

BEFORE_NODE_START

Invoked before the node’s startup routine is initiated.

AFTER_NODE_START

Invoked right after then node has started.

BEFORE_NODE_STOP

Invoked right before the node’s stop routine is initiated.

AFTER_NODE_STOP

Invoked right after then node has stopped.

The following steps describe how to add a custom lifecycle event listener.

  1. Create a custom lifecycle bean by implementing the LifecycleBean interface. The interface has the onLifecycleEvent() method, which is called for any lifecycle event.

    public class MyLifecycleBean implements LifecycleBean {
        @IgniteInstanceResource
        public Ignite ignite;
    
        @Override
        public void onLifecycleEvent(LifecycleEventType evt) {
            if (evt == LifecycleEventType.AFTER_NODE_START) {
    
                System.out.format("After the node (consistentId = %s) starts.\n", ignite.cluster().node().consistentId());
    
            }
        }
    }
  2. Register the implementation in the node configuration.

    <bean class="org.apache.ignite.configuration.IgniteConfiguration">
        <property name="lifecycleBeans">
            <list>
                <bean class="org.apache.ignite.snippets.MyLifecycleBean"/>
            </list>
        </property>
    </bean>
    IgniteConfiguration cfg = new IgniteConfiguration();
    
    // Specify a lifecycle bean in the node configuration.
    cfg.setLifecycleBeans(new MyLifecycleBean());
    
    // Start the node.
    Ignite ignite = Ignition.start(cfg);