private TempBlockMeta createBlockMetaInternal ( long sessionId , long blockId , BlockStoreLocation location , long initialBlockSize , boolean newBlock ) throws BlockAlreadyExistsException { // NOTE: a temp block is supposed to be visible for its own writer, unnecessary to acquire // block lock here since no sharing try ( LockResource r = new LockResource ( mMetadataWriteLock ) ) { if ( newBlock ) { checkTempBlockIdAvailable ( blockId ) ; } StorageDirView dirView = mAllocator . allocateBlockWithView ( sessionId , initialBlockSize , location , getUpdatedView ( ) ) ; if ( dirView == null ) { // Allocator fails to find a proper place for this new block. return null ; } // TODO(carson): Add tempBlock to corresponding storageDir and remove the use of // StorageDirView.createTempBlockMeta. TempBlockMeta tempBlock = dirView . createTempBlockMeta ( sessionId , blockId , initialBlockSize ) ; try { // Add allocated temp block to metadata manager. This should never fail if allocator // correctly assigns a StorageDir. mMetaManager . addTempBlockMeta ( tempBlock ) ; } catch ( WorkerOutOfSpaceException | BlockAlreadyExistsException e ) { // If we reach here, allocator is not working properly LOG . error ( "Unexpected failure: {} bytes allocated at {} by allocator, " + "but addTempBlockMeta failed" , initialBlockSize , location ) ; throw Throwables . propagate ( e ) ; } return tempBlock ; } }
Creates a temp block meta only if allocator finds available space . This method will not trigger any eviction .