public class CachePartitionFairAffinity extends Object implements CacheAffinityFunction
Cache affinity can be configured for individual caches via CacheConfiguration.getAffinity()
method.
Modifier and Type | Field and Description |
---|---|
static int |
DFLT_PART_CNT
Default partition count.
|
Constructor and Description |
---|
CachePartitionFairAffinity()
Creates fair affinity with default partition count.
|
CachePartitionFairAffinity(int parts) |
Modifier and Type | Method and Description |
---|---|
List<List<ClusterNode>> |
assignPartitions(CacheAffinityFunctionContext ctx)
Gets affinity nodes for a partition.
|
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.
|
public static final int DFLT_PART_CNT
public CachePartitionFairAffinity()
public CachePartitionFairAffinity(int parts)
parts
- Number of partitions.public List<List<ClusterNode>> assignPartitions(CacheAffinityFunctionContext ctx)
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 CacheAffinityFunction
ctx
- Affinity function context. Will provide all required information to calculate
new partition assignments.public void reset()
reset
in interface CacheAffinityFunction
public int partitions()
0
inclusively to
N
exclusively without any gaps.partitions
in interface CacheAffinityFunction
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 CacheAffinityFunction
key
- Key to get partition for.public void removeNode(UUID nodeId)
removeNode
in interface CacheAffinityFunction
nodeId
- ID of node to remove.
Follow @ApacheIgnite
Apache Ignite Fabric : ver. 1.0.0-RC3 Release Date : March 24 2015