org.apache.ignite.internal.processors.cache

## Class CacheAffinitySharedManager<K,V>

- java.lang.Object
- - org.apache.ignite.internal.processors.cache.GridCacheSharedManagerAdapter<K,V>
  - - org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager<K,V>

All Implemented Interfaces:
  GridCacheSharedManager<K,V>

    public class CacheAffinitySharedManager<K,V>
    extends GridCacheSharedManagerAdapter<K,V>

### Field Summary

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

`cctx, diagnosticLog, log`

### Constructor Summary

Constructors
Constructor and Description
`CacheAffinitySharedManager()`

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `addDhtAssignmentFetchFuture(GridDhtAssignmentFetchFuture fut)`
`void` `addToWaitGroup(int grpId, int part, AffinityTopologyVersion topVer, List<ClusterNode> assignment)` Adds historically rebalancing partitions to wait group.
`GridAffinityAssignmentCache` `affinity(Integer grpId)`
`void` `applyAffinityFromFullMessage(GridDhtPartitionsExchangeFuture fut, Map<Integer,CacheGroupAffinityMessage> idealAffDiff)` Applies affinity diff from the received full message.
`Map<Integer,CacheGroupDescriptor>` `cacheGroups()`
`Map<Integer,DynamicCacheDescriptor>` `caches()`
`void` `clearGroupHoldersAndRegistry()`
`void` `dumpDebugInfo()`
`void` `forceCloseCaches(GridDhtPartitionsExchangeFuture fut, boolean crd, ExchangeActions exchActions)` Called during the rollback of the exchange partitions procedure in order to stop the given cache even if it's not fully initialized (e.g. failed on cache init stage).
`@Nullable GridAffinityAssignmentCache` `groupAffinity(int grpId)`
`IgniteInternalFuture<Map<Integer,Map<Integer,List<UUID>>>>` `initAffinityOnNodeLeft(GridDhtPartitionsExchangeFuture fut)`
`IgniteInternalFuture<?>` `initCachesOnLocalJoin(Map<Integer,CacheGroupDescriptor> grpDescs, Map<String,DynamicCacheDescriptor> cacheDescs)` Must be called from exchange thread.
`IgniteInternalFuture<?>` `initCoordinatorCaches(GridDhtPartitionsExchangeFuture fut, boolean newAff)`
`IgniteInternalFuture<?>` `initStartedCaches(boolean crd, GridDhtPartitionsExchangeFuture fut, Collection<DynamicCacheDescriptor> descs)` Initialized affinity for cache received from node joining on this exchange.
`void` `onBaselineTopologyChanged(GridDhtPartitionsExchangeFuture fut, boolean crd)`
`IgniteInternalFuture<?>` `onCacheChangeRequest(GridDhtPartitionsExchangeFuture fut, boolean crd, ExchangeActions exchActions)` Called on exchange initiated for cache start/stop request.
`boolean` `onCentralizedAffinityChange(GridDhtPartitionsExchangeFuture fut, boolean crd)` Called on exchange initiated by server node leave or custom event with centralized affinity assignment.
`void` `onChangeAffinityMessage(GridDhtPartitionsExchangeFuture exchFut, CacheAffinityChangeMessage msg)` Called on exchange initiated by `CacheAffinityChangeMessage` which sent after rebalance finished.
`void` `onClientEvent(GridDhtPartitionsExchangeFuture fut)` Called on exchange initiated by client node join/fail.
`Map<Integer,CacheGroupAffinityMessage>` `onCustomEventWithEnforcedAffinityReassignment(GridDhtPartitionsExchangeFuture fut)` Calculates affinity on coordinator for custom event types that require centralized assignment.
`void` `onCustomMessageNoAffinityChange(GridDhtPartitionsExchangeFuture fut, @Nullable ExchangeActions exchActions)`
`void` `onDisconnected(IgniteFuture<?> reconnectFut)`
`void` `onExchangeChangeAffinityMessage(GridDhtPartitionsExchangeFuture exchFut, CacheAffinityChangeMessage msg)` Called when received `CacheAffinityChangeMessage` which should complete exchange.
`void` `onExchangeFreeSwitch(GridDhtPartitionsExchangeFuture fut)` Called on exchange initiated by baseline server node leave on fully-rebalanced topology.
`Set<Integer>` `onLocalJoin(GridDhtPartitionsExchangeFuture fut, Map<Integer,CacheGroupAffinityMessage> receivedAff, AffinityTopologyVersion resTopVer)`
`Map<Integer,CacheGroupAffinityMessage>` `onReassignmentEnforced(GridDhtPartitionsExchangeFuture fut)` Calculates new affinity assignment on coordinator and creates affinity diff messages for other nodes.
`void` `onServerJoin(GridDhtPartitionsExchangeFuture fut, boolean crd)` Called on exchange initiated by server node join.
`void` `onServerJoinWithExchangeMergeProtocol(GridDhtPartitionsExchangeFuture fut, boolean crd)`
`Map<Integer,CacheGroupAffinityMessage>` `onServerLeftWithExchangeMergeProtocol(GridDhtPartitionsExchangeFuture fut)`
`boolean` `rebalanceRequired()`
`void` `removeDhtAssignmentFetchFuture(GridDhtAssignmentFetchFuture fut)`
`protected void` `start0()`
`void` `stopCacheGroupOnReconnect(CacheGroupContext grpCtx)`
`void` `stopCacheOnReconnect(GridCacheContext cctx)`
`Set<Integer>` `waitGroups()`

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

