Search in sources :

Example 11 with RegisterWorkerPRequest

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);
}
Also used : RegisterWorkerPRequest(alluxio.grpc.RegisterWorkerPRequest) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Test(org.junit.Test)

Example 12 with RegisterWorkerPRequest

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);
}
Also used : Command(alluxio.grpc.Command) BlockInfo(alluxio.wire.BlockInfo) MasterWorkerInfo(alluxio.master.block.meta.MasterWorkerInfo) RegisterWorkerPRequest(alluxio.grpc.RegisterWorkerPRequest) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 13 with RegisterWorkerPRequest

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);
}
Also used : RegisterWorkerPRequest(alluxio.grpc.RegisterWorkerPRequest) IOException(java.io.IOException) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) AssertionException(javolution.testing.AssertionException) UnavailableException(alluxio.exception.status.UnavailableException) BlockInfoException(alluxio.exception.BlockInfoException) IOException(java.io.IOException) Test(org.junit.Test)

Example 14 with RegisterWorkerPRequest

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);
}
Also used : RegisterWorkerPRequest(alluxio.grpc.RegisterWorkerPRequest) IOException(java.io.IOException) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) AssertionException(javolution.testing.AssertionException) UnavailableException(alluxio.exception.status.UnavailableException) BlockInfoException(alluxio.exception.BlockInfoException) IOException(java.io.IOException) Test(org.junit.Test)

Example 15 with RegisterWorkerPRequest

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);
}
Also used : MasterWorkerInfo(alluxio.master.block.meta.MasterWorkerInfo) RegisterWorkerPRequest(alluxio.grpc.RegisterWorkerPRequest) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Test(org.junit.Test)

Aggregations

RegisterWorkerPRequest (alluxio.grpc.RegisterWorkerPRequest)30 Test (org.junit.Test)22 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)15 LocationBlockIdListEntry (alluxio.grpc.LocationBlockIdListEntry)9 BlockStoreLocation (alluxio.worker.block.BlockStoreLocation)9 MasterWorkerInfo (alluxio.master.block.meta.MasterWorkerInfo)8 StorageList (alluxio.grpc.StorageList)6 List (java.util.List)6 BlockIdList (alluxio.grpc.BlockIdList)5 BlockStoreLocationProto (alluxio.grpc.BlockStoreLocationProto)5 RegisterWorkerPResponse (alluxio.grpc.RegisterWorkerPResponse)5 RegisterStreamer (alluxio.worker.block.RegisterStreamer)5 ImmutableList (com.google.common.collect.ImmutableList)5 IOException (java.io.IOException)5 Command (alluxio.grpc.Command)4 StreamObserver (io.grpc.stub.StreamObserver)4 BlockInfoException (alluxio.exception.BlockInfoException)3 UnavailableException (alluxio.exception.status.UnavailableException)3 GetRegisterLeasePRequest (alluxio.grpc.GetRegisterLeasePRequest)3 BlockMasterWorkerServiceHandler (alluxio.master.block.BlockMasterWorkerServiceHandler)3