hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From git-site-r...@apache.org
Subject [05/18] hbase-site git commit: Published site at 02f5f171f51b7ed801355c8acdcfc4ad47c23a3e.
Date Tue, 30 Oct 2018 14:54:31 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/2752c924/devapidocs/src-html/org/apache/hadoop/hbase/master/assignment/AssignmentManager.RegionInTransitionStat.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/master/assignment/AssignmentManager.RegionInTransitionStat.html b/devapidocs/src-html/org/apache/hadoop/hbase/master/assignment/AssignmentManager.RegionInTransitionStat.html
index 801dc55..5d3c5eb 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/master/assignment/AssignmentManager.RegionInTransitionStat.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/master/assignment/AssignmentManager.RegionInTransitionStat.html
@@ -1369,556 +1369,557 @@
 <span class="sourceLineNo">1361</span>    return 0;<a name="line.1361"></a>
 <span class="sourceLineNo">1362</span>  }<a name="line.1362"></a>
 <span class="sourceLineNo">1363</span><a name="line.1363"></a>
-<span class="sourceLineNo">1364</span>  public void submitServerCrash(final ServerName serverName, final boolean shouldSplitWal) {<a name="line.1364"></a>
+<span class="sourceLineNo">1364</span>  public long submitServerCrash(final ServerName serverName, final boolean shouldSplitWal) {<a name="line.1364"></a>
 <span class="sourceLineNo">1365</span>    boolean carryingMeta = isCarryingMeta(serverName);<a name="line.1365"></a>
 <span class="sourceLineNo">1366</span>    ProcedureExecutor&lt;MasterProcedureEnv&gt; procExec = this.master.getMasterProcedureExecutor();<a name="line.1366"></a>
-<span class="sourceLineNo">1367</span>    procExec.submitProcedure(new ServerCrashProcedure(procExec.getEnvironment(), serverName,<a name="line.1367"></a>
-<span class="sourceLineNo">1368</span>      shouldSplitWal, carryingMeta));<a name="line.1368"></a>
-<span class="sourceLineNo">1369</span>    LOG.debug("Added=" + serverName +<a name="line.1369"></a>
-<span class="sourceLineNo">1370</span>      " to dead servers, submitted shutdown handler to be executed meta=" + carryingMeta);<a name="line.1370"></a>
-<span class="sourceLineNo">1371</span>  }<a name="line.1371"></a>
-<span class="sourceLineNo">1372</span><a name="line.1372"></a>
-<span class="sourceLineNo">1373</span>  public void offlineRegion(final RegionInfo regionInfo) {<a name="line.1373"></a>
-<span class="sourceLineNo">1374</span>    // TODO used by MasterRpcServices<a name="line.1374"></a>
-<span class="sourceLineNo">1375</span>    RegionStateNode node = regionStates.getRegionStateNode(regionInfo);<a name="line.1375"></a>
-<span class="sourceLineNo">1376</span>    if (node != null) {<a name="line.1376"></a>
-<span class="sourceLineNo">1377</span>      node.offline();<a name="line.1377"></a>
-<span class="sourceLineNo">1378</span>    }<a name="line.1378"></a>
-<span class="sourceLineNo">1379</span>  }<a name="line.1379"></a>
-<span class="sourceLineNo">1380</span><a name="line.1380"></a>
-<span class="sourceLineNo">1381</span>  public void onlineRegion(final RegionInfo regionInfo, final ServerName serverName) {<a name="line.1381"></a>
-<span class="sourceLineNo">1382</span>    // TODO used by TestSplitTransactionOnCluster.java<a name="line.1382"></a>
-<span class="sourceLineNo">1383</span>  }<a name="line.1383"></a>
-<span class="sourceLineNo">1384</span><a name="line.1384"></a>
-<span class="sourceLineNo">1385</span>  public Map&lt;ServerName, List&lt;RegionInfo&gt;&gt; getSnapShotOfAssignment(<a name="line.1385"></a>
-<span class="sourceLineNo">1386</span>      final Collection&lt;RegionInfo&gt; regions) {<a name="line.1386"></a>
-<span class="sourceLineNo">1387</span>    return regionStates.getSnapShotOfAssignment(regions);<a name="line.1387"></a>
-<span class="sourceLineNo">1388</span>  }<a name="line.1388"></a>
-<span class="sourceLineNo">1389</span><a name="line.1389"></a>
-<span class="sourceLineNo">1390</span>  // ============================================================================================<a name="line.1390"></a>
-<span class="sourceLineNo">1391</span>  //  TODO: UTILS/HELPERS?<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>   * Used by the client (via master) to identify if all regions have the schema updates<a name="line.1394"></a>
-<span class="sourceLineNo">1395</span>   *<a name="line.1395"></a>
-<span class="sourceLineNo">1396</span>   * @param tableName<a name="line.1396"></a>
-<span class="sourceLineNo">1397</span>   * @return Pair indicating the status of the alter command (pending/total)<a name="line.1397"></a>
-<span class="sourceLineNo">1398</span>   * @throws IOException<a name="line.1398"></a>
-<span class="sourceLineNo">1399</span>   */<a name="line.1399"></a>
-<span class="sourceLineNo">1400</span>  public Pair&lt;Integer, Integer&gt; getReopenStatus(TableName tableName) {<a name="line.1400"></a>
-<span class="sourceLineNo">1401</span>    if (isTableDisabled(tableName)) return new Pair&lt;Integer, Integer&gt;(0, 0);<a name="line.1401"></a>
-<span class="sourceLineNo">1402</span><a name="line.1402"></a>
-<span class="sourceLineNo">1403</span>    final List&lt;RegionState&gt; states = regionStates.getTableRegionStates(tableName);<a name="line.1403"></a>
-<span class="sourceLineNo">1404</span>    int ritCount = 0;<a name="line.1404"></a>
-<span class="sourceLineNo">1405</span>    for (RegionState regionState: states) {<a name="line.1405"></a>
-<span class="sourceLineNo">1406</span>      if (!regionState.isOpened()) ritCount++;<a name="line.1406"></a>
-<span class="sourceLineNo">1407</span>    }<a name="line.1407"></a>
-<span class="sourceLineNo">1408</span>    return new Pair&lt;Integer, Integer&gt;(ritCount, states.size());<a name="line.1408"></a>
-<span class="sourceLineNo">1409</span>  }<a name="line.1409"></a>
-<span class="sourceLineNo">1410</span><a name="line.1410"></a>
-<span class="sourceLineNo">1411</span>  // ============================================================================================<a name="line.1411"></a>
-<span class="sourceLineNo">1412</span>  //  TODO: Region State In Transition<a name="line.1412"></a>
-<span class="sourceLineNo">1413</span>  // ============================================================================================<a name="line.1413"></a>
-<span class="sourceLineNo">1414</span>  public boolean hasRegionsInTransition() {<a name="line.1414"></a>
-<span class="sourceLineNo">1415</span>    return regionStates.hasRegionsInTransition();<a name="line.1415"></a>
-<span class="sourceLineNo">1416</span>  }<a name="line.1416"></a>
-<span class="sourceLineNo">1417</span><a name="line.1417"></a>
-<span class="sourceLineNo">1418</span>  public List&lt;RegionStateNode&gt; getRegionsInTransition() {<a name="line.1418"></a>
-<span class="sourceLineNo">1419</span>    return regionStates.getRegionsInTransition();<a name="line.1419"></a>
-<span class="sourceLineNo">1420</span>  }<a name="line.1420"></a>
-<span class="sourceLineNo">1421</span><a name="line.1421"></a>
-<span class="sourceLineNo">1422</span>  public List&lt;RegionInfo&gt; getAssignedRegions() {<a name="line.1422"></a>
-<span class="sourceLineNo">1423</span>    return regionStates.getAssignedRegions();<a name="line.1423"></a>
-<span class="sourceLineNo">1424</span>  }<a name="line.1424"></a>
-<span class="sourceLineNo">1425</span><a name="line.1425"></a>
-<span class="sourceLineNo">1426</span>  public RegionInfo getRegionInfo(final byte[] regionName) {<a name="line.1426"></a>
-<span class="sourceLineNo">1427</span>    final RegionStateNode regionState = regionStates.getRegionStateNodeFromName(regionName);<a name="line.1427"></a>
-<span class="sourceLineNo">1428</span>    return regionState != null ? regionState.getRegionInfo() : null;<a name="line.1428"></a>
-<span class="sourceLineNo">1429</span>  }<a name="line.1429"></a>
-<span class="sourceLineNo">1430</span><a name="line.1430"></a>
-<span class="sourceLineNo">1431</span>  // ============================================================================================<a name="line.1431"></a>
-<span class="sourceLineNo">1432</span>  //  Expected states on region state transition.<a name="line.1432"></a>
-<span class="sourceLineNo">1433</span>  //  Notice that there is expected states for transiting to OPENING state, this is because SCP.<a name="line.1433"></a>
-<span class="sourceLineNo">1434</span>  //  See the comments in regionOpening method for more details.<a name="line.1434"></a>
-<span class="sourceLineNo">1435</span>  // ============================================================================================<a name="line.1435"></a>
-<span class="sourceLineNo">1436</span>  private static final State[] STATES_EXPECTED_ON_OPEN = {<a name="line.1436"></a>
-<span class="sourceLineNo">1437</span>    State.OPENING, // Normal case<a name="line.1437"></a>
-<span class="sourceLineNo">1438</span>    State.OPEN // Retrying<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>  private static final State[] STATES_EXPECTED_ON_CLOSING = {<a name="line.1441"></a>
-<span class="sourceLineNo">1442</span>    State.OPEN, // Normal case<a name="line.1442"></a>
-<span class="sourceLineNo">1443</span>    State.CLOSING, // Retrying<a name="line.1443"></a>
-<span class="sourceLineNo">1444</span>    State.SPLITTING, // Offline the split parent<a name="line.1444"></a>
-<span class="sourceLineNo">1445</span>    State.MERGING // Offline the merge parents<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 static final State[] STATES_EXPECTED_ON_CLOSED = {<a name="line.1448"></a>
-<span class="sourceLineNo">1449</span>    State.CLOSING, // Normal case<a name="line.1449"></a>
-<span class="sourceLineNo">1450</span>    State.CLOSED // Retrying<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>  // This is for manually scheduled region assign, can add other states later if we find out other<a name="line.1453"></a>
-<span class="sourceLineNo">1454</span>  // usages<a name="line.1454"></a>
-<span class="sourceLineNo">1455</span>  private static final State[] STATES_EXPECTED_ON_ASSIGN = { State.CLOSED, State.OFFLINE };<a name="line.1455"></a>
-<span class="sourceLineNo">1456</span><a name="line.1456"></a>
-<span class="sourceLineNo">1457</span>  // We only allow unassign or move a region which is in OPEN state.<a name="line.1457"></a>
-<span class="sourceLineNo">1458</span>  private static final State[] STATES_EXPECTED_ON_UNASSIGN_OR_MOVE = { State.OPEN };<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>  //  Region Status update<a name="line.1461"></a>
-<span class="sourceLineNo">1462</span>  //  Should only be called in TransitRegionStateProcedure<a name="line.1462"></a>
-<span class="sourceLineNo">1463</span>  // ============================================================================================<a name="line.1463"></a>
-<span class="sourceLineNo">1464</span>  private void transitStateAndUpdate(RegionStateNode regionNode, RegionState.State newState,<a name="line.1464"></a>
-<span class="sourceLineNo">1465</span>      RegionState.State... expectedStates) throws IOException {<a name="line.1465"></a>
-<span class="sourceLineNo">1466</span>    RegionState.State state = regionNode.getState();<a name="line.1466"></a>
-<span class="sourceLineNo">1467</span>    regionNode.transitionState(newState, expectedStates);<a name="line.1467"></a>
-<span class="sourceLineNo">1468</span>    boolean succ = false;<a name="line.1468"></a>
-<span class="sourceLineNo">1469</span>    try {<a name="line.1469"></a>
-<span class="sourceLineNo">1470</span>      regionStateStore.updateRegionLocation(regionNode);<a name="line.1470"></a>
-<span class="sourceLineNo">1471</span>      succ = true;<a name="line.1471"></a>
-<span class="sourceLineNo">1472</span>    } finally {<a name="line.1472"></a>
-<span class="sourceLineNo">1473</span>      if (!succ) {<a name="line.1473"></a>
-<span class="sourceLineNo">1474</span>        // revert<a name="line.1474"></a>
-<span class="sourceLineNo">1475</span>        regionNode.setState(state);<a name="line.1475"></a>
-<span class="sourceLineNo">1476</span>      }<a name="line.1476"></a>
-<span class="sourceLineNo">1477</span>    }<a name="line.1477"></a>
-<span class="sourceLineNo">1478</span>  }<a name="line.1478"></a>
-<span class="sourceLineNo">1479</span><a name="line.1479"></a>
-<span class="sourceLineNo">1480</span>  // should be called within the synchronized block of RegionStateNode<a name="line.1480"></a>
-<span class="sourceLineNo">1481</span>  void regionOpening(RegionStateNode regionNode) throws IOException {<a name="line.1481"></a>
-<span class="sourceLineNo">1482</span>    // As in SCP, for performance reason, there is no TRSP attached with this region, we will not<a name="line.1482"></a>
-<span class="sourceLineNo">1483</span>    // update the region state, which means that the region could be in any state when we want to<a name="line.1483"></a>
-<span class="sourceLineNo">1484</span>    // assign it after a RS crash. So here we do not pass the expectedStates parameter.<a name="line.1484"></a>
-<span class="sourceLineNo">1485</span>    transitStateAndUpdate(regionNode, State.OPENING);<a name="line.1485"></a>
-<span class="sourceLineNo">1486</span>    regionStates.addRegionToServer(regionNode);<a name="line.1486"></a>
-<span class="sourceLineNo">1487</span>    // update the operation count metrics<a name="line.1487"></a>
-<span class="sourceLineNo">1488</span>    metrics.incrementOperationCounter();<a name="line.1488"></a>
-<span class="sourceLineNo">1489</span>  }<a name="line.1489"></a>
-<span class="sourceLineNo">1490</span><a name="line.1490"></a>
-<span class="sourceLineNo">1491</span>  // should be called within the synchronized block of RegionStateNode.<a name="line.1491"></a>
-<span class="sourceLineNo">1492</span>  // The parameter 'giveUp' means whether we will try to open the region again, if it is true, then<a name="line.1492"></a>
-<span class="sourceLineNo">1493</span>  // we will persist the FAILED_OPEN state into hbase:meta.<a name="line.1493"></a>
-<span class="sourceLineNo">1494</span>  void regionFailedOpen(RegionStateNode regionNode, boolean giveUp) throws IOException {<a name="line.1494"></a>
-<span class="sourceLineNo">1495</span>    RegionState.State state = regionNode.getState();<a name="line.1495"></a>
-<span class="sourceLineNo">1496</span>    ServerName regionLocation = regionNode.getRegionLocation();<a name="line.1496"></a>
-<span class="sourceLineNo">1497</span>    if (giveUp) {<a name="line.1497"></a>
-<span class="sourceLineNo">1498</span>      regionNode.setState(State.FAILED_OPEN);<a name="line.1498"></a>
-<span class="sourceLineNo">1499</span>      regionNode.setRegionLocation(null);<a name="line.1499"></a>
-<span class="sourceLineNo">1500</span>      boolean succ = false;<a name="line.1500"></a>
-<span class="sourceLineNo">1501</span>      try {<a name="line.1501"></a>
-<span class="sourceLineNo">1502</span>        regionStateStore.updateRegionLocation(regionNode);<a name="line.1502"></a>
-<span class="sourceLineNo">1503</span>        succ = true;<a name="line.1503"></a>
-<span class="sourceLineNo">1504</span>      } finally {<a name="line.1504"></a>
-<span class="sourceLineNo">1505</span>        if (!succ) {<a name="line.1505"></a>
-<span class="sourceLineNo">1506</span>          // revert<a name="line.1506"></a>
-<span class="sourceLineNo">1507</span>          regionNode.setState(state);<a name="line.1507"></a>
-<span class="sourceLineNo">1508</span>          regionNode.setRegionLocation(regionLocation);<a name="line.1508"></a>
-<span class="sourceLineNo">1509</span>        }<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>    if (regionLocation != null) {<a name="line.1512"></a>
-<span class="sourceLineNo">1513</span>      regionStates.removeRegionFromServer(regionLocation, regionNode);<a name="line.1513"></a>
-<span class="sourceLineNo">1514</span>    }<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>  // should be called within the synchronized block of RegionStateNode<a name="line.1517"></a>
-<span class="sourceLineNo">1518</span>  void regionOpened(RegionStateNode regionNode) throws IOException {<a name="line.1518"></a>
-<span class="sourceLineNo">1519</span>    // TODO: OPENING Updates hbase:meta too... we need to do both here and there?<a name="line.1519"></a>
-<span class="sourceLineNo">1520</span>    // That is a lot of hbase:meta writing.<a name="line.1520"></a>
-<span class="sourceLineNo">1521</span>    transitStateAndUpdate(regionNode, State.OPEN, STATES_EXPECTED_ON_OPEN);<a name="line.1521"></a>
-<span class="sourceLineNo">1522</span>    RegionInfo hri = regionNode.getRegionInfo();<a name="line.1522"></a>
-<span class="sourceLineNo">1523</span>    if (isMetaRegion(hri)) {<a name="line.1523"></a>
-<span class="sourceLineNo">1524</span>      // Usually we'd set a table ENABLED at this stage but hbase:meta is ALWAYs enabled, it<a name="line.1524"></a>
-<span class="sourceLineNo">1525</span>      // can't be disabled -- so skip the RPC (besides... enabled is managed by TableStateManager<a name="line.1525"></a>
-<span class="sourceLineNo">1526</span>      // which is backed by hbase:meta... Avoid setting ENABLED to avoid having to update state<a name="line.1526"></a>
-<span class="sourceLineNo">1527</span>      // on table that contains state.<a name="line.1527"></a>
-<span class="sourceLineNo">1528</span>      setMetaAssigned(hri, true);<a name="line.1528"></a>
-<span class="sourceLineNo">1529</span>    }<a name="line.1529"></a>
-<span class="sourceLineNo">1530</span>    regionStates.addRegionToServer(regionNode);<a name="line.1530"></a>
-<span class="sourceLineNo">1531</span>    regionStates.removeFromFailedOpen(hri);<a name="line.1531"></a>
-<span class="sourceLineNo">1532</span>  }<a name="line.1532"></a>
-<span class="sourceLineNo">1533</span><a name="line.1533"></a>
-<span class="sourceLineNo">1534</span>  // should be called within the synchronized block of RegionStateNode<a name="line.1534"></a>
-<span class="sourceLineNo">1535</span>  void regionClosing(RegionStateNode regionNode) throws IOException {<a name="line.1535"></a>
-<span class="sourceLineNo">1536</span>    transitStateAndUpdate(regionNode, State.CLOSING, STATES_EXPECTED_ON_CLOSING);<a name="line.1536"></a>
-<span class="sourceLineNo">1537</span><a name="line.1537"></a>
-<span class="sourceLineNo">1538</span>    RegionInfo hri = regionNode.getRegionInfo();<a name="line.1538"></a>
-<span class="sourceLineNo">1539</span>    // Set meta has not initialized early. so people trying to create/edit tables will wait<a name="line.1539"></a>
-<span class="sourceLineNo">1540</span>    if (isMetaRegion(hri)) {<a name="line.1540"></a>
-<span class="sourceLineNo">1541</span>      setMetaAssigned(hri, false);<a name="line.1541"></a>
-<span class="sourceLineNo">1542</span>    }<a name="line.1542"></a>
-<span class="sourceLineNo">1543</span>    regionStates.addRegionToServer(regionNode);<a name="line.1543"></a>
-<span class="sourceLineNo">1544</span>    // update the operation count metrics<a name="line.1544"></a>
-<span class="sourceLineNo">1545</span>    metrics.incrementOperationCounter();<a name="line.1545"></a>
-<span class="sourceLineNo">1546</span>  }<a name="line.1546"></a>
-<span class="sourceLineNo">1547</span><a name="line.1547"></a>
-<span class="sourceLineNo">1548</span>  // should be called within the synchronized block of RegionStateNode<a name="line.1548"></a>
-<span class="sourceLineNo">1549</span>  // The parameter 'normally' means whether we are closed cleanly, if it is true, then it means that<a name="line.1549"></a>
-<span class="sourceLineNo">1550</span>  // we are closed due to a RS crash.<a name="line.1550"></a>
-<span class="sourceLineNo">1551</span>  void regionClosed(RegionStateNode regionNode, boolean normally) throws IOException {<a name="line.1551"></a>
-<span class="sourceLineNo">1552</span>    RegionState.State state = regionNode.getState();<a name="line.1552"></a>
-<span class="sourceLineNo">1553</span>    ServerName regionLocation = regionNode.getRegionLocation();<a name="line.1553"></a>
-<span class="sourceLineNo">1554</span>    if (normally) {<a name="line.1554"></a>
-<span class="sourceLineNo">1555</span>      regionNode.transitionState(State.CLOSED, STATES_EXPECTED_ON_CLOSED);<a name="line.1555"></a>
-<span class="sourceLineNo">1556</span>    } else {<a name="line.1556"></a>
-<span class="sourceLineNo">1557</span>      // For SCP<a name="line.1557"></a>
-<span class="sourceLineNo">1558</span>      regionNode.transitionState(State.ABNORMALLY_CLOSED);<a name="line.1558"></a>
-<span class="sourceLineNo">1559</span>    }<a name="line.1559"></a>
-<span class="sourceLineNo">1560</span>    regionNode.setRegionLocation(null);<a name="line.1560"></a>
-<span class="sourceLineNo">1561</span>    boolean succ = false;<a name="line.1561"></a>
-<span class="sourceLineNo">1562</span>    try {<a name="line.1562"></a>
-<span class="sourceLineNo">1563</span>      regionStateStore.updateRegionLocation(regionNode);<a name="line.1563"></a>
-<span class="sourceLineNo">1564</span>      succ = true;<a name="line.1564"></a>
-<span class="sourceLineNo">1565</span>    } finally {<a name="line.1565"></a>
-<span class="sourceLineNo">1566</span>      if (!succ) {<a name="line.1566"></a>
-<span class="sourceLineNo">1567</span>        // revert<a name="line.1567"></a>
-<span class="sourceLineNo">1568</span>        regionNode.setState(state);<a name="line.1568"></a>
-<span class="sourceLineNo">1569</span>        regionNode.setRegionLocation(regionLocation);<a name="line.1569"></a>
-<span class="sourceLineNo">1570</span>      }<a name="line.1570"></a>
-<span class="sourceLineNo">1571</span>    }<a name="line.1571"></a>
-<span class="sourceLineNo">1572</span>    if (regionLocation != null) {<a name="line.1572"></a>
-<span class="sourceLineNo">1573</span>      regionNode.setLastHost(regionLocation);<a name="line.1573"></a>
-<span class="sourceLineNo">1574</span>      regionStates.removeRegionFromServer(regionLocation, regionNode);<a name="line.1574"></a>
-<span class="sourceLineNo">1575</span>    }<a name="line.1575"></a>
-<span class="sourceLineNo">1576</span>  }<a name="line.1576"></a>
-<span class="sourceLineNo">1577</span><a name="line.1577"></a>
-<span class="sourceLineNo">1578</span>  public void markRegionAsSplit(final RegionInfo parent, final ServerName serverName,<a name="line.1578"></a>
-<span class="sourceLineNo">1579</span>      final RegionInfo daughterA, final RegionInfo daughterB) throws IOException {<a name="line.1579"></a>
-<span class="sourceLineNo">1580</span>    // Update hbase:meta. Parent will be marked offline and split up in hbase:meta.<a name="line.1580"></a>
-<span class="sourceLineNo">1581</span>    // The parent stays in regionStates until cleared when removed by CatalogJanitor.<a name="line.1581"></a>
-<span class="sourceLineNo">1582</span>    // Update its state in regionStates to it shows as offline and split when read<a name="line.1582"></a>
-<span class="sourceLineNo">1583</span>    // later figuring what regions are in a table and what are not: see<a name="line.1583"></a>
-<span class="sourceLineNo">1584</span>    // regionStates#getRegionsOfTable<a name="line.1584"></a>
-<span class="sourceLineNo">1585</span>    final RegionStateNode node = regionStates.getOrCreateRegionStateNode(parent);<a name="line.1585"></a>
-<span class="sourceLineNo">1586</span>    node.setState(State.SPLIT);<a name="line.1586"></a>
-<span class="sourceLineNo">1587</span>    final RegionStateNode nodeA = regionStates.getOrCreateRegionStateNode(daughterA);<a name="line.1587"></a>
-<span class="sourceLineNo">1588</span>    nodeA.setState(State.SPLITTING_NEW);<a name="line.1588"></a>
-<span class="sourceLineNo">1589</span>    final RegionStateNode nodeB = regionStates.getOrCreateRegionStateNode(daughterB);<a name="line.1589"></a>
-<span class="sourceLineNo">1590</span>    nodeB.setState(State.SPLITTING_NEW);<a name="line.1590"></a>
-<span class="sourceLineNo">1591</span><a name="line.1591"></a>
-<span class="sourceLineNo">1592</span>    regionStateStore.splitRegion(parent, daughterA, daughterB, serverName);<a name="line.1592"></a>
-<span class="sourceLineNo">1593</span>    if (shouldAssignFavoredNodes(parent)) {<a name="line.1593"></a>
-<span class="sourceLineNo">1594</span>      List&lt;ServerName&gt; onlineServers = this.master.getServerManager().getOnlineServersList();<a name="line.1594"></a>
-<span class="sourceLineNo">1595</span>      ((FavoredNodesPromoter)getBalancer()).<a name="line.1595"></a>
-<span class="sourceLineNo">1596</span>          generateFavoredNodesForDaughter(onlineServers, parent, daughterA, daughterB);<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><a name="line.1599"></a>
-<span class="sourceLineNo">1600</span>  /**<a name="line.1600"></a>
-<span class="sourceLineNo">1601</span>   * When called here, the merge has happened. The two merged regions have been<a name="line.1601"></a>
-<span class="sourceLineNo">1602</span>   * unassigned and the above markRegionClosed has been called on each so they have been<a name="line.1602"></a>
-<span class="sourceLineNo">1603</span>   * disassociated from a hosting Server. The merged region will be open after this call. The<a name="line.1603"></a>
-<span class="sourceLineNo">1604</span>   * merged regions are removed from hbase:meta below&gt; Later they are deleted from the filesystem<a name="line.1604"></a>
-<span class="sourceLineNo">1605</span>   * by the catalog janitor running against hbase:meta. It notices when the merged region no<a name="line.1605"></a>
-<span class="sourceLineNo">1606</span>   * longer holds references to the old regions.<a name="line.1606"></a>
-<span class="sourceLineNo">1607</span>   */<a name="line.1607"></a>
-<span class="sourceLineNo">1608</span>  public void markRegionAsMerged(final RegionInfo child, final ServerName serverName,<a name="line.1608"></a>
-<span class="sourceLineNo">1609</span>      final RegionInfo mother, final RegionInfo father) throws IOException {<a name="line.1609"></a>
-<span class="sourceLineNo">1610</span>    final RegionStateNode node = regionStates.getOrCreateRegionStateNode(child);<a name="line.1610"></a>
-<span class="sourceLineNo">1611</span>    node.setState(State.MERGED);<a name="line.1611"></a>
-<span class="sourceLineNo">1612</span>    regionStates.deleteRegion(mother);<a name="line.1612"></a>
-<span class="sourceLineNo">1613</span>    regionStates.deleteRegion(father);<a name="line.1613"></a>
-<span class="sourceLineNo">1614</span>    regionStateStore.mergeRegions(child, mother, father, serverName);<a name="line.1614"></a>
-<span class="sourceLineNo">1615</span>    if (shouldAssignFavoredNodes(child)) {<a name="line.1615"></a>
-<span class="sourceLineNo">1616</span>      ((FavoredNodesPromoter)getBalancer()).<a name="line.1616"></a>
-<span class="sourceLineNo">1617</span>        generateFavoredNodesForMergedRegion(child, mother, father);<a name="line.1617"></a>
-<span class="sourceLineNo">1618</span>    }<a name="line.1618"></a>
-<span class="sourceLineNo">1619</span>  }<a name="line.1619"></a>
-<span class="sourceLineNo">1620</span><a name="line.1620"></a>
-<span class="sourceLineNo">1621</span>  /*<a name="line.1621"></a>
-<span class="sourceLineNo">1622</span>   * Favored nodes should be applied only when FavoredNodes balancer is configured and the region<a name="line.1622"></a>
-<span class="sourceLineNo">1623</span>   * belongs to a non-system table.<a name="line.1623"></a>
-<span class="sourceLineNo">1624</span>   */<a name="line.1624"></a>
-<span class="sourceLineNo">1625</span>  private boolean shouldAssignFavoredNodes(RegionInfo region) {<a name="line.1625"></a>
-<span class="sourceLineNo">1626</span>    return this.shouldAssignRegionsWithFavoredNodes &amp;&amp;<a name="line.1626"></a>
-<span class="sourceLineNo">1627</span>        FavoredNodesManager.isFavoredNodeApplicable(region);<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>  // ============================================================================================<a name="line.1630"></a>
-<span class="sourceLineNo">1631</span>  //  Assign Queue (Assign/Balance)<a name="line.1631"></a>
-<span class="sourceLineNo">1632</span>  // ============================================================================================<a name="line.1632"></a>
-<span class="sourceLineNo">1633</span>  private final ArrayList&lt;RegionStateNode&gt; pendingAssignQueue = new ArrayList&lt;RegionStateNode&gt;();<a name="line.1633"></a>
-<span class="sourceLineNo">1634</span>  private final ReentrantLock assignQueueLock = new ReentrantLock();<a name="line.1634"></a>
-<span class="sourceLineNo">1635</span>  private final Condition assignQueueFullCond = assignQueueLock.newCondition();<a name="line.1635"></a>
-<span class="sourceLineNo">1636</span><a name="line.1636"></a>
-<span class="sourceLineNo">1637</span>  /**<a name="line.1637"></a>
-<span class="sourceLineNo">1638</span>   * Add the assign operation to the assignment queue.<a name="line.1638"></a>
-<span class="sourceLineNo">1639</span>   * The pending assignment operation will be processed,<a name="line.1639"></a>
-<span class="sourceLineNo">1640</span>   * and each region will be assigned by a server using the balancer.<a name="line.1640"></a>
-<span class="sourceLineNo">1641</span>   */<a name="line.1641"></a>
-<span class="sourceLineNo">1642</span>  protected void queueAssign(final RegionStateNode regionNode) {<a name="line.1642"></a>
-<span class="sourceLineNo">1643</span>    regionNode.getProcedureEvent().suspend();<a name="line.1643"></a>
-<span class="sourceLineNo">1644</span><a name="line.1644"></a>
-<span class="sourceLineNo">1645</span>    // TODO: quick-start for meta and the other sys-tables?<a name="line.1645"></a>
-<span class="sourceLineNo">1646</span>    assignQueueLock.lock();<a name="line.1646"></a>
-<span class="sourceLineNo">1647</span>    try {<a name="line.1647"></a>
-<span class="sourceLineNo">1648</span>      pendingAssignQueue.add(regionNode);<a name="line.1648"></a>
-<span class="sourceLineNo">1649</span>      if (regionNode.isSystemTable() ||<a name="line.1649"></a>
-<span class="sourceLineNo">1650</span>          pendingAssignQueue.size() == 1 ||<a name="line.1650"></a>
-<span class="sourceLineNo">1651</span>          pendingAssignQueue.size() &gt;= assignDispatchWaitQueueMaxSize) {<a name="line.1651"></a>
-<span class="sourceLineNo">1652</span>        assignQueueFullCond.signal();<a name="line.1652"></a>
-<span class="sourceLineNo">1653</span>      }<a name="line.1653"></a>
-<span class="sourceLineNo">1654</span>    } finally {<a name="line.1654"></a>
-<span class="sourceLineNo">1655</span>      assignQueueLock.unlock();<a name="line.1655"></a>
-<span class="sourceLineNo">1656</span>    }<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 startAssignmentThread() {<a name="line.1659"></a>
-<span class="sourceLineNo">1660</span>    // Get Server Thread name. Sometimes the Server is mocked so may not implement HasThread.<a name="line.1660"></a>
-<span class="sourceLineNo">1661</span>    // For example, in tests.<a name="line.1661"></a>
-<span class="sourceLineNo">1662</span>    String name = master instanceof HasThread? ((HasThread)master).getName():<a name="line.1662"></a>
-<span class="sourceLineNo">1663</span>        master.getServerName().toShortString();<a name="line.1663"></a>
-<span class="sourceLineNo">1664</span>    assignThread = new Thread(name) {<a name="line.1664"></a>
-<span class="sourceLineNo">1665</span>      @Override<a name="line.1665"></a>
-<span class="sourceLineNo">1666</span>      public void run() {<a name="line.1666"></a>
-<span class="sourceLineNo">1667</span>        while (isRunning()) {<a name="line.1667"></a>
-<span class="sourceLineNo">1668</span>          processAssignQueue();<a name="line.1668"></a>
-<span class="sourceLineNo">1669</span>        }<a name="line.1669"></a>
-<span class="sourceLineNo">1670</span>        pendingAssignQueue.clear();<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>    assignThread.setDaemon(true);<a name="line.1673"></a>
-<span class="sourceLineNo">1674</span>    assignThread.start();<a name="line.1674"></a>
-<span class="sourceLineNo">1675</span>  }<a name="line.1675"></a>
-<span class="sourceLineNo">1676</span><a name="line.1676"></a>
-<span class="sourceLineNo">1677</span>  private void stopAssignmentThread() {<a name="line.1677"></a>
-<span class="sourceLineNo">1678</span>    assignQueueSignal();<a name="line.1678"></a>
-<span class="sourceLineNo">1679</span>    try {<a name="line.1679"></a>
-<span class="sourceLineNo">1680</span>      while (assignThread.isAlive()) {<a name="line.1680"></a>
-<span class="sourceLineNo">1681</span>        assignQueueSignal();<a name="line.1681"></a>
-<span class="sourceLineNo">1682</span>        assignThread.join(250);<a name="line.1682"></a>
-<span class="sourceLineNo">1683</span>      }<a name="line.1683"></a>
-<span class="sourceLineNo">1684</span>    } catch (InterruptedException e) {<a name="line.1684"></a>
-<span class="sourceLineNo">1685</span>      LOG.warn("join interrupted", e);<a name="line.1685"></a>
-<span class="sourceLineNo">1686</span>      Thread.currentThread().interrupt();<a name="line.1686"></a>
-<span class="sourceLineNo">1687</span>    }<a name="line.1687"></a>
-<span class="sourceLineNo">1688</span>  }<a name="line.1688"></a>
-<span class="sourceLineNo">1689</span><a name="line.1689"></a>
-<span class="sourceLineNo">1690</span>  private void assignQueueSignal() {<a name="line.1690"></a>
-<span class="sourceLineNo">1691</span>    assignQueueLock.lock();<a name="line.1691"></a>
-<span class="sourceLineNo">1692</span>    try {<a name="line.1692"></a>
-<span class="sourceLineNo">1693</span>      assignQueueFullCond.signal();<a name="line.1693"></a>
-<span class="sourceLineNo">1694</span>    } finally {<a name="line.1694"></a>
-<span class="sourceLineNo">1695</span>      assignQueueLock.unlock();<a name="line.1695"></a>
-<span class="sourceLineNo">1696</span>    }<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>  @edu.umd.cs.findbugs.annotations.SuppressWarnings("WA_AWAIT_NOT_IN_LOOP")<a name="line.1699"></a>
-<span class="sourceLineNo">1700</span>  private HashMap&lt;RegionInfo, RegionStateNode&gt; waitOnAssignQueue() {<a name="line.1700"></a>
-<span class="sourceLineNo">1701</span>    HashMap&lt;RegionInfo, RegionStateNode&gt; regions = null;<a name="line.1701"></a>
-<span class="sourceLineNo">1702</span><a name="line.1702"></a>
-<span class="sourceLineNo">1703</span>    assignQueueLock.lock();<a name="line.1703"></a>
-<span class="sourceLineNo">1704</span>    try {<a name="line.1704"></a>
-<span class="sourceLineNo">1705</span>      if (pendingAssignQueue.isEmpty() &amp;&amp; isRunning()) {<a name="line.1705"></a>
-<span class="sourceLineNo">1706</span>        assignQueueFullCond.await();<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>      if (!isRunning()) return null;<a name="line.1709"></a>
-<span class="sourceLineNo">1710</span>      assignQueueFullCond.await(assignDispatchWaitMillis, TimeUnit.MILLISECONDS);<a name="line.1710"></a>
-<span class="sourceLineNo">1711</span>      regions = new HashMap&lt;RegionInfo, RegionStateNode&gt;(pendingAssignQueue.size());<a name="line.1711"></a>
-<span class="sourceLineNo">1712</span>      for (RegionStateNode regionNode: pendingAssignQueue) {<a name="line.1712"></a>
-<span class="sourceLineNo">1713</span>        regions.put(regionNode.getRegionInfo(), regionNode);<a name="line.1713"></a>
-<span class="sourceLineNo">1714</span>      }<a name="line.1714"></a>
-<span class="sourceLineNo">1715</span>      pendingAssignQueue.clear();<a name="line.1715"></a>
-<span class="sourceLineNo">1716</span>    } catch (InterruptedException e) {<a name="line.1716"></a>
-<span class="sourceLineNo">1717</span>      LOG.warn("got interrupted ", e);<a name="line.1717"></a>
-<span class="sourceLineNo">1718</span>      Thread.currentThread().interrupt();<a name="line.1718"></a>
-<span class="sourceLineNo">1719</span>    } finally {<a name="line.1719"></a>
-<span class="sourceLineNo">1720</span>      assignQueueLock.unlock();<a name="line.1720"></a>
-<span class="sourceLineNo">1721</span>    }<a name="line.1721"></a>
-<span class="sourceLineNo">1722</span>    return regions;<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>  private void processAssignQueue() {<a name="line.1725"></a>
-<span class="sourceLineNo">1726</span>    final HashMap&lt;RegionInfo, RegionStateNode&gt; regions = waitOnAssignQueue();<a name="line.1726"></a>
-<span class="sourceLineNo">1727</span>    if (regions == null || regions.size() == 0 || !isRunning()) {<a name="line.1727"></a>
-<span class="sourceLineNo">1728</span>      return;<a name="line.1728"></a>
-<span class="sourceLineNo">1729</span>    }<a name="line.1729"></a>
-<span class="sourceLineNo">1730</span><a name="line.1730"></a>
-<span class="sourceLineNo">1731</span>    if (LOG.isTraceEnabled()) {<a name="line.1731"></a>
-<span class="sourceLineNo">1732</span>      LOG.trace("PROCESS ASSIGN QUEUE regionCount=" + regions.size());<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>    // TODO: Optimize balancer. pass a RegionPlan?<a name="line.1735"></a>
-<span class="sourceLineNo">1736</span>    final HashMap&lt;RegionInfo, ServerName&gt; retainMap = new HashMap&lt;&gt;();<a name="line.1736"></a>
-<span class="sourceLineNo">1737</span>    final List&lt;RegionInfo&gt; userHRIs = new ArrayList&lt;&gt;(regions.size());<a name="line.1737"></a>
-<span class="sourceLineNo">1738</span>    // Regions for system tables requiring reassignment<a name="line.1738"></a>
-<span class="sourceLineNo">1739</span>    final List&lt;RegionInfo&gt; systemHRIs = new ArrayList&lt;&gt;();<a name="line.1739"></a>
-<span class="sourceLineNo">1740</span>    for (RegionStateNode regionStateNode: regions.values()) {<a name="line.1740"></a>
-<span class="sourceLineNo">1741</span>      boolean sysTable = regionStateNode.isSystemTable();<a name="line.1741"></a>
-<span class="sourceLineNo">1742</span>      final List&lt;RegionInfo&gt; hris = sysTable? systemHRIs: userHRIs;<a name="line.1742"></a>
-<span class="sourceLineNo">1743</span>      if (regionStateNode.getRegionLocation() != null) {<a name="line.1743"></a>
-<span class="sourceLineNo">1744</span>        retainMap.put(regionStateNode.getRegionInfo(), regionStateNode.getRegionLocation());<a name="line.1744"></a>
-<span class="sourceLineNo">1745</span>      } else {<a name="line.1745"></a>
-<span class="sourceLineNo">1746</span>        hris.add(regionStateNode.getRegionInfo());<a name="line.1746"></a>
-<span class="sourceLineNo">1747</span>      }<a name="line.1747"></a>
-<span class="sourceLineNo">1748</span>    }<a name="line.1748"></a>
-<span class="sourceLineNo">1749</span><a name="line.1749"></a>
-<span class="sourceLineNo">1750</span>    // TODO: connect with the listener to invalidate the cache<a name="line.1750"></a>
-<span class="sourceLineNo">1751</span><a name="line.1751"></a>
-<span class="sourceLineNo">1752</span>    // TODO use events<a name="line.1752"></a>
-<span class="sourceLineNo">1753</span>    List&lt;ServerName&gt; servers = master.getServerManager().createDestinationServersList();<a name="line.1753"></a>
-<span class="sourceLineNo">1754</span>    for (int i = 0; servers.size() &lt; 1; ++i) {<a name="line.1754"></a>
-<span class="sourceLineNo">1755</span>      // Report every fourth time around this loop; try not to flood log.<a name="line.1755"></a>
-<span class="sourceLineNo">1756</span>      if (i % 4 == 0) {<a name="line.1756"></a>
-<span class="sourceLineNo">1757</span>        LOG.warn("No servers available; cannot place " + regions.size() + " unassigned regions.");<a name="line.1757"></a>
-<span class="sourceLineNo">1758</span>      }<a name="line.1758"></a>
-<span class="sourceLineNo">1759</span><a name="line.1759"></a>
-<span class="sourceLineNo">1760</span>      if (!isRunning()) {<a name="line.1760"></a>
-<span class="sourceLineNo">1761</span>        LOG.debug("Stopped! Dropping assign of " + regions.size() + " queued regions.");<a name="line.1761"></a>
-<span class="sourceLineNo">1762</span>        return;<a name="line.1762"></a>
-<span class="sourceLineNo">1763</span>      }<a name="line.1763"></a>
-<span class="sourceLineNo">1764</span>      Threads.sleep(250);<a name="line.1764"></a>
-<span class="sourceLineNo">1765</span>      servers = master.getServerManager().createDestinationServersList();<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>    if (!systemHRIs.isEmpty()) {<a name="line.1768"></a>
-<span class="sourceLineNo">1769</span>      // System table regions requiring reassignment are present, get region servers<a name="line.1769"></a>
-<span class="sourceLineNo">1770</span>      // not available for system table regions<a name="line.1770"></a>
-<span class="sourceLineNo">1771</span>      final List&lt;ServerName&gt; excludeServers = getExcludedServersForSystemTable();<a name="line.1771"></a>
-<span class="sourceLineNo">1772</span>      List&lt;ServerName&gt; serversForSysTables = servers.stream()<a name="line.1772"></a>
-<span class="sourceLineNo">1773</span>          .filter(s -&gt; !excludeServers.contains(s)).collect(Collectors.toList());<a name="line.1773"></a>
-<span class="sourceLineNo">1774</span>      if (serversForSysTables.isEmpty()) {<a name="line.1774"></a>
-<span class="sourceLineNo">1775</span>        LOG.warn("Filtering old server versions and the excluded produced an empty set; " +<a name="line.1775"></a>
-<span class="sourceLineNo">1776</span>            "instead considering all candidate servers!");<a name="line.1776"></a>
-<span class="sourceLineNo">1777</span>      }<a name="line.1777"></a>
-<span class="sourceLineNo">1778</span>      LOG.debug("Processing assignQueue; systemServersCount=" + serversForSysTables.size() +<a name="line.1778"></a>
-<span class="sourceLineNo">1779</span>          ", allServersCount=" + servers.size());<a name="line.1779"></a>
-<span class="sourceLineNo">1780</span>      processAssignmentPlans(regions, null, systemHRIs,<a name="line.1780"></a>
-<span class="sourceLineNo">1781</span>          serversForSysTables.isEmpty()? servers: serversForSysTables);<a name="line.1781"></a>
-<span class="sourceLineNo">1782</span>    }<a name="line.1782"></a>
-<span class="sourceLineNo">1783</span><a name="line.1783"></a>
-<span class="sourceLineNo">1784</span>    processAssignmentPlans(regions, retainMap, userHRIs, servers);<a name="line.1784"></a>
-<span class="sourceLineNo">1785</span>  }<a name="line.1785"></a>
-<span class="sourceLineNo">1786</span><a name="line.1786"></a>
-<span class="sourceLineNo">1787</span>  private void processAssignmentPlans(final HashMap&lt;RegionInfo, RegionStateNode&gt; regions,<a name="line.1787"></a>
-<span class="sourceLineNo">1788</span>      final HashMap&lt;RegionInfo, ServerName&gt; retainMap, final List&lt;RegionInfo&gt; hris,<a name="line.1788"></a>
-<span class="sourceLineNo">1789</span>      final List&lt;ServerName&gt; servers) {<a name="line.1789"></a>
-<span class="sourceLineNo">1790</span>    boolean isTraceEnabled = LOG.isTraceEnabled();<a name="line.1790"></a>
-<span class="sourceLineNo">1791</span>    if (isTraceEnabled) {<a name="line.1791"></a>
-<span class="sourceLineNo">1792</span>      LOG.trace("Available servers count=" + servers.size() + ": " + servers);<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>    final LoadBalancer balancer = getBalancer();<a name="line.1795"></a>
-<span class="sourceLineNo">1796</span>    // ask the balancer where to place regions<a name="line.1796"></a>
-<span class="sourceLineNo">1797</span>    if (retainMap != null &amp;&amp; !retainMap.isEmpty()) {<a name="line.1797"></a>
-<span class="sourceLineNo">1798</span>      if (isTraceEnabled) {<a name="line.1798"></a>
-<span class="sourceLineNo">1799</span>        LOG.trace("retain assign regions=" + retainMap);<a name="line.1799"></a>
-<span class="sourceLineNo">1800</span>      }<a name="line.1800"></a>
-<span class="sourceLineNo">1801</span>      try {<a name="line.1801"></a>
-<span class="sourceLineNo">1802</span>        acceptPlan(regions, balancer.retainAssignment(retainMap, servers));<a name="line.1802"></a>
-<span class="sourceLineNo">1803</span>      } catch (HBaseIOException e) {<a name="line.1803"></a>
-<span class="sourceLineNo">1804</span>        LOG.warn("unable to retain assignment", e);<a name="line.1804"></a>
-<span class="sourceLineNo">1805</span>        addToPendingAssignment(regions, retainMap.keySet());<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><a name="line.1808"></a>
-<span class="sourceLineNo">1809</span>    // TODO: Do we need to split retain and round-robin?<a name="line.1809"></a>
-<span class="sourceLineNo">1810</span>    // the retain seems to fallback to round-robin/random if the region is not in the map.<a name="line.1810"></a>
-<span class="sourceLineNo">1811</span>    if (!hris.isEmpty()) {<a name="line.1811"></a>
-<span class="sourceLineNo">1812</span>      Collections.sort(hris, RegionInfo.COMPARATOR);<a name="line.1812"></a>
-<span class="sourceLineNo">1813</span>      if (isTraceEnabled) {<a name="line.1813"></a>
-<span class="sourceLineNo">1814</span>        LOG.trace("round robin regions=" + hris);<a name="line.1814"></a>
-<span class="sourceLineNo">1815</span>      }<a name="line.1815"></a>
-<span class="sourceLineNo">1816</span>      try {<a name="line.1816"></a>
-<span class="sourceLineNo">1817</span>        acceptPlan(regions, balancer.roundRobinAssignment(hris, servers));<a name="line.1817"></a>
-<span class="sourceLineNo">1818</span>      } catch (HBaseIOException e) {<a name="line.1818"></a>
-<span class="sourceLineNo">1819</span>        LOG.warn("unable to round-robin assignment", e);<a name="line.1819"></a>
-<span class="sourceLineNo">1820</span>        addToPendingAssignment(regions, hris);<a name="line.1820"></a>
-<span class="sourceLineNo">1821</span>      }<a name="line.1821"></a>
-<span class="sourceLineNo">1822</span>    }<a name="line.1822"></a>
-<span class="sourceLineNo">1823</span>  }<a name="line.1823"></a>
-<span class="sourceLineNo">1824</span><a name="line.1824"></a>
-<span class="sourceLineNo">1825</span>  private void acceptPlan(final HashMap&lt;RegionInfo, RegionStateNode&gt; regions,<a name="line.1825"></a>
-<span class="sourceLineNo">1826</span>      final Map&lt;ServerName, List&lt;RegionInfo&gt;&gt; plan) throws HBaseIOException {<a name="line.1826"></a>
-<span class="sourceLineNo">1827</span>    final ProcedureEvent&lt;?&gt;[] events = new ProcedureEvent[regions.size()];<a name="line.1827"></a>
-<span class="sourceLineNo">1828</span>    final long st = System.currentTimeMillis();<a name="line.1828"></a>
-<span class="sourceLineNo">1829</span><a name="line.1829"></a>
-<span class="sourceLineNo">1830</span>    if (plan == null) {<a name="line.1830"></a>
-<span class="sourceLineNo">1831</span>      throw new HBaseIOException("unable to compute plans for regions=" + regions.size());<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>    if (plan.isEmpty()) return;<a name="line.1834"></a>
-<span class="sourceLineNo">1835</span><a name="line.1835"></a>
-<span class="sourceLineNo">1836</span>    int evcount = 0;<a name="line.1836"></a>
-<span class="sourceLineNo">1837</span>    for (Map.Entry&lt;ServerName, List&lt;RegionInfo&gt;&gt; entry: plan.entrySet()) {<a name="line.1837"></a>
-<span class="sourceLineNo">1838</span>      final ServerName server = entry.getKey();<a name="line.1838"></a>
-<span class="sourceLineNo">1839</span>      for (RegionInfo hri: entry.getValue()) {<a name="line.1839"></a>
-<span class="sourceLineNo">1840</span>        final RegionStateNode regionNode = regions.get(hri);<a name="line.1840"></a>
-<span class="sourceLineNo">1841</span>        regionNode.setRegionLocation(server);<a name="line.1841"></a>
-<span class="sourceLineNo">1842</span>        events[evcount++] = regionNode.getProcedureEvent();<a name="line.1842"></a>
-<span class="sourceLineNo">1843</span>      }<a name="line.1843"></a>
-<span class="sourceLineNo">1844</span>    }<a name="line.1844"></a>
-<span class="sourceLineNo">1845</span>    ProcedureEvent.wakeEvents(getProcedureScheduler(), events);<a name="line.1845"></a>
-<span class="sourceLineNo">1846</span><a name="line.1846"></a>
-<span class="sourceLineNo">1847</span>    final long et = System.currentTimeMillis();<a name="line.1847"></a>
-<span class="sourceLineNo">1848</span>    if (LOG.isTraceEnabled()) {<a name="line.1848"></a>
-<span class="sourceLineNo">1849</span>      LOG.trace("ASSIGN ACCEPT " + events.length + " -&gt; " +<a name="line.1849"></a>
-<span class="sourceLineNo">1850</span>          StringUtils.humanTimeDiff(et - st));<a name="line.1850"></a>
-<span class="sourceLineNo">1851</span>    }<a name="line.1851"></a>
-<span class="sourceLineNo">1852</span>  }<a name="line.1852"></a>
-<span class="sourceLineNo">1853</span><a name="line.1853"></a>
-<span class="sourceLineNo">1854</span>  private void addToPendingAssignment(final HashMap&lt;RegionInfo, RegionStateNode&gt; regions,<a name="line.1854"></a>
-<span class="sourceLineNo">1855</span>      final Collection&lt;RegionInfo&gt; pendingRegions) {<a name="line.1855"></a>
-<span class="sourceLineNo">1856</span>    assignQueueLock.lock();<a name="line.1856"></a>
-<span class="sourceLineNo">1857</span>    try {<a name="line.1857"></a>
-<span class="sourceLineNo">1858</span>      for (RegionInfo hri: pendingRegions) {<a name="line.1858"></a>
-<span class="sourceLineNo">1859</span>        pendingAssignQueue.add(regions.get(hri));<a name="line.1859"></a>
-<span class="sourceLineNo">1860</span>      }<a name="line.1860"></a>
-<span class="sourceLineNo">1861</span>    } finally {<a name="line.1861"></a>
-<span class="sourceLineNo">1862</span>      assignQueueLock.unlock();<a name="line.1862"></a>
-<span class="sourceLineNo">1863</span>    }<a name="line.1863"></a>
-<span class="sourceLineNo">1864</span>  }<a name="line.1864"></a>
-<span class="sourceLineNo">1865</span><a name="line.1865"></a>
-<span class="sourceLineNo">1866</span>  /**<a name="line.1866"></a>
-<span class="sourceLineNo">1867</span>   * Get a list of servers that this region cannot be assigned to.<a name="line.1867"></a>
-<span class="sourceLineNo">1868</span>   * For system tables, we must assign them to a server with highest version.<a name="line.1868"></a>
-<span class="sourceLineNo">1869</span>   */<a name="line.1869"></a>
-<span class="sourceLineNo">1870</span>  public List&lt;ServerName&gt; getExcludedServersForSystemTable() {<a name="line.1870"></a>
-<span class="sourceLineNo">1871</span>    // TODO: This should be a cached list kept by the ServerManager rather than calculated on each<a name="line.1871"></a>
-<span class="sourceLineNo">1872</span>    // move or system region assign. The RegionServerTracker keeps list of online Servers with<a name="line.1872"></a>
-<span class="sourceLineNo">1873</span>    // RegionServerInfo that includes Version.<a name="line.1873"></a>
-<span class="sourceLineNo">1874</span>    List&lt;Pair&lt;ServerName, String&gt;&gt; serverList = master.getServerManager().getOnlineServersList()<a name="line.1874"></a>
-<span class="sourceLineNo">1875</span>        .stream()<a name="line.1875"></a>
-<span class="sourceLineNo">1876</span>        .map((s)-&gt;new Pair&lt;&gt;(s, master.getRegionServerVersion(s)))<a name="line.1876"></a>
-<span class="sourceLineNo">1877</span>        .collect(Collectors.toList());<a name="line.1877"></a>
-<span class="sourceLineNo">1878</span>    if (serverList.isEmpty()) {<a name="line.1878"></a>
-<span class="sourceLineNo">1879</span>      return Collections.emptyList();<a name="line.1879"></a>
-<span class="sourceLineNo">1880</span>    }<a name="line.1880"></a>
-<span class="sourceLineNo">1881</span>    String highestVersion = Collections.max(serverList,<a name="line.1881"></a>
-<span class="sourceLineNo">1882</span>        (o1, o2) -&gt; VersionInfo.compareVersion(o1.getSecond(), o2.getSecond())).getSecond();<a name="line.1882"></a>
-<span class="sourceLineNo">1883</span>    return serverList.stream()<a name="line.1883"></a>
-<span class="sourceLineNo">1884</span>        .filter((p)-&gt;!p.getSecond().equals(highestVersion))<a name="line.1884"></a>
-<span class="sourceLineNo">1885</span>        .map(Pair::getFirst)<a name="line.1885"></a>
-<span class="sourceLineNo">1886</span>        .collect(Collectors.toList());<a name="line.1886"></a>
-<span class="sourceLineNo">1887</span>  }<a name="line.1887"></a>
-<span class="sourceLineNo">1888</span><a name="line.1888"></a>
-<span class="sourceLineNo">1889</span>  // ============================================================================================<a name="line.1889"></a>
-<span class="sourceLineNo">1890</span>  //  Server Helpers<a name="line.1890"></a>
-<span class="sourceLineNo">1891</span>  // ============================================================================================<a name="line.1891"></a>
-<span class="sourceLineNo">1892</span>  @Override<a name="line.1892"></a>
-<span class="sourceLineNo">1893</span>  public void serverAdded(final ServerName serverName) {<a name="line.1893"></a>
-<span class="sourceLineNo">1894</span>  }<a name="line.1894"></a>
-<span class="sourceLineNo">1895</span><a name="line.1895"></a>
-<span class="sourceLineNo">1896</span>  @Override<a name="line.1896"></a>
-<span class="sourceLineNo">1897</span>  public void serverRemoved(final ServerName serverName) {<a name="line.1897"></a>
-<span class="sourceLineNo">1898</span>    final ServerStateNode serverNode = regionStates.getServerNode(serverName);<a name="line.1898"></a>
-<span class="sourceLineNo">1899</span>    if (serverNode == null) return;<a name="line.1899"></a>
-<span class="sourceLineNo">1900</span><a name="line.1900"></a>
-<span class="sourceLineNo">1901</span>    // just in case, wake procedures waiting for this server report<a name="line.1901"></a>
-<span class="sourceLineNo">1902</span>    wakeServerReportEvent(serverNode);<a name="line.1902"></a>
-<span class="sourceLineNo">1903</span>  }<a name="line.1903"></a>
-<span class="sourceLineNo">1904</span><a name="line.1904"></a>
-<span class="sourceLineNo">1905</span>  private void killRegionServer(final ServerStateNode serverNode) {<a name="line.1905"></a>
-<span class="sourceLineNo">1906</span>    master.getServerManager().expireServer(serverNode.getServerName());<a name="line.1906"></a>
-<span class="sourceLineNo">1907</span>  }<a name="line.1907"></a>
-<span class="sourceLineNo">1908</span><a name="line.1908"></a>
-<span class="sourceLineNo">1909</span>  @VisibleForTesting<a name="line.1909"></a>
-<span class="sourceLineNo">1910</span>  MasterServices getMaster() {<a name="line.1910"></a>
-<span class="sourceLineNo">1911</span>    return master;<a name="line.1911"></a>
-<span class="sourceLineNo">1912</span>  }<a name="line.1912"></a>
-<span class="sourceLineNo">1913</span>}<a name="line.1913"></a>
+<span class="sourceLineNo">1367</span>    long pid = procExec.submitProcedure(new ServerCrashProcedure(procExec.getEnvironment(),<a name="line.1367"></a>
+<span class="sourceLineNo">1368</span>        serverName, shouldSplitWal, carryingMeta));<a name="line.1368"></a>
+<span class="sourceLineNo">1369</span>    LOG.debug("Added=" + serverName<a name="line.1369"></a>
+<span class="sourceLineNo">1370</span>        + " to dead servers, submitted shutdown handler to be executed meta=" + carryingMeta);<a name="line.1370"></a>
+<span class="sourceLineNo">1371</span>    return pid;<a name="line.1371"></a>
+<span class="sourceLineNo">1372</span>  }<a name="line.1372"></a>
+<span class="sourceLineNo">1373</span><a name="line.1373"></a>
+<span class="sourceLineNo">1374</span>  public void offlineRegion(final RegionInfo regionInfo) {<a name="line.1374"></a>
+<span class="sourceLineNo">1375</span>    // TODO used by MasterRpcServices<a name="line.1375"></a>
+<span class="sourceLineNo">1376</span>    RegionStateNode node = regionStates.getRegionStateNode(regionInfo);<a name="line.1376"></a>
+<span class="sourceLineNo">1377</span>    if (node != null) {<a name="line.1377"></a>
+<span class="sourceLineNo">1378</span>      node.offline();<a name="line.1378"></a>
+<span class="sourceLineNo">1379</span>    }<a name="line.1379"></a>
+<span class="sourceLineNo">1380</span>  }<a name="line.1380"></a>
+<span class="sourceLineNo">1381</span><a name="line.1381"></a>
+<span class="sourceLineNo">1382</span>  public void onlineRegion(final RegionInfo regionInfo, final ServerName serverName) {<a name="line.1382"></a>
+<span class="sourceLineNo">1383</span>    // TODO used by TestSplitTransactionOnCluster.java<a name="line.1383"></a>
+<span class="sourceLineNo">1384</span>  }<a name="line.1384"></a>
+<span class="sourceLineNo">1385</span><a name="line.1385"></a>
+<span class="sourceLineNo">1386</span>  public Map&lt;ServerName, List&lt;RegionInfo&gt;&gt; getSnapShotOfAssignment(<a name="line.1386"></a>
+<span class="sourceLineNo">1387</span>      final Collection&lt;RegionInfo&gt; regions) {<a name="line.1387"></a>
+<span class="sourceLineNo">1388</span>    return regionStates.getSnapShotOfAssignment(regions);<a name="line.1388"></a>
+<span class="sourceLineNo">1389</span>  }<a name="line.1389"></a>
+<span class="sourceLineNo">1390</span><a name="line.1390"></a>
+<span class="sourceLineNo">1391</span>  // ============================================================================================<a name="line.1391"></a>
+<span class="sourceLineNo">1392</span>  //  TODO: UTILS/HELPERS?<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>   * Used by the client (via master) to identify if all regions have the schema updates<a name="line.1395"></a>
+<span class="sourceLineNo">1396</span>   *<a name="line.1396"></a>
+<span class="sourceLineNo">1397</span>   * @param tableName<a name="line.1397"></a>
+<span class="sourceLineNo">1398</span>   * @return Pair indicating the status of the alter command (pending/total)<a name="line.1398"></a>
+<span class="sourceLineNo">1399</span>   * @throws IOException<a name="line.1399"></a>
+<span class="sourceLineNo">1400</span>   */<a name="line.1400"></a>
+<span class="sourceLineNo">1401</span>  public Pair&lt;Integer, Integer&gt; getReopenStatus(TableName tableName) {<a name="line.1401"></a>
+<span class="sourceLineNo">1402</span>    if (isTableDisabled(tableName)) return new Pair&lt;Integer, Integer&gt;(0, 0);<a name="line.1402"></a>
+<span class="sourceLineNo">1403</span><a name="line.1403"></a>
+<span class="sourceLineNo">1404</span>    final List&lt;RegionState&gt; states = regionStates.getTableRegionStates(tableName);<a name="line.1404"></a>
+<span class="sourceLineNo">1405</span>    int ritCount = 0;<a name="line.1405"></a>
+<span class="sourceLineNo">1406</span>    for (RegionState regionState: states) {<a name="line.1406"></a>
+<span class="sourceLineNo">1407</span>      if (!regionState.isOpened()) ritCount++;<a name="line.1407"></a>
+<span class="sourceLineNo">1408</span>    }<a name="line.1408"></a>
+<span class="sourceLineNo">1409</span>    return new Pair&lt;Integer, Integer&gt;(ritCount, states.size());<a name="line.1409"></a>
+<span class="sourceLineNo">1410</span>  }<a name="line.1410"></a>
+<span class="sourceLineNo">1411</span><a name="line.1411"></a>
+<span class="sourceLineNo">1412</span>  // ============================================================================================<a name="line.1412"></a>
+<span class="sourceLineNo">1413</span>  //  TODO: Region State In Transition<a name="line.1413"></a>
+<span class="sourceLineNo">1414</span>  // ============================================================================================<a name="line.1414"></a>
+<span class="sourceLineNo">1415</span>  public boolean hasRegionsInTransition() {<a name="line.1415"></a>
+<span class="sourceLineNo">1416</span>    return regionStates.hasRegionsInTransition();<a name="line.1416"></a>
+<span class="sourceLineNo">1417</span>  }<a name="line.1417"></a>
+<span class="sourceLineNo">1418</span><a name="line.1418"></a>
+<span class="sourceLineNo">1419</span>  public List&lt;RegionStateNode&gt; getRegionsInTransition() {<a name="line.1419"></a>
+<span class="sourceLineNo">1420</span>    return regionStates.getRegionsInTransition();<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>  public List&lt;RegionInfo&gt; getAssignedRegions() {<a name="line.1423"></a>
+<span class="sourceLineNo">1424</span>    return regionStates.getAssignedRegions();<a name="line.1424"></a>
+<span class="sourceLineNo">1425</span>  }<a name="line.1425"></a>
+<span class="sourceLineNo">1426</span><a name="line.1426"></a>
+<span class="sourceLineNo">1427</span>  public RegionInfo getRegionInfo(final byte[] regionName) {<a name="line.1427"></a>
+<span class="sourceLineNo">1428</span>    final RegionStateNode regionState = regionStates.getRegionStateNodeFromName(regionName);<a name="line.1428"></a>
+<span class="sourceLineNo">1429</span>    return regionState != null ? regionState.getRegionInfo() : null;<a name="line.1429"></a>
+<span class="sourceLineNo">1430</span>  }<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>  //  Expected states on region state transition.<a name="line.1433"></a>
+<span class="sourceLineNo">1434</span>  //  Notice that there is expected states for transiting to OPENING state, this is because SCP.<a name="line.1434"></a>
+<span class="sourceLineNo">1435</span>  //  See the comments in regionOpening method for more details.<a name="line.1435"></a>
+<span class="sourceLineNo">1436</span>  // ============================================================================================<a name="line.1436"></a>
+<span class="sourceLineNo">1437</span>  private static final State[] STATES_EXPECTED_ON_OPEN = {<a name="line.1437"></a>
+<span class="sourceLineNo">1438</span>    State.OPENING, // Normal case<a name="line.1438"></a>
+<span class="sourceLineNo">1439</span>    State.OPEN // Retrying<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>  private static final State[] STATES_EXPECTED_ON_CLOSING = {<a name="line.1442"></a>
+<span class="sourceLineNo">1443</span>    State.OPEN, // Normal case<a name="line.1443"></a>
+<span class="sourceLineNo">1444</span>    State.CLOSING, // Retrying<a name="line.1444"></a>
+<span class="sourceLineNo">1445</span>    State.SPLITTING, // Offline the split parent<a name="line.1445"></a>
+<span class="sourceLineNo">1446</span>    State.MERGING // Offline the merge parents<a name="line.1446"></a>
+<span class="sourceLineNo">1447</span>  };<a name="line.1447"></a>
+<span class="sourceLineNo">1448</span><a name="line.1448"></a>
+<span class="sourceLineNo">1449</span>  private static final State[] STATES_EXPECTED_ON_CLOSED = {<a name="line.1449"></a>
+<span class="sourceLineNo">1450</span>    State.CLOSING, // Normal case<a name="line.1450"></a>
+<span class="sourceLineNo">1451</span>    State.CLOSED // Retrying<a name="line.1451"></a>
+<span class="sourceLineNo">1452</span>  };<a name="line.1452"></a>
+<span class="sourceLineNo">1453</span><a name="line.1453"></a>
+<span class="sourceLineNo">1454</span>  // This is for manually scheduled region assign, can add other states later if we find out other<a name="line.1454"></a>
+<span class="sourceLineNo">1455</span>  // usages<a name="line.1455"></a>
+<span class="sourceLineNo">1456</span>  private static final State[] STATES_EXPECTED_ON_ASSIGN = { State.CLOSED, State.OFFLINE };<a name="line.1456"></a>
+<span class="sourceLineNo">1457</span><a name="line.1457"></a>
+<span class="sourceLineNo">1458</span>  // We only allow unassign or move a region which is in OPEN state.<a name="line.1458"></a>
+<span class="sourceLineNo">1459</span>  private static final State[] STATES_EXPECTED_ON_UNASSIGN_OR_MOVE = { State.OPEN };<a name="line.1459"></a>
+<span class="sourceLineNo">1460</span><a name="line.1460"></a>
+<span class="sourceLineNo">1461</span>  // ============================================================================================<a name="line.1461"></a>
+<span class="sourceLineNo">1462</span>  //  Region Status update<a name="line.1462"></a>
+<span class="sourceLineNo">1463</span>  //  Should only be called in TransitRegionStateProcedure<a name="line.1463"></a>
+<span class="sourceLineNo">1464</span>  // ============================================================================================<a name="line.1464"></a>
+<span class="sourceLineNo">1465</span>  private void transitStateAndUpdate(RegionStateNode regionNode, RegionState.State newState,<a name="line.1465"></a>
+<span class="sourceLineNo">1466</span>      RegionState.State... expectedStates) throws IOException {<a name="line.1466"></a>
+<span class="sourceLineNo">1467</span>    RegionState.State state = regionNode.getState();<a name="line.1467"></a>
+<span class="sourceLineNo">1468</span>    regionNode.transitionState(newState, expectedStates);<a name="line.1468"></a>
+<span class="sourceLineNo">1469</span>    boolean succ = false;<a name="line.1469"></a>
+<span class="sourceLineNo">1470</span>    try {<a name="line.1470"></a>
+<span class="sourceLineNo">1471</span>      regionStateStore.updateRegionLocation(regionNode);<a name="line.1471"></a>
+<span class="sourceLineNo">1472</span>      succ = true;<a name="line.1472"></a>
+<span class="sourceLineNo">1473</span>    } finally {<a name="line.1473"></a>
+<span class="sourceLineNo">1474</span>      if (!succ) {<a name="line.1474"></a>
+<span class="sourceLineNo">1475</span>        // revert<a name="line.1475"></a>
+<span class="sourceLineNo">1476</span>        regionNode.setState(state);<a name="line.1476"></a>
+<span class="sourceLineNo">1477</span>      }<a name="line.1477"></a>
+<span class="sourceLineNo">1478</span>    }<a name="line.1478"></a>
+<span class="sourceLineNo">1479</span>  }<a name="line.1479"></a>
+<span class="sourceLineNo">1480</span><a name="line.1480"></a>
+<span class="sourceLineNo">1481</span>  // should be called within the synchronized block of RegionStateNode<a name="line.1481"></a>
+<span class="sourceLineNo">1482</span>  void regionOpening(RegionStateNode regionNode) throws IOException {<a name="line.1482"></a>
+<span class="sourceLineNo">1483</span>    // As in SCP, for performance reason, there is no TRSP attached with this region, we will not<a name="line.1483"></a>
+<span class="sourceLineNo">1484</span>    // update the region state, which means that the region could be in any state when we want to<a name="line.1484"></a>
+<span class="sourceLineNo">1485</span>    // assign it after a RS crash. So here we do not pass the expectedStates parameter.<a name="line.1485"></a>
+<span class="sourceLineNo">1486</span>    transitStateAndUpdate(regionNode, State.OPENING);<a name="line.1486"></a>
+<span class="sourceLineNo">1487</span>    regionStates.addRegionToServer(regionNode);<a name="line.1487"></a>
+<span class="sourceLineNo">1488</span>    // update the operation count metrics<a name="line.1488"></a>
+<span class="sourceLineNo">1489</span>    metrics.incrementOperationCounter();<a name="line.1489"></a>
+<span class="sourceLineNo">1490</span>  }<a name="line.1490"></a>
+<span class="sourceLineNo">1491</span><a name="line.1491"></a>
+<span class="sourceLineNo">1492</span>  // should be called within the synchronized block of RegionStateNode.<a name="line.1492"></a>
+<span class="sourceLineNo">1493</span>  // The parameter 'giveUp' means whether we will try to open the region again, if it is true, then<a name="line.1493"></a>
+<span class="sourceLineNo">1494</span>  // we will persist the FAILED_OPEN state into hbase:meta.<a name="line.1494"></a>
+<span class="sourceLineNo">1495</span>  void regionFailedOpen(RegionStateNode regionNode, boolean giveUp) throws IOException {<a name="line.1495"></a>
+<span class="sourceLineNo">1496</span>    RegionState.State state = regionNode.getState();<a name="line.1496"></a>
+<span class="sourceLineNo">1497</span>    ServerName regionLocation = regionNode.getRegionLocation();<a name="line.1497"></a>
+<span class="sourceLineNo">1498</span>    if (giveUp) {<a name="line.1498"></a>
+<span class="sourceLineNo">1499</span>      regionNode.setState(State.FAILED_OPEN);<a name="line.1499"></a>
+<span class="sourceLineNo">1500</span>      regionNode.setRegionLocation(null);<a name="line.1500"></a>
+<span class="sourceLineNo">1501</span>      boolean succ = false;<a name="line.1501"></a>
+<span class="sourceLineNo">1502</span>      try {<a name="line.1502"></a>
+<span class="sourceLineNo">1503</span>        regionStateStore.updateRegionLocation(regionNode);<a name="line.1503"></a>
+<span class="sourceLineNo">1504</span>        succ = true;<a name="line.1504"></a>
+<span class="sourceLineNo">1505</span>      } finally {<a name="line.1505"></a>
+<span class="sourceLineNo">1506</span>        if (!succ) {<a name="line.1506"></a>
+<span class="sourceLineNo">1507</span>          // revert<a name="line.1507"></a>
+<span class="sourceLineNo">1508</span>          regionNode.setState(state);<a name="line.1508"></a>
+<span class="sourceLineNo">1509</span>          regionNode.setRegionLocation(regionLocation);<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>    }<a name="line.1512"></a>
+<span class="sourceLineNo">1513</span>    if (regionLocation != null) {<a name="line.1513"></a>
+<span class="sourceLineNo">1514</span>      regionStates.removeRegionFromServer(regionLocation, regionNode);<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><a name="line.1517"></a>
+<span class="sourceLineNo">1518</span>  // should be called within the synchronized block of RegionStateNode<a name="line.1518"></a>
+<span class="sourceLineNo">1519</span>  void regionOpened(RegionStateNode regionNode) throws IOException {<a name="line.1519"></a>
+<span class="sourceLineNo">1520</span>    // TODO: OPENING Updates hbase:meta too... we need to do both here and there?<a name="line.1520"></a>
+<span class="sourceLineNo">1521</span>    // That is a lot of hbase:meta writing.<a name="line.1521"></a>
+<span class="sourceLineNo">1522</span>    transitStateAndUpdate(regionNode, State.OPEN, STATES_EXPECTED_ON_OPEN);<a name="line.1522"></a>
+<span class="sourceLineNo">1523</span>    RegionInfo hri = regionNode.getRegionInfo();<a name="line.1523"></a>
+<span class="sourceLineNo">1524</span>    if (isMetaRegion(hri)) {<a name="line.1524"></a>
+<span class="sourceLineNo">1525</span>      // Usually we'd set a table ENABLED at this stage but hbase:meta is ALWAYs enabled, it<a name="line.1525"></a>
+<span class="sourceLineNo">1526</span>      // can't be disabled -- so skip the RPC (besides... enabled is managed by TableStateManager<a name="line.1526"></a>
+<span class="sourceLineNo">1527</span>      // which is backed by hbase:meta... Avoid setting ENABLED to avoid having to update state<a name="line.1527"></a>
+<span class="sourceLineNo">1528</span>      // on table that contains state.<a name="line.1528"></a>
+<span class="sourceLineNo">1529</span>      setMetaAssigned(hri, true);<a name="line.1529"></a>
+<span class="sourceLineNo">1530</span>    }<a name="line.1530"></a>
+<span class="sourceLineNo">1531</span>    regionStates.addRegionToServer(regionNode);<a name="line.1531"></a>
+<span class="sourceLineNo">1532</span>    regionStates.removeFromFailedOpen(hri);<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>  // should be called within the synchronized block of RegionStateNode<a name="line.1535"></a>
+<span class="sourceLineNo">1536</span>  void regionClosing(RegionStateNode regionNode) throws IOException {<a name="line.1536"></a>
+<span class="sourceLineNo">1537</span>    transitStateAndUpdate(regionNode, State.CLOSING, STATES_EXPECTED_ON_CLOSING);<a name="line.1537"></a>
+<span class="sourceLineNo">1538</span><a name="line.1538"></a>
+<span class="sourceLineNo">1539</span>    RegionInfo hri = regionNode.getRegionInfo();<a name="line.1539"></a>
+<span class="sourceLineNo">1540</span>    // Set meta has not initialized early. so people trying to create/edit tables will wait<a name="line.1540"></a>
+<span class="sourceLineNo">1541</span>    if (isMetaRegion(hri)) {<a name="line.1541"></a>
+<span class="sourceLineNo">1542</span>      setMetaAssigned(hri, false);<a name="line.1542"></a>
+<span class="sourceLineNo">1543</span>    }<a name="line.1543"></a>
+<span class="sourceLineNo">1544</span>    regionStates.addRegionToServer(regionNode);<a name="line.1544"></a>
+<span class="sourceLineNo">1545</span>    // update the operation count metrics<a name="line.1545"></a>
+<span class="sourceLineNo">1546</span>    metrics.incrementOperationCounter();<a name="line.1546"></a>
+<span class="sourceLineNo">1547</span>  }<a name="line.1547"></a>
+<span class="sourceLineNo">1548</span><a name="line.1548"></a>
+<span class="sourceLineNo">1549</span>  // should be called within the synchronized block of RegionStateNode<a name="line.1549"></a>
+<span class="sourceLineNo">1550</span>  // The parameter 'normally' means whether we are closed cleanly, if it is true, then it means that<a name="line.1550"></a>
+<span class="sourceLineNo">1551</span>  // we are closed due to a RS crash.<a name="line.1551"></a>
+<span class="sourceLineNo">1552</span>  void regionClosed(RegionStateNode regionNode, boolean normally) throws IOException {<a name="line.1552"></a>
+<span class="sourceLineNo">1553</span>    RegionState.State state = regionNode.getState();<a name="line.1553"></a>
+<span class="sourceLineNo">1554</span>    ServerName regionLocation = regionNode.getRegionLocation();<a name="line.1554"></a>
+<span class="sourceLineNo">1555</span>    if (normally) {<a name="line.1555"></a>
+<span class="sourceLineNo">1556</span>      regionNode.transitionState(State.CLOSED, STATES_EXPECTED_ON_CLOSED);<a name="line.1556"></a>
+<span class="sourceLineNo">1557</span>    } else {<a name="line.1557"></a>
+<span class="sourceLineNo">1558</span>      // For SCP<a name="line.1558"></a>
+<span class="sourceLineNo">1559</span>      regionNode.transitionState(State.ABNORMALLY_CLOSED);<a name="line.1559"></a>
+<span class="sourceLineNo">1560</span>    }<a name="line.1560"></a>
+<span class="sourceLineNo">1561</span>    regionNode.setRegionLocation(null);<a name="line.1561"></a>
+<span class="sourceLineNo">1562</span>    boolean succ = false;<a name="line.1562"></a>
+<span class="sourceLineNo">1563</span>    try {<a name="line.1563"></a>
+<span class="sourceLineNo">1564</span>      regionStateStore.updateRegionLocation(regionNode);<a name="line.1564"></a>
+<span class="sourceLineNo">1565</span>      succ = true;<a name="line.1565"></a>
+<span class="sourceLineNo">1566</span>    } finally {<a name="line.1566"></a>
+<span class="sourceLineNo">1567</span>      if (!succ) {<a name="line.1567"></a>
+<span class="sourceLineNo">1568</span>        // revert<a name="line.1568"></a>
+<span class="sourceLineNo">1569</span>        regionNode.setState(state);<a name="line.1569"></a>
+<span class="sourceLineNo">1570</span>        regionNode.setRegionLocation(regionLocation);<a name="line.1570"></a>
+<span class="sourceLineNo">1571</span>      }<a name="line.1571"></a>
+<span class="sourceLineNo">1572</span>    }<a name="line.1572"></a>
+<span class="sourceLineNo">1573</span>    if (regionLocation != null) {<a name="line.1573"></a>
+<span class="sourceLineNo">1574</span>      regionNode.setLastHost(regionLocation);<a name="line.1574"></a>
+<span class="sourceLineNo">1575</span>      regionStates.removeRegionFromServer(regionLocation, regionNode);<a name="line.1575"></a>
+<span class="sourceLineNo">1576</span>    }<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>  public void markRegionAsSplit(final RegionInfo parent, final ServerName serverName,<a name="line.1579"></a>
+<span class="sourceLineNo">1580</span>      final RegionInfo daughterA, final RegionInfo daughterB) throws IOException {<a name="line.1580"></a>
+<span class="sourceLineNo">1581</span>    // Update hbase:meta. Parent will be marked offline and split up in hbase:meta.<a name="line.1581"></a>
+<span class="sourceLineNo">1582</span>    // The parent stays in regionStates until cleared when removed by CatalogJanitor.<a name="line.1582"></a>
+<span class="sourceLineNo">1583</span>    // Update its state in regionStates to it shows as offline and split when read<a name="line.1583"></a>
+<span class="sourceLineNo">1584</span>    // later figuring what regions are in a table and what are not: see<a name="line.1584"></a>
+<span class="sourceLineNo">1585</span>    // regionStates#getRegionsOfTable<a name="line.1585"></a>
+<span class="sourceLineNo">1586</span>    final RegionStateNode node = regionStates.getOrCreateRegionStateNode(parent);<a name="line.1586"></a>
+<span class="sourceLineNo">1587</span>    node.setState(State.SPLIT);<a name="line.1587"></a>
+<span class="sourceLineNo">1588</span>    final RegionStateNode nodeA = regionStates.getOrCreateRegionStateNode(daughterA);<a name="line.1588"></a>
+<span class="sourceLineNo">1589</span>    nodeA.setState(State.SPLITTING_NEW);<a name="line.1589"></a>
+<span class="sourceLineNo">1590</span>    final RegionStateNode nodeB = regionStates.getOrCreateRegionStateNode(daughterB);<a name="line.1590"></a>
+<span class="sourceLineNo">1591</span>    nodeB.setState(State.SPLITTING_NEW);<a name="line.1591"></a>
+<span class="sourceLineNo">1592</span><a name="line.1592"></a>
+<span class="sourceLineNo">1593</span>    regionStateStore.splitRegion(parent, daughterA, daughterB, serverName);<a name="line.1593"></a>
+<span class="sourceLineNo">1594</span>    if (shouldAssignFavoredNodes(parent)) {<a name="line.1594"></a>
+<span class="sourceLineNo">1595</span>      List&lt;ServerName&gt; onlineServers = this.master.getServerManager().getOnlineServersList();<a name="line.1595"></a>
+<span class="sourceLineNo">1596</span>      ((FavoredNodesPromoter)getBalancer()).<a name="line.1596"></a>
+<span class="sourceLineNo">1597</span>          generateFavoredNodesForDaughter(onlineServers, parent, daughterA, daughterB);<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><a name="line.1600"></a>
+<span class="sourceLineNo">1601</span>  /**<a name="line.1601"></a>
+<span class="sourceLineNo">1602</span>   * When called here, the merge has happened. The two merged regions have been<a name="line.1602"></a>
+<span class="sourceLineNo">1603</span>   * unassigned and the above markRegionClosed has been called on each so they have been<a name="line.1603"></a>
+<span class="sourceLineNo">1604</span>   * disassociated from a hosting Server. The merged region will be open after this call. The<a name="line.1604"></a>
+<span class="sourceLineNo">1605</span>   * merged regions are removed from hbase:meta below&gt; Later they are deleted from the filesystem<a name="line.1605"></a>
+<span class="sourceLineNo">1606</span>   * by the catalog janitor running against hbase:meta. It notices when the merged region no<a name="line.1606"></a>
+<span class="sourceLineNo">1607</span>   * longer holds references to the old regions.<a name="line.1607"></a>
+<span class="sourceLineNo">1608</span>   */<a name="line.1608"></a>
+<span class="sourceLineNo">1609</span>  public void markRegionAsMerged(final RegionInfo child, final ServerName serverName,<a name="line.1609"></a>
+<span class="sourceLineNo">1610</span>      final RegionInfo mother, final RegionInfo father) throws IOException {<a name="line.1610"></a>
+<span class="sourceLineNo">1611</span>    final RegionStateNode node = regionStates.getOrCreateRegionStateNode(child);<a name="line.1611"></a>
+<span class="sourceLineNo">1612</span>    node.setState(State.MERGED);<a name="line.1612"></a>
+<span class="sourceLineNo">1613</span>    regionStates.deleteRegion(mother);<a name="line.1613"></a>
+<span class="sourceLineNo">1614</span>    regionStates.deleteRegion(father);<a name="line.1614"></a>
+<span class="sourceLineNo">1615</span>    regionStateStore.mergeRegions(child, mother, father, serverName);<a name="line.1615"></a>
+<span class="sourceLineNo">1616</span>    if (shouldAssignFavoredNodes(child)) {<a name="line.1616"></a>
+<span class="sourceLineNo">1617</span>      ((FavoredNodesPromoter)getBalancer()).<a name="line.1617"></a>
+<span class="sourceLineNo">1618</span>        generateFavoredNodesForMergedRegion(child, mother, father);<a name="line.1618"></a>
+<span class="sourceLineNo">1619</span>    }<a name="line.1619"></a>
+<span class="sourceLineNo">1620</span>  }<a name="line.1620"></a>
+<span class="sourceLineNo">1621</span><a name="line.1621"></a>
+<span class="sourceLineNo">1622</span>  /*<a name="line.1622"></a>
+<span class="sourceLineNo">1623</span>   * Favored nodes should be applied only when FavoredNodes balancer is configured and the region<a name="line.1623"></a>
+<span class="sourceLineNo">1624</span>   * belongs to a non-system table.<a name="line.1624"></a>
+<span class="sourceLineNo">1625</span>   */<a name="line.1625"></a>
+<span class="sourceLineNo">1626</span>  private boolean shouldAssignFavoredNodes(RegionInfo region) {<a name="line.1626"></a>
+<span class="sourceLineNo">1627</span>    return this.shouldAssignRegionsWithFavoredNodes &amp;&amp;<a name="line.1627"></a>
+<span class="sourceLineNo">1628</span>        FavoredNodesManager.isFavoredNodeApplicable(region);<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>  // ============================================================================================<a name="line.1631"></a>
+<span class="sourceLineNo">1632</span>  //  Assign Queue (Assign/Balance)<a name="line.1632"></a>
+<span class="sourceLineNo">1633</span>  // ============================================================================================<a name="line.1633"></a>
+<span class="sourceLineNo">1634</span>  private final ArrayList&lt;RegionStateNode&gt; pendingAssignQueue = new ArrayList&lt;RegionStateNode&gt;();<a name="line.1634"></a>
+<span class="sourceLineNo">1635</span>  private final ReentrantLock assignQueueLock = new ReentrantLock();<a name="line.1635"></a>
+<span class="sourceLineNo">1636</span>  private final Condition assignQueueFullCond = assignQueueLock.newCondition();<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>   * Add the assign operation to the assignment queue.<a name="line.1639"></a>
+<span class="sourceLineNo">1640</span>   * The pending assignment operation will be processed,<a name="line.1640"></a>
+<span class="sourceLineNo">1641</span>   * and each region will be assigned by a server using the balancer.<a name="line.1641"></a>
+<span class="sourceLineNo">1642</span>   */<a name="line.1642"></a>
+<span class="sourceLineNo">1643</span>  protected void queueAssign(final RegionStateNode regionNode) {<a name="line.1643"></a>
+<span class="sourceLineNo">1644</span>    regionNode.getProcedureEvent().suspend();<a name="line.1644"></a>
+<span class="sourceLineNo">1645</span><a name="line.1645"></a>
+<span class="sourceLineNo">1646</span>    // TODO: quick-start for meta and the other sys-tables?<a name="line.1646"></a>
+<span class="sourceLineNo">1647</span>    assignQueueLock.lock();<a name="line.1647"></a>
+<span class="sourceLineNo">1648</span>    try {<a name="line.1648"></a>
+<span class="sourceLineNo">1649</span>      pendingAssignQueue.add(regionNode);<a name="line.1649"></a>
+<span class="sourceLineNo">1650</span>      if (regionNode.isSystemTable() ||<a name="line.1650"></a>
+<span class="sourceLineNo">1651</span>          pendingAssignQueue.size() == 1 ||<a name="line.1651"></a>
+<span class="sourceLineNo">1652</span>          pendingAssignQueue.size() &gt;= assignDispatchWaitQueueMaxSize) {<a name="line.1652"></a>
+<span class="sourceLineNo">1653</span>        assignQueueFullCond.signal();<a name="line.1653"></a>
+<span class="sourceLineNo">1654</span>      }<a name="line.1654"></a>
+<span class="sourceLineNo">1655</span>    } finally {<a name="line.1655"></a>
+<span class="sourceLineNo">1656</span>      assignQueueLock.unlock();<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><a name="line.1659"></a>
+<span class="sourceLineNo">1660</span>  private void startAssignmentThread() {<a name="line.1660"></a>
+<span class="sourceLineNo">1661</span>    // Get Server Thread name. Sometimes the Server is mocked so may not implement HasThread.<a name="line.1661"></a>
+<span class="sourceLineNo">1662</span>    // For exampl

<TRUNCATED>

Mime
View raw message