public void lockBlocks ( long fileId , List < Long > blockIds ) throws IOException { Map < Long , Long > blockIdToLockId = new HashMap <> ( ) ; List < Throwable > errors = new ArrayList <> ( ) ; synchronized ( mLock ) { if ( mPersistingInProgressFiles . containsKey ( fileId ) ) { throw new IOException ( "the file " + fileId + " is already being persisted" ) ; } } try { // lock all the blocks to prevent any eviction for ( long blockId : blockIds ) { long lockId = mBlockWorker . lockBlock ( Sessions . CHECKPOINT_SESSION_ID , blockId ) ; blockIdToLockId . put ( blockId , lockId ) ; } } catch ( BlockDoesNotExistException e ) { errors . add ( e ) ; // make sure all the locks are released for ( long lockId : blockIdToLockId . values ( ) ) { try { mBlockWorker . unlockBlock ( lockId ) ; } catch ( BlockDoesNotExistException bdnee ) { errors . add ( bdnee ) ; } } if ( ! errors . isEmpty ( ) ) { StringBuilder errorStr = new StringBuilder ( ) ; errorStr . append ( "failed to lock all blocks of file " ) . append ( fileId ) . append ( "\n" ) ; for ( Throwable error : errors ) { errorStr . append ( error ) . append ( ' ' ) ; } throw new IOException ( errorStr . toString ( ) ) ; } } synchronized ( mLock ) { mPersistingInProgressFiles . put ( fileId , blockIdToLockId ) ; } }
Locks all the blocks of a given file Id .