`context, isStopping, kernalStartInfo, kernalStopInfo, log, onKernalStart, onKernalStart0, onKernalStop, onKernalStop0, onReconnected, printMemoryStats, start, startInfo, stop, stop0, stopInfo, toString`

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

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

### Constructor Detail

#### CacheAffinitySharedManager

    public CacheAffinitySharedManager()

### Method Detail

#### start0

    protected void start0()
                   throws IgniteCheckedException

Overrides:
  `start0` in class `GridCacheSharedManagerAdapter<K,V>`
Throws:
  `IgniteCheckedException` - If failed.

#### initCachesOnLocalJoin

    public IgniteInternalFuture<?> initCachesOnLocalJoin(Map<Integer,CacheGroupDescriptor> grpDescs,
                                                         Map<String,DynamicCacheDescriptor> cacheDescs)

Must be called from exchange thread.

#### waitGroups

    public Set<Integer> waitGroups()

Returns:
  Group IDs.

#### rebalanceRequired

    public boolean rebalanceRequired()

Returns:
  `true` if rebalance expected.

#### addToWaitGroup

    public void addToWaitGroup(int grpId,
                               int part,
                               AffinityTopologyVersion topVer,
                               List<ClusterNode> assignment)

Adds historically rebalancing partitions to wait group. Not doing so could trigger late affinity switching before actual rebalancing will finish.

Parameters:
  `grpId` - Group id.
  `part` - Part.
  `topVer` - Topology version.
  `assignment` - Ideal assignment.

#### onCustomMessageNoAffinityChange

    public void onCustomMessageNoAffinityChange(GridDhtPartitionsExchangeFuture fut,
                                                @Nullable
                                                @Nullable ExchangeActions exchActions)

Parameters:
  `fut` - Exchange future.
  `exchActions` - Exchange actions.

#### stopCacheOnReconnect

    public void stopCacheOnReconnect(GridCacheContext cctx)

Parameters:
  `cctx` - Stopped cache context.

#### stopCacheGroupOnReconnect

    public void stopCacheGroupOnReconnect(CacheGroupContext grpCtx)

Parameters:
  `grpCtx` - Stopped cache group context.

#### onDisconnected

    public void onDisconnected(IgniteFuture<?> reconnectFut)

Specified by:
  `onDisconnected` in interface `GridCacheSharedManager<K,V>`
Overrides:
  `onDisconnected` in class `GridCacheSharedManagerAdapter<K,V>`
Parameters:
  `reconnectFut` - Reconnect future.

#### forceCloseCaches

    public void forceCloseCaches(GridDhtPartitionsExchangeFuture fut,
                                 boolean crd,
                                 ExchangeActions exchActions)

