Search in sources :

Example 21 with BlockDoesNotExistException

use of alluxio.exception.BlockDoesNotExistException in project alluxio by Alluxio.

the class FileDataManagerTest method lockBlocksErrorHandling.

/**
   * Tests the blocks are unlocked correctly when exception is encountered in
   * {@link FileDataManager#lockBlocks(long, List)}.
   */
@Test
public void lockBlocksErrorHandling() throws Exception {
    long fileId = 1;
    List<Long> blockIds = Lists.newArrayList(1L, 2L, 3L);
    Mockito.when(mBlockWorker.lockBlock(Sessions.CHECKPOINT_SESSION_ID, 1L)).thenReturn(1L);
    Mockito.when(mBlockWorker.lockBlock(Sessions.CHECKPOINT_SESSION_ID, 2L)).thenReturn(2L);
    Mockito.when(mBlockWorker.lockBlock(Sessions.CHECKPOINT_SESSION_ID, 3L)).thenThrow(new BlockDoesNotExistException("block 3 does not exist"));
    try {
        mManager.lockBlocks(fileId, blockIds);
        Assert.fail("the lock should fail");
    } catch (IOException e) {
        assertEquals("failed to lock all blocks of file 1\n" + "alluxio.exception.BlockDoesNotExistException: block 3 does not exist\n", e.getMessage());
        // verify the locks are all unlocked
        Mockito.verify(mBlockWorker).unlockBlock(1L);
        Mockito.verify(mBlockWorker).unlockBlock(2L);
    }
}
Also used : IOException(java.io.IOException) BlockDoesNotExistException(alluxio.exception.BlockDoesNotExistException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 22 with BlockDoesNotExistException

use of alluxio.exception.BlockDoesNotExistException in project alluxio by Alluxio.

the class BlockWorkerDataWriter method create.

/**
 * Creates an instance of {@link BlockWorkerDataWriter}.
 *
 * @param context the file system context
 * @param blockId the block ID
 * @param blockSize the block size in bytes
 * @param options the output stream options
 * @return the {@link BlockWorkerDataWriter} created
 */
public static BlockWorkerDataWriter create(final FileSystemContext context, long blockId, long blockSize, OutStreamOptions options) throws IOException {
    AlluxioConfiguration conf = context.getClusterConf();
    int chunkSize = (int) conf.getBytes(PropertyKey.USER_LOCAL_WRITER_CHUNK_SIZE_BYTES);
    long reservedBytes = Math.min(blockSize, conf.getBytes(PropertyKey.USER_FILE_RESERVED_BYTES));
    BlockWorker blockWorker = context.getProcessLocalWorker();
    Preconditions.checkNotNull(blockWorker, "blockWorker");
    long sessionId = SessionIdUtils.createSessionId();
    try {
        blockWorker.createBlock(sessionId, blockId, options.getWriteTier(), options.getMediumType(), reservedBytes);
        BlockWriter blockWriter = blockWorker.createBlockWriter(sessionId, blockId);
        return new BlockWorkerDataWriter(sessionId, blockId, options, blockWriter, blockWorker, chunkSize, reservedBytes, conf);
    } catch (BlockAlreadyExistsException | WorkerOutOfSpaceException | BlockDoesNotExistException | InvalidWorkerStateException e) {
        throw new IOException(e);
    }
}
Also used : BlockAlreadyExistsException(alluxio.exception.BlockAlreadyExistsException) BlockWriter(alluxio.worker.block.io.BlockWriter) IOException(java.io.IOException) WorkerOutOfSpaceException(alluxio.exception.WorkerOutOfSpaceException) BlockDoesNotExistException(alluxio.exception.BlockDoesNotExistException) AlluxioConfiguration(alluxio.conf.AlluxioConfiguration) BlockWorker(alluxio.worker.block.BlockWorker) InvalidWorkerStateException(alluxio.exception.InvalidWorkerStateException)

Example 23 with BlockDoesNotExistException

use of alluxio.exception.BlockDoesNotExistException in project alluxio by Alluxio.

the class TieredBlockStore method freeSpace.

/**
 * Free space is the entry for immediate block deletion in order to open up space for
 * new or ongoing blocks.
 *
 * - New blocks creations will not try to free space until all tiers are out of space.
 * - Ongoing blocks could end up freeing space oftenly, when the file's origin location is
 * low on space.
 *
 * This method is synchronized in order to prevent race in its only client, allocations.
 * If not synchronized, new allocations could steal space reserved by ongoing ones.
 * Removing synchronized requires implementing retries to this call along with an optimal
 * locking strategy for fairness.
 *
 * TODO(ggezer): Remove synchronized.
 *
 * @param sessionId the session id
 * @param minContiguousBytes the minimum amount of contigious free space in bytes
 * @param minAvailableBytes the minimum amount of free space in bytes
 * @param location the location to free space
 * @throws WorkerOutOfSpaceException if there is not enough space to fulfill minimum requirement
 */
@VisibleForTesting
public synchronized void freeSpace(long sessionId, long minContiguousBytes, long minAvailableBytes, BlockStoreLocation location) throws WorkerOutOfSpaceException, IOException {
    LOG.debug("freeSpace: sessionId={}, minContiguousBytes={}, minAvailableBytes={}, location={}", sessionId, minAvailableBytes, minAvailableBytes, location);
    // TODO(ggezer): Too much memory pressure when pinned-inodes list is large.
    BlockMetadataEvictorView evictorView = getUpdatedView();
    boolean contiguousSpaceFound = false;
    boolean availableBytesFound = false;
    int blocksIterated = 0;
    int blocksRemoved = 0;
    int spaceFreed = 0;
    // List of all dirs that belong to the given location.
    List<StorageDirView> dirViews = evictorView.getDirs(location);
    Iterator<Long> evictionCandidates = mBlockIterator.getIterator(location, BlockOrder.NATURAL);
    while (true) {
        // Check if minContiguousBytes is satisfied.
        if (!contiguousSpaceFound) {
            for (StorageDirView dirView : dirViews) {
                if (dirView.getAvailableBytes() >= minContiguousBytes) {
                    contiguousSpaceFound = true;
                    break;
                }
            }
        }
        // Check minAvailableBytes is satisfied.
        if (!availableBytesFound) {
            if (evictorView.getAvailableBytes(location) >= minAvailableBytes) {
                availableBytesFound = true;
            }
        }
        if (contiguousSpaceFound && availableBytesFound) {
            break;
        }
        if (!evictionCandidates.hasNext()) {
            break;
        }
        long blockToDelete = evictionCandidates.next();
        blocksIterated++;
        if (evictorView.isBlockEvictable(blockToDelete)) {
            try {
                BlockMeta blockMeta = mMetaManager.getBlockMeta(blockToDelete);
                removeBlockFileAndMeta(blockMeta);
                blocksRemoved++;
                for (BlockStoreEventListener listener : mBlockStoreEventListeners) {
                    synchronized (listener) {
                        listener.onRemoveBlockByWorker(sessionId, blockMeta.getBlockId());
                        listener.onRemoveBlock(sessionId, blockMeta.getBlockId(), blockMeta.getBlockLocation());
                    }
                }
                spaceFreed += blockMeta.getBlockSize();
            } catch (BlockDoesNotExistException e) {
                LOG.warn("Failed to evict blockId {}, it could be already deleted", blockToDelete);
                continue;
            }
        }
    }
    if (!contiguousSpaceFound || !availableBytesFound) {
        throw new WorkerOutOfSpaceException(String.format("Failed to free %d bytes space at location %s. " + "Min contiguous requested: %d, Min available requested: %d, " + "Blocks iterated: %d, Blocks removed: %d, Space freed: %d", minAvailableBytes, location.tierAlias(), minContiguousBytes, minAvailableBytes, blocksIterated, blocksRemoved, spaceFreed));
    }
}
Also used : StorageDirView(alluxio.worker.block.meta.StorageDirView) BlockMeta(alluxio.worker.block.meta.BlockMeta) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta) BlockDoesNotExistException(alluxio.exception.BlockDoesNotExistException) WorkerOutOfSpaceException(alluxio.exception.WorkerOutOfSpaceException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 24 with BlockDoesNotExistException

use of alluxio.exception.BlockDoesNotExistException in project alluxio by Alluxio.

the class TieredBlockStore method abortBlockInternal.

/**
 * Aborts a temp block.
 *
 * @param sessionId the id of session
 * @param blockId the id of block
 * @throws BlockDoesNotExistException if block id can not be found in temporary blocks
 * @throws BlockAlreadyExistsException if block id already exists in committed blocks
 * @throws InvalidWorkerStateException if block id is not owned by session id
 */
private void abortBlockInternal(long sessionId, long blockId) throws BlockDoesNotExistException, BlockAlreadyExistsException, InvalidWorkerStateException, IOException {
    String path;
    TempBlockMeta tempBlockMeta;
    try (LockResource r = new LockResource(mMetadataReadLock)) {
        checkTempBlockOwnedBySession(sessionId, blockId);
        tempBlockMeta = mMetaManager.getTempBlockMeta(blockId);
        path = tempBlockMeta.getPath();
    }
    // The metadata lock is released during heavy IO. The temp block is private to one session, so
    // we do not lock it.
    Files.delete(Paths.get(path));
    try (LockResource r = new LockResource(mMetadataWriteLock)) {
        mMetaManager.abortTempBlockMeta(tempBlockMeta);
    } catch (BlockDoesNotExistException e) {
        // We shall never reach here
        throw Throwables.propagate(e);
    }
}
Also used : LockResource(alluxio.resource.LockResource) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta) BlockDoesNotExistException(alluxio.exception.BlockDoesNotExistException)

