hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From git-site-r...@apache.org
Subject [14/18] hbase-site git commit: Published site at 59e8b8e2ba4d403d042fe4cc02f8f9f80aad67af.
Date Sat, 08 Apr 2017 00:05:54 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/799947ba/devapidocs/src-html/org/apache/hadoop/hbase/procedure2/ProcedureExecutor.InlineChore.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/procedure2/ProcedureExecutor.InlineChore.html b/devapidocs/src-html/org/apache/hadoop/hbase/procedure2/ProcedureExecutor.InlineChore.html
index b6b4cb6..a1495ff 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/procedure2/ProcedureExecutor.InlineChore.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/procedure2/ProcedureExecutor.InlineChore.html
@@ -1381,472 +1381,477 @@
 <span class="sourceLineNo">1373</span>        return;<a name="line.1373"></a>
 <span class="sourceLineNo">1374</span>      }<a name="line.1374"></a>
 <span class="sourceLineNo">1375</span><a name="line.1375"></a>
-<span class="sourceLineNo">1376</span>      // if the store is not running we are aborting<a name="line.1376"></a>
-<span class="sourceLineNo">1377</span>      if (!store.isRunning()) return;<a name="line.1377"></a>
-<span class="sourceLineNo">1378</span><a name="line.1378"></a>
-<span class="sourceLineNo">1379</span>      // Commit the transaction<a name="line.1379"></a>
-<span class="sourceLineNo">1380</span>      updateStoreOnExec(procStack, procedure, subprocs);<a name="line.1380"></a>
-<span class="sourceLineNo">1381</span><a name="line.1381"></a>
-<span class="sourceLineNo">1382</span>      // if the procedure is kind enough to pass the slot to someone else, yield<a name="line.1382"></a>
-<span class="sourceLineNo">1383</span>      if (procedure.isRunnable() &amp;&amp; !suspended &amp;&amp;<a name="line.1383"></a>
-<span class="sourceLineNo">1384</span>          procedure.isYieldAfterExecutionStep(getEnvironment())) {<a name="line.1384"></a>
-<span class="sourceLineNo">1385</span>        scheduler.yield(procedure);<a name="line.1385"></a>
-<span class="sourceLineNo">1386</span>        return;<a name="line.1386"></a>
-<span class="sourceLineNo">1387</span>      }<a name="line.1387"></a>
-<span class="sourceLineNo">1388</span><a name="line.1388"></a>
-<span class="sourceLineNo">1389</span>      assert (reExecute &amp;&amp; subprocs == null) || !reExecute;<a name="line.1389"></a>
-<span class="sourceLineNo">1390</span>    } while (reExecute);<a name="line.1390"></a>
-<span class="sourceLineNo">1391</span><a name="line.1391"></a>
-<span class="sourceLineNo">1392</span>    // Submit the new subprocedures<a name="line.1392"></a>
-<span class="sourceLineNo">1393</span>    if (subprocs != null &amp;&amp; !procedure.isFailed()) {<a name="line.1393"></a>
-<span class="sourceLineNo">1394</span>      submitChildrenProcedures(subprocs);<a name="line.1394"></a>
-<span class="sourceLineNo">1395</span>    }<a name="line.1395"></a>
+<span class="sourceLineNo">1376</span>      // TODO: The code here doesn't check if store is running before persisting to the store as<a name="line.1376"></a>
+<span class="sourceLineNo">1377</span>      // it relies on the method call below to throw RuntimeException to wind up the stack and<a name="line.1377"></a>
+<span class="sourceLineNo">1378</span>      // executor thread to stop. The statement following the method call below seems to check if<a name="line.1378"></a>
+<span class="sourceLineNo">1379</span>      // store is not running, to prevent scheduling children procedures, re-execution or yield<a name="line.1379"></a>
+<span class="sourceLineNo">1380</span>      // of this procedure. This may need more scrutiny and subsequent cleanup in future<a name="line.1380"></a>
+<span class="sourceLineNo">1381</span>      // Commit the transaction<a name="line.1381"></a>
+<span class="sourceLineNo">1382</span>      updateStoreOnExec(procStack, procedure, subprocs);<a name="line.1382"></a>
+<span class="sourceLineNo">1383</span><a name="line.1383"></a>
+<span class="sourceLineNo">1384</span>      // if the store is not running we are aborting<a name="line.1384"></a>
+<span class="sourceLineNo">1385</span>      if (!store.isRunning()) return;<a name="line.1385"></a>
+<span class="sourceLineNo">1386</span><a name="line.1386"></a>
+<span class="sourceLineNo">1387</span>      // if the procedure is kind enough to pass the slot to someone else, yield<a name="line.1387"></a>
+<span class="sourceLineNo">1388</span>      if (procedure.isRunnable() &amp;&amp; !suspended &amp;&amp;<a name="line.1388"></a>
+<span class="sourceLineNo">1389</span>          procedure.isYieldAfterExecutionStep(getEnvironment())) {<a name="line.1389"></a>
+<span class="sourceLineNo">1390</span>        scheduler.yield(procedure);<a name="line.1390"></a>
+<span class="sourceLineNo">1391</span>        return;<a name="line.1391"></a>
+<span class="sourceLineNo">1392</span>      }<a name="line.1392"></a>
+<span class="sourceLineNo">1393</span><a name="line.1393"></a>
+<span class="sourceLineNo">1394</span>      assert (reExecute &amp;&amp; subprocs == null) || !reExecute;<a name="line.1394"></a>
+<span class="sourceLineNo">1395</span>    } while (reExecute);<a name="line.1395"></a>
 <span class="sourceLineNo">1396</span><a name="line.1396"></a>
