Search in sources :

Example 6 with BlockIdList

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

the class BlockMasterClient method convertBlockListMapToProto.

/**
 * Converts the block list map to a proto list.
 * Because the list is flattened from a map, in the list no two {@link LocationBlockIdListEntry}
 * instances shall have the same {@link BlockStoreLocationProto}.
 * The uniqueness of {@link BlockStoreLocationProto} is determined by tier alias and medium type.
 * That means directories with the same tier alias and medium type will be merged into the same
 * {@link LocationBlockIdListEntry}.
 *
 * @param blockListOnLocation a map from block location to the block list
 * @return a flattened and deduplicated list
 */
@VisibleForTesting
public List<LocationBlockIdListEntry> convertBlockListMapToProto(Map<BlockStoreLocation, List<Long>> blockListOnLocation) {
    final List<LocationBlockIdListEntry> entryList = new ArrayList<>();
    Map<BlockStoreLocationProto, List<Long>> tierToBlocks = new HashMap<>();
    for (Map.Entry<BlockStoreLocation, List<Long>> entry : blockListOnLocation.entrySet()) {
        BlockStoreLocation loc = entry.getKey();
        BlockStoreLocationProto locationProto = BlockStoreLocationProto.newBuilder().setTierAlias(loc.tierAlias()).setMediumType(loc.mediumType()).build();
        if (tierToBlocks.containsKey(locationProto)) {
            tierToBlocks.get(locationProto).addAll(entry.getValue());
        } else {
            List<Long> blockList = new ArrayList<>(entry.getValue());
            tierToBlocks.put(locationProto, blockList);
        }
    }
    for (Map.Entry<BlockStoreLocationProto, List<Long>> entry : tierToBlocks.entrySet()) {
        BlockIdList blockIdList = BlockIdList.newBuilder().addAllBlockId(entry.getValue()).build();
        LocationBlockIdListEntry listEntry = LocationBlockIdListEntry.newBuilder().setKey(entry.getKey()).setValue(blockIdList).build();
        entryList.add(listEntry);
    }
    return entryList;
}
Also used : BlockIdList(alluxio.grpc.BlockIdList) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LocationBlockIdListEntry(alluxio.grpc.LocationBlockIdListEntry) ArrayList(java.util.ArrayList) BlockIdList(alluxio.grpc.BlockIdList) List(java.util.List) StorageList(alluxio.grpc.StorageList) BlockStoreLocationProto(alluxio.grpc.BlockStoreLocationProto) HashMap(java.util.HashMap) Map(java.util.Map) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 7 with BlockIdList

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

the class BlockMapIterator method nextBatchFromTier.

private LocationBlockIdListEntry nextBatchFromTier(BlockStoreLocationProto currentLoc, Iterator<Long> currentIterator, int spaceLeft) {
    // Generate the next batch
    List<Long> blockIdBatch = new ArrayList<>(spaceLeft);
    while (blockIdBatch.size() < spaceLeft && currentIterator.hasNext()) {
        blockIdBatch.add(currentIterator.next());
        mCounter++;
    }
    BlockIdList blockIdList = BlockIdList.newBuilder().addAllBlockId(blockIdBatch).build();
    LocationBlockIdListEntry listEntry = LocationBlockIdListEntry.newBuilder().setKey(currentLoc).setValue(blockIdList).build();
    return listEntry;
}
Also used : BlockIdList(alluxio.grpc.BlockIdList) ArrayList(java.util.ArrayList) LocationBlockIdListEntry(alluxio.grpc.LocationBlockIdListEntry)

Aggregations

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