Called during the rollback of the exchange partitions procedure in order to stop the given cache even if it's not fully initialized (e.g. failed on cache init stage).

Parameters:
  `fut` - Exchange future.
  `crd` - Coordinator flag.
  `exchActions` - Cache change requests.

#### onCacheChangeRequest

    public IgniteInternalFuture<?> onCacheChangeRequest(GridDhtPartitionsExchangeFuture fut,
                                                        boolean crd,
                                                        ExchangeActions exchActions)
                                                 throws IgniteCheckedException

Called on exchange initiated for cache start/stop request.

Parameters:
  `fut` - Exchange future.
  `crd` - Coordinator flag.
  `exchActions` - Cache change requests.
Throws:
  `IgniteCheckedException` - If failed.

#### clearGroupHoldersAndRegistry

    public void clearGroupHoldersAndRegistry()

#### onExchangeChangeAffinityMessage

    public void onExchangeChangeAffinityMessage(GridDhtPartitionsExchangeFuture exchFut,
                                                CacheAffinityChangeMessage msg)

Called when received `CacheAffinityChangeMessage` which should complete exchange.

Parameters:
  `exchFut` - Exchange future.
  `msg` - Affinity change message.

#### onChangeAffinityMessage

    public void onChangeAffinityMessage(GridDhtPartitionsExchangeFuture exchFut,
                                        CacheAffinityChangeMessage msg)

Called on exchange initiated by `CacheAffinityChangeMessage` which sent after rebalance finished.

Parameters:
  `exchFut` - Exchange future.
  `msg` - Message.

#### onClientEvent

    public void onClientEvent(GridDhtPartitionsExchangeFuture fut)
                       throws IgniteCheckedException

Called on exchange initiated by client node join/fail.

Parameters:
  `fut` - Exchange future.
Throws:
  `IgniteCheckedException` - If failed.

#### addDhtAssignmentFetchFuture

    public void addDhtAssignmentFetchFuture(GridDhtAssignmentFetchFuture fut)

Parameters:
  `fut` - Future to add.

#### removeDhtAssignmentFetchFuture

    public void removeDhtAssignmentFetchFuture(GridDhtAssignmentFetchFuture fut)

Parameters:
  `fut` - Future to remove.

#### initStartedCaches

    public IgniteInternalFuture<?> initStartedCaches(boolean crd,
                                                     GridDhtPartitionsExchangeFuture fut,
                                                     Collection<DynamicCacheDescriptor> descs)
                                              throws IgniteCheckedException

Initialized affinity for cache received from node joining on this exchange.

Parameters:
  `crd` - Coordinator flag.
  `fut` - Exchange future.
  `descs` - Cache descriptors.
Throws:
  `IgniteCheckedException` - If failed.

#### affinity

    public GridAffinityAssignmentCache affinity(Integer grpId)

Parameters:
  `grpId` - Cache group ID.
Returns:
  Affinity assignments.

#### applyAffinityFromFullMessage

    public void applyAffinityFromFullMessage(GridDhtPartitionsExchangeFuture fut,
                                             Map<Integer,CacheGroupAffinityMessage> idealAffDiff)

Applies affinity diff from the received full message.

Parameters:
  `fut` - Current exchange future.
  `idealAffDiff` - Map [Cache group id - Affinity distribution] which contains difference with ideal affinity.

#### onLocalJoin

    public Set<Integer> onLocalJoin(GridDhtPartitionsExchangeFuture fut,
                                    Map<Integer,CacheGroupAffinityMessage> receivedAff,
                                    AffinityTopologyVersion resTopVer)

Parameters:
  `fut` - Current exchange future.
  `receivedAff` - Map [Cache group id - Affinity distribution] received from coordinator to apply.
  `resTopVer` - Result topology version.
Returns:
  Set of cache groups with no affinity localed in given `receivedAff`.

#### onServerJoinWithExchangeMergeProtocol

    public void onServerJoinWithExchangeMergeProtocol(GridDhtPartitionsExchangeFuture fut,
                                                      boolean crd)

