public class CacheRendezvousAffinityFunction extends Object implements CacheAffinityFunction, Externalizable
partitions
- Number of partitions to spread across nodes.
excludeNeighbors
- If set to true
, will exclude same-host-neighbors
from being backups of each other. 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 |
---|
CacheRendezvousAffinityFunction()
Empty constructor with all defaults.
|
CacheRendezvousAffinityFunction(boolean exclNeighbors)
Initializes affinity with flag to exclude same-host-neighbors from being backups of each other
and specified number of backups.
|
CacheRendezvousAffinityFunction(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.
|
CacheRendezvousAffinityFunction(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(CacheAffinityFunctionContext affCtx)
Gets affinity nodes for a partition.
|
IgniteBiPredicate<ClusterNode,ClusterNode> |
getBackupFilter()
Gets optional backup filter.
|
CacheAffinityNodeHashResolver |
getHashIdResolver()
Gets hash ID resolver for nodes.
|
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 |
readExternal(ObjectInput in) |
void |
removeNode(UUID nodeId)
Removes node from affinity.
|
void |
reset()
Resets cache affinity to its initial state.
|
void |
setBackupFilter(IgniteBiPredicate<ClusterNode,ClusterNode> backupFilter)
Sets optional backup filter.
|
void |
setExcludeNeighbors(boolean exclNeighbors)
Sets flag to exclude same-host-neighbors from being backups of each other (default is
false ). |
void |
setHashIdResolver(CacheAffinityNodeHashResolver hashIdRslvr)
Sets hash ID resolver for nodes.
|
void |
setPartitions(int parts)
Sets total number of partitions.
|
void |
writeExternal(ObjectOutput out) |
public static final int DFLT_PARTITION_COUNT
public CacheRendezvousAffinityFunction()
public CacheRendezvousAffinityFunction(boolean exclNeighbors)
Note that excludeNeighbors
parameter is ignored if #getBackupFilter()
is set.
exclNeighbors
- True
if nodes residing on the same host may not act as backups
of each other.public CacheRendezvousAffinityFunction(boolean exclNeighbors, int parts)
Note that excludeNeighbors
parameter is ignored if #getBackupFilter()
is set.
exclNeighbors
- True
if nodes residing on the same host may not act as backups
of each other.parts
- Total number of partitions.public CacheRendezvousAffinityFunction(int parts, @Nullable IgniteBiPredicate<ClusterNode,ClusterNode> backupFilter)
Note that excludeNeighbors
parameter is ignored if backupFilter
is set.
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 excludeNeighbors
parameter is ignored if backupFilter
is set.
public int getPartitions()
Note that for fully replicated caches this method should always
return 1
.
public void setPartitions(int parts)
parts
- Total number of partitions.public CacheAffinityNodeHashResolver getHashIdResolver()
Node IDs constantly change when nodes get restarted, which causes them to be placed on different locations in the hash ring, and hence causing repartitioning. Providing an alternate hash ID, which survives node restarts, puts node on the same location on the hash ring, hence minimizing required repartitioning.
public void setHashIdResolver(CacheAffinityNodeHashResolver hashIdRslvr)
Node IDs constantly change when nodes get restarted, which causes them to be placed on different locations in the hash ring, and hence causing repartitioning. Providing an alternate hash ID, which survives node restarts, puts node on the same location on the hash ring, hence minimizing required repartitioning.
hashIdRslvr
- Hash ID resolver.@Nullable 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 excludeNeighbors
parameter is ignored if backupFilter
is set.
public void setBackupFilter(@Nullable IgniteBiPredicate<ClusterNode,ClusterNode> backupFilter)
Note that excludeNeighbors
parameter is ignored if backupFilter
is set.
backupFilter
- Optional backup filter.public boolean isExcludeNeighbors()
false
).
Note that excludeNeighbors
parameter is ignored if #getBackupFilter()
is set.
True
if nodes residing on the same host may not act as backups of each other.public void setExcludeNeighbors(boolean exclNeighbors)
false
).
Note that excludeNeighbors
parameter is ignored if #getBackupFilter()
is set.
exclNeighbors
- True
if nodes residing on the same host may not act as backups of each other.public List<ClusterNode> assignPartition(int part, List<ClusterNode> nodes, int backups, @Nullable Map<UUID,Collection<ClusterNode>> neighborhoodCache)
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 List<List<ClusterNode>> assignPartitions(CacheAffinityFunctionContext 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 CacheAffinityFunction
affCtx
- Affinity function context. Will provide all required information to calculate
new partition assignments.public void removeNode(UUID nodeId)
removeNode
in interface CacheAffinityFunction
nodeId
- ID of node to remove.public void writeExternal(ObjectOutput out) throws IOException
writeExternal
in interface Externalizable
IOException
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
readExternal
in interface Externalizable
IOException
ClassNotFoundException
Follow @ApacheIgnite
Apache Ignite Fabric : ver. 1.0.0-RC3 Release Date : March 24 2015