Search in sources :

Example 31 with BlockLocation

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

the class EvictDefinitionTest method selectExecutorsBothWorkers.

@Test
public void selectExecutorsBothWorkers() throws Exception {
    Set<Pair<WorkerInfo, SerializableVoid>> result = selectExecutorsTestHelper(Lists.newArrayList(new BlockLocation().setWorkerAddress(ADDRESS_1), new BlockLocation().setWorkerAddress(ADDRESS_2)), 3, Lists.newArrayList(WORKER_INFO_1, WORKER_INFO_2, WORKER_INFO_3));
    Set<Pair<WorkerInfo, SerializableVoid>> expected = Sets.newHashSet();
    expected.add(new Pair<>(WORKER_INFO_1, null));
    expected.add(new Pair<>(WORKER_INFO_2, null));
    // Expect both workers having this block should be selected
    Assert.assertEquals(expected, result);
}
Also used : BlockLocation(alluxio.wire.BlockLocation) Pair(alluxio.collections.Pair) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 32 with BlockLocation

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

the class ReplicateDefinitionTest method selectExecutorsInsufficientWorkerValid.

@Test
public void selectExecutorsInsufficientWorkerValid() throws Exception {
    mTestBlockInfo.setLocations(Lists.newArrayList(new BlockLocation().setWorkerAddress(ADDRESS_1)));
    Set<Pair<WorkerInfo, SerializableVoid>> result = selectExecutorsTestHelper(2, Lists.newArrayList(WORKER_INFO_1, WORKER_INFO_2));
    Set<Pair<WorkerInfo, SerializableVoid>> expected = Sets.newHashSet();
    expected.add(new Pair<>(WORKER_INFO_2, null));
    // select the only worker left though more copies are requested
    assertEquals(expected, result);
}
Also used : BlockLocation(alluxio.wire.BlockLocation) Pair(alluxio.collections.Pair) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 33 with BlockLocation

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

the class ReplicateDefinitionTest method runTaskReplicateTestHelper.

/**
 * Helper function to run a replicate task.
 *
 * @param blockWorkers available block workers
 * @param mockInStream mock blockInStream returned by the Block Store
 * @param mockOutStream mock blockOutStream returned by the Block Store
 */
private void runTaskReplicateTestHelper(List<BlockWorkerInfo> blockWorkers, BlockInStream mockInStream, BlockOutStream mockOutStream) throws Exception {
    when(mMockFileSystem.getStatus(any(AlluxioURI.class))).thenReturn(mTestStatus);
    when(mMockFileSystemContext.getCachedWorkers()).thenReturn(blockWorkers);
    when(mMockBlockStore.getInStream(anyLong(), any(InStreamOptions.class))).thenReturn(mockInStream);
    when(mMockBlockStore.getInStream(any(BlockInfo.class), any(InStreamOptions.class), any(Map.class))).thenReturn(mockInStream);
    PowerMockito.mockStatic(BlockInStream.class);
    when(BlockInStream.create(any(FileSystemContext.class), any(BlockInfo.class), any(WorkerNetAddress.class), any(BlockInStreamSource.class), any(InStreamOptions.class))).thenReturn(mockInStream);
    when(mMockBlockStore.getOutStream(eq(TEST_BLOCK_ID), eq(TEST_BLOCK_SIZE), eq(LOCAL_ADDRESS), any(OutStreamOptions.class))).thenReturn(mockOutStream);
    when(mMockBlockStore.getInfo(TEST_BLOCK_ID)).thenReturn(mTestBlockInfo.setLocations(Lists.newArrayList(new BlockLocation().setWorkerAddress(ADDRESS_1))));
    PowerMockito.mockStatic(AlluxioBlockStore.class);
    when(AlluxioBlockStore.create(any(FileSystemContext.class))).thenReturn(mMockBlockStore);
    ReplicateConfig config = new ReplicateConfig(TEST_PATH, TEST_BLOCK_ID, 1);
    ReplicateDefinition definition = new ReplicateDefinition();
    definition.runTask(config, null, new RunTaskContext(1, 1, mMockJobServerContext));
}
Also used : OutStreamOptions(alluxio.client.file.options.OutStreamOptions) RunTaskContext(alluxio.job.RunTaskContext) BlockInfo(alluxio.wire.BlockInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) WorkerNetAddress(alluxio.wire.WorkerNetAddress) BlockInStreamSource(alluxio.client.block.stream.BlockInStream.BlockInStreamSource) FileSystemContext(alluxio.client.file.FileSystemContext) BlockLocation(alluxio.wire.BlockLocation) Map(java.util.Map) AlluxioURI(alluxio.AlluxioURI) InStreamOptions(alluxio.client.file.options.InStreamOptions)

