Esempio n. 1
0
  /**
   * Commits a block to Tachyon managed space. The block must be temporary. The block is persisted
   * after {@link BlockStore#commitBlock(long, long)}. The block will not be accessible until {@link
   * WorkerBlockMasterClient#commitBlock} succeeds.
   *
   * @param sessionId The id of the client
   * @param blockId The id of the block to commit
   * @throws BlockAlreadyExistsException if blockId already exists in committed blocks
   * @throws BlockDoesNotExistException if the temporary block cannot be found
   * @throws InvalidWorkerStateException if blockId does not belong to sessionId
   * @throws IOException if the block cannot be moved from temporary path to committed path
   * @throws WorkerOutOfSpaceException if there is no more space left to hold the block
   */
  public void commitBlock(long sessionId, long blockId)
      throws BlockAlreadyExistsException, BlockDoesNotExistException, InvalidWorkerStateException,
          IOException, WorkerOutOfSpaceException {
    mBlockStore.commitBlock(sessionId, blockId);

    // TODO(calvin): Reconsider how to do this without heavy locking.
    // Block successfully committed, update master with new block metadata
    Long lockId = mBlockStore.lockBlock(sessionId, blockId);
    try {
      BlockMeta meta = mBlockStore.getBlockMeta(sessionId, blockId, lockId);
      BlockStoreLocation loc = meta.getBlockLocation();
      Long length = meta.getBlockSize();
      BlockStoreMeta storeMeta = mBlockStore.getBlockStoreMeta();
      Long bytesUsedOnTier = storeMeta.getUsedBytesOnTiers().get(loc.tierAlias());
      mBlockMasterClient.commitBlock(
          WorkerIdRegistry.getWorkerId(), bytesUsedOnTier, loc.tierAlias(), blockId, length);
    } catch (IOException ioe) {
      throw new IOException("Failed to commit block to master.", ioe);
    } finally {
      mBlockStore.unlockBlock(lockId);
    }
  }
Esempio n. 2
0
 /**
  * Gets the path to the block file in local storage. The block must be a permanent block, and the
  * caller must first obtain the lock on the block.
  *
  * @param sessionId The id of the client
  * @param blockId The id of the block to read
  * @param lockId The id of the lock on this block
  * @return a string representing the path to this block in local storage
  * @throws BlockDoesNotExistException if the blockId cannot be found in committed blocks or lockId
  *     cannot be found
  * @throws InvalidWorkerStateException if sessionId or blockId is not the same as that in the
  *     LockRecord of lockId
  */
 public String readBlock(long sessionId, long blockId, long lockId)
     throws BlockDoesNotExistException, InvalidWorkerStateException {
   BlockMeta meta = mBlockStore.getBlockMeta(sessionId, blockId, lockId);
   return meta.getPath();
 }