Search in sources :

Example 11 with StorageServerChannel

use of org.apache.bookkeeper.clients.impl.channel.StorageServerChannel in project bookkeeper by apache.

the class TestStorageContainerChannel method testGetRootRangeServiceUnexpectedException.

@Test
public void testGetRootRangeServiceUnexpectedException() throws Exception {
    CompletableFuture<List<OneStorageContainerEndpointResponse>> locateResponses1 = FutureUtils.createFuture();
    CompletableFuture<List<OneStorageContainerEndpointResponse>> locateResponses2 = FutureUtils.createFuture();
    when(locationClient.locateStorageContainers(anyList())).thenReturn(locateResponses1).thenReturn(locateResponses2);
    // the future is not set before #getRootRangeService
    assertNull(scClient.getStorageServerChannelFuture());
    assertNull(scClient.getStorageContainerInfo());
    // call #getRootRangeService
    CompletableFuture<StorageServerChannel> rsChannelFuture = scClient.getStorageContainerChannelFuture();
    // the future is set and the locationClient#locateStorageContainers is called
    assertNotNull(scClient.getStorageServerChannelFuture());
    assertNull(scClient.getStorageContainerInfo());
    verify(locationClient, times(1)).locateStorageContainers(anyList());
    // if the request is outstanding, a second call will not call locationClient#locateStorageContainers
    CompletableFuture<StorageServerChannel> rsChannelFuture1 = scClient.getStorageContainerChannelFuture();
    assertTrue(rsChannelFuture == rsChannelFuture1);
    assertNull(scClient.getStorageContainerInfo());
    verify(locationClient, times(1)).locateStorageContainers(anyList());
    // prepare the result and complete the request
    OneStorageContainerEndpointResponse oneResp = OneStorageContainerEndpointResponse.newBuilder().setStatusCode(StatusCode.SUCCESS).setEndpoint(StorageContainerEndpoint.newBuilder().setStorageContainerId(ROOT_STORAGE_CONTAINER_ID).setRevision(1000L).setRwEndpoint(endpoint).addRoEndpoint(endpoint).build()).build();
    // complete with wrong responses
    locateResponses1.complete(Lists.newArrayList(oneResp, oneResp));
    ensureCallbackExecuted();
    // verify channel
    assertNull(channelManager.getChannel(endpoint));
    // verify storage container info
    assertNull(scClient.getStorageContainerInfo());
    // complete with right responses
    locateResponses2.complete(Lists.newArrayList(oneResp));
    // get the service
    StorageServerChannel rsChannel = rsChannelFuture.get();
    assertTrue(rsChannel == mockChannel);
    // verify storage container info
    StorageContainerInfo scInfo = scClient.getStorageContainerInfo();
    assertEquals(ROOT_STORAGE_CONTAINER_ID, scInfo.getGroupId());
    assertEquals(1000L, scInfo.getRevision());
    assertEquals(endpoint, scInfo.getWriteEndpoint());
    assertEquals(Lists.newArrayList(endpoint, endpoint), scInfo.getReadEndpoints());
    // verify channel
    assertEquals(mockChannel, channelManager.getChannel(endpoint));
    verify(locationClient, times(2)).locateStorageContainers(anyList());
}
Also used : OneStorageContainerEndpointResponse(org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse) StorageServerChannel(org.apache.bookkeeper.clients.impl.channel.StorageServerChannel) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) List(java.util.List) Test(org.junit.Test)

Example 12 with StorageServerChannel

use of org.apache.bookkeeper.clients.impl.channel.StorageServerChannel in project bookkeeper by apache.

the class TestMetaRangeClientImpl method testGetActiveStreamRanges.

@Test
public void testGetActiveStreamRanges() throws Exception {
    CompletableFuture<StorageServerChannel> serviceFuture = FutureUtils.createFuture();
    metaRangeClient.getStorageContainerClient().setStorageServerChannelFuture(serviceFuture);
    // create response
    GetActiveRangesResponse getActiveRangesResponse = GetActiveRangesResponse.newBuilder().addRanges(buildRelatedRange(Long.MIN_VALUE, 0L, 123L, 1L, Lists.newArrayList(113L))).addRanges(buildRelatedRange(0L, Long.MAX_VALUE, 124L, 2L, Lists.newArrayList(114L))).build();
    StorageContainerResponse response = StorageContainerResponse.newBuilder().setCode(StatusCode.SUCCESS).setGetActiveRangesResp(getActiveRangesResponse).build();
    MetaRangeServiceImplBase metaRangeService = new MetaRangeServiceImplBase() {

        @Override
        public void getActiveRanges(StorageContainerRequest request, StreamObserver<StorageContainerResponse> responseObserver) {
            responseObserver.onNext(response);
            responseObserver.onCompleted();
        }
    };
    serviceRegistry.addService(metaRangeService.bindService());
    StorageServerChannel rsChannel = new StorageServerChannel(InProcessChannelBuilder.forName(serverName).directExecutor().build(), Optional.empty());
    serviceFuture.complete(rsChannel);
    HashStreamRanges expectedStream = createActiveRanges(response.getGetActiveRangesResp());
    CompletableFuture<HashStreamRanges> getFuture = metaRangeClient.getActiveDataRanges();
    assertEquals(expectedStream, getFuture.get());
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) HashStreamRanges(org.apache.bookkeeper.clients.impl.internal.api.HashStreamRanges) StorageContainerRequest(org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest) GetActiveRangesResponse(org.apache.bookkeeper.stream.proto.storage.GetActiveRangesResponse) StorageServerChannel(org.apache.bookkeeper.clients.impl.channel.StorageServerChannel) MetaRangeServiceImplBase(org.apache.bookkeeper.stream.proto.storage.MetaRangeServiceGrpc.MetaRangeServiceImplBase) StorageContainerResponse(org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse) Test(org.junit.Test)

