Skip to content

Commit 994a6bc

Browse files
IGNITE-24580 Implement happy-case and preform of a test
1 parent 1c660d8 commit 994a6bc

2 files changed

Lines changed: 68 additions & 7 deletions

File tree

modules/core/src/main/java/org/apache/ignite/cache/affinity/rendezvous/DcAffinityBackupFilter.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,28 @@ public class DcAffinityBackupFilter implements IgniteBiPredicate<ClusterNode, Li
4040

4141
/**
4242
* @param dcsCount
43-
* @param primaryAndBackups
43+
* @param backups
4444
*/
45-
public DcAffinityBackupFilter(int dcsCount, int primaryAndBackups) {
45+
public DcAffinityBackupFilter(int dcsCount, int backups) {
4646
this.dcsCount = dcsCount;
4747
partsDistrMap = new LinkedHashMap<>(4);
48-
this.primaryAndBackups = primaryAndBackups;
48+
primaryAndBackups = backups + 1;
4949
}
5050

5151
/** {@inheritDoc} */
5252
@Override public boolean apply(ClusterNode node, List<ClusterNode> list) {
53+
if (list.size() == 1)
54+
partsDistrMap.put(list.get(0).dataCenterId(), 1); //account for primary node which is assigned beforehand
55+
5356
String candidateDcId = node.dataCenterId();
5457
Integer candDcPartsCopies = partsDistrMap.get(candidateDcId);
5558
boolean res = false;
5659

57-
if (candDcPartsCopies == null || candDcPartsCopies == -1)
60+
if (candDcPartsCopies == null || candDcPartsCopies == -1) {
5861
partsDistrMap.put(candidateDcId, 1);
62+
63+
res = true;
64+
}
5965
else {
6066
int partCopiesPerDc = primaryAndBackups / dcsCount;
6167

@@ -68,11 +74,9 @@ public DcAffinityBackupFilter(int dcsCount, int primaryAndBackups) {
6874

6975
Optional<Integer> sum = partsDistrMap.values().stream().reduce(Integer::sum);
7076

71-
if (sum.isPresent() || sum.get() == primaryAndBackups)
77+
if (sum.isPresent() && sum.get() == primaryAndBackups)
7278
partsDistrMap.replaceAll((e, v) -> -1);
7379

7480
return res;
7581
}
76-
77-
// private int nextBucketVolume(int primaryAndBackups, int dcsCount, int ) {
7882
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.ignite.cache.affinity.rendezvous;
19+
20+
import org.apache.ignite.IgniteCheckedException;
21+
import org.apache.ignite.IgniteSystemProperties;
22+
import org.apache.ignite.configuration.CacheConfiguration;
23+
import org.apache.ignite.configuration.IgniteConfiguration;
24+
import org.apache.ignite.internal.IgniteEx;
25+
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
26+
import org.junit.Test;
27+
28+
/** */
29+
public class DcAffinityBackupFilterSelfTest extends GridCommonAbstractTest {
30+
/** */
31+
private static final String DC_0_ID = "DC_0";
32+
33+
/** */
34+
private static final String DC_1_ID = "DC_1";
35+
36+
@Override protected IgniteConfiguration optimize(IgniteConfiguration cfg) throws IgniteCheckedException {
37+
return super.optimize(cfg).setIncludeProperties((String[])null);
38+
}
39+
40+
@Test
41+
public void test1() throws Exception {
42+
System.setProperty(IgniteSystemProperties.IGNITE_DATA_CENTER_ID, DC_0_ID);
43+
startGrids(3);
44+
45+
System.setProperty(IgniteSystemProperties.IGNITE_DATA_CENTER_ID, DC_1_ID);
46+
startGrid(3);
47+
startGrid(4);
48+
IgniteEx srv = startGrid(5);
49+
50+
CacheConfiguration ccfg = defaultCacheConfiguration();
51+
ccfg.setBackups(3);
52+
ccfg.setAffinity(new RendezvousAffinityFunction(false, 2)
53+
.setAffinityBackupFilter(new DcAffinityBackupFilter(2, 3)));
54+
55+
srv.getOrCreateCache(ccfg);
56+
}
57+
}

0 commit comments

Comments
 (0)