public class RendezvousAffinityFunction extends Object implements AffinityFunction, Serializable
partitions
- Number of partitions to spread across nodes.
excludeNeighbors
- If set to true
, will exclude same-host-neighbors
from being backups of each other. This flag can be ignored in cases when topology has no enough nodes
for assign backups.
Note that backupFilter
is ignored if excludeNeighbors
is set to true
.
backupFilter
- Optional filter for back up nodes. If provided, then only
nodes that pass this filter will be selected as backup nodes. If not provided, then
primary and backup nodes will be selected out of all nodes available for this cache.
Cache affinity can be configured for individual caches via CacheConfiguration.getAffinity()
method.
Modifier and Type | Field and Description |
---|---|
static int |
DFLT_PARTITION_COUNT
Default number of partitions.
|
Constructor and Description |
---|
RendezvousAffinityFunction()
Empty constructor with all defaults.
|
RendezvousAffinityFunction(boolean exclNeighbors)
Initializes affinity with flag to exclude same-host-neighbors from being backups of each other
and specified number of backups.
|
RendezvousAffinityFunction(boolean exclNeighbors,
int parts)
Initializes affinity with flag to exclude same-host-neighbors from being backups of each other,
and specified number of backups and partitions.
|
RendezvousAffinityFunction(int parts,
IgniteBiPredicate<ClusterNode,ClusterNode> backupFilter)
Initializes optional counts for replicas and backups.
|
Modifier and Type | Method and Description |
---|---|
List<ClusterNode> |
assignPartition(int part,
List<ClusterNode> nodes,
int backups,
Map<UUID,Collection<ClusterNode>> neighborhoodCache)
Returns collection of nodes (primary first) for specified partition.
|
List<List<ClusterNode>> |
assignPartitions(AffinityFunctionContext affCtx)
Gets affinity nodes for a partition.
|
static int |
calculateMask(int parts)
Helper method to calculates mask.
|
static int |
calculatePartition(Object key,
int mask,
int parts)
Helper method to calculate partition.
|
IgniteBiPredicate<ClusterNode,List<ClusterNode>> |
getAffinityBackupFilter()
Gets optional backup filter.
|
IgniteBiPredicate<ClusterNode,ClusterNode> |
getBackupFilter()
Gets optional backup filter.
|
int |
getPartitions()
Gets total number of key partitions.
|
boolean |
isExcludeNeighbors()
Checks flag to exclude same-host-neighbors from being backups of each other (default is
false ). |
int |
partition(Object key)
Gets partition number for a given key starting from
0 . |
int |
partitions()
Gets total number of partitions available.
|
void |
removeNode(UUID nodeId)
Removes node from affinity.
|
void |
reset()
Resets cache affinity to its initial state.
|
Object |
resolveNodeHash(ClusterNode node)
Resolves node hash.
|
RendezvousAffinityFunction |
setAffinityBackupFilter(IgniteBiPredicate<ClusterNode,List<ClusterNode>> affinityBackupFilter)
Sets optional backup filter.
|
RendezvousAffinityFunction |
setBackupFilter(IgniteBiPredicate<ClusterNode,ClusterNode> backupFilter)
Deprecated.
Use
affinityBackupFilter instead. |
RendezvousAffinityFunction |
setExcludeNeighbors(boolean exclNeighbors)
Sets flag to exclude same-host-neighbors from being backups of each other (default is
false ). |
RendezvousAffinityFunction |
setPartitions(int parts)
Sets total number of partitions.If the number of partitions is a power of two,
the PowerOfTwo hashing method will be used.
|
String |
toString() |
public static final int DFLT_PARTITION_COUNT
public RendezvousAffinityFunction()
public RendezvousAffinityFunction(boolean exclNeighbors)
Note that backupFilter
is ignored if excludeNeighbors
is set to true
.
exclNeighbors
- True
if nodes residing on the same host may not act as backups
of each other.public RendezvousAffinityFunction(boolean exclNeighbors, int parts)
Note that backupFilter
is ignored if excludeNeighbors
is set to true
.
exclNeighbors
- True
if nodes residing on the same host may not act as backups
of each other.parts
- Total number of partitions.public RendezvousAffinityFunction(int parts, IgniteBiPredicate<ClusterNode,ClusterNode> backupFilter)
Note that backupFilter
is ignored if excludeNeighbors
is set to true
.
parts
- Total number of partitions.backupFilter
- Optional back up filter for nodes. If provided, backups will be selected
from all nodes that pass this filter. First argument for this filter is primary node, and second
argument is node being tested.
Note that backupFilter
is ignored if excludeNeighbors
is set to true
.
public static int calculateMask(int parts)
parts
- Number of partitions.public static int calculatePartition(Object key, int mask, int parts)
key
- – Key to get partition for.mask
- Mask to use in calculation when partitions count is power of 2.parts
- Number of partitions.public int getPartitions()
For fully replicated caches this method works the same way as a partitioned cache.
public RendezvousAffinityFunction setPartitions(int parts)
parts
- Total number of partitions.this
for chaining.public IgniteBiPredicate<ClusterNode,ClusterNode> getBackupFilter()
null
, backups will be selected
from all nodes that pass this filter. First node passed to this filter is primary node,
and second node is a node being tested.
Note that backupFilter
is ignored if excludeNeighbors
is set to true
.
@Deprecated public RendezvousAffinityFunction setBackupFilter(IgniteBiPredicate<ClusterNode,ClusterNode> backupFilter)
affinityBackupFilter
instead.
Note that backupFilter
is ignored if excludeNeighbors
is set to true
.
backupFilter
- Optional backup filter.this
for chaining.public IgniteBiPredicate<ClusterNode,List<ClusterNode>> getAffinityBackupFilter()
null
, backups will be selected
from all nodes that pass this filter. First node passed to this filter is a node being tested,
and the second parameter is a list of nodes that are already assigned for a given partition (primary node is the first in the list).
Note that affinityBackupFilter
is ignored if excludeNeighbors
is set to true
.
public RendezvousAffinityFunction setAffinityBackupFilter(IgniteBiPredicate<ClusterNode,List<ClusterNode>> affinityBackupFilter)
Note that affinityBackupFilter
is ignored if excludeNeighbors
is set to true
.
For an example filter, see ClusterNodeAttributeAffinityBackupFilter
.
affinityBackupFilter
- Optional backup filter.this
for chaining.public boolean isExcludeNeighbors()
false
).
Note that backupFilter
is ignored if excludeNeighbors
is set to true
.
True
if nodes residing on the same host may not act as backups of each other.public RendezvousAffinityFunction setExcludeNeighbors(boolean exclNeighbors)
false
).
Note that backupFilter
is ignored if excludeNeighbors
is set to true
.
exclNeighbors
- True
if nodes residing on the same host may not act as backups of each other.this
for chaining.public Object resolveNodeHash(ClusterNode node)
node
- Cluster node;public List<ClusterNode> assignPartition(int part, List<ClusterNode> nodes, int backups, Map<UUID,Collection<ClusterNode>> neighborhoodCache)
part
- Partition.nodes
- Nodes.backups
- Number of backups.neighborhoodCache
- Neighborhood.public void reset()
reset
in interface AffinityFunction
public int partitions()
0
inclusively to
N
exclusively without any gaps.partitions
in interface AffinityFunction
public int partition(Object key)
0
. Partitioned caches
should make sure that keys are about evenly distributed across all partitions
from 0
to partition count
for best performance.
Note that for fully replicated caches it is possible to segment key sets among different grid node groups. In that case each node group should return a unique partition number. However, unlike partitioned cache, mappings of keys to nodes in replicated caches are constant and a node cannot migrate from one partition to another.
partition
in interface AffinityFunction
key
- Key to get partition for.public List<List<ClusterNode>> assignPartitions(AffinityFunctionContext affCtx)
Note that partitioned affinity must obey the following contract: given that node
N
is primary for some key K
, if any other node(s) leave
grid and no node joins grid, node N
will remain primary for key K
.
assignPartitions
in interface AffinityFunction
affCtx
- Affinity function context. Will provide all required information to calculate
new partition assignments.public void removeNode(UUID nodeId)
removeNode
in interface AffinityFunction
nodeId
- ID of node to remove.
GridGain In-Memory Computing Platform : ver. 8.9.14 Release Date : November 5 2024