HDFS-13072. Ozone: DatanodeStateMachine: Handling Uncaught Exception in command handler thread. Contributed by Nanda kumar.

This commit is contained in:
Nanda kumar 2018-01-27 16:24:24 +05:30 committed by Owen O'Malley
parent 10e1e2c2f5
commit 7b3179f551

View File

@ -356,17 +356,22 @@ public class DatanodeStateMachine implements Closeable {
}; };
// We will have only one thread for command processing in a datanode. // We will have only one thread for command processing in a datanode.
cmdProcessThread = new Thread(processCommandQueue); cmdProcessThread = getCommandHandlerThread(processCommandQueue);
cmdProcessThread.setDaemon(true); cmdProcessThread.start();
cmdProcessThread.setName("Command processor thread"); }
cmdProcessThread.setUncaughtExceptionHandler((Thread t, Throwable e) -> {
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. // Let us just restart this thread after logging a critical error.
// if this thread is not running we cannot handle commands from SCM. // if this thread is not running we cannot handle commands from SCM.
LOG.error("Critical Error : Command processor thread encountered an " + LOG.error("Critical Error : Command processor thread encountered an " +
"error. Thread: {}", t.toString(), e); "error. Thread: {}", t.toString(), e);
cmdProcessThread.start(); getCommandHandlerThread(processCommandQueue).start();
}); });
cmdProcessThread.start(); return handlerThread;
} }
/** /**