Search in sources :

Example 1 with StorageContainerException

use of org.apache.bookkeeper.clients.exceptions.StorageContainerException 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

StorageContainerException (org.apache.bookkeeper.clients.exceptions.StorageContainerException)1 StorageServerChannel (org.apache.bookkeeper.clients.impl.channel.StorageServerChannel)1 ObjectClosedException (org.apache.bookkeeper.common.exceptions.ObjectClosedException)1 Endpoint (org.apache.bookkeeper.stream.proto.common.Endpoint)1 OneStorageContainerEndpointResponse (org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse)1 StorageContainerEndpoint (org.apache.bookkeeper.stream.proto.storage.StorageContainerEndpoint)1