Search in sources :

Example 36 with BlockLocation

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

the class EvictDefinition method selectExecutors.

@Override
public Set<Pair<WorkerInfo, SerializableVoid>> selectExecutors(EvictConfig config, List<WorkerInfo> jobWorkerInfoList, SelectExecutorsContext context) throws Exception {
    Preconditions.checkArgument(!jobWorkerInfoList.isEmpty(), "No worker is available");
    long blockId = config.getBlockId();
    int numReplicas = config.getReplicas();
    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 have this block locally to evict
        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) BlockWorkerInfo(alluxio.client.block.BlockWorkerInfo) WorkerInfo(alluxio.wire.WorkerInfo) AlluxioBlockStore(alluxio.client.block.AlluxioBlockStore) BlockLocation(alluxio.wire.BlockLocation) HashSet(java.util.HashSet) Pair(alluxio.collections.Pair)

Example 37 with BlockLocation

use of alluxio.wire.BlockLocation 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 38 with BlockLocation

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

the class AlluxioBlockStoreTest method getInStreamRemote.

@Test
public void getInStreamRemote() throws Exception {
    WorkerNetAddress remote1 = new WorkerNetAddress().setHost("remote1");
    WorkerNetAddress remote2 = new WorkerNetAddress().setHost("remote2");
    BlockInfo info = new BlockInfo().setBlockId(BLOCK_ID).setLocations(Arrays.asList(new BlockLocation().setWorkerAddress(remote1), new BlockLocation().setWorkerAddress(remote2)));
    when(mMasterClient.getBlockInfo(BLOCK_ID)).thenReturn(info);
    // We should sometimes get remote1 and sometimes get remote2.
    Set<WorkerNetAddress> results = new HashSet<>();
    for (int i = 0; i < 40; i++) {
        results.add(mBlockStore.getInStream(BLOCK_ID, new InStreamOptions(new URIStatus(new FileInfo().setBlockIds(Lists.newArrayList(BLOCK_ID))), sConf)).getAddress());
    }
    assertEquals(Sets.newHashSet(remote1, remote2), results);
}
Also used : FileInfo(alluxio.wire.FileInfo) WorkerNetAddress(alluxio.wire.WorkerNetAddress) BlockInfo(alluxio.wire.BlockInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) BlockLocation(alluxio.wire.BlockLocation) URIStatus(alluxio.client.file.URIStatus) HashSet(java.util.HashSet) InStreamOptions(alluxio.client.file.options.InStreamOptions) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 39 with BlockLocation

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

the class ConcurrentBlockMasterTest method concurrentCommitWithReaders.

/**
 * RW contention: Concurrent commit and readers.
 * Signal in commit and the readers inquire the state
 */
@Test
public void concurrentCommitWithReaders() throws Exception {
    // Prepare worker
    long worker1 = registerEmptyWorker(NET_ADDRESS_1);
    // Replace the latch used for preparation
    CountDownLatch readerLatch = new CountDownLatch(1);
    mBlockMaster.setLatch(readerLatch);
    concurrentWriterWithReaders(readerLatch, // Writer
    () -> {
        mBlockMaster.commitBlock(worker1, BLOCK1_LENGTH, "MEM", "MEM", BLOCK1_ID, BLOCK1_LENGTH);
        return null;
    }, // Reader
    () -> {
        try {
            // If the block is not committed yet, a BlockInfoException will be thrown
            BlockInfo blockInfo = mBlockMaster.getBlockInfo(BLOCK1_ID);
            List<WorkerInfo> workerInfoList = mBlockMaster.getWorkerReport(GetWorkerReportOptions.defaults());
            WorkerInfo worker = findWorkerInfo(workerInfoList, worker1);
            assertEquals(BLOCK1_LENGTH, worker.getUsedBytes());
            BlockLocation blockLocation = new BlockLocation().setTierAlias("MEM").setWorkerAddress(NET_ADDRESS_1).setWorkerId(worker1).setMediumType("MEM");
            BlockInfo expectedBlockInfo = new BlockInfo().setBlockId(BLOCK1_ID).setLength(BLOCK1_LENGTH).setLocations(ImmutableList.of(blockLocation));
            assertEquals(expectedBlockInfo, blockInfo);
            assertEquals(1, workerInfoList.size());
        } catch (BlockInfoException e) {
            // The reader came in before the writer started the commit
            List<WorkerInfo> workerInfoList = mBlockMaster.getWorkerReport(GetWorkerReportOptions.defaults());
            assertEquals(1, workerInfoList.size());
            WorkerInfo worker = workerInfoList.get(0);
            // We may just see the result before or after the commit
            // But other values should be illegal
            assertTrue(BLOCK1_LENGTH == worker.getUsedBytes() || 100L == worker.getUsedBytes());
        }
        return null;
    });
}
Also used : BlockInfo(alluxio.wire.BlockInfo) WorkerInfo(alluxio.wire.WorkerInfo) BlockMasterTestUtils.findWorkerInfo(alluxio.master.block.BlockMasterTestUtils.findWorkerInfo) BlockInfoException(alluxio.exception.BlockInfoException) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) StorageList(alluxio.grpc.StorageList) CountDownLatch(java.util.concurrent.CountDownLatch) BlockLocation(alluxio.wire.BlockLocation) Test(org.junit.Test)

Example 40 with BlockLocation

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

the class BlockMasterTest method getBlockInfo.

@Test
public void getBlockInfo() throws Exception {
    // Create a worker with a block.
    long worker1 = mBlockMaster.getWorkerId(NET_ADDRESS_1);
    long blockId = 1L;
    long blockLength = 20L;
    mBlockMaster.workerRegister(worker1, Arrays.asList(Constants.MEDIUM_MEM), ImmutableMap.of(Constants.MEDIUM_MEM, 100L), ImmutableMap.of(Constants.MEDIUM_MEM, 0L), NO_BLOCKS_ON_LOCATION, NO_LOST_STORAGE, RegisterWorkerPOptions.getDefaultInstance());
    mBlockMaster.commitBlock(worker1, 50L, Constants.MEDIUM_MEM, Constants.MEDIUM_MEM, blockId, blockLength);
    BlockLocation blockLocation = new BlockLocation().setTierAlias(Constants.MEDIUM_MEM).setWorkerAddress(NET_ADDRESS_1).setWorkerId(worker1).setMediumType(Constants.MEDIUM_MEM);
    BlockInfo expectedBlockInfo = new BlockInfo().setBlockId(1L).setLength(20L).setLocations(ImmutableList.of(blockLocation));
    assertEquals(expectedBlockInfo, mBlockMaster.getBlockInfo(blockId));
}
Also used : BlockInfo(alluxio.wire.BlockInfo) BlockLocation(alluxio.wire.BlockLocation) Test(org.junit.Test)

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