Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ public SelectedPool selectWritePool(CostModule cm, List<PoolInfo> pools, FileAtt
return new SelectedPool(weightedPools[index].getCostInfo());
}

private WeightedPool[] toWeightedWritePoolsArray(List<PoolInfo> costInfos, long fileSize)
throws CacheException {
private WeightedPool[] toWeightedWritePoolsArray(List<PoolInfo> costInfos, long fileSize) {

long totalFree = 0;
int validCount = 0;
Expand All @@ -108,11 +107,10 @@ private WeightedPool[] toWeightedWritePoolsArray(List<PoolInfo> 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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
}
}