HBASE-16639 TestProcedureInMemoryChore#testChoreAddAndRemove occasionally fails

This commit is contained in:
Matteo Bertozzi 2016-09-15 18:25:11 -07:00
parent 76a0760269
commit 08e44919cc
3 changed files with 22 additions and 8 deletions

View File

@ -325,6 +325,13 @@ public abstract class Procedure<TEnvironment> implements Comparable<Procedure> {
return nonceKey;
}
/**
* @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.

View File

@ -595,15 +595,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);
}
@ -901,13 +903,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;
}

View File

@ -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> {