private boolean cacheBlockFromUfs ( long blockId , long blockSize , Protocol . OpenUfsBlockOptions openUfsBlockOptions ) { // Check if the block has been requested in UFS block store try { if ( ! mBlockWorker . openUfsBlock ( Sessions . ASYNC_CACHE_SESSION_ID , blockId , openUfsBlockOptions ) ) { LOG . warn ( "Failed to async cache block {} from UFS on opening the block" , blockId ) ; return false ; } } catch ( BlockAlreadyExistsException e ) { // It is already cached return true ; } try ( BlockReader reader = mBlockWorker . readUfsBlock ( Sessions . ASYNC_CACHE_SESSION_ID , blockId , 0 ) ) { // Read the entire block, caching to block store will be handled internally in UFS block store // Note that, we read from UFS with a smaller buffer to avoid high pressure on heap // memory when concurrent async requests are received and thus trigger GC. long offset = 0 ; while ( offset < blockSize ) { long bufferSize = Math . min ( 8 * Constants . MB , blockSize - offset ) ; reader . read ( offset , bufferSize ) ; offset += bufferSize ; } } catch ( AlluxioException | IOException e ) { // This is only best effort LOG . warn ( "Failed to async cache block {} from UFS on copying the block: {}" , blockId , e ) ; return false ; } finally { try { mBlockWorker . closeUfsBlock ( Sessions . ASYNC_CACHE_SESSION_ID , blockId ) ; } catch ( AlluxioException | IOException ee ) { LOG . warn ( "Failed to close UFS block {}: {}" , blockId , ee ) ; return false ; } } return true ; }
Caches the block via the local worker to read from UFS .