Example 34 with BlockLocation

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

the class AlluxioBlockStore method getDataSourceAndType.

/**
 * Gets the data source and type of data source of a block. This method is primarily responsible
 * for determining the data source and type of data source. It takes a map of failed workers and
 * their most recently failed time and tries to update it when BlockInStream created failed,
 * attempting to avoid reading from a recently failed worker.
 *
 * @param info the info of the block to read
 * @param status the URIStatus associated with the read request
 * @param policy the policy determining the Alluxio worker location
 * @param failedWorkers the map of workers address to most recent failure time
 * @return the data source and type of data source of the block
 */
public Pair<WorkerNetAddress, BlockInStreamSource> getDataSourceAndType(BlockInfo info, URIStatus status, BlockLocationPolicy policy, Map<WorkerNetAddress, Long> failedWorkers) throws IOException {
    List<BlockLocation> locations = info.getLocations();
    List<BlockWorkerInfo> blockWorkerInfo = Collections.EMPTY_LIST;
    // Initial target workers to read the block given the block locations.
    Set<WorkerNetAddress> workerPool;
    // Note that, it is possible that the blocks have been written as UFS blocks
    if (status.isPersisted() || status.getPersistenceState().equals("TO_BE_PERSISTED")) {
        blockWorkerInfo = mContext.getCachedWorkers();
        if (blockWorkerInfo.isEmpty()) {
            throw new UnavailableException(ExceptionMessage.NO_WORKER_AVAILABLE.getMessage());
        }
        workerPool = blockWorkerInfo.stream().map(BlockWorkerInfo::getNetAddress).collect(toSet());
    } else {
        if (locations.isEmpty()) {
            blockWorkerInfo = mContext.getCachedWorkers();
            if (blockWorkerInfo.isEmpty()) {
                throw new UnavailableException(ExceptionMessage.NO_WORKER_AVAILABLE.getMessage());
            }
            throw new UnavailableException(ExceptionMessage.BLOCK_UNAVAILABLE.getMessage(info.getBlockId()));
        }
        workerPool = locations.stream().map(BlockLocation::getWorkerAddress).collect(toSet());
    }
    // Workers to read the block, after considering failed workers.
    Set<WorkerNetAddress> workers = handleFailedWorkers(workerPool, failedWorkers);
    // TODO(calvin, jianjian): Consider containing these two variables in one object
    BlockInStreamSource dataSourceType = null;
    WorkerNetAddress dataSource = null;
    locations = locations.stream().filter(location -> workers.contains(location.getWorkerAddress())).collect(toList());
    // First try to read data from Alluxio
    if (!locations.isEmpty()) {
        // TODO(calvin): Get location via a policy
        List<WorkerNetAddress> tieredLocations = locations.stream().map(location -> location.getWorkerAddress()).collect(toList());
        Collections.shuffle(tieredLocations);
        Optional<Pair<WorkerNetAddress, Boolean>> nearest = BlockLocationUtils.nearest(mTieredIdentity, tieredLocations, mContext.getClusterConf());
        if (nearest.isPresent()) {
            dataSource = nearest.get().getFirst();
            dataSourceType = nearest.get().getSecond() ? mContext.hasProcessLocalWorker() ? BlockInStreamSource.PROCESS_LOCAL : BlockInStreamSource.NODE_LOCAL : BlockInStreamSource.REMOTE;
        }
    }
    // Can't get data from Alluxio, get it from the UFS instead
    if (dataSource == null) {
        dataSourceType = BlockInStreamSource.UFS;
        Preconditions.checkNotNull(policy, PreconditionMessage.UFS_READ_LOCATION_POLICY_UNSPECIFIED);
        blockWorkerInfo = blockWorkerInfo.stream().filter(workerInfo -> workers.contains(workerInfo.getNetAddress())).collect(toList());
        GetWorkerOptions getWorkerOptions = GetWorkerOptions.defaults().setBlockInfo(new BlockInfo().setBlockId(info.getBlockId()).setLength(info.getLength()).setLocations(locations)).setBlockWorkerInfos(blockWorkerInfo);
        dataSource = policy.getWorker(getWorkerOptions);
        if (dataSource != null) {
            if (mContext.hasProcessLocalWorker() && dataSource.equals(mContext.getNodeLocalWorker())) {
                dataSourceType = BlockInStreamSource.PROCESS_LOCAL;
                LOG.debug("Create BlockInStream to read data from UFS through process local worker {}", dataSource);
            } else {
                LOG.debug("Create BlockInStream to read data from UFS through worker {} " + "(client embedded in local worker process: {}," + "client co-located with worker in different processes: {}, " + "local worker address: {})", dataSource, mContext.hasProcessLocalWorker(), mContext.hasNodeLocalWorker(), mContext.hasNodeLocalWorker() ? mContext.getNodeLocalWorker() : "N/A");
            }
        }
    }
    if (dataSource == null) {
        throw new UnavailableException(ExceptionMessage.NO_WORKER_AVAILABLE.getMessage());
    }
    return new Pair<>(dataSource, dataSourceType);
}
Also used : BlockLocationPolicy(alluxio.client.block.policy.BlockLocationPolicy) WorkerNetAddress(alluxio.wire.WorkerNetAddress) LoggerFactory(org.slf4j.LoggerFactory) BlockInfo(alluxio.wire.BlockInfo) TieredIdentity(alluxio.wire.TieredIdentity) HashMap(java.util.HashMap) BlockOutStream(alluxio.client.block.stream.BlockOutStream) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) CloseableResource(alluxio.resource.CloseableResource) Map(java.util.Map) BlockLocationUtils(alluxio.client.block.util.BlockLocationUtils) DataWriter(alluxio.client.block.stream.DataWriter) PreconditionMessage(alluxio.exception.PreconditionMessage) TieredIdentityFactory(alluxio.network.TieredIdentityFactory) Collectors.toSet(java.util.stream.Collectors.toSet) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) BlockInStream(alluxio.client.block.stream.BlockInStream) InStreamOptions(alluxio.client.file.options.InStreamOptions) ExceptionMessage(alluxio.exception.ExceptionMessage) OutStreamOptions(alluxio.client.file.options.OutStreamOptions) Set(java.util.Set) IOException(java.io.IOException) ThreadSafe(javax.annotation.concurrent.ThreadSafe) Pair(alluxio.collections.Pair) GetWorkerOptions(alluxio.client.block.policy.options.GetWorkerOptions) BlockLocation(alluxio.wire.BlockLocation) Collectors.toList(java.util.stream.Collectors.toList) URIStatus(alluxio.client.file.URIStatus) List(java.util.List) FileSystemContext(alluxio.client.file.FileSystemContext) BlockInStreamSource(alluxio.client.block.stream.BlockInStream.BlockInStreamSource) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) WriteType(alluxio.client.WriteType) Collections(java.util.Collections) UnavailableException(alluxio.exception.status.UnavailableException) UnavailableException(alluxio.exception.status.UnavailableException) BlockInStreamSource(alluxio.client.block.stream.BlockInStream.BlockInStreamSource) GetWorkerOptions(alluxio.client.block.policy.options.GetWorkerOptions) BlockLocation(alluxio.wire.BlockLocation) WorkerNetAddress(alluxio.wire.WorkerNetAddress) BlockInfo(alluxio.wire.BlockInfo) Pair(alluxio.collections.Pair)

