Search in sources :

Example 1 with LocationBlockIdListEntry

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

the class BlockMasterWorkerServiceHandlerTest method registerLeaseExpired.

@Test
public void registerLeaseExpired() {
    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();
    // Prepare a lease
    GetRegisterLeasePRequest leaseRequest = GetRegisterLeasePRequest.newBuilder().setWorkerId(workerId).setBlockCount(blockIdList1.getBlockIdCount()).build();
    Optional<RegisterLease> lease = mBlockMaster.tryAcquireRegisterLease(leaseRequest);
    assertTrue(lease.isPresent());
    // Sleep for a while so that the lease expires
    SleepUtils.sleepMs(5000);
    // The lease is recycled and taken away
    GetRegisterLeasePRequest newLeaseRequest = GetRegisterLeasePRequest.newBuilder().setWorkerId(workerId + 1).setBlockCount(blockIdList1.getBlockIdCount()).build();
    Optional<RegisterLease> newLease = mBlockMaster.tryAcquireRegisterLease(newLeaseRequest);
    assertTrue(newLease.isPresent());
    RegisterWorkerPRequest request = RegisterWorkerPRequest.newBuilder().setWorkerId(workerId).addStorageTiers("MEM").putTotalBytesOnTiers("MEM", 1000L).putUsedBytesOnTiers("MEM", 0L).setOptions(RegisterWorkerPOptions.getDefaultInstance()).addCurrentBlocks(listEntry1).build();
    // Noop response observer
    Queue<Throwable> errors = new ConcurrentLinkedDeque<>();
    StreamObserver<RegisterWorkerPResponse> noopResponseObserver = new StreamObserver<RegisterWorkerPResponse>() {

        @Override
        public void onNext(RegisterWorkerPResponse response) {
        }

        @Override
        public void onError(Throwable t) {
            errors.offer(t);
        }

        @Override
        public void onCompleted() {
        }
    };
    mHandler.registerWorker(request, noopResponseObserver);
    assertEquals(1, errors.size());
    Throwable t = errors.poll();
    Assert.assertThat(t.getMessage(), containsString("does not have a lease or the lease has expired."));
    mBlockMaster.releaseRegisterLease(workerId + 1);
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) BlockIdList(alluxio.grpc.BlockIdList) RegisterLease(alluxio.wire.RegisterLease) RegisterWorkerPRequest(alluxio.grpc.RegisterWorkerPRequest) LocationBlockIdListEntry(alluxio.grpc.LocationBlockIdListEntry) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) GetRegisterLeasePRequest(alluxio.grpc.GetRegisterLeasePRequest) RegisterWorkerPResponse(alluxio.grpc.RegisterWorkerPResponse) BlockStoreLocation(alluxio.worker.block.BlockStoreLocation) BlockStoreLocationProto(alluxio.grpc.BlockStoreLocationProto) Test(org.junit.Test)

Example 2 with LocationBlockIdListEntry

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

the class BlockMasterWorkerServiceHandlerTest method registerWithNoLeaseIsRejected.

@Test
public void registerWithNoLeaseIsRejected() {
    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();
    RegisterWorkerPRequest request = RegisterWorkerPRequest.newBuilder().setWorkerId(workerId).addStorageTiers("MEM").putTotalBytesOnTiers("MEM", 1000L).putUsedBytesOnTiers("MEM", 0L).setOptions(RegisterWorkerPOptions.getDefaultInstance()).addCurrentBlocks(listEntry1).build();
    Queue<Throwable> errors = new ConcurrentLinkedDeque<>();
    StreamObserver<RegisterWorkerPResponse> noopResponseObserver = new StreamObserver<RegisterWorkerPResponse>() {

        @Override
        public void onNext(RegisterWorkerPResponse response) {
        }

        @Override
        public void onError(Throwable t) {
            errors.offer(t);
        }

        @Override
        public void onCompleted() {
        }
    };
    // The responseObserver should see an error
    mHandler.registerWorker(request, noopResponseObserver);
    assertEquals(1, errors.size());
    Throwable t = errors.poll();
    Assert.assertThat(t.getMessage(), containsString("does not have a lease or the lease has expired."));
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) BlockIdList(alluxio.grpc.BlockIdList) RegisterWorkerPResponse(alluxio.grpc.RegisterWorkerPResponse) RegisterWorkerPRequest(alluxio.grpc.RegisterWorkerPRequest) BlockStoreLocation(alluxio.worker.block.BlockStoreLocation) BlockStoreLocationProto(alluxio.grpc.BlockStoreLocationProto) LocationBlockIdListEntry(alluxio.grpc.LocationBlockIdListEntry) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) Test(org.junit.Test)

Example 3 with LocationBlockIdListEntry

use of alluxio.grpc.LocationBlockIdListEntry 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);
    });
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) BlockIdList(alluxio.grpc.BlockIdList) BlockHeartbeatPRequest(alluxio.grpc.BlockHeartbeatPRequest) BlockHeartbeatPResponse(alluxio.grpc.BlockHeartbeatPResponse) BlockStoreLocation(alluxio.worker.block.BlockStoreLocation) BlockStoreLocationProto(alluxio.grpc.BlockStoreLocationProto) LocationBlockIdListEntry(alluxio.grpc.LocationBlockIdListEntry) Test(org.junit.Test)

