Skip to content

Commit 852068c

Browse files
committed
add select by zone logic for read/write pool selection
1 parent c0b0202 commit 852068c

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ public SelectedPool selectWritePool(long preallocated)
259259
.map(_costModule::getPoolInfo)
260260
.filter(Objects::nonNull)
261261
.collect(toList());
262+
pools = filterByZone(pools);
263+
262264
if (!pools.isEmpty()) {
263265
Partition partition = _partitionManager.getPartition(level.getTag());
264266
try {
@@ -341,6 +343,8 @@ public SelectedPool selectReadPool()
341343
LOGGER.debug("[read] Available pools at level {}: {}",
342344
prio, pools);
343345

346+
pools = filterByZone(pools);
347+
344348
/* If allowed, fallback to next link if current link doesn't point
345349
* to any pool holding the file.
346350
*/
@@ -393,6 +397,17 @@ public SelectedPool selectReadPool()
393397
"File is online, but not in read-allowed pool");
394398
}
395399

400+
private List<PoolInfo> filterByZone(List<PoolInfo> pools) {
401+
if (_zone.isPresent()) {
402+
List<PoolInfo> poolsZ =
403+
pools.stream()
404+
.filter(p -> Objects.equals(p.getTags().get("zone"), _zone.get()))
405+
.toList();
406+
pools = (poolsZ.isEmpty()) ? pools : poolsZ;
407+
}
408+
return pools;
409+
}
410+
396411
@Nullable
397412
private String getHostName() {
398413
if (_protocolInfo instanceof IpProtocolInfo) {

modules/dcache/src/test/java/org/dcache/tests/poolmanager/PoolMonitorTest.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import java.util.Collections;
3030
import java.util.HashSet;
3131
import java.util.List;
32+
import java.util.Map;
33+
import java.util.Optional;
3234
import java.util.Set;
3335
import org.dcache.cells.UniversalSpringCell;
3436
import org.dcache.pool.classic.IoQueueManager;
@@ -151,7 +153,37 @@ public void testGsonDeserialization() throws Exception {
151153
.disableHtmlEscaping().create().toJson(obj);
152154
}
153155

156+
@Test
157+
public void testWritePoolZonePreference() throws Exception {
158+
prepareCostModule(false, true);
159+
160+
FileAttributes attributes = FileAttributes.of().pnfsId(_pnfsId).build();
161+
StorageInfos.injectInto(_storageInfo, attributes);
162+
163+
PoolSelector selector = _poolMonitor.getPoolSelector(attributes, _protocolInfo,
164+
null, Optional.of("1"), Collections.EMPTY_SET);
165+
166+
assertEquals("pool1", selector.selectWritePool(0).name());
167+
}
168+
169+
@Test
170+
public void testReadPoolZonePreference() throws Exception {
171+
prepareCostModule(false, true);
172+
173+
FileAttributes attributes = FileAttributes.of().pnfsId(_pnfsId).locations(_pools).build();
174+
StorageInfos.injectInto(_storageInfo, attributes);
175+
176+
PoolSelector selector = _poolMonitor.getPoolSelector(attributes, _protocolInfo,
177+
null, Optional.of("1"), Collections.EMPTY_SET);
178+
179+
assertEquals("pool1", selector.selectReadPool().name());
180+
}
181+
154182
private void prepareCostModule(boolean linkPerPool) throws Exception {
183+
prepareCostModule(linkPerPool, false);
184+
}
185+
186+
private void prepareCostModule(boolean linkPerPool, boolean withZones) throws Exception {
155187
if (linkPerPool) {
156188
PoolMonitorHelper.prepareLinkPerPool(_selectionUnit, _access, _pools);
157189
} else {
@@ -179,6 +211,11 @@ private void prepareCostModule(boolean linkPerPool) throws Exception {
179211
pool1UpMessage.setHostName(_localhost);
180212
pool2UpMessage.setHostName(_localhost);
181213

214+
if (withZones) {
215+
pool1UpMessage.setTagMap(Map.of("zone", "1"));
216+
pool2UpMessage.setTagMap(Map.of("zone", "2"));
217+
}
218+
182219
CellMessage envelope1 = new CellMessage(new CellAddressCore("PoolManager"), null);
183220
envelope1.addSourceAddress(new CellAddressCore("pool1"));
184221
CellMessage envelope2 = new CellMessage(new CellAddressCore("PoolManager"), null);

0 commit comments

Comments
 (0)