Search in sources :

Example 6 with LocationBlockIdListEntry

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

the class BlockMasterClient method heartbeat.

/**
 * The method the worker should periodically execute to heartbeat back to the master.
 *
 * @param workerId the worker id
 * @param capacityBytesOnTiers a mapping from storage tier alias to capacity bytes
 * @param usedBytesOnTiers a mapping from storage tier alias to used bytes
 * @param removedBlocks a list of block removed from this worker
 * @param addedBlocks a mapping from storage tier alias to added blocks
 * @param lostStorage a mapping from storage tier alias to a list of lost storage paths
 * @param metrics a list of worker metrics
 * @return an optional command for the worker to execute
 */
public synchronized Command heartbeat(final long workerId, final Map<String, Long> capacityBytesOnTiers, final Map<String, Long> usedBytesOnTiers, final List<Long> removedBlocks, final Map<BlockStoreLocation, List<Long>> addedBlocks, final Map<String, List<String>> lostStorage, final List<Metric> metrics) throws IOException {
    final BlockHeartbeatPOptions options = BlockHeartbeatPOptions.newBuilder().addAllMetrics(metrics).putAllCapacityBytesOnTiers(capacityBytesOnTiers).build();
    final List<LocationBlockIdListEntry> entryList = convertBlockListMapToProto(addedBlocks);
    final Map<String, StorageList> lostStorageMap = lostStorage.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> StorageList.newBuilder().addAllStorage(e.getValue()).build()));
    final BlockHeartbeatPRequest request = BlockHeartbeatPRequest.newBuilder().setWorkerId(workerId).putAllUsedBytesOnTiers(usedBytesOnTiers).addAllRemovedBlockIds(removedBlocks).addAllAddedBlocks(entryList).setOptions(options).putAllLostStorage(lostStorageMap).build();
    return retryRPC(() -> mClient.withDeadlineAfter(mContext.getClusterConf().getMs(PropertyKey.WORKER_MASTER_PERIODICAL_RPC_TIMEOUT), TimeUnit.MILLISECONDS).blockHeartbeat(request).getCommand(), LOG, "Heartbeat", "workerId=%d", workerId);
}
Also used : WorkerNetAddress(alluxio.wire.WorkerNetAddress) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) PropertyKey(alluxio.conf.PropertyKey) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) BlockMasterWorkerServiceGrpc(alluxio.grpc.BlockMasterWorkerServiceGrpc) BlockHeartbeatPOptions(alluxio.grpc.BlockHeartbeatPOptions) Constants(alluxio.Constants) GetRegisterLeasePRequest(alluxio.grpc.GetRegisterLeasePRequest) GrpcUtils(alluxio.grpc.GrpcUtils) GetWorkerIdPRequest(alluxio.grpc.GetWorkerIdPRequest) Map(java.util.Map) BlockHeartbeatPRequest(alluxio.grpc.BlockHeartbeatPRequest) LocationBlockIdListEntry(alluxio.grpc.LocationBlockIdListEntry) AbstractMasterClient(alluxio.AbstractMasterClient) Metric(alluxio.grpc.Metric) RetryPolicy(alluxio.retry.RetryPolicy) BlockIdList(alluxio.grpc.BlockIdList) CommitBlockInUfsPRequest(alluxio.grpc.CommitBlockInUfsPRequest) FailedToAcquireRegisterLeaseException(alluxio.exception.FailedToAcquireRegisterLeaseException) Logger(org.slf4j.Logger) BlockStoreLocationProto(alluxio.grpc.BlockStoreLocationProto) GetRegisterLeasePResponse(alluxio.grpc.GetRegisterLeasePResponse) IOException(java.io.IOException) ThreadSafe(javax.annotation.concurrent.ThreadSafe) ConfigProperty(alluxio.grpc.ConfigProperty) Command(alluxio.grpc.Command) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) RegisterWorkerPOptions(alluxio.grpc.RegisterWorkerPOptions) MasterClientContext(alluxio.master.MasterClientContext) CommitBlockPRequest(alluxio.grpc.CommitBlockPRequest) ServiceType(alluxio.grpc.ServiceType) VisibleForTesting(com.google.common.annotations.VisibleForTesting) RegisterWorkerPRequest(alluxio.grpc.RegisterWorkerPRequest) StorageList(alluxio.grpc.StorageList) BlockHeartbeatPRequest(alluxio.grpc.BlockHeartbeatPRequest) StorageList(alluxio.grpc.StorageList) HashMap(java.util.HashMap) Map(java.util.Map) BlockHeartbeatPOptions(alluxio.grpc.BlockHeartbeatPOptions) LocationBlockIdListEntry(alluxio.grpc.LocationBlockIdListEntry)

Example 7 with LocationBlockIdListEntry

use of alluxio.grpc.LocationBlockIdListEntry 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 8 with LocationBlockIdListEntry

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

the class RegisterStreamer method next.

@Override
public RegisterWorkerPRequest next() {
    RegisterWorkerPRequest request;
    List<LocationBlockIdListEntry> blockBatch;
    if (mBatchNumber == 0) {
        if (mBlockMapIterator.hasNext()) {
            blockBatch = mBlockMapIterator.next();
        } else {
            blockBatch = Collections.emptyList();
        }
        // If it is the 1st batch, include metadata
        request = RegisterWorkerPRequest.newBuilder().setWorkerId(mWorkerId).addAllStorageTiers(mStorageTierAliases).putAllTotalBytesOnTiers(mTotalBytesOnTiers).putAllUsedBytesOnTiers(mUsedBytesOnTiers).putAllLostStorage(mLostStorageMap).setOptions(mOptions).addAllCurrentBlocks(blockBatch).build();
    } else {
        blockBatch = mBlockMapIterator.next();
        // Following batches only include the block list
        request = RegisterWorkerPRequest.newBuilder().setWorkerId(mWorkerId).addAllCurrentBlocks(blockBatch).build();
    }
    mBatchNumber++;
    return request;
}
Also used : RegisterWorkerPRequest(alluxio.grpc.RegisterWorkerPRequest) LocationBlockIdListEntry(alluxio.grpc.LocationBlockIdListEntry)

