Skip to content

Commit

Permalink
pool: Fix pool selection bugs in migration module
Browse files Browse the repository at this point in the history
There were two bugs in migration module:

- Random pool selection would select pools even when they are full.

- Proportional pool selection would trigger a NPE as it would return
  null when all pools are full.

Target: trunk
Request: 2.10
Request: 2.9
Request: 2.8
Request: 2.7
Request: 2.6
Require-notes: yes
Require-book: no
Acked-by: Paul Millar <paul.millar@desy.de>
Patch: https://rb.dcache.org/r/7362/
(cherry picked from commit 55de0de)

Conflicts:
	modules/dcache/src/main/java/org/dcache/pool/migration/Task.java

(cherry picked from commit d85629d)
  • Loading branch information
gbehrmann committed Oct 16, 2014
1 parent b995c0b commit 7b90e31
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
@@ -1,5 +1,7 @@
package org.dcache.pool.migration;

import javax.annotation.Nullable;

import java.util.List;

import diskCacheV111.vehicles.PoolManagerPoolInformation;
Expand All @@ -9,5 +11,6 @@
*/
public interface PoolSelectionStrategy
{
@Nullable
PoolManagerPoolInformation select(List<PoolManagerPoolInformation> pools);
}
@@ -1,10 +1,15 @@
package org.dcache.pool.migration;

import com.google.common.base.Predicate;

import java.util.List;
import java.util.Random;

import diskCacheV111.pools.PoolCostInfo;
import diskCacheV111.vehicles.PoolManagerPoolInformation;

import static com.google.common.collect.Iterables.*;

/**
* Implements a pool selection strategy in which the pool is selected
* randomly from the list.
Expand All @@ -18,6 +23,19 @@ public class RandomPoolSelectionStrategy
public PoolManagerPoolInformation
select(List<PoolManagerPoolInformation> pools)
{
return pools.get(_random.nextInt(pools.size()));
Iterable<PoolManagerPoolInformation> nonFullPools =
filter(pools, new Predicate<PoolManagerPoolInformation>()
{
@Override
public boolean apply(PoolManagerPoolInformation pool)
{
PoolCostInfo.PoolSpaceInfo info = pool.getPoolCostInfo().getSpaceInfo();
return info.getFreeSpace() >= info.getGap();
}
});
if (isEmpty(nonFullPools)) {
return null;
}
return get(nonFullPools, _random.nextInt(size(nonFullPools)));
}
}
10 changes: 7 additions & 3 deletions modules/dcache/src/main/java/org/dcache/pool/migration/Task.java
Expand Up @@ -207,10 +207,14 @@ private CellPath selectPool()
{
List<PoolManagerPoolInformation> pools =
_definition.poolList.getPools();
if (pools.isEmpty()) {
throw new NoSuchElementException("No pools available");
PoolManagerPoolInformation pool = _definition.selectionStrategy.select(pools);
if (pool == null) {
if (pools.isEmpty()) {
throw new NoSuchElementException("No pools available.");
}
throw new NoSuchElementException("All target pools are full.");
}
return new CellPath(_definition.selectionStrategy.select(pools).getName());
return new CellPath(pool.getName());
}


Expand Down

0 comments on commit 7b90e31

Please sign in to comment.