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