From e7bd29e2c0cb7b0b06e5da6b5e002b0f5c5f309e Mon Sep 17 00:00:00 2001 From: Umesh Agashe Date: Fri, 31 Mar 2017 15:12:46 -0700 Subject: [PATCH] HBASE-17863: Some cleanup around Procedure.isFinished() and procedure executor Change-Id: I8c47d6973792234aed04d989343901c1d960f423 --- .../org/apache/hadoop/hbase/procedure2/Procedure.java | 16 ++++------------ .../hadoop/hbase/procedure2/ProcedureExecutor.java | 16 ++++++++-------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/Procedure.java b/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/Procedure.java index 2a7fa6e..c3d0135 100644 --- a/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/Procedure.java +++ b/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/Procedure.java @@ -216,9 +216,9 @@ public abstract class Procedure implements Comparable { } /** - * By default, the executor will try ro run procedures start to finish. + * By default, the executor will try to run procedures from start to finish. * Return true to make the executor yield between each execution step to - * give other procedures time to run their steps. + * give other procedures a chance to run. * @param env the environment passed to the ProcedureExecutor * @return Return true if the executor should yield on completion of an execution step. * Defaults to return false. @@ -532,19 +532,11 @@ public abstract class Procedure implements Comparable { } /** - * @return true if the procedure is finished. The Procedure may be completed + * @return true if the procedure is finished. The Procedure may be finished * successfuly or failed and rolledback. */ public synchronized boolean isFinished() { - switch (state) { - case ROLLEDBACK: - return true; - case FINISHED: - return exception == null; - default: - break; - } - return false; + return isFailed() || isSuccess(); } /** diff --git a/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/ProcedureExecutor.java b/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/ProcedureExecutor.java index e2f63c6..5707781 100644 --- a/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/ProcedureExecutor.java +++ b/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/ProcedureExecutor.java @@ -1317,7 +1317,7 @@ public class ProcedureExecutor { Preconditions.checkArgument(procedure.getState() == ProcedureState.RUNNABLE); // Execute the procedure - boolean isSuspended = false; + boolean suspended = false; boolean reExecute = false; Procedure[] subprocs = null; do { @@ -1328,7 +1328,7 @@ public class ProcedureExecutor { subprocs = null; } } catch (ProcedureSuspendedException e) { - isSuspended = true; + suspended = true; } catch (ProcedureYieldException e) { if (LOG.isTraceEnabled()) { LOG.trace("Yield " + procedure + ": " + e.getMessage()); @@ -1358,7 +1358,7 @@ public class ProcedureExecutor { } } else if (procedure.getState() == ProcedureState.WAITING_TIMEOUT) { timeoutExecutor.add(procedure); - } else if (!isSuspended) { + } else if (!suspended) { // No subtask, so we are done procedure.setState(ProcedureState.FINISHED); } @@ -1369,20 +1369,20 @@ public class ProcedureExecutor { // allows to kill the executor before something is stored to the wal. // useful to test the procedure recovery. - if (testing != null && testing.shouldKillBeforeStoreUpdate(isSuspended)) { + if (testing != null && testing.shouldKillBeforeStoreUpdate(suspended)) { LOG.debug("TESTING: Kill before store update: " + procedure); stop(); return; } - // Commit the transaction - updateStoreOnExec(procStack, procedure, subprocs); - // if the store is not running we are aborting if (!store.isRunning()) return; + // Commit the transaction + updateStoreOnExec(procStack, procedure, subprocs); + // if the procedure is kind enough to pass the slot to someone else, yield - if (procedure.isRunnable() && !isSuspended && + if (procedure.isRunnable() && !suspended && procedure.isYieldAfterExecutionStep(getEnvironment())) { scheduler.yield(procedure); return; -- 2.10.1 (Apple Git-78)