Example 25 with BlockDoesNotExistException

use of alluxio.exception.BlockDoesNotExistException in project alluxio by Alluxio.

the class TieredBlockStore method removeBlockInternal.

@VisibleForTesting
BlockMeta removeBlockInternal(long sessionId, long blockId, BlockStoreLocation location, long timeoutMs) throws InvalidWorkerStateException, BlockDoesNotExistException, IOException {
    long lockId = mLockManager.tryLockBlock(sessionId, blockId, BlockLockType.WRITE, timeoutMs, TimeUnit.MILLISECONDS);
    if (lockId == BlockWorker.INVALID_LOCK_ID) {
        throw new DeadlineExceededException(String.format("Can not acquire lock to remove block %d for session %d after %d ms", blockId, sessionId, REMOVE_BLOCK_TIMEOUT_MS));
    }
    BlockMeta blockMeta;
    try (LockResource r = new LockResource(mMetadataReadLock)) {
        if (mMetaManager.hasTempBlockMeta(blockId)) {
            throw new InvalidWorkerStateException(ExceptionMessage.REMOVE_UNCOMMITTED_BLOCK, blockId);
        }
        blockMeta = mMetaManager.getBlockMeta(blockId);
        if (!blockMeta.getBlockLocation().belongsTo(location)) {
            throw new BlockDoesNotExistException(ExceptionMessage.BLOCK_NOT_FOUND_AT_LOCATION, blockId, location);
        }
    } catch (Exception e) {
        mLockManager.unlockBlock(lockId);
        throw e;
    }
    try (LockResource r = new LockResource(mMetadataWriteLock)) {
        removeBlockFileAndMeta(blockMeta);
    } finally {
        mLockManager.unlockBlock(lockId);
    }
    return blockMeta;
}
Also used : LockResource(alluxio.resource.LockResource) DeadlineExceededException(alluxio.exception.status.DeadlineExceededException) BlockMeta(alluxio.worker.block.meta.BlockMeta) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta) BlockDoesNotExistException(alluxio.exception.BlockDoesNotExistException) InvalidWorkerStateException(alluxio.exception.InvalidWorkerStateException) BlockAlreadyExistsException(alluxio.exception.BlockAlreadyExistsException) WorkerOutOfSpaceException(alluxio.exception.WorkerOutOfSpaceException) IOException(java.io.IOException) DeadlineExceededException(alluxio.exception.status.DeadlineExceededException) BlockDoesNotExistException(alluxio.exception.BlockDoesNotExistException) InvalidWorkerStateException(alluxio.exception.InvalidWorkerStateException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

BlockDoesNotExistException (alluxio.exception.BlockDoesNotExistException)31 IOException (java.io.IOException)16 WorkerOutOfSpaceException (alluxio.exception.WorkerOutOfSpaceException)14 BlockAlreadyExistsException (alluxio.exception.BlockAlreadyExistsException)12 BlockMeta (alluxio.worker.block.meta.BlockMeta)12 InvalidWorkerStateException (alluxio.exception.InvalidWorkerStateException)11 LockResource (alluxio.resource.LockResource)8 TempBlockMeta (alluxio.worker.block.meta.TempBlockMeta)8 AlluxioException (alluxio.exception.AlluxioException)6 BlockReader (alluxio.worker.block.io.BlockReader)6 ArrayList (java.util.ArrayList)5 UnavailableException (alluxio.exception.status.UnavailableException)4 BlockTransferInfo (alluxio.worker.block.evictor.BlockTransferInfo)4 StorageDirView (alluxio.worker.block.meta.StorageDirView)4 AlluxioURI (alluxio.AlluxioURI)3 DelegatingBlockReader (alluxio.worker.block.io.DelegatingBlockReader)3 StorageTierView (alluxio.worker.block.meta.StorageTierView)3 LinkedList (java.util.LinkedList)3 List (java.util.List)3 Test (org.junit.Test)3