org.apache.ignite.internal.processors.cache

## Class GridCacheAffinityManager

- java.lang.Object
- - org.apache.ignite.internal.processors.cache.GridCacheManagerAdapter
  - - org.apache.ignite.internal.processors.cache.GridCacheAffinityManager

All Implemented Interfaces:
  GridCacheManager

    public class GridCacheAffinityManager
    extends GridCacheManagerAdapter

Cache affinity manager.

### Field Summary

### Fields inherited from class org.apache.ignite.internal.processors.cache.GridCacheManagerAdapter

`cctx, log, starting`

### Constructor Summary

Constructors
Constructor and Description
`GridCacheAffinityManager()`

### Method Summary

All Methods Instance Methods Concrete Methods
`Object` `affinityKey(Object key)` If Key is `GridCacheInternal` entry when won't passed into user's mapper and will use `default`.
`IgniteInternalFuture<AffinityTopologyVersion>` `affinityReadyFuture(AffinityTopologyVersion topVer)` Gets affinity ready future, a future that will be completed after affinity with given topology version is calculated.
`IgniteInternalFuture<AffinityTopologyVersion>` `affinityReadyFuture(long topVer)` Gets affinity ready future, a future that will be completed after affinity with given topology version is calculated.
`IgniteInternalFuture<AffinityTopologyVersion>` `affinityReadyFuturex(AffinityTopologyVersion topVer)` Gets affinity ready future that will be completed after affinity with given topology version is calculated.
`AffinityTopologyVersion` `affinityTopologyVersion()`
`AffinityAssignment` `assignment(AffinityTopologyVersion topVer)` Get affinity assignment for the given topology version.
`List<List<ClusterNode>>` `assignments(AffinityTopologyVersion topVer)`
`boolean` `backupByPartition(ClusterNode n, int part, AffinityTopologyVersion topVer)`
`Set<Integer>` `backupPartitions(UUID nodeId, AffinityTopologyVersion topVer)`
`Collection<ClusterNode>` `backupsByKey(Object key, AffinityTopologyVersion topVer)`
`List<List<ClusterNode>>` `idealAssignment()`
`boolean` `keyLocalNode(Object key, AffinityTopologyVersion topVer)`
`List<ClusterNode>` `nodesByKey(Object key, AffinityTopologyVersion topVer)`
`List<ClusterNode>` `nodesByPartition(int part, AffinityTopologyVersion topVer)`
`protected void` `onKernalStart0()`
`int` `partition(Object key)`
`int` `partition(Object key, boolean useKeyPart)` NOTE: Use this method always when you need to calculate partition id for a key provided by user.
`boolean` `partitionBelongs(ClusterNode node, int part, AffinityTopologyVersion topVer)`
`boolean` `partitionLocalNode(int part, AffinityTopologyVersion topVer)`
`int` `partitions()`
`boolean` `primaryByKey(ClusterNode n, Object key, AffinityTopologyVersion topVer)`
`ClusterNode` `primaryByKey(Object key, AffinityTopologyVersion topVer)`
`boolean` `primaryByPartition(ClusterNode n, int part, AffinityTopologyVersion topVer)`
`ClusterNode` `primaryByPartition(int part, AffinityTopologyVersion topVer)`
`boolean` `primaryChanged(int part, AffinityTopologyVersion startVer, AffinityTopologyVersion endVer)`
`Set<Integer>` `primaryPartitions(UUID nodeId, AffinityTopologyVersion topVer)`
`void` `start0()`
`protected void` `stop0(boolean cancel, boolean destroy)`

### Methods inherited from class org.apache.ignite.internal.processors.cache.GridCacheManagerAdapter

`context, kernalStartInfo, kernalStopInfo, log, onDisconnected, onKernalStart, onKernalStop, onKernalStop0, printMemoryStats, start, startInfo, stop, stopInfo, toString`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### GridCacheAffinityManager

    public GridCacheAffinityManager()

### Method Detail

#### start0

    public void start0()
                throws IgniteCheckedException

Overrides:
  `start0` in class `GridCacheManagerAdapter`
Throws:
  `IgniteCheckedException` - If failed.

#### onKernalStart0

    protected void onKernalStart0()
                           throws IgniteCheckedException

Overrides:
  `onKernalStart0` in class `GridCacheManagerAdapter`
Throws:
  `IgniteCheckedException` - If failed.

#### 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.

#### affinityReadyFuture

    public IgniteInternalFuture<AffinityTopologyVersion> affinityReadyFuture(AffinityTopologyVersion 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 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`.

#### assignments

    public List<List<ClusterNode>> assignments(AffinityTopologyVersion topVer)

Parameters:
  `topVer` - Topology version.
Returns:
  Affinity assignments.

#### idealAssignment

    public List<List<ClusterNode>> idealAssignment()

Returns:
  Assignment.

#### 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.

#### nodesByKey

    public List<ClusterNode> nodesByKey(Object key,
                                        AffinityTopologyVersion topVer)

Parameters:
  `key` - Key.
  `topVer` - Topology version.
Returns:
  Affinity nodes.

#### 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 ClusterNode primaryByKey(Object key,
                                              AffinityTopologyVersion topVer)

Parameters:
  `key` - Key to check.
  `topVer` - Topology version.
Returns:
  Primary node for given key.

#### primaryByPartition

    @Nullable
    public 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.

#### backupsByKey

    public Collection<ClusterNode> backupsByKey(Object key,
                                                AffinityTopologyVersion topVer)

Parameters:
  `key` - Key to check.
  `topVer` - Topology version.
Returns:
  Backup nodes.

#### 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.

2018 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 2.4.0
Release Date | : March 5 2018