Search in sources :

Example 6 with SelectExecutorsContext

use of alluxio.job.SelectExecutorsContext in project alluxio by Alluxio.

the class StressBenchDefinition method selectExecutors.

@Override
public Set<Pair<WorkerInfo, ArrayList<String>>> selectExecutors(StressBenchConfig config, List<WorkerInfo> jobWorkerInfoList, SelectExecutorsContext context) {
    Set<Pair<WorkerInfo, ArrayList<String>>> result = Sets.newHashSet();
    // sort copy of workers by hashcode
    List<WorkerInfo> workerList = Lists.newArrayList(jobWorkerInfoList);
    workerList.sort(Comparator.comparing(w -> w.getAddress().getHost()));
    // take the first subset, according to cluster limit
    int clusterLimit = config.getClusterLimit();
    if (clusterLimit == 0) {
        clusterLimit = workerList.size();
    }
    if (clusterLimit < 0) {
        // if negative, reverse the list
        clusterLimit = -clusterLimit;
        Collections.reverse(workerList);
    }
    workerList = workerList.subList(0, clusterLimit);
    for (WorkerInfo worker : workerList) {
        LOG.info("Generating job for worker {}", worker.getId());
        ArrayList<String> args = new ArrayList<>(2);
        // Add the worker hostname + worker id as the unique task id for each distributed task.
        // The worker id is used since there may be multiple workers on a single host.
        args.add(BaseParameters.ID_FLAG);
        args.add(worker.getAddress().getHost() + "-" + worker.getId());
        result.add(new Pair<>(worker, args));
    }
    return result;
}
Also used : JsonSerializable(alluxio.util.JsonSerializable) LoggerFactory(org.slf4j.LoggerFactory) UnderFileSystemConfiguration(alluxio.underfs.UnderFileSystemConfiguration) PropertyKey(alluxio.conf.PropertyKey) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) RunTaskContext(alluxio.job.RunTaskContext) CloseableResource(alluxio.resource.CloseableResource) WorkerInfo(alluxio.wire.WorkerInfo) Map(java.util.Map) UfsIOParameters(alluxio.stress.worker.UfsIOParameters) AlluxioConfiguration(alluxio.conf.AlluxioConfiguration) Logger(org.slf4j.Logger) ServerConfiguration(alluxio.conf.ServerConfiguration) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) SelectExecutorsContext(alluxio.job.SelectExecutorsContext) IOException(java.io.IOException) Pair(alluxio.collections.Pair) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) List(java.util.List) PlanDefinition(alluxio.job.plan.PlanDefinition) StressBenchConfig(alluxio.stress.job.StressBenchConfig) UnderFileSystem(alluxio.underfs.UnderFileSystem) BaseParameters(alluxio.stress.BaseParameters) Comparator(java.util.Comparator) TaskResult(alluxio.stress.TaskResult) Collections(java.util.Collections) ShellUtils(alluxio.util.ShellUtils) MountPointInfo(alluxio.wire.MountPointInfo) ArrayList(java.util.ArrayList) WorkerInfo(alluxio.wire.WorkerInfo) Pair(alluxio.collections.Pair)

Example 7 with SelectExecutorsContext

use of alluxio.job.SelectExecutorsContext in project alluxio by Alluxio.

the class LoadDefinition method selectExecutors.

