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();
}
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());
}
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);
}
}
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());
}
}
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();
}
Aggregations