Search in sources :

Example 6 with LockResource

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);
    }
}
Also used : LockResource(alluxio.resource.LockResource)

Example 7 with LockResource

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;
}
Also used : LockResource(alluxio.resource.LockResource)

Example 8 with LockResource

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;
    }
}
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 9 with LockResource

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);
}
Also used : LockResource(alluxio.resource.LockResource) BlockDoesNotExistException(alluxio.exception.BlockDoesNotExistException)

Example 10 with LockResource

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);
    }
}
Also used : LockResource(alluxio.resource.LockResource) MountInfo(alluxio.master.file.meta.options.MountInfo) UnderFileSystem(alluxio.underfs.UnderFileSystem) AlluxioURI(alluxio.AlluxioURI)

Aggregations

LockResource (alluxio.resource.LockResource)19 BlockDoesNotExistException (alluxio.exception.BlockDoesNotExistException)7 TempBlockMeta (alluxio.worker.block.meta.TempBlockMeta)6 BlockAlreadyExistsException (alluxio.exception.BlockAlreadyExistsException)5 WorkerOutOfSpaceException (alluxio.exception.WorkerOutOfSpaceException)5 InvalidWorkerStateException (alluxio.exception.InvalidWorkerStateException)4 MountInfo (alluxio.master.file.meta.options.MountInfo)4 HashMap (java.util.HashMap)3 AlluxioURI (alluxio.AlluxioURI)2 BlockMeta (alluxio.worker.block.meta.BlockMeta)2 Map (java.util.Map)2 AccessControlException (alluxio.exception.AccessControlException)1 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)1 InvalidPathException (alluxio.exception.InvalidPathException)1 UnderFileSystem (alluxio.underfs.UnderFileSystem)1 BlockTransferInfo (alluxio.worker.block.evictor.BlockTransferInfo)1 EvictionPlan (alluxio.worker.block.evictor.EvictionPlan)1 StorageDirView (alluxio.worker.block.meta.StorageDirView)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1