use of alluxio.worker.block.RegisterStreamer in project alluxio by Alluxio.
the class RegisterStreamTestUtils method generateRegisterStreamForEmptyWorker.
public static List<RegisterWorkerPRequest> generateRegisterStreamForEmptyWorker(long workerId) {
String tierConfig = "";
// Generate block IDs heuristically
Map<BlockStoreLocation, List<Long>> blockMap = RpcBenchPreparationUtils.generateBlockIdOnTiers(parseTierConfig(tierConfig));
RegisterStreamer registerStreamer = new RegisterStreamer(null, workerId, ImmutableList.of("MEM"), MEM_CAPACITY, MEM_USAGE_EMPTY, blockMap, LOST_STORAGE, EMPTY_CONFIG);
// For an empty worker there is only 1 request
List<RegisterWorkerPRequest> requestChunks = ImmutableList.copyOf(registerStreamer);
assertEquals(1, requestChunks.size());
return requestChunks;
}
use of alluxio.worker.block.RegisterStreamer in project alluxio by Alluxio.
the class BlockMasterRegisterStreamIntegrationTest method registerExistingWorkerBlocksAdded.
@Test
public void registerExistingWorkerBlocksAdded() throws Exception {
long workerId = mBlockMaster.getWorkerId(NET_ADDRESS_1);
// Register the worker for the 1st time
List<RegisterWorkerPRequest> requestChunks = RegisterStreamTestUtils.generateRegisterStreamForWorker(workerId);
prepareBlocksOnMaster(requestChunks);
Queue<Throwable> errorQueue = new ConcurrentLinkedQueue<>();
sendStreamToMaster(requestChunks, RegisterStreamTestUtils.getErrorCapturingResponseObserver(errorQueue));
assertEquals(0, errorQueue.size());
// Verify the worker has registered
assertEquals(1, mBlockMaster.getWorkerCount());
MasterWorkerInfo worker = mBlockMaster.getWorker(workerId);
assertEquals(TIER_BLOCK_TOTAL, worker.getBlockCount());
assertEquals(0, worker.getToRemoveBlockCount());
// Generate block IDs in the same way but add some more
Map<BlockStoreLocation, List<Long>> blockMap = RpcBenchPreparationUtils.generateBlockIdOnTiers(parseTierConfig(TIER_CONFIG));
Set<Long> addedBlocks = addSomeBlocks(blockMap);
// Make the master accept these blocks
prepareBlocksOnMaster(addedBlocks);
// Re-generate the request
List<String> tierAliases = getTierAliases(parseTierConfig(TIER_CONFIG));
Map<String, Long> capacityMap = Maps.toMap(tierAliases, (tier) -> CAPACITY);
Map<String, Long> usedMap = Maps.toMap(tierAliases, (tier) -> 0L);
RegisterStreamer newRegisterStreamer = new RegisterStreamer(null, workerId, tierAliases, capacityMap, usedMap, blockMap, LOST_STORAGE, EMPTY_CONFIG);
List<RegisterWorkerPRequest> newRequestChunks = ImmutableList.copyOf(newRegisterStreamer);
int newExpectedBatchCount = (int) Math.ceil((TIER_BLOCK_TOTAL + addedBlocks.size()) / (double) BATCH_SIZE);
assertEquals(newExpectedBatchCount, newRequestChunks.size());
// Register again with the new request stream
Queue<Throwable> newErrorQueue = new ConcurrentLinkedQueue<>();
sendStreamToMaster(newRequestChunks, RegisterStreamTestUtils.getErrorCapturingResponseObserver(newErrorQueue));
assertEquals(0, newErrorQueue.size());
// Verify the worker is registered
assertEquals(1, mBlockMaster.getWorkerCount());
MasterWorkerInfo updatedWorker = mBlockMaster.getWorker(workerId);
assertEquals(TIER_BLOCK_TOTAL + addedBlocks.size(), updatedWorker.getBlockCount());
assertEquals(0, updatedWorker.getToRemoveBlockCount());
// No command from the master because the update is received during registration
assertEquals(EMPTY_CMD, sendHeartbeatToMaster(workerId));
// Verify the worker is readable and writable
verifyWorkerWritable(workerId);
}
use of alluxio.worker.block.RegisterStreamer in project alluxio by Alluxio.
the class BlockMasterRegisterStreamIntegrationTest method registerExistingWorkerBlocksLost.
@Test
public void registerExistingWorkerBlocksLost() throws Exception {
long workerId = mBlockMaster.getWorkerId(NET_ADDRESS_1);
// Register the worker for the 1st time
List<RegisterWorkerPRequest> requestChunks = RegisterStreamTestUtils.generateRegisterStreamForWorker(workerId);
prepareBlocksOnMaster(requestChunks);
Queue<Throwable> errorQueue = new ConcurrentLinkedQueue<>();
sendStreamToMaster(requestChunks, RegisterStreamTestUtils.getErrorCapturingResponseObserver(errorQueue));
assertEquals(0, errorQueue.size());
// Verify the worker has registered
assertEquals(1, mBlockMaster.getWorkerCount());
MasterWorkerInfo worker = mBlockMaster.getWorker(workerId);
assertEquals(TIER_BLOCK_TOTAL, worker.getBlockCount());
assertEquals(0, worker.getToRemoveBlockCount());
// Manually generate the blocks again and remove some
List<String> tierAliases = getTierAliases(parseTierConfig(TIER_CONFIG));
Map<BlockStoreLocation, List<Long>> blockMap = RpcBenchPreparationUtils.generateBlockIdOnTiers(parseTierConfig(TIER_CONFIG));
Set<Long> lostBlocks = removeSomeBlocks(blockMap);
// Regenerate the requests
RegisterStreamer newRegisterStreamer = new RegisterStreamer(null, workerId, tierAliases, CAPACITY_MAP, USAGE_MAP, blockMap, LOST_STORAGE, EMPTY_CONFIG);
List<RegisterWorkerPRequest> newRequestChunks = ImmutableList.copyOf(newRegisterStreamer);
int newExpectedBatchCount = (int) Math.ceil((TIER_BLOCK_TOTAL - lostBlocks.size()) / (double) BATCH_SIZE);
assertEquals(newExpectedBatchCount, newRequestChunks.size());
// Register again with the updated stream
Queue<Throwable> newErrorQueue = new ConcurrentLinkedQueue<>();
sendStreamToMaster(newRequestChunks, RegisterStreamTestUtils.getErrorCapturingResponseObserver(newErrorQueue));
assertEquals(0, newErrorQueue.size());
// Verify the worker is registered
assertEquals(1, mBlockMaster.getWorkerCount());
MasterWorkerInfo updatedWorker = mBlockMaster.getWorker(workerId);
assertEquals(TIER_BLOCK_TOTAL - lostBlocks.size(), updatedWorker.getBlockCount());
// The master will mark the lost blocks as to be removed
// This is to ensure the unrecognized blocks do no live on the worker anymore
assertEquals(lostBlocks.size(), updatedWorker.getToRemoveBlockCount());
// The update is received during the registration so no command to send to the worker
Command command = sendHeartbeatToMaster(workerId);
assertEquals(CommandType.Free, command.getCommandType());
assertEquals(lostBlocks, new HashSet<>(command.getDataList()));
// Verify the worker is readable and writable
verifyWorkerWritable(workerId);
}
use of alluxio.worker.block.RegisterStreamer in project alluxio by Alluxio.
the class BlockWorkerRegisterStreamIntegrationTest method registerWorkerErrorDuringStream.
@Test
public void registerWorkerErrorDuringStream() throws Exception {
// Create the stream and control the request/response observers
BlockMasterWorkerServiceStub asyncClient = PowerMockito.mock(BlockMasterWorkerServiceStub.class);
when(asyncClient.withDeadlineAfter(anyLong(), any())).thenReturn(asyncClient);
ManualRegisterStreamObserver requestObserver = new ManualRegisterStreamObserver(MasterMode.SECOND_REQUEST);
when(asyncClient.registerWorkerStream(any())).thenReturn(requestObserver);
RegisterStreamer registerStreamer = new RegisterStreamer(asyncClient, WORKER_ID, mTierAliases, mCapacityMap, mUsedMap, mBlockMap, LOST_STORAGE, EMPTY_CONFIG);
StreamObserver<RegisterWorkerPResponse> responseObserver = getResponseObserver(registerStreamer);
requestObserver.setResponseObserver(responseObserver);
assertThrows(InternalException.class, () -> {
// An error received from the master side will be InternalException
registerStreamer.registerWithMaster();
});
}
use of alluxio.worker.block.RegisterStreamer in project alluxio by Alluxio.
the class BlockWorkerRegisterStreamIntegrationTest method masterHangsInStream.
@Test
public void masterHangsInStream() throws Exception {
// Create the stream and control the request/response observers
BlockMasterWorkerServiceStub asyncClient = PowerMockito.mock(BlockMasterWorkerServiceStub.class);
when(asyncClient.withDeadlineAfter(anyLong(), any())).thenReturn(asyncClient);
ManualRegisterStreamObserver requestObserver = new ManualRegisterStreamObserver(MasterMode.HANG_IN_STREAM);
when(asyncClient.registerWorkerStream(any())).thenReturn(requestObserver);
RegisterStreamer registerStreamer = new RegisterStreamer(asyncClient, WORKER_ID, mTierAliases, mCapacityMap, mUsedMap, mBlockMap, LOST_STORAGE, EMPTY_CONFIG);
StreamObserver<RegisterWorkerPResponse> responseObserver = getResponseObserver(registerStreamer);
requestObserver.setResponseObserver(responseObserver);
// The master will hang during the stream which exceeds the deadline between messages
assertThrows(DeadlineExceededException.class, () -> {
registerStreamer.registerWithMaster();
});
}
Aggregations