Class GridCacheAffinityManager

    • Constructor Detail

      • GridCacheAffinityManager

        public GridCacheAffinityManager()
    • Method Detail

      • stop0

        protected void stop0​(boolean cancel,
                             boolean destroy)
        Overrides:
        stop0 in class GridCacheManagerAdapter
        Parameters:
        cancel - Cancel flag.
        destroy - Cache destroy flag.
      • affinityReadyFuture

        public IgniteInternalFuture<AffinityTopologyVersion> affinityReadyFuture​(long topVer)
        Gets affinity ready future, a future that will be completed after affinity with given topology version is calculated.
        Parameters:
        topVer - Topology version to wait.
        Returns:
        Affinity ready future.
      • affinityReadyFuturex

        @Nullable
        public @Nullable IgniteInternalFuture<AffinityTopologyVersion> affinityReadyFuturex​(AffinityTopologyVersion topVer)
        Gets affinity ready future that will be completed after affinity with given topology version is calculated. Will return null if topology with given version is ready by the moment method is invoked.
        Parameters:
        topVer - Topology version to wait.
        Returns:
        Affinity ready future or null.
      • partitions

        public int partitions()
        Returns:
        Partition count.
      • partition

        public int partition​(Object key)
        Parameters:
        key - Key.
        Returns:
        Partition.
      • partition

        public int partition​(Object key,
                             boolean useKeyPart)
        NOTE: Use this method always when you need to calculate partition id for a key provided by user. It's required since we should apply affinity mapper logic in order to find a key that will eventually be passed to affinity function.
        Parameters:
        key - Key.
        useKeyPart - If true can use pre-calculated partition stored in KeyCacheObject.
        Returns:
        Partition.
      • affinityKey

        public Object affinityKey​(Object key)
        If Key is GridCacheInternal entry when won't passed into user's mapper and will use default.
        Parameters:
        key - Key.
        Returns:
        Affinity key.
      • nodesByPartition

        public List<ClusterNode> nodesByPartition​(int part,
                                                  AffinityTopologyVersion topVer)
        Parameters:
        part - Partition.
        topVer - Topology version.
        Returns:
        Affinity nodes.
      • assignment

        public AffinityAssignment assignment​(AffinityTopologyVersion topVer)
        Get affinity assignment for the given topology version.
        Parameters:
        topVer - Topology version.
        Returns:
        Affinity assignment.
      • primaryByKey

        @Nullable
        public @Nullable ClusterNode primaryByKey​(Object key,
                                                  AffinityTopologyVersion topVer)
        Parameters:
        key - Key to check.
        topVer - Topology version.
        Returns:
        Primary node for given key.
      • primaryByPartition

        @Nullable
        public @Nullable ClusterNode primaryByPartition​(int part,
                                                        AffinityTopologyVersion topVer)
        Parameters:
        part - Partition.
        topVer - Topology version.
        Returns:
        Primary node for given key.
      • primaryByKey

        public boolean primaryByKey​(ClusterNode n,
                                    Object key,
                                    AffinityTopologyVersion topVer)
        Parameters:
        n - Node to check.
        key - Key to check.
        topVer - Topology version.
        Returns:
        True if checked node is primary for given key.
      • primaryByPartition

        public boolean primaryByPartition​(ClusterNode n,
                                          int part,
                                          AffinityTopologyVersion topVer)
        Parameters:
        n - Node to check.
        part - Partition.
        topVer - Topology version.
        Returns:
        True if checked node is primary for given partition.
      • backupByPartition

        public boolean backupByPartition​(ClusterNode n,
                                         int part,
                                         AffinityTopologyVersion topVer)
        Parameters:
        n - Node to check.
        part - Partition.
        topVer - Topology version.
        Returns:
        True if checked node is a backup node for given partition.
      • keyLocalNode

        public boolean keyLocalNode​(Object key,
                                    AffinityTopologyVersion topVer)
        Parameters:
        key - Key to check.
        topVer - Topology version.
        Returns:
        true if given key belongs to local node.
      • partitionLocalNode

        public boolean partitionLocalNode​(int part,
                                          AffinityTopologyVersion topVer)
        Parameters:
        part - Partition number to check.
        topVer - Topology version.
        Returns:
        true if given partition belongs to local node.
      • partitionBelongs

        public boolean partitionBelongs​(ClusterNode node,
                                        int part,
                                        AffinityTopologyVersion topVer)
        Parameters:
        node - Node.
        part - Partition number to check.
        topVer - Topology version.
        Returns:
        true if given partition belongs to specified node.
      • primaryPartitions

        public Set<Integer> primaryPartitions​(UUID nodeId,
                                              AffinityTopologyVersion topVer)
        Parameters:
        nodeId - Node ID.
        topVer - Topology version to calculate affinity.
        Returns:
        Partitions for which given node is primary.
      • backupPartitions

        public Set<Integer> backupPartitions​(UUID nodeId,
                                             AffinityTopologyVersion topVer)
        Parameters:
        nodeId - Node ID.
        topVer - Topology version to calculate affinity.
        Returns:
        Partitions for which given node is backup.
      • affinityTopologyVersion

        public AffinityTopologyVersion affinityTopologyVersion()
        Returns:
        Affinity-ready topology version.
      • primaryChanged

        public boolean primaryChanged​(int part,
                                      AffinityTopologyVersion startVer,
                                      AffinityTopologyVersion endVer)
        Parameters:
        part - Partition.
        startVer - Start version.
        endVer - End version.
        Returns:
        True if primary changed or required affinity version not found in history.
      • isCompatibleWithCurrentTopologyVersion

        public boolean isCompatibleWithCurrentTopologyVersion​(AffinityTopologyVersion rmtVer)
        Parameters:
        rmtVer - Topology version to check.
        Returns:
        Whether the specified topology version can be considered identical to the current topology version.