Search in sources :

Example 1 with Pair

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;
}
Also used : ArrayList(java.util.ArrayList) StorageDirView(alluxio.worker.block.meta.StorageDirView) Pair(alluxio.collections.Pair)

Example 2 with Pair

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;
    }
}
Also used : ArrayList(java.util.ArrayList) StorageDirView(alluxio.worker.block.meta.StorageDirView) Pair(alluxio.collections.Pair)

Example 3 with Pair

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;
}
Also used : HashMap(java.util.HashMap) StorageDir(alluxio.worker.block.meta.StorageDir) BlockStoreLocation(alluxio.worker.block.BlockStoreLocation) BlockMeta(alluxio.worker.block.meta.BlockMeta) Pair(alluxio.collections.Pair)

Example 4 with Pair

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());
}
Also used : HashMap(java.util.HashMap) StorageTier(alluxio.worker.block.meta.StorageTier) StorageDir(alluxio.worker.block.meta.StorageDir) Pair(alluxio.collections.Pair) Test(org.junit.Test)

Example 5 with Pair

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);
    }
}
Also used : ArrayList(java.util.ArrayList) Pair(alluxio.collections.Pair) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Aggregations

Pair (alluxio.collections.Pair)11 ArrayList (java.util.ArrayList)6 AlluxioURI (alluxio.AlluxioURI)5 Test (org.junit.Test)5 HashMap (java.util.HashMap)4 StorageDir (alluxio.worker.block.meta.StorageDir)3 StorageDirView (alluxio.worker.block.meta.StorageDirView)3 Mode (alluxio.security.authorization.Mode)2 MkdirsOptions (alluxio.underfs.options.MkdirsOptions)2 BlockStoreLocation (alluxio.worker.block.BlockStoreLocation)2 BlockMeta (alluxio.worker.block.meta.BlockMeta)2 StorageTier (alluxio.worker.block.meta.StorageTier)2 IOException (java.io.IOException)2 Stack (java.util.Stack)2 URIStatus (alluxio.client.file.URIStatus)1 AccessControlException (alluxio.exception.AccessControlException)1 AlluxioException (alluxio.exception.AlluxioException)1 BlockInfoException (alluxio.exception.BlockInfoException)1 DirectoryNotEmptyException (alluxio.exception.DirectoryNotEmptyException)1 FileAlreadyCompletedException (alluxio.exception.FileAlreadyCompletedException)1