public interface AffinityFunction extends Serializable
Whenever a key is given to cache, it is first passed to a pluggable
AffinityKeyMapper which may potentially map this key to an alternate
key which should be used for affinity. The key returned from
AffinityKeyMapper.affinityKey(Object) method is then passed to
partition(Object) method to find out the partition for the key.
On each topology change, partition-to-node mapping is calculated using
assignPartitions(AffinityFunctionContext) method, which assigns a collection
of nodes to each partition.
This collection of nodes is used for node affinity. In
cache mode the key will be cached on all returned nodes; generally, all caching nodes
participate in caching every key in replicated mode. In
mode, only primary and backup nodes are returned with primary node always in the
first position. So if there is
1 backup node, then the returned collection will
2 nodes in it -
primary node in first position, and
node in second.
|Modifier and Type||Method and Description|
Gets affinity nodes for a partition.
Gets partition number for a given key starting from
Gets total number of partitions available.
Removes node from affinity.
Resets cache affinity to its initial state.
Nexclusively without any gaps.
int partition(Object key)
0. Partitioned caches should make sure that keys are about evenly distributed across all partitions from
partition countfor 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.
key- Key to get partition for.
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
affCtx- Affinity function context. Will provide all required information to calculate new partition assignments.
void removeNode(UUID nodeId)
nodeId- ID of node to remove.