Example 9 with LocationBlockIdListEntry

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

the class BlockMasterClientTest method convertBlockListMapToProtoMergeDirsInSameTier.

@Test
public void convertBlockListMapToProtoMergeDirsInSameTier() {
    BlockMasterClient client = new BlockMasterClient(MasterClientContext.newBuilder(ClientContext.create(mConf)).build());
    Map<BlockStoreLocation, List<Long>> blockMap = new HashMap<>();
    BlockStoreLocation memDir0 = new BlockStoreLocation("MEM", 0);
    blockMap.put(memDir0, Arrays.asList(1L, 2L, 3L));
    BlockStoreLocation memDir1 = new BlockStoreLocation("MEM", 1);
    blockMap.put(memDir1, Arrays.asList(4L, 5L, 6L, 7L));
    BlockStoreLocation ssdDir0 = new BlockStoreLocation("SSD", 0);
    blockMap.put(ssdDir0, Arrays.asList(11L, 12L, 13L, 14L));
    BlockStoreLocation ssdDir1 = new BlockStoreLocation("SSD", 1);
    blockMap.put(ssdDir1, Arrays.asList(15L, 16L, 17L, 18L, 19L));
    // Directories on the same tier will be merged together
    List<LocationBlockIdListEntry> protoList = client.convertBlockListMapToProto(blockMap);
    assertEquals(2, protoList.size());
    BlockStoreLocationProto memLocationProto = BlockStoreLocationProto.newBuilder().setTierAlias("MEM").setMediumType("").build();
    BlockStoreLocationProto ssdLocationProto = BlockStoreLocationProto.newBuilder().setTierAlias("SSD").setMediumType("").build();
    Set<BlockStoreLocationProto> blockLocations = protoList.stream().map(LocationBlockIdListEntry::getKey).collect(Collectors.toSet());
    assertEquals(ImmutableSet.of(memLocationProto, ssdLocationProto), blockLocations);
    LocationBlockIdListEntry firstEntry = protoList.get(0);
    if (firstEntry.getKey().getTierAlias().equals("MEM")) {
        LocationBlockIdListEntry memTierEntry = protoList.get(0);
        List<Long> memProtoBlockList = memTierEntry.getValue().getBlockIdList();
        assertEquals(ImmutableSet.of(1L, 2L, 3L, 4L, 5L, 6L, 7L), new HashSet<>(memProtoBlockList));
        LocationBlockIdListEntry ssdTierEntry = protoList.get(1);
        List<Long> ssdProtoBlockList = ssdTierEntry.getValue().getBlockIdList();
        assertEquals(ImmutableSet.of(11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L), new HashSet<>(ssdProtoBlockList));
    } else {
        LocationBlockIdListEntry memTierEntry = protoList.get(1);
        List<Long> memProtoBlockList = memTierEntry.getValue().getBlockIdList();
        assertEquals(ImmutableSet.of(1L, 2L, 3L, 4L, 5L, 6L, 7L), new HashSet<>(memProtoBlockList));
        LocationBlockIdListEntry ssdTierEntry = protoList.get(0);
        List<Long> ssdProtoBlockList = ssdTierEntry.getValue().getBlockIdList();
        assertEquals(ImmutableSet.of(11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L), new HashSet<>(ssdProtoBlockList));
    }
}
Also used : HashMap(java.util.HashMap) List(java.util.List) BlockStoreLocationProto(alluxio.grpc.BlockStoreLocationProto) LocationBlockIdListEntry(alluxio.grpc.LocationBlockIdListEntry) Test(org.junit.Test)

Example 10 with LocationBlockIdListEntry

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

the class BlockWorkerRegisterStreamIntegrationTest method requestsForEmptyWorker.

/**
 * Tests below cover the most normal cases.
 */
@Test
public void requestsForEmptyWorker() throws Exception {
    List<RegisterWorkerPRequest> requestChunks = RegisterStreamTestUtils.generateRegisterStreamForEmptyWorker(WORKER_ID);
    // Verify the size and content of the requests
    assertEquals(1, requestChunks.size());
    RegisterWorkerPRequest request = requestChunks.get(0);
    assertEquals(WORKER_ID, request.getWorkerId());
    assertEquals(MEM_USAGE_EMPTY, request.getUsedBytesOnTiersMap());
    assertEquals(MEM_CAPACITY, request.getTotalBytesOnTiersMap());
    Map<String, StorageList> lostMap = request.getLostStorageMap();
    assertEquals(1, lostMap.size());
    assertEquals(StorageList.newBuilder().build(), lostMap.get("MEM"));
    assertEquals(ImmutableList.of("MEM"), request.getStorageTiersList());
    List<LocationBlockIdListEntry> entries = request.getCurrentBlocksList();
    assertEquals(0, entries.size());
}
Also used : RegisterWorkerPRequest(alluxio.grpc.RegisterWorkerPRequest) StorageList(alluxio.grpc.StorageList) LocationBlockIdListEntry(alluxio.grpc.LocationBlockIdListEntry) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) 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