hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mi...@apache.org
Subject svn commit: r1711891 [38/50] - in /hbase/hbase.apache.org/trunk: ./ apidocs/ apidocs/org/apache/hadoop/hbase/ apidocs/org/apache/hadoop/hbase/class-use/ apidocs/org/apache/hadoop/hbase/client/ apidocs/org/apache/hadoop/hbase/client/class-use/ apidocs/o...
Date Mon, 02 Nov 2015 03:51:05 GMT
Modified: hbase/hbase.apache.org/trunk/testdevapidocs/src-html/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransactionOnCluster.MyMaster.html
URL: http://svn.apache.org/viewvc/hbase/hbase.apache.org/trunk/testdevapidocs/src-html/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransactionOnCluster.MyMaster.html?rev=1711891&r1=1711890&r2=1711891&view=diff
==============================================================================
--- hbase/hbase.apache.org/trunk/testdevapidocs/src-html/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransactionOnCluster.MyMaster.html (original)
+++ hbase/hbase.apache.org/trunk/testdevapidocs/src-html/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransactionOnCluster.MyMaster.html Mon Nov  2 03:51:02 2015
@@ -232,295 +232,294 @@
 <span class="sourceLineNo">224</span>          HConstants.MERGEB_QUALIFIER) != null);<a name="line.224"></a>
 <span class="sourceLineNo">225</span><a name="line.225"></a>
 <span class="sourceLineNo">226</span>      // merging regions' directory are in the file system all the same<a name="line.226"></a>
