http://git-wip-us.apache.org/repos/asf/hbase-site/blob/aa3fb87f/devapidocs/src-html/org/apache/hadoop/hbase/master/assignment/AssignmentManager.RegionInTransitionChore.html
----------------------------------------------------------------------
diff --git 
a/devapidocs/src-html/org/apache/hadoop/hbase/master/assignment/AssignmentManager.RegionInTransitionChore.html
 
b/devapidocs/src-html/org/apache/hadoop/hbase/master/assignment/AssignmentManager.RegionInTransitionChore.html
index e763690..f66043c 100644
--- 
a/devapidocs/src-html/org/apache/hadoop/hbase/master/assignment/AssignmentManager.RegionInTransitionChore.html
+++ 
b/devapidocs/src-html/org/apache/hadoop/hbase/master/assignment/AssignmentManager.RegionInTransitionChore.html
@@ -1301,610 +1301,613 @@
 <span class="sourceLineNo">1293</span>        }<a name="line.1293"></a>
 <span class="sourceLineNo">1294</span>        RegionStateNode regionNode = 
regionStates.getOrCreateRegionStateNode(regionInfo);<a name="line.1294"></a>
 <span class="sourceLineNo">1295</span>        // Do not need to lock on 
regionNode, as we can make sure that before we finish loading<a 
name="line.1295"></a>
-<span class="sourceLineNo">1296</span>        // meta, all the related 
procedures can not be executed. The only exception is formeta<a 
name="line.1296"></a>
+<span class="sourceLineNo">1296</span>        // meta, all the related 
procedures can not be executed. The only exception is for meta<a 
name="line.1296"></a>
 <span class="sourceLineNo">1297</span>        // region related operations, 
but here we do not load the informations for meta region.<a 
name="line.1297"></a>
 <span class="sourceLineNo">1298</span>        
regionNode.setState(localState);<a name="line.1298"></a>
 <span class="sourceLineNo">1299</span>        
regionNode.setLastHost(lastHost);<a name="line.1299"></a>
 <span class="sourceLineNo">1300</span>        
regionNode.setRegionLocation(regionLocation);<a name="line.1300"></a>
 <span class="sourceLineNo">1301</span>        
regionNode.setOpenSeqNum(openSeqNum);<a name="line.1301"></a>
 <span class="sourceLineNo">1302</span><a name="line.1302"></a>
