Skip to content

Commit fc7ffc9

Browse files
lens161Lennart Sack
authored andcommitted
p2p: select dst by zone in WassPartition
1 parent 62eec1c commit fc7ffc9

9 files changed

Lines changed: 94 additions & 3 deletions

File tree

modules/dcache/src/main/java/diskCacheV111/poolManager/PoolMonitorV5.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ public Partition.P2pPair selectPool2Pool(String poolGroup,
509509
Lists.newArrayList(sources.values()),
510510
pools,
511511
_fileAttributes,
512+
_zone,
512513
force);
513514
}
514515
}

modules/dcache/src/main/java/org/dcache/poolmanager/BufferPartition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public SelectedPool selectReadPool(CostModule cm, List<PoolInfo> pools,
145145

146146
@Override
147147
public P2pPair selectPool2Pool(CostModule cm, List<PoolInfo> src, List<PoolInfo> dst,
148-
FileAttributes attributes, boolean force) throws CacheException {
148+
FileAttributes attributes, Optional<String> zone, boolean force) throws CacheException {
149149
return new P2pPair(selectPool(src), selectPool(dst, attributes.getSize()));
150150
}
151151

modules/dcache/src/main/java/org/dcache/poolmanager/LruPartition.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ public P2pPair selectPool2Pool(CostModule cm,
133133
List<PoolInfo> src,
134134
List<PoolInfo> dst,
135135
FileAttributes attributes,
136+
Optional<String> zone,
136137
boolean force)
137138
throws CacheException {
138139
return new P2pPair(new SelectedPool(select(src, _lastRead)),

modules/dcache/src/main/java/org/dcache/poolmanager/Partition.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ public abstract P2pPair selectPool2Pool(CostModule cm,
335335
List<PoolInfo> src,
336336
List<PoolInfo> dst,
337337
FileAttributes attributes,
338+
Optional<String> zone,
338339
boolean force)
339340
throws CacheException;
340341

modules/dcache/src/main/java/org/dcache/poolmanager/RandomPartition.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public SelectedPool selectReadPool(CostModule cm,
8282
List<PoolInfo> src,
8383
List<PoolInfo> dst,
8484
FileAttributes attributes,
85+
Optional<String> zone,
8586
boolean force)
8687
throws CacheException {
8788
return new P2pPair(new SelectedPool(select(src)),

modules/dcache/src/main/java/org/dcache/poolmanager/WRandomPartition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public String getType() {
5151
}
5252

5353
@Override
54-
public P2pPair selectPool2Pool(CostModule cm, List<PoolInfo> src, List<PoolInfo> dst, FileAttributes attributes, boolean force) throws CacheException {
54+
public P2pPair selectPool2Pool(CostModule cm, List<PoolInfo> src, List<PoolInfo> dst, FileAttributes attributes, Optional<String> zone, boolean force) throws CacheException {
5555

5656
Collections.shuffle(src);
5757

modules/dcache/src/main/java/org/dcache/poolmanager/WassPartition.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public P2pPair selectPool2Pool(CostModule cm,
8383
List<PoolInfo> src,
8484
List<PoolInfo> dst,
8585
FileAttributes attributes,
86+
Optional<String> zone,
8687
boolean force)
8788
throws CacheException {
8889
checkState(!src.isEmpty());
@@ -139,6 +140,11 @@ public P2pPair selectPool2Pool(CostModule cm,
139140
: new AvailableSpaceAssumption(filesize).and(PerformanceCostAssumption.of(
140141
_error, maxTargetCost));
141142

143+
if (zone.isPresent()) {
144+
List<PoolInfo> dstZ = filterByZone(dst, zone);
145+
dst = (dstZ.isEmpty()) ? dst : dstZ;
146+
}
147+
142148
if (_allowSameHostCopy != SameHost.NOTCHECKED) {
143149
/* Loop over all sources and find the most appropriate
144150
* destination such that same host constraints are
@@ -177,6 +183,13 @@ public P2pPair selectPool2Pool(CostModule cm,
177183
new SelectedPool(destination, destinationAssumption));
178184
}
179185

186+
private List<PoolInfo> filterByZone(List<PoolInfo> pools, Optional<String> zone) {
187+
pools = pools.stream()
188+
.filter(p -> Objects.equals(p.getTags().get("zone"), zone.get()))
189+
.toList();
190+
return pools;
191+
}
192+
180193
private PoolInfo selectByPrevious(List<PoolInfo> pools,
181194
Optional<PoolInfo> previous,
182195
FileAttributes attributes) {

modules/dcache/src/test/java/org/dcache/mock/SimplePartition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public SelectedPool selectReadPool(CostModule cm, List<PoolInfo> pools,
6666

6767
@Override
6868
public P2pPair selectPool2Pool(CostModule cm, List<PoolInfo> src,
69-
List<PoolInfo> dst, FileAttributes attributes, boolean force)
69+
List<PoolInfo> dst, FileAttributes attributes, Optional<String> zone, boolean force)
7070
throws CacheException {
7171
throw new UnsupportedOperationException("Not supported yet.");
7272
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package org.dcache.poolmanager;
2+
3+
import com.google.common.collect.ImmutableMap;
4+
import diskCacheV111.poolManager.CostModule;
5+
import diskCacheV111.pools.PoolCostInfo;
6+
import diskCacheV111.util.CacheException;
7+
import dmg.cells.nucleus.CellAddressCore;
8+
import org.dcache.vehicles.FileAttributes;
9+
import org.junit.Before;
10+
import org.junit.Test;
11+
import org.junit.jupiter.api.RepeatedTest;
12+
13+
import java.util.ArrayList;
14+
import java.util.List;
15+
import java.util.Map;
16+
import java.util.Optional;
17+
import java.util.stream.IntStream;
18+
import java.util.stream.Stream;
19+
20+
import static org.junit.Assert.assertEquals;
21+
import static org.junit.Assert.assertTrue;
22+
23+
public class WassPartitionTest {
24+
25+
WassPartition wass;
26+
FileAttributes attributes;
27+
List<PoolInfo> dst;
28+
List<PoolInfo> src;
29+
Optional<String> zone;
30+
31+
@Before
32+
public void setUp() {
33+
wass = new WassPartition(Map.of());
34+
attributes = FileAttributes.ofSize(1000L);
35+
zone = Optional.of("A");
36+
37+
src = IntStream.range(0, 1).mapToObj(i -> {
38+
var cost = new PoolCostInfo("pool" + i, "default-queue");
39+
cost.setSpaceUsage(10_000L, 5000L, 0L, 0L);
40+
cost.getSpaceInfo().setParameter(0.0d, 2500L);
41+
42+
return new PoolInfo(new CellAddressCore("pool" + i), cost, ImmutableMap.of("zone", "A"));
43+
}
44+
).toList();
45+
46+
List<PoolInfo>dstCorrect = IntStream.range(2, 4).mapToObj(i -> {
47+
var cost = new PoolCostInfo("pool" + i, "default-queue");
48+
cost.setSpaceUsage(10_000L, 5000L, 0L, 0L);
49+
cost.getSpaceInfo().setParameter(0.0d, 2500L);
50+
51+
return new PoolInfo(new CellAddressCore("pool" + i), cost, ImmutableMap.of("zone", "A"));
52+
}
53+
).toList();
54+
55+
List<PoolInfo>dstWrong = IntStream.range(5, 7).mapToObj(i -> {
56+
var cost = new PoolCostInfo("pool" + i, "default-queue");
57+
cost.setSpaceUsage(10_000L, 5000L, 0L, 0L);
58+
cost.getSpaceInfo().setParameter(0.0d, 2500L);
59+
60+
return new PoolInfo(new CellAddressCore("pool" + i), cost, ImmutableMap.of("zone", "B"));
61+
}
62+
).toList();
63+
64+
dst = Stream.concat(dstCorrect.stream(), dstWrong.stream()).toList();
65+
}
66+
67+
@Test
68+
public void testCorrectZoneDst() throws CacheException {
69+
for (int i = 0; i < 9; i++){
70+
PoolInfo info = wass.selectPool2Pool(null, src, dst, attributes, zone, false).destination.info();
71+
assertEquals(zone.get(), info.getTags().get("zone"));
72+
}
73+
}
74+
}

0 commit comments

Comments
 (0)