Example 35 with BlockLocation

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

the class UIFileBlockInfo method addLocations.

private void addLocations(FileBlockInfo fileBlockInfo) {
    Set<String> locations = new HashSet<>();
    // add alluxio locations
    for (BlockLocation location : fileBlockInfo.getBlockInfo().getLocations()) {
        locations.add(location.getWorkerAddress().getHost());
    }
    // add underFS locations
    for (String location : fileBlockInfo.getUfsLocations()) {
        locations.add(HostAndPort.fromString(location).getHost());
    }
    mLocations.addAll(locations);
}
Also used : BlockLocation(alluxio.wire.BlockLocation) HashSet(java.util.HashSet)

Aggregations

BlockLocation (alluxio.wire.BlockLocation)42 Test (org.junit.Test)22 BlockInfo (alluxio.wire.BlockInfo)21 FileBlockInfo (alluxio.wire.FileBlockInfo)17 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)17 Pair (alluxio.collections.Pair)15 WorkerNetAddress (alluxio.wire.WorkerNetAddress)14 FileInfo (alluxio.wire.FileInfo)13 URIStatus (alluxio.client.file.URIStatus)12 ArrayList (java.util.ArrayList)11 AlluxioURI (alluxio.AlluxioURI)10 InStreamOptions (alluxio.client.file.options.InStreamOptions)8 IOException (java.io.IOException)8 WorkerInfo (alluxio.wire.WorkerInfo)7 HashSet (java.util.HashSet)7 UnavailableException (alluxio.exception.status.UnavailableException)6 Map (java.util.Map)6 AlluxioBlockStore (alluxio.client.block.AlluxioBlockStore)5 OutStreamOptions (alluxio.client.file.options.OutStreamOptions)5 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)5