Skip to content

Commit

Permalink
poolmanager: fix wrandom partition incompatibilities
Browse files Browse the repository at this point in the history
  • Loading branch information
kofemann committed Sep 21, 2023
1 parent fb04d1c commit 449651f
Showing 1 changed file with 8 additions and 7 deletions.
Expand Up @@ -10,6 +10,7 @@
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Random;

import diskCacheV111.poolManager.CostModule;
Expand Down Expand Up @@ -63,29 +64,29 @@ public P2pPair selectPool2Pool(CostModule cm, List<PoolInfo> src, List<PoolInfo>
filter(dst, new DifferentHost(srcPoolInfo.getHostName())));

if (!tryList.isEmpty()) {
PoolInfo destPoolInfo = selectWritePool(cm, tryList, attributes, attributes.getSize());
return new P2pPair(srcPoolInfo, destPoolInfo);
SelectedPool destPoolInfo = selectWritePool(cm, tryList, attributes, attributes.getSize());
return new P2pPair(new SelectedPool(srcPoolInfo), destPoolInfo);
}
}

return null;
}

@Override
public PoolInfo selectReadPool(CostModule cm, List<PoolInfo> pools, FileAttributes attributes) throws CacheException {
return pools.get(_random.nextInt(pools.size()));
public SelectedPool selectReadPool(CostModule cm, List<PoolInfo> pools, FileAttributes attributes) throws CacheException {
return new SelectedPool(pools.get(_random.nextInt(pools.size())));
}

@Override
public PoolInfo selectStagePool(CostModule cm, List<PoolInfo> pools, String previousPool, String previousHost, FileAttributes attributes) throws CacheException {
public SelectedPool selectStagePool(CostModule cm, List<PoolInfo> pools, Optional<PoolInfo> previousPool, FileAttributes attributes) throws CacheException {
return selectWritePool(cm, pools, attributes, attributes.getSize());
}

@Override
public PoolInfo selectWritePool(CostModule cm, List<PoolInfo> pools, FileAttributes attributes, long preallocated) throws CacheException {
public SelectedPool selectWritePool(CostModule cm, List<PoolInfo> pools, FileAttributes attributes, long preallocated) throws CacheException {
WeightedPool weightedPools[] = toWeightedWritePoolsArray(pools);
int index = selectWrandomIndex(weightedPools);
return weightedPools[index].getCostInfo();
return new SelectedPool(weightedPools[index].getCostInfo());
}

private WeightedPool[] toWeightedWritePoolsArray(Collection<PoolInfo> costInfos) {
Expand Down

0 comments on commit 449651f

Please sign in to comment.