Search in sources :

Example 41 with WorkerInfo

use of alluxio.wire.WorkerInfo in project alluxio by Alluxio.

the class ReplicateDefinition method selectExecutors.

@Override
public Set<Pair<WorkerInfo, SerializableVoid>> selectExecutors(ReplicateConfig config, List<WorkerInfo> jobWorkerInfoList, SelectExecutorsContext context) throws Exception {
    Preconditions.checkArgument(!jobWorkerInfoList.isEmpty(), "No worker is available");
    long blockId = config.getBlockId();
    int numReplicas = config.getReplicas();
    Preconditions.checkArgument(numReplicas > 0);
    AlluxioBlockStore blockStore = AlluxioBlockStore.create(context.getFsContext());
    BlockInfo blockInfo = blockStore.getInfo(blockId);
    Set<String> hosts = new HashSet<>();
    for (BlockLocation blockLocation : blockInfo.getLocations()) {
        hosts.add(blockLocation.getWorkerAddress().getHost());
    }
    Set<Pair<WorkerInfo, SerializableVoid>> result = Sets.newHashSet();
    Collections.shuffle(jobWorkerInfoList);
    for (WorkerInfo workerInfo : jobWorkerInfoList) {
        // Select job workers that don't have this block locally to replicate
        if (!hosts.contains(workerInfo.getAddress().getHost())) {
            result.add(new Pair<>(workerInfo, null));
            if (result.size() >= numReplicas) {
                break;
            }
        }
    }
    return result;
}
Also used : BlockInfo(alluxio.wire.BlockInfo) WorkerInfo(alluxio.wire.WorkerInfo) AlluxioBlockStore(alluxio.client.block.AlluxioBlockStore) BlockLocation(alluxio.wire.BlockLocation) HashSet(java.util.HashSet) Pair(alluxio.collections.Pair)

Example 42 with WorkerInfo

use of alluxio.wire.WorkerInfo in project alluxio by Alluxio.

the class BatchedJobDefinition method selectExecutors.

@Override
public Set<Pair<WorkerInfo, BatchedJobTask>> selectExecutors(BatchedJobConfig config, List<WorkerInfo> jobWorkerInfoList, SelectExecutorsContext context) throws Exception {
    // get job type and config
    String jobType = config.getJobType();
    PlanDefinition plan = JobDefinitionFactory.create(jobType);
    // convert map to config
    final ObjectMapper mapper = new ObjectMapper();
    Class<?> jobConfigClass = plan.getJobConfigClass();
    Set<Pair<WorkerInfo, BatchedJobTask>> allTasks = Sets.newHashSet();
    for (Map<String, String> configMap : config.getJobConfigs()) {
        JobConfig jobConfig = (JobConfig) mapper.convertValue(configMap, jobConfigClass);
        Set<Pair<WorkerInfo, Serializable>> tasks = plan.selectExecutors(jobConfig, jobWorkerInfoList, context);
        for (Pair<WorkerInfo, Serializable> task : tasks) {
            BatchedJobTask batchedTask = new BatchedJobTask(jobConfig, task.getSecond());
            allTasks.add(new Pair<>(task.getFirst(), batchedTask));
        }
    }
    return allTasks;
}
Also used : Serializable(java.io.Serializable) WorkerInfo(alluxio.wire.WorkerInfo) BatchedJobConfig(alluxio.job.plan.BatchedJobConfig) JobConfig(alluxio.job.JobConfig) AbstractVoidPlanDefinition(alluxio.job.plan.AbstractVoidPlanDefinition) PlanDefinition(alluxio.job.plan.PlanDefinition) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Pair(alluxio.collections.Pair)

Example 43 with WorkerInfo

use of alluxio.wire.WorkerInfo in project alluxio by Alluxio.

the class DefaultBlockMaster method generateBlockInfo.

