Search in sources :

Example 6 with GroupMismatchException

use of org.apache.ratis.protocol.exceptions.GroupMismatchException in project incubator-ratis by apache.

the class OrderedAsync method sendRequest.

private CompletableFuture<RaftClientReply> sendRequest(PendingOrderedRequest pending) {
    final RetryPolicy retryPolicy = client.getRetryPolicy();
    final CompletableFuture<RaftClientReply> f;
    final RaftClientRequest request;
    if (getSlidingWindow((RaftPeerId) null).isFirst(pending.getSeqNum())) {
        pending.setFirstRequest();
    }
    request = pending.newRequest();
    LOG.debug("{}: send* {}", client.getId(), request);
    f = client.getClientRpc().sendRequestAsync(request);
    return f.thenApply(reply -> {
        LOG.debug("{}: receive* {}", client.getId(), reply);
        getSlidingWindow(request).receiveReply(request.getSlidingWindowEntry().getSeqNum(), reply, this::sendRequestWithRetry);
        return reply;
    }).exceptionally(e -> {
        if (LOG.isTraceEnabled()) {
            LOG.trace(client.getId() + ": Failed* " + request, e);
        } else {
            LOG.debug("{}: Failed* {} with {}", client.getId(), request, e);
        }
        e = JavaUtils.unwrapCompletionException(e);
        if (e instanceof IOException && !(e instanceof GroupMismatchException)) {
            pending.incrementExceptionCount(e);
            final ClientRetryEvent event = new ClientRetryEvent(request, e, pending);
            if (!retryPolicy.handleAttemptFailure(event).shouldRetry()) {
                handleAsyncRetryFailure(event);
            } else {
                if (e instanceof NotLeaderException) {
                    NotLeaderException nle = (NotLeaderException) e;
                    client.handleNotLeaderException(request, nle, this::resetSlidingWindow);
                } else {
                    client.handleIOException(request, (IOException) e, null, this::resetSlidingWindow);
                }
            }
            throw new CompletionException(e);
        }
        failAllAsyncRequests(request, e);
        return null;
    });
}
Also used : Preconditions(org.apache.ratis.util.Preconditions) SlidingWindowEntry(org.apache.ratis.proto.RaftProtos.SlidingWindowEntry) LoggerFactory(org.slf4j.LoggerFactory) ClientRetryEvent(org.apache.ratis.client.retry.ClientRetryEvent) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) CallId(org.apache.ratis.rpc.CallId) ConcurrentMap(java.util.concurrent.ConcurrentMap) Message(org.apache.ratis.protocol.Message) NotLeaderException(org.apache.ratis.protocol.exceptions.NotLeaderException) ProtoUtils(org.apache.ratis.util.ProtoUtils) JavaUtils(org.apache.ratis.util.JavaUtils) IOUtils(org.apache.ratis.util.IOUtils) SlidingWindow(org.apache.ratis.util.SlidingWindow) Logger(org.slf4j.Logger) LongFunction(java.util.function.LongFunction) RetryPolicy(org.apache.ratis.retry.RetryPolicy) Semaphore(java.util.concurrent.Semaphore) RaftPeerId(org.apache.ratis.protocol.RaftPeerId) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) RaftClientRequest(org.apache.ratis.protocol.RaftClientRequest) IOException(java.io.IOException) CompletionException(java.util.concurrent.CompletionException) TypeCase(org.apache.ratis.proto.RaftProtos.RaftClientRequestProto.TypeCase) Objects(java.util.Objects) RaftClientReply(org.apache.ratis.protocol.RaftClientReply) RaftProperties(org.apache.ratis.conf.RaftProperties) Optional(java.util.Optional) GroupMismatchException(org.apache.ratis.protocol.exceptions.GroupMismatchException) RaftClientConfigKeys(org.apache.ratis.client.RaftClientConfigKeys) PendingClientRequest(org.apache.ratis.client.impl.RaftClientImpl.PendingClientRequest) TimeDuration(org.apache.ratis.util.TimeDuration) ClientRetryEvent(org.apache.ratis.client.retry.ClientRetryEvent) NotLeaderException(org.apache.ratis.protocol.exceptions.NotLeaderException) RaftClientRequest(org.apache.ratis.protocol.RaftClientRequest) RaftClientReply(org.apache.ratis.protocol.RaftClientReply) CompletionException(java.util.concurrent.CompletionException) GroupMismatchException(org.apache.ratis.protocol.exceptions.GroupMismatchException) RaftPeerId(org.apache.ratis.protocol.RaftPeerId) IOException(java.io.IOException) RetryPolicy(org.apache.ratis.retry.RetryPolicy)

