Search in sources :

Example 6 with OneStorageContainerEndpointResponse

use of org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse in project bookkeeper by apache.

the class TestStorageContainerChannel method testGetRootRangeServiceFailureWhenClosingChannelManager.

@Test
public void testGetRootRangeServiceFailureWhenClosingChannelManager() throws Exception {
    CompletableFuture<List<OneStorageContainerEndpointResponse>> locateResponses = FutureUtils.createFuture();
    when(locationClient.locateStorageContainers(anyList())).thenReturn(locateResponses);
    // 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());
    // closing the channel manager
    channelManager.close();
    // 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();
    locateResponses.complete(Lists.newArrayList(oneResp));
    // verify the result
    try {
        rsChannelFuture.get();
        fail("Should fail get root range service if channel manager is shutting down.");
    } catch (ExecutionException ee) {
        assertNotNull(ee.getCause());
        assertTrue(ee.getCause() instanceof ObjectClosedException);
    }
    // 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
    assertNull(channelManager.getChannel(endpoint));
    verify(locationClient, times(1)).locateStorageContainers(anyList());
}
Also used : OneStorageContainerEndpointResponse(org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse) ObjectClosedException(org.apache.bookkeeper.common.exceptions.ObjectClosedException) StorageServerChannel(org.apache.bookkeeper.clients.impl.channel.StorageServerChannel) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) List(java.util.List) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 7 with OneStorageContainerEndpointResponse

use of org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse 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 8 with OneStorageContainerEndpointResponse

use of org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse 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 9 with OneStorageContainerEndpointResponse

use of org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse 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)

Example 10 with OneStorageContainerEndpointResponse

use of org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse in project bookkeeper by apache.

the class LocationClientTest method testLocateStorageContainers.

@Test
public void testLocateStorageContainers() throws Exception {
    List<OneStorageContainerEndpointResponse> responses = client.locateStorageContainers(Lists.newArrayList(Revisioned.of(ROOT_STORAGE_CONTAINER_ID, -1L))).get();
    assertEquals(1, responses.size());
    OneStorageContainerEndpointResponse oneResponse = responses.get(0);
    assertEquals(StatusCode.SUCCESS, oneResponse.getStatusCode());
    Endpoint endpoint = oneResponse.getEndpoint().getRwEndpoint();
    log.info("Current cluster endpoints = {}", cluster.getRpcEndpoints());
    log.info("Response : rw endpoint = {}", endpoint);
    assertTrue(cluster.getRpcEndpoints().contains(endpoint));
    assertEquals(1, oneResponse.getEndpoint().getRoEndpointCount());
    endpoint = oneResponse.getEndpoint().getRoEndpoint(0);
    log.info("Response : ro endpoint = {}", endpoint);
    assertTrue(cluster.getRpcEndpoints().contains(endpoint));
}
Also used : Endpoint(org.apache.bookkeeper.stream.proto.common.Endpoint) OneStorageContainerEndpointResponse(org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse) Test(org.junit.Test)

Aggregations

OneStorageContainerEndpointResponse (org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse)10 Test (org.junit.Test)8 StorageServerChannel (org.apache.bookkeeper.clients.impl.channel.StorageServerChannel)7 List (java.util.List)5 ArgumentMatchers.anyList (org.mockito.ArgumentMatchers.anyList)5 Endpoint (org.apache.bookkeeper.stream.proto.common.Endpoint)3 StorageContainerEndpoint (org.apache.bookkeeper.stream.proto.storage.StorageContainerEndpoint)3 ObjectClosedException (org.apache.bookkeeper.common.exceptions.ObjectClosedException)2 GetStorageContainerEndpointResponse (org.apache.bookkeeper.stream.proto.storage.GetStorageContainerEndpointResponse)2 Server (io.grpc.Server)1 InProcessChannelBuilder (io.grpc.inprocess.InProcessChannelBuilder)1 InProcessServerBuilder (io.grpc.inprocess.InProcessServerBuilder)1 StreamObserver (io.grpc.stub.StreamObserver)1 MutableHandlerRegistry (io.grpc.util.MutableHandlerRegistry)1 Optional (java.util.Optional)1 ExecutionException (java.util.concurrent.ExecutionException)1 StorageClientSettings (org.apache.bookkeeper.clients.config.StorageClientSettings)1 ClientException (org.apache.bookkeeper.clients.exceptions.ClientException)1 StorageContainerException (org.apache.bookkeeper.clients.exceptions.StorageContainerException)1 StorageServerClientManagerImpl (org.apache.bookkeeper.clients.impl.internal.StorageServerClientManagerImpl)1