Search in sources :

Example 1 with LockResource

use of alluxio.resource.LockResource in project alluxio by Alluxio.

the class MountTable method delete.

/**
   * Unmounts the given Alluxio path. The path should match an existing mount point.
   *
   * @param uri an Alluxio path URI
   * @return whether the operation succeeded or not
   */
public boolean delete(AlluxioURI uri) {
    String path = uri.getPath();
    LOG.info("Unmounting {}", path);
    if (path.equals(ROOT)) {
        LOG.warn("Cannot unmount the root mount point.");
        return false;
    }
    try (LockResource r = new LockResource(mWriteLock)) {
        if (mMountTable.containsKey(path)) {
            mMountTable.remove(path);
            return true;
        }
        LOG.warn("Mount point {} does not exist.", path);
        return false;
    }
}
Also used : LockResource(alluxio.resource.LockResource)

Example 2 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 3 with LockResource

use of alluxio.resource.LockResource in project alluxio by Alluxio.

the class AbstractJournalSystem method removeJournalSink.

@Override
public void removeJournalSink(Master master, JournalSink journalSink) {
    try (LockResource r = new LockResource(mSinkLock.writeLock())) {
        Set<JournalSink> sinks = mJournalSinks.get(master.getName());
        if (sinks != null) {
            sinks.remove(journalSink);
            if (sinks.isEmpty()) {
                mJournalSinks.remove(master.getName());
            }
        }
        // Compute the full set of sinks on removal. Simply removing it may be incorrect, if the same
        // sink is associated with other masters.
        mAllJournalSinks.clear();
        for (Set<JournalSink> s : mJournalSinks.values()) {
            mAllJournalSinks.addAll(s);
        }
    }
}
Also used : LockResource(alluxio.resource.LockResource) JournalSink(alluxio.master.journal.sink.JournalSink)

Example 4 with LockResource

use of alluxio.resource.LockResource in project alluxio by Alluxio.

the class DefaultFileSystemMaster method updateMountInternal.

private void updateMountInternal(Supplier<JournalContext> journalContext, LockedInodePath inodePath, AlluxioURI ufsPath, MountInfo mountInfo, MountContext context) throws FileAlreadyExistsException, InvalidPathException, IOException {
    long newMountId = IdUtils.createMountId();
    // lock sync manager to ensure no sync point is added before the mount point is removed
    try (LockResource r = new LockResource(mSyncManager.getLock())) {
        List<AlluxioURI> syncPoints = mSyncManager.getFilterList(mountInfo.getMountId());
        if (syncPoints != null && !syncPoints.isEmpty()) {
            throw new InvalidArgumentException("Updating a mount point with ActiveSync enabled is not" + " supported. Please remove all sync'ed paths from the mount point and try again.");
        }
        AlluxioURI alluxioPath = inodePath.getUri();
        // validate new UFS client before updating the mount table
        mUfsManager.addMount(newMountId, new AlluxioURI(ufsPath.toString()), UnderFileSystemConfiguration.defaults(ServerConfiguration.global()).setReadOnly(context.getOptions().getReadOnly()).setShared(context.getOptions().getShared()).createMountSpecificConf(context.getOptions().getPropertiesMap()));
        prepareForMount(ufsPath, newMountId, context);
        // old ufsClient is removed as part of the mount table update process
        mMountTable.update(journalContext, alluxioPath, newMountId, context.getOptions().build());
    } catch (FileAlreadyExistsException | InvalidPathException | IOException e) {
        // revert everything
        mUfsManager.removeMount(newMountId);
        throw e;
    }
}
Also used : FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) InvalidArgumentException(alluxio.exception.status.InvalidArgumentException) LockResource(alluxio.resource.LockResource) IOException(java.io.IOException) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI)

Example 5 with LockResource

use of alluxio.resource.LockResource in project alluxio by Alluxio.

the class DefaultBlockMaster method workerRegister.

