Interface SeedNodeProvider

  • All Known Implementing Classes:
    CloudSeedNodeProvider, CloudStoreSeedNodeProvider, ConsulSeedNodeProvider, EtcdSeedNodeProvider, FsSeedNodeProvider, JdbcSeedNodeProvider, KubernetesSeedNodeProvider, MulticastSeedNodeProvider, SeedNodeProviderGroup, StaticSeedNodeProvider, ZooKeeperSeedNodeProvider

    public interface SeedNodeProvider
    « start hereSeed node provider.

    Overview

    Implementations of this interface are responsible for providing seed node addresses to the ClusterService when it starts joining to the cluster. Seed nodes in this context are nodes that are already running within the cluster and can be used by the newly joining node to send its initial contact information and start the cluster joining negotiations. Due to the decentralized cluster management algorithm any existing node within the cluster can be used as a seed node. Once new node completes its joining to the cluster then it can also be used as a seed node for other nodes.

    Generic usage

    This interface provides API that can be used to implement various strategies of seed node discovering, f.e. based on group communications protocols (like IP multicast), shared storage (like RDBMS, distributes file system, etc) or simple pre-configured list of addresses. Below are the key points of how this interface is used by the cluster service:

    • When cluster service starts joining the cluster it calls startDiscovery(String, InetSocketAddress) method in order to register the local node address and instruct the seed node provider to start discovering other nodes. Implementations of this method can start sending multicast advertisement messages or register the local node address within some shared central repository.
    • Cluster service periodically calls findSeedNodes(String) method and tries to contact each of the returned addresses one by one by sending a join request message.
    • If any of the discovered nodes replies with the join accept message then cluster service calls suspendDiscovery() so that seed node provider could stop all activities that are not necessary after live seed node have been discovered (f.e. stop advertising via multicast). Seed node provider should still keep its local node information registered so that other joining nodes could use the local node as seed node.
    • When cluster service stops it calls stopDiscovery(String, InetSocketAddress) method to unregister the local node address and stop the seed node provider.

    Shared state and stale data

    If implementation of this interface uses some kind of persistent shared storage then in case of a particular node crash it's address information can still remain registered in the shared storage. In order to clean such stale information the cluster service elects a leader that periodically scans through all registered addresses, checks their aliveness and removes addresses that are not accessible.

    Time interval of stale data checking is controlled by the value of cleanupInterval() method. If this method returns a positive value then once per such interval the findSeedNodes(String) method will be called and each of the returned address will be checked for aliveness (by sending a ping message). If particular address is considered to be failed then it will be unregistered via unregisterRemote(String, InetSocketAddress) method. Cluster service will also compare its know topology with the list of addresses and will re-registered missing addresses via registerRemote(String, InetSocketAddress).

    Registration

    Instances of this interface can be registered within the cluster service via ClusterServiceFactory.setSeedNodeProvider(SeedNodeProvider) method.

    See Also:
    ClusterService, ClusterServiceFactory.setSeedNodeProvider(SeedNodeProvider)
    • Method Detail

      • suspendDiscovery

        void suspendDiscovery()
                       throws HekateException
        Suspends discovery activities.
        Throws:
        HekateException - If failed to suspend discovery activities due to some system failure.
      • cleanupInterval

        long cleanupInterval()
        Returns the time interval in milliseconds for the cluster service to perform the stale data cleaning. If the returned value if less than or equals to zero then stale data cleaning will be disabled.
        Returns:
        Time interval in milliseconds.
      • registerRemote

        void registerRemote​(String namespace,
                            InetSocketAddress node)
                     throws HekateException
        Registered the specified addresses within this provider.

        This method is the part of a stale data cleanup activity and is performed by the cluster service if it detects that particular node is within its cluster topology but is not registered within this provider (i.e. not returned from findSeedNodes(String) method).

        Parameters:
        namespace - Cluster namespace (see ClusterServiceFactory.setNamespace(String)).
        node - Node address that should be registered.
        Throws:
        HekateException - If node couldn't be registered due to the system failure.
      • unregisterRemote

        void unregisterRemote​(String namespace,
                              InetSocketAddress node)
                       throws HekateException
        Unregisters the specified address from this provider.

        This method is the part of a stale data cleanup activity and is called by the cluster service if it detects that there is no cluster node running at the specified address while this address is still registered within this provider (i.e. is returned from findSeedNodes(String) method).

        Parameters:
        namespace - Cluster namespace (see ClusterServiceFactory.setNamespace(String)).
        node - Node address that should be unregistered.
        Throws:
        HekateException - If node couldn't be unregistered due to the system failure.