@ GuardedBy ( "masterBlockInfo" ) private Optional < BlockInfo > generateBlockInfo ( long blockId ) throws UnavailableException { if ( mSafeModeManager . isInSafeMode ( ) ) { throw new UnavailableException ( ExceptionMessage . MASTER_IN_SAFEMODE . getMessage ( ) ) ; } BlockMeta block ; List < BlockLocation > blockLocations ; try ( LockResource lr = lockBlock ( blockId ) ) { Optional < BlockMeta > blockOpt = mBlockStore . getBlock ( blockId ) ; if ( ! blockOpt . isPresent ( ) ) { return Optional . empty ( ) ; } block = blockOpt . get ( ) ; blockLocations = new ArrayList <> ( mBlockStore . getLocations ( blockId ) ) ; } // Sort the block locations by their alias ordinal in the master storage tier mapping Collections . sort ( blockLocations , Comparator . comparingInt ( o -> mGlobalStorageTierAssoc . getOrdinal ( o . getTier ( ) ) ) ) ; List < alluxio . wire . BlockLocation > locations = new ArrayList <> ( ) ; for ( BlockLocation location : blockLocations ) { MasterWorkerInfo workerInfo = mWorkers . getFirstByField ( ID_INDEX , location . getWorkerId ( ) ) ; if ( workerInfo != null ) { // worker metadata is intentionally not locked here because: // - it would be an incorrect order (correct order is lock worker first, then block) // - only uses getters of final variables locations . add ( new alluxio . wire . BlockLocation ( ) . setWorkerId ( location . getWorkerId ( ) ) . setWorkerAddress ( workerInfo . getWorkerAddress ( ) ) . setTierAlias ( location . getTier ( ) ) ) ; } } return Optional . of ( new BlockInfo ( ) . setBlockId ( blockId ) . setLength ( block . getLength ( ) ) . setLocations ( locations ) ) ; }
Generates block info including worker locations for a block id .