@Override
public void workerRegister(long workerId, List<String> storageTiers, Map<String, Long> totalBytesOnTiers, Map<String, Long> usedBytesOnTiers, Map<BlockLocation, List<Long>> currentBlocksOnLocation, Map<String, StorageList> lostStorage, RegisterWorkerPOptions options) throws NotFoundException {
    MasterWorkerInfo worker = mWorkers.getFirstByField(ID_INDEX, workerId);
    if (worker == null) {
        worker = findUnregisteredWorker(workerId);
    }
    if (worker == null) {
        throw new NotFoundException(ExceptionMessage.NO_WORKER_FOUND.getMessage(workerId));
    }
    // Gather all blocks on this worker.
    int totalSize = currentBlocksOnLocation.values().stream().mapToInt(List::size).sum();
    HashSet<Long> blocks = new HashSet<>(totalSize);
    for (List<Long> blockIds : currentBlocksOnLocation.values()) {
        blocks.addAll(blockIds);
    }
    // Lock all the locks
    try (LockResource r = worker.lockWorkerMeta(EnumSet.of(WorkerMetaLockSection.STATUS, WorkerMetaLockSection.USAGE, WorkerMetaLockSection.BLOCKS), false)) {
        // Detect any lost blocks on this worker.
        Set<Long> removedBlocks = worker.register(mGlobalStorageTierAssoc, storageTiers, totalBytesOnTiers, usedBytesOnTiers, blocks);
        processWorkerRemovedBlocks(worker, removedBlocks, false);
        processWorkerAddedBlocks(worker, currentBlocksOnLocation);
        processWorkerOrphanedBlocks(worker);
        worker.addLostStorage(lostStorage);
    }
    if (options.getConfigsCount() > 0) {
        for (BiConsumer<Address, List<ConfigProperty>> function : mWorkerRegisteredListeners) {
            WorkerNetAddress workerAddress = worker.getWorkerAddress();
            function.accept(new Address(workerAddress.getHost(), workerAddress.getRpcPort()), options.getConfigsList());
        }
    }
    recordWorkerRegistration(workerId);
    // Update the TS at the end of the process
    worker.updateLastUpdatedTimeMs();
    // Invalidate cache to trigger new build of worker info list
    mWorkerInfoCache.invalidate(WORKER_INFO_CACHE_KEY);
    LOG.info("registerWorker(): {}", worker);
}
Also used : Address(alluxio.wire.Address) WorkerNetAddress(alluxio.wire.WorkerNetAddress) NotFoundException(alluxio.exception.status.NotFoundException) LockResource(alluxio.resource.LockResource) WorkerNetAddress(alluxio.wire.WorkerNetAddress) MasterWorkerInfo(alluxio.master.block.meta.MasterWorkerInfo) ArrayList(java.util.ArrayList) StorageList(alluxio.grpc.StorageList) List(java.util.List) ConcurrentHashSet(alluxio.collections.ConcurrentHashSet) HashSet(java.util.HashSet)

Aggregations

LockResource (alluxio.resource.LockResource)116 IOException (java.io.IOException)14 TempBlockMeta (alluxio.worker.block.meta.TempBlockMeta)13 HashMap (java.util.HashMap)12 BlockAlreadyExistsException (alluxio.exception.BlockAlreadyExistsException)11 BlockDoesNotExistException (alluxio.exception.BlockDoesNotExistException)11 Map (java.util.Map)11 AlluxioURI (alluxio.AlluxioURI)10 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)10 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)10 WorkerOutOfSpaceException (alluxio.exception.WorkerOutOfSpaceException)9 ArrayList (java.util.ArrayList)9 MasterWorkerInfo (alluxio.master.block.meta.MasterWorkerInfo)8 InvalidPathException (alluxio.exception.InvalidPathException)7 NotFoundException (alluxio.exception.status.NotFoundException)7 List (java.util.List)7 Lock (java.util.concurrent.locks.Lock)7 ConcurrentHashSet (alluxio.collections.ConcurrentHashSet)6 InvalidWorkerStateException (alluxio.exception.InvalidWorkerStateException)6 UnavailableException (alluxio.exception.status.UnavailableException)6