Example 13 with StorageServerChannel

use of org.apache.bookkeeper.clients.impl.channel.StorageServerChannel in project bookkeeper by apache.

the class GrpcClientTestBase method setUp.

@Before
public void setUp() throws Exception {
    fakeServer = InProcessServerBuilder.forName(serverName).fallbackHandlerRegistry(serviceRegistry).directExecutor().build().start();
    scheduler = OrderedScheduler.newSchedulerBuilder().name("scheduler-" + getClass()).numThreads(Runtime.getRuntime().availableProcessors()).build();
    settings = StorageClientSettings.newBuilder().managedChannelBuilder(InProcessChannelBuilder.forName(serverName).directExecutor()).usePlaintext(true).build();
    serverManager = new StorageServerClientManagerImpl(settings, resources.scheduler(), endpoint -> new StorageServerChannel(InProcessChannelBuilder.forName(serverName).directExecutor().build(), Optional.empty()));
    StorageContainerServiceImplBase scService = new StorageContainerServiceImplBase() {

        @Override
        public void getStorageContainerEndpoint(GetStorageContainerEndpointRequest request, StreamObserver<GetStorageContainerEndpointResponse> responseObserver) {
            GetStorageContainerEndpointResponse.Builder respBuilder = GetStorageContainerEndpointResponse.newBuilder();
            respBuilder.setStatusCode(StatusCode.SUCCESS);
            for (OneStorageContainerEndpointRequest oneReq : request.getRequestsList()) {
                OneStorageContainerEndpointResponse oneResp = OneStorageContainerEndpointResponse.newBuilder().setEndpoint(StorageContainerEndpoint.newBuilder().setStorageContainerId(oneReq.getStorageContainer()).setRevision(oneReq.getRevision() + 1).setRwEndpoint(ENDPOINT)).build();
                respBuilder.addResponses(oneResp);
            }
            responseObserver.onNext(respBuilder.build());
            responseObserver.onCompleted();
        }
    };
    serviceRegistry.addService(scService.bindService());
    doSetup();
}
Also used : GetStorageContainerEndpointRequest(org.apache.bookkeeper.stream.proto.storage.GetStorageContainerEndpointRequest) StorageServerChannel(org.apache.bookkeeper.clients.impl.channel.StorageServerChannel) OrderedScheduler(org.apache.bookkeeper.common.util.OrderedScheduler) OneStorageContainerEndpointResponse(org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse) StorageContainerServiceImplBase(org.apache.bookkeeper.stream.proto.storage.StorageContainerServiceGrpc.StorageContainerServiceImplBase) InProcessServerBuilder(io.grpc.inprocess.InProcessServerBuilder) MutableHandlerRegistry(io.grpc.util.MutableHandlerRegistry) ClientResources(org.apache.bookkeeper.clients.utils.ClientResources) OneStorageContainerEndpointRequest(org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointRequest) StreamObserver(io.grpc.stub.StreamObserver) StorageServerClientManagerImpl(org.apache.bookkeeper.clients.impl.internal.StorageServerClientManagerImpl) StorageClientSettings(org.apache.bookkeeper.clients.config.StorageClientSettings) Endpoint(org.apache.bookkeeper.stream.proto.common.Endpoint) StorageContainerEndpoint(org.apache.bookkeeper.stream.proto.storage.StorageContainerEndpoint) After(org.junit.After) Optional(java.util.Optional) Server(io.grpc.Server) InProcessChannelBuilder(io.grpc.inprocess.InProcessChannelBuilder) StatusCode(org.apache.bookkeeper.stream.proto.storage.StatusCode) GetStorageContainerEndpointResponse(org.apache.bookkeeper.stream.proto.storage.GetStorageContainerEndpointResponse) Before(org.junit.Before) StreamObserver(io.grpc.stub.StreamObserver) StorageContainerServiceImplBase(org.apache.bookkeeper.stream.proto.storage.StorageContainerServiceGrpc.StorageContainerServiceImplBase) StorageServerClientManagerImpl(org.apache.bookkeeper.clients.impl.internal.StorageServerClientManagerImpl) GetStorageContainerEndpointResponse(org.apache.bookkeeper.stream.proto.storage.GetStorageContainerEndpointResponse) OneStorageContainerEndpointResponse(org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse) StorageServerChannel(org.apache.bookkeeper.clients.impl.channel.StorageServerChannel) GetStorageContainerEndpointRequest(org.apache.bookkeeper.stream.proto.storage.GetStorageContainerEndpointRequest) OneStorageContainerEndpointRequest(org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointRequest) Before(org.junit.Before)

