use of alluxio.grpc.BlockHeartbeatPRequest in project alluxio by Alluxio.
the class BlockMasterWorkerServiceHandlerTest method workerHeartbeatFailsOnDuplicateBlockLocation.
@Test
public void workerHeartbeatFailsOnDuplicateBlockLocation() throws Exception {
long workerId = mBlockMaster.getWorkerId(NET_ADDRESS_1);
// Prepare LocationBlockIdListEntry objects
BlockStoreLocation loc = new BlockStoreLocation("MEM", 0);
BlockStoreLocationProto locationProto = BlockStoreLocationProto.newBuilder().setTierAlias(loc.tierAlias()).setMediumType(loc.mediumType()).build();
BlockIdList blockIdList1 = BlockIdList.newBuilder().addAllBlockId(ImmutableList.of(1L, 2L)).build();
LocationBlockIdListEntry listEntry1 = LocationBlockIdListEntry.newBuilder().setKey(locationProto).setValue(blockIdList1).build();
BlockIdList blockIdList2 = BlockIdList.newBuilder().addAllBlockId(ImmutableList.of(3L, 4L)).build();
LocationBlockIdListEntry listEntry2 = LocationBlockIdListEntry.newBuilder().setKey(locationProto).setValue(blockIdList2).build();
BlockHeartbeatPRequest request = BlockHeartbeatPRequest.newBuilder().setWorkerId(workerId).addAddedBlocks(listEntry1).addAddedBlocks(listEntry2).build();
// Noop response observer
StreamObserver<BlockHeartbeatPResponse> noopResponseObserver = new StreamObserver<BlockHeartbeatPResponse>() {
@Override
public void onNext(BlockHeartbeatPResponse response) {
}
@Override
public void onError(Throwable t) {
}
@Override
public void onCompleted() {
}
};
assertThrows(AssertionError.class, () -> {
mHandler.blockHeartbeat(request, noopResponseObserver);
});
}
use of alluxio.grpc.BlockHeartbeatPRequest 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);
}
Aggregations