private BlockStoreLocation commitBlockInternal(long sessionId, long blockId)
      throws BlockAlreadyExistsException, InvalidWorkerStateException, BlockDoesNotExistException,
      IOException {
    long lockId = mLockManager.lockBlock(sessionId, blockId, BlockLockType.WRITE);
    try {
      // When committing TempBlockMeta, the final BlockMeta calculates the block size according to
      // the actual file size of this TempBlockMeta. Therefore, commitTempBlockMeta must happen
      // after moving actual block file to its committed path.
      BlockStoreLocation loc;
      String srcPath;
      String dstPath;
      TempBlockMeta tempBlockMeta;
      try (LockResource r = new LockResource(mMetadataReadLock)) {
        checkTempBlockOwnedBySession(sessionId, blockId);
        tempBlockMeta = mMetaManager.getTempBlockMeta(blockId);
        srcPath = tempBlockMeta.getPath();
        dstPath = tempBlockMeta.getCommitPath();
        loc = tempBlockMeta.getBlockLocation();
      }

      // Heavy IO is guarded by block lock but not metadata lock. This may throw IOException.
      FileUtils.move(srcPath, dstPath);

      try (LockResource r = new LockResource(mMetadataWriteLock)) {
        mMetaManager.commitTempBlockMeta(tempBlockMeta);
      } catch (BlockAlreadyExistsException | BlockDoesNotExistException
          | WorkerOutOfSpaceException e) {
        throw Throwables.propagate(e); // we shall never reach here
      }
      return loc;
    } finally {
      mLockManager.unlockBlock(lockId);
    }
  }
private BlockStoreLocation commitBlockInternal ( long sessionId , long blockId ) throws BlockAlreadyExistsException , InvalidWorkerStateException , BlockDoesNotExistException , IOException { long lockId = mLockManager . lockBlock ( sessionId , blockId , BlockLockType . WRITE ) ; try { BlockStoreLocation loc ; String srcPath ; String dstPath ; TempBlockMeta tempBlockMeta ; try ( LockResource r = new LockResource ( mMetadataReadLock ) ) { checkTempBlockOwnedBySession ( sessionId , blockId ) ; tempBlockMeta = mMetaManager . getTempBlockMeta ( blockId ) ; srcPath = tempBlockMeta . getPath ( ) ; dstPath = tempBlockMeta . getCommitPath ( ) ; loc = tempBlockMeta . getBlockLocation ( ) ; } FileUtils . move ( srcPath , dstPath ) ; try ( LockResource r = new LockResource ( mMetadataWriteLock ) ) { mMetaManager . commitTempBlockMeta ( tempBlockMeta ) ; } catch ( BlockAlreadyExistsException | BlockDoesNotExistException | WorkerOutOfSpaceException e ) { throw Throwables . propagate ( e ) ; } return loc ; } finally { mLockManager . unlockBlock ( lockId ) ; } }
Commits a temp block.

@param sessionId the id of session
@param blockId the id of block
@return destination location to move the 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