Cluster Groups | Ignite Documentation

Ignite Summit: Сloud Edition | Using Ignite In The Cloud - Watch On Demand →

Edit

Cluster Groups

The ClusterGroup interface represents a logical group of nodes, which can be used in many of Ignite’s APIs when you want to limit the scope of specific operations to a subset of nodes (instead of the whole cluster). For example, you may wish to deploy a service only on remote nodes or execute a job only on the set of nodes that have a specific attribute.

Tip
Note that the IgniteCluster interface is also a cluster group which includes all the nodes in the cluster.

You can limit job execution, service deployment, messaging, events, and other tasks to run only on a specific set of node. For example, here is how to broadcast a job only to remote nodes (excluding the local node).

Ignite ignite = Ignition.ignite();

IgniteCluster cluster = ignite.cluster();

// Get compute instance which will only execute
// over remote nodes, i.e. all the nodes except for this one.
IgniteCompute compute = ignite.compute(cluster.forRemotes());

// Broadcast to all remote nodes and print the ID of the node
// on which this closure is executing.
compute.broadcast(
        () -> System.out.println("Hello Node: " + ignite.cluster().localNode().id()));
class PrintNodeIdAction : IComputeAction
{
    public void Invoke()
    {
        Console.WriteLine("Hello node: " +
                          Ignition.GetIgnite().GetCluster().GetLocalNode().Id);
    }
}

public static void RemotesBroadcastDemo()
{
    var ignite = Ignition.Start();

    var cluster = ignite.GetCluster();

    // Get compute instance which will only execute
    // over remote nodes, i.e. all the nodes except for this one.
    var compute = cluster.ForRemotes().GetCompute();

    // Broadcast to all remote nodes and print the ID of the node
    // on which this closure is executing.
    compute.Broadcast(new PrintNodeIdAction());
}
class PrintNodeIdAction : public ComputeFunc<void> {
public:
    virtual void Call() {
        std::cout << "Hello node " <<  Ignition::Get().GetCluster().GetLocalNode().GetId() << std::endl;
    }
};
namespace ignite { namespace binary {
    template<> struct BinaryType<PrintNodeIdAction>: BinaryTypeDefaultAll<PrintNodeIdAction> {
        static void GetTypeName(std::string& dst) {
            dst = "PrintNodeIdAction";
        }
        static void Write(BinaryWriter& writer, const PrintNodeIdAction& obj) {}
        static void Read(BinaryReader& reader, PrintNodeIdAction& dst) {}
    };
}}
void void RemotesBroadcastDemo()
{
    Ignite ignite = Ignition::Get();
    IgniteCluster cluster = ignite.GetCluster();
    // Get compute instance which will only execute
    // over remote nodes, i.e. all the nodes except for this one.
    Compute compute = ignite.GetCompute(cluster.AsClusterGroup().ForRemotes());
    // Broadcast to all remote nodes and print the ID of the node
    // on which this closure is executing.
    compute.Broadcast(PrintNodeIdAction());
}

For convenience, Ignite comes with a number of predefined cluster groups.

IgniteCluster cluster = ignite.cluster();

// All nodes on which the cache with name "myCache" is deployed,
// either in client or server mode.
ClusterGroup cacheGroup = cluster.forCacheNodes("myCache");

// All data nodes responsible for caching data for "myCache".
ClusterGroup dataGroup = cluster.forDataNodes("myCache");

// All client nodes that can access "myCache".
ClusterGroup clientGroup = cluster.forClientNodes("myCache");
var cluster = ignite.GetCluster();

// All nodes on which cache with name "myCache" is deployed,
// either in client or server mode.
var cacheGroup = cluster.ForCacheNodes("myCache");

// All data nodes responsible for caching data for "myCache".
var dataGroup = cluster.ForDataNodes("myCache");

// All client nodes that access "myCache".
var clientGroup = cluster.ForClientNodes("myCache");
Ignite ignite = Ignition::Get();
ClusterGroup cluster = ignite.GetCluster().AsClusterGroup();
// All nodes on which cache with name "myCache" is deployed,
// either in client or server mode.
ClusterGroup cacheGroup = cluster.ForCacheNodes("myCache");
// All data nodes responsible for caching data for "myCache".
ClusterGroup dataGroup = cluster.ForDataNodes("myCache");
// All client nodes that access "myCache".
ClusterGroup clientGroup = cluster.ForClientNodes("myCache");