org.apache.ratis.protocol.TimeoutIOException Java Examples

The following examples show how to use org.apache.ratis.protocol.TimeoutIOException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WatchRequestTests.java    From incubator-ratis with Apache License 2.0 6 votes vote down vote up
static void runTestWatchRequestClientTimeout(TestParameters p) throws Exception {
  final Logger LOG = p.log;

  CompletableFuture<RaftClientReply> watchReply;
  // watch 1000 which will never be committed
  // so client can not receive reply, and connection closed, throw TimeoutException.
  // We should not retry, because if retry, RaftClientImpl::handleIOException will random select a leader,
  // then sometimes throw NotLeaderException.
  watchReply = p.sendWatchRequest(1000, RetryPolicies.noRetry());

  try {
    watchReply.get();
    fail("runTestWatchRequestClientTimeout failed");
  } catch (Exception ex) {
    LOG.error("error occurred", ex);
    Assert.assertTrue(ex.getCause().getClass() == AlreadyClosedException.class ||
        ex.getCause().getClass() == RaftRetryFailureException.class);
    if (ex.getCause() != null) {
      if (ex.getCause().getCause() != null) {
        Assert.assertEquals(TimeoutIOException.class,
            ex.getCause().getCause().getClass());
      }
    }
  }
}
 
Example #2
Source File: RatisHelper.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
private static ExceptionDependentRetry createExceptionDependentPolicy(
    ExponentialBackoffRetry exponentialBackoffRetry,
    MultipleLinearRandomRetry multipleLinearRandomRetry,
    RetryPolicy timeoutPolicy) {
  ExceptionDependentRetry.Builder builder =
      ExceptionDependentRetry.newBuilder();
  for (Class c : NO_RETRY_EXCEPTIONS) {
    builder.setExceptionToPolicy(c, RetryPolicies.noRetry());
  }
  return builder.setExceptionToPolicy(ResourceUnavailableException.class,
          exponentialBackoffRetry)
      .setExceptionToPolicy(TimeoutIOException.class, timeoutPolicy)
      .setDefaultPolicy(multipleLinearRandomRetry)
      .build();
}
 
Example #3
Source File: TestExceptionDependentRetry.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
@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);

}
 
Example #4
Source File: TestExceptionDependentRetry.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
@Test
public void testExceptionRetryAttempts()
    throws InterruptedException, IOException {
  RaftProperties prop = new RaftProperties();
  RaftClientConfigKeys.Rpc.setRequestTimeout(prop, TimeDuration.valueOf(100, TimeUnit.MILLISECONDS));
  prop.setClass(MiniRaftCluster.STATEMACHINE_CLASS_KEY,
      SimpleStateMachine4Testing.class, StateMachine.class);
  RaftServerConfigKeys.Write.setElementLimit(prop, 1);
  MiniRaftClusterWithGrpc cluster = getFactory().newCluster(1, prop);
  RaftServerImpl leader = null;
  try {
    cluster.start();
    ExceptionDependentRetry.Builder builder =
        ExceptionDependentRetry.newBuilder();
    builder.setExceptionToPolicy(TimeoutIOException.class,
        MultipleLinearRandomRetry.parseCommaSeparated("1ms, 5"));
    builder.setDefaultPolicy(RetryPolicies.retryForeverNoSleep());

    // create a client with the exception dependent policy
    try (final RaftClient client = cluster.createClient(builder.build())) {
      client.sendAsync(new RaftTestUtil.SimpleMessage("1")).get();

      leader = cluster.getLeader();
      ((SimpleStateMachine4Testing) leader.getStateMachine()).blockWriteStateMachineData();

      client.sendAsync(new RaftTestUtil.SimpleMessage("2")).get();
    }
    Assert.fail("Test should have failed.");
  } catch (ExecutionException e) {
    RaftRetryFailureException rrfe = (RaftRetryFailureException) e.getCause();
    Assert.assertEquals(6, rrfe.getAttemptCount());
  } finally {
    ((SimpleStateMachine4Testing)leader.getStateMachine()).unblockWriteStateMachineData();
    cluster.shutdown();
  }
}
 
Example #5
Source File: SegmentedRaftLogWorker.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
void getFromFuture(CompletableFuture<?> future, Supplier<Object> getName) throws IOException {
  Preconditions.assertTrue(isSync());
  TimeoutIOException lastException = null;
  for(int retry = 0; syncTimeoutRetry == -1 || retry <= syncTimeoutRetry; retry++) {
    try {
      IOUtils.getFromFuture(future, getName, syncTimeout);
      return;
    } catch(TimeoutIOException e) {
      LOG.warn("Timeout " + retry + (syncTimeoutRetry == -1? "/~": "/" + syncTimeoutRetry), e);
      lastException = e;
    }
  }
  Objects.requireNonNull(lastException, "lastException == null");
  throw lastException;
}
 
Example #6
Source File: RaftLogWorker.java    From ratis with Apache License 2.0 5 votes vote down vote up
void getFromFuture(CompletableFuture<?> future, Supplier<Object> getName) throws IOException {
  Preconditions.assertTrue(isSync());
  TimeoutIOException lastException = null;
  for(int retry = 0; syncTimeoutRetry == -1 || retry <= syncTimeoutRetry; retry++) {
    try {
      IOUtils.getFromFuture(future, getName, syncTimeout);
      return;
    } catch(TimeoutIOException e) {
      LOG.warn("Timeout " + retry + (syncTimeoutRetry == -1? "/~": "/" + syncTimeoutRetry), e);
      lastException = e;
    }
  }
  Objects.requireNonNull(lastException, "lastException == null");
  throw lastException;
}
 
Example #7
Source File: GrpcClientProtocolClient.java    From incubator-ratis with Apache License 2.0 4 votes vote down vote up
private void timeoutCheck(long callId, TimeDuration timeOutDuration) {
  handleReplyFuture(callId, f -> f.completeExceptionally(
      new TimeoutIOException("Request #" + callId + " timeout " + timeOutDuration)));
}