Search code examples
igniteapacheignite

Affinity Backup Filter


Trying to set up an affinity backup filter. Most of the bits are clear and I am following the details outlined here - https://ignite.apache.org/releases/latest/javadoc/index.html?org/apache/ignite/cache/affinity/rendezvous/ClusterNodeAttributeAffinityBackupFilter.html which talks about backup by availability zone. And each node can set the value of that AZ.

However, the thing I am not very clear on is where this AZ value goes for each node, the above link says "that the environment variable "AVAILABILTY_ZONE" be set appropriately on each node via some means external to Ignite".

I see a couple of options where this could be set,

  1. Use System.setProperty()(based on the above comment around environment variable)
  2. Set it as part of IgniteConfiguration.setUserAttributes() (based on looking at the ClusterNodeAttributeAffinityBackupFilter source which is comparing node attributes)

Any inputs around this are helpful.

TIA


Solution

  • I suppose this documentation might be better structured.

    Main idea is to set a user-defined attribute, for example "color" to red or blue.

    <bean class="org.apache.ignite.configuration.IgniteConfiguration">
        <property name="userAttributes">
            <map>
                <entry key="color" value="blue"/>
            </map>
        </property>
    </bean>
    

    Or config.setUserAttributes(F.asMap("color", "red"));

    And use it in your backup filter implementation:

    <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">
                        <value>color</value>
                    </array>
                </constructor-arg>
            </bean>
        </property>
    </bean>
    

    In that case, prior to saving a backup copy, Ignite will check if the "color" attribute of the current node differs from the backup's one (i.e. if it's "read", then we need to search for a "blue" node).