Class TcpDiscoveryNodesRing


  • public class TcpDiscoveryNodesRing
    extends Object
    Convenient way to represent topology for TcpDiscoverySpi
    • Constructor Detail

      • TcpDiscoveryNodesRing

        public TcpDiscoveryNodesRing()
    • Method Detail

      • minimumNodeVersion

        public IgniteProductVersion minimumNodeVersion()
        Returns:
        Minimum node version.
      • localNode

        public void localNode​(TcpDiscoveryNode locNode)
        Sets local node.
        Parameters:
        locNode - Local node.
      • visibleNodes

        public Collection<TcpDiscoveryNode> visibleNodes()
        Gets visible nodes in the topology.
        Returns:
        Collection of visible nodes.
      • visibleRemoteNodes

        public Collection<TcpDiscoveryNode> visibleRemoteNodes()
        Gets visible remote nodes in the topology.
        Returns:
        Collection of visible remote nodes.
      • hasRemoteNodes

        public boolean hasRemoteNodes()
        Checks whether the topology has remote nodes in.
        Returns:
        true if the topology has remote nodes in.
      • hasRemoteServerNodes

        public boolean hasRemoteServerNodes()
        Checks whether the topology has remote server nodes in.
        Returns:
        true if the topology has remote server nodes in.
      • add

        public boolean add​(TcpDiscoveryNode node)
        Adds node to topology, also initializes node last update time with current system time.
        Parameters:
        node - Node to add.
        Returns:
        true if such node was added and did not present previously in the topology.
      • maxInternalOrder

        public long maxInternalOrder()
        Returns:
        Max internal order.
      • restoreTopology

        public void restoreTopology​(Iterable<TcpDiscoveryNode> nodes,
                                    long topVer)
        Restores topology from parameters values.

        This method is called when new node receives topology from coordinator. In this case all nodes received are remote for local.

        Also initializes nodes last update time with current system time.

        Parameters:
        nodes - List of remote nodes.
        topVer - Topology version.
      • node

        @Nullable
        public @Nullable TcpDiscoveryNode node​(UUID nodeId)
        Finds node by ID.
        Parameters:
        nodeId - Node id to find.
        Returns:
        Node with ID provided or null if not found.
      • removeNode

        @Nullable
        public @Nullable TcpDiscoveryNode removeNode​(UUID nodeId)
        Removes node from the topology.
        Parameters:
        nodeId - ID of the node to remove.
        Returns:
        true if node was removed.
      • clear

        public void clear()
        Removes all remote nodes, leaves only local node.

        This should be called when SPI should be disconnected from topology and reconnected back after.

      • coordinator

        @Nullable
        public @Nullable TcpDiscoveryNode coordinator()
        Finds coordinator in the topology.
        Returns:
        Coordinator node that gives versions to topology (node with the smallest order).
      • coordinator

        @Nullable
        public @Nullable TcpDiscoveryNode coordinator​(@Nullable
                                                      @Nullable Collection<TcpDiscoveryNode> excluded)
        Finds coordinator in the topology filtering excluded nodes from the search.

        This may be used when handling current coordinator leave or failure.

        Parameters:
        excluded - Nodes to exclude from the search (optional).
        Returns:
        Coordinator node among remaining nodes or null if all nodes are excluded.
      • nextNode

        @Nullable
        public @Nullable TcpDiscoveryNode nextNode()
        Finds next node in the topology.
        Returns:
        Next node.
      • nextNode

        @Nullable
        public @Nullable TcpDiscoveryNode nextNode​(@Nullable
                                                   @Nullable Collection<TcpDiscoveryNode> excluded)
        Finds next node in the topology filtering excluded nodes from search.

        This may be used when detecting and handling nodes failure.

        Parameters:
        excluded - Nodes to exclude from the search (optional). If provided, cannot contain local node.
        Returns:
        Next node or null if all nodes were filtered out or topology contains less than two nodes.
      • previousNode

        @Nullable
        public @Nullable TcpDiscoveryNode previousNode​(@Nullable
                                                       @Nullable Collection<TcpDiscoveryNode> excluded)
        Finds previous node in the topology filtering excluded nodes from search.

        This may be used when detecting and handling nodes failure.

        Parameters:
        excluded - Nodes to exclude from the search (optional). If provided, cannot contain local node.
        Returns:
        Previous node or null if all nodes were filtered out or topology contains less than two nodes.
      • previousNodeOf

        public TcpDiscoveryNode previousNodeOf​(TcpDiscoveryNode ringNode)
        Parameters:
        ringNode - Node for which to find a predecessor.
        Returns:
        Previous node of the given node in the ring.
        Throws:
        IllegalArgumentException - If the given node was not found in the ring.
      • topologyVersion

        public long topologyVersion()
        Gets current topology version.
        Returns:
        Current topology version.
      • topologyVersion

        public boolean topologyVersion​(long topVer)
        Sets new topology version.
        Parameters:
        topVer - New topology version (should be greater than current, otherwise no-op).
        Returns:
        True if topology has been changed.
      • incrementTopologyVersion

        public long incrementTopologyVersion()
        Increments topology version and gets new value.
        Returns:
        Topology version (incremented).
      • nextNodeOrder

        public long nextNodeOrder()
        Increments topology version and gets new value.
        Returns:
        Topology version (incremented).