Example 4 with LocationBlockIdListEntry

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

the class BlockMasterWorkerServiceHandlerTest method registerWorkerFailsOnDuplicateBlockLocation.

@Test
public void registerWorkerFailsOnDuplicateBlockLocation() 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();
    // Prepare a lease
    GetRegisterLeasePRequest leaseRequest = GetRegisterLeasePRequest.newBuilder().setWorkerId(workerId).setBlockCount(blockIdList1.getBlockIdCount() + blockIdList2.getBlockIdCount()).build();
    Optional<RegisterLease> lease = mBlockMaster.tryAcquireRegisterLease(leaseRequest);
    assertTrue(lease.isPresent());
    // The request is not deduplicated
    RegisterWorkerPRequest request = RegisterWorkerPRequest.newBuilder().setWorkerId(workerId).addStorageTiers("MEM").putTotalBytesOnTiers("MEM", 1000L).putUsedBytesOnTiers("MEM", 0L).setOptions(RegisterWorkerPOptions.getDefaultInstance()).addCurrentBlocks(listEntry1).addCurrentBlocks(listEntry2).build();
    // Noop response observer
    StreamObserver<RegisterWorkerPResponse> noopResponseObserver = new StreamObserver<RegisterWorkerPResponse>() {

        @Override
        public void onNext(RegisterWorkerPResponse response) {
        }

        @Override
        public void onError(Throwable t) {
        }

        @Override
        public void onCompleted() {
        }
    };
    assertThrows(AssertionError.class, () -> {
        mHandler.registerWorker(request, noopResponseObserver);
    });
    mBlockMaster.releaseRegisterLease(workerId);
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) BlockIdList(alluxio.grpc.BlockIdList) RegisterLease(alluxio.wire.RegisterLease) RegisterWorkerPRequest(alluxio.grpc.RegisterWorkerPRequest) LocationBlockIdListEntry(alluxio.grpc.LocationBlockIdListEntry) GetRegisterLeasePRequest(alluxio.grpc.GetRegisterLeasePRequest) RegisterWorkerPResponse(alluxio.grpc.RegisterWorkerPResponse) BlockStoreLocation(alluxio.worker.block.BlockStoreLocation) BlockStoreLocationProto(alluxio.grpc.BlockStoreLocationProto) Test(org.junit.Test)

Example 5 with LocationBlockIdListEntry

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

the class BlockMasterWorkerServiceHandlerTest method registerLeaseTurnedOff.

@Test
public void registerLeaseTurnedOff() throws Exception {
    initServiceHandler(false);
    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();
    // No lease is acquired
    RegisterWorkerPRequest request = RegisterWorkerPRequest.newBuilder().setWorkerId(workerId).addStorageTiers("MEM").putTotalBytesOnTiers("MEM", 1000L).putUsedBytesOnTiers("MEM", 0L).setOptions(RegisterWorkerPOptions.getDefaultInstance()).addCurrentBlocks(listEntry1).build();
    Queue<Throwable> errors = new ConcurrentLinkedDeque<>();
    StreamObserver<RegisterWorkerPResponse> noopResponseObserver = new StreamObserver<RegisterWorkerPResponse>() {

        @Override
        public void onNext(RegisterWorkerPResponse response) {
        }

        @Override
        public void onError(Throwable t) {
            errors.offer(t);
        }

        @Override
        public void onCompleted() {
        }
    };
    mHandler.registerWorker(request, noopResponseObserver);
    assertEquals(0, errors.size());
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) BlockIdList(alluxio.grpc.BlockIdList) RegisterWorkerPResponse(alluxio.grpc.RegisterWorkerPResponse) RegisterWorkerPRequest(alluxio.grpc.RegisterWorkerPRequest) BlockStoreLocation(alluxio.worker.block.BlockStoreLocation) BlockStoreLocationProto(alluxio.grpc.BlockStoreLocationProto) LocationBlockIdListEntry(alluxio.grpc.LocationBlockIdListEntry) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) Test(org.junit.Test)

Aggregations

LocationBlockIdListEntry (alluxio.grpc.LocationBlockIdListEntry)19 BlockStoreLocationProto (alluxio.grpc.BlockStoreLocationProto)10 RegisterWorkerPRequest (alluxio.grpc.RegisterWorkerPRequest)10 Test (org.junit.Test)10 BlockIdList (alluxio.grpc.BlockIdList)9 ArrayList (java.util.ArrayList)7 List (java.util.List)6 StorageList (alluxio.grpc.StorageList)5 BlockStoreLocation (alluxio.worker.block.BlockStoreLocation)5 StreamObserver (io.grpc.stub.StreamObserver)5 GetRegisterLeasePRequest (alluxio.grpc.GetRegisterLeasePRequest)4 RegisterWorkerPResponse (alluxio.grpc.RegisterWorkerPResponse)4 HashMap (java.util.HashMap)4 BlockHeartbeatPRequest (alluxio.grpc.BlockHeartbeatPRequest)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 ConcurrentLinkedDeque (java.util.concurrent.ConcurrentLinkedDeque)3 AbstractMasterClient (alluxio.AbstractMasterClient)2 Constants (alluxio.Constants)2