HBASE-23615 Use a dedicated thread for executing WorkerMonitor in Pro… (#961)

Signed-off-by: stack <stack@apache.org>
Signed-off-by: Duo Zhang <zhangduo@apache.org>
Signed-off-by: virajjasani <34790606+virajjasani@users.noreply.github.com>
This commit is contained in:
binlijin 2019-12-31 10:03:01 +08:00 committed by GitHub
parent 923ba7763e
commit 06eff551c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 5 deletions

View File

@ -217,6 +217,15 @@ public class ProcedureExecutor<TEnvironment> {
*/ */
private TimeoutExecutorThread<TEnvironment> timeoutExecutor; private TimeoutExecutorThread<TEnvironment> timeoutExecutor;
/**
* WorkerMonitor check for stuck workers and new worker thread when necessary, for example if
* there is no worker to assign meta, it will new worker thread for it, so it is very important.
* TimeoutExecutor execute many tasks like DeadServerMetricRegionChore RegionInTransitionChore
* and so on, some tasks may execute for a long time so will block other tasks like
* WorkerMonitor, so use a dedicated thread for executing WorkerMonitor.
*/
private TimeoutExecutorThread<TEnvironment> workerMonitorExecutor;
private int corePoolSize; private int corePoolSize;
private int maxPoolSize; private int maxPoolSize;
@ -560,7 +569,8 @@ public class ProcedureExecutor<TEnvironment> {
corePoolSize, maxPoolSize); corePoolSize, maxPoolSize);
this.threadGroup = new ThreadGroup("PEWorkerGroup"); this.threadGroup = new ThreadGroup("PEWorkerGroup");
this.timeoutExecutor = new TimeoutExecutorThread<>(this, threadGroup); this.timeoutExecutor = new TimeoutExecutorThread<>(this, threadGroup, "ProcExecTimeout");
this.workerMonitorExecutor = new TimeoutExecutorThread<>(this, threadGroup, "WorkerMonitor");
// Create the workers // Create the workers
workerId.set(0); workerId.set(0);
@ -604,12 +614,13 @@ public class ProcedureExecutor<TEnvironment> {
// Start the executors. Here we must have the lastProcId set. // Start the executors. Here we must have the lastProcId set.
LOG.trace("Start workers {}", workerThreads.size()); LOG.trace("Start workers {}", workerThreads.size());
timeoutExecutor.start(); timeoutExecutor.start();
workerMonitorExecutor.start();
for (WorkerThread worker: workerThreads) { for (WorkerThread worker: workerThreads) {
worker.start(); worker.start();
} }
// Internal chores // Internal chores
timeoutExecutor.add(new WorkerMonitor()); workerMonitorExecutor.add(new WorkerMonitor());
// Add completed cleaner chore // Add completed cleaner chore
addChore(new CompletedProcedureCleaner<>(conf, store, procExecutionLock, completed, addChore(new CompletedProcedureCleaner<>(conf, store, procExecutionLock, completed,
@ -624,6 +635,7 @@ public class ProcedureExecutor<TEnvironment> {
LOG.info("Stopping"); LOG.info("Stopping");
scheduler.stop(); scheduler.stop();
timeoutExecutor.sendStopSignal(); timeoutExecutor.sendStopSignal();
workerMonitorExecutor.sendStopSignal();
} }
@VisibleForTesting @VisibleForTesting
@ -632,6 +644,8 @@ public class ProcedureExecutor<TEnvironment> {
// stop the timeout executor // stop the timeout executor
timeoutExecutor.awaitTermination(); timeoutExecutor.awaitTermination();
// stop the work monitor executor
workerMonitorExecutor.awaitTermination();
// stop the worker threads // stop the worker threads
for (WorkerThread worker: workerThreads) { for (WorkerThread worker: workerThreads) {

View File

@ -37,8 +37,9 @@ class TimeoutExecutorThread<TEnvironment> extends StoppableThread {
private final DelayQueue<DelayedWithTimeout> queue = new DelayQueue<>(); private final DelayQueue<DelayedWithTimeout> queue = new DelayQueue<>();
public TimeoutExecutorThread(ProcedureExecutor<TEnvironment> executor, ThreadGroup group) { public TimeoutExecutorThread(ProcedureExecutor<TEnvironment> executor, ThreadGroup group,
super(group, "ProcExecTimeout"); String name) {
super(group, name);
setDaemon(true); setDaemon(true);
this.executor = executor; this.executor = executor;
} }

View File

@ -57,7 +57,6 @@ public class TestProcedureAdmin {
protected static final HBaseTestingUtility UTIL = new HBaseTestingUtility(); protected static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
private static void setupConf(Configuration conf) { private static void setupConf(Configuration conf) {
conf.setInt(MasterProcedureConstants.MASTER_PROCEDURE_THREADS, 1); conf.setInt(MasterProcedureConstants.MASTER_PROCEDURE_THREADS, 1);
} }