Search in sources :

Example 6 with NotLeaderException

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

the class LeaderStateImpl method stop.

void stop() {
    this.running = false;
    // do not interrupt event processor since it may be in the middle of logSync
    senders.forEach(LogAppender::stop);
    final NotLeaderException nle = server.generateNotLeaderException();
    final Collection<CommitInfoProto> commitInfos = server.getCommitInfos();
    try {
        final Collection<TransactionContext> transactions = pendingRequests.sendNotLeaderResponses(nle, commitInfos);
        server.getStateMachine().leaderEvent().notifyNotLeader(transactions);
        watchRequests.failWatches(nle);
    } catch (IOException e) {
        LOG.warn("{}: Caught exception in sendNotLeaderResponses", this, e);
    }
    messageStreamRequests.clear();
    server.getServerRpc().notifyNotLeader(server.getMemberId().getGroupId());
    logAppenderMetrics.unregister();
    raftServerMetrics.unregister();
    pendingRequests.close();
}
Also used : NotLeaderException(org.apache.ratis.protocol.exceptions.NotLeaderException) CommitInfoProto(org.apache.ratis.proto.RaftProtos.CommitInfoProto) LogAppender(org.apache.ratis.server.leader.LogAppender) TransactionContext(org.apache.ratis.statemachine.TransactionContext) IOException(java.io.IOException)

Example 7 with NotLeaderException

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

the class RaftExceptionBaseTest method assertNotLeaderException.

RaftClientReply assertNotLeaderException(RaftPeerId expectedSuggestedLeader, String messageId, RaftPeerId server, RaftClientRpc rpc, CLUSTER cluster) throws IOException {
    final SimpleMessage message = new SimpleMessage(messageId);
    final RaftClientReply reply = rpc.sendRequest(cluster.newRaftClientRequest(ClientId.randomId(), server, message));
    Assert.assertNotNull(reply);
    Assume.assumeFalse(reply.isSuccess());
    final NotLeaderException nle = reply.getNotLeaderException();
    Objects.requireNonNull(nle);
    Assert.assertEquals(expectedSuggestedLeader, nle.getSuggestedLeader().getId());
    return reply;
}
Also used : NotLeaderException(org.apache.ratis.protocol.exceptions.NotLeaderException) SimpleMessage(org.apache.ratis.RaftTestUtil.SimpleMessage)

Example 8 with NotLeaderException

use of org.apache.ratis.protocol.exceptions.NotLeaderException in project alluxio by Alluxio.

the class MasterJournalContext method waitForJournalFlush.

/**
 * Waits for the flush counter to be flushed to the journal. If the counter is
 * {@link #INVALID_FLUSH_COUNTER}, this is a noop.
 */
private void waitForJournalFlush() throws UnavailableException {
    if (mFlushCounter == INVALID_FLUSH_COUNTER) {
        // Check this before the precondition.
        return;
    }
    RetryPolicy retry = new TimeoutRetry(FLUSH_RETRY_TIMEOUT_MS, FLUSH_RETRY_INTERVAL_MS);
    while (retry.attempt()) {
        try {
            mAsyncJournalWriter.flush(mFlushCounter);
            return;
        } catch (NotLeaderException | JournalClosedException e) {
            throw new UnavailableException(String.format("Failed to complete request: %s", e.getMessage()), e);
        } catch (AlluxioStatusException e) {
            // written already
            if (e.getStatus().equals(Status.CANCELLED)) {
                LOG.warn("Journal flush interrupted because the RPC was cancelled. ", e);
            } else {
                LOG.warn("Journal flush failed. retrying...", e);
            }
        } catch (IOException e) {
            if (e instanceof AlluxioStatusException && ((AlluxioStatusException) e).getStatusCode() == Status.Code.CANCELLED) {
                throw new UnavailableException(String.format("Failed to complete request: %s", e.getMessage()), e);
            }
            LOG.warn("Journal flush failed. retrying...", e);
        } catch (Throwable e) {
            ProcessUtils.fatalError(LOG, e, "Journal flush failed");
        }
    }
    ProcessUtils.fatalError(LOG, "Journal flush failed after %d attempts", retry.getAttemptCount());
}
Also used : NotLeaderException(org.apache.ratis.protocol.exceptions.NotLeaderException) JournalClosedException(alluxio.exception.JournalClosedException) UnavailableException(alluxio.exception.status.UnavailableException) AlluxioStatusException(alluxio.exception.status.AlluxioStatusException) TimeoutRetry(alluxio.retry.TimeoutRetry) IOException(java.io.IOException) RetryPolicy(alluxio.retry.RetryPolicy)

Aggregations

NotLeaderException (org.apache.ratis.protocol.exceptions.NotLeaderException)8 IOException (java.io.IOException)4 GroupMismatchException (org.apache.ratis.protocol.exceptions.GroupMismatchException)3 LeaderNotReadyException (org.apache.ratis.protocol.exceptions.LeaderNotReadyException)3 RaftException (org.apache.ratis.protocol.exceptions.RaftException)3 CompletionException (java.util.concurrent.CompletionException)2 ClientRetryEvent (org.apache.ratis.client.retry.ClientRetryEvent)2 RaftClientReply (org.apache.ratis.protocol.RaftClientReply)2 RaftClientRequest (org.apache.ratis.protocol.RaftClientRequest)2 LeaderSteppingDownException (org.apache.ratis.protocol.exceptions.LeaderSteppingDownException)2 NotReplicatedException (org.apache.ratis.protocol.exceptions.NotReplicatedException)2 RetryPolicy (org.apache.ratis.retry.RetryPolicy)2 TimeDuration (org.apache.ratis.util.TimeDuration)2 JournalClosedException (alluxio.exception.JournalClosedException)1 AlluxioStatusException (alluxio.exception.status.AlluxioStatusException)1 UnavailableException (alluxio.exception.status.UnavailableException)1 RetryPolicy (alluxio.retry.RetryPolicy)1 TimeoutRetry (alluxio.retry.TimeoutRetry)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1