Parameters:
  `fut` - Current exchange future.
  `crd` - Coordinator flag.

#### onServerLeftWithExchangeMergeProtocol

    public Map<Integer,CacheGroupAffinityMessage> onServerLeftWithExchangeMergeProtocol(GridDhtPartitionsExchangeFuture fut)

Parameters:
  `fut` - Current exchange future.
Returns:
  Computed difference with ideal affinity.

#### onExchangeFreeSwitch

    public void onExchangeFreeSwitch(GridDhtPartitionsExchangeFuture fut)

Called on exchange initiated by baseline server node leave on fully-rebalanced topology.

Parameters:
  `fut` - Exchange future.

#### onCustomEventWithEnforcedAffinityReassignment

    public Map<Integer,CacheGroupAffinityMessage> onCustomEventWithEnforcedAffinityReassignment(GridDhtPartitionsExchangeFuture fut)
                                                                                         throws IgniteCheckedException

Calculates affinity on coordinator for custom event types that require centralized assignment.

Parameters:
  `fut` - Current exchange future.
Returns:
  Computed difference with ideal affinity.
Throws:
  `IgniteCheckedException` - If failed.

#### onReassignmentEnforced

    public Map<Integer,CacheGroupAffinityMessage> onReassignmentEnforced(GridDhtPartitionsExchangeFuture fut)

Calculates new affinity assignment on coordinator and creates affinity diff messages for other nodes.

Parameters:
  `fut` - Current exchange future.
Returns:
  Computed difference with ideal affinity.

#### onServerJoin

    public void onServerJoin(GridDhtPartitionsExchangeFuture fut,
                             boolean crd)
                      throws IgniteCheckedException

Called on exchange initiated by server node join.

Parameters:
  `fut` - Exchange future.
  `crd` - Coordinator flag.
Throws:
  `IgniteCheckedException` - If failed.

#### onBaselineTopologyChanged

    public void onBaselineTopologyChanged(GridDhtPartitionsExchangeFuture fut,
                                          boolean crd)

Parameters:
  `fut` - Exchange future
  `crd` - Coordinator flag.

#### onCentralizedAffinityChange

    public boolean onCentralizedAffinityChange(GridDhtPartitionsExchangeFuture fut,
                                               boolean crd)
                                        throws IgniteCheckedException

Called on exchange initiated by server node leave or custom event with centralized affinity assignment.

Parameters:
  `fut` - Exchange future.
  `crd` - Coordinator flag.
Returns:
  `True` if affinity should be assigned by coordinator.
Throws:
  `IgniteCheckedException` - If failed.

#### initCoordinatorCaches

    public IgniteInternalFuture<?> initCoordinatorCaches(GridDhtPartitionsExchangeFuture fut,
                                                         boolean newAff)
                                                  throws IgniteCheckedException

Parameters:
  `fut` - Exchange future.
  `newAff` - `True` if there are no older nodes with affinity info available.
Returns:
  Future completed when caches initialization is done.
Throws:
  `IgniteCheckedException` - If failed.

#### initAffinityOnNodeLeft

    public IgniteInternalFuture<Map<Integer,Map<Integer,List<UUID>>>> initAffinityOnNodeLeft(GridDhtPartitionsExchangeFuture fut)
                                                                                      throws IgniteCheckedException

Parameters:
  `fut` - Exchange future.
Returns:
  Affinity assignment.
Throws:
  `IgniteCheckedException` - If failed.

#### cacheGroups

    public Map<Integer,CacheGroupDescriptor> cacheGroups()

Returns:
  All registered cache groups.

#### caches

    public Map<Integer,DynamicCacheDescriptor> caches()

Returns:
  All registered cache groups.

#### groupAffinity

    @Nullable
    public @Nullable GridAffinityAssignmentCache groupAffinity(int grpId)

Parameters:
  `grpId` - Cache group ID
Returns:
  Cache affinity cache.

#### dumpDebugInfo

    public void dumpDebugInfo()

${current.year} Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Database and Caching Platform | : ver. 2.8.0
Release Date | : February 27 2020