Search in sources :

Example 56 with WorkerInfo

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

the class PersistDefinitionTest method selectExecutorsMissingLocationTest.

@Test
public void selectExecutorsMissingLocationTest() throws Exception {
    AlluxioURI uri = new AlluxioURI("/test");
    PersistConfig config = new PersistConfig(uri.getPath(), -1, true, "");
    long blockId = 1;
    BlockInfo blockInfo = new BlockInfo().setBlockId(blockId);
    FileBlockInfo fileBlockInfo = new FileBlockInfo().setBlockInfo(blockInfo);
    FileInfo testFileInfo = new FileInfo();
    testFileInfo.setFileBlockInfos(Lists.newArrayList(fileBlockInfo));
    Mockito.when(mMockFileSystem.getStatus(uri)).thenReturn(new URIStatus(testFileInfo));
    try {
        new PersistDefinition().selectExecutors(config, Lists.newArrayList(new WorkerInfo()), new SelectExecutorsContext(1, mJobServerContext));
    } catch (Exception e) {
        Assert.assertEquals("Block " + blockId + " does not exist", e.getMessage());
    }
}
Also used : FileInfo(alluxio.wire.FileInfo) BlockInfo(alluxio.wire.BlockInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) WorkerInfo(alluxio.wire.WorkerInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) URIStatus(alluxio.client.file.URIStatus) SelectExecutorsContext(alluxio.job.SelectExecutorsContext) AlluxioURI(alluxio.AlluxioURI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 57 with WorkerInfo

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

the class BatchedJobDefinitionTest method batchLoad.

@Test
public void batchLoad() throws Exception {
    int numBlocks = 2;
    int replication = 2;
    int batchSize = 2;
    HashSet<Map<String, String>> configs = Sets.newHashSet();
    for (int i = 0; i < batchSize; i++) {
        createFileWithNoLocations(TEST_URI + i, numBlocks);
        LoadConfig loadConfig = new LoadConfig(TEST_URI + i, replication, Collections.EMPTY_SET, Collections.EMPTY_SET, Collections.EMPTY_SET, Collections.EMPTY_SET, true);
        ObjectMapper oMapper = new ObjectMapper();
        Map<String, String> map = oMapper.convertValue(loadConfig, Map.class);
        configs.add(map);
    }
    BatchedJobConfig config = new BatchedJobConfig("Load", configs);
    Set<Pair<WorkerInfo, BatchedJobDefinition.BatchedJobTask>> assignments = new BatchedJobDefinition().selectExecutors(config, JOB_WORKERS, new SelectExecutorsContext(1, mJobServerContext));
    // Check that we are loading the right number of blocks.
    int totalBlockLoads = 0;
    for (Pair<WorkerInfo, BatchedJobDefinition.BatchedJobTask> assignment : assignments) {
        ArrayList<LoadTask> second = (ArrayList<LoadTask>) assignment.getSecond().getJobTaskArgs();
        totalBlockLoads += second.size();
    }
    Assert.assertEquals(numBlocks * replication * batchSize, totalBlockLoads);
}
Also used : BatchedJobDefinition(alluxio.job.plan.batch.BatchedJobDefinition) ArrayList(java.util.ArrayList) BlockWorkerInfo(alluxio.client.block.BlockWorkerInfo) WorkerInfo(alluxio.wire.WorkerInfo) SelectExecutorsContext(alluxio.job.SelectExecutorsContext) LoadTask(alluxio.job.plan.load.LoadDefinition.LoadTask) LoadConfig(alluxio.job.plan.load.LoadConfig) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Pair(alluxio.collections.Pair) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 58 with WorkerInfo

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

the class FileSystemContext method getWorkerAddresses.

/**
 * @return if there are any local workers, the returned list will ONLY contain the local workers,
 *         otherwise a list of all remote workers will be returned
 */
private List<WorkerNetAddress> getWorkerAddresses() throws IOException {
    List<WorkerInfo> infos;
    BlockMasterClient blockMasterClient = mBlockMasterClientPool.acquire();
    try {
        infos = blockMasterClient.getWorkerInfoList();
    } finally {
        mBlockMasterClientPool.release(blockMasterClient);
    }
    if (infos.isEmpty()) {
        throw new UnavailableException(ExceptionMessage.NO_WORKER_AVAILABLE.getMessage());
    }
    // Convert the worker infos into net addresses, if there are local addresses, only keep those
    List<WorkerNetAddress> workerNetAddresses = new ArrayList<>();
    List<WorkerNetAddress> localWorkerNetAddresses = new ArrayList<>();
    String localHostname = NetworkAddressUtils.getClientHostName(getClusterConf());
    for (WorkerInfo info : infos) {
        WorkerNetAddress netAddress = info.getAddress();
        if (netAddress.getHost().equals(localHostname)) {
            localWorkerNetAddresses.add(netAddress);
        }
        workerNetAddresses.add(netAddress);
    }
    return localWorkerNetAddresses.isEmpty() ? workerNetAddresses : localWorkerNetAddresses;
}
Also used : BlockMasterClient(alluxio.client.block.BlockMasterClient) WorkerNetAddress(alluxio.wire.WorkerNetAddress) UnavailableException(alluxio.exception.status.UnavailableException) ArrayList(java.util.ArrayList) BlockWorkerInfo(alluxio.client.block.BlockWorkerInfo) WorkerInfo(alluxio.wire.WorkerInfo)

Example 59 with WorkerInfo

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

the class DefaultAsyncPersistHandler method getWorkerStoringFile.

/**
 * Gets a worker where the given file is stored.
 *
 * @param path the path to the file
 * @return the id of the storing worker
 * @throws FileDoesNotExistException when the file does not exist on any worker
 * @throws AccessControlException if permission checking fails
 */
// TODO(calvin): Propagate the exceptions in certain cases
private long getWorkerStoringFile(AlluxioURI path) throws FileDoesNotExistException, AccessControlException, UnavailableException {
    long fileId = mFileSystemMasterView.getFileId(path);
    try {
        if (mFileSystemMasterView.getFileInfo(fileId).getLength() == 0) {
            // if file is empty, return any worker
            List<WorkerInfo> workerInfoList = mFileSystemMasterView.getWorkerInfoList();
            if (workerInfoList.isEmpty()) {
                LOG.error("No worker is available");
                return IdUtils.INVALID_WORKER_ID;
            }
            // randomly pick a worker
            int index = new Random().nextInt(workerInfoList.size());
            return workerInfoList.get(index).getId();
        }
    } catch (UnavailableException e) {
        return IdUtils.INVALID_WORKER_ID;
    }
    Map<Long, Integer> workerBlockCounts = new HashMap<>();
    List<FileBlockInfo> blockInfoList;
    try {
        blockInfoList = mFileSystemMasterView.getFileBlockInfoList(path);
        for (FileBlockInfo fileBlockInfo : blockInfoList) {
            for (BlockLocation blockLocation : fileBlockInfo.getBlockInfo().getLocations()) {
                if (workerBlockCounts.containsKey(blockLocation.getWorkerId())) {
                    workerBlockCounts.put(blockLocation.getWorkerId(), workerBlockCounts.get(blockLocation.getWorkerId()) + 1);
                } else {
                    workerBlockCounts.put(blockLocation.getWorkerId(), 1);
                }
                // all the blocks of a file must be stored on the same worker
                if (workerBlockCounts.get(blockLocation.getWorkerId()) == blockInfoList.size()) {
                    return blockLocation.getWorkerId();
                }
            }
        }
    } catch (FileDoesNotExistException e) {
        LOG.error("The file {} to persist does not exist", path);
        return IdUtils.INVALID_WORKER_ID;
    } catch (InvalidPathException e) {
        LOG.error("The file {} to persist is invalid", path);
        return IdUtils.INVALID_WORKER_ID;
    } catch (UnavailableException e) {
        return IdUtils.INVALID_WORKER_ID;
    }
    if (workerBlockCounts.size() == 0) {
        LOG.error("The file " + path + " does not exist on any worker");
        return IdUtils.INVALID_WORKER_ID;
    }
    LOG.error("Not all the blocks of file {} stored on the same worker", path);
    return IdUtils.INVALID_WORKER_ID;
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) HashMap(java.util.HashMap) UnavailableException(alluxio.exception.status.UnavailableException) WorkerInfo(alluxio.wire.WorkerInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) BlockLocation(alluxio.wire.BlockLocation) InvalidPathException(alluxio.exception.InvalidPathException) Random(java.util.Random)

Example 60 with WorkerInfo

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

the class MasterWorkerInfo method generateWorkerInfo.

/**
 * Gets the selected field information for this worker.
 *
 * You should lock externally with {@link MasterWorkerInfo#lockWorkerMeta(EnumSet, boolean)}
 * with {@link WorkerMetaLockSection#USAGE} specified.
 * A shared lock is required.
 *
 * @param fieldRange the client selected fields
 * @param isLiveWorker the worker is live or not
 * @return generated worker information
 */
public WorkerInfo generateWorkerInfo(Set<WorkerInfoField> fieldRange, boolean isLiveWorker) {
    WorkerInfo info = new WorkerInfo();
    Set<WorkerInfoField> checkedFieldRange = fieldRange != null ? fieldRange : new HashSet<>(Arrays.asList(WorkerInfoField.values()));
    for (WorkerInfoField field : checkedFieldRange) {
        switch(field) {
            case ADDRESS:
                info.setAddress(mMeta.mWorkerAddress);
                break;
            case BLOCK_COUNT:
                info.setBlockCount(getBlockCount());
                break;
            case WORKER_CAPACITY_BYTES:
                info.setCapacityBytes(mUsage.mCapacityBytes);
                break;
            case WORKER_CAPACITY_BYTES_ON_TIERS:
                info.setCapacityBytesOnTiers(mUsage.mTotalBytesOnTiers);
                break;
            case ID:
                info.setId(mMeta.mId);
                break;
            case LAST_CONTACT_SEC:
                info.setLastContactSec((int) ((CommonUtils.getCurrentMs() - mLastUpdatedTimeMs.get()) / Constants.SECOND_MS));
                break;
            case START_TIME_MS:
                info.setStartTimeMs(mMeta.mStartTimeMs);
                break;
            case STATE:
                if (isLiveWorker) {
                    info.setState(LIVE_WORKER_STATE);
                } else {
                    info.setState(LOST_WORKER_STATE);
                }
                break;
            case WORKER_USED_BYTES:
                info.setUsedBytes(mUsage.mUsedBytes);
                break;
            case WORKER_USED_BYTES_ON_TIERS:
                info.setUsedBytesOnTiers(mUsage.mUsedBytesOnTiers);
                break;
            default:
                LOG.warn("Unrecognized worker info field: " + field);
        }
    }
    return info;
}
Also used : WorkerInfoField(alluxio.client.block.options.GetWorkerReportOptions.WorkerInfoField) WorkerInfo(alluxio.wire.WorkerInfo)

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