Skip to content

Commit 7fa54b3

Browse files
kofemannkhys95
authored andcommitted
poolmanager: fix wrandom partition
Motivation: the merge of commit a778f97 added silent conflict which introduced infinite loop due to loop index freez, that ended in infinite loop. Modification: fix the loop using iterator and index (as original code aimed to to). Added extra unit test that check loop in action. Result: fixed infinite loop in wrandom partition Acked-by: Dmitry Litvintsev Target: master, 11.1, 11.0, 10.2, 10.1, 10.0, 9.2 Require-book: no Require-notes: yes (cherry picked from commit cd23f59) Signed-off-by: Tigran Mkrtchyan <[email protected]>
1 parent ad13fcc commit 7fa54b3

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ public SelectedPool selectWritePool(CostModule cm, List<PoolInfo> pools, FileAtt
9191
return new SelectedPool(weightedPools[index].getCostInfo());
9292
}
9393

94-
private WeightedPool[] toWeightedWritePoolsArray(List<PoolInfo> costInfos, long fileSize)
95-
throws CacheException {
94+
private WeightedPool[] toWeightedWritePoolsArray(List<PoolInfo> costInfos, long fileSize) {
9695

9796
long totalFree = 0;
9897
int validCount = 0;
@@ -108,11 +107,10 @@ private WeightedPool[] toWeightedWritePoolsArray(List<PoolInfo> costInfos, long
108107
validCount++;
109108
}
110109

111-
// the validCount should macht the number of pools that have enough space, thus elegible for selection
110+
// the validCount should mach the number of pools that have enough space, thus eligible for selection
112111
WeightedPool[] weightedPools = new WeightedPool[validCount];
113-
for (int i = 0; i < weightedPools.length; /* incremented in the loop */) {
114-
115-
var costInfo = costInfos.get(i);
112+
int i = 0;
113+
for (PoolInfo costInfo : costInfos) {
116114

117115
long gap = costInfo.getCostInfo().getSpaceInfo().getGap();
118116

modules/dcache/src/test/java/org/dcache/poolmanager/WRandomPartitionTest.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void shouldFailIfAllocatesIntoGap() throws CacheException {
3131
).toList();
3232

3333
long fileSize = 1000L;
34-
var selectedPool = wrandom.selectWritePool(null, pools, null, fileSize);
34+
wrandom.selectWritePool(null, pools, null, fileSize);
3535
}
3636

3737
@Test
@@ -51,7 +51,30 @@ public void shouldSelectValidPool() throws CacheException {
5151
var selectedPool = wrandom.selectWritePool(null, pools, null, fileSize);
5252

5353
var spaceInfo = selectedPool.info().getCostInfo().getSpaceInfo();
54-
assertTrue("selected pool has no sufficient space", spaceInfo.getFreeSpace() + spaceInfo.getRemovableSpace() - fileSize > spaceInfo.getGap());
54+
assertTrue("selected pool has no sufficient space", spaceInfo.getFreeSpace() + spaceInfo.getRemovableSpace() - fileSize >= spaceInfo.getGap());
5555
}
5656

57+
58+
@Test
59+
public void shouldSkipFullPool() throws CacheException {
60+
61+
var wrandom = new WRandomPartition(Map.of());
62+
63+
// starting the 5th pools have enough space
64+
var pools = IntStream.range(0, 10).mapToObj(i -> {
65+
var cost = new PoolCostInfo("pool" + i, "default-queue");
66+
cost.setSpaceUsage(10_000L, 3_000L + 100L*i, 0L, 0L);
67+
cost.getSpaceInfo().setParameter(0.0d, 2500L);
68+
69+
return new PoolInfo(new CellAddressCore("pool" + i), cost, ImmutableMap.of());
70+
}
71+
).toList();
72+
73+
long fileSize = 1000L;
74+
var selectedPool = wrandom.selectWritePool(null, pools, null, fileSize);
75+
76+
var spaceInfo = selectedPool.info().getCostInfo().getSpaceInfo();
77+
System.out.println(selectedPool.info().getCostInfo().getPoolName()+ " " + spaceInfo);
78+
assertTrue("selected pool has no sufficient space", spaceInfo.getFreeSpace() + spaceInfo.getRemovableSpace() - fileSize >= spaceInfo.getGap());
79+
}
5780
}

0 commit comments

Comments
 (0)