-<span class="sourceLineNo">1303</span>        if (localState == State.OPEN) 
{<a name="line.1303"></a>
-<span class="sourceLineNo">1304</span>          assert regionLocation != null 
: "found null region location for " + regionNode;<a name="line.1304"></a>
-<span class="sourceLineNo">1305</span>          
regionStates.addRegionToServer(regionNode);<a name="line.1305"></a>
-<span class="sourceLineNo">1306</span>        } else if (localState == 
State.OFFLINE || regionInfo.isOffline()) {<a name="line.1306"></a>
-<span class="sourceLineNo">1307</span>          
regionStates.addToOfflineRegions(regionNode);<a name="line.1307"></a>
-<span class="sourceLineNo">1308</span>        }<a name="line.1308"></a>
-<span class="sourceLineNo">1309</span>      }<a name="line.1309"></a>
-<span class="sourceLineNo">1310</span>    });<a name="line.1310"></a>
-<span class="sourceLineNo">1311</span><a name="line.1311"></a>
-<span class="sourceLineNo">1312</span>    // every assignment is blocked until 
meta is loaded.<a name="line.1312"></a>
-<span class="sourceLineNo">1313</span>    wakeMetaLoadedEvent();<a 
name="line.1313"></a>
-<span class="sourceLineNo">1314</span>  }<a name="line.1314"></a>
-<span class="sourceLineNo">1315</span><a name="line.1315"></a>
-<span class="sourceLineNo">1316</span>  /**<a name="line.1316"></a>
-<span class="sourceLineNo">1317</span>   * Used to check if the meta loading 
is done.<a name="line.1317"></a>
-<span class="sourceLineNo">1318</span>   * &lt;p/&gt;<a name="line.1318"></a>
-<span class="sourceLineNo">1319</span>   * if not we throw PleaseHoldException 
since we are rebuilding the RegionStates<a name="line.1319"></a>
-<span class="sourceLineNo">1320</span>   * @param hri region to check if it is 
already rebuild<a name="line.1320"></a>
-<span class="sourceLineNo">1321</span>   * @throws PleaseHoldException if meta 
has not been loaded yet<a name="line.1321"></a>
-<span class="sourceLineNo">1322</span>   */<a name="line.1322"></a>
-<span class="sourceLineNo">1323</span>  private void 
checkMetaLoaded(RegionInfo hri) throws PleaseHoldException {<a 
name="line.1323"></a>
-<span class="sourceLineNo">1324</span>    if (!isRunning()) {<a 
name="line.1324"></a>
-<span class="sourceLineNo">1325</span>      throw new 
PleaseHoldException("AssignmentManager not running");<a name="line.1325"></a>
-<span class="sourceLineNo">1326</span>    }<a name="line.1326"></a>
-<span class="sourceLineNo">1327</span>    boolean meta = isMetaRegion(hri);<a 
name="line.1327"></a>
-<span class="sourceLineNo">1328</span>    boolean metaLoaded = 
isMetaLoaded();<a name="line.1328"></a>
-<span class="sourceLineNo">1329</span>    if (!meta &amp;&amp; !metaLoaded) 
{<a name="line.1329"></a>
-<span class="sourceLineNo">1330</span>      throw new PleaseHoldException(<a 
name="line.1330"></a>
-<span class="sourceLineNo">1331</span>        "Master not fully online; 
hbase:meta=" + meta + ", metaLoaded=" + metaLoaded);<a name="line.1331"></a>
-<span class="sourceLineNo">1332</span>    }<a name="line.1332"></a>
-<span class="sourceLineNo">1333</span>  }<a name="line.1333"></a>
-<span class="sourceLineNo">1334</span><a name="line.1334"></a>
-<span class="sourceLineNo">1335</span>  // 
============================================================================================<a
 name="line.1335"></a>
-<span class="sourceLineNo">1336</span>  //  TODO: Metrics<a 
name="line.1336"></a>
-<span class="sourceLineNo">1337</span>  // 
============================================================================================<a
 name="line.1337"></a>
-<span class="sourceLineNo">1338</span>  public int getNumRegionsOpened() {<a 
name="line.1338"></a>
-<span class="sourceLineNo">1339</span>    // TODO: Used by 
TestRegionPlacement.java and assume monotonically increasing value<a 
name="line.1339"></a>
-<span class="sourceLineNo">1340</span>    return 0;<a name="line.1340"></a>
-<span class="sourceLineNo">1341</span>  }<a name="line.1341"></a>
-<span class="sourceLineNo">1342</span><a name="line.1342"></a>
-<span class="sourceLineNo">1343</span>  public long 
submitServerCrash(ServerName serverName, boolean shouldSplitWal) {<a 
name="line.1343"></a>
-<span class="sourceLineNo">1344</span>    boolean carryingMeta;<a 
name="line.1344"></a>
-<span class="sourceLineNo">1345</span>    long pid;<a name="line.1345"></a>
-<span class="sourceLineNo">1346</span>    ServerStateNode serverNode = 
regionStates.getServerNode(serverName);<a name="line.1346"></a>
-<span class="sourceLineNo">1347</span>    if(serverNode == null){<a 
name="line.1347"></a>
-<span class="sourceLineNo">1348</span>      LOG.info("Skip to add SCP for {} 
since this server should be OFFLINE already", serverName);<a 
name="line.1348"></a>
-<span class="sourceLineNo">1349</span>      return -1;<a name="line.1349"></a>
-<span class="sourceLineNo">1350</span>    }<a name="line.1350"></a>
-<span class="sourceLineNo">1351</span>    // we hold the write lock here for 
fencing on reportRegionStateTransition. Once we set the<a name="line.1351"></a>
-<span class="sourceLineNo">1352</span>    // server state to CRASHED, we will 
no longer accept the reportRegionStateTransition call from<a 
name="line.1352"></a>
-<span class="sourceLineNo">1353</span>    // this server. This is used to 
simplify the implementation for TRSP and SCP, where we can make<a 
name="line.1353"></a>
-<span class="sourceLineNo">1354</span>    // sure that, the region list 
fetched by SCP will not be changed any more.<a name="line.1354"></a>
-<span class="sourceLineNo">1355</span>    serverNode.writeLock().lock();<a 
name="line.1355"></a>
-<span class="sourceLineNo">1356</span>    try {<a name="line.1356"></a>
-<span class="sourceLineNo">1357</span>      
ProcedureExecutor&lt;MasterProcedureEnv&gt; procExec = 
this.master.getMasterProcedureExecutor();<a name="line.1357"></a>
-<span class="sourceLineNo">1358</span>      carryingMeta = 
isCarryingMeta(serverName);<a name="line.1358"></a>
-<span class="sourceLineNo">1359</span>      if 
(!serverNode.isInState(ServerState.ONLINE)) {<a name="line.1359"></a>
-<span class="sourceLineNo">1360</span>        LOG.info(<a name="line.1360"></a>
-<span class="sourceLineNo">1361</span>          "Skip to add SCP for {} with 
meta= {}, " +<a name="line.1361"></a>
-<span class="sourceLineNo">1362</span>              "since there should be a 
SCP is processing or already done for this server node",<a name="line.1362"></a>
-<span class="sourceLineNo">1363</span>          serverName, carryingMeta);<a 
name="line.1363"></a>
-<span class="sourceLineNo">1364</span>        return -1;<a 
name="line.1364"></a>
-<span class="sourceLineNo">1365</span>      } else {<a name="line.1365"></a>
-<span class="sourceLineNo">1366</span>        
serverNode.setState(ServerState.CRASHED);<a name="line.1366"></a>
-<span class="sourceLineNo">1367</span>        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.info(<a name="line.1369"></a>
-<span class="sourceLineNo">1370</span>          "Added {} to dead servers 
which carryingMeta={}, submitted ServerCrashProcedure pid={}",<a 
name="line.1370"></a>
-<span class="sourceLineNo">1371</span>          serverName, carryingMeta, 
pid);<a name="line.1371"></a>
-<span class="sourceLineNo">1372</span>      }<a name="line.1372"></a>
-<span class="sourceLineNo">1373</span>    } finally {<a name="line.1373"></a>
-<span class="sourceLineNo">1374</span>      serverNode.writeLock().unlock();<a 
name="line.1374"></a>
-<span class="sourceLineNo">1375</span>    }<a name="line.1375"></a>
-<span class="sourceLineNo">1376</span>    return pid;<a name="line.1376"></a>
-<span class="sourceLineNo">1377</span>  }<a name="line.1377"></a>
-<span class="sourceLineNo">1378</span><a name="line.1378"></a>
-<span class="sourceLineNo">1379</span>  public void offlineRegion(final 
RegionInfo regionInfo) {<a name="line.1379"></a>
-<span class="sourceLineNo">1380</span>    // TODO used by MasterRpcServices<a 
name="line.1380"></a>
-<span class="sourceLineNo">1381</span>    RegionStateNode node = 
regionStates.getRegionStateNode(regionInfo);<a name="line.1381"></a>
-<span class="sourceLineNo">1382</span>    if (node != null) {<a 
name="line.1382"></a>
-<span class="sourceLineNo">1383</span>      node.offline();<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><a name="line.1386"></a>
-<span class="sourceLineNo">1387</span>  public void onlineRegion(final 
RegionInfo regionInfo, final ServerName serverName) {<a name="line.1387"></a>
-<span class="sourceLineNo">1388</span>    // TODO used by 
TestSplitTransactionOnCluster.java<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>  public Map&lt;ServerName, 
List&lt;RegionInfo&gt;&gt; getSnapShotOfAssignment(<a name="line.1391"></a>
-<span class="sourceLineNo">1392</span>      final Collection&lt;RegionInfo&gt; 
regions) {<a name="line.1392"></a>
-<span class="sourceLineNo">1393</span>    return 
regionStates.getSnapShotOfAssignment(regions);<a name="line.1393"></a>
-<span class="sourceLineNo">1394</span>  }<a name="line.1394"></a>
-<span class="sourceLineNo">1395</span><a name="line.1395"></a>
-<span class="sourceLineNo">1396</span>  // 
============================================================================================<a
 name="line.1396"></a>
-<span class="sourceLineNo">1397</span>  //  TODO: UTILS/HELPERS?<a 
name="line.1397"></a>
-<span class="sourceLineNo">1398</span>  // 
============================================================================================<a
 name="line.1398"></a>
-<span class="sourceLineNo">1399</span>  /**<a name="line.1399"></a>
-<span class="sourceLineNo">1400</span>   * Used by the client (via master) to 
identify if all regions have the schema updates<a name="line.1400"></a>
-<span class="sourceLineNo">1401</span>   *<a name="line.1401"></a>
-<span class="sourceLineNo">1402</span>   * @param tableName<a 
name="line.1402"></a>
-<span class="sourceLineNo">1403</span>   * @return Pair indicating the status 
of the alter command (pending/total)<a name="line.1403"></a>
-<span class="sourceLineNo">1404</span>   * @throws IOException<a 
name="line.1404"></a>
-<span class="sourceLineNo">1405</span>   */<a name="line.1405"></a>
-<span class="sourceLineNo">1406</span>  public Pair&lt;Integer, Integer&gt; 
getReopenStatus(TableName tableName) {<a name="line.1406"></a>
-<span class="sourceLineNo">1407</span>    if (isTableDisabled(tableName)) 
return new Pair&lt;Integer, Integer&gt;(0, 0);<a name="line.1407"></a>
-<span class="sourceLineNo">1408</span><a name="line.1408"></a>
-<span class="sourceLineNo">1409</span>    final List&lt;RegionState&gt; states 
= regionStates.getTableRegionStates(tableName);<a name="line.1409"></a>
-<span class="sourceLineNo">1410</span>    int ritCount = 0;<a 
name="line.1410"></a>
-<span class="sourceLineNo">1411</span>    for (RegionState regionState: 
states) {<a name="line.1411"></a>
-<span class="sourceLineNo">1412</span>      if (!regionState.isOpened()) 
ritCount++;<a name="line.1412"></a>
-<span class="sourceLineNo">1413</span>    }<a name="line.1413"></a>
-<span class="sourceLineNo">1414</span>    return new Pair&lt;Integer, 
Integer&gt;(ritCount, states.size());<a name="line.1414"></a>
-<span class="sourceLineNo">1415</span>  }<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>  //  TODO: Region State In Transition<a 
name="line.1418"></a>
-<span class="sourceLineNo">1419</span>  // 
============================================================================================<a
 name="line.1419"></a>
-<span class="sourceLineNo">1420</span>  public boolean 
hasRegionsInTransition() {<a name="line.1420"></a>
-<span class="sourceLineNo">1421</span>    return 
regionStates.hasRegionsInTransition();<a name="line.1421"></a>
-<span class="sourceLineNo">1422</span>  }<a name="line.1422"></a>
-<span class="sourceLineNo">1423</span><a name="line.1423"></a>
-<span class="sourceLineNo">1424</span>  public List&lt;RegionStateNode&gt; 
getRegionsInTransition() {<a name="line.1424"></a>
-<span class="sourceLineNo">1425</span>    return 
regionStates.getRegionsInTransition();<a name="line.1425"></a>
-<span class="sourceLineNo">1426</span>  }<a name="line.1426"></a>
-<span class="sourceLineNo">1427</span><a name="line.1427"></a>
-<span class="sourceLineNo">1428</span>  public List&lt;RegionInfo&gt; 
getAssignedRegions() {<a name="line.1428"></a>
-<span class="sourceLineNo">1429</span>    return 
regionStates.getAssignedRegions();<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>  public RegionInfo getRegionInfo(final 
byte[] regionName) {<a name="line.1432"></a>
-<span class="sourceLineNo">1433</span>    final RegionStateNode regionState = 
regionStates.getRegionStateNodeFromName(regionName);<a name="line.1433"></a>
-<span class="sourceLineNo">1434</span>    return regionState != null ? 
regionState.getRegionInfo() : null;<a name="line.1434"></a>
-<span class="sourceLineNo">1435</span>  }<a name="line.1435"></a>
-<span class="sourceLineNo">1436</span><a name="line.1436"></a>
-<span class="sourceLineNo">1437</span>  // 
============================================================================================<a
 name="line.1437"></a>
-<span class="sourceLineNo">1438</span>  //  Expected states on region state 
transition.<a name="line.1438"></a>
-<span class="sourceLineNo">1439</span>  //  Notice that there is expected 
states for transiting to OPENING state, this is because SCP.<a 
name="line.1439"></a>
-<span class="sourceLineNo">1440</span>  //  See the comments in regionOpening 
method for more details.<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_OPEN = {<a name="line.1442"></a>
-<span class="sourceLineNo">1443</span>    State.OPENING, // Normal case<a 
name="line.1443"></a>
-<span class="sourceLineNo">1444</span>    State.OPEN // Retrying<a 
name="line.1444"></a>
-<span class="sourceLineNo">1445</span>  };<a name="line.1445"></a>
-<span class="sourceLineNo">1446</span><a name="line.1446"></a>
-<span class="sourceLineNo">1447</span>  private static final State[] 
STATES_EXPECTED_ON_CLOSING = {<a name="line.1447"></a>
-<span class="sourceLineNo">1448</span>    State.OPEN, // Normal case<a 
name="line.1448"></a>
-<span class="sourceLineNo">1449</span>    State.CLOSING, // Retrying<a 
name="line.1449"></a>
-<span class="sourceLineNo">1450</span>    State.SPLITTING, // Offline the 
split parent<a name="line.1450"></a>
-<span class="sourceLineNo">1451</span>    State.MERGING // Offline the merge 
parents<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>  private static final State[] 
STATES_EXPECTED_ON_CLOSED = {<a name="line.1454"></a>
-<span class="sourceLineNo">1455</span>    State.CLOSING, // Normal case<a 
name="line.1455"></a>
-<span class="sourceLineNo">1456</span>    State.CLOSED // Retrying<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>  // This is for manually scheduled 
region assign, can add other states later if we find out other<a 
name="line.1459"></a>
-<span class="sourceLineNo">1460</span>  // usages<a name="line.1460"></a>
-<span class="sourceLineNo">1461</span>  private static final State[] 
STATES_EXPECTED_ON_ASSIGN = { State.CLOSED, State.OFFLINE };<a 
name="line.1461"></a>
-<span class="sourceLineNo">1462</span><a name="line.1462"></a>
-<span class="sourceLineNo">1463</span>  // We only allow unassign or move a 
region which is in OPEN state.<a name="line.1463"></a>
-<span class="sourceLineNo">1464</span>  private static final State[] 
STATES_EXPECTED_ON_UNASSIGN_OR_MOVE = { State.OPEN };<a name="line.1464"></a>
+<span class="sourceLineNo">1303</span>        // Note: keep consistent with 
other methods, see region(Opening|Opened|Closing)<a name="line.1303"></a>
+<span class="sourceLineNo">1304</span>        //       RIT/ServerCrash 
handling should take care of the transiting regions.<a name="line.1304"></a>
+<span class="sourceLineNo">1305</span>        if 
(localState.matches(State.OPEN, State.OPENING, State.CLOSING, 
State.SPLITTING,<a name="line.1305"></a>
+<span class="sourceLineNo">1306</span>          State.MERGING)) {<a 
name="line.1306"></a>
+<span class="sourceLineNo">1307</span>          assert regionLocation != null 
: "found null region location for " + regionNode;<a name="line.1307"></a>
+<span class="sourceLineNo">1308</span>          
regionStates.addRegionToServer(regionNode);<a name="line.1308"></a>
+<span class="sourceLineNo">1309</span>        } else if (localState == 
State.OFFLINE || regionInfo.isOffline()) {<a name="line.1309"></a>
+<span class="sourceLineNo">1310</span>          
regionStates.addToOfflineRegions(regionNode);<a name="line.1310"></a>
+<span class="sourceLineNo">1311</span>        }<a name="line.1311"></a>
+<span class="sourceLineNo">1312</span>      }<a name="line.1312"></a>
+<span class="sourceLineNo">1313</span>    });<a name="line.1313"></a>
+<span class="sourceLineNo">1314</span><a name="line.1314"></a>
+<span class="sourceLineNo">1315</span>    // every assignment is blocked until 
meta is loaded.<a name="line.1315"></a>
+<span class="sourceLineNo">1316</span>    wakeMetaLoadedEvent();<a 
name="line.1316"></a>
+<span class="sourceLineNo">1317</span>  }<a name="line.1317"></a>
+<span class="sourceLineNo">1318</span><a name="line.1318"></a>
+<span class="sourceLineNo">1319</span>  /**<a name="line.1319"></a>
+<span class="sourceLineNo">1320</span>   * Used to check if the meta loading 
is done.<a name="line.1320"></a>
+<span class="sourceLineNo">1321</span>   * &lt;p/&gt;<a name="line.1321"></a>
+<span class="sourceLineNo">1322</span>   * if not we throw PleaseHoldException 
since we are rebuilding the RegionStates<a name="line.1322"></a>
+<span class="sourceLineNo">1323</span>   * @param hri region to check if it is 
already rebuild<a name="line.1323"></a>
+<span class="sourceLineNo">1324</span>   * @throws PleaseHoldException if meta 
has not been loaded yet<a name="line.1324"></a>
+<span class="sourceLineNo">1325</span>   */<a name="line.1325"></a>
+<span class="sourceLineNo">1326</span>  private void 
checkMetaLoaded(RegionInfo hri) throws PleaseHoldException {<a 
name="line.1326"></a>
+<span class="sourceLineNo">1327</span>    if (!isRunning()) {<a 
name="line.1327"></a>
+<span class="sourceLineNo">1328</span>      throw new 
PleaseHoldException("AssignmentManager not running");<a name="line.1328"></a>
+<span class="sourceLineNo">1329</span>    }<a name="line.1329"></a>
+<span class="sourceLineNo">1330</span>    boolean meta = isMetaRegion(hri);<a 
name="line.1330"></a>
+<span class="sourceLineNo">1331</span>    boolean metaLoaded = 
isMetaLoaded();<a name="line.1331"></a>
+<span class="sourceLineNo">1332</span>    if (!meta &amp;&amp; !metaLoaded) 
{<a name="line.1332"></a>
+<span class="sourceLineNo">1333</span>      throw new PleaseHoldException(<a 
name="line.1333"></a>
+<span class="sourceLineNo">1334</span>        "Master not fully online; 
hbase:meta=" + meta + ", metaLoaded=" + metaLoaded);<a name="line.1334"></a>
+<span class="sourceLineNo">1335</span>    }<a name="line.1335"></a>
+<span class="sourceLineNo">1336</span>  }<a name="line.1336"></a>
+<span class="sourceLineNo">1337</span><a name="line.1337"></a>
+<span class="sourceLineNo">1338</span>  // 
============================================================================================<a
 name="line.1338"></a>
+<span class="sourceLineNo">1339</span>  //  TODO: Metrics<a 
name="line.1339"></a>
+<span class="sourceLineNo">1340</span>  // 
============================================================================================<a
 name="line.1340"></a>
+<span class="sourceLineNo">1341</span>  public int getNumRegionsOpened() {<a 
name="line.1341"></a>
+<span class="sourceLineNo">1342</span>    // TODO: Used by 
TestRegionPlacement.java and assume monotonically increasing value<a 
name="line.1342"></a>
+<span class="sourceLineNo">1343</span>    return 0;<a name="line.1343"></a>
+<span class="sourceLineNo">1344</span>  }<a name="line.1344"></a>
+<span class="sourceLineNo">1345</span><a name="line.1345"></a>
+<span class="sourceLineNo">1346</span>  public long 
submitServerCrash(ServerName serverName, boolean shouldSplitWal) {<a 
name="line.1346"></a>
+<span class="sourceLineNo">1347</span>    boolean carryingMeta;<a 
name="line.1347"></a>
+<span class="sourceLineNo">1348</span>    long pid;<a name="line.1348"></a>
+<span class="sourceLineNo">1349</span>    ServerStateNode serverNode = 
regionStates.getServerNode(serverName);<a name="line.1349"></a>
+<span class="sourceLineNo">1350</span>    if(serverNode == null){<a 
name="line.1350"></a>
+<span class="sourceLineNo">1351</span>      LOG.info("Skip to add SCP for {} 
since this server should be OFFLINE already", serverName);<a 
name="line.1351"></a>
+<span class="sourceLineNo">1352</span>      return -1;<a name="line.1352"></a>
+<span class="sourceLineNo">1353</span>    }<a name="line.1353"></a>
+<span class="sourceLineNo">1354</span>    // we hold the write lock here for 
fencing on reportRegionStateTransition. Once we set the<a name="line.1354"></a>
+<span class="sourceLineNo">1355</span>    // server state to CRASHED, we will 
no longer accept the reportRegionStateTransition call from<a 
name="line.1355"></a>
+<span class="sourceLineNo">1356</span>    // this server. This is used to 
simplify the implementation for TRSP and SCP, where we can make<a 
name="line.1356"></a>
+<span class="sourceLineNo">1357</span>    // sure that, the region list 
fetched by SCP will not be changed any more.<a name="line.1357"></a>
+<span class="sourceLineNo">1358</span>    serverNode.writeLock().lock();<a 
name="line.1358"></a>
+<span class="sourceLineNo">1359</span>    try {<a name="line.1359"></a>
+<span class="sourceLineNo">1360</span>      
ProcedureExecutor&lt;MasterProcedureEnv&gt; procExec = 
this.master.getMasterProcedureExecutor();<a name="line.1360"></a>
+<span class="sourceLineNo">1361</span>      carryingMeta = 
isCarryingMeta(serverName);<a name="line.1361"></a>
+<span class="sourceLineNo">1362</span>      if 
(!serverNode.isInState(ServerState.ONLINE)) {<a name="line.1362"></a>
+<span class="sourceLineNo">1363</span>        LOG.info(<a name="line.1363"></a>
+<span class="sourceLineNo">1364</span>          "Skip to add SCP for {} with 
meta= {}, " +<a name="line.1364"></a>
+<span class="sourceLineNo">1365</span>              "since there should be a 
SCP is processing or already done for this server node",<a name="line.1365"></a>
+<span class="sourceLineNo">1366</span>          serverName, carryingMeta);<a 
name="line.1366"></a>
+<span class="sourceLineNo">1367</span>        return -1;<a 
name="line.1367"></a>
+<span class="sourceLineNo">1368</span>      } else {<a name="line.1368"></a>
+<span class="sourceLineNo">1369</span>        
serverNode.setState(ServerState.CRASHED);<a name="line.1369"></a>
+<span class="sourceLineNo">1370</span>        pid = 
procExec.submitProcedure(new ServerCrashProcedure(procExec.getEnvironment(),<a 
name="line.1370"></a>
+<span class="sourceLineNo">1371</span>            serverName, shouldSplitWal, 
carryingMeta));<a name="line.1371"></a>
+<span class="sourceLineNo">1372</span>        LOG.info(<a name="line.1372"></a>
+<span class="sourceLineNo">1373</span>          "Added {} to dead servers 
which carryingMeta={}, submitted ServerCrashProcedure pid={}",<a 
name="line.1373"></a>
+<span class="sourceLineNo">1374</span>          serverName, carryingMeta, 
pid);<a name="line.1374"></a>
+<span class="sourceLineNo">1375</span>      }<a name="line.1375"></a>
+<span class="sourceLineNo">1376</span>    } finally {<a name="line.1376"></a>
+<span class="sourceLineNo">1377</span>      serverNode.writeLock().unlock();<a 
name="line.1377"></a>
+<span class="sourceLineNo">1378</span>    }<a name="line.1378"></a>
+<span class="sourceLineNo">1379</span>    return pid;<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 offlineRegion(final 
RegionInfo regionInfo) {<a name="line.1382"></a>
+<span class="sourceLineNo">1383</span>    // TODO used by MasterRpcServices<a 
name="line.1383"></a>
+<span class="sourceLineNo">1384</span>    RegionStateNode node = 
regionStates.getRegionStateNode(regionInfo);<a name="line.1384"></a>
+<span class="sourceLineNo">1385</span>    if (node != null) {<a 
name="line.1385"></a>
+<span class="sourceLineNo">1386</span>      node.offline();<a 
name="line.1386"></a>
+<span class="sourceLineNo">1387</span>    }<a name="line.1387"></a>
+<span class="sourceLineNo">1388</span>  }<a name="line.1388"></a>
+<span class="sourceLineNo">1389</span><a name="line.1389"></a>
+<span class="sourceLineNo">1390</span>  public void onlineRegion(final 
RegionInfo regionInfo, final ServerName serverName) {<a name="line.1390"></a>
+<span class="sourceLineNo">1391</span>    // TODO used by 
TestSplitTransactionOnCluster.java<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>  public Map&lt;ServerName, 
List&lt;RegionInfo&gt;&gt; getSnapShotOfAssignment(<a name="line.1394"></a>
+<span class="sourceLineNo">1395</span>      final Collection&lt;RegionInfo&gt; 
regions) {<a name="line.1395"></a>
+<span class="sourceLineNo">1396</span>    return 
regionStates.getSnapShotOfAssignment(regions);<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>  // 
============================================================================================<a
 name="line.1399"></a>
+<span class="sourceLineNo">1400</span>  //  TODO: UTILS/HELPERS?<a 
name="line.1400"></a>
+<span class="sourceLineNo">1401</span>  // 
============================================================================================<a
 name="line.1401"></a>
+<span class="sourceLineNo">1402</span>  /**<a name="line.1402"></a>
+<span class="sourceLineNo">1403</span>   * Used by the client (via master) to 
identify if all regions have the schema updates<a name="line.1403"></a>
+<span class="sourceLineNo">1404</span>   *<a name="line.1404"></a>
+<span class="sourceLineNo">1405</span>   * @param tableName<a 
name="line.1405"></a>
+<span class="sourceLineNo">1406</span>   * @return Pair indicating the status 
of the alter command (pending/total)<a name="line.1406"></a>
+<span class="sourceLineNo">1407</span>   * @throws IOException<a 
name="line.1407"></a>
+<span class="sourceLineNo">1408</span>   */<a name="line.1408"></a>
+<span class="sourceLineNo">1409</span>  public Pair&lt;Integer, Integer&gt; 
getReopenStatus(TableName tableName) {<a name="line.1409"></a>
+<span class="sourceLineNo">1410</span>    if (isTableDisabled(tableName)) 
return new Pair&lt;Integer, Integer&gt;(0, 0);<a name="line.1410"></a>
+<span class="sourceLineNo">1411</span><a name="line.1411"></a>
+<span class="sourceLineNo">1412</span>    final List&lt;RegionState&gt; states 
= regionStates.getTableRegionStates(tableName);<a name="line.1412"></a>
+<span class="sourceLineNo">1413</span>    int ritCount = 0;<a 
name="line.1413"></a>
+<span class="sourceLineNo">1414</span>    for (RegionState regionState: 
states) {<a name="line.1414"></a>
+<span class="sourceLineNo">1415</span>      if (!regionState.isOpened()) 
ritCount++;<a name="line.1415"></a>
+<span class="sourceLineNo">1416</span>    }<a name="line.1416"></a>
+<span class="sourceLineNo">1417</span>    return new Pair&lt;Integer, 
Integer&gt;(ritCount, states.size());<a name="line.1417"></a>
+<span class="sourceLineNo">1418</span>  }<a name="line.1418"></a>
+<span class="sourceLineNo">1419</span><a name="line.1419"></a>
+<span class="sourceLineNo">1420</span>  // 
============================================================================================<a
 name="line.1420"></a>
+<span class="sourceLineNo">1421</span>  //  TODO: Region State In Transition<a 
name="line.1421"></a>
+<span class="sourceLineNo">1422</span>  // 
============================================================================================<a
 name="line.1422"></a>
+<span class="sourceLineNo">1423</span>  public boolean 
hasRegionsInTransition() {<a name="line.1423"></a>
+<span class="sourceLineNo">1424</span>    return 
regionStates.hasRegionsInTransition();<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 List&lt;RegionStateNode&gt; 
getRegionsInTransition() {<a name="line.1427"></a>
+<span class="sourceLineNo">1428</span>    return 
regionStates.getRegionsInTransition();<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>  public List&lt;RegionInfo&gt; 
getAssignedRegions() {<a name="line.1431"></a>
+<span class="sourceLineNo">1432</span>    return 
regionStates.getAssignedRegions();<a name="line.1432"></a>
+<span class="sourceLineNo">1433</span>  }<a name="line.1433"></a>
+<span class="sourceLineNo">1434</span><a name="line.1434"></a>
+<span class="sourceLineNo">1435</span>  public RegionInfo getRegionInfo(final 
byte[] regionName) {<a name="line.1435"></a>
+<span class="sourceLineNo">1436</span>    final RegionStateNode regionState = 
regionStates.getRegionStateNodeFromName(regionName);<a name="line.1436"></a>
+<span class="sourceLineNo">1437</span>    return regionState != null ? 
regionState.getRegionInfo() : null;<a name="line.1437"></a>
+<span class="sourceLineNo">1438</span>  }<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>  //  Expected states on region state 
transition.<a name="line.1441"></a>
+<span class="sourceLineNo">1442</span>  //  Notice that there is expected 
states for transiting to OPENING state, this is because SCP.<a 
name="line.1442"></a>
+<span class="sourceLineNo">1443</span>  //  See the comments in regionOpening 
method for more details.<a name="line.1443"></a>
+<span class="sourceLineNo">1444</span>  // 
============================================================================================<a
 name="line.1444"></a>
+<span class="sourceLineNo">1445</span>  private static final State[] 
STATES_EXPECTED_ON_OPEN = {<a name="line.1445"></a>
+<span class="sourceLineNo">1446</span>    State.OPENING, // Normal case<a 
name="line.1446"></a>
+<span class="sourceLineNo">1447</span>    State.OPEN // Retrying<a 
name="line.1447"></a>
+<span class="sourceLineNo">1448</span>  };<a name="line.1448"></a>
+<span class="sourceLineNo">1449</span><a name="line.1449"></a>
+<span class="sourceLineNo">1450</span>  private static final State[] 
STATES_EXPECTED_ON_CLOSING = {<a name="line.1450"></a>
+<span class="sourceLineNo">1451</span>    State.OPEN, // Normal case<a 
name="line.1451"></a>
+<span class="sourceLineNo">1452</span>    State.CLOSING, // Retrying<a 
name="line.1452"></a>
+<span class="sourceLineNo">1453</span>    State.SPLITTING, // Offline the 
split parent<a name="line.1453"></a>
+<span class="sourceLineNo">1454</span>    State.MERGING // Offline the merge 
parents<a name="line.1454"></a>
+<span class="sourceLineNo">1455</span>  };<a name="line.1455"></a>
+<span class="sourceLineNo">1456</span><a name="line.1456"></a>
+<span class="sourceLineNo">1457</span>  private static final State[] 
STATES_EXPECTED_ON_CLOSED = {<a name="line.1457"></a>
+<span class="sourceLineNo">1458</span>    State.CLOSING, // Normal case<a 
name="line.1458"></a>
+<span class="sourceLineNo">1459</span>    State.CLOSED // Retrying<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>  // This is for manually scheduled 
region assign, can add other states later if we find out other<a 
name="line.1462"></a>
+<span class="sourceLineNo">1463</span>  // usages<a name="line.1463"></a>
+<span class="sourceLineNo">1464</span>  private static final State[] 
STATES_EXPECTED_ON_ASSIGN = { State.CLOSED, State.OFFLINE };<a 
name="line.1464"></a>
 <span class="sourceLineNo">1465</span><a name="line.1465"></a>
-<span class="sourceLineNo">1466</span>  // 
============================================================================================<a
 name="line.1466"></a>
-<span class="sourceLineNo">1467</span>  //  Region Status update<a 
name="line.1467"></a>
-<span class="sourceLineNo">1468</span>  //  Should only be called in 
TransitRegionStateProcedure<a name="line.1468"></a>
+<span class="sourceLineNo">1466</span>  // We only allow unassign or move a 
region which is in OPEN state.<a name="line.1466"></a>
+<span class="sourceLineNo">1467</span>  private static final State[] 
STATES_EXPECTED_ON_UNASSIGN_OR_MOVE = { State.OPEN };<a name="line.1467"></a>
+<span class="sourceLineNo">1468</span><a name="line.1468"></a>
 <span class="sourceLineNo">1469</span>  // 
============================================================================================<a
 name="line.1469"></a>
-<span class="sourceLineNo">1470</span>  private void 
transitStateAndUpdate(RegionStateNode regionNode, RegionState.State newState,<a 
name="line.1470"></a>
-<span class="sourceLineNo">1471</span>      RegionState.State... 
expectedStates) throws IOException {<a name="line.1471"></a>
-<span class="sourceLineNo">1472</span>    RegionState.State state = 
regionNode.getState();<a name="line.1472"></a>
-<span class="sourceLineNo">1473</span>    regionNode.transitionState(newState, 
expectedStates);<a name="line.1473"></a>
-<span class="sourceLineNo">1474</span>    boolean succ = false;<a 
name="line.1474"></a>
-<span class="sourceLineNo">1475</span>    try {<a name="line.1475"></a>
-<span class="sourceLineNo">1476</span>      
regionStateStore.updateRegionLocation(regionNode);<a name="line.1476"></a>
-<span class="sourceLineNo">1477</span>      succ = true;<a 
name="line.1477"></a>
-<span class="sourceLineNo">1478</span>    } finally {<a name="line.1478"></a>
-<span class="sourceLineNo">1479</span>      if (!succ) {<a 
name="line.1479"></a>
-<span class="sourceLineNo">1480</span>        // revert<a name="line.1480"></a>
-<span class="sourceLineNo">1481</span>        regionNode.setState(state);<a 
name="line.1481"></a>
-<span class="sourceLineNo">1482</span>      }<a name="line.1482"></a>
-<span class="sourceLineNo">1483</span>    }<a name="line.1483"></a>
-<span class="sourceLineNo">1484</span>  }<a name="line.1484"></a>
-<span class="sourceLineNo">1485</span><a name="line.1485"></a>
-<span class="sourceLineNo">1486</span>  // should be called within the 
synchronized block of RegionStateNode<a name="line.1486"></a>
-<span class="sourceLineNo">1487</span>  void regionOpening(RegionStateNode 
regionNode) throws IOException {<a name="line.1487"></a>
-<span class="sourceLineNo">1488</span>    // As in SCP, for performance 
reason, there is no TRSP attached with this region, we will not<a 
name="line.1488"></a>
-<span class="sourceLineNo">1489</span>    // update the region state, which 
means that the region could be in any state when we want to<a 
name="line.1489"></a>
-<span class="sourceLineNo">1490</span>    // assign it after a RS crash. So 
here we do not pass the expectedStates parameter.<a name="line.1490"></a>
-<span class="sourceLineNo">1491</span>    transitStateAndUpdate(regionNode, 
State.OPENING);<a name="line.1491"></a>
-<span class="sourceLineNo">1492</span>    
regionStates.addRegionToServer(regionNode);<a name="line.1492"></a>
-<span class="sourceLineNo">1493</span>    // update the operation count 
metrics<a name="line.1493"></a>
-<span class="sourceLineNo">1494</span>    
metrics.incrementOperationCounter();<a name="line.1494"></a>
-<span class="sourceLineNo">1495</span>  }<a name="line.1495"></a>
-<span class="sourceLineNo">1496</span><a name="line.1496"></a>
-<span class="sourceLineNo">1497</span>  // should be called within the 
synchronized block of RegionStateNode.<a name="line.1497"></a>
-<span class="sourceLineNo">1498</span>  // The parameter 'giveUp' means 
whether we will try to open the region again, if it is true, then<a 
name="line.1498"></a>
-<span class="sourceLineNo">1499</span>  // we will persist the FAILED_OPEN 
state into hbase:meta.<a name="line.1499"></a>
-<span class="sourceLineNo">1500</span>  void regionFailedOpen(RegionStateNode 
regionNode, boolean giveUp) throws IOException {<a name="line.1500"></a>
-<span class="sourceLineNo">1501</span>    RegionState.State state = 
regionNode.getState();<a name="line.1501"></a>
-<span class="sourceLineNo">1502</span>    ServerName regionLocation = 
regionNode.getRegionLocation();<a name="line.1502"></a>
-<span class="sourceLineNo">1503</span>    if (giveUp) {<a name="line.1503"></a>
-<span class="sourceLineNo">1504</span>      
regionNode.setState(State.FAILED_OPEN);<a name="line.1504"></a>
-<span class="sourceLineNo">1505</span>      
regionNode.setRegionLocation(null);<a name="line.1505"></a>
-<span class="sourceLineNo">1506</span>      boolean succ = false;<a 
name="line.1506"></a>
-<span class="sourceLineNo">1507</span>      try {<a name="line.1507"></a>
-<span class="sourceLineNo">1508</span>        
regionStateStore.updateRegionLocation(regionNode);<a name="line.1508"></a>
-<span class="sourceLineNo">1509</span>        succ = true;<a 
name="line.1509"></a>
-<span class="sourceLineNo">1510</span>      } finally {<a name="line.1510"></a>
-<span class="sourceLineNo">1511</span>        if (!succ) {<a 
name="line.1511"></a>
-<span class="sourceLineNo">1512</span>          // revert<a 
name="line.1512"></a>
-<span class="sourceLineNo">1513</span>          regionNode.setState(state);<a 
name="line.1513"></a>
-<span class="sourceLineNo">1514</span>          
regionNode.setRegionLocation(regionLocation);<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>    if (regionLocation != null) {<a 
name="line.1518"></a>
-<span class="sourceLineNo">1519</span>      
regionStates.removeRegionFromServer(regionLocation, regionNode);<a 
name="line.1519"></a>
+<span class="sourceLineNo">1470</span>  //  Region Status update<a 
name="line.1470"></a>
+<span class="sourceLineNo">1471</span>  //  Should only be called in 
TransitRegionStateProcedure<a name="line.1471"></a>
+<span class="sourceLineNo">1472</span>  // 
============================================================================================<a
 name="line.1472"></a>
+<span class="sourceLineNo">1473</span>  private void 
transitStateAndUpdate(RegionStateNode regionNode, RegionState.State newState,<a 
name="line.1473"></a>
+<span class="sourceLineNo">1474</span>      RegionState.State... 
expectedStates) throws IOException {<a name="line.1474"></a>
+<span class="sourceLineNo">1475</span>    RegionState.State state = 
regionNode.getState();<a name="line.1475"></a>
+<span class="sourceLineNo">1476</span>    regionNode.transitionState(newState, 
expectedStates);<a name="line.1476"></a>
+<span class="sourceLineNo">1477</span>    boolean succ = false;<a 
name="line.1477"></a>
+<span class="sourceLineNo">1478</span>    try {<a name="line.1478"></a>
+<span class="sourceLineNo">1479</span>      
regionStateStore.updateRegionLocation(regionNode);<a name="line.1479"></a>
+<span class="sourceLineNo">1480</span>      succ = true;<a 
name="line.1480"></a>
+<span class="sourceLineNo">1481</span>    } finally {<a name="line.1481"></a>
+<span class="sourceLineNo">1482</span>      if (!succ) {<a 
name="line.1482"></a>
+<span class="sourceLineNo">1483</span>        // revert<a name="line.1483"></a>
+<span class="sourceLineNo">1484</span>        regionNode.setState(state);<a 
name="line.1484"></a>
+<span class="sourceLineNo">1485</span>      }<a name="line.1485"></a>
+<span class="sourceLineNo">1486</span>    }<a name="line.1486"></a>
+<span class="sourceLineNo">1487</span>  }<a name="line.1487"></a>
+<span class="sourceLineNo">1488</span><a name="line.1488"></a>
+<span class="sourceLineNo">1489</span>  // should be called within the 
synchronized block of RegionStateNode<a name="line.1489"></a>
+<span class="sourceLineNo">1490</span>  void regionOpening(RegionStateNode 
regionNode) throws IOException {<a name="line.1490"></a>
+<span class="sourceLineNo">1491</span>    // As in SCP, for performance 
reason, there is no TRSP attached with this region, we will not<a 
name="line.1491"></a>
+<span class="sourceLineNo">1492</span>    // update the region state, which 
means that the region could be in any state when we want to<a 
name="line.1492"></a>
+<span class="sourceLineNo">1493</span>    // assign it after a RS crash. So 
here we do not pass the expectedStates parameter.<a name="line.1493"></a>
+<span class="sourceLineNo">1494</span>    transitStateAndUpdate(regionNode, 
State.OPENING);<a name="line.1494"></a>
+<span class="sourceLineNo">1495</span>    
regionStates.addRegionToServer(regionNode);<a name="line.1495"></a>
+<span class="sourceLineNo">1496</span>    // update the operation count 
metrics<a name="line.1496"></a>
+<span class="sourceLineNo">1497</span>    
metrics.incrementOperationCounter();<a name="line.1497"></a>
+<span class="sourceLineNo">1498</span>  }<a name="line.1498"></a>
+<span class="sourceLineNo">1499</span><a name="line.1499"></a>
+<span class="sourceLineNo">1500</span>  // should be called within the 
synchronized block of RegionStateNode.<a name="line.1500"></a>
+<span class="sourceLineNo">1501</span>  // The parameter 'giveUp' means 
whether we will try to open the region again, if it is true, then<a 
name="line.1501"></a>
+<span class="sourceLineNo">1502</span>  // we will persist the FAILED_OPEN 
state into hbase:meta.<a name="line.1502"></a>
+<span class="sourceLineNo">1503</span>  void regionFailedOpen(RegionStateNode 
regionNode, boolean giveUp) throws IOException {<a name="line.1503"></a>
+<span class="sourceLineNo">1504</span>    RegionState.State state = 
regionNode.getState();<a name="line.1504"></a>
+<span class="sourceLineNo">1505</span>    ServerName regionLocation = 
regionNode.getRegionLocation();<a name="line.1505"></a>
+<span class="sourceLineNo">1506</span>    if (giveUp) {<a name="line.1506"></a>
+<span class="sourceLineNo">1507</span>      
regionNode.setState(State.FAILED_OPEN);<a name="line.1507"></a>
+<span class="sourceLineNo">1508</span>      
regionNode.setRegionLocation(null);<a name="line.1508"></a>
+<span class="sourceLineNo">1509</span>      boolean succ = false;<a 
name="line.1509"></a>
+<span class="sourceLineNo">1510</span>      try {<a name="line.1510"></a>
+<span class="sourceLineNo">1511</span>        
regionStateStore.updateRegionLocation(regionNode);<a name="line.1511"></a>
+<span class="sourceLineNo">1512</span>        succ = true;<a 
name="line.1512"></a>
+<span class="sourceLineNo">1513</span>      } finally {<a name="line.1513"></a>
+<span class="sourceLineNo">1514</span>        if (!succ) {<a 
name="line.1514"></a>
+<span class="sourceLineNo">1515</span>          // revert<a 
name="line.1515"></a>
+<span class="sourceLineNo">1516</span>          regionNode.setState(state);<a 
name="line.1516"></a>
+<span class="sourceLineNo">1517</span>          
regionNode.setRegionLocation(regionLocation);<a name="line.1517"></a>
+<span class="sourceLineNo">1518</span>        }<a name="line.1518"></a>
+<span class="sourceLineNo">1519</span>      }<a name="line.1519"></a>
 <span class="sourceLineNo">1520</span>    }<a name="line.1520"></a>
-<span class="sourceLineNo">1521</span>  }<a name="line.1521"></a>
-<span class="sourceLineNo">1522</span><a name="line.1522"></a>
-<span class="sourceLineNo">1523</span>  // should be called within the 
synchronized block of RegionStateNode<a name="line.1523"></a>
-<span class="sourceLineNo">1524</span>  void regionOpened(RegionStateNode 
regionNode) throws IOException {<a name="line.1524"></a>
-<span class="sourceLineNo">1525</span>    // TODO: OPENING Updates hbase:meta 
too... we need to do both here and there?<a name="line.1525"></a>
-<span class="sourceLineNo">1526</span>    // That is a lot of hbase:meta 
writing.<a name="line.1526"></a>
-<span class="sourceLineNo">1527</span>    transitStateAndUpdate(regionNode, 
State.OPEN, STATES_EXPECTED_ON_OPEN);<a name="line.1527"></a>
-<span class="sourceLineNo">1528</span>    RegionInfo hri = 
regionNode.getRegionInfo();<a name="line.1528"></a>
-<span class="sourceLineNo">1529</span>    if (isMetaRegion(hri)) {<a 
name="line.1529"></a>
-<span class="sourceLineNo">1530</span>      // Usually we'd set a table 
ENABLED at this stage but hbase:meta is ALWAYs enabled, it<a 
name="line.1530"></a>
-<span class="sourceLineNo">1531</span>      // can't be disabled -- so skip 
the RPC (besides... enabled is managed by TableStateManager<a 
name="line.1531"></a>
-<span class="sourceLineNo">1532</span>      // which is backed by 
hbase:meta... Avoid setting ENABLED to avoid having to update state<a 
name="line.1532"></a>
-<span class="sourceLineNo">1533</span>      // on table that contains state.<a 
name="line.1533"></a>
-<span class="sourceLineNo">1534</span>      setMetaAssigned(hri, true);<a 
name="line.1534"></a>
-<span class="sourceLineNo">1535</span>    }<a name="line.1535"></a>
-<span class="sourceLineNo">1536</span>    
regionStates.addRegionToServer(regionNode);<a name="line.1536"></a>
-<span class="sourceLineNo">1537</span>    
regionStates.removeFromFailedOpen(hri);<a name="line.1537"></a>
-<span class="sourceLineNo">1538</span>  }<a name="line.1538"></a>
-<span class="sourceLineNo">1539</span><a name="line.1539"></a>
-<span class="sourceLineNo">1540</span>  // should be called within the 
synchronized block of RegionStateNode<a name="line.1540"></a>
-<span class="sourceLineNo">1541</span>  void regionClosing(RegionStateNode 
regionNode) throws IOException {<a name="line.1541"></a>
-<span class="sourceLineNo">1542</span>    transitStateAndUpdate(regionNode, 
State.CLOSING, STATES_EXPECTED_ON_CLOSING);<a name="line.1542"></a>
-<span class="sourceLineNo">1543</span><a name="line.1543"></a>
-<span class="sourceLineNo">1544</span>    RegionInfo hri = 
regionNode.getRegionInfo();<a name="line.1544"></a>
-<span class="sourceLineNo">1545</span>    // Set meta has not initialized 
early. so people trying to create/edit tables will wait<a name="line.1545"></a>
-<span class="sourceLineNo">1546</span>    if (isMetaRegion(hri)) {<a 
name="line.1546"></a>
-<span class="sourceLineNo">1547</span>      setMetaAssigned(hri, false);<a 
name="line.1547"></a>
-<span class="sourceLineNo">1548</span>    }<a name="line.1548"></a>
-<span class="sourceLineNo">1549</span>    
regionStates.addRegionToServer(regionNode);<a name="line.1549"></a>
-<span class="sourceLineNo">1550</span>    // update the operation count 
metrics<a name="line.1550"></a>
-<span class="sourceLineNo">1551</span>    
metrics.incrementOperationCounter();<a name="line.1551"></a>
-<span class="sourceLineNo">1552</span>  }<a name="line.1552"></a>
-<span class="sourceLineNo">1553</span><a name="line.1553"></a>
-<span class="sourceLineNo">1554</span>  // should be called within the 
synchronized block of RegionStateNode<a name="line.1554"></a>
-<span class="sourceLineNo">1555</span>  // The parameter 'normally' means 
whether we are closed cleanly, if it is true, then it means that<a 
name="line.1555"></a>
-<span class="sourceLineNo">1556</span>  // we are closed due to a RS crash.<a 
name="line.1556"></a>
-<span class="sourceLineNo">1557</span>  void regionClosed(RegionStateNode 
regionNode, boolean normally) throws IOException {<a name="line.1557"></a>
-<span class="sourceLineNo">1558</span>    RegionState.State state = 
regionNode.getState();<a name="line.1558"></a>
-<span class="sourceLineNo">1559</span>    ServerName regionLocation = 
regionNode.getRegionLocation();<a name="line.1559"></a>
-<span class="sourceLineNo">1560</span>    if (normally) {<a 
name="line.1560"></a>
-<span class="sourceLineNo">1561</span>      
regionNode.transitionState(State.CLOSED, STATES_EXPECTED_ON_CLOSED);<a 
name="line.1561"></a>
-<span class="sourceLineNo">1562</span>    } else {<a name="line.1562"></a>
-<span class="sourceLineNo">1563</span>      // For SCP<a name="line.1563"></a>
-<span class="sourceLineNo">1564</span>      
regionNode.transitionState(State.ABNORMALLY_CLOSED);<a name="line.1564"></a>
-<span class="sourceLineNo">1565</span>    }<a name="line.1565"></a>
-<span class="sourceLineNo">1566</span>    
regionNode.setRegionLocation(null);<a name="line.1566"></a>
-<span class="sourceLineNo">1567</span>    boolean succ = false;<a 
name="line.1567"></a>
-<span class="sourceLineNo">1568</span>    try {<a name="line.1568"></a>
-<span class="sourceLineNo">1569</span>      
regionStateStore.updateRegionLocation(regionNode);<a name="line.1569"></a>
-<span class="sourceLineNo">1570</span>      succ = true;<a 
name="line.1570"></a>
-<span class="sourceLineNo">1571</span>    } finally {<a name="line.1571"></a>
-<span class="sourceLineNo">1572</span>      if (!succ) {<a 
name="line.1572"></a>
-<span class="sourceLineNo">1573</span>        // revert<a name="line.1573"></a>
-<span class="sourceLineNo">1574</span>        regionNode.setState(state);<a 
name="line.1574"></a>
-<span class="sourceLineNo">1575</span>        
regionNode.setRegionLocation(regionLocation);<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>    if (regionLocation != null) {<a 
name="line.1578"></a>
-<span class="sourceLineNo">1579</span>      
regionNode.setLastHost(regionLocation);<a name="line.1579"></a>
-<span class="sourceLineNo">1580</span>      
regionStates.removeRegionFromServer(regionLocation, regionNode);<a 
name="line.1580"></a>
-<span class="sourceLineNo">1581</span>    }<a name="line.1581"></a>
-<span class="sourceLineNo">1582</span>  }<a name="line.1582"></a>
-<span class="sourceLineNo">1583</span><a name="line.1583"></a>
-<span class="sourceLineNo">1584</span>  public void markRegionAsSplit(final 
RegionInfo parent, final ServerName serverName,<a name="line.1584"></a>
-<span class="sourceLineNo">1585</span>      final RegionInfo daughterA, final 
RegionInfo daughterB) throws IOException {<a name="line.1585"></a>
-<span class="sourceLineNo">1586</span>    // Update hbase:meta. Parent will be 
marked offline and split up in hbase:meta.<a name="line.1586"></a>
-<span class="sourceLineNo">1587</span>    // The parent stays in regionStates 
until cleared when removed by CatalogJanitor.<a name="line.1587"></a>
-<span class="sourceLineNo">1588</span>    // Update its state in regionStates 
to it shows as offline and split when read<a name="line.1588"></a>
-<span class="sourceLineNo">1589</span>    // later figuring what regions are 
in a table and what are not: see<a name="line.1589"></a>
-<span class="sourceLineNo">1590</span>    // regionStates#getRegionsOfTable<a 
name="line.1590"></a>
-<span class="sourceLineNo">1591</span>    final RegionStateNode node = 
regionStates.getOrCreateRegionStateNode(parent);<a name="line.1591"></a>
-<span class="sourceLineNo">1592</span>    node.setState(State.SPLIT);<a 
name="line.1592"></a>
-<span class="sourceLineNo">1593</span>    final RegionStateNode nodeA = 
regionStates.getOrCreateRegionStateNode(daughterA);<a name="line.1593"></a>
-<span class="sourceLineNo">1594</span>    
nodeA.setState(State.SPLITTING_NEW);<a name="line.1594"></a>
-<span class="sourceLineNo">1595</span>    final RegionStateNode nodeB = 
regionStates.getOrCreateRegionStateNode(daughterB);<a name="line.1595"></a>
-<span class="sourceLineNo">1596</span>    
nodeB.setState(State.SPLITTING_NEW);<a name="line.1596"></a>
-<span class="sourceLineNo">1597</span><a name="line.1597"></a>
-<span class="sourceLineNo">1598</span>    regionStateStore.splitRegion(parent, 
daughterA, daughterB, serverName);<a name="line.1598"></a>
-<span class="sourceLineNo">1599</span>    if 
(shouldAssignFavoredNodes(parent)) {<a name="line.1599"></a>
-<span class="sourceLineNo">1600</span>      List&lt;ServerName&gt; 
onlineServers = this.master.getServerManager().getOnlineServersList();<a 
name="line.1600"></a>
-<span class="sourceLineNo">1601</span>      
((FavoredNodesPromoter)getBalancer()).<a name="line.1601"></a>
-<span class="sourceLineNo">1602</span>          
generateFavoredNodesForDaughter(onlineServers, parent, daughterA, daughterB);<a 
name="line.1602"></a>
-<span class="sourceLineNo">1603</span>    }<a name="line.1603"></a>
-<span class="sourceLineNo">1604</span>  }<a name="line.1604"></a>
-<span class="sourceLineNo">1605</span><a name="line.1605"></a>
-<span class="sourceLineNo">1606</span>  /**<a name="line.1606"></a>
-<span class="sourceLineNo">1607</span>   * When called here, the merge has 
happened. The two merged regions have been<a name="line.1607"></a>
-<span class="sourceLineNo">1608</span>   * unassigned and the above 
markRegionClosed has been called on each so they have been<a 
name="line.1608"></a>
-<span class="sourceLineNo">1609</span>   * disassociated from a hosting 
Server. The merged region will be open after this call. The<a 
name="line.1609"></a>
-<span class="sourceLineNo">1610</span>   * merged regions are removed from 
hbase:meta below&gt; Later they are deleted from the filesystem<a 
name="line.1610"></a>
-<span class="sourceLineNo">1611</span>   * by the catalog janitor running 
against hbase:meta. It notices when the merged region no<a name="line.1611"></a>
-<span class="sourceLineNo">1612</span>   * longer holds references to the old 
regions.<a name="line.1612"></a>
-<span class="sourceLineNo">1613</span>   */<a name="line.1613"></a>
-<span class="sourceLineNo">1614</span>  public void markRegionAsMerged(final 
RegionInfo child, final ServerName serverName,<a name="line.1614"></a>
-<span class="sourceLineNo">1615</span>      final RegionInfo mother, final 
RegionInfo father) throws IOException {<a name="line.1615"></a>
-<span class="sourceLineNo">1616</span>    final RegionStateNode node = 
regionStates.getOrCreateRegionStateNode(child);<a name="line.1616"></a>
-<span class="sourceLineNo">1617</span>    node.setState(State.MERGED);<a 
name="line.1617"></a>
-<span class="sourceLineNo">1618</span>    regionStates.deleteRegion(mother);<a 
name="line.1618"></a>
-<span class="sourceLineNo">1619</span>    regionStates.deleteRegion(father);<a 
name="line.1619"></a>
-<span class="sourceLineNo">1620</span>    regionStateStore.mergeRegions(child, 
mother, father, serverName);<a name="line.1620"></a>
-<span class="sourceLineNo">1621</span>    if (shouldAssignFavoredNodes(child)) 
{<a name="line.1621"></a>
-<span class="sourceLineNo">1622</span>      
((FavoredNodesPromoter)getBalancer()).<a name="line.1622"></a>
-<span class="sourceLineNo">1623</span>        
generateFavoredNodesForMergedRegion(child, mother, father);<a 
name="line.1623"></a>
-<span class="sourceLineNo">1624</span>    }<a name="line.1624"></a>
-<span class="sourceLineNo">1625</span>  }<a name="line.1625"></a>
-<span class="sourceLineNo">1626</span><a name="line.1626"></a>
-<span class="sourceLineNo">1627</span>  /*<a name="line.1627"></a>
-<span class="sourceLineNo">1628</span>   * Favored nodes should be applied 
only when FavoredNodes balancer is configured and the region<a 
name="line.1628"></a>
-<span class="sourceLineNo">1629</span>   * belongs to a non-system table.<a 
name="line.1629"></a>
-<span class="sourceLineNo">1630</span>   */<a name="line.1630"></a>
-<span class="sourceLineNo">1631</span>  private boolean 
shouldAssignFavoredNodes(RegionInfo region) {<a name="line.1631"></a>
-<span class="sourceLineNo">1632</span>    return 
this.shouldAssignRegionsWithFavoredNodes &amp;&amp;<a name="line.1632"></a>
-<span class="sourceLineNo">1633</span>        
FavoredNodesManager.isFavoredNodeApplicable(region);<a name="line.1633"></a>
-<span class="sourceLineNo">1634</span>  }<a name="line.1634"></a>
-<span class="sourceLineNo">1635</span><a name="line.1635"></a>
-<span class="sourceLineNo">1636</span>  // 
============================================================================================<a
 name="line.1636"></a>
-<span class="sourceLineNo">1637</span>  //  Assign Queue (Assign/Balance)<a 
name="line.1637"></a>
-<span class="sourceLineNo">1638</span>  // 
============================================================================================<a
 name="line.1638"></a>
-<span class="sourceLineNo">1639</span>  private final 
ArrayList&lt;RegionStateNode&gt; pendingAssignQueue = new 
ArrayList&lt;RegionStateNode&gt;();<a name="line.1639"></a>
-<span class="sourceLineNo">1640</span>  private final ReentrantLock 
assignQueueLock = new ReentrantLock();<a name="line.1640"></a>
-<span class="sourceLineNo">1641</span>  private final Condition 
assignQueueFullCond = assignQueueLock.newCondition();<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>   * Add the assign operation to the 
assignment queue.<a name="line.1644"></a>
-<span class="sourceLineNo">1645</span>   * The pending assignment operation 
will be processed,<a name="line.1645"></a>
-<span class="sourceLineNo">1646</span>   * and each region will be assigned by 
a server using the balancer.<a name="line.1646"></a>
-<span class="sourceLineNo">1647</span>   */<a name="line.1647"></a>
-<span class="sourceLineNo">1648</span>  protected void queueAssign(final 
RegionStateNode regionNode) {<a name="line.1648"></a>
-<span class="sourceLineNo">1649</span>    
regionNode.getProcedureEvent().suspend();<a name="line.1649"></a>
-<span class="sourceLineNo">1650</span><a name="line.1650"></a>
-<span class="sourceLineNo">1651</span>    // TODO: quick-start for meta and 
the other sys-tables?<a name="line.1651"></a>
-<span class="sourceLineNo">1652</span>    assignQueueLock.lock();<a 
name="line.1652"></a>
-<span class="sourceLineNo">1653</span>    try {<a name="line.1653"></a>
-<span class="sourceLineNo">1654</span>      
pendingAssignQueue.add(regionNode);<a name="line.1654"></a>
-<span class="sourceLineNo">1655</span>      if (regionNode.isSystemTable() 
||<a name="line.1655"></a>
-<span class="sourceLineNo">1656</span>          pendingAssignQueue.size() == 1 
||<a name="line.1656"></a>
-<span class="sourceLineNo">1657</span>          pendingAssignQueue.size() 
&gt;= assignDispatchWaitQueueMaxSize) {<a name="line.1657"></a>
-<span class="sourceLineNo">1658</span>        assignQueueFullCond.signal();<a 
name="line.1658"></a>
-<span class="sourceLineNo">1659</span>      }<a name="line.1659"></a>
-<span class="sourceLineNo">1660</span>    } finally {<a name="line.1660"></a>
-<span class="sourceLineNo">1661</span>      assignQueueLock.unlock();<a 
name="line.1661"></a>
-<span class="sourceLineNo">1662</span>    }<a name="line.1662"></a>
-<span class="sourceLineNo">1663</span>  }<a name="line.1663"></a>
-<span class="sourceLineNo">1664</span><a name="line.1664"></a>
-<span class="sourceLineNo">1665</span>  private void startAssignmentThread() 
{<a name="line.1665"></a>
-<span class="sourceLineNo">1666</span>    // Get Server Thread name. Sometimes 
the Server is mocked so may not implement HasThread.<a name="line.1666"></a>
-<span class="sourceLineNo">1667</span>    // For example, in tests.<a 
name="line.1667"></a>
-<span class="sourceLineNo">1668</span>    String name = master instanceof 
HasThread? ((HasThread)master).getName():<a name="line.1668"></a>
-<span class="sourceLineNo">1669</span>        
master.getServerName().toShortString();<a name="line.1669"></a>
-<span class="sourceLineNo">1670</span>    assignThread = new Thread(name) {<a 
name="line.1670"></a>
-<span class="sourceLineNo">1671</span>      @Override<a name="line.1671"></a>
-<span class="sourceLineNo">1672</span>      public void run() {<a 
name="line.1672"></a>
-<span class="sourceLineNo">1673</span>        while (isRunning()) {<a 
name="line.1673"></a>
-<span class="sourceLineNo">1674</span>          processAssignQueue();<a 
name="line.1674"></a>
-<span class="sourceLineNo">1675</span>        }<a name="line.1675"></a>
-<span class="sourceLineNo">1676</span>        pendingAssignQueue.clear();<a 
name="line.1676"></a>
-<span class="sourceLineNo">1677</span>      }<a name="line.1677"></a>
-<span class="sourceLineNo">1678</span>    };<a name="line.1678"></a>
-<span class="sourceLineNo">1679</span>    assignThread.setDaemon(true);<a 
name="line.1679"></a>
-<span class="sourceLineNo">1680</span>    assignThread.start();<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>  private void stopAssignmentThread() 
{<a name="line.1683"></a>
-<span class="sourceLineNo">1684</span>    assignQueueSignal();<a 
name="line.1684"></a>
-<span class="sourceLineNo">1685</span>    try {<a name="line.1685"></a>
-<span class="sourceLineNo">1686</span>      while (assignThread.isAlive()) {<a 
name="line.1686"></a>
-<span class="sourceLineNo">1687</span>        assignQueueSignal();<a 
name="line.1687"></a>
-<span class="sourceLineNo">1688</span>        assignThread.join(250);<a 
name="line.1688"></a>
-<span class="sourceLineNo">1689</span>      }<a name="line.1689"></a>
-<span class="sourceLineNo">1690</span>    } catch (InterruptedException e) {<a 
name="line.1690"></a>
-<span class="sourceLineNo">1691</span>      LOG.warn("join interrupted", e);<a 
name="line.1691"></a>
-<span class="sourceLineNo">1692</span>      
Thread.currentThread().interrupt();<a name="line.1692"></a>
-<span class="sourceLineNo">1693</span>    }<a name="line.1693"></a>
-<span class="sourceLineNo">1694</span>  }<a name="line.1694"></a>
-<span class="sourceLineNo">1695</span><a name="line.1695"></a>
-<span class="sourceLineNo">1696</span>  private void assignQueueSignal() {<a 
name="line.1696"></a>
-<span class="sourceLineNo">1697</span>    assignQueueLock.lock();<a 
name="line.1697"></a>
-<span class="sourceLineNo">1698</span>    try {<a name="line.1698"></a>
-<span class="sourceLineNo">1699</span>      assignQueueFullCond.signal();<a 
name="line.1699"></a>
-<span class="sourceLineNo">1700</span>    } finally {<a name="line.1700"></a>
-<span class="sourceLineNo">1701</span>      assignQueueLock.unlock();<a 
name="line.1701"></a>
-<span class="sourceLineNo">1702</span>    }<a name="line.1702"></a>
-<span class="sourceLineNo">1703</span>  }<a name="line.1703"></a>
-<span class="sourceLineNo">1704</span><a name="line.1704"></a>
-<span class="sourceLineNo">1705</span>  
@edu.umd.cs.findbugs.annotations.SuppressWarnings("WA_AWAIT_NOT_IN_LOOP")<a 
name="line.1705"></a>
-<span class="sourceLineNo">1706</span>  private HashMap&lt;RegionInfo, 
RegionStateNode&gt; waitOnAssignQueue() {<a name="line.1706"></a>
-<span class="sourceLineNo">1707</span>    HashMap&lt;RegionInfo, 
RegionStateNode&gt; regions = null;<a name="line.1707"></a>
-<span class="sourceLineNo">1708</span><a name="line.1708"></a>
-<span class="sourceLineNo">1709</span>    assignQueueLock.lock();<a 
name="line.1709"></a>
-<span class="sourceLineNo">1710</span>    try {<a name="line.1710"></a>
-<span class="sourceLineNo">1711</span>      if (pendingAssignQueue.isEmpty() 
&amp;&amp; isRunning()) {<a name="line.1711"></a>
-<span class="sourceLineNo">1712</span>        assignQueueFullCond.await();<a 
name="line.1712"></a>
-<span class="sourceLineNo">1713</span>      }<a name="line.1713"></a>
-<span class="sourceLineNo">1714</span><a name="line.1714"></a>
-<span class="sourceLineNo">1715</span>      if (!isRunning()) return null;<a 
name="line.1715"></a>
-<span class="sourceLineNo">1716</span>      
assignQueueFullCond.await(assignDispatchWaitMillis, TimeUnit.MILLISECONDS);<a 
name="line.1716"></a>
-<span class="sourceLineNo">1717</span>      regions = new 
HashMap&lt;RegionInfo, RegionStateNode&gt;(pendingAssignQueue.size());<a 
name="line.1717"></a>
-<span class="sourceLineNo">1718</span>      for (RegionStateNode regionNode: 
pendingAssignQueue) {<a name="line.1718"></a>
-<span class="sourceLineNo">1719</span>        
regions.put(regionNode.getRegionInfo(), regionNode);<a name="line.1719"></a>
-<span class="sourceLineNo">1720</span>      }<a name="line.1720"></a>
-<span class="sourceLineNo">1721</span>      pendingAssignQueue.clear();<a 
name="line.1721"></a>
-<span class="sourceLineNo">1722</span>    } catch (InterruptedException e) {<a 
name="line.1722"></a>
-<span class="sourceLineNo">1723</span>      LOG.warn("got interrupted ", e);<a 
name="line.1723"></a>
-<span class="sourceLineNo">1724</span>      
Thread.currentThread().interrupt();<a name="line.1724"></a>
-<span class="sourceLineNo">1725</span>    } finally {<a name="line.1725"></a>
-<span class="sourceLineNo">1726</span>      assignQueueLock.unlock();<a 
name="line.1726"></a>
-<span class="sourceLineNo">1727</span>    }<a name="line.1727"></a>
-<span class="sourceLineNo">1728</span>    return regions;<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>  private void processAssignQueue() {<a 
name="line.1731"></a>
-<span class="sourceLineNo">1732</span>    final HashMap&lt;RegionInfo, 
RegionStateNode&gt; regions = waitOnAssignQueue();<a name="line.1732"></a>
-<span class="sourceLineNo">1733</span>    if (regions == null || 
regions.size() == 0 || !isRunning()) {<a name="line.1733"></a>
-<span class="sourceLineNo">1734</span>      return;<a name="line.1734"></a>
-<span class="sourceLineNo">1735</span>    }<a name="line.1735"></a>
-<span class="sourceLineNo">1736</span><a name="line.1736"></a>
-<span class="sourceLineNo">1737</span>    if (LOG.isTraceEnabled()) {<a 
name="line.1737"></a>
-<span class="sourceLineNo">1738</span>      LOG.trace("PROCESS ASSIGN QUEUE 
regionCount=" + regions.size());<a name="line.1738"></a>
-<span class="sourceLineNo">1739</span>    }<a name="line.1739"></a>
-<span class="sourceLineNo">1740</span><a name="line.1740"></a>
-<span class="sourceLineNo">1741</span>    // TODO: Optimize balancer. pass a 
RegionPlan?<a name="line.1741"></a>
-<span class="sourceLineNo">1742</span>    final HashMap&lt;RegionInfo, 
ServerName&gt; retainMap = new HashMap&lt;&gt;();<a name="line.1742"></a>
-<span class="sourceLineNo">1743</span>    final List&lt;RegionInfo&gt; 
userHRIs = new ArrayList&lt;&gt;(regions.size());<a name="line.1743"></a>
-<span class="sourceLineNo">1744</span>    // Regions for system tables 
requiring reassignment<a name="line.1744"></a>
-<span class="sourceLineNo">1745</span>    final List&lt;RegionInfo&gt; 
systemHRIs = new ArrayList&lt;&gt;();<a name="line.1745"></a>
-<span class="sourceLineNo">1746</span>    for (RegionStateNode 
regionStateNode: regions.values()) {<a name="line.1746"></a>
-<span class="sourceLineNo">1747</span>      boolean sysTable = 
regionStateNode.isSystemTable();<a name="line.1747"></a>
-<span class="sourceLineNo">1748</span>      final List&lt;RegionInfo&gt; hris 
= sysTable? systemHRIs: userHRIs;<a name="line.1748"></a>
-<span class="sourceLineNo">1749</span>      if 
(regionStateNode.getRegionLocation() != null) {<a name="line.1749"></a>
-<span class="sourceLineNo">1750</span>        
retainMap.put(regionStateNode.getRegionInfo(), 
regionStateNode.getRegionLocation());<a name="line.1750"></a>
-<span class="sourceLineNo">1751</span>      } else {<a name="line.1751"></a>
-<span class="sourceLineNo">1752</span>        
hris.add(regionStateNode.getRegionInfo());<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><a name="line.1755"></a>
-<span class="sourceLineNo">1756</span>    // TODO: connect with the listener 
to invalidate the cache<a name="line.1756"></a>
-<span class="sourceLineNo">1757</span><a name="line.1757"></a>
-<span class="sourceLineNo">1758</span>    // TODO use events<a 
name="line.1758"></a>
-<span class="sourceLineNo">1759</span>    List&lt;ServerName&gt; servers = 
master.getServerManager().createDestinationServersList();<a 
name="line.1759"></a>
-<span class="sourceLineNo">1760</span>    for (int i = 0; servers.size() &lt; 
1; ++i) {<a name="line.1760"></a>
-<span class="sourceLineNo">1761</span>      // Report every fourth time around 
this loop; try not to flood log.<a name="line.1761"></a>
-<span class="sourceLineNo">1762</span>      if (i % 4 == 0) {<a 
name="line.1762"></a>
-<span class="sourceLineNo">1763</span>        LOG.warn("No servers available; 
cannot place " + regions.size() + " unassigned regions.");<a 
name="line.1763"></a>
-<span class="sourceLineNo">1764</span>      }<a name="line.1764"></a>
-<span class="sourceLineNo">1765</span><a name="line.1765"></a>
-<span class="sourceLineNo">1766</span>      if (!isRunning()) {<a 
name="line.1766"></a>
-<span class="sourceLineNo">1767</span>        LOG.debug("Stopped! Dropping 
assign of " + regions.size() + " queued regions.");<a name="line.1767"></a>
-<span class="sourceLineNo">1768</span>        return;<a name="line.1768"></a>
-<span class="sourceLineNo">1769</span>      }<a name="line.1769"></a>
-<span class="sourceLineNo">1770</span>      Threads.sleep(250);<a 
name="line.1770"></a>
-<span class="sourceLineNo">1771</span>      servers = 
master.getServerManager().createDestinationServersList();<a 
name="line.1771"></a>
-<span class="sourceLineNo">1772</span>    }<a name="line.1772"></a>
-<span class="sourceLineNo">1773</span><a name="line.1773"></a>
-<span class="sourceLineNo">1774</span>    if (!systemHRIs.isEmpty()) {<a 
name="line.1774"></a>
-<span class="sourceLineNo">1775</span>      // System table regions requiring 
reassignment are present, get region servers<a name="line.1775"></a>
-<span class="sourceLineNo">1776</span>      // not available for system table 
regions<a name="line.1776"></a>
-<span class="sourceLineNo">1777</span>      final List&lt;ServerName&gt; 
excludeServers = getExcludedServersForSystemTable();<a name="line.1777"></a>
-<span class="sourceLineNo">1778</span>      List&lt;ServerName&gt; 
serversForSysTables = servers.stream()<a name="line.1778"></a>
-<span class="sourceLineNo">1779</span>          .filter(s -&gt; 
!excludeServers.contains(s)).collect(Collectors.toList());<a 
name="line.1779"></a>
-<span class="sourceLineNo">1780</span>      if (serversForSysTables.isEmpty()) 
{<a name="line.1780"></a>
-<span class="sourceLineNo">1781</span>        LOG.warn("Filtering old server 
versions and the excluded produced an empty set; " +<a name="line.1781"></a>
-<span class="sourceLineNo">1782</span>            "instead considering all 
candidate servers!");<a name="line.1782"></a>
-<span class="sourceLineNo">1783</span>      }<a name="line.1783"></a>
-<span class="sourceLineNo">1784</span>      LOG.debug("Processing assignQueue; 
systemServersCount=" + serversForSysTables.size() +<a name="line.1784"></a>
-<span class="sourceLineNo">1785</span>          ", allServersCount=" + 
servers.size());<a name="line.1785"></a>
-<span class="sourceLineNo">1786</span>      processAssignmentPlans(regions, 
null, systemHRIs,<a name="line.1786"></a>
-<span class="sourceLineNo">1787</span>          serversForSysTables.isEmpty()? 
servers: serversForSysTables);<a name="line.1787"></a>
-<span class="sourceLineNo">1788</span>    }<a name="line.1788"></a>
-<span class="sourceLineNo">1789</span><a name="line.1789"></a>
-<span class="sourceLineNo">1790</span>    processAssignmentPlans(regions, 
retainMap, userHRIs, servers);<a name="line.1790"></a>
-<span class="sourceLineNo">1791</span>  }<a name="line.1791"></a>
+<span class="sourceLineNo">1521</span>    if (regionLocation != null) {<a 
name="line.1521"></a>
+<span class="sourceLineNo">1522</span>      
regionStates.removeRegionFromServer(regionLocation, regionNode);<a 
name="line.1522"></a>
+<span class="sourceLineNo">1523</span>    }<a name="line.1523"></a>
+<span class="sourceLineNo">1524</span>  }<a name="line.1524"></a>
+<span class="sourceLineNo">1525</span><a name="line.1525"></a>
+<span class="sourceLineNo">1526</span>  // should be called within the 
synchronized block of RegionStateNode<a name="line.1526"></a>
+<span class="sourceLineNo">1527</span>  void regionOpened(RegionStateNode 
regionNode) throws IOException {<a name="line.1527"></a>
+<span class="sourceLineNo">1528</span>    // TODO: OPENING Updates hbase:meta 
too... we need to do both here and there?<a name="line.1528"></a>
+<span class="sourceLineNo">1529</span>    // That is a lot of hbase:meta 
writing.<a name="line.1529"></a>
+<span class="sourceLineNo">1530</span>    transitStateAndUpdate(regionNode, 
State.OPEN, STATES_EXPECTED_ON_OPEN);<a name="line.1530"></a>
+<span class="sourceLineNo">1531</span>    RegionInfo hri = 
regionNode.getRegionInfo();<a name="line.1531"></a>
+<span class="sourceLineNo">1532</span>    if (isMetaRegion(hri)) {<a 
name="line.1532"></a>
+<span class="sourceLineNo">1533</span>      // Usually we'd set a table 
ENABLED at this stage but hbase:meta is ALWAYs enabled, it<a 
name="line.1533"></a>
+<span class="sourceLineNo">1534</span>      // can't be disabled -- so skip 
the RPC (besides... enabled is managed by TableStateManager<a 
name="line.1534"></a>
+<span class="sourceLineNo">1535</span>      // which is backed by 
hbase:meta... Avoid setting ENABLED to avoid having to update state<a 
name="line.1535"></a>
+<span class="sourceLineNo">1536</span>      // on table that contains state.<a 
name="line.1536"></a>
+<span class="sourceLineNo">1537</span>      setMetaAssigned(hri, true);<a 
name="line.1537"></a>
+<span class="sourceLineNo">1538</span>    }<a name="line.1538"></a>
+<span class="sourceLineNo">1539</span>    
regionStates.addRegionToServer(regionNode);<a name="line.1539"></a>
+<span class="sourceLineNo">1540</span>    
regionStates.removeFromFailedOpen(hri);<a name="line.1540"></a>
+<span class="sourceLineNo">1541</span>  }<a name="line.1541"></a>
+<span class="sourceLineNo">1542</span><a name="line.1542"></a>
+<span class="sourceLineNo">1543</span>  // should be called within the 
synchronized block of RegionStateNode<a name="line.1543"></a>
+<span class="sourceLineNo">1544</span>  void regionClosing(RegionStateNode 
regionNode) throws IOException {<a name="line.1544"></a>
+<span class="sourceLineNo">1545</span>    transitStateAndUpdate(regionNode, 
State.CLOSING, STATES_EXPECTED_ON_CLOSING);<a name="line.1545"></a>
+<span class="sourceLineNo">1546</span><a name="line.1546"></a>
+<span class="sourceLineNo">1547</span>    RegionInfo hri = 
regionNode.getRegionInfo();<a name="line.1547"></a>
+<span class="sourceLineNo">1548</span>    // Set meta has not initialized 
early. so people trying to create/edit tables will wait<a name="line.1548"></a>
+<span class="sourceLineNo">1549</span>    if (isMetaRegion(hri)) {<a 
name="line.1549"></a>
+<span class="sourceLineNo">1550</span>      setMetaAssigned(hri, false);<a 
name="line.1550"></a>
+<span class="sourceLineNo">1551</span>    }<a name="line.1551"></a>
+<span class="sourceLineNo">1552</span>    
regionStates.addRegionToServer(regionNode);<a name="line.1552"></a>
+<span class="sourceLineNo">1553</span>    // update the operation count 
metrics<a name="line.1553"></a>
+<span class="sourceLineNo">1554</span>    
metrics.incrementOperationCounter();<a name="line.1554"></a>
+<span class="sourceLineNo">1555</span>  }<a name="line.1555"></a>
+<span class="sourceLineNo">1556</span><a name="line.1556"></a>
+<span class="sourceLineNo">1557</span>  // should be called within the 
synchronized block of RegionStateNode<a name="line.1557"></a>
+<span class="sourceLineNo">1558</span>  // The parameter 'normally' means 
whether we are closed cleanly, if it is true, then it means that<a 
name="line.1558"></a>
+<span class="sourceLineNo">1559</span>  // we are closed due to a RS crash.<a 
name="line.1559"></a>
+<span class="sourceLineNo">1560</span>  void regionClosed(RegionStateNode 
regionNode, boolean normally) throws IOException {<a name="line.1560"></a>
+<span class="sourceLineNo">1561</span>    RegionState.State state = 
regionNode.getState();<a name="line.1561"></a>
+<span class="sourceLineNo">1562</span>    ServerName regionLocation = 
regionNode.getRegionLocation();<a name="line.1562"></a>
+<span class="sourceLineNo">1563</span>    if (normally) {<a 
name="line.1563"></a>
+<span class="sourceLineNo">1564</span>      
regionNode.transitionState(State.CLOSED, STATES_EXPECTED_ON_CLOSED);<a 
name="line.1564"></a>
+<span class="sourceLineNo">1565</span>    } else {<a name="line.1565"></a>
+<span class="sourceLineNo">1566</span>      // For SCP<a name="line.1566"></a>
+<span class="sourceLineNo">1567</span>      
regionNode.transitionState(State.ABNORMALLY_CLOSED);<a name="line.1567"></a>
+<span class="sourceLineNo">1568</span>    }<a name="line.1568"></a>
+<span class="sourceLineNo">1569</span>    
regionNode.setRegionLocation(null);<a name="line.1569"></a>
+<span class="sourceLineNo">1570</span>    boolean succ = false;<a 
name="line.1570"></a>
+<span class="sourceLineNo">1571</span>    try {<a name="line.1571"></a>
+<span class="sourceLineNo">1572</span>      
regionStateStore.updateRegionLocation(regionNode);<a name="line.1572"></a>
+<span class="sourceLineNo">1573</span>      succ = true;<a 
name="line.1573"></a>
+<span class="sourceLineNo">1574</span>    } finally {<a name="line.1574"></a>
+<span class="sourceLineNo">1575</span>      if (!succ) {<a 
name="line.1575"></a>
+<span class="sourceLineNo">1576</span>        // revert<a name="line.1576"></a>
+<span class="sourceLineNo">1577</span>        regionNode.setState(state);<a 
name="line.1577"></a>
+<span class="sourceLineNo">1578</span>        
regionNode.setRegionLocation(regionLocation);<a name="line.1578"></a>
+<span class="sourceLineNo">1579</span>      }<a name="line.1579"></a>
+<span class="sourceLineNo">1580</span>    }<a name="line.1580"></a>
+<span class="sourceLineNo">1581</span>    if (regionLocation != null) {<a 
name="line.1581"></a>
+<span class="sourceLineNo">1582</span>      
regionNode.setLastHost(regionLocation);<a name="line.1582"></a>
+<span class="sourceLineNo">1583</span>      
regionStates.removeRegionFromServer(regionLocation, regionNode);<a 
name="line.1583"></a>
+<span class="sourceLineNo">1584</span>    }<a name="line.1584"></a>
+<span class="sourceLineNo">1585</span>  }<a name="line.1585"></a>
+<span class="sourceLineNo">1586</span><a name="line.1586"></a>
+<span class="sourceLineNo">1587</span>  public void markRegionAsSplit(final 
RegionInfo parent, final ServerName serverName,<a name="line.1587"></a>
+<span class="sourceLineNo">1588</span>      final RegionInfo daughterA, final 
RegionInfo daughterB) throws IOException {<a name="line.1588"></a>
+<span class="sourceLineNo">1589</span>    // Update hbase:meta. Parent will be 
marked offline and split up in hbase:meta.<a name="line.1589"></a>
+<span class="sourceLineNo">1590</span>    // The parent stays in regionStates 
until cleared when removed by CatalogJanitor.<a name="line.1590"></a>
+<span class="sourceLineNo">1591</span>    // Update its state in regionStates 
to it shows as offline and split when read<a name="line.1591"></a>
+<span class="sourceLineNo">1592</span>    // later figuring what regions are 
in a table and what are not: see<a name="line.1592"></a>
+<span class="sourceLineNo">1593</span>    // regionStates#getRegionsOfTable<a 
name="line.1593"></a>
+<span class="sourceLineNo">1594</span>    final RegionStateNode node = 
regionStates.getOrCreateRegionStateNode(parent);<a name="line.1594"></a>
+<span class="sourceLineNo">1595</span>    node.setState(State.SPLIT);<a 
name="line.1595"></a>
+<span class="sourceLineNo">1596</span>    final RegionStateNode nodeA = 
regionStates.getOrCreateRegionStateNode(daughterA);<a name="line.1596"></a>
+<span class="sourceLineNo">1597</span>    
nodeA.setState(State.SPLITTING_NEW);<a name="line.1597"></a>
+<span class="sourceLineNo">1598</span>    final RegionStateNode nodeB = 
regionStates.getOrCreateRegionStateNode(daughterB);<a name="line.1598"></a>
+<span class="sourceLineNo">1599</span>    
nodeB.setState(State.SPLITTING_NEW);<a name="line.1599"></a>
+<span class="sourceLineNo">1600</span><a name="line.1600"></a>
+<span class="sourceLineNo">1601</span>    regionStateStore.splitRegion(parent, 
daughterA, daughterB, serverName);<a name="line.1601"></a>
+<span class="sourceLineNo">1602</span>    if 
(shouldAssignFavoredNodes(parent)) {<a name="line.1602"></a>
+<span class="sourceLineNo">1603</span>      List&lt;ServerName&gt; 
onlineServers = this.master.getServerManager().getOnlineServersList();<a 
name="line.1603"></a>
+<span class="sourceLineNo">1604</span>      
((FavoredNodesPromoter)getBalancer()).<a name="line.1604"></a>
+<span class="sourceLineNo">1605</span>          
generateFavoredNodesForDaughter(onlineServers, parent, daughterA, daughterB);<a 
name="line.1605"></a>
+<span class="sourceLineNo">1606</span>    }<a name="line.1606"></a>
+<span class="sourceLineNo">1607</span>  }<a name="line.1607"></a>
+<span class="sourceLineNo">1608</span><a name="line.1608"></a>
+<span class="sourceLineNo">1609</span>  /**<a name="line.1609"></a>
+<span class="sourceLineNo">1610</span>   * When called here, the merge has 
happened. The two merged regions have been<a name="line.1610"></a>
+<span class="sourceLineNo">1611</span>   * unassigned and the above 
markRegionClosed has been called on each so they have been<a 
name="line.1611"></a>
+<span class="sourceLineNo">1612</span>   * disassociated from a hosting 
Server. The merged region will be open after this call. The<a 
name="line.1612"></a>
+<span class="sourceLineNo">1613</span>   * merged regions are removed from 
hbase:meta below&gt; Later they are deleted from the filesystem<a 
name="line.1613"></a>
+<span class="sourceLineNo">1614</span>   * by the catalog janitor running 
against hbase:meta. It notices when the merged region no<a name="line.1614"></a>
+<span class="sourceLineNo">1615</span>   * longer holds references to the old 
regions.<a name="line.1615"></a>
+<span class="sourceLineNo">1616</span>   */<a name="line.1616"></a>
+<span class="sourceLineNo">1617</span>  public void markRegionAsMerged(final 
RegionInfo child, final ServerName serverName,<a name="line.1617"></a>
+<span class="sourceLineNo">1618</span>      final RegionInfo mother, final 
RegionInfo father) throws IOException {<a name="line.1618"></a>
+<span class="sourceLineNo">1619</span>    final RegionStateNode node = 
regionStates.getOrCreateRegionStateNode(child);<a name="line.1619"></a>
+<span class="sourceLineNo">1620</span>    node.setState(State.MERGED);<a 
name="line.1620"></a>
+<span class="sourceLineNo">1621</span>    regionStates.deleteRegion(mother);<a 
name="line.1621"></a>
+<span class="sourceLineNo">1622</span>    regionStates.deleteRegion(father);<a 
name="line.1622"></a>
+<span class="sourceLineNo">1623</span>    regionStateStore.mergeRegions(child, 
mother, father, serverName);<a name="line.1623"></a>
+<span class="sourceLineNo">1624</span>    if (shouldAssignFavoredNodes(child)) 
{<a name="line.1624"></a>
+<span class="sourceLineNo">1625</span>      
((FavoredNodesPromoter)getBalancer()).<a name="line.1625"></a>
+<span class="sourceLineNo">1626</span>        
generateFavoredNodesForMergedRegion(child, mother, father);<a 
name="line.1626"></a>
+<span class="sourceLineNo">1627</span>    }<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>   * Favored nodes should be applied 
only when FavoredNodes balancer is configured and the region<a 
name="line.1631"></a>
+<span class="sourceLineNo">1632</span>   * belongs to a non-system table.<a 
name="line.1632"></a>
+<span class="sourceLineNo">1633</span>   */<a name="line.1633"></a>
+<span class="sourceLineNo">1634</span>  private boolean 
shouldAssignFavoredNodes(RegionInfo region) {<a name="line.1634"></a>
+<span class="sourceLineNo">1635</span>    return 
this.shouldAssignRegionsWithFavoredNodes &amp;&amp;<a name="line.1635"></a>
+<span class="sourceLineNo">1636</span>        
FavoredNodesManager.isFavoredNodeApplicable(region);<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>  // 
============================================================================================<a
 name="line.1639"></a>
+<span class="sourceLineNo">1640</span>  //  Assign Queue (Assign/Balance)<a 
name="line.1640"></a>
+<span class="sourceLineNo">1641</span>  // 
============================================================================================<a
 name="line.1641"></a>
+<span class="sourceLineNo">1642</span>  private final 
ArrayList&lt;RegionStateNode&gt; pendingAssignQueue = new 
ArrayList&lt;RegionStateNode&gt;();<a name="line.1642"></a>
+<span class="sourceLineNo">1643</span>  private final ReentrantLock 
assignQueueLock = new ReentrantLock();<a name="line.1643"></a>
+<span class="sourceLineNo">1644</span>  private final Condition 
assignQueueFullCond = assignQueueLock.newCondition();<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>  

<TRUNCATED>

Reply via email to