Example 7 with GroupMismatchException

use of org.apache.ratis.protocol.exceptions.GroupMismatchException in project incubator-ratis by apache.

the class RaftServerProxy method groupManagementAsync.

@Override
public CompletableFuture<RaftClientReply> groupManagementAsync(GroupManagementRequest request) {
    final RaftGroupId groupId = request.getRaftGroupId();
    if (groupId == null) {
        return JavaUtils.completeExceptionally(new GroupMismatchException(getId() + ": Request group id == null"));
    }
    final GroupManagementRequest.Add add = request.getAdd();
    if (add != null) {
        return groupAddAsync(request, add.getGroup());
    }
    final GroupManagementRequest.Remove remove = request.getRemove();
    if (remove != null) {
        return groupRemoveAsync(request, remove.getGroupId(), remove.isDeleteDirectory(), remove.isRenameDirectory());
    }
    return JavaUtils.completeExceptionally(new UnsupportedOperationException(getId() + ": Request not supported " + request));
}
Also used : GroupMismatchException(org.apache.ratis.protocol.exceptions.GroupMismatchException)

Example 8 with GroupMismatchException

use of org.apache.ratis.protocol.exceptions.GroupMismatchException in project incubator-ratis by apache.

the class RaftServerProxy method snapshotManagementAsync.

@Override
public CompletableFuture<RaftClientReply> snapshotManagementAsync(SnapshotManagementRequest request) {
    final RaftGroupId groupId = request.getRaftGroupId();
    if (groupId == null) {
        return JavaUtils.completeExceptionally(new GroupMismatchException(getId() + ": Request group id == null"));
    }
    final SnapshotManagementRequest.Create create = request.getCreate();
    if (create != null) {
        return createAsync(request);
    }
    return JavaUtils.completeExceptionally(new UnsupportedOperationException(getId() + ": Request not supported " + request));
}
Also used : GroupMismatchException(org.apache.ratis.protocol.exceptions.GroupMismatchException)

Aggregations

GroupMismatchException (org.apache.ratis.protocol.exceptions.GroupMismatchException)8 IOException (java.io.IOException)5 RaftClientReply (org.apache.ratis.protocol.RaftClientReply)4 TimeDuration (org.apache.ratis.util.TimeDuration)4 ClientRetryEvent (org.apache.ratis.client.retry.ClientRetryEvent)3 RaftClientRequest (org.apache.ratis.protocol.RaftClientRequest)3 InterruptedIOException (java.io.InterruptedIOException)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 CompletionException (java.util.concurrent.CompletionException)2 RaftProperties (org.apache.ratis.conf.RaftProperties)2 AlreadyClosedException (org.apache.ratis.protocol.exceptions.AlreadyClosedException)2 AlreadyExistsException (org.apache.ratis.protocol.exceptions.AlreadyExistsException)2 LeaderSteppingDownException (org.apache.ratis.protocol.exceptions.LeaderSteppingDownException)2 NotLeaderException (org.apache.ratis.protocol.exceptions.NotLeaderException)2 RetryPolicy (org.apache.ratis.retry.RetryPolicy)2 Closeable (java.io.Closeable)1 File (java.io.File)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1