private void removeBlockInternal ( long sessionId , long blockId , BlockStoreLocation location ) throws InvalidWorkerStateException , BlockDoesNotExistException , IOException { long lockId = mLockManager . lockBlock ( sessionId , blockId , BlockLockType . WRITE ) ; try { String filePath ; BlockMeta blockMeta ; try ( LockResource r = new LockResource ( mMetadataReadLock ) ) { if ( mMetaManager . hasTempBlockMeta ( blockId ) ) { throw new InvalidWorkerStateException ( ExceptionMessage . REMOVE_UNCOMMITTED_BLOCK , blockId ) ; } blockMeta = mMetaManager . getBlockMeta ( blockId ) ; filePath = blockMeta . getPath ( ) ; } if ( ! blockMeta . getBlockLocation ( ) . belongsTo ( location ) ) { throw new BlockDoesNotExistException ( ExceptionMessage . BLOCK_NOT_FOUND_AT_LOCATION , blockId , location ) ; } // Heavy IO is guarded by block lock but not metadata lock. This may throw IOException. Files . delete ( Paths . get ( filePath ) ) ; try ( LockResource r = new LockResource ( mMetadataWriteLock ) ) { mMetaManager . removeBlockMeta ( blockMeta ) ; } catch ( BlockDoesNotExistException e ) { throw Throwables . propagate ( e ) ; // we shall never reach here } } finally { mLockManager . unlockBlock ( lockId ) ; } }
Removes a block .