Search in sources :

Example 6 with StorageDirView

use of alluxio.worker.block.meta.StorageDirView 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 7 with StorageDirView

use of alluxio.worker.block.meta.StorageDirView in project alluxio by Alluxio.

the class TieredBlockStore method createBlockMetaInternal.

/**
   * Creates a temp block meta only if allocator finds available space. This method will not trigger
   * any eviction.
   *
   * @param sessionId session Id
   * @param blockId block Id
   * @param location location to create the block
   * @param initialBlockSize initial block size in bytes
   * @param newBlock true if this temp block is created for a new block
   * @return a temp block created if successful, or null if allocation failed (instead of throwing
   *         {@link WorkerOutOfSpaceException} because allocation failure could be an expected case)
   * @throws BlockAlreadyExistsException if there is already a block with the same block id
   */
private TempBlockMeta createBlockMetaInternal(long sessionId, long blockId, BlockStoreLocation location, long initialBlockSize, boolean newBlock) throws BlockAlreadyExistsException {
    // block lock here since no sharing
    try (LockResource r = new LockResource(mMetadataWriteLock)) {
        if (newBlock) {
            checkTempBlockIdAvailable(blockId);
        }
        StorageDirView dirView = mAllocator.allocateBlockWithView(sessionId, initialBlockSize, location, getUpdatedView());
        if (dirView == null) {
            // Allocator fails to find a proper place for this new block.
            return null;
        }
        // TODO(carson): Add tempBlock to corresponding storageDir and remove the use of
        // StorageDirView.createTempBlockMeta.
        TempBlockMeta tempBlock = dirView.createTempBlockMeta(sessionId, blockId, initialBlockSize);
        try {
            // Add allocated temp block to metadata manager. This should never fail if allocator
            // correctly assigns a StorageDir.
            mMetaManager.addTempBlockMeta(tempBlock);
        } catch (WorkerOutOfSpaceException | BlockAlreadyExistsException e) {
            // If we reach here, allocator is not working properly
            LOG.error("Unexpected failure: {} bytes allocated at {} by allocator, " + "but addTempBlockMeta failed", initialBlockSize, location);
            throw Throwables.propagate(e);
        }
        return tempBlock;
    }
}
Also used : BlockAlreadyExistsException(alluxio.exception.BlockAlreadyExistsException) LockResource(alluxio.resource.LockResource) StorageDirView(alluxio.worker.block.meta.StorageDirView) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta) WorkerOutOfSpaceException(alluxio.exception.WorkerOutOfSpaceException)

Example 8 with StorageDirView

use of alluxio.worker.block.meta.StorageDirView in project alluxio by Alluxio.

the class TieredBlockStore method requestSpace.

@Override
public void requestSpace(long sessionId, long blockId, long additionalBytes) throws BlockDoesNotExistException, WorkerOutOfSpaceException, IOException {
    LOG.debug("requestSpace: sessionId={}, blockId={}, additionalBytes={}", sessionId, blockId, additionalBytes);
    if (additionalBytes <= 0) {
        return;
    }
    // block lock here since no sharing
    try (LockResource r = new LockResource(mMetadataWriteLock)) {
        TempBlockMeta tempBlockMeta = mMetaManager.getTempBlockMeta(blockId);
        StorageDirView allocationDir = allocateSpace(sessionId, AllocateOptions.forRequestSpace(additionalBytes, tempBlockMeta.getBlockLocation()));
        if (!allocationDir.toBlockStoreLocation().equals(tempBlockMeta.getBlockLocation())) {
            // If reached here, allocateSpace() failed to enforce 'forceLocation' flag.
            throw new IllegalStateException(String.format("Allocation error: location enforcement failed for location: %s", allocationDir.toBlockStoreLocation()));
        }
        // Increase the size of this temp block
        try {
            mMetaManager.resizeTempBlockMeta(tempBlockMeta, tempBlockMeta.getBlockSize() + additionalBytes);
        } catch (InvalidWorkerStateException e) {
            // we shall never reach here
            throw Throwables.propagate(e);
        }
    }
}
Also used : LockResource(alluxio.resource.LockResource) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta) StorageDirView(alluxio.worker.block.meta.StorageDirView) InvalidWorkerStateException(alluxio.exception.InvalidWorkerStateException)