/**
 * Generates block info, including worker locations, for a block id.
 * This requires no locks on the {@link MasterWorkerInfo} because it is only reading
 * final fields.
 *
 * @param blockId a block id
 * @return optional block info, empty if the block does not exist
 */
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 r = 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()).setMediumType(location.getMediumType()));
        }
    }
    return Optional.of(new BlockInfo().setBlockId(blockId).setLength(block.getLength()).setLocations(locations));
}
Also used : Arrays(java.util.Arrays) SystemClock(alluxio.clock.SystemClock) LoadingCache(com.google.common.cache.LoadingCache) Server(alluxio.Server) BlockInfo(alluxio.wire.BlockInfo) PropertyKey(alluxio.conf.PropertyKey) GrpcService(alluxio.grpc.GrpcService) Future(java.util.concurrent.Future) WorkerInfo(alluxio.wire.WorkerInfo) Map(java.util.Map) MetricsMaster(alluxio.master.metrics.MetricsMaster) GetWorkerReportOptions(alluxio.client.block.options.GetWorkerReportOptions) EnumSet(java.util.EnumSet) RegisterLease(alluxio.wire.RegisterLease) MasterWorkerInfo(alluxio.master.block.meta.MasterWorkerInfo) IndexedSet(alluxio.collections.IndexedSet) ConcurrentHashSet(alluxio.collections.ConcurrentHashSet) Set(java.util.Set) ConfigProperty(alluxio.grpc.ConfigProperty) Block(alluxio.master.metastore.BlockStore.Block) Command(alluxio.grpc.Command) GuardedBy(javax.annotation.concurrent.GuardedBy) ServiceType(alluxio.grpc.ServiceType) BlockStore(alluxio.master.metastore.BlockStore) Metric(alluxio.metrics.Metric) ArrayList(java.util.ArrayList) GrpcUtils(alluxio.grpc.GrpcUtils) BlockInfoException(alluxio.exception.BlockInfoException) BiConsumer(java.util.function.BiConsumer) MetricsSystem(alluxio.metrics.MetricsSystem) Nullable(javax.annotation.Nullable) IdUtils(alluxio.util.IdUtils) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) ExecutorServiceFactory(alluxio.util.executor.ExecutorServiceFactory) Lock(java.util.concurrent.locks.Lock) RegisterWorkerPOptions(alluxio.grpc.RegisterWorkerPOptions) Preconditions(com.google.common.base.Preconditions) ExecutorServiceFactories(alluxio.util.executor.ExecutorServiceFactories) StorageList(alluxio.grpc.StorageList) CommonUtils(alluxio.util.CommonUtils) Address(alluxio.wire.Address) NotThreadSafe(javax.annotation.concurrent.NotThreadSafe) CloseableIterator(alluxio.resource.CloseableIterator) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) HeartbeatThread(alluxio.heartbeat.HeartbeatThread) MasterStorageTierAssoc(alluxio.MasterStorageTierAssoc) GetRegisterLeasePRequest(alluxio.grpc.GetRegisterLeasePRequest) MetricKey(alluxio.metrics.MetricKey) BlockInfoEntry(alluxio.proto.journal.Block.BlockInfoEntry) InvalidArgumentException(alluxio.exception.status.InvalidArgumentException) IndexDefinition(alluxio.collections.IndexDefinition) ImmutableSet(com.google.common.collect.ImmutableSet) ServerConfiguration(alluxio.conf.ServerConfiguration) StorageTierAssoc(alluxio.StorageTierAssoc) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SuppressFBWarnings(alluxio.annotation.SuppressFBWarnings) CheckpointName(alluxio.master.journal.checkpoint.CheckpointName) Collectors(java.util.stream.Collectors) CacheLoader(com.google.common.cache.CacheLoader) List(java.util.List) CoreMasterContext(alluxio.master.CoreMasterContext) Optional(java.util.Optional) WorkerRange(alluxio.client.block.options.GetWorkerReportOptions.WorkerRange) Gauge(com.codahale.metrics.Gauge) CacheBuilder(com.google.common.cache.CacheBuilder) RegisterWorkerPRequest(alluxio.grpc.RegisterWorkerPRequest) BlockContainerIdGeneratorEntry(alluxio.proto.journal.Block.BlockContainerIdGeneratorEntry) JournalContext(alluxio.master.journal.JournalContext) UnavailableException(alluxio.exception.status.UnavailableException) WorkerLostStorageInfo(alluxio.grpc.WorkerLostStorageInfo) WorkerNetAddress(alluxio.wire.WorkerNetAddress) HashMap(java.util.HashMap) CommandType(alluxio.grpc.CommandType) NetworkAddressUtils(alluxio.util.network.NetworkAddressUtils) Function(java.util.function.Function) MetricInfo(alluxio.metrics.MetricInfo) JournalEntry(alluxio.proto.journal.Journal.JournalEntry) HashSet(java.util.HashSet) Constants(alluxio.Constants) NoSuchElementException(java.util.NoSuchElementException) CoreMaster(alluxio.master.CoreMaster) Striped(com.google.common.util.concurrent.Striped) Logger(org.slf4j.Logger) HeartbeatContext(alluxio.heartbeat.HeartbeatContext) Iterator(java.util.Iterator) BlockMeta(alluxio.proto.meta.Block.BlockMeta) ExceptionMessage(alluxio.exception.ExceptionMessage) HeartbeatExecutor(alluxio.heartbeat.HeartbeatExecutor) NotFoundException(alluxio.exception.status.NotFoundException) LockResource(alluxio.resource.LockResource) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) WorkerMetaLockSection(alluxio.master.block.meta.WorkerMetaLockSection) DeleteBlockEntry(alluxio.proto.journal.Block.DeleteBlockEntry) Clock(java.time.Clock) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) BlockLocation(alluxio.proto.meta.Block.BlockLocation) Collections(java.util.Collections) UnavailableException(alluxio.exception.status.UnavailableException) ArrayList(java.util.ArrayList) BlockLocation(alluxio.proto.meta.Block.BlockLocation) LockResource(alluxio.resource.LockResource) BlockInfo(alluxio.wire.BlockInfo) MasterWorkerInfo(alluxio.master.block.meta.MasterWorkerInfo) BlockMeta(alluxio.proto.meta.Block.BlockMeta)

