hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From syuanji...@apache.org
Subject hbase git commit: HBASE-15371: Procedure V2 - Completed support parent-child procedure (Stephen Yuan Jiang)
Date Wed, 02 Mar 2016 03:45:34 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-1 12853268e -> d0c818630


HBASE-15371: Procedure V2 - Completed support parent-child procedure (Stephen Yuan Jiang)


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/d0c81863
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/d0c81863
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/d0c81863

Branch: refs/heads/branch-1
Commit: d0c818630b71072d81e5a997add2a8eba5a283d0
Parents: 1285326
Author: Stephen Yuan Jiang <syuanjiangdev@gmail.com>
Authored: Tue Mar 1 19:37:56 2016 -0800
Committer: Stephen Yuan Jiang <syuanjiangdev@gmail.com>
Committed: Tue Mar 1 19:38:38 2016 -0800

----------------------------------------------------------------------
 .../hbase/procedure2/StateMachineProcedure.java | 21 +++++++++++++++
 .../hbase/procedure2/TestProcedureRecovery.java | 28 +++++++++++++++++++-
 2 files changed, 48 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/d0c81863/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/StateMachineProcedure.java
----------------------------------------------------------------------
diff --git a/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/StateMachineProcedure.java
b/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/StateMachineProcedure.java
index 286a7bf..c2b4548 100644
--- a/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/StateMachineProcedure.java
+++ b/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/StateMachineProcedure.java
@@ -21,6 +21,7 @@ package org.apache.hadoop.hbase.procedure2;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.util.ArrayList;
 import java.util.Arrays;
 
 import org.apache.hadoop.hbase.classification.InterfaceAudience;
@@ -45,6 +46,8 @@ public abstract class StateMachineProcedure<TEnvironment, TState>
   private int stateCount = 0;
   private int[] states = null;
 
+  private ArrayList<Procedure> subProcList = null;
+
   protected enum Flow {
     HAS_MORE_STATE,
     NO_MORE_STATE,
@@ -107,6 +110,17 @@ public abstract class StateMachineProcedure<TEnvironment, TState>
     return false;
   }
 
+  /**
+   * Add a child procedure to execute
+   * @param subProcedure the child procedure
+   */
+  protected void addChildProcedure(Procedure subProcedure) {
+    if (subProcList == null) {
+      subProcList = new ArrayList<Procedure>();
+    }
+    subProcList.add(subProcedure);
+  }
+
   @Override
   protected Procedure[] execute(final TEnvironment env)
       throws ProcedureYieldException, InterruptedException {
@@ -120,6 +134,13 @@ public abstract class StateMachineProcedure<TEnvironment, TState>
         // completed
         return null;
       }
+
+      if (subProcList != null && subProcList.size() != 0) {
+        Procedure[] subProcedures = subProcList.toArray(new Procedure[subProcList.size()]);
+        subProcList = null;
+        return subProcedures;
+      }
+
       return (isWaiting() || isFailed()) ? null : new Procedure[] {this};
     } finally {
       updateTimestamp();

http://git-wip-us.apache.org/repos/asf/hbase/blob/d0c81863/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/TestProcedureRecovery.java
----------------------------------------------------------------------
diff --git a/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/TestProcedureRecovery.java
b/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/TestProcedureRecovery.java
index 9e01fcf..e0f2b87 100644
--- a/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/TestProcedureRecovery.java
+++ b/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/TestProcedureRecovery.java
@@ -336,8 +336,13 @@ public class TestProcedureRecovery {
 
     public TestStateMachineProcedure() {}
 
+    public TestStateMachineProcedure(final boolean testSubmitChildProc) {
+      this.submitChildProc = testSubmitChildProc;
+    }
+
     private AtomicBoolean aborted = new AtomicBoolean(false);
     private int iResult = 0;
+    private boolean submitChildProc = false;
 
     @Override
     protected StateMachineProcedure.Flow executeFromState(TestProcEnv env, State state) {
@@ -349,7 +354,13 @@ public class TestProcedureRecovery {
           break;
         case STATE_2:
           LOG.info("execute step 2 " + this);
-          setNextState(State.STATE_3);
+          if (submitChildProc) {
+            addChildProcedure(new TestStateMachineProcedure());
+            addChildProcedure(new TestStateMachineProcedure());
+            setNextState(State.DONE);
+          } else {
+            setNextState(State.STATE_3);
+          }
           iResult += 5;
           break;
         case STATE_3:
@@ -362,6 +373,8 @@ public class TestProcedureRecovery {
           }
           setNextState(State.DONE);
           iResult += 7;
+          break;
+        case DONE:
           setResult(Bytes.toBytes(iResult));
           return Flow.NO_MORE_STATE;
         default:
@@ -424,6 +437,14 @@ public class TestProcedureRecovery {
   }
 
   @Test(timeout=30000)
+  public void testStateMachineMultipleLevel() throws Exception {
+    long procId = procExecutor.submitProcedure(new TestStateMachineProcedure(true));
+    // Wait the completion
+    ProcedureTestingUtility.waitProcedure(procExecutor, procId);
+    ProcedureTestingUtility.assertProcNotFailed(procExecutor, procId);
+  }
+
+  @Test(timeout=30000)
   public void testStateMachineRecovery() throws Exception {
     ProcedureTestingUtility.setToggleKillBeforeStoreUpdate(procExecutor, true);
     ProcedureTestingUtility.setKillBeforeStoreUpdate(procExecutor, true);
@@ -448,6 +469,11 @@ public class TestProcedureRecovery {
     // Step 3 exec
     restart();
     waitProcedure(procId);
+    ProcedureTestingUtility.assertProcNotYetCompleted(procExecutor, procId);
+    assertFalse(procExecutor.isRunning());
+
+    restart();
+    waitProcedure(procId);
     assertTrue(procExecutor.isRunning());
 
     // The procedure is completed


Mime
View raw message