Example 9 with StorageDirView

use of alluxio.worker.block.meta.StorageDirView in project alluxio by Alluxio.

the class MaxFreeAllocator method allocateBlock.

/**
 * Allocates a block from the given block store location. The location can be a specific location,
 * or {@link BlockStoreLocation#anyTier()} or {@link BlockStoreLocation#anyDirInTier(String)}.
 *
 * @param sessionId the id of session to apply for the block allocation
 * @param blockSize the size of block in bytes
 * @param location the location in block store
 * @param skipReview whether the review should be skipped
 * @return a {@link StorageDirView} in which to create the temp block meta if success,
 *         null otherwise
 */
private StorageDirView allocateBlock(long sessionId, long blockSize, BlockStoreLocation location, boolean skipReview) {
    Preconditions.checkNotNull(location, "location");
    StorageDirView candidateDirView = null;
    if (location.equals(BlockStoreLocation.anyTier())) {
        for (StorageTierView tierView : mMetadataView.getTierViews()) {
            candidateDirView = getCandidateDirInTier(tierView, blockSize, BlockStoreLocation.ANY_MEDIUM);
            if (candidateDirView != null) {
                if (skipReview || mReviewer.acceptAllocation(candidateDirView)) {
                    break;
                }
                // We tried the dir on this tier with max free bytes but that is not good enough.
                // So we move on to the lower tier.
                LOG.debug("Allocation rejected for anyTier: {}", candidateDirView.toBlockStoreLocation());
            }
        }
    } else if (location.equals(BlockStoreLocation.anyDirInTier(location.tierAlias()))) {
        StorageTierView tierView = mMetadataView.getTierView(location.tierAlias());
        candidateDirView = getCandidateDirInTier(tierView, blockSize, BlockStoreLocation.ANY_MEDIUM);
        if (candidateDirView != null) {
            // The allocation is not good enough. Revert it.
            if (!skipReview && !mReviewer.acceptAllocation(candidateDirView)) {
                LOG.debug("Allocation rejected for anyDirInTier: {}", candidateDirView.toBlockStoreLocation());
                candidateDirView = null;
            }
        }
    } else if (location.equals(BlockStoreLocation.anyDirInAnyTierWithMedium(location.mediumType()))) {
        for (StorageTierView tierView : mMetadataView.getTierViews()) {
            candidateDirView = getCandidateDirInTier(tierView, blockSize, location.mediumType());
            if (candidateDirView != null) {
                if (skipReview || mReviewer.acceptAllocation(candidateDirView)) {
                    break;
                }
                // We tried the dir on this tier with max free bytes but that is not good enough.
                // So we move on to the lower tier.
                LOG.debug("Allocation rejected for anyDirInTierWithMedium: {}", candidateDirView.toBlockStoreLocation());
            }
        }
    } else {
        // For allocation in a specific directory, we are not checking the reviewer,
        // because we do not want the reviewer to reject it.
        StorageTierView tierView = mMetadataView.getTierView(location.tierAlias());
        StorageDirView dirView = tierView.getDirView(location.dir());
        if (dirView != null && dirView.getAvailableBytes() >= blockSize) {
            candidateDirView = dirView;
        }
    }
    return candidateDirView;
}
Also used : StorageTierView(alluxio.worker.block.meta.StorageTierView) StorageDirView(alluxio.worker.block.meta.StorageDirView)

Example 10 with StorageDirView

use of alluxio.worker.block.meta.StorageDirView in project alluxio by Alluxio.

the class GreedyAllocator method allocateBlock.

/**
 * Allocates a block from the given block store location. The location can be a specific location,
 * or {@link BlockStoreLocation#anyTier()} or {@link BlockStoreLocation#anyDirInTier(String)}.
 *
 * @param sessionId the id of session to apply for the block allocation
 * @param blockSize the size of block in bytes
 * @param location the location in block store
 * @return a {@link StorageDirView} in which to create the temp block meta if success,
 *         null otherwise
 */