-<span class="sourceLineNo">227</span>      HRegionInfo regionA = HRegionInfo.getHRegionInfo(mergedRegionResult,<a name="line.227"></a>
-<span class="sourceLineNo">228</span>          HConstants.MERGEA_QUALIFIER);<a name="line.228"></a>
-<span class="sourceLineNo">229</span>      HRegionInfo regionB = HRegionInfo.getHRegionInfo(mergedRegionResult,<a name="line.229"></a>
-<span class="sourceLineNo">230</span>          HConstants.MERGEB_QUALIFIER);<a name="line.230"></a>
-<span class="sourceLineNo">231</span>      FileSystem fs = master.getMasterFileSystem().getFileSystem();<a name="line.231"></a>
-<span class="sourceLineNo">232</span>      Path rootDir = master.getMasterFileSystem().getRootDir();<a name="line.232"></a>
-<span class="sourceLineNo">233</span><a name="line.233"></a>
-<span class="sourceLineNo">234</span>      Path tabledir = FSUtils.getTableDir(rootDir, mergedRegionInfo.getTable());<a name="line.234"></a>
-<span class="sourceLineNo">235</span>      Path regionAdir = new Path(tabledir, regionA.getEncodedName());<a name="line.235"></a>
-<span class="sourceLineNo">236</span>      Path regionBdir = new Path(tabledir, regionB.getEncodedName());<a name="line.236"></a>
-<span class="sourceLineNo">237</span>      assertTrue(fs.exists(regionAdir));<a name="line.237"></a>
-<span class="sourceLineNo">238</span>      assertTrue(fs.exists(regionBdir));<a name="line.238"></a>
-<span class="sourceLineNo">239</span><a name="line.239"></a>
-<span class="sourceLineNo">240</span>      admin.compactRegion(mergedRegionInfo.getRegionName());<a name="line.240"></a>
-<span class="sourceLineNo">241</span>      // wait until merged region doesn't have reference file<a name="line.241"></a>
-<span class="sourceLineNo">242</span>      long timeout = System.currentTimeMillis() + waitTime;<a name="line.242"></a>
-<span class="sourceLineNo">243</span>      HRegionFileSystem hrfs = new HRegionFileSystem(<a name="line.243"></a>
-<span class="sourceLineNo">244</span>          TEST_UTIL.getConfiguration(), fs, tabledir, mergedRegionInfo);<a name="line.244"></a>
-<span class="sourceLineNo">245</span>      while (System.currentTimeMillis() &lt; timeout) {<a name="line.245"></a>
-<span class="sourceLineNo">246</span>        if (!hrfs.hasReferences(tableDescritor)) {<a name="line.246"></a>
-<span class="sourceLineNo">247</span>          break;<a name="line.247"></a>
-<span class="sourceLineNo">248</span>        }<a name="line.248"></a>
-<span class="sourceLineNo">249</span>        Thread.sleep(50);<a name="line.249"></a>
-<span class="sourceLineNo">250</span>      }<a name="line.250"></a>
-<span class="sourceLineNo">251</span>      assertFalse(hrfs.hasReferences(tableDescritor));<a name="line.251"></a>
-<span class="sourceLineNo">252</span><a name="line.252"></a>
-<span class="sourceLineNo">253</span>      // run CatalogJanitor to clean merge references in hbase:meta and archive the<a name="line.253"></a>
-<span class="sourceLineNo">254</span>      // files of merging regions<a name="line.254"></a>
-<span class="sourceLineNo">255</span>      int cleaned = admin.runCatalogScan();<a name="line.255"></a>
-<span class="sourceLineNo">256</span>      assertTrue(cleaned &gt; 0);<a name="line.256"></a>
-<span class="sourceLineNo">257</span>      assertFalse(fs.exists(regionAdir));<a name="line.257"></a>
-<span class="sourceLineNo">258</span>      assertFalse(fs.exists(regionBdir));<a name="line.258"></a>
-<span class="sourceLineNo">259</span><a name="line.259"></a>
-<span class="sourceLineNo">260</span>      mergedRegionResult = MetaTableAccessor.getRegionResult(<a name="line.260"></a>
-<span class="sourceLineNo">261</span>        master.getConnection(), mergedRegionInfo.getRegionName());<a name="line.261"></a>
-<span class="sourceLineNo">262</span>      assertFalse(mergedRegionResult.getValue(HConstants.CATALOG_FAMILY,<a name="line.262"></a>
-<span class="sourceLineNo">263</span>          HConstants.MERGEA_QUALIFIER) != null);<a name="line.263"></a>
-<span class="sourceLineNo">264</span>      assertFalse(mergedRegionResult.getValue(HConstants.CATALOG_FAMILY,<a name="line.264"></a>
-<span class="sourceLineNo">265</span>          HConstants.MERGEB_QUALIFIER) != null);<a name="line.265"></a>
-<span class="sourceLineNo">266</span><a name="line.266"></a>
-<span class="sourceLineNo">267</span>    } finally {<a name="line.267"></a>
-<span class="sourceLineNo">268</span>      admin.enableCatalogJanitor(true);<a name="line.268"></a>
-<span class="sourceLineNo">269</span>    }<a name="line.269"></a>
-<span class="sourceLineNo">270</span>  }<a name="line.270"></a>
-<span class="sourceLineNo">271</span><a name="line.271"></a>
-<span class="sourceLineNo">272</span>  /**<a name="line.272"></a>
-<span class="sourceLineNo">273</span>   * This test tests 1, merging region not online;<a name="line.273"></a>
-<span class="sourceLineNo">274</span>   * 2, merging same two regions; 3, merging unknown regions.<a name="line.274"></a>
-<span class="sourceLineNo">275</span>   * They are in one test case so that we don't have to create<a name="line.275"></a>
-<span class="sourceLineNo">276</span>   * many tables, and these tests are simple.<a name="line.276"></a>
-<span class="sourceLineNo">277</span>   */<a name="line.277"></a>
-<span class="sourceLineNo">278</span>  @Test<a name="line.278"></a>
-<span class="sourceLineNo">279</span>  public void testMerge() throws Exception {<a name="line.279"></a>
-<span class="sourceLineNo">280</span>    LOG.info("Starting testMerge");<a name="line.280"></a>
-<span class="sourceLineNo">281</span>    final TableName tableName = TableName.valueOf("testMerge");<a name="line.281"></a>
-<span class="sourceLineNo">282</span><a name="line.282"></a>
-<span class="sourceLineNo">283</span>    try {<a name="line.283"></a>
-<span class="sourceLineNo">284</span>      // Create table and load data.<a name="line.284"></a>
-<span class="sourceLineNo">285</span>      Table table = createTableAndLoadData(master, tableName);<a name="line.285"></a>
-<span class="sourceLineNo">286</span>      RegionStates regionStates = master.getAssignmentManager().getRegionStates();<a name="line.286"></a>
-<span class="sourceLineNo">287</span>      List&lt;HRegionInfo&gt; regions = regionStates.getRegionsOfTable(tableName);<a name="line.287"></a>
-<span class="sourceLineNo">288</span>      // Fake offline one region<a name="line.288"></a>
-<span class="sourceLineNo">289</span>      HRegionInfo a = regions.get(0);<a name="line.289"></a>
-<span class="sourceLineNo">290</span>      HRegionInfo b = regions.get(1);<a name="line.290"></a>
-<span class="sourceLineNo">291</span>      regionStates.regionOffline(a);<a name="line.291"></a>
-<span class="sourceLineNo">292</span>      try {<a name="line.292"></a>
-<span class="sourceLineNo">293</span>        // Merge offline region. Region a is offline here<a name="line.293"></a>
-<span class="sourceLineNo">294</span>        admin.mergeRegions(a.getEncodedNameAsBytes(), b.getEncodedNameAsBytes(), false);<a name="line.294"></a>
-<span class="sourceLineNo">295</span>        fail("Offline regions should not be able to merge");<a name="line.295"></a>
-<span class="sourceLineNo">296</span>      } catch (IOException ie) {<a name="line.296"></a>
-<span class="sourceLineNo">297</span>        System.out.println(ie);<a name="line.297"></a>
-<span class="sourceLineNo">298</span>        assertTrue("Exception should mention regions not online",<a name="line.298"></a>
-<span class="sourceLineNo">299</span>          StringUtils.stringifyException(ie).contains("regions not online")<a name="line.299"></a>
-<span class="sourceLineNo">300</span>            &amp;&amp; ie instanceof MergeRegionException);<a name="line.300"></a>
-<span class="sourceLineNo">301</span>      }<a name="line.301"></a>
-<span class="sourceLineNo">302</span>      try {<a name="line.302"></a>
-<span class="sourceLineNo">303</span>        // Merge the same region: b and b.<a name="line.303"></a>
-<span class="sourceLineNo">304</span>        admin.mergeRegions(b.getEncodedNameAsBytes(), b.getEncodedNameAsBytes(), true);<a name="line.304"></a>
-<span class="sourceLineNo">305</span>        fail("A region should not be able to merge with itself, even forcifully");<a name="line.305"></a>
-<span class="sourceLineNo">306</span>      } catch (IOException ie) {<a name="line.306"></a>
-<span class="sourceLineNo">307</span>        assertTrue("Exception should mention regions not online",<a name="line.307"></a>
-<span class="sourceLineNo">308</span>          StringUtils.stringifyException(ie).contains("region to itself")<a name="line.308"></a>
-<span class="sourceLineNo">309</span>            &amp;&amp; ie instanceof MergeRegionException);<a name="line.309"></a>
-<span class="sourceLineNo">310</span>      }<a name="line.310"></a>
-<span class="sourceLineNo">311</span>      try {<a name="line.311"></a>
-<span class="sourceLineNo">312</span>        // Merge unknown regions<a name="line.312"></a>
-<span class="sourceLineNo">313</span>        admin.mergeRegions(Bytes.toBytes("-f1"), Bytes.toBytes("-f2"), true);<a name="line.313"></a>
-<span class="sourceLineNo">314</span>        fail("Unknown region could not be merged");<a name="line.314"></a>
-<span class="sourceLineNo">315</span>      } catch (IOException ie) {<a name="line.315"></a>
-<span class="sourceLineNo">316</span>        assertTrue("UnknownRegionException should be thrown",<a name="line.316"></a>
-<span class="sourceLineNo">317</span>          ie instanceof UnknownRegionException);<a name="line.317"></a>
-<span class="sourceLineNo">318</span>      }<a name="line.318"></a>
-<span class="sourceLineNo">319</span>      table.close();<a name="line.319"></a>
-<span class="sourceLineNo">320</span>    } finally {<a name="line.320"></a>
-<span class="sourceLineNo">321</span>      TEST_UTIL.deleteTable(tableName);<a name="line.321"></a>
-<span class="sourceLineNo">322</span>    }<a name="line.322"></a>
-<span class="sourceLineNo">323</span>  }<a name="line.323"></a>
-<span class="sourceLineNo">324</span><a name="line.324"></a>
-<span class="sourceLineNo">325</span>  @Test<a name="line.325"></a>
-<span class="sourceLineNo">326</span>  public void testMergeWithReplicas() throws Exception {<a name="line.326"></a>
-<span class="sourceLineNo">327</span>    final TableName tableName = TableName.valueOf("testMergeWithReplicas");<a name="line.327"></a>
-<span class="sourceLineNo">328</span>    // Create table and load data.<a name="line.328"></a>
-<span class="sourceLineNo">329</span>    createTableAndLoadData(master, tableName, 5, 2);<a name="line.329"></a>
-<span class="sourceLineNo">330</span>    List&lt;Pair&lt;HRegionInfo, ServerName&gt;&gt; initialRegionToServers =<a name="line.330"></a>
-<span class="sourceLineNo">331</span>        MetaTableAccessor.getTableRegionsAndLocations(<a name="line.331"></a>
-<span class="sourceLineNo">332</span>            master.getConnection(), tableName);<a name="line.332"></a>
-<span class="sourceLineNo">333</span>    // Merge 1st and 2nd region<a name="line.333"></a>
-<span class="sourceLineNo">334</span>    PairOfSameType&lt;HRegionInfo&gt; mergedRegions = mergeRegionsAndVerifyRegionNum(master, tableName,<a name="line.334"></a>
-<span class="sourceLineNo">335</span>        0, 2, 5 * 2 - 2);<a name="line.335"></a>
-<span class="sourceLineNo">336</span>    List&lt;Pair&lt;HRegionInfo, ServerName&gt;&gt; currentRegionToServers =<a name="line.336"></a>
-<span class="sourceLineNo">337</span>        MetaTableAccessor.getTableRegionsAndLocations(<a name="line.337"></a>
-<span class="sourceLineNo">338</span>            master.getConnection(), tableName);<a name="line.338"></a>
-<span class="sourceLineNo">339</span>    List&lt;HRegionInfo&gt; initialRegions = new ArrayList&lt;HRegionInfo&gt;();<a name="line.339"></a>
-<span class="sourceLineNo">340</span>    for (Pair&lt;HRegionInfo, ServerName&gt; p : initialRegionToServers) {<a name="line.340"></a>
-<span class="sourceLineNo">341</span>      initialRegions.add(p.getFirst());<a name="line.341"></a>
-<span class="sourceLineNo">342</span>    }<a name="line.342"></a>
-<span class="sourceLineNo">343</span>    List&lt;HRegionInfo&gt; currentRegions = new ArrayList&lt;HRegionInfo&gt;();<a name="line.343"></a>
-<span class="sourceLineNo">344</span>    for (Pair&lt;HRegionInfo, ServerName&gt; p : currentRegionToServers) {<a name="line.344"></a>
-<span class="sourceLineNo">345</span>      currentRegions.add(p.getFirst());<a name="line.345"></a>
-<span class="sourceLineNo">346</span>    }<a name="line.346"></a>
-<span class="sourceLineNo">347</span>    assertTrue(initialRegions.contains(mergedRegions.getFirst())); //this is the first region<a name="line.347"></a>
-<span class="sourceLineNo">348</span>    assertTrue(initialRegions.contains(RegionReplicaUtil.getRegionInfoForReplica(<a name="line.348"></a>
-<span class="sourceLineNo">349</span>        mergedRegions.getFirst(), 1))); //this is the replica of the first region<a name="line.349"></a>
-<span class="sourceLineNo">350</span>    assertTrue(initialRegions.contains(mergedRegions.getSecond())); //this is the second region<a name="line.350"></a>
-<span class="sourceLineNo">351</span>    assertTrue(initialRegions.contains(RegionReplicaUtil.getRegionInfoForReplica(<a name="line.351"></a>
-<span class="sourceLineNo">352</span>        mergedRegions.getSecond(), 1))); //this is the replica of the second region<a name="line.352"></a>
-<span class="sourceLineNo">353</span>    assertTrue(!initialRegions.contains(currentRegions.get(0))); //this is the new region<a name="line.353"></a>
-<span class="sourceLineNo">354</span>    assertTrue(!initialRegions.contains(RegionReplicaUtil.getRegionInfoForReplica(<a name="line.354"></a>
-<span class="sourceLineNo">355</span>        currentRegions.get(0), 1))); //replica of the new region<a name="line.355"></a>
-<span class="sourceLineNo">356</span>    assertTrue(currentRegions.contains(RegionReplicaUtil.getRegionInfoForReplica(<a name="line.356"></a>
-<span class="sourceLineNo">357</span>        currentRegions.get(0), 1))); //replica of the new region<a name="line.357"></a>
-<span class="sourceLineNo">358</span>    assertTrue(!currentRegions.contains(RegionReplicaUtil.getRegionInfoForReplica(<a name="line.358"></a>
-<span class="sourceLineNo">359</span>        mergedRegions.getFirst(), 1))); //replica of the merged region<a name="line.359"></a>
-<span class="sourceLineNo">360</span>    assertTrue(!currentRegions.contains(RegionReplicaUtil.getRegionInfoForReplica(<a name="line.360"></a>
-<span class="sourceLineNo">361</span>        mergedRegions.getSecond(), 1))); //replica of the merged region<a name="line.361"></a>
-<span class="sourceLineNo">362</span>  }<a name="line.362"></a>
-<span class="sourceLineNo">363</span><a name="line.363"></a>
-<span class="sourceLineNo">364</span>  private PairOfSameType&lt;HRegionInfo&gt; mergeRegionsAndVerifyRegionNum(<a name="line.364"></a>
-<span class="sourceLineNo">365</span>      HMaster master, TableName tablename,<a name="line.365"></a>
-<span class="sourceLineNo">366</span>      int regionAnum, int regionBnum, int expectedRegionNum) throws Exception {<a name="line.366"></a>
-<span class="sourceLineNo">367</span>    PairOfSameType&lt;HRegionInfo&gt; mergedRegions =<a name="line.367"></a>
-<span class="sourceLineNo">368</span>      requestMergeRegion(master, tablename, regionAnum, regionBnum);<a name="line.368"></a>
-<span class="sourceLineNo">369</span>    waitAndVerifyRegionNum(master, tablename, expectedRegionNum);<a name="line.369"></a>
-<span class="sourceLineNo">370</span>    return mergedRegions;<a name="line.370"></a>
-<span class="sourceLineNo">371</span>  }<a name="line.371"></a>
-<span class="sourceLineNo">372</span><a name="line.372"></a>
-<span class="sourceLineNo">373</span>  private PairOfSameType&lt;HRegionInfo&gt; requestMergeRegion(<a name="line.373"></a>
-<span class="sourceLineNo">374</span>      HMaster master, TableName tablename,<a name="line.374"></a>
-<span class="sourceLineNo">375</span>      int regionAnum, int regionBnum) throws Exception {<a name="line.375"></a>
-<span class="sourceLineNo">376</span>    List&lt;Pair&lt;HRegionInfo, ServerName&gt;&gt; tableRegions = MetaTableAccessor<a name="line.376"></a>
-<span class="sourceLineNo">377</span>        .getTableRegionsAndLocations(<a name="line.377"></a>
-<span class="sourceLineNo">378</span>          master.getConnection(), tablename);<a name="line.378"></a>
-<span class="sourceLineNo">379</span>    HRegionInfo regionA = tableRegions.get(regionAnum).getFirst();<a name="line.379"></a>
-<span class="sourceLineNo">380</span>    HRegionInfo regionB = tableRegions.get(regionBnum).getFirst();<a name="line.380"></a>
-<span class="sourceLineNo">381</span>    TEST_UTIL.getHBaseAdmin().mergeRegions(<a name="line.381"></a>
-<span class="sourceLineNo">382</span>      regionA.getEncodedNameAsBytes(),<a name="line.382"></a>
-<span class="sourceLineNo">383</span>      regionB.getEncodedNameAsBytes(), false);<a name="line.383"></a>
-<span class="sourceLineNo">384</span>    return new PairOfSameType&lt;HRegionInfo&gt;(regionA, regionB);<a name="line.384"></a>
-<span class="sourceLineNo">385</span>  }<a name="line.385"></a>
-<span class="sourceLineNo">386</span><a name="line.386"></a>
-<span class="sourceLineNo">387</span>  private void waitAndVerifyRegionNum(HMaster master, TableName tablename,<a name="line.387"></a>
-<span class="sourceLineNo">388</span>      int expectedRegionNum) throws Exception {<a name="line.388"></a>
-<span class="sourceLineNo">389</span>    List&lt;Pair&lt;HRegionInfo, ServerName&gt;&gt; tableRegionsInMeta;<a name="line.389"></a>
-<span class="sourceLineNo">390</span>    List&lt;HRegionInfo&gt; tableRegionsInMaster;<a name="line.390"></a>
-<span class="sourceLineNo">391</span>    long timeout = System.currentTimeMillis() + waitTime;<a name="line.391"></a>
-<span class="sourceLineNo">392</span>    while (System.currentTimeMillis() &lt; timeout) {<a name="line.392"></a>
-<span class="sourceLineNo">393</span>      tableRegionsInMeta = MetaTableAccessor.getTableRegionsAndLocations(<a name="line.393"></a>
-<span class="sourceLineNo">394</span>        master.getConnection(), tablename);<a name="line.394"></a>
-<span class="sourceLineNo">395</span>      tableRegionsInMaster = master.getAssignmentManager().getRegionStates()<a name="line.395"></a>
-<span class="sourceLineNo">396</span>          .getRegionsOfTable(tablename);<a name="line.396"></a>
-<span class="sourceLineNo">397</span>      if (tableRegionsInMeta.size() == expectedRegionNum<a name="line.397"></a>
-<span class="sourceLineNo">398</span>          &amp;&amp; tableRegionsInMaster.size() == expectedRegionNum) {<a name="line.398"></a>
-<span class="sourceLineNo">399</span>        break;<a name="line.399"></a>
-<span class="sourceLineNo">400</span>      }<a name="line.400"></a>
-<span class="sourceLineNo">401</span>      Thread.sleep(250);<a name="line.401"></a>
-<span class="sourceLineNo">402</span>    }<a name="line.402"></a>
-<span class="sourceLineNo">403</span><a name="line.403"></a>
-<span class="sourceLineNo">404</span>    tableRegionsInMeta = MetaTableAccessor.getTableRegionsAndLocations(<a name="line.404"></a>
-<span class="sourceLineNo">405</span>      master.getConnection(), tablename);<a name="line.405"></a>
-<span class="sourceLineNo">406</span>    LOG.info("Regions after merge:" + Joiner.on(',').join(tableRegionsInMeta));<a name="line.406"></a>
-<span class="sourceLineNo">407</span>    assertEquals(expectedRegionNum, tableRegionsInMeta.size());<a name="line.407"></a>
-<span class="sourceLineNo">408</span>  }<a name="line.408"></a>
-<span class="sourceLineNo">409</span><a name="line.409"></a>
-<span class="sourceLineNo">410</span>  private Table createTableAndLoadData(HMaster master, TableName tablename)<a name="line.410"></a>
-<span class="sourceLineNo">411</span>      throws Exception {<a name="line.411"></a>
-<span class="sourceLineNo">412</span>    return createTableAndLoadData(master, tablename, INITIAL_REGION_NUM, 1);<a name="line.412"></a>
-<span class="sourceLineNo">413</span>  }<a name="line.413"></a>
-<span class="sourceLineNo">414</span><a name="line.414"></a>
-<span class="sourceLineNo">415</span>  private Table createTableAndLoadData(HMaster master, TableName tablename,<a name="line.415"></a>
-<span class="sourceLineNo">416</span>      int numRegions, int replication) throws Exception {<a name="line.416"></a>
-<span class="sourceLineNo">417</span>    assertTrue("ROWSIZE must &gt; numregions:" + numRegions, ROWSIZE &gt; numRegions);<a name="line.417"></a>
-<span class="sourceLineNo">418</span>    byte[][] splitRows = new byte[numRegions - 1][];<a name="line.418"></a>
-<span class="sourceLineNo">419</span>    for (int i = 0; i &lt; splitRows.length; i++) {<a name="line.419"></a>
-<span class="sourceLineNo">420</span>      splitRows[i] = ROWS[(i + 1) * ROWSIZE / numRegions];<a name="line.420"></a>
-<span class="sourceLineNo">421</span>    }<a name="line.421"></a>
-<span class="sourceLineNo">422</span><a name="line.422"></a>
-<span class="sourceLineNo">423</span>    Table table = TEST_UTIL.createTable(tablename, FAMILYNAME, splitRows);<a name="line.423"></a>
-<span class="sourceLineNo">424</span>    if (replication &gt; 1) {<a name="line.424"></a>
-<span class="sourceLineNo">425</span>      HBaseTestingUtility.setReplicas(admin, tablename, replication);<a name="line.425"></a>
-<span class="sourceLineNo">426</span>    }<a name="line.426"></a>
-<span class="sourceLineNo">427</span>    loadData(table);<a name="line.427"></a>
-<span class="sourceLineNo">428</span>    verifyRowCount(table, ROWSIZE);<a name="line.428"></a>
-<span class="sourceLineNo">429</span><a name="line.429"></a>
-<span class="sourceLineNo">430</span>    // sleep here is an ugly hack to allow region transitions to finish<a name="line.430"></a>
-<span class="sourceLineNo">431</span>    long timeout = System.currentTimeMillis() + waitTime;<a name="line.431"></a>
-<span class="sourceLineNo">432</span>    List&lt;Pair&lt;HRegionInfo, ServerName&gt;&gt; tableRegions;<a name="line.432"></a>
-<span class="sourceLineNo">433</span>    while (System.currentTimeMillis() &lt; timeout) {<a name="line.433"></a>
-<span class="sourceLineNo">434</span>      tableRegions = MetaTableAccessor.getTableRegionsAndLocations(<a name="line.434"></a>
-<span class="sourceLineNo">435</span>        master.getConnection(), tablename);<a name="line.435"></a>
-<span class="sourceLineNo">436</span>      if (tableRegions.size() == numRegions * replication)<a name="line.436"></a>
-<span class="sourceLineNo">437</span>        break;<a name="line.437"></a>
-<span class="sourceLineNo">438</span>      Thread.sleep(250);<a name="line.438"></a>
-<span class="sourceLineNo">439</span>    }<a name="line.439"></a>
-<span class="sourceLineNo">440</span><a name="line.440"></a>
-<span class="sourceLineNo">441</span>    tableRegions = MetaTableAccessor.getTableRegionsAndLocations(<a name="line.441"></a>
-<span class="sourceLineNo">442</span>      master.getConnection(), tablename);<a name="line.442"></a>
-<span class="sourceLineNo">443</span>    LOG.info("Regions after load: " + Joiner.on(',').join(tableRegions));<a name="line.443"></a>
-<span class="sourceLineNo">444</span>    assertEquals(numRegions * replication, tableRegions.size());<a name="line.444"></a>
-<span class="sourceLineNo">445</span>    return table;<a name="line.445"></a>
-<span class="sourceLineNo">446</span>  }<a name="line.446"></a>
-<span class="sourceLineNo">447</span><a name="line.447"></a>
-<span class="sourceLineNo">448</span>  private static byte[][] makeN(byte[] base, int n) {<a name="line.448"></a>
-<span class="sourceLineNo">449</span>    byte[][] ret = new byte[n][];<a name="line.449"></a>
-<span class="sourceLineNo">450</span>    for (int i = 0; i &lt; n; i++) {<a name="line.450"></a>
-<span class="sourceLineNo">451</span>      ret[i] = Bytes.add(base, Bytes.toBytes(String.format("%04d", i)));<a name="line.451"></a>
-<span class="sourceLineNo">452</span>    }<a name="line.452"></a>
-<span class="sourceLineNo">453</span>    return ret;<a name="line.453"></a>
-<span class="sourceLineNo">454</span>  }<a name="line.454"></a>
-<span class="sourceLineNo">455</span><a name="line.455"></a>
-<span class="sourceLineNo">456</span>  private void loadData(Table table) throws IOException {<a name="line.456"></a>
-<span class="sourceLineNo">457</span>    for (int i = 0; i &lt; ROWSIZE; i++) {<a name="line.457"></a>
-<span class="sourceLineNo">458</span>      Put put = new Put(ROWS[i]);<a name="line.458"></a>
-<span class="sourceLineNo">459</span>      put.addColumn(FAMILYNAME, QUALIFIER, Bytes.toBytes(i));<a name="line.459"></a>
-<span class="sourceLineNo">460</span>      table.put(put);<a name="line.460"></a>
-<span class="sourceLineNo">461</span>    }<a name="line.461"></a>
-<span class="sourceLineNo">462</span>  }<a name="line.462"></a>
-<span class="sourceLineNo">463</span><a name="line.463"></a>
-<span class="sourceLineNo">464</span>  private void verifyRowCount(Table table, int expectedRegionNum)<a name="line.464"></a>
-<span class="sourceLineNo">465</span>      throws IOException {<a name="line.465"></a>
-<span class="sourceLineNo">466</span>    ResultScanner scanner = table.getScanner(new Scan());<a name="line.466"></a>
-<span class="sourceLineNo">467</span>    int rowCount = 0;<a name="line.467"></a>
-<span class="sourceLineNo">468</span>    while (scanner.next() != null) {<a name="line.468"></a>
-<span class="sourceLineNo">469</span>      rowCount++;<a name="line.469"></a>
-<span class="sourceLineNo">470</span>    }<a name="line.470"></a>
-<span class="sourceLineNo">471</span>    assertEquals(expectedRegionNum, rowCount);<a name="line.471"></a>
-<span class="sourceLineNo">472</span>    scanner.close();<a name="line.472"></a>
-<span class="sourceLineNo">473</span>  }<a name="line.473"></a>
-<span class="sourceLineNo">474</span><a name="line.474"></a>
-<span class="sourceLineNo">475</span>  // Make it public so that JVMClusterUtil can access it.<a name="line.475"></a>
-<span class="sourceLineNo">476</span>  public static class MyMaster extends HMaster {<a name="line.476"></a>
-<span class="sourceLineNo">477</span>    public MyMaster(Configuration conf, CoordinatedStateManager cp)<a name="line.477"></a>
-<span class="sourceLineNo">478</span>      throws IOException, KeeperException,<a name="line.478"></a>
-<span class="sourceLineNo">479</span>        InterruptedException {<a name="line.479"></a>
-<span class="sourceLineNo">480</span>      super(conf, cp);<a name="line.480"></a>
-<span class="sourceLineNo">481</span>    }<a name="line.481"></a>
-<span class="sourceLineNo">482</span><a name="line.482"></a>
-<span class="sourceLineNo">483</span>    @Override<a name="line.483"></a>
-<span class="sourceLineNo">484</span>    protected RSRpcServices createRpcServices() throws IOException {<a name="line.484"></a>
-<span class="sourceLineNo">485</span>      return new MyMasterRpcServices(this);<a name="line.485"></a>
-<span class="sourceLineNo">486</span>    }<a name="line.486"></a>
-<span class="sourceLineNo">487</span>  }<a name="line.487"></a>
-<span class="sourceLineNo">488</span><a name="line.488"></a>
-<span class="sourceLineNo">489</span>  static class MyMasterRpcServices extends MasterRpcServices {<a name="line.489"></a>
-<span class="sourceLineNo">490</span>    static AtomicBoolean enabled = new AtomicBoolean(false);<a name="line.490"></a>
-<span class="sourceLineNo">491</span><a name="line.491"></a>
-<span class="sourceLineNo">492</span>    private HMaster myMaster;<a name="line.492"></a>
-<span class="sourceLineNo">493</span>    public MyMasterRpcServices(HMaster master) throws IOException {<a name="line.493"></a>
-<span class="sourceLineNo">494</span>      super(master);<a name="line.494"></a>
-<span class="sourceLineNo">495</span>      myMaster = master;<a name="line.495"></a>
-<span class="sourceLineNo">496</span>    }<a name="line.496"></a>
-<span class="sourceLineNo">497</span><a name="line.497"></a>
-<span class="sourceLineNo">498</span>    @Override<a name="line.498"></a>
-<span class="sourceLineNo">499</span>    public ReportRegionStateTransitionResponse reportRegionStateTransition(RpcController c,<a name="line.499"></a>
-<span class="sourceLineNo">500</span>        ReportRegionStateTransitionRequest req) throws ServiceException {<a name="line.500"></a>
-<span class="sourceLineNo">501</span>      ReportRegionStateTransitionResponse resp = super.reportRegionStateTransition(c, req);<a name="line.501"></a>
-<span class="sourceLineNo">502</span>      if (enabled.get() &amp;&amp; req.getTransition(0).getTransitionCode()<a name="line.502"></a>
-<span class="sourceLineNo">503</span>          == TransitionCode.READY_TO_MERGE &amp;&amp; !resp.hasErrorMessage()) {<a name="line.503"></a>
-<span class="sourceLineNo">504</span>        RegionStates regionStates = myMaster.getAssignmentManager().getRegionStates();<a name="line.504"></a>
-<span class="sourceLineNo">505</span>        for (RegionState regionState: regionStates.getRegionsInTransition().values()) {<a name="line.505"></a>
-<span class="sourceLineNo">506</span>          // Find the merging_new region and remove it<a name="line.506"></a>
-<span class="sourceLineNo">507</span>          if (regionState.isMergingNew()) {<a name="line.507"></a>
-<span class="sourceLineNo">508</span>            regionStates.deleteRegion(regionState.getRegion());<a name="line.508"></a>
-<span class="sourceLineNo">509</span>          }<a name="line.509"></a>
-<span class="sourceLineNo">510</span>        }<a name="line.510"></a>
-<span class="sourceLineNo">511</span>      }<a name="line.511"></a>
-<span class="sourceLineNo">512</span>      return resp;<a name="line.512"></a>
-<span class="sourceLineNo">513</span>    }<a name="line.513"></a>
-<span class="sourceLineNo">514</span>  }<a name="line.514"></a>
-<span class="sourceLineNo">515</span>}<a name="line.515"></a>
+<span class="sourceLineNo">227</span>      PairOfSameType&lt;HRegionInfo&gt; p = MetaTableAccessor.getMergeRegions(mergedRegionResult);<a name="line.227"></a>
+<span class="sourceLineNo">228</span>      HRegionInfo regionA = p.getFirst();<a name="line.228"></a>
+<span class="sourceLineNo">229</span>      HRegionInfo regionB = p.getSecond();<a name="line.229"></a>
+<span class="sourceLineNo">230</span>      FileSystem fs = master.getMasterFileSystem().getFileSystem();<a name="line.230"></a>
+<span class="sourceLineNo">231</span>      Path rootDir = master.getMasterFileSystem().getRootDir();<a name="line.231"></a>
+<span class="sourceLineNo">232</span><a name="line.232"></a>
+<span class="sourceLineNo">233</span>      Path tabledir = FSUtils.getTableDir(rootDir, mergedRegionInfo.getTable());<a name="line.233"></a>
+<span class="sourceLineNo">234</span>      Path regionAdir = new Path(tabledir, regionA.getEncodedName());<a name="line.234"></a>
+<span class="sourceLineNo">235</span>      Path regionBdir = new Path(tabledir, regionB.getEncodedName());<a name="line.235"></a>
+<span class="sourceLineNo">236</span>      assertTrue(fs.exists(regionAdir));<a name="line.236"></a>
+<span class="sourceLineNo">237</span>      assertTrue(fs.exists(regionBdir));<a name="line.237"></a>
+<span class="sourceLineNo">238</span><a name="line.238"></a>
+<span class="sourceLineNo">239</span>      admin.compactRegion(mergedRegionInfo.getRegionName());<a name="line.239"></a>
+<span class="sourceLineNo">240</span>      // wait until merged region doesn't have reference file<a name="line.240"></a>
+<span class="sourceLineNo">241</span>      long timeout = System.currentTimeMillis() + waitTime;<a name="line.241"></a>
+<span class="sourceLineNo">242</span>      HRegionFileSystem hrfs = new HRegionFileSystem(<a name="line.242"></a>
+<span class="sourceLineNo">243</span>          TEST_UTIL.getConfiguration(), fs, tabledir, mergedRegionInfo);<a name="line.243"></a>
+<span class="sourceLineNo">244</span>      while (System.currentTimeMillis() &lt; timeout) {<a name="line.244"></a>
+<span class="sourceLineNo">245</span>        if (!hrfs.hasReferences(tableDescritor)) {<a name="line.245"></a>
+<span class="sourceLineNo">246</span>          break;<a name="line.246"></a>
+<span class="sourceLineNo">247</span>        }<a name="line.247"></a>
+<span class="sourceLineNo">248</span>        Thread.sleep(50);<a name="line.248"></a>
+<span class="sourceLineNo">249</span>      }<a name="line.249"></a>
+<span class="sourceLineNo">250</span>      assertFalse(hrfs.hasReferences(tableDescritor));<a name="line.250"></a>
+<span class="sourceLineNo">251</span><a name="line.251"></a>
+<span class="sourceLineNo">252</span>      // run CatalogJanitor to clean merge references in hbase:meta and archive the<a name="line.252"></a>
+<span class="sourceLineNo">253</span>      // files of merging regions<a name="line.253"></a>
+<span class="sourceLineNo">254</span>      int cleaned = admin.runCatalogScan();<a name="line.254"></a>
+<span class="sourceLineNo">255</span>      assertTrue(cleaned &gt; 0);<a name="line.255"></a>
+<span class="sourceLineNo">256</span>      assertFalse(fs.exists(regionAdir));<a name="line.256"></a>
+<span class="sourceLineNo">257</span>      assertFalse(fs.exists(regionBdir));<a name="line.257"></a>
+<span class="sourceLineNo">258</span><a name="line.258"></a>
+<span class="sourceLineNo">259</span>      mergedRegionResult = MetaTableAccessor.getRegionResult(<a name="line.259"></a>
+<span class="sourceLineNo">260</span>        master.getConnection(), mergedRegionInfo.getRegionName());<a name="line.260"></a>
+<span class="sourceLineNo">261</span>      assertFalse(mergedRegionResult.getValue(HConstants.CATALOG_FAMILY,<a name="line.261"></a>
+<span class="sourceLineNo">262</span>          HConstants.MERGEA_QUALIFIER) != null);<a name="line.262"></a>
+<span class="sourceLineNo">263</span>      assertFalse(mergedRegionResult.getValue(HConstants.CATALOG_FAMILY,<a name="line.263"></a>
+<span class="sourceLineNo">264</span>          HConstants.MERGEB_QUALIFIER) != null);<a name="line.264"></a>
+<span class="sourceLineNo">265</span><a name="line.265"></a>
+<span class="sourceLineNo">266</span>    } finally {<a name="line.266"></a>
+<span class="sourceLineNo">267</span>      admin.enableCatalogJanitor(true);<a name="line.267"></a>
+<span class="sourceLineNo">268</span>    }<a name="line.268"></a>
+<span class="sourceLineNo">269</span>  }<a name="line.269"></a>
+<span class="sourceLineNo">270</span><a name="line.270"></a>
+<span class="sourceLineNo">271</span>  /**<a name="line.271"></a>
+<span class="sourceLineNo">272</span>   * This test tests 1, merging region not online;<a name="line.272"></a>
+<span class="sourceLineNo">273</span>   * 2, merging same two regions; 3, merging unknown regions.<a name="line.273"></a>
+<span class="sourceLineNo">274</span>   * They are in one test case so that we don't have to create<a name="line.274"></a>
+<span class="sourceLineNo">275</span>   * many tables, and these tests are simple.<a name="line.275"></a>
+<span class="sourceLineNo">276</span>   */<a name="line.276"></a>
+<span class="sourceLineNo">277</span>  @Test<a name="line.277"></a>
+<span class="sourceLineNo">278</span>  public void testMerge() throws Exception {<a name="line.278"></a>
+<span class="sourceLineNo">279</span>    LOG.info("Starting testMerge");<a name="line.279"></a>
+<span class="sourceLineNo">280</span>    final TableName tableName = TableName.valueOf("testMerge");<a name="line.280"></a>
+<span class="sourceLineNo">281</span><a name="line.281"></a>
+<span class="sourceLineNo">282</span>    try {<a name="line.282"></a>
+<span class="sourceLineNo">283</span>      // Create table and load data.<a name="line.283"></a>
+<span class="sourceLineNo">284</span>      Table table = createTableAndLoadData(master, tableName);<a name="line.284"></a>
+<span class="sourceLineNo">285</span>      RegionStates regionStates = master.getAssignmentManager().getRegionStates();<a name="line.285"></a>
+<span class="sourceLineNo">286</span>      List&lt;HRegionInfo&gt; regions = regionStates.getRegionsOfTable(tableName);<a name="line.286"></a>
+<span class="sourceLineNo">287</span>      // Fake offline one region<a name="line.287"></a>
+<span class="sourceLineNo">288</span>      HRegionInfo a = regions.get(0);<a name="line.288"></a>
+<span class="sourceLineNo">289</span>      HRegionInfo b = regions.get(1);<a name="line.289"></a>
+<span class="sourceLineNo">290</span>      regionStates.regionOffline(a);<a name="line.290"></a>
+<span class="sourceLineNo">291</span>      try {<a name="line.291"></a>
+<span class="sourceLineNo">292</span>        // Merge offline region. Region a is offline here<a name="line.292"></a>
+<span class="sourceLineNo">293</span>        admin.mergeRegions(a.getEncodedNameAsBytes(), b.getEncodedNameAsBytes(), false);<a name="line.293"></a>
+<span class="sourceLineNo">294</span>        fail("Offline regions should not be able to merge");<a name="line.294"></a>
+<span class="sourceLineNo">295</span>      } catch (IOException ie) {<a name="line.295"></a>
+<span class="sourceLineNo">296</span>        System.out.println(ie);<a name="line.296"></a>
+<span class="sourceLineNo">297</span>        assertTrue("Exception should mention regions not online",<a name="line.297"></a>
+<span class="sourceLineNo">298</span>          StringUtils.stringifyException(ie).contains("regions not online")<a name="line.298"></a>
+<span class="sourceLineNo">299</span>            &amp;&amp; ie instanceof MergeRegionException);<a name="line.299"></a>
+<span class="sourceLineNo">300</span>      }<a name="line.300"></a>
+<span class="sourceLineNo">301</span>      try {<a name="line.301"></a>
+<span class="sourceLineNo">302</span>        // Merge the same region: b and b.<a name="line.302"></a>
+<span class="sourceLineNo">303</span>        admin.mergeRegions(b.getEncodedNameAsBytes(), b.getEncodedNameAsBytes(), true);<a name="line.303"></a>
+<span class="sourceLineNo">304</span>        fail("A region should not be able to merge with itself, even forcifully");<a name="line.304"></a>
+<span class="sourceLineNo">305</span>      } catch (IOException ie) {<a name="line.305"></a>
+<span class="sourceLineNo">306</span>        assertTrue("Exception should mention regions not online",<a name="line.306"></a>
+<span class="sourceLineNo">307</span>          StringUtils.stringifyException(ie).contains("region to itself")<a name="line.307"></a>
+<span class="sourceLineNo">308</span>            &amp;&amp; ie instanceof MergeRegionException);<a name="line.308"></a>
+<span class="sourceLineNo">309</span>      }<a name="line.309"></a>
+<span class="sourceLineNo">310</span>      try {<a name="line.310"></a>
+<span class="sourceLineNo">311</span>        // Merge unknown regions<a name="line.311"></a>
+<span class="sourceLineNo">312</span>        admin.mergeRegions(Bytes.toBytes("-f1"), Bytes.toBytes("-f2"), true);<a name="line.312"></a>
+<span class="sourceLineNo">313</span>        fail("Unknown region could not be merged");<a name="line.313"></a>
+<span class="sourceLineNo">314</span>      } catch (IOException ie) {<a name="line.314"></a>
+<span class="sourceLineNo">315</span>        assertTrue("UnknownRegionException should be thrown",<a name="line.315"></a>
+<span class="sourceLineNo">316</span>          ie instanceof UnknownRegionException);<a name="line.316"></a>
+<span class="sourceLineNo">317</span>      }<a name="line.317"></a>
+<span class="sourceLineNo">318</span>      table.close();<a name="line.318"></a>
+<span class="sourceLineNo">319</span>    } finally {<a name="line.319"></a>
+<span class="sourceLineNo">320</span>      TEST_UTIL.deleteTable(tableName);<a name="line.320"></a>
+<span class="sourceLineNo">321</span>    }<a name="line.321"></a>
+<span class="sourceLineNo">322</span>  }<a name="line.322"></a>
+<span class="sourceLineNo">323</span><a name="line.323"></a>
+<span class="sourceLineNo">324</span>  @Test<a name="line.324"></a>
+<span class="sourceLineNo">325</span>  public void testMergeWithReplicas() throws Exception {<a name="line.325"></a>
+<span class="sourceLineNo">326</span>    final TableName tableName = TableName.valueOf("testMergeWithReplicas");<a name="line.326"></a>
+<span class="sourceLineNo">327</span>    // Create table and load data.<a name="line.327"></a>
+<span class="sourceLineNo">328</span>    createTableAndLoadData(master, tableName, 5, 2);<a name="line.328"></a>
+<span class="sourceLineNo">329</span>    List&lt;Pair&lt;HRegionInfo, ServerName&gt;&gt; initialRegionToServers =<a name="line.329"></a>
+<span class="sourceLineNo">330</span>        MetaTableAccessor.getTableRegionsAndLocations(<a name="line.330"></a>
+<span class="sourceLineNo">331</span>            master.getConnection(), tableName);<a name="line.331"></a>
+<span class="sourceLineNo">332</span>    // Merge 1st and 2nd region<a name="line.332"></a>
+<span class="sourceLineNo">333</span>    PairOfSameType&lt;HRegionInfo&gt; mergedRegions = mergeRegionsAndVerifyRegionNum(master, tableName,<a name="line.333"></a>
+<span class="sourceLineNo">334</span>        0, 2, 5 * 2 - 2);<a name="line.334"></a>
+<span class="sourceLineNo">335</span>    List&lt;Pair&lt;HRegionInfo, ServerName&gt;&gt; currentRegionToServers =<a name="line.335"></a>
+<span class="sourceLineNo">336</span>        MetaTableAccessor.getTableRegionsAndLocations(<a name="line.336"></a>
+<span class="sourceLineNo">337</span>            master.getConnection(), tableName);<a name="line.337"></a>
+<span class="sourceLineNo">338</span>    List&lt;HRegionInfo&gt; initialRegions = new ArrayList&lt;HRegionInfo&gt;();<a name="line.338"></a>
+<span class="sourceLineNo">339</span>    for (Pair&lt;HRegionInfo, ServerName&gt; p : initialRegionToServers) {<a name="line.339"></a>
+<span class="sourceLineNo">340</span>      initialRegions.add(p.getFirst());<a name="line.340"></a>
+<span class="sourceLineNo">341</span>    }<a name="line.341"></a>
+<span class="sourceLineNo">342</span>    List&lt;HRegionInfo&gt; currentRegions = new ArrayList&lt;HRegionInfo&gt;();<a name="line.342"></a>
+<span class="sourceLineNo">343</span>    for (Pair&lt;HRegionInfo, ServerName&gt; p : currentRegionToServers) {<a name="line.343"></a>
+<span class="sourceLineNo">344</span>      currentRegions.add(p.getFirst());<a name="line.344"></a>
+<span class="sourceLineNo">345</span>    }<a name="line.345"></a>
+<span class="sourceLineNo">346</span>    assertTrue(initialRegions.contains(mergedRegions.getFirst())); //this is the first region<a name="line.346"></a>
+<span class="sourceLineNo">347</span>    assertTrue(initialRegions.contains(RegionReplicaUtil.getRegionInfoForReplica(<a name="line.347"></a>
+<span class="sourceLineNo">348</span>        mergedRegions.getFirst(), 1))); //this is the replica of the first region<a name="line.348"></a>
+<span class="sourceLineNo">349</span>    assertTrue(initialRegions.contains(mergedRegions.getSecond())); //this is the second region<a name="line.349"></a>
+<span class="sourceLineNo">350</span>    assertTrue(initialRegions.contains(RegionReplicaUtil.getRegionInfoForReplica(<a name="line.350"></a>
+<span class="sourceLineNo">351</span>        mergedRegions.getSecond(), 1))); //this is the replica of the second region<a name="line.351"></a>
+<span class="sourceLineNo">352</span>    assertTrue(!initialRegions.contains(currentRegions.get(0))); //this is the new region<a name="line.352"></a>
+<span class="sourceLineNo">353</span>    assertTrue(!initialRegions.contains(RegionReplicaUtil.getRegionInfoForReplica(<a name="line.353"></a>
+<span class="sourceLineNo">354</span>        currentRegions.get(0), 1))); //replica of the new region<a name="line.354"></a>
+<span class="sourceLineNo">355</span>    assertTrue(currentRegions.contains(RegionReplicaUtil.getRegionInfoForReplica(<a name="line.355"></a>
+<span class="sourceLineNo">356</span>        currentRegions.get(0), 1))); //replica of the new region<a name="line.356"></a>
+<span class="sourceLineNo">357</span>    assertTrue(!currentRegions.contains(RegionReplicaUtil.getRegionInfoForReplica(<a name="line.357"></a>
+<span class="sourceLineNo">358</span>        mergedRegions.getFirst(), 1))); //replica of the merged region<a name="line.358"></a>
+<span class="sourceLineNo">359</span>    assertTrue(!currentRegions.contains(RegionReplicaUtil.getRegionInfoForReplica(<a name="line.359"></a>
+<span class="sourceLineNo">360</span>        mergedRegions.getSecond(), 1))); //replica of the merged region<a name="line.360"></a>
+<span class="sourceLineNo">361</span>  }<a name="line.361"></a>
+<span class="sourceLineNo">362</span><a name="line.362"></a>
+<span class="sourceLineNo">363</span>  private PairOfSameType&lt;HRegionInfo&gt; mergeRegionsAndVerifyRegionNum(<a name="line.363"></a>
+<span class="sourceLineNo">364</span>      HMaster master, TableName tablename,<a name="line.364"></a>
+<span class="sourceLineNo">365</span>      int regionAnum, int regionBnum, int expectedRegionNum) throws Exception {<a name="line.365"></a>
+<span class="sourceLineNo">366</span>    PairOfSameType&lt;HRegionInfo&gt; mergedRegions =<a name="line.366"></a>
+<span class="sourceLineNo">367</span>      requestMergeRegion(master, tablename, regionAnum, regionBnum);<a name="line.367"></a>
+<span class="sourceLineNo">368</span>    waitAndVerifyRegionNum(master, tablename, expectedRegionNum);<a name="line.368"></a>
+<span class="sourceLineNo">369</span>    return mergedRegions;<a name="line.369"></a>
+<span class="sourceLineNo">370</span>  }<a name="line.370"></a>
+<span class="sourceLineNo">371</span><a name="line.371"></a>
+<span class="sourceLineNo">372</span>  private PairOfSameType&lt;HRegionInfo&gt; requestMergeRegion(<a name="line.372"></a>
+<span class="sourceLineNo">373</span>      HMaster master, TableName tablename,<a name="line.373"></a>
+<span class="sourceLineNo">374</span>      int regionAnum, int regionBnum) throws Exception {<a name="line.374"></a>
+<span class="sourceLineNo">375</span>    List&lt;Pair&lt;HRegionInfo, ServerName&gt;&gt; tableRegions = MetaTableAccessor<a name="line.375"></a>
+<span class="sourceLineNo">376</span>        .getTableRegionsAndLocations(<a name="line.376"></a>
+<span class="sourceLineNo">377</span>          master.getConnection(), tablename);<a name="line.377"></a>
+<span class="sourceLineNo">378</span>    HRegionInfo regionA = tableRegions.get(regionAnum).getFirst();<a name="line.378"></a>
+<span class="sourceLineNo">379</span>    HRegionInfo regionB = tableRegions.get(regionBnum).getFirst();<a name="line.379"></a>
+<span class="sourceLineNo">380</span>    TEST_UTIL.getHBaseAdmin().mergeRegions(<a name="line.380"></a>
+<span class="sourceLineNo">381</span>      regionA.getEncodedNameAsBytes(),<a name="line.381"></a>
+<span class="sourceLineNo">382</span>      regionB.getEncodedNameAsBytes(), false);<a name="line.382"></a>
+<span class="sourceLineNo">383</span>    return new PairOfSameType&lt;HRegionInfo&gt;(regionA, regionB);<a name="line.383"></a>
+<span class="sourceLineNo">384</span>  }<a name="line.384"></a>
+<span class="sourceLineNo">385</span><a name="line.385"></a>
+<span class="sourceLineNo">386</span>  private void waitAndVerifyRegionNum(HMaster master, TableName tablename,<a name="line.386"></a>
+<span class="sourceLineNo">387</span>      int expectedRegionNum) throws Exception {<a name="line.387"></a>
+<span class="sourceLineNo">388</span>    List&lt;Pair&lt;HRegionInfo, ServerName&gt;&gt; tableRegionsInMeta;<a name="line.388"></a>
+<span class="sourceLineNo">389</span>    List&lt;HRegionInfo&gt; tableRegionsInMaster;<a name="line.389"></a>
+<span class="sourceLineNo">390</span>    long timeout = System.currentTimeMillis() + waitTime;<a name="line.390"></a>
+<span class="sourceLineNo">391</span>    while (System.currentTimeMillis() &lt; timeout) {<a name="line.391"></a>
+<span class="sourceLineNo">392</span>      tableRegionsInMeta = MetaTableAccessor.getTableRegionsAndLocations(<a name="line.392"></a>
+<span class="sourceLineNo">393</span>        master.getConnection(), tablename);<a name="line.393"></a>
+<span class="sourceLineNo">394</span>      tableRegionsInMaster = master.getAssignmentManager().getRegionStates()<a name="line.394"></a>
+<span class="sourceLineNo">395</span>          .getRegionsOfTable(tablename);<a name="line.395"></a>
+<span class="sourceLineNo">396</span>      if (tableRegionsInMeta.size() == expectedRegionNum<a name="line.396"></a>
+<span class="sourceLineNo">397</span>          &amp;&amp; tableRegionsInMaster.size() == expectedRegionNum) {<a name="line.397"></a>
+<span class="sourceLineNo">398</span>        break;<a name="line.398"></a>
+<span class="sourceLineNo">399</span>      }<a name="line.399"></a>
+<span class="sourceLineNo">400</span>      Thread.sleep(250);<a name="line.400"></a>
+<span class="sourceLineNo">401</span>    }<a name="line.401"></a>
+<span class="sourceLineNo">402</span><a name="line.402"></a>
+<span class="sourceLineNo">403</span>    tableRegionsInMeta = MetaTableAccessor.getTableRegionsAndLocations(<a name="line.403"></a>
+<span class="sourceLineNo">404</span>      master.getConnection(), tablename);<a name="line.404"></a>
+<span class="sourceLineNo">405</span>    LOG.info("Regions after merge:" + Joiner.on(',').join(tableRegionsInMeta));<a name="line.405"></a>
+<span class="sourceLineNo">406</span>    assertEquals(expectedRegionNum, tableRegionsInMeta.size());<a name="line.406"></a>
+<span class="sourceLineNo">407</span>  }<a name="line.407"></a>
+<span class="sourceLineNo">408</span><a name="line.408"></a>
+<span class="sourceLineNo">409</span>  private Table createTableAndLoadData(HMaster master, TableName tablename)<a name="line.409"></a>
+<span class="sourceLineNo">410</span>      throws Exception {<a name="line.410"></a>
+<span class="sourceLineNo">411</span>    return createTableAndLoadData(master, tablename, INITIAL_REGION_NUM, 1);<a name="line.411"></a>
+<span class="sourceLineNo">412</span>  }<a name="line.412"></a>
+<span class="sourceLineNo">413</span><a name="line.413"></a>
+<span class="sourceLineNo">414</span>  private Table createTableAndLoadData(HMaster master, TableName tablename,<a name="line.414"></a>
+<span class="sourceLineNo">415</span>      int numRegions, int replication) throws Exception {<a name="line.415"></a>
+<span class="sourceLineNo">416</span>    assertTrue("ROWSIZE must &gt; numregions:" + numRegions, ROWSIZE &gt; numRegions);<a name="line.416"></a>
+<span class="sourceLineNo">417</span>    byte[][] splitRows = new byte[numRegions - 1][];<a name="line.417"></a>
+<span class="sourceLineNo">418</span>    for (int i = 0; i &lt; splitRows.length; i++) {<a name="line.418"></a>
+<span class="sourceLineNo">419</span>      splitRows[i] = ROWS[(i + 1) * ROWSIZE / numRegions];<a name="line.419"></a>
+<span class="sourceLineNo">420</span>    }<a name="line.420"></a>
+<span class="sourceLineNo">421</span><a name="line.421"></a>
+<span class="sourceLineNo">422</span>    Table table = TEST_UTIL.createTable(tablename, FAMILYNAME, splitRows);<a name="line.422"></a>
+<span class="sourceLineNo">423</span>    if (replication &gt; 1) {<a name="line.423"></a>
+<span class="sourceLineNo">424</span>      HBaseTestingUtility.setReplicas(admin, tablename, replication);<a name="line.424"></a>
+<span class="sourceLineNo">425</span>    }<a name="line.425"></a>
+<span class="sourceLineNo">426</span>    loadData(table);<a name="line.426"></a>
+<span class="sourceLineNo">427</span>    verifyRowCount(table, ROWSIZE);<a name="line.427"></a>
+<span class="sourceLineNo">428</span><a name="line.428"></a>
+<span class="sourceLineNo">429</span>    // sleep here is an ugly hack to allow region transitions to finish<a name="line.429"></a>
+<span class="sourceLineNo">430</span>    long timeout = System.currentTimeMillis() + waitTime;<a name="line.430"></a>
+<span class="sourceLineNo">431</span>    List&lt;Pair&lt;HRegionInfo, ServerName&gt;&gt; tableRegions;<a name="line.431"></a>
+<span class="sourceLineNo">432</span>    while (System.currentTimeMillis() &lt; timeout) {<a name="line.432"></a>
+<span class="sourceLineNo">433</span>      tableRegions = MetaTableAccessor.getTableRegionsAndLocations(<a name="line.433"></a>
+<span class="sourceLineNo">434</span>        master.getConnection(), tablename);<a name="line.434"></a>
+<span class="sourceLineNo">435</span>      if (tableRegions.size() == numRegions * replication)<a name="line.435"></a>
+<span class="sourceLineNo">436</span>        break;<a name="line.436"></a>
+<span class="sourceLineNo">437</span>      Thread.sleep(250);<a name="line.437"></a>
+<span class="sourceLineNo">438</span>    }<a name="line.438"></a>
+<span class="sourceLineNo">439</span><a name="line.439"></a>
+<span class="sourceLineNo">440</span>    tableRegions = MetaTableAccessor.getTableRegionsAndLocations(<a name="line.440"></a>
+<span class="sourceLineNo">441</span>      master.getConnection(), tablename);<a name="line.441"></a>
+<span class="sourceLineNo">442</span>    LOG.info("Regions after load: " + Joiner.on(',').join(tableRegions));<a name="line.442"></a>
+<span class="sourceLineNo">443</span>    assertEquals(numRegions * replication, tableRegions.size());<a name="line.443"></a>
+<span class="sourceLineNo">444</span>    return table;<a name="line.444"></a>
+<span class="sourceLineNo">445</span>  }<a name="line.445"></a>
+<span class="sourceLineNo">446</span><a name="line.446"></a>
+<span class="sourceLineNo">447</span>  private static byte[][] makeN(byte[] base, int n) {<a name="line.447"></a>
+<span class="sourceLineNo">448</span>    byte[][] ret = new byte[n][];<a name="line.448"></a>
+<span class="sourceLineNo">449</span>    for (int i = 0; i &lt; n; i++) {<a name="line.449"></a>
+<span class="sourceLineNo">450</span>      ret[i] = Bytes.add(base, Bytes.toBytes(String.format("%04d", i)));<a name="line.450"></a>
+<span class="sourceLineNo">451</span>    }<a name="line.451"></a>
+<span class="sourceLineNo">452</span>    return ret;<a name="line.452"></a>
+<span class="sourceLineNo">453</span>  }<a name="line.453"></a>
+<span class="sourceLineNo">454</span><a name="line.454"></a>
+<span class="sourceLineNo">455</span>  private void loadData(Table table) throws IOException {<a name="line.455"></a>
+<span class="sourceLineNo">456</span>    for (int i = 0; i &lt; ROWSIZE; i++) {<a name="line.456"></a>
+<span class="sourceLineNo">457</span>      Put put = new Put(ROWS[i]);<a name="line.457"></a>
+<span class="sourceLineNo">458</span>      put.addColumn(FAMILYNAME, QUALIFIER, Bytes.toBytes(i));<a name="line.458"></a>
+<span class="sourceLineNo">459</span>      table.put(put);<a name="line.459"></a>
+<span class="sourceLineNo">460</span>    }<a name="line.460"></a>
+<span class="sourceLineNo">461</span>  }<a name="line.461"></a>
+<span class="sourceLineNo">462</span><a name="line.462"></a>
+<span class="sourceLineNo">463</span>  private void verifyRowCount(Table table, int expectedRegionNum)<a name="line.463"></a>
+<span class="sourceLineNo">464</span>      throws IOException {<a name="line.464"></a>
+<span class="sourceLineNo">465</span>    ResultScanner scanner = table.getScanner(new Scan());<a name="line.465"></a>
+<span class="sourceLineNo">466</span>    int rowCount = 0;<a name="line.466"></a>
+<span class="sourceLineNo">467</span>    while (scanner.next() != null) {<a name="line.467"></a>
+<span class="sourceLineNo">468</span>      rowCount++;<a name="line.468"></a>
+<span class="sourceLineNo">469</span>    }<a name="line.469"></a>
+<span class="sourceLineNo">470</span>    assertEquals(expectedRegionNum, rowCount);<a name="line.470"></a>
+<span class="sourceLineNo">471</span>    scanner.close();<a name="line.471"></a>
+<span class="sourceLineNo">472</span>  }<a name="line.472"></a>
+<span class="sourceLineNo">473</span><a name="line.473"></a>
+<span class="sourceLineNo">474</span>  // Make it public so that JVMClusterUtil can access it.<a name="line.474"></a>
+<span class="sourceLineNo">475</span>  public static class MyMaster extends HMaster {<a name="line.475"></a>
+<span class="sourceLineNo">476</span>    public MyMaster(Configuration conf, CoordinatedStateManager cp)<a name="line.476"></a>
+<span class="sourceLineNo">477</span>      throws IOException, KeeperException,<a name="line.477"></a>
+<span class="sourceLineNo">478</span>        InterruptedException {<a name="line.478"></a>
+<span class="sourceLineNo">479</span>      super(conf, cp);<a name="line.479"></a>
+<span class="sourceLineNo">480</span>    }<a name="line.480"></a>
+<span class="sourceLineNo">481</span><a name="line.481"></a>
+<span class="sourceLineNo">482</span>    @Override<a name="line.482"></a>
+<span class="sourceLineNo">483</span>    protected RSRpcServices createRpcServices() throws IOException {<a name="line.483"></a>
+<span class="sourceLineNo">484</span>      return new MyMasterRpcServices(this);<a name="line.484"></a>
+<span class="sourceLineNo">485</span>    }<a name="line.485"></a>
+<span class="sourceLineNo">486</span>  }<a name="line.486"></a>
+<span class="sourceLineNo">487</span><a name="line.487"></a>
+<span class="sourceLineNo">488</span>  static class MyMasterRpcServices extends MasterRpcServices {<a name="line.488"></a>
+<span class="sourceLineNo">489</span>    static AtomicBoolean enabled = new AtomicBoolean(false);<a name="line.489"></a>
+<span class="sourceLineNo">490</span><a name="line.490"></a>
+<span class="sourceLineNo">491</span>    private HMaster myMaster;<a name="line.491"></a>
+<span class="sourceLineNo">492</span>    public MyMasterRpcServices(HMaster master) throws IOException {<a name="line.492"></a>
+<span class="sourceLineNo">493</span>      super(master);<a name="line.493"></a>
+<span class="sourceLineNo">494</span>      myMaster = master;<a name="line.494"></a>
+<span class="sourceLineNo">495</span>    }<a name="line.495"></a>
+<span class="sourceLineNo">496</span><a name="line.496"></a>
+<span class="sourceLineNo">497</span>    @Override<a name="line.497"></a>
+<span class="sourceLineNo">498</span>    public ReportRegionStateTransitionResponse reportRegionStateTransition(RpcController c,<a name="line.498"></a>
+<span class="sourceLineNo">499</span>        ReportRegionStateTransitionRequest req) throws ServiceException {<a name="line.499"></a>
+<span class="sourceLineNo">500</span>      ReportRegionStateTransitionResponse resp = super.reportRegionStateTransition(c, req);<a name="line.500"></a>
+<span class="sourceLineNo">501</span>      if (enabled.get() &amp;&amp; req.getTransition(0).getTransitionCode()<a name="line.501"></a>
+<span class="sourceLineNo">502</span>          == TransitionCode.READY_TO_MERGE &amp;&amp; !resp.hasErrorMessage()) {<a name="line.502"></a>
+<span class="sourceLineNo">503</span>        RegionStates regionStates = myMaster.getAssignmentManager().getRegionStates();<a name="line.503"></a>
+<span class="sourceLineNo">504</span>        for (RegionState regionState: regionStates.getRegionsInTransition().values()) {<a name="line.504"></a>
+<span class="sourceLineNo">505</span>          // Find the merging_new region and remove it<a name="line.505"></a>
+<span class="sourceLineNo">506</span>          if (regionState.isMergingNew()) {<a name="line.506"></a>
+<span class="sourceLineNo">507</span>            regionStates.deleteRegion(regionState.getRegion());<a name="line.507"></a>
+<span class="sourceLineNo">508</span>          }<a name="line.508"></a>
+<span class="sourceLineNo">509</span>        }<a name="line.509"></a>
+<span class="sourceLineNo">510</span>      }<a name="line.510"></a>
+<span class="sourceLineNo">511</span>      return resp;<a name="line.511"></a>
+<span class="sourceLineNo">512</span>    }<a name="line.512"></a>
+<span class="sourceLineNo">513</span>  }<a name="line.513"></a>
+<span class="sourceLineNo">514</span>}<a name="line.514"></a>
 
 
 



Mime
View raw message