Example 14 with StorageServerChannel

use of org.apache.bookkeeper.clients.impl.channel.StorageServerChannel in project bookkeeper by apache.

the class StorageContainerChannel method handleFetchStorageContainerInfoSuccess.

private void handleFetchStorageContainerInfoSuccess(List<OneStorageContainerEndpointResponse> storageContainerEndpoints) {
    if (storageContainerEndpoints.size() != 1) {
        handleFetchStorageContainerInfoFailure(new Exception("Expected only one storage container endpoint. But found " + storageContainerEndpoints.size() + " storage container endpoints."));
        return;
    }
    OneStorageContainerEndpointResponse response = storageContainerEndpoints.get(0);
    if (StatusCode.SUCCESS != response.getStatusCode()) {
        handleFetchStorageContainerInfoFailure(new StorageContainerException(response.getStatusCode(), "fail to fetch location for storage container (" + scId + ")"));
        return;
    }
    StorageContainerEndpoint endpoint = response.getEndpoint();
    if (null != scInfo && scInfo.getRevision() >= endpoint.getRevision()) {
        handleFetchStorageContainerInfoFailure(new StorageContainerException(StatusCode.STALE_GROUP_INFO, "Fetched a stale storage container info : current = " + scInfo.getRevision() + ", fetched = " + endpoint.getRevision() + ""));
        return;
    }
    // we got the updated location
    List<Endpoint> readEndpoints = Lists.newArrayListWithExpectedSize(1 + endpoint.getRoEndpointCount());
    readEndpoints.add(endpoint.getRwEndpoint());
    readEndpoints.addAll(endpoint.getRoEndpointList());
    scInfo = StorageContainerInfo.of(scId, endpoint.getRevision(), endpoint.getRwEndpoint(), readEndpoints);
    // get the channel from channel manager (if it doesn't exist create one)
    StorageServerChannel serverChannel = channelManager.getOrCreateChannel(endpoint.getRwEndpoint());
    if (null == serverChannel) {
        log.info("No channel found/created for range server {}. The channel manager must be shutting down." + " Stop the process of fetching storage container ({}).", endpoint.getRwEndpoint(), scId);
        synchronized (this) {
            rsChannelFuture.completeExceptionally(new ObjectClosedException("StorageServerChannelManager is closed"));
        }
        return;
    }
    // update the future
    synchronized (this) {
        rsChannelFuture.complete(serverChannel);
    }
}
Also used : StorageContainerEndpoint(org.apache.bookkeeper.stream.proto.storage.StorageContainerEndpoint) Endpoint(org.apache.bookkeeper.stream.proto.common.Endpoint) StorageContainerEndpoint(org.apache.bookkeeper.stream.proto.storage.StorageContainerEndpoint) OneStorageContainerEndpointResponse(org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse) ObjectClosedException(org.apache.bookkeeper.common.exceptions.ObjectClosedException) StorageServerChannel(org.apache.bookkeeper.clients.impl.channel.StorageServerChannel) StorageContainerException(org.apache.bookkeeper.clients.exceptions.StorageContainerException) StorageContainerException(org.apache.bookkeeper.clients.exceptions.StorageContainerException) ObjectClosedException(org.apache.bookkeeper.common.exceptions.ObjectClosedException)

Aggregations

StorageServerChannel (org.apache.bookkeeper.clients.impl.channel.StorageServerChannel)14 Test (org.junit.Test)11 OneStorageContainerEndpointResponse (org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse)7 List (java.util.List)5 ArgumentMatchers.anyList (org.mockito.ArgumentMatchers.anyList)5 StreamObserver (io.grpc.stub.StreamObserver)4 RootRangeServiceImplBase (org.apache.bookkeeper.stream.proto.storage.RootRangeServiceGrpc.RootRangeServiceImplBase)3 StorageContainerRequest (org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest)3 ExecutionException (java.util.concurrent.ExecutionException)2 HashStreamRanges (org.apache.bookkeeper.clients.impl.internal.api.HashStreamRanges)2 ObjectClosedException (org.apache.bookkeeper.common.exceptions.ObjectClosedException)2 Endpoint (org.apache.bookkeeper.stream.proto.common.Endpoint)2 MetaRangeServiceImplBase (org.apache.bookkeeper.stream.proto.storage.MetaRangeServiceGrpc.MetaRangeServiceImplBase)2 StorageContainerEndpoint (org.apache.bookkeeper.stream.proto.storage.StorageContainerEndpoint)2 StorageContainerResponse (org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse)2 Server (io.grpc.Server)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 InProcessChannelBuilder (io.grpc.inprocess.InProcessChannelBuilder)1 InProcessServerBuilder (io.grpc.inprocess.InProcessServerBuilder)1 MutableHandlerRegistry (io.grpc.util.MutableHandlerRegistry)1