org.apache.ignite.internal.processors.affinity

## Class GridAffinityAssignmentCache

- java.lang.Object
- - org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache

    public class GridAffinityAssignmentCache
    extends Object

Affinity cached function.

### Field Summary

Fields
`static int` `DFLT_AFFINITY_HISTORY_SIZE`
`static float` `DFLT_PART_DISTRIBUTION_WARN_THRESHOLD`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`List<List<ClusterNode>>` `assignments(AffinityTopologyVersion topVer)`
`Set<Integer>` `backupPartitions(UUID nodeId, AffinityTopologyVersion topVer)` Get backup partitions for specified node ID.
`AffinityAssignment` `cachedAffinity(AffinityTopologyVersion topVer)` Get cached affinity for specified topology version.
`AffinityAssignment` `cachedAffinity(AffinityTopologyVersion topVer, AffinityTopologyVersion lastAffChangeTopVer)` Get cached affinity for specified topology version.
`NavigableSet<AffinityTopologyVersion>` `cachedVersions()`
`String` `cacheOrGroupName()`
`IdealAffinityAssignment` `calculate(AffinityTopologyVersion topVer, @Nullable ExchangeDiscoveryEvents events, @Nullable DiscoCache discoCache)` Calculates ideal assignment for given topology version and events happened since last calculation.
`void` `cancelFutures(IgniteCheckedException err)` Kernal stop callback.
`boolean` `centralizedAffinityFunction()`
`void` `clientEventTopologyChange(DiscoveryEvent evt, AffinityTopologyVersion topVer)` Copies previous affinity assignment when discovery event does not cause affinity assignment changes (e.g. client node joins on leaves).
`static GridAffinityAssignmentCache` `create(GridKernalContext ctx, AffinityFunction aff, CacheConfiguration<?,?> ccfg)`
`boolean` `dumpDebugInfo()` Dumps debug information.
`int` `groupId()`
`@Nullable IdealAffinityAssignment` `idealAssignment()`
`void` `idealAssignment(AffinityTopologyVersion topVer, List<List<ClusterNode>> assignment)`
`@Nullable List<List<ClusterNode>>` `idealAssignmentRaw()`
`void` `init(GridAffinityAssignmentCache aff)`
`void` `initialize(AffinityTopologyVersion topVer, List<List<ClusterNode>> affAssignment)` Initializes affinity with given topology version and assignment.
`AffinityAssignment` `lastReadyAffinity()`
`AffinityTopologyVersion` `lastVersion()`
`List<ClusterNode>` `nodes(int part, AffinityTopologyVersion topVer)` Gets affinity nodes for specified partition.
`void` `onReconnected()`
`Set<Integer>` `partitionPrimariesDifferentToIdeal(AffinityTopologyVersion topVer)`
`int` `partitions()`
`boolean` `primaryChanged(int part, AffinityTopologyVersion startVer, AffinityTopologyVersion endVer)`
`Set<Integer>` `primaryPartitions(UUID nodeId, AffinityTopologyVersion topVer)` Get primary partitions for specified node ID.
`AffinityAssignment` `readyAffinity(AffinityTopologyVersion topVer)`
`List<List<ClusterNode>>` `readyAssignments(AffinityTopologyVersion topVer)`
`@Nullable IgniteInternalFuture<AffinityTopologyVersion>` `readyFuture(AffinityTopologyVersion topVer)` Gets future that will be completed after topology with version `topVer` is calculated.
`Object` `similarAffinityKey()`

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

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

### Field Detail

#### DFLT_AFFINITY_HISTORY_SIZE

    public static final int DFLT_AFFINITY_HISTORY_SIZE

See Also:
  `IgniteSystemProperties.IGNITE_AFFINITY_HISTORY_SIZE`, Constant Field Values

#### DFLT_PART_DISTRIBUTION_WARN_THRESHOLD

    public static final float DFLT_PART_DISTRIBUTION_WARN_THRESHOLD

See Also:
  `IgniteSystemProperties.IGNITE_PART_DISTRIBUTION_WARN_THRESHOLD`, Constant Field Values

### Method Detail

#### create

    public static GridAffinityAssignmentCache create(GridKernalContext ctx,
                                                     AffinityFunction aff,
                                                     CacheConfiguration<?,?> ccfg)

Parameters:
  `ctx` - Kernal context.
  `aff` - Initialized affinity function.
  `ccfg` - Cache configuration.
Returns:
  Affinity assignment cache instance.

#### similarAffinityKey

    public Object similarAffinityKey()

Returns:
  Key to find caches with similar affinity.

#### cacheOrGroupName

    public String cacheOrGroupName()

Returns:
  Group name if it is specified, otherwise cache name.

#### groupId

    public int groupId()

Returns:
  Cache group ID.

#### initialize

    public void initialize(AffinityTopologyVersion topVer,
                           List<List<ClusterNode>> affAssignment)

Initializes affinity with given topology version and assignment.

Parameters:
  `topVer` - Topology version.
  `affAssignment` - Affinity assignment for topology version.

#### idealAssignment

    public void idealAssignment(AffinityTopologyVersion topVer,
                                List<List<ClusterNode>> assignment)

