org.apache.ignite.cache.affinity.rendezvous

## Class ClusterNodeAttributeColocatedBackupFilter

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

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

      public class ClusterNodeAttributeColocatedBackupFilter
      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 be co-located on nodes with the same attribute value.

  Partition copies co-location can be helpful to group nodes into cells when fixed baseline topology is used. If all copies of each partition are located inside only one cell, in case of `backup + 1` nodes leave the cluster there will be data lost only if all leaving nodes belong to the same cell. Without partition copies co-location within a cell, most probably there will be data lost if any `backup + 1` nodes leave the cluster. Note: Baseline topology change can lead to inter-cell partitions migration, i.e. rebalance can affect all copies of some partitions even if only one node is changed in the baseline topology.

  This implementation will discard backups rather than place copies on nodes with different attribute values. This avoids trying to cram more data onto remaining nodes when some have failed.

  A node attribute to compare is provided on construction. Attribute name shouldn't be null. Note: All cluster nodes, on startup, automatically register all the environment and system properties as node attributes. Note: All nodes should have not an empty co-location attribute value. The absence of the attribute on some nodes will trigger the failure handler. Note: Node attributes persisted in baseline topology at the time of baseline topology change. If the co-location attribute of some node was updated, but the baseline topology wasn't changed, the outdated attribute value can be used by the backup filter when this node left the cluster. To avoid this, the baseline topology should be updated after changing the co-location attribute.

  This class is constructed with a node attribute name, and a candidate node will be rejected if previously selected nodes for a partition have a different value for attribute on the candidate node.

  ## Spring Example

  Create a partitioned cache template plate with 1 backup, where the backup will be placed in the same cell as the primary. Note: This example requires that the environment variable "CELL" be set appropriately on each node via some means external to Ignite.

       <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.ClusterNodeAttributeColocatedBackupFilter">
                                   <!-- Backups must go to the same CELL as primary -->
                                   <constructor-arg value="CELL" />
                               </bean>
                           </property>
                       </bean>
                   </property>
               </bean>
           </list>
       </property>

  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ClusterNodeAttributeColocatedBackupFilter(String attrName)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    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.

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

    - #### ClusterNodeAttributeColocatedBackupFilter

          public ClusterNodeAttributeColocatedBackupFilter(String attrName)

      Parameters:
        `attrName` - The attribute name for the attribute to compare.

  - ### 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 attribute value is exact match with previously selected nodes. If an attribute does not exist on candidate node, then the attribute matches any attribute values of previously selected nodes. If the attribute does not exist on primary node, then the attribute matches any attribute value of candidate node.
      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.

2022 Copyright © Apache Software Foundation
| Follow @ApacheIgnite
Ignite Database and Caching Platform | : ver. 2.12.0
Release Date | : January 10 2022