Skip to content

Commit

Permalink
resolve bin's comment
Browse files Browse the repository at this point in the history
typo
  • Loading branch information
cc committed Jul 11, 2015
1 parent a0d142e commit 9d11ce3
Showing 1 changed file with 16 additions and 7 deletions.
Expand Up @@ -27,15 +27,20 @@


public class EvictorUtils { public class EvictorUtils {
/** /**
* Checks whether the plan is valid for an evictor with cascading eviction feature like * Checks whether the plan of a cascading evictor is valid.
* {@link LRUEvictor}. The plan is legal when the requested space can be satisfied, and there is *
* enough space in lower tier to move in blocks from upper tier. * A cascading evictor will try to free space by recursively moving blocks to next 1 tier and
* evict blocks only in the bottom tier.
*
* The plan is invalid when the requested space can not be satisfied or lower level of tiers do
* not have enough space to hold blocks moved from higher level of tiers.
* *
* @param bytesToBeAvailable requested bytes to be available after eviction * @param bytesToBeAvailable requested bytes to be available after eviction
* @param plan the eviction plan, should not be empty * @param plan the eviction plan, should not be empty
* @param metaManager the meta data manager * @param metaManager the meta data manager
* @return true if the above requirements are satisfied, otherwise false. * @return true if the above requirements are satisfied, otherwise false.
*/ */
// TODO: unit test this method
public static boolean validCascadingPlan(long bytesToBeAvailable, EvictionPlan plan, public static boolean validCascadingPlan(long bytesToBeAvailable, EvictionPlan plan,
BlockMetadataManager metaManager) throws IOException { BlockMetadataManager metaManager) throws IOException {
// reassure the plan is feasible: enough free space to satisfy bytesToBeAvailable, and enough // reassure the plan is feasible: enough free space to satisfy bytesToBeAvailable, and enough
Expand Down Expand Up @@ -80,24 +85,28 @@ public static boolean validCascadingPlan(long bytesToBeAvailable, EvictionPlan p
} }
} }


int firstTierAlias = Integer.MAX_VALUE; // the top tier among all tiers where blocks in the plan reside in
int topTierAlias = Integer.MAX_VALUE;
for (StorageDir dir : spaceInfoInDir.keySet()) { for (StorageDir dir : spaceInfoInDir.keySet()) {
firstTierAlias = Math.min(firstTierAlias, dir.getParentTier().getTierAlias()); topTierAlias = Math.min(topTierAlias, dir.getParentTier().getTierAlias());
} }
long maxSpace = Long.MIN_VALUE; // maximum bytes to be available in a dir in the first tier long maxSpace = Long.MIN_VALUE; // maximum bytes to be available in a dir in the top tier
for (StorageDir dir : spaceInfoInDir.keySet()) { for (StorageDir dir : spaceInfoInDir.keySet()) {
if (dir.getParentTier().getTierAlias() == firstTierAlias) { if (dir.getParentTier().getTierAlias() == topTierAlias) {
Pair<Long, Long> space = spaceInfoInDir.get(dir); Pair<Long, Long> space = spaceInfoInDir.get(dir);
maxSpace = Math.max(maxSpace, space.getFirst() - space.getSecond()); maxSpace = Math.max(maxSpace, space.getFirst() - space.getSecond());
} }
} }
if (maxSpace < bytesToBeAvailable) { if (maxSpace < bytesToBeAvailable) {
// plan is invalid because requested space can not be satisfied in the top tier
return false; return false;
} }


for (StorageDir dir : spaceInfoInDir.keySet()) { for (StorageDir dir : spaceInfoInDir.keySet()) {
Pair<Long, Long> spaceInfo = spaceInfoInDir.get(dir); Pair<Long, Long> spaceInfo = spaceInfoInDir.get(dir);
if (spaceInfo.getFirst() < spaceInfo.getSecond()) { if (spaceInfo.getFirst() < spaceInfo.getSecond()) {
// plan is invalid because there is not enough space in this dir to hold the blocks waiting
// to be moved into this dir
return false; return false;
} }
} }
Expand Down

0 comments on commit 9d11ce3

Please sign in to comment.