use of alluxio.grpc.RegisterWorkerPRequest in project alluxio by Alluxio.
the class BlockMasterRegisterStreamIntegrationTest method hangingWorkerSessionRecycled.
/**
* Tests below cover various failure cases.
*/
@Test
public void hangingWorkerSessionRecycled() throws Exception {
long workerId = mBlockMaster.getWorkerId(NET_ADDRESS_1);
List<RegisterWorkerPRequest> requestChunks = RegisterStreamTestUtils.generateRegisterStreamForWorker(workerId);
prepareBlocksOnMaster(requestChunks);
Queue<Throwable> errorQueue = new ConcurrentLinkedQueue<>();
StreamObserver<RegisterWorkerPRequest> requestObserver = mHandler.registerWorkerStream(getErrorCapturingResponseObserver(errorQueue));
// Feed the chunks into the requestObserver
for (int i = 0; i < requestChunks.size(); i++) {
RegisterWorkerPRequest chunk = requestChunks.get(i);
// From the 2nd request on, the request will be rejected
requestObserver.onNext(chunk);
if (i == 0) {
// Progress the clock so the worker stream expired
mClock.addTime(Duration.of(100_000_000, ChronoUnit.MILLIS));
// Sleep and wait for the stream recycler thread heartbeat
CommonUtils.sleepMs(3000);
}
}
// This will be rejected too
requestObserver.onCompleted();
// The 5 requests after expiry will be rejected
// And the complete message will be rejected too
// -1 because the 1st request was accepted
// +1 because master sends the TimeoutException to worker on timeout
// +count because all following requests are rejected
// +1 because the onComplete() is also rejected
assertEquals(requestChunks.size() - 1 + 1 + 1, errorQueue.size());
// Verify the session is recycled
assertEquals(0, mBlockMaster.getWorkerCount());
// Verify the worker can re-register and be operated, so the locks are managed correctly
verifyWorkerCanReregister(workerId, requestChunks, TIER_BLOCK_TOTAL);
verifyWorkerWritable(workerId);
}
use of alluxio.grpc.RegisterWorkerPRequest in project alluxio by Alluxio.
the class BlockMasterRegisterStreamIntegrationTest method reregisterWithFree.
@Test
public void reregisterWithFree() throws Exception {
// Register the worker so the worker is marked active in master
long workerId = mBlockMaster.getWorkerId(NET_ADDRESS_1);
List<RegisterWorkerPRequest> requestChunks = RegisterStreamTestUtils.generateRegisterStreamForWorker(workerId);
prepareBlocksOnMaster(requestChunks);
Queue<Throwable> errorQueue = new ConcurrentLinkedQueue<>();
sendStreamToMaster(requestChunks, RegisterStreamTestUtils.getErrorCapturingResponseObserver(errorQueue));
assertEquals(0, errorQueue.size());
assertEquals(1, mBlockMaster.getWorkerCount());
// Find a block to free
long blockToRemove = RegisterStreamTestUtils.findFirstBlock(requestChunks);
// Register again
CountDownLatch latch = new CountDownLatch(1);
Queue<Throwable> newErrorQueue = new ConcurrentLinkedQueue<>();
mExecutorService.submit(() -> {
sendStreamToMasterAndSignal(requestChunks, RegisterStreamTestUtils.getErrorCapturingResponseObserver(newErrorQueue), latch);
});
// During the register stream, trigger a delete on worker
latch.await();
mBlockMaster.removeBlocks(ImmutableList.of(blockToRemove), false);
BlockInfo info = mBlockMaster.getBlockInfo(blockToRemove);
MasterWorkerInfo worker = mBlockMaster.getWorker(workerId);
assertEquals(0, newErrorQueue.size());
assertEquals(1, mBlockMaster.getWorkerCount());
// The block still exists on the worker but a command will be issued to remove it
assertEquals(TIER_BLOCK_TOTAL, worker.getBlockCount());
Command command = sendHeartbeatToMaster(workerId);
assertEquals(Command.newBuilder().setCommandType(CommandType.Free).addData(blockToRemove).build(), command);
}
use of alluxio.grpc.RegisterWorkerPRequest in project alluxio by Alluxio.
the class BlockMasterRegisterStreamIntegrationTest method workerSendsErrorBeforeCompleting.
@Test
public void workerSendsErrorBeforeCompleting() throws Exception {
long workerId = mBlockMaster.getWorkerId(NET_ADDRESS_1);
List<RegisterWorkerPRequest> requestChunks = RegisterStreamTestUtils.generateRegisterStreamForWorker(workerId);
prepareBlocksOnMaster(requestChunks);
// Send the requests to the master
Queue<Throwable> errorQueue = new ConcurrentLinkedQueue<>();
StreamObserver<RegisterWorkerPRequest> requestObserver = mHandler.registerWorkerStream(RegisterStreamTestUtils.getErrorCapturingResponseObserver(errorQueue));
for (RegisterWorkerPRequest chunk : requestChunks) {
requestObserver.onNext(chunk);
}
// An error took place on the worker side after all the requests have been sent
Exception e = new IOException("Exception on the worker side");
requestObserver.onError(e);
// The complete should be rejected
requestObserver.onCompleted();
assertEquals(1, errorQueue.size());
// verify the worker is not registered
assertEquals(0, mBlockMaster.getWorkerCount());
verifyWorkerCanReregister(workerId, requestChunks, TIER_BLOCK_TOTAL);
}
use of alluxio.grpc.RegisterWorkerPRequest in project alluxio by Alluxio.
the class BlockMasterRegisterStreamIntegrationTest method workerSendsErrorInStream.
@Test
public void workerSendsErrorInStream() throws Exception {
long workerId = mBlockMaster.getWorkerId(NET_ADDRESS_1);
List<RegisterWorkerPRequest> requestChunks = RegisterStreamTestUtils.generateRegisterStreamForWorker(workerId);
prepareBlocksOnMaster(requestChunks);
Queue<Throwable> errorQueue = new ConcurrentLinkedQueue<>();
StreamObserver<RegisterWorkerPRequest> requestObserver = mHandler.registerWorkerStream(RegisterStreamTestUtils.getErrorCapturingResponseObserver(errorQueue));
// An error took place in the worker during the stream
RegisterWorkerPRequest first = requestChunks.get(0);
requestObserver.onNext(first);
Exception e = new IOException("An exception occurred during the stream");
requestObserver.onError(e);
// The following requests will be rejected as the stream has been closed
// on the master side.
RegisterWorkerPRequest second = requestChunks.get(1);
requestObserver.onNext(second);
requestObserver.onCompleted();
assertEquals(2, errorQueue.size());
// verify the worker is not registered
assertEquals(0, mBlockMaster.getWorkerCount());
verifyWorkerCanReregister(workerId, requestChunks, TIER_BLOCK_TOTAL);
}
use of alluxio.grpc.RegisterWorkerPRequest in project alluxio by Alluxio.
the class BlockMasterRegisterStreamIntegrationTest method registerEmptyWorkerStream.
/**
* Tests below cover the most normal cases.
*/
@Test
public void registerEmptyWorkerStream() throws Exception {
long workerId = mBlockMaster.getWorkerId(NET_ADDRESS_1);
List<RegisterWorkerPRequest> requestChunks = RegisterStreamTestUtils.generateRegisterStreamForEmptyWorker(workerId);
Queue<Throwable> errorQueue = new ConcurrentLinkedQueue<>();
sendStreamToMaster(requestChunks, RegisterStreamTestUtils.getErrorCapturingResponseObserver(errorQueue));
// Verify the worker is registered
assertEquals(0, errorQueue.size());
assertEquals(1, mBlockMaster.getWorkerCount());
MasterWorkerInfo worker = mBlockMaster.getWorker(workerId);
assertEquals(0, worker.getBlockCount());
assertEquals(0, worker.getToRemoveBlockCount());
assertEquals(MEM_CAPACITY_BYTES, worker.getCapacityBytes());
assertEquals(MEM_CAPACITY_BYTES, worker.getAvailableBytes());
assertEquals(0L, worker.getUsedBytes());
// Verify the worker is readable and writable
verifyWorkerWritable(workerId);
}
Aggregations