use of org.apache.ratis.server.raftlog.segmented.SegmentedRaftLog.Task in project incubator-ratis by apache.
the class SegmentedRaftLogWorker method run.
private void run() {
// if and when a log task encounters an exception
RaftLogIOException logIOException = null;
while (running) {
try {
Task task = queue.poll(ONE_SECOND);
if (task != null) {
task.stopTimerOnDequeue();
try {
if (logIOException != null) {
throw logIOException;
} else {
final Timer.Context executionTimeContext = raftLogMetrics.getRaftLogTaskExecutionTimer(JavaUtils.getClassSimpleName(task.getClass()).toLowerCase()).time();
task.execute();
executionTimeContext.stop();
}
} catch (IOException e) {
if (task.getEndIndex() < lastWrittenIndex) {
LOG.info("Ignore IOException when handling task " + task + " which is smaller than the lastWrittenIndex." + " There should be a snapshot installed.", e);
} else {
task.failed(e);
if (logIOException == null) {
logIOException = new RaftLogIOException("Log already failed" + " at index " + task.getEndIndex() + " for task " + task, e);
}
continue;
}
}
task.done();
}
flushIfNecessary();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
if (running) {
LOG.warn("{} got interrupted while still running", Thread.currentThread().getName());
}
LOG.info(Thread.currentThread().getName() + " was interrupted, exiting. There are " + queue.getNumElements() + " tasks remaining in the queue.");
return;
} catch (Exception e) {
if (!running) {
LOG.info("{} got closed and hit exception", Thread.currentThread().getName(), e);
} else {
LOG.error("{} hit exception", Thread.currentThread().getName(), e);
Optional.ofNullable(server).ifPresent(RaftServer.Division::close);
}
}
}
}
Aggregations