Class GridAffinityAssignmentCache
- java.lang.Object
-
- org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentCache
-
public class GridAffinityAssignmentCache extends Object
Affinity cached function.
-
-
Field Summary
Fields Modifier and Type Field Description static intDFLT_AFFINITY_HISTORY_SIZEstatic floatDFLT_PART_DISTRIBUTION_WARN_THRESHOLD
-
Method Summary
-
-
-
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:
Trueif affinity function hasAffinityCentralizedFunctionannotation.
-
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 versiontopVeris calculated.- Parameters:
topVer- Topology version to await for.- Returns:
- Future that will be completed after affinity for topology version
topVeris 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:
Trueif 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 versiontopVeris 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 versiontopVeris 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:
Trueif 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.
-
-