diff --git a/modules/dcache/src/main/java/org/dcache/poolmanager/WRandomPartition.java b/modules/dcache/src/main/java/org/dcache/poolmanager/WRandomPartition.java index 4f30e1523e0..e01bddb2823 100644 --- a/modules/dcache/src/main/java/org/dcache/poolmanager/WRandomPartition.java +++ b/modules/dcache/src/main/java/org/dcache/poolmanager/WRandomPartition.java @@ -91,8 +91,7 @@ public SelectedPool selectWritePool(CostModule cm, List pools, FileAtt return new SelectedPool(weightedPools[index].getCostInfo()); } - private WeightedPool[] toWeightedWritePoolsArray(List costInfos, long fileSize) - throws CacheException { + private WeightedPool[] toWeightedWritePoolsArray(List costInfos, long fileSize) { long totalFree = 0; int validCount = 0; @@ -108,11 +107,10 @@ private WeightedPool[] toWeightedWritePoolsArray(List costInfos, long validCount++; } - // the validCount should macht the number of pools that have enough space, thus elegible for selection + // the validCount should mach the number of pools that have enough space, thus eligible for selection WeightedPool[] weightedPools = new WeightedPool[validCount]; - for (int i = 0; i < weightedPools.length; /* incremented in the loop */) { - - var costInfo = costInfos.get(i); + int i = 0; + for (PoolInfo costInfo : costInfos) { long gap = costInfo.getCostInfo().getSpaceInfo().getGap(); diff --git a/modules/dcache/src/test/java/org/dcache/poolmanager/WRandomPartitionTest.java b/modules/dcache/src/test/java/org/dcache/poolmanager/WRandomPartitionTest.java index 940e7650e73..60f3780ace4 100644 --- a/modules/dcache/src/test/java/org/dcache/poolmanager/WRandomPartitionTest.java +++ b/modules/dcache/src/test/java/org/dcache/poolmanager/WRandomPartitionTest.java @@ -31,7 +31,7 @@ public void shouldFailIfAllocatesIntoGap() throws CacheException { ).toList(); long fileSize = 1000L; - var selectedPool = wrandom.selectWritePool(null, pools, null, fileSize); + wrandom.selectWritePool(null, pools, null, fileSize); } @Test @@ -51,7 +51,30 @@ public void shouldSelectValidPool() throws CacheException { var selectedPool = wrandom.selectWritePool(null, pools, null, fileSize); var spaceInfo = selectedPool.info().getCostInfo().getSpaceInfo(); - assertTrue("selected pool has no sufficient space", spaceInfo.getFreeSpace() + spaceInfo.getRemovableSpace() - fileSize > spaceInfo.getGap()); + assertTrue("selected pool has no sufficient space", spaceInfo.getFreeSpace() + spaceInfo.getRemovableSpace() - fileSize >= spaceInfo.getGap()); } + + @Test + public void shouldSkipFullPool() throws CacheException { + + var wrandom = new WRandomPartition(Map.of()); + + // starting the 5th pools have enough space + var pools = IntStream.range(0, 10).mapToObj(i -> { + var cost = new PoolCostInfo("pool" + i, "default-queue"); + cost.setSpaceUsage(10_000L, 3_000L + 100L*i, 0L, 0L); + cost.getSpaceInfo().setParameter(0.0d, 2500L); + + return new PoolInfo(new CellAddressCore("pool" + i), cost, ImmutableMap.of()); + } + ).toList(); + + long fileSize = 1000L; + var selectedPool = wrandom.selectWritePool(null, pools, null, fileSize); + + var spaceInfo = selectedPool.info().getCostInfo().getSpaceInfo(); + System.out.println(selectedPool.info().getCostInfo().getPoolName()+ " " + spaceInfo); + assertTrue("selected pool has no sufficient space", spaceInfo.getFreeSpace() + spaceInfo.getRemovableSpace() - fileSize >= spaceInfo.getGap()); + } } \ No newline at end of file