Example 44 with WorkerInfo

use of alluxio.wire.WorkerInfo in project alluxio by Alluxio.

the class DefaultBlockMaster method getLostWorkersInfoList.

@Override
public List<WorkerInfo> getLostWorkersInfoList() throws UnavailableException {
    if (mSafeModeManager.isInSafeMode()) {
        throw new UnavailableException(ExceptionMessage.MASTER_IN_SAFEMODE.getMessage());
    }
    List<WorkerInfo> workerInfoList = new ArrayList<>(mLostWorkers.size());
    for (MasterWorkerInfo worker : mLostWorkers) {
        // extractWorkerInfo handles the locking internally
        workerInfoList.add(extractWorkerInfo(worker, null, false));
    }
    Collections.sort(workerInfoList, new WorkerInfo.LastContactSecComparator());
    return workerInfoList;
}
Also used : UnavailableException(alluxio.exception.status.UnavailableException) ArrayList(java.util.ArrayList) MasterWorkerInfo(alluxio.master.block.meta.MasterWorkerInfo) WorkerInfo(alluxio.wire.WorkerInfo) MasterWorkerInfo(alluxio.master.block.meta.MasterWorkerInfo)

Example 45 with WorkerInfo

use of alluxio.wire.WorkerInfo in project alluxio by Alluxio.

the class DefaultBlockMaster method getWorkerReport.

