diff options
author | Nanda kumar <nanda@apache.org> | 2018-01-27 16:24:24 +0530 |
---|---|---|
committer | Owen O'Malley <omalley@apache.org> | 2018-04-26 05:36:04 -0700 |
commit | 7b3179f55172b39c50802caaa4da517d508d7670 (patch) | |
tree | 449e70f312d6f95e8d21049e96657369e088ebc9 /hadoop-hdfs-project/hadoop-hdfs/src/main | |
parent | 10e1e2c2f5964a3f5c3cfb18be0757b1e9e381ec (diff) |
HDFS-13072. Ozone: DatanodeStateMachine: Handling Uncaught Exception in command handler thread. Contributed by Nanda kumar.
Diffstat (limited to 'hadoop-hdfs-project/hadoop-hdfs/src/main')
-rw-r--r-- | hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/container/common/statemachine/DatanodeStateMachine.java | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/container/common/statemachine/DatanodeStateMachine.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/container/common/statemachine/DatanodeStateMachine.java index c264650162..de55d96d29 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/container/common/statemachine/DatanodeStateMachine.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/container/common/statemachine/DatanodeStateMachine.java @@ -356,17 +356,22 @@ public class DatanodeStateMachine implements Closeable { }; // We will have only one thread for command processing in a datanode. - cmdProcessThread = new Thread(processCommandQueue); - cmdProcessThread.setDaemon(true); - cmdProcessThread.setName("Command processor thread"); - cmdProcessThread.setUncaughtExceptionHandler((Thread t, Throwable e) -> { + cmdProcessThread = getCommandHandlerThread(processCommandQueue); + cmdProcessThread.start(); + } + + private Thread getCommandHandlerThread(Runnable processCommandQueue) { + Thread handlerThread = new Thread(processCommandQueue); + handlerThread.setDaemon(true); + handlerThread.setName("Command processor thread"); + handlerThread.setUncaughtExceptionHandler((Thread t, Throwable e) -> { // Let us just restart this thread after logging a critical error. // if this thread is not running we cannot handle commands from SCM. LOG.error("Critical Error : Command processor thread encountered an " + "error. Thread: {}", t.toString(), e); - cmdProcessThread.start(); + getCommandHandlerThread(processCommandQueue).start(); }); - cmdProcessThread.start(); + return handlerThread; } /** |