Repository: hbase
Updated Branches:
  refs/heads/branch-1 76a076026 -> 08e44919c
  refs/heads/master e782d0bbd -> e19632a19


HBASE-16639 TestProcedureInMemoryChore#testChoreAddAndRemove occasionally fails


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

Branch: refs/heads/master
Commit: 216e8473668c1a2f5cfb5c5bf05284d4274c8548
Parents: e782d0b
Author: Matteo Bertozzi <matteo.berto...@cloudera.com>
Authored: Thu Sep 15 18:25:11 2016 -0700
Committer: Matteo Bertozzi <matteo.berto...@cloudera.com>
Committed: Thu Sep 15 18:25:11 2016 -0700

----------------------------------------------------------------------
 .../apache/hadoop/hbase/procedure2/Procedure.java |  7 +++++++
 .../hbase/procedure2/ProcedureExecutor.java       | 18 +++++++++++-------
 .../procedure2/TestProcedureInMemoryChore.java    |  5 ++++-
 3 files changed, 22 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/216e8473/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/Procedure.java
----------------------------------------------------------------------
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 b401871..b9145e7 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
@@ -333,6 +333,13 @@ public abstract class Procedure<TEnvironment> implements 
Comparable<Procedure> {
   }
 
   /**
+   * @return true if the procedure is in a RUNNABLE state.
+   */
+  protected synchronized boolean isRunnable() {
+    return state == ProcedureState.RUNNABLE;
+  }
+
+  /**
    * @return true if the procedure has failed.
    *         true may mean failed but not yet rolledback or failed and 
rolledback.
    */

http://git-wip-us.apache.org/repos/asf/hbase/blob/216e8473/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/ProcedureExecutor.java
----------------------------------------------------------------------
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 1a9010d..5066fb4 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
@@ -609,15 +609,17 @@ public class ProcedureExecutor<TEnvironment> {
    * @param chore the chore to add
    */
   public void addChore(final ProcedureInMemoryChore chore) {
+    chore.setState(ProcedureState.RUNNABLE);
     waitingTimeout.add(chore);
   }
 
   /**
    * Remove a chore procedure from the executor
    * @param chore the chore to remove
-   * @return whether the chore is removed
+   * @return whether the chore is removed, or it will be removed later
    */
   public boolean removeChore(final ProcedureInMemoryChore chore) {
+    chore.setState(ProcedureState.FINISHED);
     return waitingTimeout.remove(chore);
   }
 
@@ -907,13 +909,15 @@ public class ProcedureExecutor<TEnvironment> {
       // instead of bringing the Chore class in, we reuse this timeout thread 
for
       // this special case.
       if (proc instanceof ProcedureInMemoryChore) {
-        try {
-          ((ProcedureInMemoryChore)proc).periodicExecute(getEnvironment());
-        } catch (Throwable e) {
-          LOG.error("Ignoring CompletedProcedureCleaner exception: " + 
e.getMessage(), e);
+        if (proc.isRunnable()) {
+          try {
+            ((ProcedureInMemoryChore)proc).periodicExecute(getEnvironment());
+          } catch (Throwable e) {
+            LOG.error("Ignoring CompletedProcedureCleaner exception: " + 
e.getMessage(), e);
+          }
+          proc.setStartTime(EnvironmentEdgeManager.currentTime());
+          if (proc.isRunnable()) waitingTimeout.add(proc);
         }
-        proc.setStartTime(EnvironmentEdgeManager.currentTime());
-        waitingTimeout.add(proc);
         continue;
       }
 

http://git-wip-us.apache.org/repos/asf/hbase/blob/216e8473/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/TestProcedureInMemoryChore.java
----------------------------------------------------------------------
diff --git 
a/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/TestProcedureInMemoryChore.java
 
b/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/TestProcedureInMemoryChore.java
index 32e3e8c..8bc8fa8 100644
--- 
a/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/TestProcedureInMemoryChore.java
+++ 
b/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/TestProcedureInMemoryChore.java
@@ -76,15 +76,18 @@ public class TestProcedureInMemoryChore {
     CountDownLatch latch = new CountDownLatch(nCountDown);
     TestLatchChore chore = new TestLatchChore(timeoutMSec, latch);
     procExecutor.addChore(chore);
+    assertTrue(chore.isRunnable());
     latch.await();
 
     // remove the chore and verify it is no longer executed
+    assertTrue(chore.isRunnable());
     procExecutor.removeChore(chore);
     latch = new CountDownLatch(nCountDown);
     chore.setLatch(latch);
     latch.await(timeoutMSec * nCountDown, TimeUnit.MILLISECONDS);
     LOG.info("chore latch count=" + latch.getCount());
-    assertTrue(latch.getCount() > 0);
+    assertFalse(chore.isRunnable());
+    assertTrue("latchCount=" + latch.getCount(), latch.getCount() > 0);
   }
 
   public static class TestLatchChore extends 
ProcedureInMemoryChore<TestProcEnv> {

Reply via email to