@Override
public Set<Pair<WorkerInfo, ArrayList<LoadTask>>> selectExecutors(LoadConfig config, List<WorkerInfo> jobWorkerInfoList, SelectExecutorsContext context) throws Exception {
    Map<String, WorkerInfo> jobWorkersByAddress = jobWorkerInfoList.stream().collect(Collectors.toMap(info -> info.getAddress().getHost(), info -> info));
    // Filter out workers which have no local job worker available.
    List<String> missingJobWorkerHosts = new ArrayList<>();
    List<BlockWorkerInfo> workers = new ArrayList<>();
    for (BlockWorkerInfo worker : context.getFsContext().getCachedWorkers()) {
        if (jobWorkersByAddress.containsKey(worker.getNetAddress().getHost())) {
            String workerHost = worker.getNetAddress().getHost().toUpperCase();
            if (!isEmptySet(config.getExcludedWorkerSet()) && config.getExcludedWorkerSet().contains(workerHost)) {
                continue;
            }
            // If specified the locality id, the candidate worker must match one at least
            boolean match = false;
            if (worker.getNetAddress().getTieredIdentity().getTiers() != null) {
                if (!(isEmptySet(config.getLocalityIds()) && isEmptySet(config.getExcludedLocalityIds()))) {
                    boolean exclude = false;
                    for (LocalityTier tier : worker.getNetAddress().getTieredIdentity().getTiers()) {
                        if (!isEmptySet(config.getExcludedLocalityIds()) && config.getExcludedLocalityIds().contains(tier.getValue().toUpperCase())) {
                            exclude = true;
                            break;
                        }
                        if (!isEmptySet(config.getLocalityIds()) && config.getLocalityIds().contains(tier.getValue().toUpperCase())) {
                            match = true;
                            break;
                        }
                    }
                    if (exclude) {
                        continue;
                    }
                }
            }
            // Or user specified neither worker-set nor locality id
            if ((isEmptySet(config.getWorkerSet()) && isEmptySet(config.getLocalityIds())) || match || (!isEmptySet(config.getWorkerSet()) && config.getWorkerSet().contains(workerHost))) {
                workers.add(worker);
            }
        } else {
            LOG.warn("Worker on host {} has no local job worker", worker.getNetAddress().getHost());
            missingJobWorkerHosts.add(worker.getNetAddress().getHost());
        }
    }
    // Mapping from worker to block ids which that worker is supposed to load.
    Multimap<WorkerInfo, LoadTask> assignments = LinkedListMultimap.create();
    AlluxioURI uri = new AlluxioURI(config.getFilePath());
    for (FileBlockInfo blockInfo : context.getFileSystem().getStatus(uri).getFileBlockInfos()) {
        List<BlockWorkerInfo> workersWithoutBlock = getWorkersWithoutBlock(workers, blockInfo);
        int neededReplicas = config.getReplication() - blockInfo.getBlockInfo().getLocations().size();
        if (workersWithoutBlock.size() < neededReplicas) {
            String missingJobWorkersMessage = "";
            if (!missingJobWorkerHosts.isEmpty()) {
                missingJobWorkersMessage = ". The following workers could not be used because they have " + "no local job workers: " + missingJobWorkerHosts;
            }
            throw new FailedPreconditionException(String.format("Failed to find enough block workers to replicate to. Needed %s but only found %s. " + "Available workers without the block: %s" + missingJobWorkersMessage, neededReplicas, workersWithoutBlock.size(), workersWithoutBlock));
        }
        Collections.shuffle(workersWithoutBlock);
        for (int i = 0; i < neededReplicas; i++) {
            String address = workersWithoutBlock.get(i).getNetAddress().getHost();
            WorkerInfo jobWorker = jobWorkersByAddress.get(address);
            assignments.put(jobWorker, new LoadTask(blockInfo.getBlockInfo().getBlockId(), workersWithoutBlock.get(i).getNetAddress()));
        }
    }
    Set<Pair<WorkerInfo, ArrayList<LoadTask>>> result = Sets.newHashSet();
    for (Map.Entry<WorkerInfo, Collection<LoadTask>> assignment : assignments.asMap().entrySet()) {
        Collection<LoadTask> loadTasks = assignment.getValue();
        List<List<LoadTask>> partitionedTasks = CommonUtils.partition(Lists.newArrayList(loadTasks), JOBS_PER_WORKER);
        for (List<LoadTask> tasks : partitionedTasks) {
            if (!tasks.isEmpty()) {
                result.add(new Pair<>(assignment.getKey(), Lists.newArrayList(tasks)));
            }
        }
    }
    return result;
}
Also used : FailedPreconditionException(alluxio.exception.status.FailedPreconditionException) WorkerNetAddress(alluxio.wire.WorkerNetAddress) LoggerFactory(org.slf4j.LoggerFactory) BlockWorkerInfo(alluxio.client.block.BlockWorkerInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) Multimap(com.google.common.collect.Multimap) ArrayList(java.util.ArrayList) AbstractVoidPlanDefinition(alluxio.job.plan.AbstractVoidPlanDefinition) JobUtils(alluxio.job.util.JobUtils) SerializableVoid(alluxio.job.util.SerializableVoid) Lists(com.google.common.collect.Lists) Constants(alluxio.Constants) RunTaskContext(alluxio.job.RunTaskContext) WorkerInfo(alluxio.wire.WorkerInfo) AlluxioURI(alluxio.AlluxioURI) Map(java.util.Map) LinkedListMultimap(com.google.common.collect.LinkedListMultimap) LocalityTier(alluxio.wire.TieredIdentity.LocalityTier) Logger(org.slf4j.Logger) Collection(java.util.Collection) MoreObjects(com.google.common.base.MoreObjects) Set(java.util.Set) SelectExecutorsContext(alluxio.job.SelectExecutorsContext) Pair(alluxio.collections.Pair) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Serializable(java.io.Serializable) LoadTask(alluxio.job.plan.load.LoadDefinition.LoadTask) BlockLocation(alluxio.wire.BlockLocation) URIStatus(alluxio.client.file.URIStatus) List(java.util.List) Collections(java.util.Collections) CommonUtils(alluxio.util.CommonUtils) NotThreadSafe(javax.annotation.concurrent.NotThreadSafe) ArrayList(java.util.ArrayList) BlockWorkerInfo(alluxio.client.block.BlockWorkerInfo) WorkerInfo(alluxio.wire.WorkerInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) ArrayList(java.util.ArrayList) List(java.util.List) Pair(alluxio.collections.Pair) LocalityTier(alluxio.wire.TieredIdentity.LocalityTier) LoadTask(alluxio.job.plan.load.LoadDefinition.LoadTask) BlockWorkerInfo(alluxio.client.block.BlockWorkerInfo) FailedPreconditionException(alluxio.exception.status.FailedPreconditionException) Collection(java.util.Collection) Map(java.util.Map) AlluxioURI(alluxio.AlluxioURI)

