hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From git-site-r...@apache.org
Subject [10/32] hbase-site git commit: Published site at a07e755625382d3904c935c21a4f240ede6d2f43.
Date Mon, 13 Aug 2018 14:49:43 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/75e49c45/devapidocs/src-html/org/apache/hadoop/hbase/procedure2/ProcedureExecutor.CompletedProcedureRetainer.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/procedure2/ProcedureExecutor.CompletedProcedureRetainer.html b/devapidocs/src-html/org/apache/hadoop/hbase/procedure2/ProcedureExecutor.CompletedProcedureRetainer.html
index 9c54904..0a656db 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/procedure2/ProcedureExecutor.CompletedProcedureRetainer.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/procedure2/ProcedureExecutor.CompletedProcedureRetainer.html
@@ -1371,589 +1371,581 @@
 <span class="sourceLineNo">1363</span>    assert subprocStack != null : "Called rollback with no steps executed rootProc=" + rootProc;<a name="line.1363"></a>
 <span class="sourceLineNo">1364</span><a name="line.1364"></a>
 <span class="sourceLineNo">1365</span>    int stackTail = subprocStack.size();<a name="line.1365"></a>
-<span class="sourceLineNo">1366</span>    boolean reuseLock = false;<a name="line.1366"></a>
-<span class="sourceLineNo">1367</span>    while (stackTail --&gt; 0) {<a name="line.1367"></a>
-<span class="sourceLineNo">1368</span>      Procedure&lt;TEnvironment&gt; proc = subprocStack.get(stackTail);<a name="line.1368"></a>
-<span class="sourceLineNo">1369</span><a name="line.1369"></a>
-<span class="sourceLineNo">1370</span>      LockState lockState;<a name="line.1370"></a>
-<span class="sourceLineNo">1371</span>      if (!reuseLock &amp;&amp; (lockState = acquireLock(proc)) != LockState.LOCK_ACQUIRED) {<a name="line.1371"></a>
-<span class="sourceLineNo">1372</span>        // can't take a lock on the procedure, add the root-proc back on the<a name="line.1372"></a>
-<span class="sourceLineNo">1373</span>        // queue waiting for the lock availability<a name="line.1373"></a>
-<span class="sourceLineNo">1374</span>        return lockState;<a name="line.1374"></a>
-<span class="sourceLineNo">1375</span>      }<a name="line.1375"></a>
-<span class="sourceLineNo">1376</span><a name="line.1376"></a>
-<span class="sourceLineNo">1377</span>      lockState = executeRollback(proc);<a name="line.1377"></a>
+<span class="sourceLineNo">1366</span>    while (stackTail-- &gt; 0) {<a name="line.1366"></a>
+<span class="sourceLineNo">1367</span>      Procedure&lt;TEnvironment&gt; proc = subprocStack.get(stackTail);<a name="line.1367"></a>
+<span class="sourceLineNo">1368</span><a name="line.1368"></a>
+<span class="sourceLineNo">1369</span>      LockState lockState = acquireLock(proc);<a name="line.1369"></a>
+<span class="sourceLineNo">1370</span>      if (lockState != LockState.LOCK_ACQUIRED) {<a name="line.1370"></a>
+<span class="sourceLineNo">1371</span>        // can't take a lock on the procedure, add the root-proc back on the<a name="line.1371"></a>
+<span class="sourceLineNo">1372</span>        // queue waiting for the lock availability<a name="line.1372"></a>
+<span class="sourceLineNo">1373</span>        return lockState;<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>      lockState = executeRollback(proc);<a name="line.1376"></a>
+<span class="sourceLineNo">1377</span>      releaseLock(proc, false);<a name="line.1377"></a>
 <span class="sourceLineNo">1378</span>      boolean abortRollback = lockState != LockState.LOCK_ACQUIRED;<a name="line.1378"></a>
 <span class="sourceLineNo">1379</span>      abortRollback |= !isRunning() || !store.isRunning();<a name="line.1379"></a>
 <span class="sourceLineNo">1380</span><a name="line.1380"></a>
-<span class="sourceLineNo">1381</span>      // If the next procedure is the same to this one<a name="line.1381"></a>
-<span class="sourceLineNo">1382</span>      // (e.g. StateMachineProcedure reuse the same instance)<a name="line.1382"></a>
-<span class="sourceLineNo">1383</span>      // we can avoid to lock/unlock each step<a name="line.1383"></a>
-<span class="sourceLineNo">1384</span>      reuseLock = stackTail &gt; 0 &amp;&amp; (subprocStack.get(stackTail - 1) == proc) &amp;&amp; !abortRollback;<a name="line.1384"></a>
-<span class="sourceLineNo">1385</span>      if (!reuseLock &amp;&amp; proc.hasLock()) {<a name="line.1385"></a>
-<span class="sourceLineNo">1386</span>        releaseLock(proc, false);<a name="line.1386"></a>
-<span class="sourceLineNo">1387</span>      }<a name="line.1387"></a>
+<span class="sourceLineNo">1381</span>      // allows to kill the executor before something is stored to the wal.<a name="line.1381"></a>
+<span class="sourceLineNo">1382</span>      // useful to test the procedure recovery.<a name="line.1382"></a>
+<span class="sourceLineNo">1383</span>      if (abortRollback) {<a name="line.1383"></a>
+<span class="sourceLineNo">1384</span>        return lockState;<a name="line.1384"></a>
+<span class="sourceLineNo">1385</span>      }<a name="line.1385"></a>
+<span class="sourceLineNo">1386</span><a name="line.1386"></a>
+<span class="sourceLineNo">1387</span>      subprocStack.remove(stackTail);<a name="line.1387"></a>
 <span class="sourceLineNo">1388</span><a name="line.1388"></a>
-<span class="sourceLineNo">1389</span>      // allows to kill the executor before something is stored to the wal.<a name="line.1389"></a>
-<span class="sourceLineNo">1390</span>      // useful to test the procedure recovery.<a name="line.1390"></a>
-<span class="sourceLineNo">1391</span>      if (abortRollback) {<a name="line.1391"></a>
-<span class="sourceLineNo">1392</span>        return lockState;<a name="line.1392"></a>
-<span class="sourceLineNo">1393</span>      }<a name="line.1393"></a>
-<span class="sourceLineNo">1394</span><a name="line.1394"></a>
-<span class="sourceLineNo">1395</span>      subprocStack.remove(stackTail);<a name="line.1395"></a>
-<span class="sourceLineNo">1396</span><a name="line.1396"></a>
-<span class="sourceLineNo">1397</span>      // if the procedure is kind enough to pass the slot to someone else, yield<a name="line.1397"></a>
-<span class="sourceLineNo">1398</span>      if (proc.isYieldAfterExecutionStep(getEnvironment())) {<a name="line.1398"></a>
-<span class="sourceLineNo">1399</span>        return LockState.LOCK_YIELD_WAIT;<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>      if (proc != rootProc) {<a name="line.1402"></a>
-<span class="sourceLineNo">1403</span>        execCompletionCleanup(proc);<a name="line.1403"></a>
-<span class="sourceLineNo">1404</span>      }<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>    // Finalize the procedure state<a name="line.1407"></a>
-<span class="sourceLineNo">1408</span>    LOG.info("Rolled back " + rootProc +<a name="line.1408"></a>
-<span class="sourceLineNo">1409</span>             " exec-time=" + StringUtils.humanTimeDiff(rootProc.elapsedTime()));<a name="line.1409"></a>
-<span class="sourceLineNo">1410</span>    procedureFinished(rootProc);<a name="line.1410"></a>
-<span class="sourceLineNo">1411</span>    return LockState.LOCK_ACQUIRED;<a name="line.1411"></a>
-<span class="sourceLineNo">1412</span>  }<a name="line.1412"></a>
-<span class="sourceLineNo">1413</span><a name="line.1413"></a>
-<span class="sourceLineNo">1414</span>  /**<a name="line.1414"></a>
-<span class="sourceLineNo">1415</span>   * Execute the rollback of the procedure step.<a name="line.1415"></a>
-<span class="sourceLineNo">1416</span>   * It updates the store with the new state (stack index)<a name="line.1416"></a>
-<span class="sourceLineNo">1417</span>   * or will remove completly the procedure in case it is a child.<a name="line.1417"></a>
-<span class="sourceLineNo">1418</span>   */<a name="line.1418"></a>
-<span class="sourceLineNo">1419</span>  private LockState executeRollback(Procedure&lt;TEnvironment&gt; proc) {<a name="line.1419"></a>
-<span class="sourceLineNo">1420</span>    try {<a name="line.1420"></a>
-<span class="sourceLineNo">1421</span>      proc.doRollback(getEnvironment());<a name="line.1421"></a>
-<span class="sourceLineNo">1422</span>    } catch (IOException e) {<a name="line.1422"></a>
-<span class="sourceLineNo">1423</span>      LOG.debug("Roll back attempt failed for {}", proc, e);<a name="line.1423"></a>
-<span class="sourceLineNo">1424</span>      return LockState.LOCK_YIELD_WAIT;<a name="line.1424"></a>
-<span class="sourceLineNo">1425</span>    } catch (InterruptedException e) {<a name="line.1425"></a>
-<span class="sourceLineNo">1426</span>      handleInterruptedException(proc, e);<a name="line.1426"></a>
-<span class="sourceLineNo">1427</span>      return LockState.LOCK_YIELD_WAIT;<a name="line.1427"></a>
-<span class="sourceLineNo">1428</span>    } catch (Throwable e) {<a name="line.1428"></a>
-<span class="sourceLineNo">1429</span>      // Catch NullPointerExceptions or similar errors...<a name="line.1429"></a>
-<span class="sourceLineNo">1430</span>      LOG.error(HBaseMarkers.FATAL, "CODE-BUG: Uncaught runtime exception for " + proc, e);<a name="line.1430"></a>
-<span class="sourceLineNo">1431</span>    }<a name="line.1431"></a>
-<span class="sourceLineNo">1432</span><a name="line.1432"></a>
-<span class="sourceLineNo">1433</span>    // allows to kill the executor before something is stored to the wal.<a name="line.1433"></a>
-<span class="sourceLineNo">1434</span>    // useful to test the procedure recovery.<a name="line.1434"></a>
-<span class="sourceLineNo">1435</span>    if (testing != null &amp;&amp; testing.shouldKillBeforeStoreUpdate()) {<a name="line.1435"></a>
-<span class="sourceLineNo">1436</span>      String msg = "TESTING: Kill before store update";<a name="line.1436"></a>
-<span class="sourceLineNo">1437</span>      LOG.debug(msg);<a name="line.1437"></a>
-<span class="sourceLineNo">1438</span>      stop();<a name="line.1438"></a>
-<span class="sourceLineNo">1439</span>      throw new RuntimeException(msg);<a name="line.1439"></a>
-<span class="sourceLineNo">1440</span>    }<a name="line.1440"></a>
-<span class="sourceLineNo">1441</span><a name="line.1441"></a>
-<span class="sourceLineNo">1442</span>    if (proc.removeStackIndex()) {<a name="line.1442"></a>
-<span class="sourceLineNo">1443</span>      proc.setState(ProcedureState.ROLLEDBACK);<a name="line.1443"></a>
-<span class="sourceLineNo">1444</span><a name="line.1444"></a>
-<span class="sourceLineNo">1445</span>      // update metrics on finishing the procedure (fail)<a name="line.1445"></a>
-<span class="sourceLineNo">1446</span>      proc.updateMetricsOnFinish(getEnvironment(), proc.elapsedTime(), false);<a name="line.1446"></a>
-<span class="sourceLineNo">1447</span><a name="line.1447"></a>
-<span class="sourceLineNo">1448</span>      if (proc.hasParent()) {<a name="line.1448"></a>
-<span class="sourceLineNo">1449</span>        store.delete(proc.getProcId());<a name="line.1449"></a>
-<span class="sourceLineNo">1450</span>        procedures.remove(proc.getProcId());<a name="line.1450"></a>
-<span class="sourceLineNo">1451</span>      } else {<a name="line.1451"></a>
-<span class="sourceLineNo">1452</span>        final long[] childProcIds = rollbackStack.get(proc.getProcId()).getSubprocedureIds();<a name="line.1452"></a>
-<span class="sourceLineNo">1453</span>        if (childProcIds != null) {<a name="line.1453"></a>
-<span class="sourceLineNo">1454</span>          store.delete(proc, childProcIds);<a name="line.1454"></a>
-<span class="sourceLineNo">1455</span>        } else {<a name="line.1455"></a>
-<span class="sourceLineNo">1456</span>          store.update(proc);<a name="line.1456"></a>
-<span class="sourceLineNo">1457</span>        }<a name="line.1457"></a>
-<span class="sourceLineNo">1458</span>      }<a name="line.1458"></a>
-<span class="sourceLineNo">1459</span>    } else {<a name="line.1459"></a>
-<span class="sourceLineNo">1460</span>      store.update(proc);<a name="line.1460"></a>
-<span class="sourceLineNo">1461</span>    }<a name="line.1461"></a>
+<span class="sourceLineNo">1389</span>      // if the procedure is kind enough to pass the slot to someone else, yield<a name="line.1389"></a>
+<span class="sourceLineNo">1390</span>      if (proc.isYieldAfterExecutionStep(getEnvironment())) {<a name="line.1390"></a>
+<span class="sourceLineNo">1391</span>        return LockState.LOCK_YIELD_WAIT;<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>      if (proc != rootProc) {<a name="line.1394"></a>
+<span class="sourceLineNo">1395</span>        execCompletionCleanup(proc);<a name="line.1395"></a>
+<span class="sourceLineNo">1396</span>      }<a name="line.1396"></a>
+<span class="sourceLineNo">1397</span>    }<a name="line.1397"></a>
+<span class="sourceLineNo">1398</span><a name="line.1398"></a>
+<span class="sourceLineNo">1399</span>    // Finalize the procedure state<a name="line.1399"></a>
+<span class="sourceLineNo">1400</span>    LOG.info("Rolled back " + rootProc +<a name="line.1400"></a>
+<span class="sourceLineNo">1401</span>             " exec-time=" + StringUtils.humanTimeDiff(rootProc.elapsedTime()));<a name="line.1401"></a>
+<span class="sourceLineNo">1402</span>    procedureFinished(rootProc);<a name="line.1402"></a>
+<span class="sourceLineNo">1403</span>    return LockState.LOCK_ACQUIRED;<a name="line.1403"></a>
+<span class="sourceLineNo">1404</span>  }<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>   * Execute the rollback of the procedure step.<a name="line.1407"></a>
+<span class="sourceLineNo">1408</span>   * It updates the store with the new state (stack index)<a name="line.1408"></a>
+<span class="sourceLineNo">1409</span>   * or will remove completly the procedure in case it is a child.<a name="line.1409"></a>
+<span class="sourceLineNo">1410</span>   */<a name="line.1410"></a>
+<span class="sourceLineNo">1411</span>  private LockState executeRollback(Procedure&lt;TEnvironment&gt; proc) {<a name="line.1411"></a>
+<span class="sourceLineNo">1412</span>    try {<a name="line.1412"></a>
+<span class="sourceLineNo">1413</span>      proc.doRollback(getEnvironment());<a name="line.1413"></a>
+<span class="sourceLineNo">1414</span>    } catch (IOException e) {<a name="line.1414"></a>
+<span class="sourceLineNo">1415</span>      LOG.debug("Roll back attempt failed for {}", proc, e);<a name="line.1415"></a>
+<span class="sourceLineNo">1416</span>      return LockState.LOCK_YIELD_WAIT;<a name="line.1416"></a>
+<span class="sourceLineNo">1417</span>    } catch (InterruptedException e) {<a name="line.1417"></a>
+<span class="sourceLineNo">1418</span>      handleInterruptedException(proc, e);<a name="line.1418"></a>
+<span class="sourceLineNo">1419</span>      return LockState.LOCK_YIELD_WAIT;<a name="line.1419"></a>
+<span class="sourceLineNo">1420</span>    } catch (Throwable e) {<a name="line.1420"></a>
+<span class="sourceLineNo">1421</span>      // Catch NullPointerExceptions or similar errors...<a name="line.1421"></a>
+<span class="sourceLineNo">1422</span>      LOG.error(HBaseMarkers.FATAL, "CODE-BUG: Uncaught runtime exception for " + proc, e);<a name="line.1422"></a>
+<span class="sourceLineNo">1423</span>    }<a name="line.1423"></a>
+<span class="sourceLineNo">1424</span><a name="line.1424"></a>
+<span class="sourceLineNo">1425</span>    // allows to kill the executor before something is stored to the wal.<a name="line.1425"></a>
+<span class="sourceLineNo">1426</span>    // useful to test the procedure recovery.<a name="line.1426"></a>
+<span class="sourceLineNo">1427</span>    if (testing != null &amp;&amp; testing.shouldKillBeforeStoreUpdate()) {<a name="line.1427"></a>
+<span class="sourceLineNo">1428</span>      String msg = "TESTING: Kill before store update";<a name="line.1428"></a>
+<span class="sourceLineNo">1429</span>      LOG.debug(msg);<a name="line.1429"></a>
+<span class="sourceLineNo">1430</span>      stop();<a name="line.1430"></a>
+<span class="sourceLineNo">1431</span>      throw new RuntimeException(msg);<a name="line.1431"></a>
+<span class="sourceLineNo">1432</span>    }<a name="line.1432"></a>
+<span class="sourceLineNo">1433</span><a name="line.1433"></a>
+<span class="sourceLineNo">1434</span>    if (proc.removeStackIndex()) {<a name="line.1434"></a>
+<span class="sourceLineNo">1435</span>      proc.setState(ProcedureState.ROLLEDBACK);<a name="line.1435"></a>
+<span class="sourceLineNo">1436</span><a name="line.1436"></a>
+<span class="sourceLineNo">1437</span>      // update metrics on finishing the procedure (fail)<a name="line.1437"></a>
+<span class="sourceLineNo">1438</span>      proc.updateMetricsOnFinish(getEnvironment(), proc.elapsedTime(), false);<a name="line.1438"></a>
+<span class="sourceLineNo">1439</span><a name="line.1439"></a>
+<span class="sourceLineNo">1440</span>      if (proc.hasParent()) {<a name="line.1440"></a>
+<span class="sourceLineNo">1441</span>        store.delete(proc.getProcId());<a name="line.1441"></a>
+<span class="sourceLineNo">1442</span>        procedures.remove(proc.getProcId());<a name="line.1442"></a>
+<span class="sourceLineNo">1443</span>      } else {<a name="line.1443"></a>
+<span class="sourceLineNo">1444</span>        final long[] childProcIds = rollbackStack.get(proc.getProcId()).getSubprocedureIds();<a name="line.1444"></a>
+<span class="sourceLineNo">1445</span>        if (childProcIds != null) {<a name="line.1445"></a>
+<span class="sourceLineNo">1446</span>          store.delete(proc, childProcIds);<a name="line.1446"></a>
+<span class="sourceLineNo">1447</span>        } else {<a name="line.1447"></a>
+<span class="sourceLineNo">1448</span>          store.update(proc);<a name="line.1448"></a>
+<span class="sourceLineNo">1449</span>        }<a name="line.1449"></a>
+<span class="sourceLineNo">1450</span>      }<a name="line.1450"></a>
+<span class="sourceLineNo">1451</span>    } else {<a name="line.1451"></a>
+<span class="sourceLineNo">1452</span>      store.update(proc);<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>    return LockState.LOCK_ACQUIRED;<a name="line.1455"></a>
+<span class="sourceLineNo">1456</span>  }<a name="line.1456"></a>
+<span class="sourceLineNo">1457</span><a name="line.1457"></a>
+<span class="sourceLineNo">1458</span>  private void yieldProcedure(Procedure&lt;TEnvironment&gt; proc) {<a name="line.1458"></a>
+<span class="sourceLineNo">1459</span>    releaseLock(proc, false);<a name="line.1459"></a>
+<span class="sourceLineNo">1460</span>    scheduler.yield(proc);<a name="line.1460"></a>
+<span class="sourceLineNo">1461</span>  }<a name="line.1461"></a>
 <span class="sourceLineNo">1462</span><a name="line.1462"></a>
-<span class="sourceLineNo">1463</span>    return LockState.LOCK_ACQUIRED;<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>  private void yieldProcedure(Procedure&lt;TEnvironment&gt; proc) {<a name="line.1466"></a>
-<span class="sourceLineNo">1467</span>    releaseLock(proc, false);<a name="line.1467"></a>
-<span class="sourceLineNo">1468</span>    scheduler.yield(proc);<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>   * Executes &lt;code&gt;procedure&lt;/code&gt;<a name="line.1472"></a>
-<span class="sourceLineNo">1473</span>   * &lt;ul&gt;<a name="line.1473"></a>
-<span class="sourceLineNo">1474</span>   *  &lt;li&gt;Calls the doExecute() of the procedure<a name="line.1474"></a>
-<span class="sourceLineNo">1475</span>   *  &lt;li&gt;If the procedure execution didn't fail (i.e. valid user input)<a name="line.1475"></a>
-<span class="sourceLineNo">1476</span>   *  &lt;ul&gt;<a name="line.1476"></a>
-<span class="sourceLineNo">1477</span>   *    &lt;li&gt;...and returned subprocedures<a name="line.1477"></a>
-<span class="sourceLineNo">1478</span>   *    &lt;ul&gt;&lt;li&gt;The subprocedures are initialized.<a name="line.1478"></a>
-<span class="sourceLineNo">1479</span>   *      &lt;li&gt;The subprocedures are added to the store<a name="line.1479"></a>
-<span class="sourceLineNo">1480</span>   *      &lt;li&gt;The subprocedures are added to the runnable queue<a name="line.1480"></a>
-<span class="sourceLineNo">1481</span>   *      &lt;li&gt;The procedure is now in a WAITING state, waiting for the subprocedures to complete<a name="line.1481"></a>
-<span class="sourceLineNo">1482</span>   *    &lt;/ul&gt;<a name="line.1482"></a>
-<span class="sourceLineNo">1483</span>   *    &lt;/li&gt;<a name="line.1483"></a>
-<span class="sourceLineNo">1484</span>   *   &lt;li&gt;...if there are no subprocedure<a name="line.1484"></a>
-<span class="sourceLineNo">1485</span>   *    &lt;ul&gt;&lt;li&gt;the procedure completed successfully<a name="line.1485"></a>
-<span class="sourceLineNo">1486</span>   *      &lt;li&gt;if there is a parent (WAITING)<a name="line.1486"></a>
-<span class="sourceLineNo">1487</span>   *      &lt;li&gt;the parent state will be set to RUNNABLE<a name="line.1487"></a>
-<span class="sourceLineNo">1488</span>   *    &lt;/ul&gt;<a name="line.1488"></a>
-<span class="sourceLineNo">1489</span>   *   &lt;/li&gt;<a name="line.1489"></a>
+<span class="sourceLineNo">1463</span>  /**<a name="line.1463"></a>
+<span class="sourceLineNo">1464</span>   * Executes &lt;code&gt;procedure&lt;/code&gt;<a name="line.1464"></a>
+<span class="sourceLineNo">1465</span>   * &lt;ul&gt;<a name="line.1465"></a>
+<span class="sourceLineNo">1466</span>   *  &lt;li&gt;Calls the doExecute() of the procedure<a name="line.1466"></a>
+<span class="sourceLineNo">1467</span>   *  &lt;li&gt;If the procedure execution didn't fail (i.e. valid user input)<a name="line.1467"></a>
+<span class="sourceLineNo">1468</span>   *  &lt;ul&gt;<a name="line.1468"></a>
+<span class="sourceLineNo">1469</span>   *    &lt;li&gt;...and returned subprocedures<a name="line.1469"></a>
+<span class="sourceLineNo">1470</span>   *    &lt;ul&gt;&lt;li&gt;The subprocedures are initialized.<a name="line.1470"></a>
+<span class="sourceLineNo">1471</span>   *      &lt;li&gt;The subprocedures are added to the store<a name="line.1471"></a>
+<span class="sourceLineNo">1472</span>   *      &lt;li&gt;The subprocedures are added to the runnable queue<a name="line.1472"></a>
+<span class="sourceLineNo">1473</span>   *      &lt;li&gt;The procedure is now in a WAITING state, waiting for the subprocedures to complete<a name="line.1473"></a>
+<span class="sourceLineNo">1474</span>   *    &lt;/ul&gt;<a name="line.1474"></a>
+<span class="sourceLineNo">1475</span>   *    &lt;/li&gt;<a name="line.1475"></a>
+<span class="sourceLineNo">1476</span>   *   &lt;li&gt;...if there are no subprocedure<a name="line.1476"></a>
+<span class="sourceLineNo">1477</span>   *    &lt;ul&gt;&lt;li&gt;the procedure completed successfully<a name="line.1477"></a>
+<span class="sourceLineNo">1478</span>   *      &lt;li&gt;if there is a parent (WAITING)<a name="line.1478"></a>
+<span class="sourceLineNo">1479</span>   *      &lt;li&gt;the parent state will be set to RUNNABLE<a name="line.1479"></a>
+<span class="sourceLineNo">1480</span>   *    &lt;/ul&gt;<a name="line.1480"></a>
+<span class="sourceLineNo">1481</span>   *   &lt;/li&gt;<a name="line.1481"></a>
+<span class="sourceLineNo">1482</span>   *  &lt;/ul&gt;<a name="line.1482"></a>
+<span class="sourceLineNo">1483</span>   *  &lt;/li&gt;<a name="line.1483"></a>
+<span class="sourceLineNo">1484</span>   *  &lt;li&gt;In case of failure<a name="line.1484"></a>
+<span class="sourceLineNo">1485</span>   *  &lt;ul&gt;<a name="line.1485"></a>
+<span class="sourceLineNo">1486</span>   *    &lt;li&gt;The store is updated with the new state&lt;/li&gt;<a name="line.1486"></a>
+<span class="sourceLineNo">1487</span>   *    &lt;li&gt;The executor (caller of this method) will start the rollback of the procedure&lt;/li&gt;<a name="line.1487"></a>
+<span class="sourceLineNo">1488</span>   *  &lt;/ul&gt;<a name="line.1488"></a>
+<span class="sourceLineNo">1489</span>   *  &lt;/li&gt;<a name="line.1489"></a>
 <span class="sourceLineNo">1490</span>   *  &lt;/ul&gt;<a name="line.1490"></a>
-<span class="sourceLineNo">1491</span>   *  &lt;/li&gt;<a name="line.1491"></a>
-<span class="sourceLineNo">1492</span>   *  &lt;li&gt;In case of failure<a name="line.1492"></a>
-<span class="sourceLineNo">1493</span>   *  &lt;ul&gt;<a name="line.1493"></a>
-<span class="sourceLineNo">1494</span>   *    &lt;li&gt;The store is updated with the new state&lt;/li&gt;<a name="line.1494"></a>
-<span class="sourceLineNo">1495</span>   *    &lt;li&gt;The executor (caller of this method) will start the rollback of the procedure&lt;/li&gt;<a name="line.1495"></a>
-<span class="sourceLineNo">1496</span>   *  &lt;/ul&gt;<a name="line.1496"></a>
-<span class="sourceLineNo">1497</span>   *  &lt;/li&gt;<a name="line.1497"></a>
-<span class="sourceLineNo">1498</span>   *  &lt;/ul&gt;<a name="line.1498"></a>
-<span class="sourceLineNo">1499</span>   */<a name="line.1499"></a>
-<span class="sourceLineNo">1500</span>  private void execProcedure(RootProcedureState&lt;TEnvironment&gt; procStack,<a name="line.1500"></a>
-<span class="sourceLineNo">1501</span>      Procedure&lt;TEnvironment&gt; procedure) {<a name="line.1501"></a>
-<span class="sourceLineNo">1502</span>    Preconditions.checkArgument(procedure.getState() == ProcedureState.RUNNABLE,<a name="line.1502"></a>
-<span class="sourceLineNo">1503</span>        "NOT RUNNABLE! " + procedure.toString());<a name="line.1503"></a>
-<span class="sourceLineNo">1504</span><a name="line.1504"></a>
-<span class="sourceLineNo">1505</span>    // Procedures can suspend themselves. They skip out by throwing a ProcedureSuspendedException.<a name="line.1505"></a>
-<span class="sourceLineNo">1506</span>    // The exception is caught below and then we hurry to the exit without disturbing state. The<a name="line.1506"></a>
-<span class="sourceLineNo">1507</span>    // idea is that the processing of this procedure will be unsuspended later by an external event<a name="line.1507"></a>
-<span class="sourceLineNo">1508</span>    // such the report of a region open.<a name="line.1508"></a>
-<span class="sourceLineNo">1509</span>    boolean suspended = false;<a name="line.1509"></a>
-<span class="sourceLineNo">1510</span><a name="line.1510"></a>
-<span class="sourceLineNo">1511</span>    // Whether to 're-' -execute; run through the loop again.<a name="line.1511"></a>
-<span class="sourceLineNo">1512</span>    boolean reExecute = false;<a name="line.1512"></a>
-<span class="sourceLineNo">1513</span><a name="line.1513"></a>
-<span class="sourceLineNo">1514</span>    Procedure&lt;TEnvironment&gt;[] subprocs = null;<a name="line.1514"></a>
-<span class="sourceLineNo">1515</span>    do {<a name="line.1515"></a>
-<span class="sourceLineNo">1516</span>      reExecute = false;<a name="line.1516"></a>
-<span class="sourceLineNo">1517</span>      try {<a name="line.1517"></a>
-<span class="sourceLineNo">1518</span>        subprocs = procedure.doExecute(getEnvironment());<a name="line.1518"></a>
-<span class="sourceLineNo">1519</span>        if (subprocs != null &amp;&amp; subprocs.length == 0) {<a name="line.1519"></a>
-<span class="sourceLineNo">1520</span>          subprocs = null;<a name="line.1520"></a>
-<span class="sourceLineNo">1521</span>        }<a name="line.1521"></a>
-<span class="sourceLineNo">1522</span>      } catch (ProcedureSuspendedException e) {<a name="line.1522"></a>
-<span class="sourceLineNo">1523</span>        LOG.trace("Suspend {}", procedure);<a name="line.1523"></a>
-<span class="sourceLineNo">1524</span>        suspended = true;<a name="line.1524"></a>
-<span class="sourceLineNo">1525</span>      } catch (ProcedureYieldException e) {<a name="line.1525"></a>
-<span class="sourceLineNo">1526</span>        LOG.trace("Yield {}", procedure, e);<a name="line.1526"></a>
-<span class="sourceLineNo">1527</span>        yieldProcedure(procedure);<a name="line.1527"></a>
-<span class="sourceLineNo">1528</span>        return;<a name="line.1528"></a>
-<span class="sourceLineNo">1529</span>      } catch (InterruptedException e) {<a name="line.1529"></a>
-<span class="sourceLineNo">1530</span>        LOG.trace("Yield interrupt {}", procedure, e);<a name="line.1530"></a>
-<span class="sourceLineNo">1531</span>        handleInterruptedException(procedure, e);<a name="line.1531"></a>
-<span class="sourceLineNo">1532</span>        yieldProcedure(procedure);<a name="line.1532"></a>
-<span class="sourceLineNo">1533</span>        return;<a name="line.1533"></a>
-<span class="sourceLineNo">1534</span>      } catch (Throwable e) {<a name="line.1534"></a>
-<span class="sourceLineNo">1535</span>        // Catch NullPointerExceptions or similar errors...<a name="line.1535"></a>
-<span class="sourceLineNo">1536</span>        String msg = "CODE-BUG: Uncaught runtime exception: " + procedure;<a name="line.1536"></a>
-<span class="sourceLineNo">1537</span>        LOG.error(msg, e);<a name="line.1537"></a>
-<span class="sourceLineNo">1538</span>        procedure.setFailure(new RemoteProcedureException(msg, e));<a name="line.1538"></a>
-<span class="sourceLineNo">1539</span>      }<a name="line.1539"></a>
-<span class="sourceLineNo">1540</span><a name="line.1540"></a>
-<span class="sourceLineNo">1541</span>      if (!procedure.isFailed()) {<a name="line.1541"></a>
-<span class="sourceLineNo">1542</span>        if (subprocs != null) {<a name="line.1542"></a>
-<span class="sourceLineNo">1543</span>          if (subprocs.length == 1 &amp;&amp; subprocs[0] == procedure) {<a name="line.1543"></a>
-<span class="sourceLineNo">1544</span>            // Procedure returned itself. Quick-shortcut for a state machine-like procedure;<a name="line.1544"></a>
-<span class="sourceLineNo">1545</span>            // i.e. we go around this loop again rather than go back out on the scheduler queue.<a name="line.1545"></a>
-<span class="sourceLineNo">1546</span>            subprocs = null;<a name="line.1546"></a>
-<span class="sourceLineNo">1547</span>            reExecute = true;<a name="line.1547"></a>
-<span class="sourceLineNo">1548</span>            LOG.trace("Short-circuit to next step on pid={}", procedure.getProcId());<a name="line.1548"></a>
-<span class="sourceLineNo">1549</span>          } else {<a name="line.1549"></a>
-<span class="sourceLineNo">1550</span>            // Yield the current procedure, and make the subprocedure runnable<a name="line.1550"></a>
-<span class="sourceLineNo">1551</span>            // subprocs may come back 'null'.<a name="line.1551"></a>
-<span class="sourceLineNo">1552</span>            subprocs = initializeChildren(procStack, procedure, subprocs);<a name="line.1552"></a>
-<span class="sourceLineNo">1553</span>            LOG.info("Initialized subprocedures=" +<a name="line.1553"></a>
-<span class="sourceLineNo">1554</span>              (subprocs == null? null:<a name="line.1554"></a>
-<span class="sourceLineNo">1555</span>                Stream.of(subprocs).map(e -&gt; "{" + e.toString() + "}").<a name="line.1555"></a>
-<span class="sourceLineNo">1556</span>                collect(Collectors.toList()).toString()));<a name="line.1556"></a>
-<span class="sourceLineNo">1557</span>          }<a name="line.1557"></a>
-<span class="sourceLineNo">1558</span>        } else if (procedure.getState() == ProcedureState.WAITING_TIMEOUT) {<a name="line.1558"></a>
-<span class="sourceLineNo">1559</span>          LOG.trace("Added to timeoutExecutor {}", procedure);<a name="line.1559"></a>
-<span class="sourceLineNo">1560</span>          timeoutExecutor.add(procedure);<a name="line.1560"></a>
-<span class="sourceLineNo">1561</span>        } else if (!suspended) {<a name="line.1561"></a>
-<span class="sourceLineNo">1562</span>          // No subtask, so we are done<a name="line.1562"></a>
-<span class="sourceLineNo">1563</span>          procedure.setState(ProcedureState.SUCCESS);<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><a name="line.1566"></a>
-<span class="sourceLineNo">1567</span>      // Add the procedure to the stack<a name="line.1567"></a>
-<span class="sourceLineNo">1568</span>      procStack.addRollbackStep(procedure);<a name="line.1568"></a>
-<span class="sourceLineNo">1569</span><a name="line.1569"></a>
-<span class="sourceLineNo">1570</span>      // allows to kill the executor before something is stored to the wal.<a name="line.1570"></a>
-<span class="sourceLineNo">1571</span>      // useful to test the procedure recovery.<a name="line.1571"></a>
-<span class="sourceLineNo">1572</span>      if (testing != null &amp;&amp; testing.shouldKillBeforeStoreUpdate(suspended)) {<a name="line.1572"></a>
-<span class="sourceLineNo">1573</span>        String msg = "TESTING: Kill before store update: " + procedure;<a name="line.1573"></a>
-<span class="sourceLineNo">1574</span>        LOG.debug(msg);<a name="line.1574"></a>
-<span class="sourceLineNo">1575</span>        stop();<a name="line.1575"></a>
-<span class="sourceLineNo">1576</span>        throw new RuntimeException(msg);<a name="line.1576"></a>
-<span class="sourceLineNo">1577</span>      }<a name="line.1577"></a>
-<span class="sourceLineNo">1578</span><a name="line.1578"></a>
-<span class="sourceLineNo">1579</span>      // TODO: The code here doesn't check if store is running before persisting to the store as<a name="line.1579"></a>
-<span class="sourceLineNo">1580</span>      // it relies on the method call below to throw RuntimeException to wind up the stack and<a name="line.1580"></a>
-<span class="sourceLineNo">1581</span>      // executor thread to stop. The statement following the method call below seems to check if<a name="line.1581"></a>
-<span class="sourceLineNo">1582</span>      // store is not running, to prevent scheduling children procedures, re-execution or yield<a name="line.1582"></a>
-<span class="sourceLineNo">1583</span>      // of this procedure. This may need more scrutiny and subsequent cleanup in future<a name="line.1583"></a>
-<span class="sourceLineNo">1584</span>      //<a name="line.1584"></a>
-<span class="sourceLineNo">1585</span>      // Commit the transaction even if a suspend (state may have changed). Note this append<a name="line.1585"></a>
-<span class="sourceLineNo">1586</span>      // can take a bunch of time to complete.<a name="line.1586"></a>
-<span class="sourceLineNo">1587</span>      updateStoreOnExec(procStack, procedure, subprocs);<a name="line.1587"></a>
-<span class="sourceLineNo">1588</span><a name="line.1588"></a>
-<span class="sourceLineNo">1589</span>      // if the store is not running we are aborting<a name="line.1589"></a>
-<span class="sourceLineNo">1590</span>      if (!store.isRunning()) {<a name="line.1590"></a>
-<span class="sourceLineNo">1591</span>        return;<a name="line.1591"></a>
-<span class="sourceLineNo">1592</span>      }<a name="line.1592"></a>
-<span class="sourceLineNo">1593</span>      // if the procedure is kind enough to pass the slot to someone else, yield<a name="line.1593"></a>
-<span class="sourceLineNo">1594</span>      if (procedure.isRunnable() &amp;&amp; !suspended &amp;&amp;<a name="line.1594"></a>
-<span class="sourceLineNo">1595</span>          procedure.isYieldAfterExecutionStep(getEnvironment())) {<a name="line.1595"></a>
-<span class="sourceLineNo">1596</span>        yieldProcedure(procedure);<a name="line.1596"></a>
-<span class="sourceLineNo">1597</span>        return;<a name="line.1597"></a>
-<span class="sourceLineNo">1598</span>      }<a name="line.1598"></a>
-<span class="sourceLineNo">1599</span><a name="line.1599"></a>
-<span class="sourceLineNo">1600</span>      assert (reExecute &amp;&amp; subprocs == null) || !reExecute;<a name="line.1600"></a>
-<span class="sourceLineNo">1601</span>    } while (reExecute);<a name="line.1601"></a>
-<span class="sourceLineNo">1602</span>    // Submit the new subprocedures<a name="line.1602"></a>
-<span class="sourceLineNo">1603</span>    if (subprocs != null &amp;&amp; !procedure.isFailed()) {<a name="line.1603"></a>
-<span class="sourceLineNo">1604</span>      submitChildrenProcedures(subprocs);<a name="line.1604"></a>
-<span class="sourceLineNo">1605</span>    }<a name="line.1605"></a>
-<span class="sourceLineNo">1606</span><a name="line.1606"></a>
-<span class="sourceLineNo">1607</span>    // we need to log the release lock operation before waking up the parent procedure, as there<a name="line.1607"></a>
-<span class="sourceLineNo">1608</span>    // could be race that the parent procedure may call updateStoreOnExec ahead of us and remove all<a name="line.1608"></a>
-<span class="sourceLineNo">1609</span>    // the sub procedures from store and cause problems...<a name="line.1609"></a>
-<span class="sourceLineNo">1610</span>    releaseLock(procedure, false);<a name="line.1610"></a>
-<span class="sourceLineNo">1611</span><a name="line.1611"></a>
-<span class="sourceLineNo">1612</span>    // if the procedure is complete and has a parent, count down the children latch.<a name="line.1612"></a>
-<span class="sourceLineNo">1613</span>    // If 'suspended', do nothing to change state -- let other threads handle unsuspend event.<a name="line.1613"></a>
-<span class="sourceLineNo">1614</span>    if (!suspended &amp;&amp; procedure.isFinished() &amp;&amp; procedure.hasParent()) {<a name="line.1614"></a>
-<span class="sourceLineNo">1615</span>      countDownChildren(procStack, procedure);<a name="line.1615"></a>
-<span class="sourceLineNo">1616</span>    }<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>  private Procedure&lt;TEnvironment&gt;[] initializeChildren(RootProcedureState&lt;TEnvironment&gt; procStack,<a name="line.1619"></a>
-<span class="sourceLineNo">1620</span>      Procedure&lt;TEnvironment&gt; procedure, Procedure&lt;TEnvironment&gt;[] subprocs) {<a name="line.1620"></a>
-<span class="sourceLineNo">1621</span>    assert subprocs != null : "expected subprocedures";<a name="line.1621"></a>
-<span class="sourceLineNo">1622</span>    final long rootProcId = getRootProcedureId(procedure);<a name="line.1622"></a>
-<span class="sourceLineNo">1623</span>    for (int i = 0; i &lt; subprocs.length; ++i) {<a name="line.1623"></a>
-<span class="sourceLineNo">1624</span>      Procedure&lt;TEnvironment&gt; subproc = subprocs[i];<a name="line.1624"></a>
-<span class="sourceLineNo">1625</span>      if (subproc == null) {<a name="line.1625"></a>
-<span class="sourceLineNo">1626</span>        String msg = "subproc[" + i + "] is null, aborting the procedure";<a name="line.1626"></a>
-<span class="sourceLineNo">1627</span>        procedure.setFailure(new RemoteProcedureException(msg,<a name="line.1627"></a>
-<span class="sourceLineNo">1628</span>          new IllegalArgumentIOException(msg)));<a name="line.1628"></a>
-<span class="sourceLineNo">1629</span>        return null;<a name="line.1629"></a>
-<span class="sourceLineNo">1630</span>      }<a name="line.1630"></a>
-<span class="sourceLineNo">1631</span><a name="line.1631"></a>
-<span class="sourceLineNo">1632</span>      assert subproc.getState() == ProcedureState.INITIALIZING : subproc;<a name="line.1632"></a>
-<span class="sourceLineNo">1633</span>      subproc.setParentProcId(procedure.getProcId());<a name="line.1633"></a>
-<span class="sourceLineNo">1634</span>      subproc.setRootProcId(rootProcId);<a name="line.1634"></a>
-<span class="sourceLineNo">1635</span>      subproc.setProcId(nextProcId());<a name="line.1635"></a>
-<span class="sourceLineNo">1636</span>      procStack.addSubProcedure(subproc);<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>    if (!procedure.isFailed()) {<a name="line.1639"></a>
-<span class="sourceLineNo">1640</span>      procedure.setChildrenLatch(subprocs.length);<a name="line.1640"></a>
-<span class="sourceLineNo">1641</span>      switch (procedure.getState()) {<a name="line.1641"></a>
-<span class="sourceLineNo">1642</span>        case RUNNABLE:<a name="line.1642"></a>
-<span class="sourceLineNo">1643</span>          procedure.setState(ProcedureState.WAITING);<a name="line.1643"></a>
-<span class="sourceLineNo">1644</span>          break;<a name="line.1644"></a>
-<span class="sourceLineNo">1645</span>        case WAITING_TIMEOUT:<a name="line.1645"></a>
-<span class="sourceLineNo">1646</span>          timeoutExecutor.add(procedure);<a name="line.1646"></a>
-<span class="sourceLineNo">1647</span>          break;<a name="line.1647"></a>
-<span class="sourceLineNo">1648</span>        default:<a name="line.1648"></a>
-<span class="sourceLineNo">1649</span>          break;<a name="line.1649"></a>
-<span class="sourceLineNo">1650</span>      }<a name="line.1650"></a>
-<span class="sourceLineNo">1651</span>    }<a name="line.1651"></a>
-<span class="sourceLineNo">1652</span>    return subprocs;<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>  private void submitChildrenProcedures(Procedure&lt;TEnvironment&gt;[] subprocs) {<a name="line.1655"></a>
-<span class="sourceLineNo">1656</span>    for (int i = 0; i &lt; subprocs.length; ++i) {<a name="line.1656"></a>
-<span class="sourceLineNo">1657</span>      Procedure&lt;TEnvironment&gt; subproc = subprocs[i];<a name="line.1657"></a>
-<span class="sourceLineNo">1658</span>      subproc.updateMetricsOnSubmit(getEnvironment());<a name="line.1658"></a>
-<span class="sourceLineNo">1659</span>      assert !procedures.containsKey(subproc.getProcId());<a name="line.1659"></a>
-<span class="sourceLineNo">1660</span>      procedures.put(subproc.getProcId(), subproc);<a name="line.1660"></a>
-<span class="sourceLineNo">1661</span>      scheduler.addFront(subproc);<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">1491</span>   */<a name="line.1491"></a>
+<span class="sourceLineNo">1492</span>  private void execProcedure(RootProcedureState&lt;TEnvironment&gt; procStack,<a name="line.1492"></a>
+<span class="sourceLineNo">1493</span>      Procedure&lt;TEnvironment&gt; procedure) {<a name="line.1493"></a>
+<span class="sourceLineNo">1494</span>    Preconditions.checkArgument(procedure.getState() == ProcedureState.RUNNABLE,<a name="line.1494"></a>
+<span class="sourceLineNo">1495</span>        "NOT RUNNABLE! " + procedure.toString());<a name="line.1495"></a>
+<span class="sourceLineNo">1496</span><a name="line.1496"></a>
+<span class="sourceLineNo">1497</span>    // Procedures can suspend themselves. They skip out by throwing a ProcedureSuspendedException.<a name="line.1497"></a>
+<span class="sourceLineNo">1498</span>    // The exception is caught below and then we hurry to the exit without disturbing state. The<a name="line.1498"></a>
+<span class="sourceLineNo">1499</span>    // idea is that the processing of this procedure will be unsuspended later by an external event<a name="line.1499"></a>
+<span class="sourceLineNo">1500</span>    // such the report of a region open.<a name="line.1500"></a>
+<span class="sourceLineNo">1501</span>    boolean suspended = false;<a name="line.1501"></a>
+<span class="sourceLineNo">1502</span><a name="line.1502"></a>
+<span class="sourceLineNo">1503</span>    // Whether to 're-' -execute; run through the loop again.<a name="line.1503"></a>
+<span class="sourceLineNo">1504</span>    boolean reExecute = false;<a name="line.1504"></a>
+<span class="sourceLineNo">1505</span><a name="line.1505"></a>
+<span class="sourceLineNo">1506</span>    Procedure&lt;TEnvironment&gt;[] subprocs = null;<a name="line.1506"></a>
+<span class="sourceLineNo">1507</span>    do {<a name="line.1507"></a>
+<span class="sourceLineNo">1508</span>      reExecute = false;<a name="line.1508"></a>
+<span class="sourceLineNo">1509</span>      try {<a name="line.1509"></a>
+<span class="sourceLineNo">1510</span>        subprocs = procedure.doExecute(getEnvironment());<a name="line.1510"></a>
+<span class="sourceLineNo">1511</span>        if (subprocs != null &amp;&amp; subprocs.length == 0) {<a name="line.1511"></a>
+<span class="sourceLineNo">1512</span>          subprocs = null;<a name="line.1512"></a>
+<span class="sourceLineNo">1513</span>        }<a name="line.1513"></a>
+<span class="sourceLineNo">1514</span>      } catch (ProcedureSuspendedException e) {<a name="line.1514"></a>
+<span class="sourceLineNo">1515</span>        LOG.trace("Suspend {}", procedure);<a name="line.1515"></a>
+<span class="sourceLineNo">1516</span>        suspended = true;<a name="line.1516"></a>
+<span class="sourceLineNo">1517</span>      } catch (ProcedureYieldException e) {<a name="line.1517"></a>
+<span class="sourceLineNo">1518</span>        LOG.trace("Yield {}", procedure, e);<a name="line.1518"></a>
+<span class="sourceLineNo">1519</span>        yieldProcedure(procedure);<a name="line.1519"></a>
+<span class="sourceLineNo">1520</span>        return;<a name="line.1520"></a>
+<span class="sourceLineNo">1521</span>      } catch (InterruptedException e) {<a name="line.1521"></a>
+<span class="sourceLineNo">1522</span>        LOG.trace("Yield interrupt {}", procedure, e);<a name="line.1522"></a>
+<span class="sourceLineNo">1523</span>        handleInterruptedException(procedure, e);<a name="line.1523"></a>
+<span class="sourceLineNo">1524</span>        yieldProcedure(procedure);<a name="line.1524"></a>
+<span class="sourceLineNo">1525</span>        return;<a name="line.1525"></a>
+<span class="sourceLineNo">1526</span>      } catch (Throwable e) {<a name="line.1526"></a>
+<span class="sourceLineNo">1527</span>        // Catch NullPointerExceptions or similar errors...<a name="line.1527"></a>
+<span class="sourceLineNo">1528</span>        String msg = "CODE-BUG: Uncaught runtime exception: " + procedure;<a name="line.1528"></a>
+<span class="sourceLineNo">1529</span>        LOG.error(msg, e);<a name="line.1529"></a>
+<span class="sourceLineNo">1530</span>        procedure.setFailure(new RemoteProcedureException(msg, e));<a name="line.1530"></a>
+<span class="sourceLineNo">1531</span>      }<a name="line.1531"></a>
+<span class="sourceLineNo">1532</span><a name="line.1532"></a>
+<span class="sourceLineNo">1533</span>      if (!procedure.isFailed()) {<a name="line.1533"></a>
+<span class="sourceLineNo">1534</span>        if (subprocs != null) {<a name="line.1534"></a>
+<span class="sourceLineNo">1535</span>          if (subprocs.length == 1 &amp;&amp; subprocs[0] == procedure) {<a name="line.1535"></a>
+<span class="sourceLineNo">1536</span>            // Procedure returned itself. Quick-shortcut for a state machine-like procedure;<a name="line.1536"></a>
+<span class="sourceLineNo">1537</span>            // i.e. we go around this loop again rather than go back out on the scheduler queue.<a name="line.1537"></a>
+<span class="sourceLineNo">1538</span>            subprocs = null;<a name="line.1538"></a>
+<span class="sourceLineNo">1539</span>            reExecute = true;<a name="line.1539"></a>
+<span class="sourceLineNo">1540</span>            LOG.trace("Short-circuit to next step on pid={}", procedure.getProcId());<a name="line.1540"></a>
+<span class="sourceLineNo">1541</span>          } else {<a name="line.1541"></a>
+<span class="sourceLineNo">1542</span>            // Yield the current procedure, and make the subprocedure runnable<a name="line.1542"></a>
+<span class="sourceLineNo">1543</span>            // subprocs may come back 'null'.<a name="line.1543"></a>
+<span class="sourceLineNo">1544</span>            subprocs = initializeChildren(procStack, procedure, subprocs);<a name="line.1544"></a>
+<span class="sourceLineNo">1545</span>            LOG.info("Initialized subprocedures=" +<a name="line.1545"></a>
+<span class="sourceLineNo">1546</span>              (subprocs == null? null:<a name="line.1546"></a>
+<span class="sourceLineNo">1547</span>                Stream.of(subprocs).map(e -&gt; "{" + e.toString() + "}").<a name="line.1547"></a>
+<span class="sourceLineNo">1548</span>                collect(Collectors.toList()).toString()));<a name="line.1548"></a>
+<span class="sourceLineNo">1549</span>          }<a name="line.1549"></a>
+<span class="sourceLineNo">1550</span>        } else if (procedure.getState() == ProcedureState.WAITING_TIMEOUT) {<a name="line.1550"></a>
+<span class="sourceLineNo">1551</span>          LOG.trace("Added to timeoutExecutor {}", procedure);<a name="line.1551"></a>
+<span class="sourceLineNo">1552</span>          timeoutExecutor.add(procedure);<a name="line.1552"></a>
+<span class="sourceLineNo">1553</span>        } else if (!suspended) {<a name="line.1553"></a>
+<span class="sourceLineNo">1554</span>          // No subtask, so we are done<a name="line.1554"></a>
+<span class="sourceLineNo">1555</span>          procedure.setState(ProcedureState.SUCCESS);<a name="line.1555"></a>
+<span class="sourceLineNo">1556</span>        }<a name="line.1556"></a>
+<span class="sourceLineNo">1557</span>      }<a name="line.1557"></a>
+<span class="sourceLineNo">1558</span><a name="line.1558"></a>
+<span class="sourceLineNo">1559</span>      // Add the procedure to the stack<a name="line.1559"></a>
+<span class="sourceLineNo">1560</span>      procStack.addRollbackStep(procedure);<a name="line.1560"></a>
+<span class="sourceLineNo">1561</span><a name="line.1561"></a>
+<span class="sourceLineNo">1562</span>      // allows to kill the executor before something is stored to the wal.<a name="line.1562"></a>
+<span class="sourceLineNo">1563</span>      // useful to test the procedure recovery.<a name="line.1563"></a>
+<span class="sourceLineNo">1564</span>      if (testing != null &amp;&amp; testing.shouldKillBeforeStoreUpdate(suspended)) {<a name="line.1564"></a>
+<span class="sourceLineNo">1565</span>        String msg = "TESTING: Kill before store update: " + procedure;<a name="line.1565"></a>
+<span class="sourceLineNo">1566</span>        LOG.debug(msg);<a name="line.1566"></a>
+<span class="sourceLineNo">1567</span>        stop();<a name="line.1567"></a>
+<span class="sourceLineNo">1568</span>        throw new RuntimeException(msg);<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>      // TODO: The code here doesn't check if store is running before persisting to the store as<a name="line.1571"></a>
+<span class="sourceLineNo">1572</span>      // it relies on the method call below to throw RuntimeException to wind up the stack and<a name="line.1572"></a>
+<span class="sourceLineNo">1573</span>      // executor thread to stop. The statement following the method call below seems to check if<a name="line.1573"></a>
+<span class="sourceLineNo">1574</span>      // store is not running, to prevent scheduling children procedures, re-execution or yield<a name="line.1574"></a>
+<span class="sourceLineNo">1575</span>      // of this procedure. This may need more scrutiny and subsequent cleanup in future<a name="line.1575"></a>
+<span class="sourceLineNo">1576</span>      //<a name="line.1576"></a>
+<span class="sourceLineNo">1577</span>      // Commit the transaction even if a suspend (state may have changed). Note this append<a name="line.1577"></a>
+<span class="sourceLineNo">1578</span>      // can take a bunch of time to complete.<a name="line.1578"></a>
+<span class="sourceLineNo">1579</span>      updateStoreOnExec(procStack, procedure, subprocs);<a name="line.1579"></a>
+<span class="sourceLineNo">1580</span><a name="line.1580"></a>
+<span class="sourceLineNo">1581</span>      // if the store is not running we are aborting<a name="line.1581"></a>
+<span class="sourceLineNo">1582</span>      if (!store.isRunning()) {<a name="line.1582"></a>
+<span class="sourceLineNo">1583</span>        return;<a name="line.1583"></a>
+<span class="sourceLineNo">1584</span>      }<a name="line.1584"></a>
+<span class="sourceLineNo">1585</span>      // if the procedure is kind enough to pass the slot to someone else, yield<a name="line.1585"></a>
+<span class="sourceLineNo">1586</span>      if (procedure.isRunnable() &amp;&amp; !suspended &amp;&amp;<a name="line.1586"></a>
+<span class="sourceLineNo">1587</span>          procedure.isYieldAfterExecutionStep(getEnvironment())) {<a name="line.1587"></a>
+<span class="sourceLineNo">1588</span>        yieldProcedure(procedure);<a name="line.1588"></a>
+<span class="sourceLineNo">1589</span>        return;<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>      assert (reExecute &amp;&amp; subprocs == null) || !reExecute;<a name="line.1592"></a>
+<span class="sourceLineNo">1593</span>    } while (reExecute);<a name="line.1593"></a>
+<span class="sourceLineNo">1594</span>    // Submit the new subprocedures<a name="line.1594"></a>
+<span class="sourceLineNo">1595</span>    if (subprocs != null &amp;&amp; !procedure.isFailed()) {<a name="line.1595"></a>
+<span class="sourceLineNo">1596</span>      submitChildrenProcedures(subprocs);<a name="line.1596"></a>
+<span class="sourceLineNo">1597</span>    }<a name="line.1597"></a>
+<span class="sourceLineNo">1598</span><a name="line.1598"></a>
+<span class="sourceLineNo">1599</span>    // we need to log the release lock operation before waking up the parent procedure, as there<a name="line.1599"></a>
+<span class="sourceLineNo">1600</span>    // could be race that the parent procedure may call updateStoreOnExec ahead of us and remove all<a name="line.1600"></a>
+<span class="sourceLineNo">1601</span>    // the sub procedures from store and cause problems...<a name="line.1601"></a>
+<span class="sourceLineNo">1602</span>    releaseLock(procedure, false);<a name="line.1602"></a>
+<span class="sourceLineNo">1603</span><a name="line.1603"></a>
+<span class="sourceLineNo">1604</span>    // if the procedure is complete and has a parent, count down the children latch.<a name="line.1604"></a>
+<span class="sourceLineNo">1605</span>    // If 'suspended', do nothing to change state -- let other threads handle unsuspend event.<a name="line.1605"></a>
+<span class="sourceLineNo">1606</span>    if (!suspended &amp;&amp; procedure.isFinished() &amp;&amp; procedure.hasParent()) {<a name="line.1606"></a>
+<span class="sourceLineNo">1607</span>      countDownChildren(procStack, procedure);<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><a name="line.1610"></a>
+<span class="sourceLineNo">1611</span>  private Procedure&lt;TEnvironment&gt;[] initializeChildren(RootProcedureState&lt;TEnvironment&gt; procStack,<a name="line.1611"></a>
+<span class="sourceLineNo">1612</span>      Procedure&lt;TEnvironment&gt; procedure, Procedure&lt;TEnvironment&gt;[] subprocs) {<a name="line.1612"></a>
+<span class="sourceLineNo">1613</span>    assert subprocs != null : "expected subprocedures";<a name="line.1613"></a>
+<span class="sourceLineNo">1614</span>    final long rootProcId = getRootProcedureId(procedure);<a name="line.1614"></a>
+<span class="sourceLineNo">1615</span>    for (int i = 0; i &lt; subprocs.length; ++i) {<a name="line.1615"></a>
+<span class="sourceLineNo">1616</span>      Procedure&lt;TEnvironment&gt; subproc = subprocs[i];<a name="line.1616"></a>
+<span class="sourceLineNo">1617</span>      if (subproc == null) {<a name="line.1617"></a>
+<span class="sourceLineNo">1618</span>        String msg = "subproc[" + i + "] is null, aborting the procedure";<a name="line.1618"></a>
+<span class="sourceLineNo">1619</span>        procedure.setFailure(new RemoteProcedureException(msg,<a name="line.1619"></a>
+<span class="sourceLineNo">1620</span>          new IllegalArgumentIOException(msg)));<a name="line.1620"></a>
+<span class="sourceLineNo">1621</span>        return null;<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>      assert subproc.getState() == ProcedureState.INITIALIZING : subproc;<a name="line.1624"></a>
+<span class="sourceLineNo">1625</span>      subproc.setParentProcId(procedure.getProcId());<a name="line.1625"></a>
+<span class="sourceLineNo">1626</span>      subproc.setRootProcId(rootProcId);<a name="line.1626"></a>
+<span class="sourceLineNo">1627</span>      subproc.setProcId(nextProcId());<a name="line.1627"></a>
+<span class="sourceLineNo">1628</span>      procStack.addSubProcedure(subproc);<a name="line.1628"></a>
+<span class="sourceLineNo">1629</span>    }<a name="line.1629"></a>
+<span class="sourceLineNo">1630</span><a name="line.1630"></a>
+<span class="sourceLineNo">1631</span>    if (!procedure.isFailed()) {<a name="line.1631"></a>
+<span class="sourceLineNo">1632</span>      procedure.setChildrenLatch(subprocs.length);<a name="line.1632"></a>
+<span class="sourceLineNo">1633</span>      switch (procedure.getState()) {<a name="line.1633"></a>
+<span class="sourceLineNo">1634</span>        case RUNNABLE:<a name="line.1634"></a>
+<span class="sourceLineNo">1635</span>          procedure.setState(ProcedureState.WAITING);<a name="line.1635"></a>
+<span class="sourceLineNo">1636</span>          break;<a name="line.1636"></a>
+<span class="sourceLineNo">1637</span>        case WAITING_TIMEOUT:<a name="line.1637"></a>
+<span class="sourceLineNo">1638</span>          timeoutExecutor.add(procedure);<a name="line.1638"></a>
+<span class="sourceLineNo">1639</span>          break;<a name="line.1639"></a>
+<span class="sourceLineNo">1640</span>        default:<a name="line.1640"></a>
+<span class="sourceLineNo">1641</span>          break;<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>    return subprocs;<a name="line.1644"></a>
+<span class="sourceLineNo">1645</span>  }<a name="line.1645"></a>
+<span class="sourceLineNo">1646</span><a name="line.1646"></a>
+<span class="sourceLineNo">1647</span>  private void submitChildrenProcedures(Procedure&lt;TEnvironment&gt;[] subprocs) {<a name="line.1647"></a>
+<span class="sourceLineNo">1648</span>    for (int i = 0; i &lt; subprocs.length; ++i) {<a name="line.1648"></a>
+<span class="sourceLineNo">1649</span>      Procedure&lt;TEnvironment&gt; subproc = subprocs[i];<a name="line.1649"></a>
+<span class="sourceLineNo">1650</span>      subproc.updateMetricsOnSubmit(getEnvironment());<a name="line.1650"></a>
+<span class="sourceLineNo">1651</span>      assert !procedures.containsKey(subproc.getProcId());<a name="line.1651"></a>
+<span class="sourceLineNo">1652</span>      procedures.put(subproc.getProcId(), subproc);<a name="line.1652"></a>
+<span class="sourceLineNo">1653</span>      scheduler.addFront(subproc);<a name="line.1653"></a>
+<span class="sourceLineNo">1654</span>    }<a name="line.1654"></a>
+<span class="sourceLineNo">1655</span>  }<a name="line.1655"></a>
+<span class="sourceLineNo">1656</span><a name="line.1656"></a>
+<span class="sourceLineNo">1657</span>  private void countDownChildren(RootProcedureState&lt;TEnvironment&gt; procStack,<a name="line.1657"></a>
+<span class="sourceLineNo">1658</span>      Procedure&lt;TEnvironment&gt; procedure) {<a name="line.1658"></a>
+<span class="sourceLineNo">1659</span>    Procedure&lt;TEnvironment&gt; parent = procedures.get(procedure.getParentProcId());<a name="line.1659"></a>
+<span class="sourceLineNo">1660</span>    if (parent == null) {<a name="line.1660"></a>
+<span class="sourceLineNo">1661</span>      assert procStack.isRollingback();<a name="line.1661"></a>
+<span class="sourceLineNo">1662</span>      return;<a name="line.1662"></a>
+<span class="sourceLineNo">1663</span>    }<a name="line.1663"></a>
 <span class="sourceLineNo">1664</span><a name="line.1664"></a>
-<span class="sourceLineNo">1665</span>  private void countDownChildren(RootProcedureState&lt;TEnvironment&gt; procStack,<a name="line.1665"></a>
-<span class="sourceLineNo">1666</span>      Procedure&lt;TEnvironment&gt; procedure) {<a name="line.1666"></a>
-<span class="sourceLineNo">1667</span>    Procedure&lt;TEnvironment&gt; parent = procedures.get(procedure.getParentProcId());<a name="line.1667"></a>
-<span class="sourceLineNo">1668</span>    if (parent == null) {<a name="line.1668"></a>
-<span class="sourceLineNo">1669</span>      assert procStack.isRollingback();<a name="line.1669"></a>
-<span class="sourceLineNo">1670</span>      return;<a name="line.1670"></a>
-<span class="sourceLineNo">1671</span>    }<a name="line.1671"></a>
-<span class="sourceLineNo">1672</span><a name="line.1672"></a>
-<span class="sourceLineNo">1673</span>    // If this procedure is the last child awake the parent procedure<a name="line.1673"></a>
-<span class="sourceLineNo">1674</span>    if (parent.tryRunnable()) {<a name="line.1674"></a>
-<span class="sourceLineNo">1675</span>      // If we succeeded in making the parent runnable -- i.e. all of its<a name="line.1675"></a>
-<span class="sourceLineNo">1676</span>      // children have completed, move parent to front of the queue.<a name="line.1676"></a>
-<span class="sourceLineNo">1677</span>      store.update(parent);<a name="line.1677"></a>
-<span class="sourceLineNo">1678</span>      scheduler.addFront(parent);<a name="line.1678"></a>
-<span class="sourceLineNo">1679</span>      LOG.info("Finished subprocedure(s) of " + parent + "; resume parent processing.");<a name="line.1679"></a>
-<span class="sourceLineNo">1680</span>      return;<a name="line.1680"></a>
-<span class="sourceLineNo">1681</span>    }<a name="line.1681"></a>
-<span class="sourceLineNo">1682</span>  }<a name="line.1682"></a>
-<span class="sourceLineNo">1683</span><a name="line.1683"></a>
-<span class="sourceLineNo">1684</span>  private void updateStoreOnExec(RootProcedureState&lt;TEnvironment&gt; procStack,<a name="line.1684"></a>
-<span class="sourceLineNo">1685</span>      Procedure&lt;TEnvironment&gt; procedure, Procedure&lt;TEnvironment&gt;[] subprocs) {<a name="line.1685"></a>
-<span class="sourceLineNo">1686</span>    if (subprocs != null &amp;&amp; !procedure.isFailed()) {<a name="line.1686"></a>
-<span class="sourceLineNo">1687</span>      if (LOG.isTraceEnabled()) {<a name="line.1687"></a>
-<span class="sourceLineNo">1688</span>        LOG.trace("Stored " + procedure + ", children " + Arrays.toString(subprocs));<a name="line.1688"></a>
-<span class="sourceLineNo">1689</span>      }<a name="line.1689"></a>
-<span class="sourceLineNo">1690</span>      store.insert(procedure, subprocs);<a name="line.1690"></a>
-<span class="sourceLineNo">1691</span>    } else {<a name="line.1691"></a>
-<span class="sourceLineNo">1692</span>      LOG.trace("Store update {}", procedure);<a name="line.1692"></a>
-<span class="sourceLineNo">1693</span>      if (procedure.isFinished() &amp;&amp; !procedure.hasParent()) {<a name="line.1693"></a>
-<span class="sourceLineNo">1694</span>        // remove child procedures<a name="line.1694"></a>
-<span class="sourceLineNo">1695</span>        final long[] childProcIds = procStack.getSubprocedureIds();<a name="line.1695"></a>
-<span class="sourceLineNo">1696</span>        if (childProcIds != null) {<a name="line.1696"></a>
-<span class="sourceLineNo">1697</span>          store.delete(procedure, childProcIds);<a name="line.1697"></a>
-<span class="sourceLineNo">1698</span>          for (int i = 0; i &lt; childProcIds.length; ++i) {<a name="line.1698"></a>
-<span class="sourceLineNo">1699</span>            procedures.remove(childProcIds[i]);<a name="line.1699"></a>
-<span class="sourceLineNo">1700</span>          }<a name="line.1700"></a>
-<span class="sourceLineNo">1701</span>        } else {<a name="line.1701"></a>
-<span class="sourceLineNo">1702</span>          store.update(procedure);<a name="line.1702"></a>
-<span class="sourceLineNo">1703</span>        }<a name="line.1703"></a>
-<span class="sourceLineNo">1704</span>      } else {<a name="line.1704"></a>
-<span class="sourceLineNo">1705</span>        store.update(procedure);<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>  }<a name="line.1708"></a>
-<span class="sourceLineNo">1709</span><a name="line.1709"></a>
-<span class="sourceLineNo">1710</span>  private void handleInterruptedException(Procedure&lt;TEnvironment&gt; proc, InterruptedException e) {<a name="line.1710"></a>
-<span class="sourceLineNo">1711</span>    LOG.trace("Interrupt during {}. suspend and retry it later.", proc, e);<a name="line.1711"></a>
-<span class="sourceLineNo">1712</span>    // NOTE: We don't call Thread.currentThread().interrupt()<a name="line.1712"></a>
-<span class="sourceLineNo">1713</span>    // because otherwise all the subsequent calls e.g. Thread.sleep() will throw<a name="line.1713"></a>
-<span class="sourceLineNo">1714</span>    // the InterruptedException. If the master is going down, we will be notified<a name="line.1714"></a>
-<span class="sourceLineNo">1715</span>    // and the executor/store will be stopped.<a name="line.1715"></a>
-<span class="sourceLineNo">1716</span>    // (The interrupted procedure will be retried on the next run)<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>  private void execCompletionCleanup(Procedure&lt;TEnvironment&gt; proc) {<a name="line.1719"></a>
-<span class="sourceLineNo">1720</span>    final TEnvironment env = getEnvironment();<a name="line.1720"></a>
-<span class="sourceLineNo">1721</span>    if (proc.hasLock()) {<a name="line.1721"></a>
-<span class="sourceLineNo">1722</span>      LOG.warn("Usually this should not happen, we will release the lock before if the procedure" +<a name="line.1722"></a>
-<span class="sourceLineNo">1723</span>        " is finished, even if the holdLock is true, arrive here means we have some holes where" +<a name="line.1723"></a>
-<span class="sourceLineNo">1724</span>        " we do not release the lock. And the releaseLock below may fail since the procedure may" +<a name="line.1724"></a>
-<span class="sourceLineNo">1725</span>        " have already been deleted from the procedure store.");<a name="line.1725"></a>
-<span class="sourceLineNo">1726</span>      releaseLock(proc, true);<a name="line.1726"></a>
-<span class="sourceLineNo">1727</span>    }<a name="line.1727"></a>
-<span class="sourceLineNo">1728</span>    try {<a name="line.1728"></a>
-<span class="sourceLineNo">1729</span>      proc.completionCleanup(env);<a name="line.1729"></a>
-<span class="sourceLineNo">1730</span>    } catch (Throwable e) {<a name="line.1730"></a>
-<span class="sourceLineNo">1731</span>      // Catch NullPointerExceptions or similar errors...<a name="line.1731"></a>
-<span class="sourceLineNo">1732</span>      LOG.error("CODE-BUG: uncatched runtime exception for procedure: " + proc, e);<a name="line.1732"></a>
-<span class="sourceLineNo">1733</span>    }<a name="line.1733"></a>
-<span class="sourceLineNo">1734</span>  }<a name="line.1734"></a>
-<span class="sourceLineNo">1735</span><a name="line.1735"></a>
-<span class="sourceLineNo">1736</span>  private void procedureFinished(Procedure&lt;TEnvironment&gt; proc) {<a name="line.1736"></a>
-<span class="sourceLineNo">1737</span>    // call the procedure completion cleanup handler<a name="line.1737"></a>
-<span class="sourceLineNo">1738</span>    execCompletionCleanup(proc);<a name="line.1738"></a>
-<span class="sourceLineNo">1739</span><a name="line.1739"></a>
-<span class="sourceLineNo">1740</span>    CompletedProcedureRetainer&lt;TEnvironment&gt; retainer = new CompletedProcedureRetainer&lt;&gt;(proc);<a name="line.1740"></a>
-<span class="sourceLineNo">1741</span><a name="line.1741"></a>
-<span class="sourceLineNo">1742</span>    // update the executor internal state maps<a name="line.1742"></a>
-<span class="sourceLineNo">1743</span>    if (!proc.shouldWaitClientAck(getEnvironment())) {<a name="line.1743"></a>
-<span class="sourceLineNo">1744</span>      retainer.setClientAckTime(0);<a name="line.1744"></a>
-<span class="sourceLineNo">1745</span>    }<a name="line.1745"></a>
-<span class="sourceLineNo">1746</span><a name="line.1746"></a>
-<span class="sourceLineNo">1747</span>    completed.put(proc.getProcId(), retainer);<a name="line.1747"></a>
-<span class="sourceLineNo">1748</span>    rollbackStack.remove(proc.getProcId());<a name="line.1748"></a>
-<span class="sourceLineNo">1749</span>    procedures.remove(proc.getProcId());<a name="line.1749"></a>
+<span class="sourceLineNo">1665</span>    // If this procedure is the last child awake the parent procedure<a name="line.1665"></a>
+<span class="sourceLineNo">1666</span>    if (parent.tryRunnable()) {<a name="line.1666"></a>
+<span class="sourceLineNo">1667</span>      // If we succeeded in making the parent runnable -- i.e. all of its<a name="line.1667"></a>
+<span class="sourceLineNo">1668</span>      // children have completed, move parent to front of the queue.<a name="line.1668"></a>
+<span class="sourceLineNo">1669</span>      store.update(parent);<a name="line.1669"></a>
+<span class="sourceLineNo">1670</span>      scheduler.addFront(parent);<a name="line.1670"></a>
+<span class="sourceLineNo">1671</span>      LOG.info("Finished subprocedure(s) of " + parent + "; resume parent processing.");<a name="line.1671"></a>
+<span class="sourceLineNo">1672</span>      return;<a name="line.1672"></a>
+<span class="sourceLineNo">1673</span>    }<a name="line.1673"></a>
+<span class="sourceLineNo">1674</span>  }<a name="line.1674"></a>
+<span class="sourceLineNo">1675</span><a name="line.1675"></a>
+<span class="sourceLineNo">1676</span>  private void updateStoreOnExec(RootProcedureState&lt;TEnvironment&gt; procStack,<a name="line.1676"></a>
+<span class="sourceLineNo">1677</span>      Procedure&lt;TEnvironment&gt; procedure, Procedure&lt;TEnvironment&gt;[] subprocs) {<a name="line.1677"></a>
+<span class="sourceLineNo">1678</span>    if (subprocs != null &amp;&amp; !procedure.isFailed()) {<a name="line.1678"></a>
+<span class="sourceLineNo">1679</span>      if (LOG.isTraceEnabled()) {<a name="line.1679"></a>
+<span class="sourceLineNo">1680</span>        LOG.trace("Stored " + procedure + ", children " + Arrays.toString(subprocs));<a name="line.1680"></a>
+<span class="sourceLineNo">1681</span>      }<a name="line.1681"></a>
+<span class="sourceLineNo">1682</span>      store.insert(procedure, subprocs);<a name="line.1682"></a>
+<span class="sourceLineNo">1683</span>    } else {<a name="line.1683"></a>
+<span class="sourceLineNo">1684</span>      LOG.trace("Store update {}", procedure);<a name="line.1684"></a>
+<span class="sourceLineNo">1685</span>      if (procedure.isFinished() &amp;&amp; !procedure.hasParent()) {<a name="line.1685"></a>
+<span class="sourceLineNo">1686</span>        // remove child procedures<a name="line.1686"></a>
+<span class="sourceLineNo">1687</span>        final long[] childProcIds = procStack.getSubprocedureIds();<a name="line.1687"></a>
+<span class="sourceLineNo">1688</span>        if (childProcIds != null) {<a name="line.1688"></a>
+<span class="sourceLineNo">1689</span>          store.delete(procedure, childProcIds);<a name="line.1689"></a>
+<span class="sourceLineNo">1690</span>          for (int i = 0; i &lt; childProcIds.length; ++i) {<a name="line.1690"></a>
+<span class="sourceLineNo">1691</span>            procedures.remove(childProcIds[i]);<a name="line.1691"></a>
+<span class="sourceLineNo">1692</span>          }<a name="line.1692"></a>
+<span class="sourceLineNo">1693</span>        } else {<a name="line.1693"></a>
+<span class="sourceLineNo">1694</span>          store.update(procedure);<a name="line.1694"></a>
+<span class="sourceLineNo">1695</span>        }<a name="line.1695"></a>
+<span class="sourceLineNo">1696</span>      } else {<a name="line.1696"></a>
+<span class="sourceLineNo">1697</span>        store.update(procedure);<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>  }<a name="line.1700"></a>
+<span class="sourceLineNo">1701</span><a name="line.1701"></a>
+<span class="sourceLineNo">1702</span>  private void handleInterruptedException(Procedure&lt;TEnvironment&gt; proc, InterruptedException e) {<a name="line.1702"></a>
+<span class="sourceLineNo">1703</span>    LOG.trace("Interrupt during {}. suspend and retry it later.", proc, e);<a name="line.1703"></a>
+<span class="sourceLineNo">1704</span>    // NOTE: We don't call Thread.currentThread().interrupt()<a name="line.1704"></a>
+<span class="sourceLineNo">1705</span>    // because otherwise all the subsequent calls e.g. Thread.sleep() will throw<a name="line.1705"></a>
+<span class="sourceLineNo">1706</span>    // the InterruptedException. If the master is going down, we will be notified<a name="line.1706"></a>
+<span class="sourceLineNo">1707</span>    // and the executor/store will be stopped.<a name="line.1707"></a>
+<span class="sourceLineNo">1708</span>    // (The interrupted procedure will be retried on the next run)<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>  private void execCompletionCleanup(Procedure&lt;TEnvironment&gt; proc) {<a name="line.1711"></a>
+<span class="sourceLineNo">1712</span>    final TEnvironment env = getEnvironment();<a name="line.1712"></a>
+<span class="sourceLineNo">1713</span>    if (proc.hasLock()) {<a name="line.1713"></a>
+<span class="sourceLineNo">1714</span>      LOG.warn("Usually this should not happen, we will release the lock before if the procedure" +<a name="line.1714"></a>
+<span class="sourceLineNo">1715</span>        " is finished, even if the holdLock is true, arrive here means we have some holes where" +<a name="line.1715"></a>
+<span class="sourceLineNo">1716</span>        " we do not release the lock. And the releaseLock below may fail since the procedure may" +<a name="line.1716"></a>
+<span class="sourceLineNo">1717</span>        " have already been deleted from the procedure store.");<a name="line.1717"></a>
+<span class="sourceLineNo">1718</span>      releaseLock(proc, true);<a name="line.1718"></a>
+<span class="sourceLineNo">1719</span>    }<a name="line.1719"></a>
+<span class="sourceLineNo">1720</span>    try {<a name="line.1720"></a>
+<span class="sourceLineNo">1721</span>      proc.completionCleanup(env);<a name="line.1721"></a>
+<span class="sourceLineNo">1722</span>    } catch (Throwable e) {<a name="line.1722"></a>
+<span class="sourceLineNo">1723</span>      // Catch NullPointerExceptions or similar errors...<a name="line.1723"></a>
+<span class="sourceLineNo">1724</span>      LOG.error("CODE-BUG: uncatched runtime exception for procedure: " + proc, e);<a name="line.1724"></a>
+<span class="sourceLineNo">1725</span>    }<a name="line.1725"></a>
+<span class="sourceLineNo">1726</span>  }<a name="line.1726"></a>
+<span class="sourceLineNo">1727</span><a name="line.1727"></a>
+<span class="sourceLineNo">1728</span>  private void procedureFinished(Procedure&lt;TEnvironment&gt; proc) {<a name="line.1728"></a>
+<span class="sourceLineNo">1729</span>    // call the procedure completion cleanup handler<a name="line.1729"></a>
+<span class="sourceLineNo">1730</span>    execCompletionCleanup(proc);<a name="line.1730"></a>
+<span class="sourceLineNo">1731</span><a name="line.1731"></a>
+<span class="sourceLineNo">1732</span>    CompletedProcedureRetainer&lt;TEnvironment&gt; retainer = new CompletedProcedureRetainer&lt;&gt;(proc);<a name="line.1732"></a>
+<span class="sourceLineNo">1733</span><a name="line.1733"></a>
+<span class="sourceLineNo">1734</span>    // update the executor internal state maps<a name="line.1734"></a>
+<span class="sourceLineNo">1735</span>    if (!proc.shouldWaitClientAck(getEnvironment())) {<a name="line.1735"></a>
+<span class="sourceLineNo">1736</span>      retainer.setClientAckTime(0);<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>    completed.put(proc.getProcId(), retainer);<a name="line.1739"></a>
+<span class="sourceLineNo">1740</span>    rollbackStack.remove(proc.getProcId());<a name="line.1740"></a>
+<span class="sourceLineNo">1741</span>    procedures.remove(proc.getProcId());<a name="line.1741"></a>
+<span class="sourceLineNo">1742</span><a name="line.1742"></a>
+<span class="sourceLineNo">1743</span>    // call the runnableSet completion cleanup handler<a name="line.1743"></a>
+<span class="sourceLineNo">1744</span>    try {<a name="line.1744"></a>
+<span class="sourceLineNo">1745</span>      scheduler.completionCleanup(proc);<a name="line.1745"></a>
+<span class="sourceLineNo">1746</span>    } catch (Throwable e) {<a name="line.1746"></a>
+<span class="sourceLineNo">1747</span>      // Catch NullPointerExceptions or similar errors...<a name="line.1747"></a>
+<span class="sourceLineNo">1748</span>      LOG.error("CODE-BUG: uncatched runtime exception for completion cleanup: {}", proc, e);<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>    // call the runnableSet completion cleanup handler<a name="line.1751"></a>
-<span class="sourceLineNo">1752</span>    try {<a name="line.1752"></a>
-<span class="sourceLineNo">1753</span>      scheduler.completionCleanup(proc);<a name="line.1753"></a>
-<span class="sourceLineNo">1754</span>    } catch (Throwable e) {<a name="line.1754"></a>
-<span class="sourceLineNo">1755</span>      // Catch NullPointerExceptions or similar errors...<a name="line.1755"></a>
-<span class="sourceLineNo">1756</span>      LOG.error("CODE-BUG: uncatched runtime exception for completion cleanup: {}", proc, e);<a name="line.1756"></a>
-<span class="sourceLineNo">1757</span>    }<a name="line.1757"></a>
+<span class="sourceLineNo">1751</span>    // Notify the listeners<a name="line.1751"></a>
+<span class="sourceLineNo">1752</span>    sendProcedureFinishedNotification(proc.getProcId());<a name="line.1752"></a>
+<span class="sourceLineNo">1753</span>  }<a name="line.1753"></a>
+<span class="sourceLineNo">1754</span><a name="line.1754"></a>
+<span class="sourceLineNo">1755</span>  RootProcedureState&lt;TEnvironment&gt; getProcStack(long rootProcId) {<a name="line.1755"></a>
+<span class="sourceLineNo">1756</span>    return rollbackStack.get(rootProcId);<a name="line.1756"></a>
+<span class="sourceLineNo">1757</span>  }<a name="line.1757"></a>
 <span class="sourceLineNo">1758</span><a name="line.1758"></a>
-<span class="sourceLineNo">1759</span>    // Notify the listeners<a name="line.1759"></a>
-<span class="sourceLineNo">1760</span>    sendProcedureFinishedNotification(proc.getProcId());<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>  RootProcedureState&lt;TEnvironment&gt; getProcStack(long rootProcId) {<a name="line.1763"></a>
-<span class="sourceLineNo">1764</span>    return rollbackStack.get(rootProcId);<a name="line.1764"></a>
-<span class="sourceLineNo">1765</span>  }<a name="line.1765"></a>
-<span class="sourceLineNo">1766</span><a name="line.1766"></a>
-<span class="sourceLineNo">1767</span>  // ==========================================================================<a name="line.1767"></a>
-<span class="sourceLineNo">1768</span>  //  Worker Thread<a name="line.1768"></a>
-<span class="sourceLineNo">1769</span>  // ==========================================================================<a name="line.1769"></a>
-<span class="sourceLineNo">1770</span>  private class WorkerThread extends StoppableThread {<a name="line.1770"></a>
-<span class="sourceLineNo">1771</span>    private final AtomicLong executionStartTime = new AtomicLong(Long.MAX_VALUE);<a name="line.1771"></a>
-<span class="sourceLineNo">1772</span>    private volatile Procedure&lt;TEnvironment&gt; activeProcedure;<a name="line.1772"></a>
-<span class="sourceLineNo">1773</span><a name="line.1773"></a>
-<span class="sourceLineNo">1774</span>    public WorkerThread(ThreadGroup group) {<a name="line.1774"></a>
-<span class="sourceLineNo">1775</span>      this(group, "PEWorker-");<a name="line.1775"></a>
-<span class="sourceLineNo">1776</span>    }<a name="line.1776"></a>
-<span class="sourceLineNo">1777</span><a name="line.1777"></a>
-<span class="sourceLineNo">1778</span>    protected WorkerThread(ThreadGroup group, String prefix) {<a name="line.1778"></a>
-<span class="sourceLineNo">1779</span>      super(group, prefix + workerId.incrementAndGet());<a name="line.1779"></a>
-<span class="sourceLineNo">1780</span>      setDaemon(true);<a name="line.1780"></a>
-<span class="sourceLineNo">1781</span>    }<a name="line.1781"></a>
-<span class="sourceLineNo">1782</span><a name="line.1782"></a>
-<span class="sourceLineNo">1783</span>    @Override<a name="line.1783"></a>
-<span class="sourceLineNo">1784</span>    public void sendStopSignal() {<a name="line.1784"></a>
-<span class="sourceLineNo">1785</span>      scheduler.signalAll();<a name="line.1785"></a>
-<span class="sourceLineNo">1786</span>    }<a name="line.1786"></a>
-<span class="sourceLineNo">1787</span><a name="line.1787"></a>
-<span class="sourceLineNo">1788</span>    @Override<a name="line.1788"></a>
-<span class="sourceLineNo">1789</span>    public void run() {<a name="line.1789"></a>
-<span class="sourceLineNo">1790</span>      long lastUpdate = EnvironmentEdgeManager.currentTime();<a name="line.1790"></a>
-<span class="sourceLineNo">1791</span>      try {<a name="line.1791"></a>
-<span class="sourceLineNo">1792</span>        while (isRunning() &amp;&amp; keepAlive(lastUpdate)) {<a name="line.1792"></a>
-<span class="sourceLineNo">1793</span>          Procedure&lt;TEnvironment&gt; proc = scheduler.poll(keepAliveTime, TimeUnit.MILLISECONDS);<a name="line.1793"></a>
-<span class="sourceLineNo">1794</span>          if (proc == null) {<a name="line.1794"></a>
-<span class="sourceLineNo">1795</span>            continue;<a name="line.1795"></a>
-<span class="sourceLineNo">1796</span>          }<a name="line.1796"></a>
-<span class="sourceLineNo">1797</span>          this.activeProcedure = proc;<a name="line.1797"></a>
-<span class="sourceLineNo">1798</span>          int activeCount = activeExecutorCount.incrementAndGet();<a name="line.1798"></a>
-<span class="sourceLineNo">1799</span>          int runningCount = store.setRunningProcedureCount(activeCount);<a name="line.1799"></a>
-<span class="sourceLineNo">1800</span>          LOG.trace("Execute pid={} runningCount={}, activeCount={}", proc.getProcId(),<a name="line.1800"></a>
-<span class="sourceLineNo">1801</span>            runningCount, activeCount);<a name="line.1801"></a>
-<span class="sourceLineNo">1802</span>          executionStartTime.set(EnvironmentEdgeManager.currentTime());<a name="line.1802"></a>
-<span class="sourceLineNo">1803</span>          IdLock.Entry lockEntry = procExecutionLock.getLockEntry(proc.getProcId());<a name="line.1803"></a>
-<span class="sourceLineNo">1804</span>          try {<a name="line.1804"></a>
-<span class="sourceLineNo">1805</span>            executeProcedure(proc);<a name="line.1805"></a>
-<span class="sourceLineNo">1806</span>          } catch (AssertionError e) {<a name="line.1806"></a>
-<span class="sourceLineNo">1807</span>            LOG.info("ASSERT pid=" + proc.getProcId(), e);<a name="line.1807"></a>
-<span class="sourceLineNo">1808</span>            throw e;<a name="line.1808"></a>
-<span class="sourceLineNo">1809</span>          } finally {<a name="line.1809"></a>
-<span class="sourceLineNo">1810</span>            procExecutionLock.releaseLockEntry(lockEntry);<a name="line.1810"></a>
-<span class="sourceLineNo">1811</span>            activeCount = activeExecutorCount.decrementAndGet();<a name="line.1811"></a>
-<span class="sourceLineNo">1812</span>            runningCount = store.setRunningProcedureCount(activeCount);<a name="line.1812"></a>
-<span class="sourceLineNo">1813</span>            LOG.trace("Halt pid={} runningCount={}, activeCount={}", proc.getProcId(),<a name="line.1813"></a>
-<span class="sourceLineNo">1814</span>              runningCount, activeCount);<a name="line.1814"></a>
-<span class="sourceLineNo">1815</span>            this.activeProcedure = null;<a name="line.1815"></a>
-<span class="sourceLineNo">1816</span>            lastUpdate = EnvironmentEdgeManager.currentTime();<a name="line.1816"></a>
-<span class="sourceLineNo">1817</span>            executionStartTime.set(Long.MAX_VALUE);<a name="line.1817"></a>
-<span class="sourceLineNo">1818</span>          }<a name="line.1818"></a>
-<span class="sourceLineNo">1819</span>        }<a name="line.1819"></a>
-<span class="sourceLineNo">1820</span>      } catch (Throwable t) {<a name="line.1820"></a>
-<span class="sourceLineNo">1821</span>        LOG.warn("Worker terminating UNNATURALLY {}", this.activeProcedure, t);<a name="line.1821"></a>
-<span class="sourceLineNo">1822</span>      } finally {<a name="line.1822"></a>
-<span class="sourceLineNo">1823</span>        LOG.trace("Worker terminated.");<a name="line.1823"></a>
-<span class="sourceLineNo">1824</span>      }<a name="line.1824"></a>
-<span class="sourceLineNo">1825</span>      workerThreads.remove(this);<a name="line.1825"></a>
-<span class="sourceLineNo">1826</span>    }<a name="line.1826"></a>
-<span class="sourceLineNo">1827</span><a name="line.1827"></a>
-<span class="sourceLineNo">1828</span>    @Override<a name="line.1828"></a>
-<span class="sourceLineNo">1829</span>    public String toString() {<a name="line.1829"></a>
-<span class="sourceLineNo">1830</span>      Procedure&lt;?&gt; p = this.activeProcedure;<a name="line.1830"></a>
-<span class="sourceLineNo">1831</span>      return getName() + "(pid=" + (p == null? Procedure.NO_PROC_ID: p.getProcId() + ")");<a name="line.1831"></a>
-<span class="sourceLineNo">1832</span>    }<a name="line.1832"></a>
-<span class="sourceLineNo">1833</span><a name="line.1833"></a>
-<span class="sourceLineNo">1834</span>    /**<a name="line.1834"></a>
-<span class="sourceLineNo">1835</span>     * @return the time since the current procedure is running<a name="line.1835"></a>
-<span class="sourceLineNo">1836</span>     */<a name="line.1836"></a>
-<span class="sourceLineNo">1837</span>    public long getCurrentRunTime() {<a name="line.1837"></a>
-<span class="sourceLineNo">1838</span>      return EnvironmentEdgeManager.currentTime() - executionStartTime.get();<a name="line.1838"></a>
-<span class="sourceLineNo">1839</span>    }<a name="line.1839"></a>
-<span class="sourceLineNo">1840</span><a name="line.1840"></a>
-<span class="sourceLineNo">1841</span>    // core worker never timeout<a name="line.1841"></a>
-<span class="sourceLineNo">1842</span>    protected boolean keepAlive(long lastUpdate) {<a name="line.1842"></a>
-<span class="sourceLineNo">1843

<TRUNCATED>

Mime
View raw message