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 Description GridCacheAffinityManager()
-
Method Summary
-
Methods inherited from class org.apache.ignite.internal.processors.cache.GridCacheManagerAdapter
context, kernalStartInfo, kernalStopInfo, log, onDisconnected, onKernalStart, onKernalStart0, onKernalStop, onKernalStop0, printMemoryStats, start, startInfo, stop, stopInfo, toString
-
-
-
-
Method Detail
-
start0
public void start0() throws IgniteCheckedException- Overrides:
start0in classGridCacheManagerAdapter- Throws:
IgniteCheckedException- If failed.
-
stop0
protected void stop0(boolean cancel, boolean destroy)- Overrides:
stop0in classGridCacheManagerAdapter- 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 @Nullable IgniteInternalFuture<AffinityTopologyVersion> affinityReadyFuturex(AffinityTopologyVersion topVer)
Gets affinity ready future that will be completed after affinity with given topology version is calculated. Will returnnullif 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- Iftruecan use pre-calculated partition stored in KeyCacheObject.- Returns:
- Partition.
-
affinityKey
public Object affinityKey(Object key)
If Key isGridCacheInternalentry when won't passed into user's mapper and will usedefault.- 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.
-
assignment
public AffinityAssignment assignment(AffinityTopologyVersion topVer, AffinityTopologyVersion lastAffChangedTopVer)
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:
Trueif 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:
Trueif 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:
Trueif 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:
trueif given key belongs to local node.
-
partitionLocalNode
public boolean partitionLocalNode(int part, AffinityTopologyVersion topVer)- Parameters:
part- Partition number to check.topVer- Topology version.- Returns:
trueif 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:
trueif 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:
Trueif 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.
-
-