Search in sources :

Example 16 with LocationBlockIdListEntry

use of alluxio.grpc.LocationBlockIdListEntry in project alluxio by Alluxio.

the class BlockMapIterator method next.

@Override
public List<LocationBlockIdListEntry> next() {
    List<LocationBlockIdListEntry> result = new ArrayList<>();
    int currentCounter = mCounter;
    int targetCounter = currentCounter + mBatchSize;
    while (mCounter < targetCounter) {
        // Find the BlockStoreLocation
        BlockStoreLocationProto currentLoc = mBlockStoreLocationProtoList.get(mCurrentBlockLocationIndex);
        Iterator<Long> currentIterator = mBlockLocationIteratorMap.get(currentLoc);
        // Generate the next batch
        // This method does NOT progress the pointers
        int spaceLeft = targetCounter - mCounter;
        LocationBlockIdListEntry batchFromThisTier = nextBatchFromTier(currentLoc, currentIterator, spaceLeft);
        result.add(batchFromThisTier);
        // Progress the iterator based on the break condition
        if (!currentIterator.hasNext()) {
            // We keep filling in using the next tier
            mCurrentBlockLocationIndex++;
            if (mCurrentBlockLocationIndex >= mBlockStoreLocationProtoList.size()) {
                // and all iterators have been exhausted
                return result;
            }
            continue;
        } else {
            return result;
        }
    }
    // Should never reach here
    return result;
}
Also used : ArrayList(java.util.ArrayList) BlockStoreLocationProto(alluxio.grpc.BlockStoreLocationProto) LocationBlockIdListEntry(alluxio.grpc.LocationBlockIdListEntry)

Example 17 with LocationBlockIdListEntry

use of alluxio.grpc.LocationBlockIdListEntry in project alluxio by Alluxio.

the class BlockWorkerRegisterStreamIntegrationTest method requestsForWorker.

@Test
public void requestsForWorker() throws Exception {
    List<RegisterWorkerPRequest> requestChunks = RegisterStreamTestUtils.generateRegisterStreamForWorker(WORKER_ID);
    // Verify the size and content of the requests
    int expectedBatchCount = (int) Math.ceil((TIER_BLOCK_TOTAL) / (double) BATCH_SIZE);
    Set<Long> containedBlockIds = new HashSet<>();
    assertEquals(expectedBatchCount, requestChunks.size());
    for (int i = 0; i < expectedBatchCount; i++) {
        RegisterWorkerPRequest request = requestChunks.get(i);
        assertEquals(WORKER_ID, request.getWorkerId());
        List<LocationBlockIdListEntry> entries = request.getCurrentBlocksList();
        int totalSize = 0;
        for (LocationBlockIdListEntry entry : entries) {
            totalSize += entry.getValue().getBlockIdCount();
            containedBlockIds.addAll(entry.getValue().getBlockIdList());
        }
        if (i != expectedBatchCount - 1) {
            assertEquals(BATCH_SIZE, totalSize);
        }
        // The 1st request contains metadata but the following do not
        if (i == 0) {
            assertEquals(USAGE_MAP, request.getUsedBytesOnTiersMap());
            assertEquals(CAPACITY_MAP, request.getTotalBytesOnTiersMap());
            Map<String, StorageList> lostMap = request.getLostStorageMap();
            assertEquals(1, lostMap.size());
            assertEquals(StorageList.newBuilder().build(), lostMap.get("MEM"));
            assertEquals(ImmutableList.of("MEM", "SSD", "HDD"), request.getStorageTiersList());
        } else {
            assertEquals(0, request.getStorageTiersCount());
            assertEquals(ImmutableMap.of(), request.getUsedBytesOnTiersMap());
            assertEquals(ImmutableMap.of(), request.getTotalBytesOnTiersMap());
            Map<String, StorageList> lostMap = request.getLostStorageMap();
            assertEquals(0, lostMap.size());
        }
    }
    assertEquals(containedBlockIds.size(), TIER_BLOCK_TOTAL);
}
Also used : ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) RegisterWorkerPRequest(alluxio.grpc.RegisterWorkerPRequest) StorageList(alluxio.grpc.StorageList) HashSet(java.util.HashSet) LocationBlockIdListEntry(alluxio.grpc.LocationBlockIdListEntry) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 18 with LocationBlockIdListEntry