-<span class="sourceLineNo">1397</span>    // if the procedure is complete and has a parent, count down the children latch<a name="line.1397"></a>
-<span class="sourceLineNo">1398</span>    if (procedure.isFinished() &amp;&amp; procedure.hasParent()) {<a name="line.1398"></a>
-<span class="sourceLineNo">1399</span>      countDownChildren(procStack, procedure);<a name="line.1399"></a>
+<span class="sourceLineNo">1397</span>    // Submit the new subprocedures<a name="line.1397"></a>
+<span class="sourceLineNo">1398</span>    if (subprocs != null &amp;&amp; !procedure.isFailed()) {<a name="line.1398"></a>
+<span class="sourceLineNo">1399</span>      submitChildrenProcedures(subprocs);<a name="line.1399"></a>
 <span class="sourceLineNo">1400</span>    }<a name="line.1400"></a>
-<span class="sourceLineNo">1401</span>  }<a name="line.1401"></a>
-<span class="sourceLineNo">1402</span><a name="line.1402"></a>
-<span class="sourceLineNo">1403</span>  private Procedure[] initializeChildren(final RootProcedureState procStack,<a name="line.1403"></a>
-<span class="sourceLineNo">1404</span>      final Procedure procedure, final Procedure[] subprocs) {<a name="line.1404"></a>
-<span class="sourceLineNo">1405</span>    assert subprocs != null : "expected subprocedures";<a name="line.1405"></a>
-<span class="sourceLineNo">1406</span>    final long rootProcId = getRootProcedureId(procedure);<a name="line.1406"></a>
-<span class="sourceLineNo">1407</span>    for (int i = 0; i &lt; subprocs.length; ++i) {<a name="line.1407"></a>
-<span class="sourceLineNo">1408</span>      final Procedure subproc = subprocs[i];<a name="line.1408"></a>
-<span class="sourceLineNo">1409</span>      if (subproc == null) {<a name="line.1409"></a>
-<span class="sourceLineNo">1410</span>        String msg = "subproc[" + i + "] is null, aborting the procedure";<a name="line.1410"></a>
-<span class="sourceLineNo">1411</span>        procedure.setFailure(new RemoteProcedureException(msg,<a name="line.1411"></a>
-<span class="sourceLineNo">1412</span>          new IllegalArgumentIOException(msg)));<a name="line.1412"></a>
-<span class="sourceLineNo">1413</span>        return null;<a name="line.1413"></a>
-<span class="sourceLineNo">1414</span>      }<a name="line.1414"></a>
-<span class="sourceLineNo">1415</span><a name="line.1415"></a>
-<span class="sourceLineNo">1416</span>      assert subproc.getState() == ProcedureState.INITIALIZING : subproc;<a name="line.1416"></a>
-<span class="sourceLineNo">1417</span>      subproc.setParentProcId(procedure.getProcId());<a name="line.1417"></a>
-<span class="sourceLineNo">1418</span>      subproc.setRootProcId(rootProcId);<a name="line.1418"></a>
-<span class="sourceLineNo">1419</span>      subproc.setProcId(nextProcId());<a name="line.1419"></a>
-<span class="sourceLineNo">1420</span>      procStack.addSubProcedure(subproc);<a name="line.1420"></a>
-<span class="sourceLineNo">1421</span>    }<a name="line.1421"></a>
-<span class="sourceLineNo">1422</span><a name="line.1422"></a>
-<span class="sourceLineNo">1423</span>    if (!procedure.isFailed()) {<a name="line.1423"></a>
-<span class="sourceLineNo">1424</span>      procedure.setChildrenLatch(subprocs.length);<a name="line.1424"></a>
-<span class="sourceLineNo">1425</span>      switch (procedure.getState()) {<a name="line.1425"></a>
-<span class="sourceLineNo">1426</span>        case RUNNABLE:<a name="line.1426"></a>
-<span class="sourceLineNo">1427</span>          procedure.setState(ProcedureState.WAITING);<a name="line.1427"></a>
-<span class="sourceLineNo">1428</span>          break;<a name="line.1428"></a>
-<span class="sourceLineNo">1429</span>        case WAITING_TIMEOUT:<a name="line.1429"></a>
-<span class="sourceLineNo">1430</span>          timeoutExecutor.add(procedure);<a name="line.1430"></a>
-<span class="sourceLineNo">1431</span>          break;<a name="line.1431"></a>
-<span class="sourceLineNo">1432</span>        default:<a name="line.1432"></a>
+<span class="sourceLineNo">1401</span><a name="line.1401"></a>
+<span class="sourceLineNo">1402</span>    // if the procedure is complete and has a parent, count down the children latch<a name="line.1402"></a>
+<span class="sourceLineNo">1403</span>    if (procedure.isFinished() &amp;&amp; procedure.hasParent()) {<a name="line.1403"></a>
+<span class="sourceLineNo">1404</span>      countDownChildren(procStack, procedure);<a name="line.1404"></a>
+<span class="sourceLineNo">1405</span>    }<a name="line.1405"></a>
+<span class="sourceLineNo">1406</span>  }<a name="line.1406"></a>
+<span class="sourceLineNo">1407</span><a name="line.1407"></a>
+<span class="sourceLineNo">1408</span>  private Procedure[] initializeChildren(final RootProcedureState procStack,<a name="line.1408"></a>
+<span class="sourceLineNo">1409</span>      final Procedure procedure, final Procedure[] subprocs) {<a name="line.1409"></a>
+<span class="sourceLineNo">1410</span>    assert subprocs != null : "expected subprocedures";<a name="line.1410"></a>
+<span class="sourceLineNo">1411</span>    final long rootProcId = getRootProcedureId(procedure);<a name="line.1411"></a>
+<span class="sourceLineNo">1412</span>    for (int i = 0; i &lt; subprocs.length; ++i) {<a name="line.1412"></a>
+<span class="sourceLineNo">1413</span>      final Procedure subproc = subprocs[i];<a name="line.1413"></a>
+<span class="sourceLineNo">1414</span>      if (subproc == null) {<a name="line.1414"></a>
+<span class="sourceLineNo">1415</span>        String msg = "subproc[" + i + "] is null, aborting the procedure";<a name="line.1415"></a>
+<span class="sourceLineNo">1416</span>        procedure.setFailure(new RemoteProcedureException(msg,<a name="line.1416"></a>
+<span class="sourceLineNo">1417</span>          new IllegalArgumentIOException(msg)));<a name="line.1417"></a>
+<span class="sourceLineNo">1418</span>        return null;<a name="line.1418"></a>
+<span class="sourceLineNo">1419</span>      }<a name="line.1419"></a>
+<span class="sourceLineNo">1420</span><a name="line.1420"></a>
+<span class="sourceLineNo">1421</span>      assert subproc.getState() == ProcedureState.INITIALIZING : subproc;<a name="line.1421"></a>
+<span class="sourceLineNo">1422</span>      subproc.setParentProcId(procedure.getProcId());<a name="line.1422"></a>
+<span class="sourceLineNo">1423</span>      subproc.setRootProcId(rootProcId);<a name="line.1423"></a>
+<span class="sourceLineNo">1424</span>      subproc.setProcId(nextProcId());<a name="line.1424"></a>
+<span class="sourceLineNo">1425</span>      procStack.addSubProcedure(subproc);<a name="line.1425"></a>
+<span class="sourceLineNo">1426</span>    }<a name="line.1426"></a>
+<span class="sourceLineNo">1427</span><a name="line.1427"></a>
+<span class="sourceLineNo">1428</span>    if (!procedure.isFailed()) {<a name="line.1428"></a>
+<span class="sourceLineNo">1429</span>      procedure.setChildrenLatch(subprocs.length);<a name="line.1429"></a>
+<span class="sourceLineNo">1430</span>      switch (procedure.getState()) {<a name="line.1430"></a>
+<span class="sourceLineNo">1431</span>        case RUNNABLE:<a name="line.1431"></a>
+<span class="sourceLineNo">1432</span>          procedure.setState(ProcedureState.WAITING);<a name="line.1432"></a>
 <span class="sourceLineNo">1433</span>          break;<a name="line.1433"></a>
-<span class="sourceLineNo">1434</span>      }<a name="line.1434"></a>
-<span class="sourceLineNo">1435</span>    }<a name="line.1435"></a>
-<span class="sourceLineNo">1436</span>    return subprocs;<a name="line.1436"></a>
-<span class="sourceLineNo">1437</span>  }<a name="line.1437"></a>
-<span class="sourceLineNo">1438</span><a name="line.1438"></a>
-<span class="sourceLineNo">1439</span>  private void submitChildrenProcedures(final Procedure[] subprocs) {<a name="line.1439"></a>
-<span class="sourceLineNo">1440</span>    for (int i = 0; i &lt; subprocs.length; ++i) {<a name="line.1440"></a>
-<span class="sourceLineNo">1441</span>      final Procedure subproc = subprocs[i];<a name="line.1441"></a>
-<span class="sourceLineNo">1442</span>      assert !procedures.containsKey(subproc.getProcId());<a name="line.1442"></a>
-<span class="sourceLineNo">1443</span>      procedures.put(subproc.getProcId(), subproc);<a name="line.1443"></a>
-<span class="sourceLineNo">1444</span>      scheduler.addFront(subproc);<a name="line.1444"></a>
-<span class="sourceLineNo">1445</span>    }<a name="line.1445"></a>
-<span class="sourceLineNo">1446</span>  }<a name="line.1446"></a>
-<span class="sourceLineNo">1447</span><a name="line.1447"></a>
-<span class="sourceLineNo">1448</span>  private void countDownChildren(final RootProcedureState procStack, final Procedure procedure) {<a name="line.1448"></a>
-<span class="sourceLineNo">1449</span>    final Procedure parent = procedures.get(procedure.getParentProcId());<a name="line.1449"></a>
-<span class="sourceLineNo">1450</span>    if (parent == null) {<a name="line.1450"></a>
-<span class="sourceLineNo">1451</span>      assert procStack.isRollingback();<a name="line.1451"></a>
-<span class="sourceLineNo">1452</span>      return;<a name="line.1452"></a>
-<span class="sourceLineNo">1453</span>    }<a name="line.1453"></a>
-<span class="sourceLineNo">1454</span><a name="line.1454"></a>
-<span class="sourceLineNo">1455</span>    // If this procedure is the last child awake the parent procedure<a name="line.1455"></a>
-<span class="sourceLineNo">1456</span>    final boolean traceEnabled = LOG.isTraceEnabled();<a name="line.1456"></a>
-<span class="sourceLineNo">1457</span>    if (traceEnabled) {<a name="line.1457"></a>
-<span class="sourceLineNo">1458</span>      LOG.trace(parent + " child is done: " + procedure);<a name="line.1458"></a>
-<span class="sourceLineNo">1459</span>    }<a name="line.1459"></a>
-<span class="sourceLineNo">1460</span><a name="line.1460"></a>
-<span class="sourceLineNo">1461</span>    if (parent.childrenCountDown() &amp;&amp; parent.getState() == ProcedureState.WAITING) {<a name="line.1461"></a>
-<span class="sourceLineNo">1462</span>      parent.setState(ProcedureState.RUNNABLE);<a name="line.1462"></a>
-<span class="sourceLineNo">1463</span>      store.update(parent);<a name="line.1463"></a>
-<span class="sourceLineNo">1464</span>      scheduler.addFront(parent);<a name="line.1464"></a>
-<span class="sourceLineNo">1465</span>      if (traceEnabled) {<a name="line.1465"></a>
-<span class="sourceLineNo">1466</span>        LOG.trace(parent + " all the children finished their work, resume.");<a name="line.1466"></a>
-<span class="sourceLineNo">1467</span>      }<a name="line.1467"></a>
-<span class="sourceLineNo">1468</span>      return;<a name="line.1468"></a>
-<span class="sourceLineNo">1469</span>    }<a name="line.1469"></a>
-<span class="sourceLineNo">1470</span>  }<a name="line.1470"></a>
-<span class="sourceLineNo">1471</span><a name="line.1471"></a>
-<span class="sourceLineNo">1472</span>  private void updateStoreOnExec(final RootProcedureState procStack,<a name="line.1472"></a>
-<span class="sourceLineNo">1473</span>      final Procedure procedure, final Procedure[] subprocs) {<a name="line.1473"></a>
-<span class="sourceLineNo">1474</span>    if (subprocs != null &amp;&amp; !procedure.isFailed()) {<a name="line.1474"></a>
-<span class="sourceLineNo">1475</span>      if (LOG.isTraceEnabled()) {<a name="line.1475"></a>
-<span class="sourceLineNo">1476</span>        LOG.trace("Stored " + procedure + ", children " + Arrays.toString(subprocs));<a name="line.1476"></a>
-<span class="sourceLineNo">1477</span>      }<a name="line.1477"></a>
-<span class="sourceLineNo">1478</span>      store.insert(procedure, subprocs);<a name="line.1478"></a>
-<span class="sourceLineNo">1479</span>    } else {<a name="line.1479"></a>
+<span class="sourceLineNo">1434</span>        case WAITING_TIMEOUT:<a name="line.1434"></a>
+<span class="sourceLineNo">1435</span>          timeoutExecutor.add(procedure);<a name="line.1435"></a>
+<span class="sourceLineNo">1436</span>          break;<a name="line.1436"></a>
+<span class="sourceLineNo">1437</span>        default:<a name="line.1437"></a>
+<span class="sourceLineNo">1438</span>          break;<a name="line.1438"></a>
+<span class="sourceLineNo">1439</span>      }<a name="line.1439"></a>
+<span class="sourceLineNo">1440</span>    }<a name="line.1440"></a>
+<span class="sourceLineNo">1441</span>    return subprocs;<a name="line.1441"></a>
+<span class="sourceLineNo">1442</span>  }<a name="line.1442"></a>
+<span class="sourceLineNo">1443</span><a name="line.1443"></a>
+<span class="sourceLineNo">1444</span>  private void submitChildrenProcedures(final Procedure[] subprocs) {<a name="line.1444"></a>
+<span class="sourceLineNo">1445</span>    for (int i = 0; i &lt; subprocs.length; ++i) {<a name="line.1445"></a>
+<span class="sourceLineNo">1446</span>      final Procedure subproc = subprocs[i];<a name="line.1446"></a>
+<span class="sourceLineNo">1447</span>      assert !procedures.containsKey(subproc.getProcId());<a name="line.1447"></a>
+<span class="sourceLineNo">1448</span>      procedures.put(subproc.getProcId(), subproc);<a name="line.1448"></a>
+<span class="sourceLineNo">1449</span>      scheduler.addFront(subproc);<a name="line.1449"></a>
+<span class="sourceLineNo">1450</span>    }<a name="line.1450"></a>
+<span class="sourceLineNo">1451</span>  }<a name="line.1451"></a>
+<span class="sourceLineNo">1452</span><a name="line.1452"></a>
+<span class="sourceLineNo">1453</span>  private void countDownChildren(final RootProcedureState procStack, final Procedure procedure) {<a name="line.1453"></a>
+<span class="sourceLineNo">1454</span>    final Procedure parent = procedures.get(procedure.getParentProcId());<a name="line.1454"></a>
+<span class="sourceLineNo">1455</span>    if (parent == null) {<a name="line.1455"></a>
+<span class="sourceLineNo">1456</span>      assert procStack.isRollingback();<a name="line.1456"></a>
+<span class="sourceLineNo">1457</span>      return;<a name="line.1457"></a>
+<span class="sourceLineNo">1458</span>    }<a name="line.1458"></a>
+<span class="sourceLineNo">1459</span><a name="line.1459"></a>
+<span class="sourceLineNo">1460</span>    // If this procedure is the last child awake the parent procedure<a name="line.1460"></a>
+<span class="sourceLineNo">1461</span>    final boolean traceEnabled = LOG.isTraceEnabled();<a name="line.1461"></a>
+<span class="sourceLineNo">1462</span>    if (traceEnabled) {<a name="line.1462"></a>
+<span class="sourceLineNo">1463</span>      LOG.trace(parent + " child is done: " + procedure);<a name="line.1463"></a>
+<span class="sourceLineNo">1464</span>    }<a name="line.1464"></a>
+<span class="sourceLineNo">1465</span><a name="line.1465"></a>
+<span class="sourceLineNo">1466</span>    if (parent.childrenCountDown() &amp;&amp; parent.getState() == ProcedureState.WAITING) {<a name="line.1466"></a>
+<span class="sourceLineNo">1467</span>      parent.setState(ProcedureState.RUNNABLE);<a name="line.1467"></a>
+<span class="sourceLineNo">1468</span>      store.update(parent);<a name="line.1468"></a>
+<span class="sourceLineNo">1469</span>      scheduler.addFront(parent);<a name="line.1469"></a>
+<span class="sourceLineNo">1470</span>      if (traceEnabled) {<a name="line.1470"></a>
+<span class="sourceLineNo">1471</span>        LOG.trace(parent + " all the children finished their work, resume.");<a name="line.1471"></a>
+<span class="sourceLineNo">1472</span>      }<a name="line.1472"></a>
+<span class="sourceLineNo">1473</span>      return;<a name="line.1473"></a>
+<span class="sourceLineNo">1474</span>    }<a name="line.1474"></a>
+<span class="sourceLineNo">1475</span>  }<a name="line.1475"></a>
+<span class="sourceLineNo">1476</span><a name="line.1476"></a>
+<span class="sourceLineNo">1477</span>  private void updateStoreOnExec(final RootProcedureState procStack,<a name="line.1477"></a>
+<span class="sourceLineNo">1478</span>      final Procedure procedure, final Procedure[] subprocs) {<a name="line.1478"></a>
+<span class="sourceLineNo">1479</span>    if (subprocs != null &amp;&amp; !procedure.isFailed()) {<a name="line.1479"></a>
 <span class="sourceLineNo">1480</span>      if (LOG.isTraceEnabled()) {<a name="line.1480"></a>
-<span class="sourceLineNo">1481</span>        LOG.trace("Store update " + procedure);<a name="line.1481"></a>
+<span class="sourceLineNo">1481</span>        LOG.trace("Stored " + procedure + ", children " + Arrays.toString(subprocs));<a name="line.1481"></a>
 <span class="sourceLineNo">1482</span>      }<a name="line.1482"></a>
-<span class="sourceLineNo">1483</span>      if (procedure.isFinished() &amp;&amp; !procedure.hasParent()) {<a name="line.1483"></a>
-<span class="sourceLineNo">1484</span>        // remove child procedures<a name="line.1484"></a>
-<span class="sourceLineNo">1485</span>        final long[] childProcIds = procStack.getSubprocedureIds();<a name="line.1485"></a>
-<span class="sourceLineNo">1486</span>        if (childProcIds != null) {<a name="line.1486"></a>
-<span class="sourceLineNo">1487</span>          store.delete(procedure, childProcIds);<a name="line.1487"></a>
-<span class="sourceLineNo">1488</span>          for (int i = 0; i &lt; childProcIds.length; ++i) {<a name="line.1488"></a>
-<span class="sourceLineNo">1489</span>            procedures.remove(childProcIds[i]);<a name="line.1489"></a>
-<span class="sourceLineNo">1490</span>          }<a name="line.1490"></a>
-<span class="sourceLineNo">1491</span>        } else {<a name="line.1491"></a>
-<span class="sourceLineNo">1492</span>          store.update(procedure);<a name="line.1492"></a>
-<span class="sourceLineNo">1493</span>        }<a name="line.1493"></a>
-<span class="sourceLineNo">1494</span>      } else {<a name="line.1494"></a>
-<span class="sourceLineNo">1495</span>        store.update(procedure);<a name="line.1495"></a>
-<span class="sourceLineNo">1496</span>      }<a name="line.1496"></a>
-<span class="sourceLineNo">1497</span>    }<a name="line.1497"></a>
-<span class="sourceLineNo">1498</span>  }<a name="line.1498"></a>
-<span class="sourceLineNo">1499</span><a name="line.1499"></a>
-<span class="sourceLineNo">1500</span>  private void handleInterruptedException(final Procedure proc, final InterruptedException e) {<a name="line.1500"></a>
-<span class="sourceLineNo">1501</span>    if (LOG.isTraceEnabled()) {<a name="line.1501"></a>
-<span class="sourceLineNo">1502</span>      LOG.trace("Interrupt during " + proc + ". suspend and retry it later.", e);<a name="line.1502"></a>
-<span class="sourceLineNo">1503</span>    }<a name="line.1503"></a>
+<span class="sourceLineNo">1483</span>      store.insert(procedure, subprocs);<a name="line.1483"></a>
+<span class="sourceLineNo">1484</span>    } else {<a name="line.1484"></a>
+<span class="sourceLineNo">1485</span>      if (LOG.isTraceEnabled()) {<a name="line.1485"></a>
+<span class="sourceLineNo">1486</span>        LOG.trace("Store update " + procedure);<a name="line.1486"></a>
+<span class="sourceLineNo">1487</span>      }<a name="line.1487"></a>
+<span class="sourceLineNo">1488</span>      if (procedure.isFinished() &amp;&amp; !procedure.hasParent()) {<a name="line.1488"></a>
+<span class="sourceLineNo">1489</span>        // remove child procedures<a name="line.1489"></a>
+<span class="sourceLineNo">1490</span>        final long[] childProcIds = procStack.getSubprocedureIds();<a name="line.1490"></a>
+<span class="sourceLineNo">1491</span>        if (childProcIds != null) {<a name="line.1491"></a>
+<span class="sourceLineNo">1492</span>          store.delete(procedure, childProcIds);<a name="line.1492"></a>
+<span class="sourceLineNo">1493</span>          for (int i = 0; i &lt; childProcIds.length; ++i) {<a name="line.1493"></a>
+<span class="sourceLineNo">1494</span>            procedures.remove(childProcIds[i]);<a name="line.1494"></a>
+<span class="sourceLineNo">1495</span>          }<a name="line.1495"></a>
+<span class="sourceLineNo">1496</span>        } else {<a name="line.1496"></a>
+<span class="sourceLineNo">1497</span>          store.update(procedure);<a name="line.1497"></a>
+<span class="sourceLineNo">1498</span>        }<a name="line.1498"></a>
+<span class="sourceLineNo">1499</span>      } else {<a name="line.1499"></a>
+<span class="sourceLineNo">1500</span>        store.update(procedure);<a name="line.1500"></a>
+<span class="sourceLineNo">1501</span>      }<a name="line.1501"></a>
+<span class="sourceLineNo">1502</span>    }<a name="line.1502"></a>
+<span class="sourceLineNo">1503</span>  }<a name="line.1503"></a>
 <span class="sourceLineNo">1504</span><a name="line.1504"></a>