Parameters:
  `assignment` - Assignment.

#### idealAssignmentRaw

    @Nullable
    public @Nullable List<List<ClusterNode>> idealAssignmentRaw()

Returns:
  Assignment.

#### idealAssignment

    @Nullable
    public @Nullable IdealAffinityAssignment idealAssignment()

#### centralizedAffinityFunction

    public boolean centralizedAffinityFunction()

Returns:
  `True` if affinity function has `AffinityCentralizedFunction` annotation.

#### cancelFutures

    public void cancelFutures(IgniteCheckedException err)

Kernal stop callback.

Parameters:
  `err` - Error.

#### onReconnected

    public void onReconnected()

#### calculate

    public IdealAffinityAssignment calculate(AffinityTopologyVersion topVer,
                                             @Nullable
                                             @Nullable ExchangeDiscoveryEvents events,
                                             @Nullable
                                             @Nullable DiscoCache discoCache)

Calculates ideal assignment for given topology version and events happened since last calculation.

Parameters:
  `topVer` - Topology version to calculate affinity cache for.
  `events` - Discovery events that caused this topology version change.
  `discoCache` - Discovery cache.
Returns:
  Ideal affinity assignment.

#### clientEventTopologyChange

    public void clientEventTopologyChange(DiscoveryEvent evt,
                                          AffinityTopologyVersion topVer)

Copies previous affinity assignment when discovery event does not cause affinity assignment changes (e.g. client node joins on leaves).

Parameters:
  `evt` - Event.
  `topVer` - Topology version.

#### lastVersion

    public AffinityTopologyVersion lastVersion()

Returns:
  Last initialized affinity version.

#### lastReadyAffinity

    public AffinityAssignment lastReadyAffinity()

Returns:
  Last initialized affinity assignment.

#### assignments

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

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

#### readyAssignments

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

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

#### readyFuture

    @Nullable
    public @Nullable IgniteInternalFuture<AffinityTopologyVersion> readyFuture(AffinityTopologyVersion topVer)

Gets future that will be completed after topology with version `topVer` is calculated.

Parameters:
  `topVer` - Topology version to await for.
Returns:
  Future that will be completed after affinity for topology version `topVer` is calculated.

#### partitions

    public int partitions()

Returns:
  Partition count.

#### nodes

    public List<ClusterNode> nodes(int part,
                                   AffinityTopologyVersion topVer)

Gets affinity nodes for specified partition.

Parameters:
  `part` - Partition.
  `topVer` - Topology version.
Returns:
  Affinity nodes.

#### partitionPrimariesDifferentToIdeal

    public Set<Integer> partitionPrimariesDifferentToIdeal(AffinityTopologyVersion topVer)

Parameters:
  `topVer` - Topology version.

#### primaryPartitions

    public Set<Integer> primaryPartitions(UUID nodeId,
                                          AffinityTopologyVersion topVer)

Get primary partitions for specified node ID.

Parameters:
  `nodeId` - Node ID to get primary partitions for.
  `topVer` - Topology version.
Returns:
  Primary partitions for specified node ID.

#### backupPartitions

    public Set<Integer> backupPartitions(UUID nodeId,
                                         AffinityTopologyVersion topVer)

Get backup partitions for specified node ID.

Parameters:
  `nodeId` - Node ID to get backup partitions for.
  `topVer` - Topology version.
Returns:
  Backup partitions for specified node ID.

#### dumpDebugInfo

    public boolean dumpDebugInfo()

Dumps debug information.

Returns:
  `True` if there are pending futures.

#### readyAffinity

    public AffinityAssignment readyAffinity(AffinityTopologyVersion topVer)

Parameters:
  `topVer` - Topology version.
Returns:
  Assignment.
Throws:
  `IllegalStateException` - If affinity assignment is not initialized for the given topology version.

#### cachedAffinity

    public AffinityAssignment cachedAffinity(AffinityTopologyVersion topVer)

Get cached affinity for specified topology version.

Parameters:
  `topVer` - Topology version.
Returns:
  Cached affinity.
Throws:
  `IllegalArgumentException` - in case of the specified topology version `topVer` is earlier than affinity is calculated or the history of assignments is already cleaned.

#### cachedAffinity

    public AffinityAssignment cachedAffinity(AffinityTopologyVersion topVer,
                                             AffinityTopologyVersion lastAffChangeTopVer)

Get cached affinity for specified topology version.

Parameters:
  `topVer` - Topology version for which affinity assignment is requested.
  `lastAffChangeTopVer` - Topology version of last affinity assignment change.
Returns:
  Cached affinity.
Throws:
  `IllegalArgumentException` - in case of the specified topology version `topVer` is earlier than affinity is calculated or the history of assignments is already cleaned.

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

#### init

    public void init(GridAffinityAssignmentCache aff)

Parameters:
  `aff` - Affinity cache.

#### cachedVersions

    public NavigableSet<AffinityTopologyVersion> cachedVersions()

Returns:
  All initialized versions.

${current.year} Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Database and Caching Platform | : ver. 2.14.0
Release Date | : September 29 2022