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;
}
}
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;
}
}
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);
}
}
}
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;
}
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;
}
Aggregations