Search in sources :

Example 1 with ObjectClosedException

use of org.apache.bookkeeper.common.exceptions.ObjectClosedException in project bookkeeper by apache.

the class StorageContainerRegistryImpl method unsafeStartStorageContainer.

private CompletableFuture<Void> unsafeStartStorageContainer(long scId) {
    if (closed) {
        return FutureUtils.exception(new ObjectClosedException(COMPONENT_NAME));
    }
    if (groups.containsKey(scId)) {
        return FutureUtils.exception(new StorageException("StorageContainer " + scId + " already registered"));
    }
    StorageContainer newStorageContainer = scFactory.createStorageContainer(scId);
    StorageContainer oldStorageContainer = groups.putIfAbsent(scId, newStorageContainer);
    if (null != oldStorageContainer) {
        newStorageContainer.close();
        return FutureUtils.exception(new StorageException("StorageContainer " + scId + " already registered"));
    }
    log.info("Registered StorageContainer ('{}').", scId);
    return newStorageContainer.start();
}
Also used : ObjectClosedException(org.apache.bookkeeper.common.exceptions.ObjectClosedException) StorageException(org.apache.bookkeeper.stream.storage.exceptions.StorageException) StorageContainer(org.apache.bookkeeper.stream.storage.api.sc.StorageContainer)

Example 2 with ObjectClosedException

use of org.apache.bookkeeper.common.exceptions.ObjectClosedException 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 3 with ObjectClosedException

use of org.apache.bookkeeper.common.exceptions.ObjectClosedException 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 4 with ObjectClosedException

use of org.apache.bookkeeper.common.exceptions.ObjectClosedException in project bookkeeper by apache.

the class TestStorageContainerRegistryImpl method testOperationsAfterClosed.

@Test
public void testOperationsAfterClosed() throws Exception {
    StorageContainerFactory scFactory = createStorageContainerFactory();
    StorageContainerRegistryImpl registry = new StorageContainerRegistryImpl(scFactory, scheduler);
    registry.close();
    long scId = 1234L;
    try {
        FutureUtils.result(registry.startStorageContainer(scId));
        fail("Should fail to start storage container after registry is closed");
    } catch (ObjectClosedException oce) {
        // expected
        assertEquals(0, registry.getNumStorageContainers());
    }
    try {
        FutureUtils.result(registry.stopStorageContainer(scId));
        fail("Should fail to start storage container after registry is closed");
    } catch (ObjectClosedException oce) {
        // expected
        assertEquals(0, registry.getNumStorageContainers());
    }
}
Also used : StorageContainerFactory(org.apache.bookkeeper.stream.storage.api.sc.StorageContainerFactory) ObjectClosedException(org.apache.bookkeeper.common.exceptions.ObjectClosedException) Test(org.junit.Test)

Example 5 with ObjectClosedException

use of org.apache.bookkeeper.common.exceptions.ObjectClosedException in project bookkeeper by apache.

the class StorageContainerRegistryImpl method unsafeStopStorageContainer.

private CompletableFuture<Void> unsafeStopStorageContainer(long scId) {
    if (closed) {
        return FutureUtils.exception(new ObjectClosedException(COMPONENT_NAME));
    }
    StorageContainer group = groups.remove(scId);
    if (null == group) {
        return FutureUtils.value(null);
    }
    log.info("Unregistered StorageContainer ('{}').", scId);
    return group.stop();
}
Also used : ObjectClosedException(org.apache.bookkeeper.common.exceptions.ObjectClosedException) StorageContainer(org.apache.bookkeeper.stream.storage.api.sc.StorageContainer)

Aggregations

ObjectClosedException (org.apache.bookkeeper.common.exceptions.ObjectClosedException)6 StorageServerChannel (org.apache.bookkeeper.clients.impl.channel.StorageServerChannel)2 OneStorageContainerEndpointResponse (org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse)2 StorageContainer (org.apache.bookkeeper.stream.storage.api.sc.StorageContainer)2 Test (org.junit.Test)2 File (java.io.File)1 Path (java.nio.file.Path)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1 StorageContainerException (org.apache.bookkeeper.clients.exceptions.StorageContainerException)1 StateStoreSpec (org.apache.bookkeeper.statelib.api.StateStoreSpec)1 Endpoint (org.apache.bookkeeper.stream.proto.common.Endpoint)1 StorageContainerEndpoint (org.apache.bookkeeper.stream.proto.storage.StorageContainerEndpoint)1 StorageContainerFactory (org.apache.bookkeeper.stream.storage.api.sc.StorageContainerFactory)1 StorageException (org.apache.bookkeeper.stream.storage.exceptions.StorageException)1 ArgumentMatchers.anyList (org.mockito.ArgumentMatchers.anyList)1