@Override
public List<WorkerInfo> getWorkerReport(GetWorkerReportOptions options) throws UnavailableException, InvalidArgumentException {
    if (mSafeModeManager.isInSafeMode()) {
        throw new UnavailableException(ExceptionMessage.MASTER_IN_SAFEMODE.getMessage());
    }
    Set<MasterWorkerInfo> selectedLiveWorkers = new HashSet<>();
    Set<MasterWorkerInfo> selectedLostWorkers = new HashSet<>();
    WorkerRange workerRange = options.getWorkerRange();
    switch(workerRange) {
        case ALL:
            selectedLiveWorkers.addAll(mWorkers);
            selectedLostWorkers.addAll(mLostWorkers);
            break;
        case LIVE:
            selectedLiveWorkers.addAll(mWorkers);
            break;
        case LOST:
            selectedLostWorkers.addAll(mLostWorkers);
            break;
        case SPECIFIED:
            Set<String> addresses = options.getAddresses();
            Set<String> workerNames = new HashSet<>();
            selectedLiveWorkers = selectInfoByAddress(addresses, mWorkers, workerNames);
            selectedLostWorkers = selectInfoByAddress(addresses, mLostWorkers, workerNames);
            if (!addresses.isEmpty()) {
                String info = String.format("Unrecognized worker names: %s%n" + "Supported worker names: %s%n", addresses.toString(), workerNames.toString());
                throw new InvalidArgumentException(info);
            }
            break;
        default:
            throw new InvalidArgumentException("Unrecognized worker range: " + workerRange);
    }
    List<WorkerInfo> workerInfoList = new ArrayList<>(selectedLiveWorkers.size() + selectedLostWorkers.size());
    for (MasterWorkerInfo worker : selectedLiveWorkers) {
        // extractWorkerInfo handles the locking internally
        workerInfoList.add(extractWorkerInfo(worker, options.getFieldRange(), true));
    }
    for (MasterWorkerInfo worker : selectedLostWorkers) {
        // extractWorkerInfo handles the locking internally
        workerInfoList.add(extractWorkerInfo(worker, options.getFieldRange(), false));
    }
    return workerInfoList;
}
Also used : InvalidArgumentException(alluxio.exception.status.InvalidArgumentException) UnavailableException(alluxio.exception.status.UnavailableException) MasterWorkerInfo(alluxio.master.block.meta.MasterWorkerInfo) WorkerRange(alluxio.client.block.options.GetWorkerReportOptions.WorkerRange) ArrayList(java.util.ArrayList) WorkerInfo(alluxio.wire.WorkerInfo) MasterWorkerInfo(alluxio.master.block.meta.MasterWorkerInfo) ConcurrentHashSet(alluxio.collections.ConcurrentHashSet) HashSet(java.util.HashSet)

Aggregations

WorkerInfo (alluxio.wire.WorkerInfo)66 Test (org.junit.Test)31 ArrayList (java.util.ArrayList)18 Pair (alluxio.collections.Pair)17 BlockMasterTestUtils.findWorkerInfo (alluxio.master.block.BlockMasterTestUtils.findWorkerInfo)14 CountDownLatch (java.util.concurrent.CountDownLatch)14 SelectExecutorsContext (alluxio.job.SelectExecutorsContext)12 BlockWorkerInfo (alluxio.client.block.BlockWorkerInfo)11 Command (alluxio.grpc.Command)11 AlluxioURI (alluxio.AlluxioURI)9 Map (java.util.Map)9 BlockInfo (alluxio.wire.BlockInfo)8 BlockLocation (alluxio.wire.BlockLocation)8 WorkerNetAddress (alluxio.wire.WorkerNetAddress)8 URIStatus (alluxio.client.file.URIStatus)7 HashMap (java.util.HashMap)7 List (java.util.List)7 HashSet (java.util.HashSet)6 UnavailableException (alluxio.exception.status.UnavailableException)5 FileBlockInfo (alluxio.wire.FileBlockInfo)5