Skip to content

Commit

Permalink
[SMALLFIX] Simplify return type of getBlockIterator
Browse files Browse the repository at this point in the history
  • Loading branch information
aaudiber committed Oct 10, 2015
1 parent fb3a3e4 commit 8a0a436
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
Expand Up @@ -18,16 +18,15 @@
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;


import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;


import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;


import tachyon.Constants; import tachyon.Constants;
import tachyon.collections.Pair;
import tachyon.Sessions; import tachyon.Sessions;
import tachyon.collections.Pair;
import tachyon.exception.BlockDoesNotExistException; import tachyon.exception.BlockDoesNotExistException;
import tachyon.worker.block.BlockMetadataManagerView; import tachyon.worker.block.BlockMetadataManagerView;
import tachyon.worker.block.BlockStoreEventListenerBase; import tachyon.worker.block.BlockStoreEventListenerBase;
Expand Down Expand Up @@ -84,9 +83,9 @@ protected StorageDirView cascadingEvict(long bytesToBeAvailable, BlockStoreLocat
// 2. Iterate over blocks in order until we find a StorageDirView that is in the range of // 2. Iterate over blocks in order until we find a StorageDirView that is in the range of
// location and can satisfy bytesToBeAvailable after evicting its blocks iterated so far // location and can satisfy bytesToBeAvailable after evicting its blocks iterated so far
EvictionDirCandidates dirCandidates = new EvictionDirCandidates(); EvictionDirCandidates dirCandidates = new EvictionDirCandidates();
Iterator<Map.Entry<Long, Object>> it = getBlockIterator(); Iterator<Long> it = getBlockIterator();
while (it.hasNext() && dirCandidates.candidateSize() < bytesToBeAvailable) { while (it.hasNext() && dirCandidates.candidateSize() < bytesToBeAvailable) {
long blockId = it.next().getKey(); long blockId = it.next();
try { try {
BlockMeta block = mManagerView.getBlockMeta(blockId); BlockMeta block = mManagerView.getBlockMeta(blockId);
if (block != null) { // might not present in this view if (block != null) { // might not present in this view
Expand Down Expand Up @@ -183,12 +182,11 @@ public EvictionPlan freeSpaceWithView(long bytesToBeAvailable, BlockStoreLocatio
} }


/** /**
* @return an iterator over the blocks in the evictor cache. The evictor is responsible for * @return an iterator over the IDs of the blocks in the evictor cache. The evictor is responsible
* specifying the iteration order using its own strategy. For example, LRUEvictor returns an * for specifying the iteration order using its own strategy. For example, LRUEvictor returns an
* iterator that iterates the blocks in LRU order. The key of the map entry is the block Id. * iterator that iterates through the block IDs in LRU order.
*/ */
// TODO(calvin): Is a key iterator sufficient? protected abstract Iterator<Long> getBlockIterator();
protected abstract Iterator<Map.Entry<Long, Object>> getBlockIterator();


/** /**
* Perform additional cleanup when a block is removed from the iterator returned by * Perform additional cleanup when a block is removed from the iterator returned by
Expand Down
Expand Up @@ -25,7 +25,9 @@
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;


import com.google.common.base.Function;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.Iterators;


import tachyon.Constants; import tachyon.Constants;
import tachyon.collections.Pair; import tachyon.collections.Pair;
Expand Down Expand Up @@ -123,8 +125,14 @@ public EvictionPlan freeSpaceWithView(long bytesToBeAvailable, BlockStoreLocatio
} }


@Override @Override
protected Iterator<Map.Entry<Long, Object>> getBlockIterator() { protected Iterator<Long> getBlockIterator() {
return (Iterator) getSortedCRF().iterator(); return Iterators.transform(getSortedCRF().iterator(),
new Function<Map.Entry<Long, Double>, Long>() {
@Override
public Long apply(Entry<Long, Double> input) {
return input.getKey();
}
});
} }


/** /**
Expand Down
Expand Up @@ -60,8 +60,8 @@ public LRUEvictor(BlockMetadataManagerView view, Allocator allocator) {
} }


@Override @Override
protected Iterator<Map.Entry<Long, Object>> getBlockIterator() { protected Iterator<Long> getBlockIterator() {
return (Iterator) mLRUCache.entrySet().iterator(); return mLRUCache.keySet().iterator();
} }


@Override @Override
Expand Down

0 comments on commit 8a0a436

Please sign in to comment.