use of alluxio.grpc.LocationBlockIdListEntry in project alluxio by Alluxio.

the class BlockMapIteratorTest method convertStream.

@Test
public void convertStream() {
    List<Integer> memList = ImmutableList.of(1000, 1000);
    List<Integer> ssdList = ImmutableList.of(10000, 10000);
    List<Integer> hddList = ImmutableList.of(20000, 20000);
    Map<String, List<Integer>> blockConfig = ImmutableMap.of("MEM", memList, "SSD", ssdList, "HDD", hddList);
    Map<BlockStoreLocation, List<Long>> blockMap = generateBlockIdOnTiers(blockConfig);
    BlockMapIterator iter = new BlockMapIterator(blockMap);
    while (iter.hasNext()) {
        List<LocationBlockIdListEntry> entries = iter.next();
        // Each batch should not contain duplicate locations
        Set<Block.BlockLocation> locations = new HashSet<>();
        for (LocationBlockIdListEntry e : entries) {
            // No duplicate
            Block.BlockLocation loc = Block.BlockLocation.newBuilder().setTier(e.getKey().getTierAlias()).setMediumType(e.getKey().getMediumType()).build();
            assertFalse(locations.contains(loc));
            locations.add(loc);
        }
    }
}
Also used : LocationBlockIdListEntry(alluxio.grpc.LocationBlockIdListEntry) Block(alluxio.proto.meta.Block) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 19 with LocationBlockIdListEntry

use of alluxio.grpc.LocationBlockIdListEntry in project alluxio by Alluxio.

the class BlockMapIteratorTest method convertStreamMergedTiers.

@Test
public void convertStreamMergedTiers() {
    List<Integer> memList = ImmutableList.of(100, 100);
    List<Integer> ssdList = ImmutableList.of(101, 22);
    List<Integer> hddList = ImmutableList.of(10, 20);
    Map<String, List<Integer>> blockConfig = ImmutableMap.of("MEM", memList, "SSD", ssdList, "HDD", hddList);
    Map<BlockStoreLocation, List<Long>> blockMap = generateBlockIdOnTiers(blockConfig);
    BlockMapIterator iter = new BlockMapIterator(blockMap);
    while (iter.hasNext()) {
        List<LocationBlockIdListEntry> entries = iter.next();
        // Each batch should not contain duplicate locations
        Set<Block.BlockLocation> locations = new HashSet<>();
        for (LocationBlockIdListEntry e : entries) {
            // No duplicate
            Block.BlockLocation loc = Block.BlockLocation.newBuilder().setTier(e.getKey().getTierAlias()).setMediumType(e.getKey().getMediumType()).build();
            assertFalse(locations.contains(loc));
            locations.add(loc);
        }
    }
}
Also used : LocationBlockIdListEntry(alluxio.grpc.LocationBlockIdListEntry) Block(alluxio.proto.meta.Block) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

LocationBlockIdListEntry (alluxio.grpc.LocationBlockIdListEntry)19 BlockStoreLocationProto (alluxio.grpc.BlockStoreLocationProto)10 RegisterWorkerPRequest (alluxio.grpc.RegisterWorkerPRequest)10 Test (org.junit.Test)10 BlockIdList (alluxio.grpc.BlockIdList)9 ArrayList (java.util.ArrayList)7 List (java.util.List)6 StorageList (alluxio.grpc.StorageList)5 BlockStoreLocation (alluxio.worker.block.BlockStoreLocation)5 StreamObserver (io.grpc.stub.StreamObserver)5 GetRegisterLeasePRequest (alluxio.grpc.GetRegisterLeasePRequest)4 RegisterWorkerPResponse (alluxio.grpc.RegisterWorkerPResponse)4 HashMap (java.util.HashMap)4 BlockHeartbeatPRequest (alluxio.grpc.BlockHeartbeatPRequest)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 ConcurrentLinkedDeque (java.util.concurrent.ConcurrentLinkedDeque)3 AbstractMasterClient (alluxio.AbstractMasterClient)2 Constants (alluxio.Constants)2