// size, return the Pair of StorageDir and blockInfoList
while (true) {
// Get oldest block in StorageDir candidates
Pair<StorageDir, Long> candidate =
getLRUBlockCandidate(storageDirs, dir2LRUBlocks, dir2BlocksToEvict, pinList);
StorageDir dirCandidate = candidate.getFirst();
long blockId = candidate.getSecond();
long blockSize = 0;
if (dirCandidate == null) {
return null;
} else {
blockSize = dirCandidate.getBlockSize(blockId);
}
// Add info of the block to the list
blockInfoList.add(new BlockInfo(dirCandidate, blockId, blockSize));
dir2BlocksToEvict.put(dirCandidate, blockId);
dir2LRUBlocks.remove(dirCandidate);
long evictionSize;
// Update eviction size for this StorageDir
if (sizeToEvict.containsKey(dirCandidate)) {
evictionSize = sizeToEvict.get(dirCandidate) + blockSize;
} else {
evictionSize = blockSize;
}
sizeToEvict.put(dirCandidate, evictionSize);
if (evictionSize + dirCandidate.getAvailableBytes() >= requestSize) {
return new Pair<StorageDir, List<BlockInfo>>(dirCandidate, blockInfoList);
}
}
}