Search in sources :

Example 16 with GuardedBy

use of javax.annotation.concurrent.GuardedBy 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

GuardedBy (javax.annotation.concurrent.GuardedBy)16 ArrayList (java.util.ArrayList)6 SchemaTableName (com.facebook.presto.spi.SchemaTableName)4 List (java.util.List)4 MasterBlockInfo (alluxio.master.block.meta.MasterBlockInfo)3 ImmutableList (com.google.common.collect.ImmutableList)3 PrestoException (com.facebook.presto.spi.PrestoException)2 Instant (java.time.Instant)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Optional (java.util.Optional)2 MasterBlockLocation (alluxio.master.block.meta.MasterBlockLocation)1 MasterWorkerInfo (alluxio.master.block.meta.MasterWorkerInfo)1 BlockInfo (alluxio.wire.BlockInfo)1 BlockLocation (alluxio.wire.BlockLocation)1 ErroneousRemoteCommandResponse (com.eightkdata.mongowp.client.core.MongoConnection.ErroneousRemoteCommandResponse)1 RemoteCommandResponse (com.eightkdata.mongowp.client.core.MongoConnection.RemoteCommandResponse)1 ScheduledSplit (com.facebook.presto.ScheduledSplit)1 TaskSource (com.facebook.presto.TaskSource)1 Split (com.facebook.presto.metadata.Split)1