Starting and Stopping Nodes | Ignite Documentation

Ignite Summit 2024 — Call For Speakers Now Open — Learn more

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:

<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You 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.
-->
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:util="http://www.springframework.org/schema/util" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="         http://www.springframework.org/schema/beans         http://www.springframework.org/schema/beans/spring-beans.xsd         http://www.springframework.org/schema/util         http://www.springframework.org/schema/util/spring-util.xsd">
    <bean class="org.apache.ignite.configuration.IgniteConfiguration">
        <property name="clientMode" value="true"/>

    </bean>
</beans>
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.

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);