Search in sources :

Example 1 with MasterBlockLocation

use of alluxio.master.block.meta.MasterBlockLocation in project alluxio by Alluxio.

the class BlockMaster method generateBlockInfo.

/**
   * Creates a {@link BlockInfo} form a given {@link MasterBlockInfo}, by populating worker
   * locations.
   *
   * @param masterBlockInfo the {@link MasterBlockInfo}
   * @return a {@link BlockInfo} from a {@link MasterBlockInfo}. Populates worker locations
   */
@GuardedBy("masterBlockInfo")
private BlockInfo generateBlockInfo(MasterBlockInfo masterBlockInfo) {
    // "Join" to get all the addresses of the workers.
    List<BlockLocation> locations = new ArrayList<>();
    List<MasterBlockLocation> blockLocations = masterBlockInfo.getBlockLocations();
    // Sort the block locations by their alias ordinal in the master storage tier mapping
    Collections.sort(blockLocations, new Comparator<MasterBlockLocation>() {

        @Override
        public int compare(MasterBlockLocation o1, MasterBlockLocation o2) {
            return mGlobalStorageTierAssoc.getOrdinal(o1.getTierAlias()) - mGlobalStorageTierAssoc.getOrdinal(o2.getTierAlias());
        }
    });
    for (MasterBlockLocation masterBlockLocation : blockLocations) {
        MasterWorkerInfo workerInfo = mWorkers.getFirstByField(ID_INDEX, masterBlockLocation.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 BlockLocation().setWorkerId(masterBlockLocation.getWorkerId()).setWorkerAddress(workerInfo.getWorkerAddress()).setTierAlias(masterBlockLocation.getTierAlias()));
        }
    }
    return new BlockInfo().setBlockId(masterBlockInfo.getBlockId()).setLength(masterBlockInfo.getLength()).setLocations(locations);
}
Also used : MasterBlockLocation(alluxio.master.block.meta.MasterBlockLocation) BlockInfo(alluxio.wire.BlockInfo) MasterBlockInfo(alluxio.master.block.meta.MasterBlockInfo) ArrayList(java.util.ArrayList) MasterWorkerInfo(alluxio.master.block.meta.MasterWorkerInfo) MasterBlockLocation(alluxio.master.block.meta.MasterBlockLocation) BlockLocation(alluxio.wire.BlockLocation) GuardedBy(javax.annotation.concurrent.GuardedBy)

Aggregations

MasterBlockInfo (alluxio.master.block.meta.MasterBlockInfo)1 MasterBlockLocation (alluxio.master.block.meta.MasterBlockLocation)1 MasterWorkerInfo (alluxio.master.block.meta.MasterWorkerInfo)1 BlockInfo (alluxio.wire.BlockInfo)1 BlockLocation (alluxio.wire.BlockLocation)1 ArrayList (java.util.ArrayList)1 GuardedBy (javax.annotation.concurrent.GuardedBy)1