public class ClusterNodeAttributeAffinityBackupFilter extends Object implements IgniteBiPredicate<ClusterNode,List<ClusterNode>>
RendezvousAffinityFunction.affinityBackupFilterto create cache templates in Spring that force each partition's primary and backup to different hardware which is not expected to fail simultaneously, e.g., in AWS, to different "availability zones". This is a per-partition selection, and different partitions may choose different primaries.
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|
|Modifier and Type||Method and Description|
Defines a predicate which returns
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
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)
trueif a node is acceptable for a backup or
falseotherwise. 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.
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.