use of org.apache.ratis.protocol.exceptions.TimeoutIOException in project incubator-ratis by apache.
the class NettyRpcProxy method send.
public RaftNettyServerReplyProto send(RaftRpcRequestProto request, RaftNettyServerRequestProto proto) throws IOException {
final CompletableFuture<RaftNettyServerReplyProto> reply = new CompletableFuture<>();
final ChannelFuture channelFuture = connection.offer(proto, reply);
try {
channelFuture.sync();
TimeDuration newDuration = requestTimeoutDuration.add(request.getTimeoutMs(), TimeUnit.MILLISECONDS);
return reply.get(newDuration.getDuration(), newDuration.getUnit());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw IOUtils.toInterruptedIOException(ProtoUtils.toString(request) + " sending from " + peer + " is interrupted.", e);
} catch (ExecutionException e) {
throw IOUtils.toIOException(e);
} catch (TimeoutException e) {
throw new TimeoutIOException(e.getMessage(), e);
}
}
use of org.apache.ratis.protocol.exceptions.TimeoutIOException in project incubator-ratis by apache.
the class TestExceptionDependentRetry method testExceptionDependentRetrySuccess.
@Test
public void testExceptionDependentRetrySuccess() {
ExceptionDependentRetry.Builder builder = ExceptionDependentRetry.newBuilder();
int ioExceptionRetries = 1;
int timeoutExceptionRetries = 2;
int defaultExceptionRetries = 5;
long ioExceptionSleepTime = 1;
long timeoutExceptionSleepTime = 4;
long defaultExceptionSleepTime = 10;
int maxAttempts = 3;
builder.setDefaultPolicy(RetryPolicies.retryUpToMaximumCountWithFixedSleep(defaultExceptionRetries, TimeDuration.valueOf(defaultExceptionSleepTime, TimeUnit.SECONDS)));
builder.setExceptionToPolicy(IOException.class, RetryPolicies.retryUpToMaximumCountWithFixedSleep(ioExceptionRetries, TimeDuration.valueOf(ioExceptionSleepTime, TimeUnit.SECONDS)));
builder.setExceptionToPolicy(TimeoutIOException.class, RetryPolicies.retryUpToMaximumCountWithFixedSleep(timeoutExceptionRetries, TimeDuration.valueOf(timeoutExceptionSleepTime, TimeUnit.SECONDS)));
builder.setMaxAttempts(maxAttempts);
ExceptionDependentRetry exceptionDependentRetry = builder.build();
testException(ioExceptionRetries, maxAttempts, exceptionDependentRetry, new IOException(), ioExceptionSleepTime);
testException(timeoutExceptionRetries, maxAttempts, exceptionDependentRetry, new TimeoutIOException("time out"), timeoutExceptionSleepTime);
// now try with an exception which is not there in the map.
testException(defaultExceptionRetries, maxAttempts, exceptionDependentRetry, new TimeoutException(), defaultExceptionSleepTime);
}
use of org.apache.ratis.protocol.exceptions.TimeoutIOException in project incubator-ratis by apache.
the class GrpcUtil method tryUnwrapException.
static IOException tryUnwrapException(StatusRuntimeException se) {
final Status status = se.getStatus();
if (status != null && status.getCode() == Status.Code.DEADLINE_EXCEEDED) {
return new TimeoutIOException(status.getDescription(), se);
}
final Metadata trailers = se.getTrailers();
if (trailers == null) {
return null;
}
final byte[] bytes = trailers.get(EXCEPTION_OBJECT_KEY);
if (bytes != null) {
try {
return IOUtils.bytes2Object(bytes, IOException.class);
} catch (Exception e) {
se.addSuppressed(e);
}
}
if (status != null) {
final String className = trailers.get(EXCEPTION_TYPE_KEY);
if (className != null) {
try {
final Class<? extends Throwable> clazz = Class.forName(className).asSubclass(Throwable.class);
final Throwable unwrapped = ReflectionUtils.instantiateException(clazz, status.getDescription());
return IOUtils.asIOException(unwrapped.initCause(se));
} catch (Throwable e) {
se.addSuppressed(e);
return new IOException(se);
}
}
}
return null;
}
Aggregations