From 7b90e312ffd40dcaca42a5f7c00e6a12a553c14a Mon Sep 17 00:00:00 2001 From: Gerd Behrmann Date: Wed, 15 Oct 2014 10:30:20 +0200 Subject: [PATCH] pool: Fix pool selection bugs in migration module 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 Patch: https://rb.dcache.org/r/7362/ (cherry picked from commit 55de0de55cc6940f6204dee68e29ec24a13c75d3) Conflicts: modules/dcache/src/main/java/org/dcache/pool/migration/Task.java (cherry picked from commit d85629dfba3027144ae0664d84120e2d0ce4bd92) --- .../pool/migration/PoolSelectionStrategy.java | 3 +++ .../RandomPoolSelectionStrategy.java | 20 ++++++++++++++++++- .../java/org/dcache/pool/migration/Task.java | 10 +++++++--- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/modules/dcache/src/main/java/org/dcache/pool/migration/PoolSelectionStrategy.java b/modules/dcache/src/main/java/org/dcache/pool/migration/PoolSelectionStrategy.java index 3059e619358..cf2c37334d3 100644 --- a/modules/dcache/src/main/java/org/dcache/pool/migration/PoolSelectionStrategy.java +++ b/modules/dcache/src/main/java/org/dcache/pool/migration/PoolSelectionStrategy.java @@ -1,5 +1,7 @@ package org.dcache.pool.migration; +import javax.annotation.Nullable; + import java.util.List; import diskCacheV111.vehicles.PoolManagerPoolInformation; @@ -9,5 +11,6 @@ */ public interface PoolSelectionStrategy { + @Nullable PoolManagerPoolInformation select(List pools); } diff --git a/modules/dcache/src/main/java/org/dcache/pool/migration/RandomPoolSelectionStrategy.java b/modules/dcache/src/main/java/org/dcache/pool/migration/RandomPoolSelectionStrategy.java index 343a9e22745..a77c04144c1 100644 --- a/modules/dcache/src/main/java/org/dcache/pool/migration/RandomPoolSelectionStrategy.java +++ b/modules/dcache/src/main/java/org/dcache/pool/migration/RandomPoolSelectionStrategy.java @@ -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. @@ -18,6 +23,19 @@ public class RandomPoolSelectionStrategy public PoolManagerPoolInformation select(List pools) { - return pools.get(_random.nextInt(pools.size())); + Iterable nonFullPools = + filter(pools, new Predicate() + { + @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))); } } diff --git a/modules/dcache/src/main/java/org/dcache/pool/migration/Task.java b/modules/dcache/src/main/java/org/dcache/pool/migration/Task.java index 967cefe5266..ffaee34fa41 100644 --- a/modules/dcache/src/main/java/org/dcache/pool/migration/Task.java +++ b/modules/dcache/src/main/java/org/dcache/pool/migration/Task.java @@ -207,10 +207,14 @@ private CellPath selectPool() { List 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()); }