Skip to content

Commit

Permalink
Update javadoc and code for evictor
Browse files Browse the repository at this point in the history
  • Loading branch information
apc999 authored and calvinjia committed Jun 27, 2015
1 parent ad792e5 commit b542a18
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
14 changes: 8 additions & 6 deletions servers/src/main/java/tachyon/worker/block/evictor/Evictor.java
Expand Up @@ -24,13 +24,15 @@
*/
public interface Evictor {
/**
* Frees space in the given block store location. The location can be a specific location, or
* {@link BlockStoreLocation#anyTier()} or {@link BlockStoreLocation#anyDirInTier(int)}. Return
* absent if Evictor can not propose such a feasible plan to meet the requirement.
* Frees space in the given block store location to ensure a specific amount of free space
* available. The location can be a specific location, or {@link BlockStoreLocation#anyTier()} or
* {@link BlockStoreLocation#anyDirInTier(int)}. This operation returns absent if Evictor fails to
* propose a feasible plan to meet its requirement, or an eviction plan (possibly an empty one) to
* ensure the free space.
*
* @param bytes the size in bytes
* @param availableBytes the size in bytes
* @param location the location in block store
* @return an eviction plan to achieve the freed space, or absent if no feasible plan
* @return an eviction plan (possibly empty) to get the free space, or absent if no feasible plan
*/
Optional<EvictionPlan> freeSpace(long bytes, BlockStoreLocation location);
Optional<EvictionPlan> freeSpace(long availableBytes, BlockStoreLocation location);
}
Expand Up @@ -40,18 +40,24 @@ public NaiveEvictor(BlockMetadataManager metadata) {
}

@Override
public Optional<EvictionPlan> freeSpace(long bytes, BlockStoreLocation location) {
public Optional<EvictionPlan> freeSpace(long availableBytes, BlockStoreLocation location) {
List<Pair<Long, BlockStoreLocation>> toMove = new ArrayList<Pair<Long, BlockStoreLocation>>();
List<Long> toEvict = new ArrayList<Long>();

long spaceFreed = 0;
long freed = 0;
long available = mMetaManager.getAvailableBytes(location);
if (available >= availableBytes) {
// The current space is sufficient, no need for eviction
return Optional.of(new EvictionPlan(toMove, toEvict));
}

if (location.equals(BlockStoreLocation.anyTier())) {
for (StorageTier tier : mMetaManager.getTiers()) {
for (StorageDir dir : tier.getStorageDirs()) {
for (BlockMeta block : dir.getBlocks()) {
toEvict.add(block.getBlockId());
spaceFreed += block.getBlockSize();
if (spaceFreed >= bytes) {
freed += block.getBlockSize();
if (available + freed >= availableBytes) {
return Optional.of(new EvictionPlan(toMove, toEvict));
}
}
Expand All @@ -67,8 +73,8 @@ public Optional<EvictionPlan> freeSpace(long bytes, BlockStoreLocation location)
for (StorageDir dir : tier.getStorageDirs()) {
for (BlockMeta block : dir.getBlocks()) {
toEvict.add(block.getBlockId());
spaceFreed += block.getBlockSize();
if (spaceFreed >= bytes) {
freed += block.getBlockSize();
if (available + freed >= availableBytes) {
return Optional.of(new EvictionPlan(toMove, toEvict));
}
}
Expand All @@ -80,8 +86,8 @@ public Optional<EvictionPlan> freeSpace(long bytes, BlockStoreLocation location)
StorageDir dir = tier.getDir(dirIndex);
for (BlockMeta block : dir.getBlocks()) {
toEvict.add(block.getBlockId());
spaceFreed += block.getBlockSize();
if (spaceFreed >= bytes) {
freed += block.getBlockSize();
if (available + freed >= availableBytes) {
return Optional.of(new EvictionPlan(toMove, toEvict));
}
}
Expand Down

0 comments on commit b542a18

Please sign in to comment.