Cluster Singletons

Define various guaranteed cluster singletons.

IServices facade allows to deploy any number of services on any of the grid nodes. However, the most commonly used feature is to deploy singleton services on the cluster. Ignite will manage the singleton contract regardless of topology changes and node crashes.

📘

Note that in case of topology changes, due to network delays, there may be a temporary situation when a singleton service instance will be active on more than one node (e.g. crash detection delay).

Cluster Singleton

You can deploy a cluster-wide singleton service. Ignite will guarantee that there is always one instance of the service in the cluster. In case the cluster node on which the service was deployed crashes or stops, Ignite will automatically redeploy it on another node. However, if the node on which the service is deployed remains in topology, then the service will always be deployed on that node only, regardless of topology changes.

IServices svcs = ignite.GetServices();

svcs.DeployClusterSingleton("myClusterSingleton", new MyService());

The above method is equivalent to calling

svcs.DeployMultiple("myClusterSingleton", new MyService(), 1, 1)

Node Singleton

You can deploy a per-node singleton service. Ignite will guarantee that there is always one instance of the service running on each node. Whenever new nodes are started within the cluster group, Ignite will automatically deploy one instance of the service on every new node.

IServices svcs = ignite.GetServices();

svcs.DeployNodeSingleton("myNodeSingleton", new MyService());

The above method is equivalent to calling

svcs.DeployMultiple("myNodeSingleton", new MyService(), 0, 1);

Cache Key Affinity Singleton

You can deploy one instance of the service on the primary node for a given affinity key. Whenever topology changes and primary key node assignment changes, Ignite will always make sure that the service is undeployed on the previous primary node and is deployed on the new primary node.

IServices svcs = ignite.GetServices();

svcs.DeployKeyAffinitySingleton("myKeySingleton", new MyService(), "myCache", new MyCacheKey());

The above method is equivalent to calling

IServices svcs = ignite.GetServices();

var cfg = new ServiceConfiguration
{
    Name = "myKeySingleton",
    Service = new MyService(),
    CacheName = "myCache",
    AffinityKey = new MyCacheKey(),
    TotalCount = 1,
    MaxPerNodeCount = 1
};
 
svcs.deploy(cfg);