Search in sources :

Example 6 with LocalityTier

use of alluxio.wire.TieredIdentity.LocalityTier in project alluxio by Alluxio.

the class TieredIdentityFactoryTest method outOfOrderScript.

@Test
public void outOfOrderScript() throws Exception {
    String scriptPath = setupScript("rack=myrack,node=myhost", mFolder.newFile());
    try (Closeable c = new ConfigurationRule(ImmutableMap.of(PropertyKey.LOCALITY_SCRIPT, scriptPath), mConfiguration).toResource()) {
        TieredIdentity identity = TieredIdentityFactory.create(mConfiguration);
        TieredIdentity expected = new TieredIdentity(Arrays.asList(new LocalityTier("node", "myhost"), new LocalityTier("rack", "myrack")));
        assertEquals(expected, identity);
    }
}
Also used : TieredIdentity(alluxio.wire.TieredIdentity) Closeable(java.io.Closeable) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ConfigurationRule(alluxio.ConfigurationRule) LocalityTier(alluxio.wire.TieredIdentity.LocalityTier) Test(org.junit.Test)

Example 7 with LocalityTier

use of alluxio.wire.TieredIdentity.LocalityTier 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 LocalityTier

use of alluxio.wire.TieredIdentity.LocalityTier in project alluxio by Alluxio.

the class ClientTestUtils method worker.

public static BlockWorkerInfo worker(long capacity, long used, String node, String rack) {
    WorkerNetAddress address = new WorkerNetAddress();
    List<LocalityTier> tiers = new ArrayList<>();
    if (node != null && !node.isEmpty()) {
        address.setHost(node);
        tiers.add(new LocalityTier(Constants.LOCALITY_NODE, node));
    }
    if (rack != null && !rack.isEmpty()) {
        tiers.add(new LocalityTier(Constants.LOCALITY_RACK, rack));
    }
    address.setTieredIdentity(new TieredIdentity(tiers));
    return new BlockWorkerInfo(address, capacity, used);
}
Also used : WorkerNetAddress(alluxio.wire.WorkerNetAddress) TieredIdentity(alluxio.wire.TieredIdentity) ArrayList(java.util.ArrayList) BlockWorkerInfo(alluxio.client.block.BlockWorkerInfo) LocalityTier(alluxio.wire.TieredIdentity.LocalityTier)

Example 9 with LocalityTier

use of alluxio.wire.TieredIdentity.LocalityTier in project alluxio by Alluxio.

the class TieredIdentityFactoryTest method defaultConf.

@Test
public void defaultConf() throws Exception {
    TieredIdentity identity = TieredIdentityFactory.create(mConfiguration);
    TieredIdentity expected = new TieredIdentity(Arrays.asList(new LocalityTier("node", NetworkAddressUtils.getLocalNodeName(mConfiguration)), new LocalityTier("rack", null)));
    assertEquals(expected, identity);
}
Also used : TieredIdentity(alluxio.wire.TieredIdentity) LocalityTier(alluxio.wire.TieredIdentity.LocalityTier) Test(org.junit.Test)

Example 10 with LocalityTier

use of alluxio.wire.TieredIdentity.LocalityTier in project alluxio by Alluxio.

the class TieredIdentityFactory method fromString.

/**
 * @param identityString tiered identity string to parse
 * @param conf Alluxio configuration
 * @return the parsed tiered identity
 */
public static TieredIdentity fromString(String identityString, AlluxioConfiguration conf) throws IOException {
    Set<String> allTiers = Sets.newHashSet(conf.getList(PropertyKey.LOCALITY_ORDER, ","));
    Map<String, String> tiers = new HashMap<>();
    for (String tier : identityString.split(",")) {
        String[] parts = tier.split("=");
        if (parts.length != 2) {
            throw new IOException(String.format("Failed to parse tiered identity. The value should be a comma-separated list " + "of key=value pairs, but was %s", identityString));
        }
        String key = parts[0].trim();
        if (tiers.containsKey(key)) {
            throw new IOException(String.format("Encountered repeated tier definition for %s when parsing tiered identity from string " + "%s", key, identityString));
        }
        if (!allTiers.contains(key)) {
            throw new IOException(String.format("Unrecognized tier: %s. The tiers defined by %s are %s", key, PropertyKey.LOCALITY_ORDER.toString(), allTiers));
        }
        tiers.put(key, parts[1].trim());
    }
    List<LocalityTier> tieredIdentity = new ArrayList<>();
    for (String localityTier : conf.getList(PropertyKey.LOCALITY_ORDER, ",")) {
        String value = tiers.getOrDefault(localityTier, null);
        tieredIdentity.add(new LocalityTier(localityTier, value));
    }
    return new TieredIdentity(tieredIdentity);
}
Also used : HashMap(java.util.HashMap) TieredIdentity(alluxio.wire.TieredIdentity) ArrayList(java.util.ArrayList) IOException(java.io.IOException) LocalityTier(alluxio.wire.TieredIdentity.LocalityTier)

Aggregations

LocalityTier (alluxio.wire.TieredIdentity.LocalityTier)12 TieredIdentity (alluxio.wire.TieredIdentity)8 Test (org.junit.Test)7 ConfigurationRule (alluxio.ConfigurationRule)4 Closeable (java.io.Closeable)4 ArrayList (java.util.ArrayList)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 BlockWorkerInfo (alluxio.client.block.BlockWorkerInfo)2 WorkerNetAddress (alluxio.wire.WorkerNetAddress)2 AlluxioURI (alluxio.AlluxioURI)1 Constants (alluxio.Constants)1 URIStatus (alluxio.client.file.URIStatus)1 Pair (alluxio.collections.Pair)1 FailedPreconditionException (alluxio.exception.status.FailedPreconditionException)1 RunTaskContext (alluxio.job.RunTaskContext)1 SelectExecutorsContext (alluxio.job.SelectExecutorsContext)1 AbstractVoidPlanDefinition (alluxio.job.plan.AbstractVoidPlanDefinition)1 LoadTask (alluxio.job.plan.load.LoadDefinition.LoadTask)1 JobUtils (alluxio.job.util.JobUtils)1 SerializableVoid (alluxio.job.util.SerializableVoid)1