use of alluxio.collections.Pair in project alluxio by Alluxio.
the class AbstractEvictor method freeSpaceWithView.
@Override
public EvictionPlan freeSpaceWithView(long bytesToBeAvailable, BlockStoreLocation location, BlockMetadataManagerView view) {
mManagerView = view;
List<BlockTransferInfo> toMove = new ArrayList<>();
List<Pair<Long, BlockStoreLocation>> toEvict = new ArrayList<>();
EvictionPlan plan = new EvictionPlan(toMove, toEvict);
StorageDirView candidateDir = cascadingEvict(bytesToBeAvailable, location, plan);
mManagerView.clearBlockMarks();
if (candidateDir == null) {
return null;
}
return plan;
}
use of alluxio.collections.Pair in project alluxio by Alluxio.
the class LRFUEvictor method freeSpaceWithView.
@Override
public EvictionPlan freeSpaceWithView(long bytesToBeAvailable, BlockStoreLocation location, BlockMetadataManagerView view) {
synchronized (mBlockIdToLastUpdateTime) {
updateCRFValue();
mManagerView = view;
List<BlockTransferInfo> toMove = new ArrayList<>();
List<Pair<Long, BlockStoreLocation>> toEvict = new ArrayList<>();
EvictionPlan plan = new EvictionPlan(toMove, toEvict);
StorageDirView candidateDir = cascadingEvict(bytesToBeAvailable, location, plan);
mManagerView.clearBlockMarks();
if (candidateDir == null) {
return null;
}
return plan;
}
}
use of alluxio.collections.Pair in project alluxio by Alluxio.
the class EvictorTestUtils method validCascadingPlan.
/**
* Checks whether the plan of a cascading evictor is valid.
*
* 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 plan the eviction plan, should not be empty
* @param metaManager the metadata manager
* @return true if the above requirements are satisfied, otherwise false
* @throws BlockDoesNotExistException if a block for which metadata cannot be found is encountered
*/
// TODO(bin): Add a unit test for this method.
public static boolean validCascadingPlan(long bytesToBeAvailable, EvictionPlan plan, BlockMetadataManager metaManager) throws BlockDoesNotExistException {
// reassure the plan is feasible: enough free space to satisfy bytesToBeAvailable, and enough
// space in lower tier to move blocks in upper tier there
// Map from dir to a pair of bytes to be available in this dir and bytes to move into this dir
// after the plan taking action
Map<StorageDir, Pair<Long, Long>> spaceInfoInDir = new HashMap<>();
for (Pair<Long, BlockStoreLocation> blockInfo : plan.toEvict()) {
BlockMeta block = metaManager.getBlockMeta(blockInfo.getFirst());
StorageDir dir = block.getParentDir();
if (spaceInfoInDir.containsKey(dir)) {
Pair<Long, Long> spaceInfo = spaceInfoInDir.get(dir);
spaceInfo.setFirst(spaceInfo.getFirst() + block.getBlockSize());
} else {
spaceInfoInDir.put(dir, new Pair<>(dir.getAvailableBytes() + block.getBlockSize(), 0L));
}
}
for (BlockTransferInfo move : plan.toMove()) {
long blockId = move.getBlockId();
BlockMeta block = metaManager.getBlockMeta(blockId);
long blockSize = block.getBlockSize();
StorageDir srcDir = block.getParentDir();
StorageDir destDir = metaManager.getDir(move.getDstLocation());
if (spaceInfoInDir.containsKey(srcDir)) {
Pair<Long, Long> spaceInfo = spaceInfoInDir.get(srcDir);
spaceInfo.setFirst(spaceInfo.getFirst() + blockSize);
} else {
spaceInfoInDir.put(srcDir, new Pair<>(srcDir.getAvailableBytes() + blockSize, 0L));
}
if (spaceInfoInDir.containsKey(destDir)) {
Pair<Long, Long> spaceInfo = spaceInfoInDir.get(destDir);
spaceInfo.setSecond(spaceInfo.getSecond() + blockSize);
} else {
spaceInfoInDir.put(destDir, new Pair<>(destDir.getAvailableBytes(), blockSize));
}
}
// the top tier among all tiers where blocks in the plan reside in
int topTierOrdinal = Integer.MAX_VALUE;
for (StorageDir dir : spaceInfoInDir.keySet()) {
topTierOrdinal = Math.min(topTierOrdinal, dir.getParentTier().getTierOrdinal());
}
// maximum bytes to be available in a dir in the top tier
long maxSpace = Long.MIN_VALUE;
for (StorageDir dir : spaceInfoInDir.keySet()) {
if (dir.getParentTier().getTierOrdinal() == topTierOrdinal) {
Pair<Long, Long> space = spaceInfoInDir.get(dir);
maxSpace = Math.max(maxSpace, space.getFirst() - space.getSecond());
}
}
if (maxSpace < bytesToBeAvailable) {
// plan is invalid because requested space can not be satisfied in the top tier
return false;
}
for (StorageDir dir : spaceInfoInDir.keySet()) {
Pair<Long, Long> spaceInfo = spaceInfoInDir.get(dir);
if (spaceInfo.getFirst() < spaceInfo.getSecond()) {
// to be moved into this dir
return false;
}
}
return true;
}
use of alluxio.collections.Pair in project alluxio by Alluxio.
the class BlockStoreMetaTest method getUsedBytesOnDirs.
/**
* Tests the {@link BlockStoreMeta#getUsedBytesOnDirs()} method.
*/
@Test
public void getUsedBytesOnDirs() {
Map<Pair<String, String>, Long> dirsToUsedBytes = new HashMap<>();
for (StorageTier tier : mMetadataManager.getTiers()) {
for (StorageDir dir : tier.getStorageDirs()) {
dirsToUsedBytes.put(new Pair<>(tier.getTierAlias(), dir.getDirPath()), dir.getCapacityBytes() - dir.getAvailableBytes());
}
}
Assert.assertEquals(dirsToUsedBytes, mBlockStoreMeta.getUsedBytesOnDirs());
}
use of alluxio.collections.Pair in project alluxio by Alluxio.
the class MasterFaultToleranceIntegrationTest method killStandby.
@Test
public void killStandby() throws Exception {
// If standby masters are killed(or node failure), current leader should not be affected and the
// cluster should run properly.
int leaderIndex = mMultiMasterLocalAlluxioCluster.getLeaderIndex();
Assert.assertNotEquals(-1, leaderIndex);
List<Pair<Long, AlluxioURI>> answer = new ArrayList<>();
for (int k = 0; k < 5; k++) {
faultTestDataCreation(new AlluxioURI("/data" + k), answer);
}
faultTestDataCheck(answer);
for (int kills = 0; kills < MASTERS - 1; kills++) {
Assert.assertTrue(mMultiMasterLocalAlluxioCluster.stopStandby());
CommonUtils.sleepMs(Constants.SECOND_MS * 2);
// Leader should not change.
Assert.assertEquals(leaderIndex, mMultiMasterLocalAlluxioCluster.getLeaderIndex());
// Cluster should still work.
faultTestDataCheck(answer);
faultTestDataCreation(new AlluxioURI("/data_kills_" + kills), answer);
}
}
Aggregations