@Nullable
private StorageDirView allocateBlock(long sessionId, long blockSize, BlockStoreLocation location, boolean skipReview) {
    Preconditions.checkNotNull(location, "location");
    if (location.equals(BlockStoreLocation.anyTier())) {
        // and return a temp block meta from the first available dirview.
        for (StorageTierView tierView : mMetadataView.getTierViews()) {
            for (StorageDirView dirView : tierView.getDirViews()) {
                if (dirView.getAvailableBytes() >= blockSize) {
                    if (skipReview || mReviewer.acceptAllocation(dirView)) {
                        return dirView;
                    } else {
                        // The allocation is rejected. Try the next dir.
                        LOG.debug("Allocation rejected for anyTier: {}", dirView.toBlockStoreLocation());
                    }
                }
            }
        }
        return null;
    }
    String mediumType = location.mediumType();
    if (!mediumType.equals(BlockStoreLocation.ANY_MEDIUM) && location.equals(BlockStoreLocation.anyDirInAnyTierWithMedium(mediumType))) {
        for (StorageTierView tierView : mMetadataView.getTierViews()) {
            for (StorageDirView dirView : tierView.getDirViews()) {
                if (dirView.getMediumType().equals(mediumType) && dirView.getAvailableBytes() >= blockSize) {
                    if (skipReview || mReviewer.acceptAllocation(dirView)) {
                        return dirView;
                    } else {
                        // Try the next dir
                        LOG.debug("Allocation rejected for anyDirInTierWithMedium: {}", dirView.toBlockStoreLocation());
                    }
                }
            }
        }
        return null;
    }
    String tierAlias = location.tierAlias();
    StorageTierView tierView = mMetadataView.getTierView(tierAlias);
    if (location.equals(BlockStoreLocation.anyDirInTier(tierAlias))) {
        // Loop over all dir views in the given tier
        for (StorageDirView dirView : tierView.getDirViews()) {
            if (dirView.getAvailableBytes() >= blockSize) {
                if (skipReview || mReviewer.acceptAllocation(dirView)) {
                    return dirView;
                } else {
                    // Try the next dir
                    LOG.debug("Allocation rejected for anyDirInTier: {}", dirView.toBlockStoreLocation());
                }
            }
        }
        return null;
    }
    // For allocation in a specific directory, we are not checking the reviewer,
    // because we do not want the reviewer to reject it.
    int dirIndex = location.dir();
    StorageDirView dirView = tierView.getDirView(dirIndex);
    if (dirView != null && dirView.getAvailableBytes() >= blockSize) {
        return dirView;
    }
    return null;
}
Also used : StorageTierView(alluxio.worker.block.meta.StorageTierView) StorageDirView(alluxio.worker.block.meta.StorageDirView) Nullable(javax.annotation.Nullable)

Aggregations

StorageDirView (alluxio.worker.block.meta.StorageDirView)33 StorageTierView (alluxio.worker.block.meta.StorageTierView)15 BlockStoreLocation (alluxio.worker.block.BlockStoreLocation)6 BlockMeta (alluxio.worker.block.meta.BlockMeta)6 TempBlockMeta (alluxio.worker.block.meta.TempBlockMeta)6 BlockDoesNotExistException (alluxio.exception.BlockDoesNotExistException)5 Pair (alluxio.collections.Pair)4 WorkerOutOfSpaceException (alluxio.exception.WorkerOutOfSpaceException)4 LockResource (alluxio.resource.LockResource)3 StorageDirEvictorView (alluxio.worker.block.meta.StorageDirEvictorView)3 ArrayList (java.util.ArrayList)3 Nullable (javax.annotation.Nullable)3 BlockAlreadyExistsException (alluxio.exception.BlockAlreadyExistsException)2 BlockTransferInfo (alluxio.worker.block.evictor.BlockTransferInfo)2 LinkedList (java.util.LinkedList)2 StorageTierAssoc (alluxio.StorageTierAssoc)1 InvalidWorkerStateException (alluxio.exception.InvalidWorkerStateException)1 DefaultBlockMeta (alluxio.worker.block.meta.DefaultBlockMeta)1 StorageDir (alluxio.worker.block.meta.StorageDir)1 StorageTier (alluxio.worker.block.meta.StorageTier)1