Example 8 with SelectExecutorsContext

use of alluxio.job.SelectExecutorsContext in project alluxio by Alluxio.

the class ReplicateDefinitionTest method selectExecutorsTestHelper.

/**
 * Helper function to select executors.
 *
 * @param numReplicas how many replicas to replicate or evict
 * @param workerInfoList a list of current available job workers
 * @return the selection result
 */
private Set<Pair<WorkerInfo, SerializableVoid>> selectExecutorsTestHelper(int numReplicas, List<WorkerInfo> workerInfoList) throws Exception {
    ReplicateConfig config = new ReplicateConfig(TEST_PATH, TEST_BLOCK_ID, numReplicas);
    ReplicateDefinition definition = new ReplicateDefinition();
    return definition.selectExecutors(config, workerInfoList, new SelectExecutorsContext(1, mMockJobServerContext));
}
Also used : SelectExecutorsContext(alluxio.job.SelectExecutorsContext)

Example 9 with SelectExecutorsContext

use of alluxio.job.SelectExecutorsContext in project alluxio by Alluxio.

the class CompactDefinitionSelectExecutorsTest method testExecutorsParallel.

@Test
public void testExecutorsParallel() throws Exception {
    int tasksPerWorker = 10;
    int numCompactedFiles = 100;
    int totalFiles = 5000;
    PartitionInfo mockPartitionInfo = mock(PartitionInfo.class);
    when(mockPartitionInfo.getFormat(any())).thenReturn(Format.CSV);
    CompactConfig config = new CompactConfig(mockPartitionInfo, INPUT_DIR, mockPartitionInfo, OUTPUT_DIR, numCompactedFiles, 2 * FileUtils.ONE_GB);
    List<URIStatus> inputFiles = new ArrayList<>();
    for (int i = 0; i < totalFiles; i++) {
        inputFiles.add(newFile(Integer.toString(i)));
    }
    when(mMockFileSystem.listStatus(new AlluxioURI(INPUT_DIR))).thenReturn(inputFiles);
    Set<Pair<WorkerInfo, ArrayList<CompactTask>>> result = new CompactDefinition().selectExecutors(config, SelectExecutorsTest.JOB_WORKERS, new SelectExecutorsContext(1, new JobServerContext(mMockFileSystem, mMockFileSystemContext, mMockUfsManager)));
    assertEquals(JOB_WORKERS.size() * tasksPerWorker, result.size());
    int allCompactTasks = 0;
    for (Pair<WorkerInfo, ArrayList<CompactTask>> tasks : result) {
        allCompactTasks += tasks.getSecond().size();
    }
    assertEquals(numCompactedFiles, allCompactTasks);
}
Also used : JobServerContext(alluxio.job.JobServerContext) ArrayList(java.util.ArrayList) WorkerInfo(alluxio.wire.WorkerInfo) URIStatus(alluxio.client.file.URIStatus) SelectExecutorsContext(alluxio.job.SelectExecutorsContext) AlluxioURI(alluxio.AlluxioURI) Pair(alluxio.collections.Pair) Test(org.junit.Test) SelectExecutorsTest(alluxio.job.plan.SelectExecutorsTest)

