anton-vinogradov commented on code in PR #12459:
URL: https://github.com/apache/ignite/pull/12459#discussion_r2477886789


##########
modules/core/src/test/java/org/apache/ignite/cache/affinity/rendezvous/MdcAffinityBackupFilterSelfTest.java:
##########
@@ -0,0 +1,289 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.affinity.rendezvous;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteSystemProperties;
+import org.apache.ignite.cache.affinity.Affinity;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.lang.IgniteBiPredicate;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+import static org.apache.ignite.testframework.GridTestUtils.assertThrows;
+
+/**
+ * Verifies behaviour of {@link MdcAffinityBackupFilter} - guarantees that 
each DC has at least one copy of every partition.
+ * Verified distribution uniformity in each DC separately.
+ */
+public class MdcAffinityBackupFilterSelfTest extends GridCommonAbstractTest {
+    /** */
+    private static final int PARTS_CNT = 1024;
+
+    /** */
+    private int backups;
+
+    /** */
+    private String[] dcIds;
+
+    /** */
+    private IgniteBiPredicate<ClusterNode, List<ClusterNode>> filter;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String 
igniteInstanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+        cfg.setCacheConfiguration(defaultCacheConfiguration()
+            .setBackups(backups)
+            .setAffinity(
+                new RendezvousAffinityFunction(false, PARTS_CNT)
+                    .setAffinityBackupFilter(filter)));
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        super.afterTest();
+
+        stopAllGrids();
+    }
+
+    /**
+     * Verifies that {@link MdcAffinityBackupFilter} prohibits single data 
center deployment.
+     */
+    @Test
+    public void testSingleDcDeploymentIsProhibited() {
+        assertThrows(null,
+            () -> new MdcAffinityBackupFilter(1, 1),
+            IllegalArgumentException.class,
+            "Number of datacenters must be at least 2.");

Review Comment:
   It's ok to have single DC, at least for case "we're planning to separate 
cluster".
   And for case "Second DC currently is down".



##########
modules/core/src/main/java/org/apache/ignite/cache/affinity/rendezvous/MdcAffinityBackupFilter.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.affinity.rendezvous;
+
+import java.util.List;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.lang.IgniteBiPredicate;
+
+/**
+ * Multi-data center affinity backup filter that ensures each partition's data 
is distributed across multiple data centers,
+ * providing high availability and fault tolerance. This implementation 
guarantees at least one copy of the data in each
+ * data center and attempts to maintain the configured backup factor without 
discarding copies.
+ * <p>
+ * The filter works by grouping nodes based on their data center 
identification attribute (@see {@link ClusterNode#dataCenterId()})
+ * and ensuring that for every partition, at least one node from each data 
center is included in the primary-backup set.
+ * <p>
+ * The filter will discard backup copies only if the number of available nodes 
in a given data center is less
+ * than the number of copies assigned to that data center.
+ * For example, if a partition has 4 copies (1 primary and 3 backups) and the 
cluster has 2 data centers,
+ * than 2 copies are assigned to each data center. The only scenario when just 
a single copy is assigned to a node in a data center is when
+ * the number of nodes in that data center is one.
+ * <p>
+ * This class is constructed with a number of data centers the cluster spans 
and a number of backups of the cache this filter is applied to.
+ * Implementation expects that all copies can be spread evenly across all data 
centers. In other words, (backups + 1) is divisible by
+ * number of data centers without remainder. Uneven distributions of copies 
are not supported.
+ * <p>
+ * Warning: Ensure that all nodes have a consistent and valid data center 
identifier attribute. Missing or inconsistent values
+ * may lead to unexpected placement of data.
+ * </pre>
+ * <h2 class="header">Spring Example</h2>
+ * Create a partitioned cache template where each data center has at least one 
copy of the data, and the backup count is maintained.
+ * <pre name="code" class="xml">
+ * &lt;property name="cacheConfiguration"&gt;
+ *     &lt;list&gt;
+ *         &lt;bean id="cache-template-bean" abstract="true" 
class="org.apache.ignite.configuration.CacheConfiguration"&gt;
+ *             &lt;property name="name" value="JobcaseDefaultCacheConfig*"/&gt;
+ *             &lt;property name="cacheMode" value="PARTITIONED" /&gt;
+ *             &lt;property name="backups" value="3" /&gt;
+ *             &lt;property name="affinity"&gt;
+ *                 &lt;bean 
class="org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction"&gt;
+ *                     &lt;property name="affinityBackupFilter"&gt;
+ *                         &lt;bean 
class="org.apache.ignite.cache.affinity.rendezvous.MdcAffinityBackupFilter"&gt;
+ *                             &lt;constructor-arg value="2"/&gt; <!-- 
dcsNumber -->
+ *                             &lt;constructor-arg value="3"/&gt; <!-- 
backups, the same as in the cache template -->
+ *                         &lt;/bean&gt;
+ *                     &lt;/property&gt;
+ *                 &lt;/bean&gt;
+ *             &lt;/property&gt;
+ *         &lt;/bean&gt;
+ *     &lt;/list&gt;
+ * &lt;/property&gt;
+ * </pre>
+ * <p>
+ * With more backups, additional replicas can be distributed across different 
data centers to further improve redundancy.
+ */
+public class MdcAffinityBackupFilter implements IgniteBiPredicate<ClusterNode, 
List<ClusterNode>> {
+    /** */
+    private static final long serialVersionUID = 1L;
+
+    /** */
+    private final int partCopiesPerDc;
+
+    /**
+     * @param dcsNum Number of data centers.
+     * @param backups Number of backups.
+     */
+    public MdcAffinityBackupFilter(int dcsNum, int backups) {
+        if (dcsNum < 2) {
+            throw new IllegalArgumentException("MdcAffinityBackupFilter cannot 
be used in an environment with only one datacenter. " +
+                "Number of datacenters must be at least 2.");
+        }
+
+        int numCopies = backups + 1;
+
+        partCopiesPerDc = numCopies / dcsNum;
+        int remainder = numCopies % dcsNum;
+
+        if (remainder != 0) {
+            String suggestion = "recommended ";
+            if (numCopies - remainder <= 0)
+                suggestion += "value is " + (backups + (dcsNum - remainder));
+            else
+                suggestion += "values are " + (backups - remainder) + " and " 
+ (backups + (dcsNum - remainder));
+            
+            throw new IllegalArgumentException("Number of copies is not 
completely divisible by number of datacenters, " +
+                "copies cannot be distributed evenly across DCs. " +
+                "Please adjust the number of backups, " + suggestion);
+        }
+
+
+    }
+
+    /**
+     * Defines a predicate which returns {@code true} if a node is acceptable 
for a backup
+     * or {@code false} otherwise.
+     * An acceptable node is the one that belongs to a data center that has 
some additional copies of partition to assign to.
+     * @param candidate A node that is a candidate for becoming a backup node 
for a partition.
+     * @param previouslySelected A list of primary/backup nodes already chosen 
for a partition.
+     *                           The primary is first.
+     */
+    @Override public boolean apply(ClusterNode candidate, List<ClusterNode> 
previouslySelected) {
+        String candidateDcId = candidate.dataCenterId();
+        int candDcCopiesAssigned = 0;
+
+        for (int i = 0; i < previouslySelected.size(); i++) {
+            String prevDcId = previouslySelected.get(i).dataCenterId();
+
+            if (prevDcId == null)
+                return false;

Review Comment:
   Should we really handle the case when DC is not set?



##########
modules/core/src/test/java/org/apache/ignite/cache/affinity/rendezvous/MdcAffinityBackupFilterSelfTest.java:
##########
@@ -0,0 +1,289 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.affinity.rendezvous;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteSystemProperties;
+import org.apache.ignite.cache.affinity.Affinity;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.lang.IgniteBiPredicate;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+import static org.apache.ignite.testframework.GridTestUtils.assertThrows;
+
+/**
+ * Verifies behaviour of {@link MdcAffinityBackupFilter} - guarantees that 
each DC has at least one copy of every partition.
+ * Verified distribution uniformity in each DC separately.
+ */
+public class MdcAffinityBackupFilterSelfTest extends GridCommonAbstractTest {
+    /** */
+    private static final int PARTS_CNT = 1024;
+
+    /** */
+    private int backups;
+
+    /** */
+    private String[] dcIds;
+
+    /** */
+    private IgniteBiPredicate<ClusterNode, List<ClusterNode>> filter;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String 
igniteInstanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+        cfg.setCacheConfiguration(defaultCacheConfiguration()
+            .setBackups(backups)
+            .setAffinity(
+                new RendezvousAffinityFunction(false, PARTS_CNT)
+                    .setAffinityBackupFilter(filter)));
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        super.afterTest();
+
+        stopAllGrids();
+    }
+
+    /**
+     * Verifies that {@link MdcAffinityBackupFilter} prohibits single data 
center deployment.
+     */
+    @Test
+    public void testSingleDcDeploymentIsProhibited() {
+        assertThrows(null,
+            () -> new MdcAffinityBackupFilter(1, 1),
+            IllegalArgumentException.class,
+            "Number of datacenters must be at least 2.");
+    }
+
+    /**
+     * Verifies that {@link MdcAffinityBackupFilter} enforces even number of 
partition copies per datacenter.
+     */
+    @Test
+    public void testUniformNumberOfPartitionCopiesPerDcIsEnforced() {
+        assertThrows(null,
+            () -> new MdcAffinityBackupFilter(3, 1),
+            IllegalArgumentException.class,
+            "recommended value is 2");
+
+        assertThrows(null,
+            () -> new MdcAffinityBackupFilter(3, 7),
+            IllegalArgumentException.class,
+            "recommended values are 5 and 8");
+    }
+
+    /**
+     * Verifies that partition copies are assigned evenly across a cluster in 
two data centers.
+     * <p/>
+     * When a node from one data center is stopped, partition distribution is 
that data center should stay uniform.
+     *
+     * @throws Exception If failed.
+     */
+    @Test
+    public void test2DcDistribution() throws Exception {
+        dcIds = new String[] {"DC_0", "DC_1"};
+        int nodesPerDc = 4;
+        backups = 3;
+        filter = new MdcAffinityBackupFilter(dcIds.length, backups);
+
+        IgniteEx srv = startClusterAcrossDataCenters(dcIds, nodesPerDc);
+
+        verifyDistributionProperties(srv, dcIds, nodesPerDc, backups);
+
+        //stopping one node in DC_1 should not compromise distribution as 
there are additional nodes in the same DC
+        stopGrid(5);
+
+        awaitPartitionMapExchange();
+
+        verifyDistributionProperties(srv, dcIds, nodesPerDc, backups);
+
+        //stopping another node in DC_1 should not compromise distribution as 
well
+        stopGrid(6);

Review Comment:
   let's stop the whole cluster as well and check there is no rebalance 
happened.



##########
modules/core/src/main/java/org/apache/ignite/cache/affinity/rendezvous/MdcAffinityBackupFilter.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.affinity.rendezvous;
+
+import java.util.List;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.lang.IgniteBiPredicate;
+
+/**
+ * Multi-data center affinity backup filter that ensures each partition's data 
is distributed across multiple data centers,
+ * providing high availability and fault tolerance. This implementation 
guarantees at least one copy of the data in each
+ * data center and attempts to maintain the configured backup factor without 
discarding copies.
+ * <p>
+ * The filter works by grouping nodes based on their data center 
identification attribute (@see {@link ClusterNode#dataCenterId()})
+ * and ensuring that for every partition, at least one node from each data 
center is included in the primary-backup set.
+ * <p>
+ * The filter will discard backup copies only if the number of available nodes 
in a given data center is less
+ * than the number of copies assigned to that data center.
+ * For example, if a partition has 4 copies (1 primary and 3 backups) and the 
cluster has 2 data centers,
+ * than 2 copies are assigned to each data center. The only scenario when just 
a single copy is assigned to a node in a data center is when
+ * the number of nodes in that data center is one.
+ * <p>
+ * This class is constructed with a number of data centers the cluster spans 
and a number of backups of the cache this filter is applied to.
+ * Implementation expects that all copies can be spread evenly across all data 
centers. In other words, (backups + 1) is divisible by
+ * number of data centers without remainder. Uneven distributions of copies 
are not supported.
+ * <p>
+ * Warning: Ensure that all nodes have a consistent and valid data center 
identifier attribute. Missing or inconsistent values
+ * may lead to unexpected placement of data.
+ * </pre>
+ * <h2 class="header">Spring Example</h2>
+ * Create a partitioned cache template where each data center has at least one 
copy of the data, and the backup count is maintained.
+ * <pre name="code" class="xml">
+ * &lt;property name="cacheConfiguration"&gt;
+ *     &lt;list&gt;
+ *         &lt;bean id="cache-template-bean" abstract="true" 
class="org.apache.ignite.configuration.CacheConfiguration"&gt;
+ *             &lt;property name="name" value="JobcaseDefaultCacheConfig*"/&gt;
+ *             &lt;property name="cacheMode" value="PARTITIONED" /&gt;
+ *             &lt;property name="backups" value="3" /&gt;
+ *             &lt;property name="affinity"&gt;
+ *                 &lt;bean 
class="org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction"&gt;
+ *                     &lt;property name="affinityBackupFilter"&gt;
+ *                         &lt;bean 
class="org.apache.ignite.cache.affinity.rendezvous.MdcAffinityBackupFilter"&gt;
+ *                             &lt;constructor-arg value="2"/&gt; <!-- 
dcsNumber -->
+ *                             &lt;constructor-arg value="3"/&gt; <!-- 
backups, the same as in the cache template -->
+ *                         &lt;/bean&gt;
+ *                     &lt;/property&gt;
+ *                 &lt;/bean&gt;
+ *             &lt;/property&gt;
+ *         &lt;/bean&gt;
+ *     &lt;/list&gt;
+ * &lt;/property&gt;
+ * </pre>
+ * <p>
+ * With more backups, additional replicas can be distributed across different 
data centers to further improve redundancy.
+ */
+public class MdcAffinityBackupFilter implements IgniteBiPredicate<ClusterNode, 
List<ClusterNode>> {
+    /** */
+    private static final long serialVersionUID = 1L;
+
+    /** */
+    private final int partCopiesPerDc;
+
+    /**
+     * @param dcsNum Number of data centers.
+     * @param backups Number of backups.
+     */
+    public MdcAffinityBackupFilter(int dcsNum, int backups) {
+        if (dcsNum < 2) {
+            throw new IllegalArgumentException("MdcAffinityBackupFilter cannot 
be used in an environment with only one datacenter. " +
+                "Number of datacenters must be at least 2.");
+        }
+
+        int numCopies = backups + 1;
+
+        partCopiesPerDc = numCopies / dcsNum;
+        int remainder = numCopies % dcsNum;
+
+        if (remainder != 0) {
+            String suggestion = "recommended ";
+            if (numCopies - remainder <= 0)
+                suggestion += "value is " + (backups + (dcsNum - remainder));
+            else
+                suggestion += "values are " + (backups - remainder) + " and " 
+ (backups + (dcsNum - remainder));
+            
+            throw new IllegalArgumentException("Number of copies is not 
completely divisible by number of datacenters, " +
+                "copies cannot be distributed evenly across DCs. " +
+                "Please adjust the number of backups, " + suggestion);
+        }

Review Comment:
   Looks overcomplicated and error-prone to me.
   We should **always** have the same number at each DC, rounded up `numCopies 
/ DC_count`.
   If % provides us a non-zero value, let's do what we have to, but with a 
warning. This should simplify logic.



##########
modules/core/src/main/java/org/apache/ignite/cache/affinity/rendezvous/MdcAffinityBackupFilter.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.affinity.rendezvous;
+
+import java.util.List;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.lang.IgniteBiPredicate;
+
+/**
+ * Multi-data center affinity backup filter that ensures each partition's data 
is distributed across multiple data centers,
+ * providing high availability and fault tolerance. This implementation 
guarantees at least one copy of the data in each
+ * data center and attempts to maintain the configured backup factor without 
discarding copies.
+ * <p>
+ * The filter works by grouping nodes based on their data center 
identification attribute (@see {@link ClusterNode#dataCenterId()})
+ * and ensuring that for every partition, at least one node from each data 
center is included in the primary-backup set.
+ * <p>
+ * The filter will discard backup copies only if the number of available nodes 
in a given data center is less
+ * than the number of copies assigned to that data center.
+ * For example, if a partition has 4 copies (1 primary and 3 backups) and the 
cluster has 2 data centers,
+ * than 2 copies are assigned to each data center. The only scenario when just 
a single copy is assigned to a node in a data center is when
+ * the number of nodes in that data center is one.
+ * <p>
+ * This class is constructed with a number of data centers the cluster spans 
and a number of backups of the cache this filter is applied to.
+ * Implementation expects that all copies can be spread evenly across all data 
centers. In other words, (backups + 1) is divisible by
+ * number of data centers without remainder. Uneven distributions of copies 
are not supported.
+ * <p>
+ * Warning: Ensure that all nodes have a consistent and valid data center 
identifier attribute. Missing or inconsistent values
+ * may lead to unexpected placement of data.
+ * </pre>
+ * <h2 class="header">Spring Example</h2>
+ * Create a partitioned cache template where each data center has at least one 
copy of the data, and the backup count is maintained.
+ * <pre name="code" class="xml">
+ * &lt;property name="cacheConfiguration"&gt;
+ *     &lt;list&gt;
+ *         &lt;bean id="cache-template-bean" abstract="true" 
class="org.apache.ignite.configuration.CacheConfiguration"&gt;
+ *             &lt;property name="name" value="JobcaseDefaultCacheConfig*"/&gt;
+ *             &lt;property name="cacheMode" value="PARTITIONED" /&gt;
+ *             &lt;property name="backups" value="3" /&gt;
+ *             &lt;property name="affinity"&gt;
+ *                 &lt;bean 
class="org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction"&gt;
+ *                     &lt;property name="affinityBackupFilter"&gt;
+ *                         &lt;bean 
class="org.apache.ignite.cache.affinity.rendezvous.MdcAffinityBackupFilter"&gt;
+ *                             &lt;constructor-arg value="2"/&gt; <!-- 
dcsNumber -->
+ *                             &lt;constructor-arg value="3"/&gt; <!-- 
backups, the same as in the cache template -->
+ *                         &lt;/bean&gt;
+ *                     &lt;/property&gt;
+ *                 &lt;/bean&gt;
+ *             &lt;/property&gt;
+ *         &lt;/bean&gt;
+ *     &lt;/list&gt;
+ * &lt;/property&gt;
+ * </pre>
+ * <p>
+ * With more backups, additional replicas can be distributed across different 
data centers to further improve redundancy.
+ */
+public class MdcAffinityBackupFilter implements IgniteBiPredicate<ClusterNode, 
List<ClusterNode>> {
+    /** */
+    private static final long serialVersionUID = 1L;
+
+    /** */
+    private final int partCopiesPerDc;
+
+    /**
+     * @param dcsNum Number of data centers.
+     * @param backups Number of backups.
+     */
+    public MdcAffinityBackupFilter(int dcsNum, int backups) {
+        if (dcsNum < 2) {
+            throw new IllegalArgumentException("MdcAffinityBackupFilter cannot 
be used in an environment with only one datacenter. " +
+                "Number of datacenters must be at least 2.");
+        }
+
+        int numCopies = backups + 1;
+
+        partCopiesPerDc = numCopies / dcsNum;
+        int remainder = numCopies % dcsNum;
+
+        if (remainder != 0) {
+            String suggestion = "recommended ";
+            if (numCopies - remainder <= 0)
+                suggestion += "value is " + (backups + (dcsNum - remainder));
+            else
+                suggestion += "values are " + (backups - remainder) + " and " 
+ (backups + (dcsNum - remainder));
+            
+            throw new IllegalArgumentException("Number of copies is not 
completely divisible by number of datacenters, " +
+                "copies cannot be distributed evenly across DCs. " +
+                "Please adjust the number of backups, " + suggestion);
+        }
+
+
+    }
+
+    /**
+     * Defines a predicate which returns {@code true} if a node is acceptable 
for a backup
+     * or {@code false} otherwise.
+     * An acceptable node is the one that belongs to a data center that has 
some additional copies of partition to assign to.
+     * @param candidate A node that is a candidate for becoming a backup node 
for a partition.
+     * @param previouslySelected A list of primary/backup nodes already chosen 
for a partition.
+     *                           The primary is first.
+     */

Review Comment:
   No need to define javadoc for overridden methods.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to