You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ratis.apache.org by sz...@apache.org on 2020/11/03 08:15:47 UTC
[incubator-ratis] branch master updated: RATIS-1119. StateMachine
is not closed when StateMachineUpdater encounters exception. (#242)
This is an automated email from the ASF dual-hosted git repository.
szetszwo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ratis.git
The following commit(s) were added to refs/heads/master by this push:
new 536d640 RATIS-1119. StateMachine is not closed when StateMachineUpdater encounters exception. (#242)
536d640 is described below
commit 536d6400fb4f0064bbaf43257f7fec04f538df34
Author: Tsz-Wo Nicholas Sze <sz...@apache.org>
AuthorDate: Tue Nov 3 16:15:40 2020 +0800
RATIS-1119. StateMachine is not closed when StateMachineUpdater encounters exception. (#242)
---
.../ratis/server/impl/StateMachineUpdater.java | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/ratis-server/src/main/java/org/apache/ratis/server/impl/StateMachineUpdater.java b/ratis-server/src/main/java/org/apache/ratis/server/impl/StateMachineUpdater.java
index 9b0abec..6c0e218 100644
--- a/ratis-server/src/main/java/org/apache/ratis/server/impl/StateMachineUpdater.java
+++ b/ratis-server/src/main/java/org/apache/ratis/server/impl/StateMachineUpdater.java
@@ -59,7 +59,7 @@ class StateMachineUpdater implements Runnable {
static final Logger LOG = LoggerFactory.getLogger(StateMachineUpdater.class);
enum State {
- RUNNING, STOP, RELOAD
+ RUNNING, STOP, RELOAD, EXCEPTION
}
private final Consumer<Object> infoIndexChange;
@@ -137,6 +137,10 @@ class StateMachineUpdater implements Runnable {
* have been applied to the state machine.
*/
void stopAndJoin() throws InterruptedException {
+ if (state == State.EXCEPTION) {
+ stop();
+ return;
+ }
if (stopIndex.compareAndSet(null, raftLog.getLastCommittedIndex())) {
notifyUpdater();
LOG.info("{}: set stopIndex = {}", this, stopIndex);
@@ -175,18 +179,14 @@ class StateMachineUpdater implements Runnable {
checkAndTakeSnapshot(futures);
stop();
}
- } catch (InterruptedException e) {
- if (state == State.STOP) {
- LOG.info("{}: the StateMachineUpdater is interrupted and will exit.", this);
+ } catch (Throwable t) {
+ if (t instanceof InterruptedException && state == State.STOP) {
+ LOG.info("{} was interrupted. Exiting ...", this);
} else {
- final String s = this + ": the StateMachineUpdater is wrongly interrupted";
- LOG.error(s, e);
+ state = State.EXCEPTION;
+ LOG.error(this + " caught a Throwable.", t);
server.shutdown();
}
- } catch (Throwable t) {
- final String s = this + ": the StateMachineUpdater hits Throwable";
- LOG.error(s, t);
- server.shutdown();
}
}
}