use of alluxio.resource.LockResource in project alluxio by Alluxio.
the class ScheduledTimer method schedule.
/**
* Schedules execution of the heartbeat.
*/
protected void schedule() {
try (LockResource r = new LockResource(mLock)) {
Preconditions.checkState(!mScheduled, "Called schedule twice without waiting for any ticks");
mScheduled = true;
mTickCondition.signal();
HeartbeatScheduler.removeTimer(this);
}
}
use of alluxio.resource.LockResource in project alluxio by Alluxio.
the class TieredBlockStore method lockBlockNoException.
@Override
public long lockBlockNoException(long sessionId, long blockId) {
long lockId = mLockManager.lockBlock(sessionId, blockId, BlockLockType.READ);
boolean hasBlock;
try (LockResource r = new LockResource(mMetadataReadLock)) {
hasBlock = mMetaManager.hasBlockMeta(blockId);
}
if (hasBlock) {
return lockId;
}
mLockManager.unlockBlockNoException(lockId);
return BlockLockManager.INVALID_LOCK_ID;
}
use of alluxio.resource.LockResource 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.resource.LockResource in project alluxio by Alluxio.
the class TieredBlockStore method lockBlock.
@Override
public long lockBlock(long sessionId, long blockId) throws BlockDoesNotExistException {
long lockId = mLockManager.lockBlock(sessionId, blockId, BlockLockType.READ);
boolean hasBlock;
try (LockResource r = new LockResource(mMetadataReadLock)) {
hasBlock = mMetaManager.hasBlockMeta(blockId);
}
if (hasBlock) {
return lockId;
}
mLockManager.unlockBlock(lockId);
throw new BlockDoesNotExistException(ExceptionMessage.NO_BLOCK_ID_FOUND, blockId);
}
use of alluxio.resource.LockResource in project alluxio by Alluxio.
the class MountTable method resolve.
/**
* Resolves the given Alluxio path. If the given Alluxio path is nested under a mount point, the
* resolution maps the Alluxio path to the corresponding UFS path. Otherwise, the resolution is a
* no-op.
*
* @param uri an Alluxio path URI
* @return the {@link Resolution} representing the UFS path
* @throws InvalidPathException if an invalid path is encountered
*/
public Resolution resolve(AlluxioURI uri) throws InvalidPathException {
try (LockResource r = new LockResource(mReadLock)) {
String path = uri.getPath();
LOG.debug("Resolving {}", path);
// This will re-acquire the read lock, but that is allowed.
String mountPoint = getMountPoint(uri);
if (mountPoint != null) {
MountInfo info = mMountTable.get(mountPoint);
AlluxioURI ufsUri = info.getUfsUri();
// TODO(gpang): this ufs should probably be cached.
UnderFileSystem ufs = UnderFileSystem.Factory.get(ufsUri.toString());
ufs.setProperties(info.getOptions().getProperties());
AlluxioURI resolvedUri = ufs.resolveUri(ufsUri, path.substring(mountPoint.length()));
return new Resolution(resolvedUri, ufs, info.getOptions().isShared());
}
return new Resolution(uri, null, false);
}
}
Aggregations