org.apache.ignite.cache.affinity.rendezvous

## Class ClusterNodeAttributeAffinityBackupFilter

- java.lang.Object
- - org.apache.ignite.cache.affinity.rendezvous.ClusterNodeAttributeAffinityBackupFilter

All Implemented Interfaces:
  Serializable, IgniteBiPredicate<ClusterNode,List<ClusterNode>>

    public class ClusterNodeAttributeAffinityBackupFilter
    extends Object
    implements IgniteBiPredicate<ClusterNode,List<ClusterNode>>

This class can be used as a `RendezvousAffinityFunction.affinityBackupFilter` to 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.

## Spring Example

Create a partitioned cache template plate with 1 backup, where the backup will not be placed in the same availability zone as the primary. Note: This example requires that the environment variable "AVAILABILTY_ZONE" be set appropriately on each node via some means external to Ignite. On AWS, some nodes might have AVAILABILTY_ZONE=us-east-1a and others AVAILABILTY_ZONE=us-east-1b.

     <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.

See Also:
  Serialized Form

### Constructor Summary

Constructors
Constructor and Description
`ClusterNodeAttributeAffinityBackupFilter(String... attributeNames)`

### Method Summary

All Methods Instance Methods Concrete Methods
`boolean` `apply(ClusterNode candidate, List<ClusterNode> previouslySelected)` Defines a predicate which returns `true` if a node is acceptable for a backup or `false` otherwise.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.apache.ignite.lang.IgniteBiPredicate

`and`

### Constructor Detail

#### ClusterNodeAttributeAffinityBackupFilter

    public ClusterNodeAttributeAffinityBackupFilter(String... attributeNames)

Parameters:
  `attributeNames` - The list of attribute names for the set of attributes to compare. Must be at least one.

### Method Detail

#### apply

    public boolean apply(ClusterNode candidate,
                         List<ClusterNode> previouslySelected)

Defines a predicate which returns `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.

Specified by:
  `apply` in interface `IgniteBiPredicate<ClusterNode,List<ClusterNode>>`
Parameters:
  `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.
Returns:
  Return value.

${current.year} Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Database and Caching Platform | : ver. 2.9.1
Release Date | : December 9 2020