public class ClusterNodeAttributeAffinityBackupFilter extends Object implements IgniteBiPredicate<ClusterNode,List<ClusterNode>>
RendezvousAffinityFunction.setAffinityBackupFilter(org.apache.ignite.lang.IgniteBiPredicate<org.apache.ignite.cluster.ClusterNode, java.util.List<org.apache.ignite.cluster.ClusterNode>>)
.
This implementation will discard backups rather than place multiple on the same set of nodes. This avoids trying to cram more data onto remaining nodes when some have failed.
A list of node attributes to compare is provided on construction. Note: "All cluster nodes, on startup, automatically register all the environment and system properties as node attributes."
This class is constructed with a array of node attribute names, and a candidate node will be rejected if *any* of the previously selected nodes for a partition have the identical values for *all* of those attributes on the candidate node. Another way to understand this is the set of attribute values defines the key of a group into which a node is placed, an the primaries and backups for a partition cannot share nodes in the same group. A null attribute is treated as a distinct value, so two nodes with a null attribute will be treated as having the same value.
Warning: the misspelling of an attribute name can cause all nodes to believe they have a null attribute, which would the number of cache entries seen in visor with the number of expected entries, e.g., SELECT COUNT(*) from YOUR_TABLE times the number of backups.
<property name="cacheConfiguration"> <list> <bean id="cache-template-bean" abstract="true" class="org.apache.ignite.configuration.CacheConfiguration"> <property name="name" value="JobcaseDefaultCacheConfig*"/> <property name="cacheMode" value="PARTITIONED" /> <property name="backups" value="1" /> <property name="affinity"> <bean class="org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction"> <property name="affinityBackupFilter"> <bean class="org.apache.ignite.cache.affinity.rendezvous.ClusterNodeAttributeAffinityBackupFilter"> <constructor-arg> <array value-type="java.lang.String"> <!-- Backups must go to different AZs --> <value>AVAILABILITY_ZONE</value> </array> </constructor-arg> </bean> </property> </bean> </property> </bean> </list> </property>
With more backups, multiple properties, e.g., SITE, ZONE, could be used to force backups to different subgroups.
Constructor and Description |
---|
ClusterNodeAttributeAffinityBackupFilter(String... attributeNames) |
Modifier and Type | Method and Description |
---|---|
boolean |
apply(ClusterNode candidate,
List<ClusterNode> previouslySelected)
Defines a predicate which returns
true if a node is acceptable for a backup
or false otherwise. |
String[] |
getAttributeNames()
Gets attribute names.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
and
public ClusterNodeAttributeAffinityBackupFilter(String... attributeNames)
attributeNames
- The list of attribute names for the set of attributes to compare. Must be at least one.public boolean apply(ClusterNode candidate, List<ClusterNode> previouslySelected)
true
if a node is acceptable for a backup
or false
otherwise. An acceptable node is one where its set of attribute values
is not exact match with any of the previously selected nodes. If an attribute does not
exist on exactly one node of a pair, then the attribute does not match. If the attribute
does not exist both nodes of a pair, then the attribute matches.
Warning: if an attribute is specified that does not exist on any node, then no backups will be created, because all nodes will match.
apply
in interface IgniteBiPredicate<ClusterNode,List<ClusterNode>>
candidate
- A node that is a candidate for becoming a backup node for a partition.previouslySelected
- A list of primary/backup nodes already chosen for a partition.
The primary is first.public String[] getAttributeNames()
GridGain In-Memory Computing Platform : ver. 8.9.4 Release Date : April 16 2024