Search in sources :

Example 1 with UnderFileSystemBlockMeta

use of alluxio.worker.block.meta.UnderFileSystemBlockMeta in project alluxio by Alluxio.

the class UnderFileSystemBlockStore method acquireAccess.

/**
   * Acquires access for a UFS block given a {@link UnderFileSystemBlockMeta} and the limit on
   * the maximum concurrency on the block. If the number of concurrent readers on this UFS block
   * exceeds a threshold, the token is not granted and this method returns false.
   *
   * @param sessionId the session ID
   * @param blockId maximum concurrency
   * @param options the options
   * @return whether an access token is acquired
   * @throws BlockAlreadyExistsException if the block already exists for a session ID
   */
public boolean acquireAccess(long sessionId, long blockId, OpenUfsBlockOptions options) throws BlockAlreadyExistsException {
    UnderFileSystemBlockMeta blockMeta = new UnderFileSystemBlockMeta(sessionId, blockId, options);
    mLock.lock();
    try {
        Key key = new Key(sessionId, blockId);
        if (mBlocks.containsKey(key)) {
            throw new BlockAlreadyExistsException(ExceptionMessage.UFS_BLOCK_ALREADY_EXISTS_FOR_SESSION, blockId, blockMeta.getUnderFileSystemPath(), sessionId);
        }
        Set<Long> sessionIds = mBlockIdToSessionIds.get(blockId);
        if (sessionIds != null && sessionIds.size() >= options.getMaxUfsReadConcurrency()) {
            return false;
        }
        if (sessionIds == null) {
            sessionIds = new HashSet<>();
            mBlockIdToSessionIds.put(blockId, sessionIds);
        }
        sessionIds.add(sessionId);
        mBlocks.put(key, new BlockInfo(blockMeta));
        Set<Long> blockIds = mSessionIdToBlockIds.get(sessionId);
        if (blockIds == null) {
            blockIds = new HashSet<>();
            mSessionIdToBlockIds.put(sessionId, blockIds);
        }
        blockIds.add(blockId);
    } finally {
        mLock.unlock();
    }
    return true;
}
Also used : UnderFileSystemBlockMeta(alluxio.worker.block.meta.UnderFileSystemBlockMeta) BlockAlreadyExistsException(alluxio.exception.BlockAlreadyExistsException)

Example 2 with UnderFileSystemBlockMeta

use of alluxio.worker.block.meta.UnderFileSystemBlockMeta in project alluxio by Alluxio.

the class UnderFileSystemBlockReaderTest method before.

@Before
public void before() throws Exception {
    Configuration.set(PropertyKey.UNDERFS_ADDRESS, mFolder.getRoot().getAbsolutePath());
    String testFilePath = mFolder.newFile().getAbsolutePath();
    byte[] buffer = BufferUtils.getIncreasingByteArray((int) TEST_BLOCK_SIZE * 2);
    BufferUtils.writeBufferToFile(testFilePath, buffer);
    mAlluxioBlockStore = Mockito.mock(BlockStore.class);
    mTempBlockMeta = Mockito.mock(TempBlockMeta.class);
    Mockito.when(mAlluxioBlockStore.createBlock(Mockito.anyLong(), Mockito.anyLong(), Mockito.any(BlockStoreLocation.class), Mockito.anyLong())).thenReturn(mTempBlockMeta);
    Mockito.when(mTempBlockMeta.getPath()).thenReturn(mFolder.newFile().getAbsolutePath());
    LockBlockTOptions options = new LockBlockTOptions();
    options.setMaxUfsReadConcurrency(10);
    options.setBlockSize(TEST_BLOCK_SIZE);
    options.setOffset(TEST_BLOCK_SIZE);
    options.setUfsPath(testFilePath);
    mUnderFileSystemBlockMeta = new UnderFileSystemBlockMeta(SESSION_ID, BLOCK_ID, new OpenUfsBlockOptions(options));
}
Also used : UnderFileSystemBlockMeta(alluxio.worker.block.meta.UnderFileSystemBlockMeta) OpenUfsBlockOptions(alluxio.worker.block.options.OpenUfsBlockOptions) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta) LockBlockTOptions(alluxio.thrift.LockBlockTOptions) Before(org.junit.Before)

Aggregations

UnderFileSystemBlockMeta (alluxio.worker.block.meta.UnderFileSystemBlockMeta)2 BlockAlreadyExistsException (alluxio.exception.BlockAlreadyExistsException)1 LockBlockTOptions (alluxio.thrift.LockBlockTOptions)1 TempBlockMeta (alluxio.worker.block.meta.TempBlockMeta)1 OpenUfsBlockOptions (alluxio.worker.block.options.OpenUfsBlockOptions)1 Before (org.junit.Before)1