Search in sources :

Example 26 with RegisterWorkerPRequest

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

the class BlockMasterRegisterStreamIntegrationTest method registerLostWorker.

@Test
public // The master has marked the worker as lost.
void registerLostWorker() throws Exception {
    long workerId = mBlockMaster.getWorkerId(NET_ADDRESS_1);
    // The worker registers to the master
    List<RegisterWorkerPRequest> requestChunks = RegisterStreamTestUtils.generateRegisterStreamForWorker(workerId);
    prepareBlocksOnMaster(requestChunks);
    Queue<Throwable> errorQueue = new ConcurrentLinkedQueue<>();
    sendStreamToMaster(requestChunks, RegisterStreamTestUtils.getErrorCapturingResponseObserver(errorQueue));
    // Verify the worker has been registered
    assertEquals(0, errorQueue.size());
    assertEquals(1, mBlockMaster.getWorkerCount());
    // The worker has lost heartbeat and been forgotten
    MasterWorkerInfo worker = mBlockMaster.getWorker(workerId);
    long newTimeMs = worker.getLastUpdatedTimeMs() + MASTER_WORKER_TIMEOUT + 1;
    mClock.setTimeMs(newTimeMs);
    DefaultBlockMaster.LostWorkerDetectionHeartbeatExecutor lostWorkerDetector = ((DefaultBlockMaster) mBlockMaster).new LostWorkerDetectionHeartbeatExecutor();
    lostWorkerDetector.heartbeat();
    // Verify the worker has been forgotten
    assertEquals(0, mBlockMaster.getWorkerCount());
    // Register again
    Queue<Throwable> newErrorQueue = new ConcurrentLinkedQueue<>();
    sendStreamToMaster(requestChunks, RegisterStreamTestUtils.getErrorCapturingResponseObserver(newErrorQueue));
    // Verify the worker is registered again
    assertEquals(0, errorQueue.size());
    MasterWorkerInfo updatedWorker = mBlockMaster.getWorker(workerId);
    assertEquals(TIER_BLOCK_TOTAL, updatedWorker.getBlockCount());
    assertEquals(0, updatedWorker.getToRemoveBlockCount());
    assertEquals(1, mBlockMaster.getWorkerCount());
    // Verify the worker is readable and writable
    verifyWorkerWritable(workerId);
}
Also used : DefaultBlockMaster(alluxio.master.block.DefaultBlockMaster) MasterWorkerInfo(alluxio.master.block.meta.MasterWorkerInfo) RegisterWorkerPRequest(alluxio.grpc.RegisterWorkerPRequest) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Test(org.junit.Test)

Example 27 with RegisterWorkerPRequest

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

the class BlockMasterRegisterStreamIntegrationTest method reregisterWithDelete.

/**
 * Tests below cover the race conditions during concurrent executions.
 *
 * When the worker registers for the 1st time, no clients should know this worker.
 * Therefore there is no concurrent client-incurred write operations on this worker.
 * The races happen typically when the worker re-registers with the master,
 * where some clients already know this worker and can direct invoke writes on the worker.
 *
 * Tests here verify the integrity of the master-side metadata.
 * In other words, we assume those writers succeed on the worker, and the subsequent
 * update on the master-side metadata should also succeed and be correct.
 */
@Test
public void reregisterWithDelete() 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 remove
    long blockToRemove = RegisterStreamTestUtils.findFirstBlock(requestChunks);
    // Register again
    CountDownLatch latch = new CountDownLatch(1);
    Queue<Throwable> newErrorQueue = new ConcurrentLinkedQueue<>();
    Future f = mExecutorService.submit(() -> {
        sendStreamToMasterAndSignal(requestChunks, RegisterStreamTestUtils.getErrorCapturingResponseObserver(newErrorQueue), latch);
    });
    // During the register stream, trigger a delete on worker
    latch.await();
    mBlockMaster.removeBlocks(ImmutableList.of(blockToRemove), true);
    // Wait for the register to finish
    f.get();
    assertThrows(BlockInfoException.class, () -> {
        mBlockMaster.getBlockInfo(blockToRemove);
    });
    MasterWorkerInfo worker = mBlockMaster.getWorker(workerId);
    assertEquals(1, mBlockMaster.getWorkerCount());
    assertEquals(TIER_BLOCK_TOTAL - 1, worker.getBlockCount());
    // BlockMaster.removeBlocks() will first remove the block from master metadata
    // (with block lock) then update the block locations (with worker lock).
    // The worker lock is being held by the registering worker, but the 1st part
    // will likely succeed.
    // So during registration when checking on the block, the block is not recognized
    // any more and will remain in MasterWorkerInfo.mToRemoveBlocks.
    // In the next heartbeat the master will issue a command to remove the block
    // from the worker.
    // Even if the block is already removed on the worker it is fine,
    // because deletion of a not-found block is a noop.
    Command command = sendHeartbeatToMaster(workerId);
    assertEquals(Command.newBuilder().addData(blockToRemove).setCommandType(CommandType.Free).build(), command);
}
Also used : Command(alluxio.grpc.Command) MasterWorkerInfo(alluxio.master.block.meta.MasterWorkerInfo) Future(java.util.concurrent.Future) RegisterWorkerPRequest(alluxio.grpc.RegisterWorkerPRequest) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 28 with RegisterWorkerPRequest

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