-<span class="sourceLineNo">1505</span>    // NOTE: We don't call Thread.currentThread().interrupt()<a name="line.1505"></a>
-<span class="sourceLineNo">1506</span>    // because otherwise all the subsequent calls e.g. Thread.sleep() will throw<a name="line.1506"></a>
-<span class="sourceLineNo">1507</span>    // the InterruptedException. If the master is going down, we will be notified<a name="line.1507"></a>
-<span class="sourceLineNo">1508</span>    // and the executor/store will be stopped.<a name="line.1508"></a>
-<span class="sourceLineNo">1509</span>    // (The interrupted procedure will be retried on the next run)<a name="line.1509"></a>
-<span class="sourceLineNo">1510</span>  }<a name="line.1510"></a>
-<span class="sourceLineNo">1511</span><a name="line.1511"></a>
-<span class="sourceLineNo">1512</span>  private void execCompletionCleanup(final Procedure proc) {<a name="line.1512"></a>
-<span class="sourceLineNo">1513</span>    final TEnvironment env = getEnvironment();<a name="line.1513"></a>
-<span class="sourceLineNo">1514</span>    if (proc.holdLock(env) &amp;&amp; proc.hasLock(env)) {<a name="line.1514"></a>
-<span class="sourceLineNo">1515</span>      releaseLock(proc, true);<a name="line.1515"></a>
-<span class="sourceLineNo">1516</span>    }<a name="line.1516"></a>
-<span class="sourceLineNo">1517</span>    try {<a name="line.1517"></a>
-<span class="sourceLineNo">1518</span>      proc.completionCleanup(env);<a name="line.1518"></a>
-<span class="sourceLineNo">1519</span>    } catch (Throwable e) {<a name="line.1519"></a>
-<span class="sourceLineNo">1520</span>      // Catch NullPointerExceptions or similar errors...<a name="line.1520"></a>
-<span class="sourceLineNo">1521</span>      LOG.error("CODE-BUG: uncatched runtime exception for procedure: " + proc, e);<a name="line.1521"></a>
-<span class="sourceLineNo">1522</span>    }<a name="line.1522"></a>
-<span class="sourceLineNo">1523</span>  }<a name="line.1523"></a>
-<span class="sourceLineNo">1524</span><a name="line.1524"></a>
-<span class="sourceLineNo">1525</span>  private void procedureFinished(final Procedure proc) {<a name="line.1525"></a>
-<span class="sourceLineNo">1526</span>    // call the procedure completion cleanup handler<a name="line.1526"></a>
-<span class="sourceLineNo">1527</span>    execCompletionCleanup(proc);<a name="line.1527"></a>
-<span class="sourceLineNo">1528</span><a name="line.1528"></a>
-<span class="sourceLineNo">1529</span>    // update the executor internal state maps<a name="line.1529"></a>
-<span class="sourceLineNo">1530</span>    final ProcedureInfo procInfo = ProcedureUtil.convertToProcedureInfo(proc, proc.getNonceKey());<a name="line.1530"></a>
-<span class="sourceLineNo">1531</span>    if (!proc.shouldWaitClientAck(getEnvironment())) {<a name="line.1531"></a>
-<span class="sourceLineNo">1532</span>      procInfo.setClientAckTime(0);<a name="line.1532"></a>
-<span class="sourceLineNo">1533</span>    }<a name="line.1533"></a>
-<span class="sourceLineNo">1534</span><a name="line.1534"></a>
-<span class="sourceLineNo">1535</span>    completed.put(procInfo.getProcId(), procInfo);<a name="line.1535"></a>
-<span class="sourceLineNo">1536</span>    rollbackStack.remove(proc.getProcId());<a name="line.1536"></a>
-<span class="sourceLineNo">1537</span>    procedures.remove(proc.getProcId());<a name="line.1537"></a>
-<span class="sourceLineNo">1538</span><a name="line.1538"></a>
-<span class="sourceLineNo">1539</span>    // call the runnableSet completion cleanup handler<a name="line.1539"></a>
-<span class="sourceLineNo">1540</span>    try {<a name="line.1540"></a>
-<span class="sourceLineNo">1541</span>      scheduler.completionCleanup(proc);<a name="line.1541"></a>
-<span class="sourceLineNo">1542</span>    } catch (Throwable e) {<a name="line.1542"></a>
-<span class="sourceLineNo">1543</span>      // Catch NullPointerExceptions or similar errors...<a name="line.1543"></a>
-<span class="sourceLineNo">1544</span>      LOG.error("CODE-BUG: uncatched runtime exception for completion cleanup: " + proc, e);<a name="line.1544"></a>
-<span class="sourceLineNo">1545</span>    }<a name="line.1545"></a>
-<span class="sourceLineNo">1546</span><a name="line.1546"></a>
-<span class="sourceLineNo">1547</span>    // Notify the listeners<a name="line.1547"></a>
-<span class="sourceLineNo">1548</span>    sendProcedureFinishedNotification(proc.getProcId());<a name="line.1548"></a>
-<span class="sourceLineNo">1549</span>  }<a name="line.1549"></a>
-<span class="sourceLineNo">1550</span><a name="line.1550"></a>
-<span class="sourceLineNo">1551</span>  // ==========================================================================<a name="line.1551"></a>
-<span class="sourceLineNo">1552</span>  //  Worker Thread<a name="line.1552"></a>
-<span class="sourceLineNo">1553</span>  // ==========================================================================<a name="line.1553"></a>
-<span class="sourceLineNo">1554</span>  private final class WorkerThread extends StoppableThread {<a name="line.1554"></a>
-<span class="sourceLineNo">1555</span>    private final AtomicLong executionStartTime = new AtomicLong(Long.MAX_VALUE);<a name="line.1555"></a>
-<span class="sourceLineNo">1556</span><a name="line.1556"></a>
-<span class="sourceLineNo">1557</span>    public WorkerThread(final ThreadGroup group) {<a name="line.1557"></a>
-<span class="sourceLineNo">1558</span>      super(group, "ProcExecWorker-" + workerId.incrementAndGet());<a name="line.1558"></a>
-<span class="sourceLineNo">1559</span>    }<a name="line.1559"></a>
-<span class="sourceLineNo">1560</span><a name="line.1560"></a>
-<span class="sourceLineNo">1561</span>    @Override<a name="line.1561"></a>
-<span class="sourceLineNo">1562</span>    public void sendStopSignal() {<a name="line.1562"></a>
-<span class="sourceLineNo">1563</span>      scheduler.signalAll();<a name="line.1563"></a>
+<span class="sourceLineNo">1505</span>  private void handleInterruptedException(final Procedure proc, final InterruptedException e) {<a name="line.1505"></a>
+<span class="sourceLineNo">1506</span>    if (LOG.isTraceEnabled()) {<a name="line.1506"></a>
+<span class="sourceLineNo">1507</span>      LOG.trace("Interrupt during " + proc + ". suspend and retry it later.", e);<a name="line.1507"></a>
+<span class="sourceLineNo">1508</span>    }<a name="line.1508"></a>
+<span class="sourceLineNo">1509</span><a name="line.1509"></a>
+<span class="sourceLineNo">1510</span>    // NOTE: We don't call Thread.currentThread().interrupt()<a name="line.1510"></a>
+<span class="sourceLineNo">1511</span>    // because otherwise all the subsequent calls e.g. Thread.sleep() will throw<a name="line.1511"></a>
+<span class="sourceLineNo">1512</span>    // the InterruptedException. If the master is going down, we will be notified<a name="line.1512"></a>
+<span class="sourceLineNo">1513</span>    // and the executor/store will be stopped.<a name="line.1513"></a>
+<span class="sourceLineNo">1514</span>    // (The interrupted procedure will be retried on the next run)<a name="line.1514"></a>
+<span class="sourceLineNo">1515</span>  }<a name="line.1515"></a>
+<span class="sourceLineNo">1516</span><a name="line.1516"></a>
+<span class="sourceLineNo">1517</span>  private void execCompletionCleanup(final Procedure proc) {<a name="line.1517"></a>
+<span class="sourceLineNo">1518</span>    final TEnvironment env = getEnvironment();<a name="line.1518"></a>
+<span class="sourceLineNo">1519</span>    if (proc.holdLock(env) &amp;&amp; proc.hasLock(env)) {<a name="line.1519"></a>
+<span class="sourceLineNo">1520</span>      releaseLock(proc, true);<a name="line.1520"></a>
+<span class="sourceLineNo">1521</span>    }<a name="line.1521"></a>
+<span class="sourceLineNo">1522</span>    try {<a name="line.1522"></a>
+<span class="sourceLineNo">1523</span>      proc.completionCleanup(env);<a name="line.1523"></a>
+<span class="sourceLineNo">1524</span>    } catch (Throwable e) {<a name="line.1524"></a>
+<span class="sourceLineNo">1525</span>      // Catch NullPointerExceptions or similar errors...<a name="line.1525"></a>
+<span class="sourceLineNo">1526</span>      LOG.error("CODE-BUG: uncatched runtime exception for procedure: " + proc, e);<a name="line.1526"></a>
+<span class="sourceLineNo">1527</span>    }<a name="line.1527"></a>
+<span class="sourceLineNo">1528</span>  }<a name="line.1528"></a>
+<span class="sourceLineNo">1529</span><a name="line.1529"></a>
+<span class="sourceLineNo">1530</span>  private void procedureFinished(final Procedure proc) {<a name="line.1530"></a>
+<span class="sourceLineNo">1531</span>    // call the procedure completion cleanup handler<a name="line.1531"></a>
+<span class="sourceLineNo">1532</span>    execCompletionCleanup(proc);<a name="line.1532"></a>
+<span class="sourceLineNo">1533</span><a name="line.1533"></a>
+<span class="sourceLineNo">1534</span>    // update the executor internal state maps<a name="line.1534"></a>
+<span class="sourceLineNo">1535</span>    final ProcedureInfo procInfo = ProcedureUtil.convertToProcedureInfo(proc, proc.getNonceKey());<a name="line.1535"></a>
+<span class="sourceLineNo">1536</span>    if (!proc.shouldWaitClientAck(getEnvironment())) {<a name="line.1536"></a>
+<span class="sourceLineNo">1537</span>      procInfo.setClientAckTime(0);<a name="line.1537"></a>
+<span class="sourceLineNo">1538</span>    }<a name="line.1538"></a>
+<span class="sourceLineNo">1539</span><a name="line.1539"></a>
+<span class="sourceLineNo">1540</span>    completed.put(procInfo.getProcId(), procInfo);<a name="line.1540"></a>
+<span class="sourceLineNo">1541</span>    rollbackStack.remove(proc.getProcId());<a name="line.1541"></a>
+<span class="sourceLineNo">1542</span>    procedures.remove(proc.getProcId());<a name="line.1542"></a>
+<span class="sourceLineNo">1543</span><a name="line.1543"></a>
+<span class="sourceLineNo">1544</span>    // call the runnableSet completion cleanup handler<a name="line.1544"></a>
+<span class="sourceLineNo">1545</span>    try {<a name="line.1545"></a>
+<span class="sourceLineNo">1546</span>      scheduler.completionCleanup(proc);<a name="line.1546"></a>
+<span class="sourceLineNo">1547</span>    } catch (Throwable e) {<a name="line.1547"></a>
+<span class="sourceLineNo">1548</span>      // Catch NullPointerExceptions or similar errors...<a name="line.1548"></a>
+<span class="sourceLineNo">1549</span>      LOG.error("CODE-BUG: uncatched runtime exception for completion cleanup: " + proc, e);<a name="line.1549"></a>
+<span class="sourceLineNo">1550</span>    }<a name="line.1550"></a>
+<span class="sourceLineNo">1551</span><a name="line.1551"></a>
+<span class="sourceLineNo">1552</span>    // Notify the listeners<a name="line.1552"></a>
+<span class="sourceLineNo">1553</span>    sendProcedureFinishedNotification(proc.getProcId());<a name="line.1553"></a>
+<span class="sourceLineNo">1554</span>  }<a name="line.1554"></a>
+<span class="sourceLineNo">1555</span><a name="line.1555"></a>
+<span class="sourceLineNo">1556</span>  // ==========================================================================<a name="line.1556"></a>
+<span class="sourceLineNo">1557</span>  //  Worker Thread<a name="line.1557"></a>
+<span class="sourceLineNo">1558</span>  // ==========================================================================<a name="line.1558"></a>
+<span class="sourceLineNo">1559</span>  private final class WorkerThread extends StoppableThread {<a name="line.1559"></a>
+<span class="sourceLineNo">1560</span>    private final AtomicLong executionStartTime = new AtomicLong(Long.MAX_VALUE);<a name="line.1560"></a>
+<span class="sourceLineNo">1561</span><a name="line.1561"></a>
+<span class="sourceLineNo">1562</span>    public WorkerThread(final ThreadGroup group) {<a name="line.1562"></a>
+<span class="sourceLineNo">1563</span>      super(group, "ProcExecWorker-" + workerId.incrementAndGet());<a name="line.1563"></a>
 <span class="sourceLineNo">1564</span>    }<a name="line.1564"></a>
 <span class="sourceLineNo">1565</span><a name="line.1565"></a>
 <span class="sourceLineNo">1566</span>    @Override<a name="line.1566"></a>
-<span class="sourceLineNo">1567</span>    public void run() {<a name="line.1567"></a>
-<span class="sourceLineNo">1568</span>      final boolean traceEnabled = LOG.isTraceEnabled();<a name="line.1568"></a>
-<span class="sourceLineNo">1569</span>      long lastUpdate = EnvironmentEdgeManager.currentTime();<a name="line.1569"></a>
-<span class="sourceLineNo">1570</span>      while (isRunning() &amp;&amp; keepAlive(lastUpdate)) {<a name="line.1570"></a>
-<span class="sourceLineNo">1571</span>        final Procedure procedure = scheduler.poll(keepAliveTime, TimeUnit.MILLISECONDS);<a name="line.1571"></a>
-<span class="sourceLineNo">1572</span>        if (procedure == null) continue;<a name="line.1572"></a>
-<span class="sourceLineNo">1573</span><a name="line.1573"></a>
-<span class="sourceLineNo">1574</span>        store.setRunningProcedureCount(activeExecutorCount.incrementAndGet());<a name="line.1574"></a>
-<span class="sourceLineNo">1575</span>        executionStartTime.set(EnvironmentEdgeManager.currentTime());<a name="line.1575"></a>
-<span class="sourceLineNo">1576</span>        try {<a name="line.1576"></a>
-<span class="sourceLineNo">1577</span>          if (traceEnabled) {<a name="line.1577"></a>
-<span class="sourceLineNo">1578</span>            LOG.trace("Trying to start the execution of " + procedure);<a name="line.1578"></a>
-<span class="sourceLineNo">1579</span>          }<a name="line.1579"></a>
-<span class="sourceLineNo">1580</span>          executeProcedure(procedure);<a name="line.1580"></a>
-<span class="sourceLineNo">1581</span>        } finally {<a name="line.1581"></a>
-<span class="sourceLineNo">1582</span>          store.setRunningProcedureCount(activeExecutorCount.decrementAndGet());<a name="line.1582"></a>
-<span class="sourceLineNo">1583</span>          lastUpdate = EnvironmentEdgeManager.currentTime();<a name="line.1583"></a>
-<span class="sourceLineNo">1584</span>          executionStartTime.set(Long.MAX_VALUE);<a name="line.1584"></a>
-<span class="sourceLineNo">1585</span>        }<a name="line.1585"></a>
-<span class="sourceLineNo">1586</span>      }<a name="line.1586"></a>
-<span class="sourceLineNo">1587</span>      LOG.debug("Worker thread terminated " + this);<a name="line.1587"></a>
-<span class="sourceLineNo">1588</span>      workerThreads.remove(this);<a name="line.1588"></a>
-<span class="sourceLineNo">1589</span>    }<a name="line.1589"></a>
-<span class="sourceLineNo">1590</span><a name="line.1590"></a>
-<span class="sourceLineNo">1591</span>    /**<a name="line.1591"></a>
-<span class="sourceLineNo">1592</span>     * @return the time since the current procedure is running<a name="line.1592"></a>
-<span class="sourceLineNo">1593</span>     */<a name="line.1593"></a>
-<span class="sourceLineNo">1594</span>    public long getCurrentRunTime() {<a name="line.1594"></a>
-<span class="sourceLineNo">1595</span>      return EnvironmentEdgeManager.currentTime() - executionStartTime.get();<a name="line.1595"></a>
-<span class="sourceLineNo">1596</span>    }<a name="line.1596"></a>
-<span class="sourceLineNo">1597</span><a name="line.1597"></a>
-<span class="sourceLineNo">1598</span>    private boolean keepAlive(final long lastUpdate) {<a name="line.1598"></a>
-<span class="sourceLineNo">1599</span>      if (workerThreads.size() &lt;= corePoolSize) return true;<a name="line.1599"></a>
-<span class="sourceLineNo">1600</span>      return (EnvironmentEdgeManager.currentTime() - lastUpdate) &lt; keepAliveTime;<a name="line.1600"></a>
+<span class="sourceLineNo">1567</span>    public void sendStopSignal() {<a name="line.1567"></a>
+<span class="sourceLineNo">1568</span>      scheduler.signalAll();<a name="line.1568"></a>
+<span class="sourceLineNo">1569</span>    }<a name="line.1569"></a>
+<span class="sourceLineNo">1570</span><a name="line.1570"></a>
+<span class="sourceLineNo">1571</span>    @Override<a name="line.1571"></a>
+<span class="sourceLineNo">1572</span>    public void run() {<a name="line.1572"></a>
+<span class="sourceLineNo">1573</span>      final boolean traceEnabled = LOG.isTraceEnabled();<a name="line.1573"></a>
+<span class="sourceLineNo">1574</span>      long lastUpdate = EnvironmentEdgeManager.currentTime();<a name="line.1574"></a>
+<span class="sourceLineNo">1575</span>      while (isRunning() &amp;&amp; keepAlive(lastUpdate)) {<a name="line.1575"></a>
+<span class="sourceLineNo">1576</span>        final Procedure procedure = scheduler.poll(keepAliveTime, TimeUnit.MILLISECONDS);<a name="line.1576"></a>
+<span class="sourceLineNo">1577</span>        if (procedure == null) continue;<a name="line.1577"></a>
+<span class="sourceLineNo">1578</span><a name="line.1578"></a>
+<span class="sourceLineNo">1579</span>        store.setRunningProcedureCount(activeExecutorCount.incrementAndGet());<a name="line.1579"></a>
+<span class="sourceLineNo">1580</span>        executionStartTime.set(EnvironmentEdgeManager.currentTime());<a name="line.1580"></a>
+<span class="sourceLineNo">1581</span>        try {<a name="line.1581"></a>
+<span class="sourceLineNo">1582</span>          if (traceEnabled) {<a name="line.1582"></a>
+<span class="sourceLineNo">1583</span>            LOG.trace("Trying to start the execution of " + procedure);<a name="line.1583"></a>
+<span class="sourceLineNo">1584</span>          }<a name="line.1584"></a>
+<span class="sourceLineNo">1585</span>          executeProcedure(procedure);<a name="line.1585"></a>
+<span class="sourceLineNo">1586</span>        } finally {<a name="line.1586"></a>
+<span class="sourceLineNo">1587</span>          store.setRunningProcedureCount(activeExecutorCount.decrementAndGet());<a name="line.1587"></a>
+<span class="sourceLineNo">1588</span>          lastUpdate = EnvironmentEdgeManager.currentTime();<a name="line.1588"></a>
+<span class="sourceLineNo">1589</span>          executionStartTime.set(Long.MAX_VALUE);<a name="line.1589"></a>
+<span class="sourceLineNo">1590</span>        }<a name="line.1590"></a>
+<span class="sourceLineNo">1591</span>      }<a name="line.1591"></a>
+<span class="sourceLineNo">1592</span>      LOG.debug("Worker thread terminated " + this);<a name="line.1592"></a>
+<span class="sourceLineNo">1593</span>      workerThreads.remove(this);<a name="line.1593"></a>
+<span class="sourceLineNo">1594</span>    }<a name="line.1594"></a>
+<span class="sourceLineNo">1595</span><a name="line.1595"></a>
+<span class="sourceLineNo">1596</span>    /**<a name="line.1596"></a>
+<span class="sourceLineNo">1597</span>     * @return the time since the current procedure is running<a name="line.1597"></a>
+<span class="sourceLineNo">1598</span>     */<a name="line.1598"></a>
+<span class="sourceLineNo">1599</span>    public long getCurrentRunTime() {<a name="line.1599"></a>
+<span class="sourceLineNo">1600</span>      return EnvironmentEdgeManager.currentTime() - executionStartTime.get();<a name="line.1600"></a>
 <span class="sourceLineNo">1601</span>    }<a name="line.1601"></a>
-<span class="sourceLineNo">1602</span>  }<a name="line.1602"></a>
-<span class="sourceLineNo">1603</span><a name="line.1603"></a>
-<span class="sourceLineNo">1604</span>  // ==========================================================================<a name="line.1604"></a>
-<span class="sourceLineNo">1605</span>  //  Timeout Thread<a name="line.1605"></a>
-<span class="sourceLineNo">1606</span>  // ==========================================================================<a name="line.1606"></a>
-<span class="sourceLineNo">1607</span>  private final class TimeoutExecutorThread extends StoppableThread {<a name="line.1607"></a>
-<span class="sourceLineNo">1608</span>    private final DelayQueue&lt;DelayedWithTimeout&gt; queue = new DelayQueue&lt;&gt;();<a name="line.1608"></a>
-<span class="sourceLineNo">1609</span><a name="line.1609"></a>
-<span class="sourceLineNo">1610</span>    public TimeoutExecutorThread(final ThreadGroup group) {<a name="line.1610"></a>
-<span class="sourceLineNo">1611</span>      super(group, "ProcedureTimeoutExecutor");<a name="line.1611"></a>
-<span class="sourceLineNo">1612</span>    }<a name="line.1612"></a>
-<span class="sourceLineNo">1613</span><a name="line.1613"></a>
-<span class="sourceLineNo">1614</span>    @Override<a name="line.1614"></a>
-<span class="sourceLineNo">1615</span>    public void sendStopSignal() {<a name="line.1615"></a>
-<span class="sourceLineNo">1616</span>      queue.add(DelayedUtil.DELAYED_POISON);<a name="line.1616"></a>
+<span class="sourceLineNo">1602</span><a name="line.1602"></a>
+<span class="sourceLineNo">1603</span>    private boolean keepAlive(final long lastUpdate) {<a name="line.1603"></a>
+<span class="sourceLineNo">1604</span>      if (workerThreads.size() &lt;= corePoolSize) return true;<a name="line.1604"></a>
+<span class="sourceLineNo">1605</span>      return (EnvironmentEdgeManager.currentTime() - lastUpdate) &lt; keepAliveTime;<a name="line.1605"></a>
+<span class="sourceLineNo">1606</span>    }<a name="line.1606"></a>
+<span class="sourceLineNo">1607</span>  }<a name="line.1607"></a>
+<span class="sourceLineNo">1608</span><a name="line.1608"></a>
+<span class="sourceLineNo">1609</span>  // ==========================================================================<a name="line.1609"></a>
+<span class="sourceLineNo">1610</span>  //  Timeout Thread<a name="line.1610"></a>
+<span class="sourceLineNo">1611</span>  // ==========================================================================<a name="line.1611"></a>
+<span class="sourceLineNo">1612</span>  private final class TimeoutExecutorThread extends StoppableThread {<a name="line.1612"></a>
+<span class="sourceLineNo">1613</span>    private final DelayQueue&lt;DelayedWithTimeout&gt; queue = new DelayQueue&lt;&gt;();<a name="line.1613"></a>
+<span class="sourceLineNo">1614</span><a name="line.1614"></a>
+<span class="sourceLineNo">1615</span>    public TimeoutExecutorThread(final ThreadGroup group) {<a name="line.1615"></a>
+<span class="sourceLineNo">1616</span>      super(group, "ProcedureTimeoutExecutor");<a name="line.1616"></a>
 <span class="sourceLineNo">1617</span>    }<a name="line.1617"></a>
 <span class="sourceLineNo">1618</span><a name="line.1618"></a>
 <span class="sourceLineNo">1619</span>    @Override<a name="line.1619"></a>
-<span class="sourceLineNo">1620</span>    public void run() {<a name="line.1620"></a>
-<span class="sourceLineNo">1621</span>      final boolean isTraceEnabled = LOG.isTraceEnabled();<a name="line.1621"></a>
-<span class="sourceLineNo">1622</span>      while (isRunning()) {<a name="line.1622"></a>
-<span class="sourceLineNo">1623</span>        final DelayedWithTimeout task = DelayedUtil.takeWithoutInterrupt(queue);<a name="line.1623"></a>
-<span class="sourceLineNo">1624</span>        if (task == null || task == DelayedUtil.DELAYED_POISON) {<a name="line.1624"></a>
-<span class="sourceLineNo">1625</span>          // the executor may be shutting down,<a name="line.1625"></a>
-<span class="sourceLineNo">1626</span>          // and the task is just the shutdown request<a name="line.1626"></a>
-<span class="sourceLineNo">1627</span>          continue;<a name="line.1627"></a>
-<span class="sourceLineNo">1628</span>        }<a name="line.1628"></a>
-<span class="sourceLineNo">1629</span><a name="line.1629"></a>
-<span class="sourceLineNo">1630</span>        if (isTraceEnabled) {<a name="line.1630"></a>
-<span class="sourceLineNo">1631</span>          LOG.trace("Trying to start the execution of " + task);<a name="line.1631"></a>
-<span class="sourceLineNo">1632</span>        }<a name="line.1632"></a>
-<span class="sourceLineNo">1633</span><a name="line.1633"></a>
-<span class="sourceLineNo">1634</span>        // execute the task<a name="line.1634"></a>
-<span class="sourceLineNo">1635</span>        if (task instanceof InlineChore) {<a name="line.1635"></a>
-<span class="sourceLineNo">1636</span>          execInlineChore((InlineChore)task);<a name="line.1636"></a>
-<span class="sourceLineNo">1637</span>        } else if (task instanceof DelayedProcedure) {<a name="line.1637"></a>
-<span class="sourceLineNo">1638</span>          execDelayedProcedure((DelayedProcedure)task);<a name="line.1638"></a>
-<span class="sourceLineNo">1639</span>        } else {<a name="line.1639"></a>
-<span class="sourceLineNo">1640</span>          LOG.error("CODE-BUG unknown timeout task type " + task);<a name="line.1640"></a>
-<span class="sourceLineNo">1641</span>        }<a name="line.1641"></a>
-<span class="sourceLineNo">1642</span>      }<a name="line.1642"></a>
-<span class="sourceLineNo">1643</span>    }<a name="line.1643"></a>
-<span class="sourceLineNo">1644</span><a name="line.1644"></a>
-<span class="sourceLineNo">1645</span>    public void add(final InlineChore chore) {<a name="line.1645"></a>
-<span class="sourceLineNo">1646</span>      chore.refreshTimeout();<a name="line.1646"></a>
-<span class="sourceLineNo">1647</span>      queue.add(chore);<a name="line.1647"></a>
+<span class="sourceLineNo">1620</span>    public void sendStopSignal() {<a name="line.1620"></a>
+<span class="sourceLineNo">1621</span>      queue.add(DelayedUtil.DELAYED_POISON);<a name="line.1621"></a>
+<span class="sourceLineNo">1622</span>    }<a name="line.1622"></a>
+<span class="sourceLineNo">1623</span><a name="line.1623"></a>
+<span class="sourceLineNo">1624</span>    @Override<a name="line.1624"></a>
+<span class="sourceLineNo">1625</span>    public void run() {<a name="line.1625"></a>
+<span class="sourceLineNo">1626</span>      final boolean isTraceEnabled = LOG.isTraceEnabled();<a name="line.1626"></a>
+<span class="sourceLineNo">1627</span>      while (isRunning()) {<a name="line.1627"></a>
+<span class="sourceLineNo">1628</span>        final DelayedWithTimeout task = DelayedUtil.takeWithoutInterrupt(queue);<a name="line.1628"></a>
+<span class="sourceLineNo">1629</span>        if (task == null || task == DelayedUtil.DELAYED_POISON) {<a name="line.1629"></a>
+<span class="sourceLineNo">1630</span>          // the executor may be shutting down,<a name="line.1630"></a>
+<span class="sourceLineNo">1631</span>          // and the task is just the shutdown request<a name="line.1631"></a>
+<span class="sourceLineNo">1632</span>          continue;<a name="line.1632"></a>
+<span class="sourceLineNo">1633</span>        }<a name="line.1633"></a>
+<span class="sourceLineNo">1634</span><a name="line.1634"></a>
+<span class="sourceLineNo">1635</span>        if (isTraceEnabled) {<a name="line.1635"></a>
+<span class="sourceLineNo">1636</span>          LOG.trace("Trying to start the execution of " + task);<a name="line.1636"></a>
+<span class="sourceLineNo">1637</span>        }<a name="line.1637"></a>
+<span class="sourceLineNo">1638</span><a name="line.1638"></a>
+<span class="sourceLineNo">1639</span>        // execute the task<a name="line.1639"></a>
+<span class="sourceLineNo">1640</span>        if (task instanceof InlineChore) {<a name="line.1640"></a>
+<span class="sourceLineNo">1641</span>          execInlineChore((InlineChore)task);<a name="line.1641"></a>
+<span class="sourceLineNo">1642</span>        } else if (task instanceof DelayedProcedure) {<a name="line.1642"></a>
+<span class="sourceLineNo">1643</span>          execDelayedProcedure((DelayedProcedure)task);<a name="line.1643"></a>
+<span class="sourceLineNo">1644</span>        } else {<a name="line.1644"></a>
+<span class="sourceLineNo">1645</span>          LOG.error("CODE-BUG unknown timeout task type " + task);<a name="line.1645"></a>
+<span class="sourceLineNo">1646</span>        }<a name="line.1646"></a>
+<span class="sourceLineNo">1647</span>      }<a name="line.1647"></a>
 <span class="sourceLineNo">1648</span>    }<a name="line.1648"></a>
 <span class="sourceLineNo">1649</span><a name="line.1649"></a>
-<span class="sourceLineNo">1650</span>    public void add(final Procedure procedure) {<a name="line.1650"></a>
-<span class="sourceLineNo">1651</span>      assert procedure.getState() == ProcedureState.WAITING_TIMEOUT;<a name="line.1651"></a>
-<span class="sourceLineNo">1652</span>      queue.add(new DelayedProcedure(procedure));<a name="line.1652"></a>
+<span class="sourceLineNo">1650</span>    public void add(final InlineChore chore) {<a name="line.1650"></a>
+<span class="sourceLineNo">1651</span>      chore.refreshTimeout();<a name="line.1651"></a>
+<span class="sourceLineNo">1652</span>      queue.add(chore);<a name="line.1652"></a>
 <span class="sourceLineNo">1653</span>    }<a name="line.1653"></a>
 <span class="sourceLineNo">1654</span><a name="line.1654"></a>
-<span class="sourceLineNo">1655</span>    public boolean remove(final Procedure procedure) {<a name="line.1655"></a>
-<span class="sourceLineNo">1656</span>      return queue.remove(new DelayedProcedure(procedure));<a name="line.1656"></a>
-<span class="sourceLineNo">1657</span>    }<a name="line.1657"></a>
-<span class="sourceLineNo">1658</span><a name="line.1658"></a>
-<span class="sourceLineNo">1659</span>    private void execInlineChore(final InlineChore chore) {<a name="line.1659"></a>
-<span class="sourceLineNo">1660</span>      chore.run();<a name="line.1660"></a>
-<span class="sourceLineNo">1661</span>      add(chore);<a name="line.1661"></a>
+<span class="sourceLineNo">1655</span>    public void add(final Procedure procedure) {<a name="line.1655"></a>
+<span class="sourceLineNo">1656</span>      assert procedure.getState() == ProcedureState.WAITING_TIMEOUT;<a name="line.1656"></a>
+<span class="sourceLineNo">1657</span>      queue.add(new DelayedProcedure(procedure));<a name="line.1657"></a>
+<span class="sourceLineNo">1658</span>    }<a name="line.1658"></a>
+<span class="sourceLineNo">1659</span><a name="line.1659"></a>
+<span class="sourceLineNo">1660</span>    public boolean remove(final Procedure procedure) {<a name="line.1660"></a>
+<span class="sourceLineNo">1661</span>      return queue.remove(new DelayedProcedure(procedure));<a name="line.1661"></a>
 <span class="sourceLineNo">1662</span>    }<a name="line.1662"></a>
 <span class="sourceLineNo">1663</span><a name="line.1663"></a>
-<span class="sourceLineNo">1664</span>    private void execDelayedProcedure(final DelayedProcedure delayed) {<a name="line.1664"></a>
-<span class="sourceLineNo">1665</span>      // TODO: treat this as a normal procedure, add it to the scheduler and<a name="line.1665"></a>
-<span class="sourceLineNo">1666</span>      // let one of the workers handle it.<a name="line.1666"></a>
-<span class="sourceLineNo">1667</span>      // Today we consider ProcedureInMemoryChore as InlineChores<a name="line.1667"></a>
-<span class="sourceLineNo">1668</span>      final Procedure procedure = delayed.getObject();<a name="line.1668"></a>
-<span class="sourceLineNo">1669</span>      if (procedure instanceof ProcedureInMemoryChore) {<a name="line.1669"></a>
-<span class="sourceLineNo">1670</span>        executeInMemoryChore((ProcedureInMemoryChore)procedure);<a name="line.1670"></a>
-<span class="sourceLineNo">1671</span>        // if the procedure is in a waiting state again, put it back in the queue<a name="line.1671"></a>
-<span class="sourceLineNo">1672</span>        procedure.updateTimestamp();<a name="line.1672"></a>
-<span class="sourceLineNo">1673</span>        if (procedure.isWaiting()) {<a name="line.1673"></a>
-<span class="sourceLineNo">1674</span>          delayed.setTimeout(procedure.getTimeoutTimestamp());<a name="line.1674"></a>
-<span class="sourceLineNo">1675</span>          queue.add(delayed);<a name="line.1675"></a>
-<span class="sourceLineNo">1676</span>        }<a name="line.1676"></a>
-<span class="sourceLineNo">1677</span>      } else {<a name="line.1677"></a>
-<span class="sourceLineNo">1678</span>        executeTimedoutProcedure(procedure);<a name="line.1678"></a>
-<span class="sourceLineNo">1679</span>      }<a name="line.1679"></a>
-<span class="sourceLineNo">1680</span>    }<a name="line.1680"></a>
-<span class="sourceLineNo">1681</span><a name="line.1681"></a>
-<span class="sourceLineNo">1682</span>    private void executeInMemoryChore(final ProcedureInMemoryChore chore) {<a name="line.1682"></a>
-<span class="sourceLineNo">1683</span>      if (!chore.isWaiting()) return;<a name="line.1683"></a>
-<span class="sourceLineNo">1684</span><a name="line.1684"></a>
-<span class="sourceLineNo">1685</span>      // The ProcedureInMemoryChore is a special case, and it acts as a chore.<a name="line.1685"></a>
-<span class="sourceLineNo">1686</span>      // instead of bringing the Chore class in, we reuse this timeout thread for<a name="line.1686"></a>
-<span class="sourceLineNo">1687</span>      // this special case.<a name="line.1687"></a>
-<span class="sourceLineNo">1688</span>      try {<a name="line.1688"></a>
-<span class="sourceLineNo">1689</span>        chore.periodicExecute(getEnvironment());<a name="line.1689"></a>
-<span class="sourceLineNo">1690</span>      } catch (Throwable e) {<a name="line.1690"></a>
-<span class="sourceLineNo">1691</span>        LOG.error("Ignoring " + chore + " exception: " + e.getMessage(), e);<a name="line.1691"></a>
-<span class="sourceLineNo">1692</span>      }<a name="line.1692"></a>
-<span class="sourceLineNo">1693</span>    }<a name="line.1693"></a>
-<span class="sourceLineNo">1694</span><a name="line.1694"></a>
-<span class="sourceLineNo">1695</span>    private void executeTimedoutProcedure(final Procedure proc) {<a name="line.1695"></a>
-<span class="sourceLineNo">1696</span>      // The procedure received a timeout. if the procedure itself does not handle it,<a name="line.1696"></a>
-<span class="sourceLineNo">1697</span>      // call abort() and add the procedure back in the queue for rollback.<a name="line.1697"></a>
-<span class="sourceLineNo">1698</span>      if (proc.setTimeoutFailure(getEnvironment())) {<a name="line.1698"></a>
-<span class="sourceLineNo">1699</span>        long rootProcId = Procedure.getRootProcedureId(procedures, proc);<a name="line.1699"></a>
-<span class="sourceLineNo">1700</span>        RootProcedureState procStack = rollbackStack.get(rootProcId);<a name="line.1700"></a>
-<span class="sourceLineNo">1701</span>        procStack.abort();<a name="line.1701"></a>
-<span class="sourceLineNo">1702</span>        store.update(proc);<a name="line.1702"></a>
-<span class="sourceLineNo">1703</span>        scheduler.addFront(proc);<a name="line.1703"></a>
-<span class="sourceLineNo">1704</span>      }<a name="line.1704"></a>
-<span class="sourceLineNo">1705</span>    }<a name="line.1705"></a>
-<span class="sourceLineNo">1706</span>  }<a name="line.1706"></a>
-<span class="sourceLineNo">1707</span><a name="line.1707"></a>
-<span class="sourceLineNo">1708</span>  private static final class DelayedProcedure<a name="line.1708"></a>
-<span class="sourceLineNo">1709</span>      extends DelayedUtil.DelayedContainerWithTimestamp&lt;Procedure&gt; {<a name="line.1709"></a>
-<span class="sourceLineNo">1710</span>    public DelayedProcedure(final Procedure procedure) {<a name="line.1710"></a>
-<span class="sourceLineNo">1711</span>      super(procedure, procedure.getTimeoutTimestamp());<a name="line.1711"></a>
-<span class="sourceLineNo">1712</span>    }<a name="line.1712"></a>
-<span class="sourceLineNo">1713</span>  }<a name="line.1713"></a>
-<span class="sourceLineNo">1714</span><a name="line.1714"></a>
-<span class="sourceLineNo">1715</span>  private static abstract class StoppableThread extends Thread {<a name="line.1715"></a>
-<span class="sourceLineNo">1716</span>    public StoppableThread(final ThreadGroup group, final String name) {<a name="line.1716"></a>
-<span class="sourceLineNo">1717</span>      super(group, name);<a name="line.1717"></a>
-<span class="sourceLineNo">1718</span>    }<a name="line.1718"></a>
+<span class="sourceLineNo">1664</span>    private void execInlineChore(final InlineChore chore) {<a name="line.1664"></a>
+<span class="sourceLineNo">1665</span>      chore.run();<a name="line.1665"></a>
+<span class="sourceLineNo">1666</span>      add(chore);<a name="line.1666"></a>
+<span class="sourceLineNo">1667</span>    }<a name="line.1667"></a>
+<span class="sourceLineNo">1668</span><a name="line.1668"></a>
+<span class="sourceLineNo">1669</span>    private void execDelayedProcedure(final DelayedProcedure delayed) {<a name="line.1669"></a>
+<span class="sourceLineNo">1670</span>      // TODO: treat this as a normal procedure, add it to the scheduler and<a name="line.1670"></a>
+<span class="sourceLineNo">1671</span>      // let one of the workers handle it.<a name="line.1671"></a>
+<span class="sourceLineNo">1672</span>      // Today we consider ProcedureInMemoryChore as InlineChores<a name="line.1672"></a>
+<span class="sourceLineNo">1673</span>      final Procedure procedure = delayed.getObject();<a name="line.1673"></a>
+<span class="sourceLineNo">1674</span>      if (procedure instanceof ProcedureInMemoryChore) {<a name="line.1674"></a>
+<span class="sourceLineNo">1675</span>        executeInMemoryChore((ProcedureInMemoryChore)procedure);<a name="line.1675"></a>
+<span class="sourceLineNo">1676</span>        // if the procedure is in a waiting state again, put it back in the queue<a name="line.1676"></a>
+<span class="sourceLineNo">1677</span>        procedure.updateTimestamp();<a name="line.1677"></a>
+<span class="sourceLineNo">1678</span>        if (procedure.isWaiting()) {<a name="line.1678"></a>
+<span class="sourceLineNo">1679</span>          delayed.setTimeout(procedure.getTimeoutTimestamp());<a name="line.1679"></a>
+<span class="sourceLineNo">1680</span>          queue.add(delayed);<a name="line.1680"></a>
+<span class="sourceLineNo">1681</span>        }<a name="line.1681"></a>
+<span class="sourceLineNo">1682</span>      } else {<a name="line.1682"></a>
+<span class="sourceLineNo">1683</span>        executeTimedoutProcedure(procedure);<a name="line.1683"></a>
+<span class="sourceLineNo">1684</span>      }<a name="line.1684"></a>
+<span class="sourceLineNo">1685</span>    }<a name="line.1685"></a>
+<span class="sourceLineNo">1686</span><a name="line.1686"></a>
+<span class="sourceLineNo">1687</span>    private void executeInMemoryChore(final ProcedureInMemoryChore chore) {<a name="line.1687"></a>
+<span class="sourceLineNo">1688</span>      if (!chore.isWaiting()) return;<a name="line.1688"></a>
+<span class="sourceLineNo">1689</span><a name="line.1689"></a>
+<span class="sourceLineNo">1690</span>      // The ProcedureInMemoryChore is a special case, and it acts as a chore.<a name="line.1690"></a>
+<span class="sourceLineNo">1691</span>      // instead of bringing the Chore class in, we reuse this timeout thread for<a name="line.1691"></a>
+<span class="sourceLineNo">1692</span>      // this special case.<a name="line.1692"></a>
+<span class="sourceLineNo">1693</span>      try {<a name="line.1693"></a>
+<span class="sourceLineNo">1694</span>        chore.periodicExecute(getEnvironment());<a name="line.1694"></a>
+<span class="sourceLineNo">1695</span>      } catch (Throwable e) {<a name="line.1695"></a>
+<span class="sourceLineNo">1696</span>        LOG.error("Ignoring " + chore + " exception: " + e.getMessage(), e);<a name="line.1696"></a>
+<span class="sourceLineNo">1697</span>      }<a name="line.1697"></a>
+<span class="sourceLineNo">1698</span>    }<a name="line.1698"></a>
+<span class="sourceLineNo">1699</span><a name="line.1699"></a>
+<span class="sourceLineNo">1700</span>    private void executeTimedoutProcedure(final Procedure proc) {<a name="line.1700"></a>
+<span class="sourceLineNo">1701</span>      // The procedure received a timeout. if the procedure itself does not handle it,<a name="line.1701"></a>
+<span class="sourceLineNo">1702</span>      // call abort() and add the procedure back in the queue for rollback.<a name="line.1702"></a>
+<span class="sourceLineNo">1703</span>      if (proc.setTimeoutFailure(getEnvironment())) {<a name="line.1703"></a>
+<span class="sourceLineNo">1704</span>        long rootProcId = Procedure.getRootProcedureId(procedures, proc);<a name="line.1704"></a>
+<span class="sourceLineNo">1705</span>        RootProcedureState procStack = rollbackStack.get(rootProcId);<a name="line.1705"></a>
+<span class="sourceLineNo">1706</span>        procStack.abort();<a name="line.1706"></a>
+<span class="sourceLineNo">1707</span>        store.update(proc);<a name="line.1707"></a>
+<span class="sourceLineNo">1708</span>        scheduler.addFront(proc);<a name="line.1708"></a>
+<span class="sourceLineNo">1709</span>      }<a name="line.1709"></a>
+<span class="sourceLineNo">1710</span>    }<a name="line.1710"></a>
+<span class="sourceLineNo">1711</span>  }<a name="line.1711"></a>
+<span class="sourceLineNo">1712</span><a name="line.1712"></a>
+<span class="sourceLineNo">1713</span>  private static final class DelayedProcedure<a name="line.1713"></a>
+<span class="sourceLineNo">1714</span>      extends DelayedUtil.DelayedContainerWithTimestamp&lt;Procedure&gt; {<a name="line.1714"></a>
+<span class="sourceLineNo">1715</span>    public DelayedProcedure(final Procedure procedure) {<a name="line.1715"></a>
+<span class="sourceLineNo">1716</span>      super(procedure, procedure.getTimeoutTimestamp());<a name="line.1716"></a>
+<span class="sourceLineNo">1717</span>    }<a name="line.1717"></a>
+<span class="sourceLineNo">1718</span>  }<a name="line.1718"></a>
 <span class="sourceLineNo">1719</span><a name="line.1719"></a>
-<span class="sourceLineNo">1720</span>    public abstract void sendStopSignal();<a name="line.1720"></a>
-<span class="sourceLineNo">1721</span><a name="line.1721"></a>
-<span class="sourceLineNo">1722</span>    public void awaitTermination() {<a name="line.1722"></a>
-<span class="sourceLineNo">1723</span>      try {<a name="line.1723"></a>
-<span class="sourceLineNo">1724</span>        final long startTime = EnvironmentEdgeManager.currentTime();<a name="line.1724"></a>
-<span class="sourceLineNo">1725</span>        for (int i = 0; isAlive(); ++i) {<a name="line.1725"></a>
-<span class="sourceLineNo">1726</span>          sendStopSignal();<a name="line.1726"></a>
-<span class="sourceLineNo">1727</span>          join(250);<a name="line.1727"></a>
-<span class="sourceLineNo">1728</span>          if (i &gt; 0 &amp;&amp; (i % 8) == 0) {<a name="line.1728"></a>
-<span class="sourceLineNo">1729</span>            LOG.warn("Waiting termination of thread " + getName() + ", " +<a name="line.1729"></a>
-<span class="sourceLineNo">1730</span>              StringUtils.humanTimeDiff(EnvironmentEdgeManager.currentTime() - startTime));<a name="line.1730"></a>
-<span class="sourceLineNo">1731</span>          }<a name="line.1731"></a>
-<span class="sourceLineNo">1732</span>        }<a name="line.1732"></a>
-<span class="sourceLineNo">1733</span>      } catch (InterruptedException e) {<a name="line.1733"></a>
-<span class="sourceLineNo">1734</span>        LOG.warn(getName() + " join wait got interrupted", e);<a name="line.1734"></a>
-<span class="sourceLineNo">1735</span>      }<a name="line.1735"></a>
-<span class="sourceLineNo">1736</span>    }<a name="line.1736"></a>
-<span class="sourceLineNo">1737</span>  }<a name="line.1737"></a>
-<span class="sourceLineNo">1738</span><a name="line.1738"></a>
-<span class="sourceLineNo">1739</span>  // ==========================================================================<a name="line.1739"></a>
-<span class="sourceLineNo">1740</span>  //  Inline Chores (executors internal chores)<a name="line.1740"></a>
-<span class="sourceLineNo">1741</span>  // ==========================================================================<a name="line.1741"></a>
-<span class="sourceLineNo">1742</span>  private static abstract class InlineChore extends DelayedUtil.DelayedObject implements Runnable {<a name="line.1742"></a>
-<span class="sourceLineNo">1743</span>    private long timeout;<a name="line.1743"></a>
-<span class="sourceLineNo">1744</span><a name="line.1744"></a>
-<span class="sourceLineNo">1745</span>    public abstract int getTimeoutInterval();<a name="line.1745"></a>
-<span class="sourceLineNo">1746</span><a name="line.1746"></a>
-<span class="sourceLineNo">1747</span>    protected void refreshTimeout() {<a name="line.1747"></a>
-<span class="sourceLineNo">1748</span>      this.timeout = EnvironmentEdgeManager.currentTime() + getTimeoutInterval();<a name="line.1748"></a>
-<span class="sourceLineNo">1749</span>    }<a name="line.1749"></a>
-<span class="sourceLineNo">1750</span><a name="line.1750"></a>
-<span class="sourceLineNo">1751</span>    @Override<a name="line.1751"></a>
-<span class="sourceLineNo">1752</span>    public long getTimeout() {<a name="line.1752"></a>
-<span class="sourceLineNo">1753</span>      return timeout;<a name="line.1753"></a>
+<span class="sourceLineNo">1720</span>  private static abstract class StoppableThread extends Thread {<a name="line.1720"></a>
+<span class="sourceLineNo">1721</span>    public StoppableThread(final ThreadGroup group, final String name) {<a name="line.1721"></a>
+<span class="sourceLineNo">1722</span>      super(group, name);<a name="line.1722"></a>
+<span class="sourceLineNo">1723</span>    }<a name="line.1723"></a>
+<span class="sourceLineNo">1724</span><a name="line.1724"></a>
+<span class="sourceLineNo">1725</span>    public abstract void sendStopSignal();<a name="line.1725"></a>
+<span class="sourceLineNo">1726</span><a name="line.1726"></a>
+<span class="sourceLineNo">1727</span>    public void awaitTermination() {<a name="line.1727"></a>
+<span class="sourceLineNo">1728</span>      try {<a name="line.1728"></a>
+<span class="sourceLineNo">1729</span>        final long startTime = EnvironmentEdgeManager.currentTime();<a name="line.1729"></a>
+<span class="sourceLineNo">1730</span>        for (int i = 0; isAlive(); ++i) {<a name="line.1730"></a>
+<span class="sourceLineNo">1731</span>          sendStopSignal();<a name="line.1731"></a>
+<span class="sourceLineNo">1732</span>          join(250);<a name="line.1732"></a>
+<span class="sourceLineNo">1733</span>          if (i &gt; 0 &amp;&amp; (i % 8) == 0) {<a name="line.1733"></a>
+<span class="sourceLineNo">1734</span>            LOG.warn("Waiting termination of thread " + getName() + ", " +<a name="line.1734"></a>
+<span class="sourceLineNo">1735</span>              StringUtils.humanTimeDiff(EnvironmentEdgeManager.currentTime() - startTime));<a name="line.1735"></a>
+<span class="sourceLineNo">1736</span>          }<a name="line.1736"></a>
+<span class="sourceLineNo">1737</span>        }<a name="line.1737"></a>
+<span class="sourceLineNo">1738</span>      } catch (InterruptedException e) {<a name="line.1738"></a>
+<span class="sourceLineNo">1739</span>        LOG.warn(getName() + " join wait got interrupted", e);<a name="line.1739"></a>
+<span class="sourceLineNo">1740</span>      }<a name="line.1740"></a>
+<span class="sourceLineNo">1741</span>    }<a name="line.1741"></a>
+<span class="sourceLineNo">1742</span>  }<a name="line.1742"></a>
+<span class="sourceLineNo">1743</span><a name="line.1743"></a>
+<span class="sourceLineNo">1744</span>  // ==========================================================================<a name="line.1744"></a>
+<span class="sourceLineNo">1745</span>  //  Inline Chores (executors internal chores)<a name="line.1745"></a>
+<span class="sourceLineNo">1746</span>  // ==========================================================================<a name="line.1746"></a>
+<span class="sourceLineNo">1747</span>  private static abstract class InlineChore extends DelayedUtil.DelayedObject implements Runnable {<a name="line.1747"></a>
+<span class="sourceLineNo">1748</span>    private long timeout;<a name="line.1748"></a>
+<span class="sourceLineNo">1749</span><a name="line.1749"></a>
+<span class="sourceLineNo">1750</span>    public abstract int getTimeoutInterval();<a name="line.1750"></a>
+<span class="sourceLineNo">1751</span><a name="line.1751"></a>
+<span class="sourceLineNo">1752</span>    protected void refreshTimeout() {<a name="line.1752"></a>
+<span class="sourceLineNo">1753</span>      this.timeout = EnvironmentEdgeManager.currentTime() + getTimeoutInterval();<a name="line.1753"></a>
 <span class="sourceLineNo">1754</span>    }<a name="line.1754"></a>
-<span class="sourceLineNo">1755</span>  }<a name="line.1755"></a>
-<span class="sourceLineNo">1756</span><a name="line.1756"></a>
-<span class="sourceLineNo">1757</span>  // ----------------------------------------------------------------------------<a name="line.1757"></a>
-<span class="sourceLineNo">1758</span>  // TODO-MAYBE: Should we provide a InlineChore to notify the store with the<a name="line.1758"></a>
-<span class="sourceLineNo">1759</span>  // full set of procedures pending and completed to write a compacted<a name="line.1759"></a>
-<span class="sourceLineNo">1760</span>  // version of the log (in case is a log)?<a name="line.1760"></a>
-<span class="sourceLineNo">1761</span>  // In theory no, procedures are have a short life, so at some point the store<a name="line.1761"></a>
-<span class="sourceLineNo">1762</span>  // will have the tracker saying everything is in the last log.<a name="line.1762"></a>
-<span class="sourceLineNo">1763</span>  // ----------------------------------------------------------------------------<a name="line.1763"></a>
-<span class="sourceLineNo">1764</span><a name="line.1764"></a>
-<span class="sourceLineNo">1765</span>  private final class WorkerMonitor extends InlineChore {<a name="line.1765"></a>
-<span class="sourceLineNo">1766</span>    public static final String WORKER_MONITOR_INTERVAL_CONF_KEY =<a name="line.1766"></a>
-<span class="sourceLineNo">1767</span>        "hbase.procedure.worker.monitor.interval.msec";<a name="line.1767"></a>
-<span class="sourceLineNo">1768</span>    private static final int DEFAULT_WORKER_MONITOR_INTERVAL = 5000; // 5sec<a name="line.1768"></a>
+<span class="sourceLineNo">1755</span><a name="line.1755"></a>
+<span class="sourceLineNo">1756</span>    @Override<a name="line.1756"></a>
+<span class="sourceLineNo">1757</span>    public long getTimeout() {<a name="line.1757"></a>
+<span class="sourceLineNo">1758</span>      return timeout;<a name="line.1758"></a>
+<span class="sourceLineNo">1759</span>    }<a name="line.1759"></a>
+<span class="sourceLineNo">1760</span>  }<a name="line.1760"></a>
+<span class="sourceLineNo">1761</span><a name="line.1761"></a>
+<span class="sourceLineNo">1762</span>  // ----------------------------------------------------------------------------<a name="line.1762"></a>
+<span class="sourceLineNo">1763</span>  // TODO-MAYBE: Should we provide a InlineChore to notify the store with the<a name="line.1763"></a>
+<span class="sourceLineNo">1764</span>  // full set of procedures pending and completed to write a compacted<a name="line.1764"></a>
+<span class="sourceLineNo">1765</span>  // version of the log (in case is a log)?<a name="line.1765"></a>
+<span class="sourceLineNo">1766</span>  // In theory no, procedures are have a short life, so at some point the store<a name="line.1766"></a>
+<span class="sourceLineNo">1767</span>  // will have the tracker saying everything is in the last log.<a name="line.1767"></a>
+<span class="sourceLineNo">1768</span>  // ----------------------------------------------------------------------------<a name="line.1768"></a>
 <span class="sourceLineNo">1769</span><a name="line.1769"></a>
-<span class="sourceLineNo">1770</span>    public static final String WORKER_STUCK_THRESHOLD_CONF_KEY =<a name="line.1770"></a>
-<span class="sourceLineNo">1771</span>        "hbase.procedure.worker.stuck.threshold.msec";<a name="line.1771"></a>
-<span class="sourceLineNo">1772</span>    private static final int DEFAULT_WORKER_STUCK_THRESHOLD = 10000; // 10sec<a name="line.1772"></a>
-<span class="sourceLineNo">1773</span><a name="line.1773"></a>
-<span class="sourceLineNo">1774</span>    public static final String WORKER_ADD_STUCK_PERCENTAGE_CONF_KEY =<a name="line.1774"></a>
-<span class="sourceLineNo">1775</span>        "hbase.procedure.worker.add.stuck.percentage";<a name="line.1775"></a>
-<span class="sourceLineNo">1776</span>    private static final float DEFAULT_WORKER_ADD_STUCK_PERCENTAGE = 0.5f; // 50% stuck<a name="line.1776"></a>
-<span class="sourceLineNo">1777</span><a name="line.1777"></a>
-<span class="sourceLineNo">1778</span>    private float addWorkerStuckPercentage = DEFAULT_WORKER_ADD_STUCK_PERCENTAGE;<a name="line.1778"></a>
-<span class="sourceLineNo">1779</span>    private int timeoutInterval = DEFAULT_WORKER_MONITOR_INTERVAL;<a name="line.1779"></a>
-<span class="sourceLineNo">1780</span>    private int stuckThreshold = DEFAULT_WORKER_STUCK_THRESHOLD;<a name="line.1780"></a>
-<span class="sourceLineNo">1781</span><a name="line.1781"></a>
-<span class="sourceLineNo">1782</span>    public WorkerMonitor() {<a name="line.1782"></a>
-<span class="sourceLineNo">1783</span>      refreshConfig();<a name="line.1783"></a>
-<span class="sourceLineNo">1784</span>    }<a name="line.1784"></a>
-<span class="sourceLineNo">1785</span><a name="line.1785"></a>
-<span class="sourceLineNo">1786</span>    @Override<a name="line.1786"></a>
-<span class="sourceLineNo">1787</span>    public void run() {<a name="line.1787"></a>
-<span class="sourceLineNo">1788</span>      final int stuckCount = checkForStuckWorkers();<a name="line.1788"></a>
-<span class="sourceLineNo">1789</span>      checkThreadCount(stuckCount);<a name="line.1789"></a>
+<span class="sourceLineNo">1770</span>  private final class WorkerMonitor extends InlineChore {<a name="line.1770"></a>
+<span class="sourceLineNo">1771</span>    public static final String WORKER_MONITOR_INTERVAL_CONF_KEY =<a name="line.1771"></a>
+<span class="sourceLineNo">1772</span>        "hbase.procedure.worker.monitor.interval.msec";<a name="line.1772"></a>
+<span class="sourceLineNo">1773</span>    private static final int DEFAULT_WORKER_MONITOR_INTERVAL = 5000; // 5sec<a name="line.1773"></a>
+<span class="sourceLineNo">1774</span><a name="line.1774"></a>
+<span class="sourceLineNo">1775</span>    public static final String WORKER_STUCK_THRESHOLD_CONF_KEY =<a name="line.1775"></a>
+<span class="sourceLineNo">1776</span>        "hbase.procedure.worker.stuck.threshold.msec";<a name="line.1776"></a>
+<span class="sourceLineNo">1777</span>    private static final int DEFAULT_WORKER_STUCK_THRESHOLD = 10000; // 10sec<a name="line.1777"></a>
+<span class="sourceLineNo">1778</span><a name="line.1778"></a>
+<span class="sourceLineNo">1779</span>    public static final String WORKER_ADD_STUCK_PERCENTAGE_CONF_KEY =<a name="line.1779"></a>
+<span class="sourceLineNo">1780</span>        "hbase.procedure.worker.add.stuck.percentage";<a name="line.1780"></a>
+<span class="sourceLineNo">1781</span>    private static final float DEFAULT_WORKER_ADD_STUCK_PERCENTAGE = 0.5f; // 50% stuck<a name="line.1781"></a>
+<span class="sourceLineNo">1782</span><a name="line.1782"></a>
+<span class="sourceLineNo">1783</span>    private float addWorkerStuckPercentage = DEFAULT_WORKER_ADD_STUCK_PERCENTAGE;<a name="line.1783"></a>
+<span class="sourceLineNo">1784</span>    private int timeoutInterval = DEFAULT_WORKER_MONITOR_INTERVAL;<a name="line.1784"></a>
+<span class="sourceLineNo">1785</span>    private int stuckThreshold = DEFAULT_WORKER_STUCK_THRESHOLD;<a name="line.1785"></a>
+<span class="sourceLineNo">1786</span><a name="line.1786"></a>
+<span class="sourceLineNo">1787</span>    public WorkerMonitor() {<a name="line.1787"></a>
+<span class="sourceLineNo">1788</span>      refreshConfig();<a name="line.1788"></a>
+<span class="sourceLineNo">1789</span>    }<a name="line.1789"></a>
 <span class="sourceLineNo">1790</span><a name="line.1790"></a>
-<span class="sourceLineNo">1791</span>      // refresh interval (poor man dynamic conf update)<a name="line.1791"></a>
-<span class="sourceLineNo">1792</span>      refreshConfig();<a name="line.1792"></a>
-<span class="sourceLineNo">1793</span>    }<a name="line.1793"></a>
-<span class="sourceLineNo">1794</span><a name="line.1794"></a>
-<span class="sourceLineNo">1795</span>    private int checkForStuckWorkers() {<a name="line.1795"></a>
-<span class="sourceLineNo">1796</span>      // check if any of the worker is stuck<a name="line.1796"></a>
-<span class="sourceLineNo">1797</span>      int stuckCount = 0;<a name="line.1797"></a>
-<span class="sourceLineNo">1798</span>      for (WorkerThread worker: workerThreads) {<a name="line.1798"></a>
-<span class="sourceLineNo">1799</span>        if (worker.getCurrentRunTime() &lt; stuckThreshold) {<a name="line.1799"></a>
-<span class="sourceLineNo">1800</span>          continue;<a name="line.1800"></a>
-<span class="sourceLineNo">1801</span>        }<a name="line.1801"></a>
-<span class="sourceLineNo">1802</span><a name="line.1802"></a>
-<span class="sourceLineNo">1803</span>        // WARN the worker is stuck<a name="line.1803"></a>
-<span class="sourceLineNo">1804</span>        stuckCount++;<a name="line.1804"></a>
-<span class="sourceLineNo">1805</span>        LOG.warn("Worker stuck " + worker +<a name="line.1805"></a>
-<span class="sourceLineNo">1806</span>            " run time " + StringUtils.humanTimeDiff(worker.getCurrentRunTime()));<a name="line.1806"></a>
-<span class="sourceLineNo">1807</span>      }<a name="line.1807"></a>
-<span class="sourceLineNo">1808</span>      return stuckCount;<a name="line.1808"></a>
-<span class="sourceLineNo">1809</span>    }<a name="line.1809"></a>
-<span class="sourceLineNo">1810</span><a name="line.1810"></a>
-<span class="sourceLineNo">1811</span>    private void checkThreadCount(final int stuckCount) {<a name="line.1811"></a>
-<span class="sourceLineNo">1812</span>      // nothing to do if there are no runnable tasks<a name="line.1812"></a>
-<span class="sourceLineNo">1813</span>      if (stuckCount &lt; 1 || !scheduler.hasRunnables()) return;<a name="line.1813"></a>
-<span class="sourceLineNo">1814</span><a name="line.1814"></a>
-<span class="sourceLineNo">1815</span>      // add a new thread if the worker stuck percentage exceed the threshold limit<a name="line.1815"></a>
-<span class="sourceLineNo">1816</span>      // and every handler is active.<a name="line.1816"></a>
-<span class="sourceLineNo">1817</span>      final float stuckPerc = ((float)stuckCount) / workerThreads.size();<a name="line.1817"></a>
-<span class="sourceLineNo">1818</span>      if (stuckPerc &gt;= addWorkerStuckPercentage &amp;&amp;<a name="line.1818"></a>
-<span class="sourceLineNo">1819</span>          activeExecutorCount.get() == workerThreads.size()) {<a name="line.1819"></a>
-<span class="sourceLineNo">1820</span>        final WorkerThread worker = new WorkerThread(threadGroup);<a name="line.1820"></a>
-<span class="sourceLineNo">1821</span>        workerThreads.add(worker);<a name="line.1821"></a>
-<span class="sourceLineNo">1822</span>        worker.start();<a name="line.1822"></a>
-<span class="sourceLineNo">1823</span>        LOG.debug("Added new worker thread " + worker);<a name="line.1823"></a>
-<span class="sourceLineNo">1824</span>      }<a name="line.1824"></a>
-<span class="sourceLineNo">1825</span>    }<a name="line.1825"></a>
-<span class="sourceLineNo">1826</span><a name="line.1826"></a>
-<span class="sourceLineNo">1827</span>    private void refreshConfig() {<a name="line.1827"></a>
-<span class="sourceLineNo">1828</span>      addWorkerStuckPercentage = conf.getFloat(WORKER_ADD_STUCK_PERCENTAGE_CONF_KEY,<a name="line.1828"></a>
-<span class="sourceLineNo">1829</span>          DEFAULT_WORKER_ADD_STUCK_PERCENTAGE);<a name="line.1829"></a>
-<span class="sourceLineNo">1830</span>      timeoutInterval = conf.getInt(WORKER_MONITOR_INTERVAL_CONF_KEY,<a name="line.1830"></a>
-<span class="sourceLineNo">1831</span>        DEFAULT_WORKER_MONITOR_INTERVAL);<a name="line.1831"></a>
-<span class="sourceLineNo">1832</span>      stuckThreshold = conf.getInt(WORKER_STUCK_THRESHOLD_CONF_KEY,<a name="line.1832"></a>
-<span class="sourceLineNo">1833</span>        DEFAULT_WORKER_STUCK_THRESHOLD);<a name="line.1833"></a>
-<span class="sourceLineNo">1834</span>    }<a name="line.1834"></a>
-<span class="sourceLineNo">1835</span><a name="line.1835"></a>
-<span class="sourceLineNo">1836</span>    @Override<a name="line.1836"></a>
-<span class="sourceLineNo">1837</span>    public int getTimeoutInterval() {<a name="line.1837"></a>
-<span class="sourceLineNo">1838</span>      return timeoutInterval;<a name="line.1838"></a>
+<span class="sourceLineNo">1791</span>    @Override<a name="line.1791"></a>
+<span class="sourceLineNo">1792</span>    public void run() {<a name="line.1792"></a>
+<span class="sourceLineNo">1793</span>      final int stuckCount = checkForStuckWorkers();<a name="line.1793"></a>
+<span class="sourceLineNo">1794</span>      checkThreadCount(stuckCount);<a name="line.1794"></a>
+<span class="sourceLineNo">1795</span><a name="line.1795"></a>
+<span class="sourceLineNo">1796</span>      // refresh interval (poor man dynamic conf update)<a name="line.1796"></a>
+<span class="sourceLineNo">1797</span>      refreshConfig();<a name="line.1797"></a>
+<span class="sourceLineNo">1798</span>    }<a name="line.1798"></a>
+<span class="sourceLineNo">1799</span><a name="line.1799"></a>
+<span class="sourceLineNo">1800</span>    private int checkForStuckWorkers() {<a name="line.1800"></a>
+<span class="sourceLineNo">1801</span>      // check if any of the worker is stuck<a name="line.1801"></a>
+<span class="sourceLineNo">1802</span>      int stuckCount = 0;<a name="line.1802"></a>
+<span class="sourceLineNo">1803</span>      for (WorkerThread worker: workerThreads) {<a name="line.1803"></a>
+<span class="sourceLineNo">1804</span>        if (worker.getCurrentRunTime() &lt; stuckThreshold) {<a name="line.1804"></a>
+<span class="sourceLineNo">1805</span>          continue;<a name="line.1805"></a>
+<span class="sourceLineNo">1806</span>        }<a name="line.1806"></a>
+<span class="sourceLineNo">1807</span><a name="line.1807"></a>
+<span class="sourceLineNo">1808</span>        // WARN the worker is stuck<a name="line.1808"></a>
+<span class="sourceLineNo">1809</span>        stuckCount++;<a name="line.1809"></a>
+<span class="sourceLineNo">1810</span>        LOG.warn("Worker stuck " + worker +<a name="line.1810"></a>
+<span class="sourceLineNo">1811</span>            " run time " + StringUtils.humanTimeDiff(worker.getCurrentRunTime()));<a name="line.1811"></a>
+<span class="sourceLineNo">1812</span>      }<a name="line.1812"></a>
+<span class="sourceLineNo">1813</span>      return stuckCount;<a name="line.1813"></a>
+<span class="sourceLineNo">1814</span>    }<a name="line.1814"></a>
+<span class="sourceLineNo">1815</span><a name="line.1815"></a>
+<span class="sourceLineNo">1816</span>    private void checkThreadCount(final int stuckCount) {<a name="line.1816"></a>
+<span class="sourceLineNo">1817</span>      // nothing to do if there are no runnable tasks<a name="line.1817"></a>
+<span class="sourceLineNo">1818</span>      if (stuckCount &lt; 1 || !scheduler.hasRunnables()) return;<a name="line.1818"></a>
+<span class="sourceLineNo">1819</span><a name="line.1819"></a>
+<span class="sourceLineNo">1820</span>      // add a new thread if the worker stuck percentage exceed the threshold lim

<TRUNCATED>

Mime
View raw message