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