the class BlockMasterRegisterStreamIntegrationTest method sendStreamToMasterAndSignal.

private void sendStreamToMasterAndSignal(List<RegisterWorkerPRequest> requestChunks, StreamObserver<RegisterWorkerPResponse> responseObserver, CountDownLatch latch) {
    StreamObserver<RegisterWorkerPRequest> requestObserver = mHandler.registerWorkerStream(responseObserver);
    for (int i = 0; i < requestChunks.size(); i++) {
        RegisterWorkerPRequest chunk = requestChunks.get(i);
        requestObserver.onNext(chunk);
        // Signal after the 1st request has been sent
        if (i == 0) {
            latch.countDown();
        }
    }
    requestObserver.onCompleted();
}
Also used : RegisterWorkerPRequest(alluxio.grpc.RegisterWorkerPRequest)

Example 29 with RegisterWorkerPRequest

use of alluxio.grpc.RegisterWorkerPRequest 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);
}
Also used : RegisterWorkerPRequest(alluxio.grpc.RegisterWorkerPRequest) RegisterStreamer(alluxio.worker.block.RegisterStreamer) Command(alluxio.grpc.Command) MasterWorkerInfo(alluxio.master.block.meta.MasterWorkerInfo) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) StorageList(alluxio.grpc.StorageList) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) BlockStoreLocation(alluxio.worker.block.BlockStoreLocation) Test(org.junit.Test)

Example 30 with RegisterWorkerPRequest

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

the class BlockWorkerRegisterStreamIntegrationTest method requestsForWorker.

@Test
public void requestsForWorker() throws Exception {
    List<RegisterWorkerPRequest> requestChunks = RegisterStreamTestUtils.generateRegisterStreamForWorker(WORKER_ID);
    // Verify the size and content of the requests
    int expectedBatchCount = (int) Math.ceil((TIER_BLOCK_TOTAL) / (double) BATCH_SIZE);
    Set<Long> containedBlockIds = new HashSet<>();
    assertEquals(expectedBatchCount, requestChunks.size());
    for (int i = 0; i < expectedBatchCount; i++) {
        RegisterWorkerPRequest request = requestChunks.get(i);
        assertEquals(WORKER_ID, request.getWorkerId());
        List<LocationBlockIdListEntry> entries = request.getCurrentBlocksList();
        int totalSize = 0;
        for (LocationBlockIdListEntry entry : entries) {
            totalSize += entry.getValue().getBlockIdCount();
            containedBlockIds.addAll(entry.getValue().getBlockIdList());
        }
        if (i != expectedBatchCount - 1) {
            assertEquals(BATCH_SIZE, totalSize);
        }
        // The 1st request contains metadata but the following do not
        if (i == 0) {
            assertEquals(USAGE_MAP, request.getUsedBytesOnTiersMap());
            assertEquals(CAPACITY_MAP, request.getTotalBytesOnTiersMap());
            Map<String, StorageList> lostMap = request.getLostStorageMap();
            assertEquals(1, lostMap.size());
            assertEquals(StorageList.newBuilder().build(), lostMap.get("MEM"));
            assertEquals(ImmutableList.of("MEM", "SSD", "HDD"), request.getStorageTiersList());
        } else {
            assertEquals(0, request.getStorageTiersCount());
            assertEquals(ImmutableMap.of(), request.getUsedBytesOnTiersMap());
            assertEquals(ImmutableMap.of(), request.getTotalBytesOnTiersMap());
            Map<String, StorageList> lostMap = request.getLostStorageMap();
            assertEquals(0, lostMap.size());
        }
    }
    assertEquals(containedBlockIds.size(), TIER_BLOCK_TOTAL);
}
Also used : ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) RegisterWorkerPRequest(alluxio.grpc.RegisterWorkerPRequest) StorageList(alluxio.grpc.StorageList) HashSet(java.util.HashSet) LocationBlockIdListEntry(alluxio.grpc.LocationBlockIdListEntry) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) 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