Example 10 with SelectExecutorsContext

use of alluxio.job.SelectExecutorsContext in project alluxio by Alluxio.

the class LoadDefinitionTest method loadedBySpecifiedHost.

private void loadedBySpecifiedHost(Set<String> workerSet, Set<String> excludedWorkerSet, Set<String> localityIds, Set<String> excludedLocalityIds, Set<Long> workerIds) throws Exception {
    int numBlocks = 10;
    createFileWithNoLocations(TEST_URI, numBlocks);
    LoadConfig config = new LoadConfig(TEST_URI, 1, workerSet, excludedWorkerSet, localityIds, excludedLocalityIds, false);
    Set<Pair<WorkerInfo, ArrayList<LoadTask>>> assignments = new LoadDefinition().selectExecutors(config, JOB_WORKERS, new SelectExecutorsContext(1, mJobServerContext));
    // Check that we are loading the right number of blocks.
    int totalBlockLoads = 0;
    for (Pair<WorkerInfo, ArrayList<LoadTask>> assignment : assignments) {
        totalBlockLoads += assignment.getSecond().size();
        Assert.assertTrue(workerIds.contains(assignment.getFirst().getId()));
    }
    Assert.assertEquals(numBlocks, totalBlockLoads);
}
Also used : LoadTask(alluxio.job.plan.load.LoadDefinition.LoadTask) ArrayList(java.util.ArrayList) BlockWorkerInfo(alluxio.client.block.BlockWorkerInfo) WorkerInfo(alluxio.wire.WorkerInfo) SelectExecutorsContext(alluxio.job.SelectExecutorsContext) Pair(alluxio.collections.Pair)

Aggregations

SelectExecutorsContext (alluxio.job.SelectExecutorsContext)16 Pair (alluxio.collections.Pair)10 WorkerInfo (alluxio.wire.WorkerInfo)10 Test (org.junit.Test)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 BlockWorkerInfo (alluxio.client.block.BlockWorkerInfo)7 ArrayList (java.util.ArrayList)6 AlluxioURI (alluxio.AlluxioURI)5 URIStatus (alluxio.client.file.URIStatus)5 LoadTask (alluxio.job.plan.load.LoadDefinition.LoadTask)5 WorkerNetAddress (alluxio.wire.WorkerNetAddress)5 BlockInfo (alluxio.wire.BlockInfo)4 FileBlockInfo (alluxio.wire.FileBlockInfo)4 Map (java.util.Map)4 BlockLocation (alluxio.wire.BlockLocation)3 FileInfo (alluxio.wire.FileInfo)3 JobServerContext (alluxio.job.JobServerContext)2 RunTaskContext (alluxio.job.RunTaskContext)2 SelectExecutorsTest (alluxio.job.plan.SelectExecutorsTest)2 BatchedJobDefinition (alluxio.job.plan.batch.BatchedJobDefinition)2