Search in sources :

Example 1 with StorageContainerEndpoint

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

the class TestProtocolInternalUtils method testCreateStorageContainerEndpointResponse.

@Test
public void testCreateStorageContainerEndpointResponse() {
    List<StorageContainerEndpoint> endpoints = Lists.newArrayList(StorageContainerEndpoint.newBuilder().setStorageContainerId(1L).build(), StorageContainerEndpoint.newBuilder().setStorageContainerId(2L).build(), StorageContainerEndpoint.newBuilder().setStorageContainerId(3L).build());
    GetStorageContainerEndpointResponse response = createGetStorageContainerEndpointResponse(endpoints);
    assertEquals(3, response.getResponsesCount());
    int i = 0;
    for (OneStorageContainerEndpointResponse oneResp : response.getResponsesList()) {
        assertEquals(StatusCode.SUCCESS, oneResp.getStatusCode());
        assertTrue(endpoints.get(i) == oneResp.getEndpoint());
        ++i;
    }
}
Also used : StorageContainerEndpoint(org.apache.bookkeeper.stream.proto.storage.StorageContainerEndpoint) ProtoUtils.createGetStorageContainerEndpointResponse(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createGetStorageContainerEndpointResponse) GetStorageContainerEndpointResponse(org.apache.bookkeeper.stream.proto.storage.GetStorageContainerEndpointResponse) OneStorageContainerEndpointResponse(org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse) StorageContainerEndpoint(org.apache.bookkeeper.stream.proto.storage.StorageContainerEndpoint) Test(org.junit.Test)

Example 2 with StorageContainerEndpoint

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

the class ProtoUtils method createGetStorageContainerEndpointResponse.

/**
 * Create a {@link GetStorageContainerEndpointResponse}.
 *
 * @param endpoints list of storage container endpoints
 * @return a get storage container endpoint response.
 */
public static GetStorageContainerEndpointResponse createGetStorageContainerEndpointResponse(List<StorageContainerEndpoint> endpoints) {
    GetStorageContainerEndpointResponse.Builder builder = GetStorageContainerEndpointResponse.newBuilder();
    builder.setStatusCode(StatusCode.SUCCESS);
    for (StorageContainerEndpoint endpoint : endpoints) {
        builder.addResponses(OneStorageContainerEndpointResponse.newBuilder().setStatusCode(StatusCode.SUCCESS).setEndpoint(endpoint));
    }
    return builder.build();
}
Also used : StorageContainerEndpoint(org.apache.bookkeeper.stream.proto.storage.StorageContainerEndpoint) GetStorageContainerEndpointResponse(org.apache.bookkeeper.stream.proto.storage.GetStorageContainerEndpointResponse)

Example 3 with StorageContainerEndpoint

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

StorageContainerEndpoint (org.apache.bookkeeper.stream.proto.storage.StorageContainerEndpoint)3 GetStorageContainerEndpointResponse (org.apache.bookkeeper.stream.proto.storage.GetStorageContainerEndpointResponse)2 OneStorageContainerEndpointResponse (org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse)2 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 ProtoUtils.createGetStorageContainerEndpointResponse (org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createGetStorageContainerEndpointResponse)1 Test (org.junit.Test)1