hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mi...@apache.org
Subject [10/30] hbase-site git commit: Published site at 28cd48b673ca743d193874b2951bc995699e8e89.
Date Wed, 24 Feb 2016 17:45:09 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/89b638a4/testdevapidocs/src-html/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransactionOnCluster.MyMaster.html
----------------------------------------------------------------------
diff --git a/testdevapidocs/src-html/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransactionOnCluster.MyMaster.html b/testdevapidocs/src-html/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransactionOnCluster.MyMaster.html
index 1bdbf69..f83e138 100644
--- a/testdevapidocs/src-html/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransactionOnCluster.MyMaster.html
+++ b/testdevapidocs/src-html/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransactionOnCluster.MyMaster.html
@@ -86,478 +86,483 @@
 <span class="sourceLineNo">078</span>import org.junit.Rule;<a name="line.78"></a>
 <span class="sourceLineNo">079</span>import org.junit.Test;<a name="line.79"></a>
 <span class="sourceLineNo">080</span>import org.junit.experimental.categories.Category;<a name="line.80"></a>
-<span class="sourceLineNo">081</span>import org.junit.rules.TestRule;<a name="line.81"></a>
-<span class="sourceLineNo">082</span><a name="line.82"></a>
-<span class="sourceLineNo">083</span>import com.google.common.base.Joiner;<a name="line.83"></a>
-<span class="sourceLineNo">084</span>import com.google.protobuf.RpcController;<a name="line.84"></a>
-<span class="sourceLineNo">085</span>import com.google.protobuf.ServiceException;<a name="line.85"></a>
-<span class="sourceLineNo">086</span><a name="line.86"></a>
-<span class="sourceLineNo">087</span>/**<a name="line.87"></a>
-<span class="sourceLineNo">088</span> * Like {@link TestRegionMergeTransaction} in that we're testing<a name="line.88"></a>
-<span class="sourceLineNo">089</span> * {@link RegionMergeTransactionImpl} only the below tests are against a running<a name="line.89"></a>
-<span class="sourceLineNo">090</span> * cluster where {@link TestRegionMergeTransaction} is tests against bare<a name="line.90"></a>
-<span class="sourceLineNo">091</span> * {@link HRegion}.<a name="line.91"></a>
-<span class="sourceLineNo">092</span> */<a name="line.92"></a>
-<span class="sourceLineNo">093</span>@Category({RegionServerTests.class, LargeTests.class})<a name="line.93"></a>
-<span class="sourceLineNo">094</span>public class TestRegionMergeTransactionOnCluster {<a name="line.94"></a>
-<span class="sourceLineNo">095</span>  private static final Log LOG = LogFactory<a name="line.95"></a>
-<span class="sourceLineNo">096</span>      .getLog(TestRegionMergeTransactionOnCluster.class);<a name="line.96"></a>
-<span class="sourceLineNo">097</span>  @Rule public final TestRule timeout = CategoryBasedTimeout.builder().withTimeout(this.getClass()).<a name="line.97"></a>
-<span class="sourceLineNo">098</span>      withLookingForStuckThread(true).build();<a name="line.98"></a>
-<span class="sourceLineNo">099</span>  private static final int NB_SERVERS = 3;<a name="line.99"></a>
-<span class="sourceLineNo">100</span><a name="line.100"></a>
-<span class="sourceLineNo">101</span>  private static final byte[] FAMILYNAME = Bytes.toBytes("fam");<a name="line.101"></a>
-<span class="sourceLineNo">102</span>  private static final byte[] QUALIFIER = Bytes.toBytes("q");<a name="line.102"></a>
-<span class="sourceLineNo">103</span><a name="line.103"></a>
-<span class="sourceLineNo">104</span>  private static byte[] ROW = Bytes.toBytes("testRow");<a name="line.104"></a>
-<span class="sourceLineNo">105</span>  private static final int INITIAL_REGION_NUM = 10;<a name="line.105"></a>
-<span class="sourceLineNo">106</span>  private static final int ROWSIZE = 200;<a name="line.106"></a>
-<span class="sourceLineNo">107</span>  private static byte[][] ROWS = makeN(ROW, ROWSIZE);<a name="line.107"></a>
-<span class="sourceLineNo">108</span><a name="line.108"></a>
-<span class="sourceLineNo">109</span>  private static int waitTime = 60 * 1000;<a name="line.109"></a>
+<span class="sourceLineNo">081</span>import org.junit.rules.TestName;<a name="line.81"></a>
+<span class="sourceLineNo">082</span>import org.junit.rules.TestRule;<a name="line.82"></a>
+<span class="sourceLineNo">083</span><a name="line.83"></a>
+<span class="sourceLineNo">084</span>import com.google.common.base.Joiner;<a name="line.84"></a>
+<span class="sourceLineNo">085</span>import com.google.protobuf.RpcController;<a name="line.85"></a>
+<span class="sourceLineNo">086</span>import com.google.protobuf.ServiceException;<a name="line.86"></a>
+<span class="sourceLineNo">087</span><a name="line.87"></a>
+<span class="sourceLineNo">088</span>/**<a name="line.88"></a>
+<span class="sourceLineNo">089</span> * Like {@link TestRegionMergeTransaction} in that we're testing<a name="line.89"></a>
+<span class="sourceLineNo">090</span> * {@link RegionMergeTransactionImpl} only the below tests are against a running<a name="line.90"></a>
+<span class="sourceLineNo">091</span> * cluster where {@link TestRegionMergeTransaction} is tests against bare<a name="line.91"></a>
+<span class="sourceLineNo">092</span> * {@link HRegion}.<a name="line.92"></a>
+<span class="sourceLineNo">093</span> */<a name="line.93"></a>
+<span class="sourceLineNo">094</span>@Category({RegionServerTests.class, LargeTests.class})<a name="line.94"></a>
+<span class="sourceLineNo">095</span>public class TestRegionMergeTransactionOnCluster {<a name="line.95"></a>
+<span class="sourceLineNo">096</span>  private static final Log LOG = LogFactory<a name="line.96"></a>
+<span class="sourceLineNo">097</span>      .getLog(TestRegionMergeTransactionOnCluster.class);<a name="line.97"></a>
+<span class="sourceLineNo">098</span>  @Rule public TestName name = new TestName();<a name="line.98"></a>
+<span class="sourceLineNo">099</span>  @Rule public final TestRule timeout = CategoryBasedTimeout.builder().withTimeout(this.getClass()).<a name="line.99"></a>
+<span class="sourceLineNo">100</span>      withLookingForStuckThread(true).build();<a name="line.100"></a>
+<span class="sourceLineNo">101</span>  private static final int NB_SERVERS = 3;<a name="line.101"></a>
+<span class="sourceLineNo">102</span><a name="line.102"></a>
+<span class="sourceLineNo">103</span>  private static final byte[] FAMILYNAME = Bytes.toBytes("fam");<a name="line.103"></a>
+<span class="sourceLineNo">104</span>  private static final byte[] QUALIFIER = Bytes.toBytes("q");<a name="line.104"></a>
+<span class="sourceLineNo">105</span><a name="line.105"></a>
+<span class="sourceLineNo">106</span>  private static byte[] ROW = Bytes.toBytes("testRow");<a name="line.106"></a>
+<span class="sourceLineNo">107</span>  private static final int INITIAL_REGION_NUM = 10;<a name="line.107"></a>
+<span class="sourceLineNo">108</span>  private static final int ROWSIZE = 200;<a name="line.108"></a>
+<span class="sourceLineNo">109</span>  private static byte[][] ROWS = makeN(ROW, ROWSIZE);<a name="line.109"></a>
 <span class="sourceLineNo">110</span><a name="line.110"></a>
-<span class="sourceLineNo">111</span>  static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();<a name="line.111"></a>
+<span class="sourceLineNo">111</span>  private static int waitTime = 60 * 1000;<a name="line.111"></a>
 <span class="sourceLineNo">112</span><a name="line.112"></a>
-<span class="sourceLineNo">113</span>  private static HMaster MASTER;<a name="line.113"></a>
-<span class="sourceLineNo">114</span>  private static Admin ADMIN;<a name="line.114"></a>
-<span class="sourceLineNo">115</span><a name="line.115"></a>
-<span class="sourceLineNo">116</span>  @BeforeClass<a name="line.116"></a>
-<span class="sourceLineNo">117</span>  public static void beforeAllTests() throws Exception {<a name="line.117"></a>
-<span class="sourceLineNo">118</span>    // Start a cluster<a name="line.118"></a>
-<span class="sourceLineNo">119</span>    TEST_UTIL.startMiniCluster(1, NB_SERVERS, null, MyMaster.class, null);<a name="line.119"></a>
-<span class="sourceLineNo">120</span>    MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();<a name="line.120"></a>
-<span class="sourceLineNo">121</span>    MASTER = cluster.getMaster();<a name="line.121"></a>
-<span class="sourceLineNo">122</span>    MASTER.balanceSwitch(false);<a name="line.122"></a>
-<span class="sourceLineNo">123</span>    ADMIN = TEST_UTIL.getConnection().getAdmin();<a name="line.123"></a>
-<span class="sourceLineNo">124</span>  }<a name="line.124"></a>
-<span class="sourceLineNo">125</span><a name="line.125"></a>
-<span class="sourceLineNo">126</span>  @AfterClass<a name="line.126"></a>
-<span class="sourceLineNo">127</span>  public static void afterAllTests() throws Exception {<a name="line.127"></a>
-<span class="sourceLineNo">128</span>    TEST_UTIL.shutdownMiniCluster();<a name="line.128"></a>
-<span class="sourceLineNo">129</span>    if (ADMIN != null) ADMIN.close();<a name="line.129"></a>
-<span class="sourceLineNo">130</span>  }<a name="line.130"></a>
-<span class="sourceLineNo">131</span><a name="line.131"></a>
-<span class="sourceLineNo">132</span>  @Test<a name="line.132"></a>
-<span class="sourceLineNo">133</span>  public void testWholesomeMerge() throws Exception {<a name="line.133"></a>
-<span class="sourceLineNo">134</span>    LOG.info("Starting testWholesomeMerge");<a name="line.134"></a>
-<span class="sourceLineNo">135</span>    final TableName tableName =<a name="line.135"></a>
-<span class="sourceLineNo">136</span>        TableName.valueOf("testWholesomeMerge");<a name="line.136"></a>
-<span class="sourceLineNo">137</span><a name="line.137"></a>
-<span class="sourceLineNo">138</span>    // Create table and load data.<a name="line.138"></a>
-<span class="sourceLineNo">139</span>    Table table = createTableAndLoadData(MASTER, tableName);<a name="line.139"></a>
-<span class="sourceLineNo">140</span>    // Merge 1st and 2nd region<a name="line.140"></a>
-<span class="sourceLineNo">141</span>    mergeRegionsAndVerifyRegionNum(MASTER, tableName, 0, 1,<a name="line.141"></a>
-<span class="sourceLineNo">142</span>        INITIAL_REGION_NUM - 1);<a name="line.142"></a>
-<span class="sourceLineNo">143</span><a name="line.143"></a>
-<span class="sourceLineNo">144</span>    // Merge 2nd and 3th region<a name="line.144"></a>
-<span class="sourceLineNo">145</span>    PairOfSameType&lt;HRegionInfo&gt; mergedRegions =<a name="line.145"></a>
-<span class="sourceLineNo">146</span>      mergeRegionsAndVerifyRegionNum(MASTER, tableName, 1, 2,<a name="line.146"></a>
-<span class="sourceLineNo">147</span>        INITIAL_REGION_NUM - 2);<a name="line.147"></a>
-<span class="sourceLineNo">148</span><a name="line.148"></a>
-<span class="sourceLineNo">149</span>    verifyRowCount(table, ROWSIZE);<a name="line.149"></a>
+<span class="sourceLineNo">113</span>  static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();<a name="line.113"></a>
+<span class="sourceLineNo">114</span><a name="line.114"></a>
+<span class="sourceLineNo">115</span>  private static HMaster MASTER;<a name="line.115"></a>
+<span class="sourceLineNo">116</span>  private static Admin ADMIN;<a name="line.116"></a>
+<span class="sourceLineNo">117</span><a name="line.117"></a>
+<span class="sourceLineNo">118</span>  @BeforeClass<a name="line.118"></a>
+<span class="sourceLineNo">119</span>  public static void beforeAllTests() throws Exception {<a name="line.119"></a>
+<span class="sourceLineNo">120</span>    // Start a cluster<a name="line.120"></a>
+<span class="sourceLineNo">121</span>    TEST_UTIL.startMiniCluster(1, NB_SERVERS, null, MyMaster.class, null);<a name="line.121"></a>
+<span class="sourceLineNo">122</span>    MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();<a name="line.122"></a>
+<span class="sourceLineNo">123</span>    MASTER = cluster.getMaster();<a name="line.123"></a>
+<span class="sourceLineNo">124</span>    MASTER.balanceSwitch(false);<a name="line.124"></a>
+<span class="sourceLineNo">125</span>    ADMIN = TEST_UTIL.getConnection().getAdmin();<a name="line.125"></a>
+<span class="sourceLineNo">126</span>  }<a name="line.126"></a>
+<span class="sourceLineNo">127</span><a name="line.127"></a>
+<span class="sourceLineNo">128</span>  @AfterClass<a name="line.128"></a>
+<span class="sourceLineNo">129</span>  public static void afterAllTests() throws Exception {<a name="line.129"></a>
+<span class="sourceLineNo">130</span>    TEST_UTIL.shutdownMiniCluster();<a name="line.130"></a>
+<span class="sourceLineNo">131</span>    if (ADMIN != null) ADMIN.close();<a name="line.131"></a>
+<span class="sourceLineNo">132</span>  }<a name="line.132"></a>
+<span class="sourceLineNo">133</span><a name="line.133"></a>
+<span class="sourceLineNo">134</span>  @Test<a name="line.134"></a>
+<span class="sourceLineNo">135</span>  public void testWholesomeMerge() throws Exception {<a name="line.135"></a>
+<span class="sourceLineNo">136</span>    LOG.info("Starting testWholesomeMerge");<a name="line.136"></a>
+<span class="sourceLineNo">137</span>    final TableName tableName =<a name="line.137"></a>
+<span class="sourceLineNo">138</span>        TableName.valueOf("testWholesomeMerge");<a name="line.138"></a>
+<span class="sourceLineNo">139</span><a name="line.139"></a>
+<span class="sourceLineNo">140</span>    // Create table and load data.<a name="line.140"></a>
+<span class="sourceLineNo">141</span>    Table table = createTableAndLoadData(MASTER, tableName);<a name="line.141"></a>
+<span class="sourceLineNo">142</span>    // Merge 1st and 2nd region<a name="line.142"></a>
+<span class="sourceLineNo">143</span>    mergeRegionsAndVerifyRegionNum(MASTER, tableName, 0, 1,<a name="line.143"></a>
+<span class="sourceLineNo">144</span>        INITIAL_REGION_NUM - 1);<a name="line.144"></a>
+<span class="sourceLineNo">145</span><a name="line.145"></a>
+<span class="sourceLineNo">146</span>    // Merge 2nd and 3th region<a name="line.146"></a>
+<span class="sourceLineNo">147</span>    PairOfSameType&lt;HRegionInfo&gt; mergedRegions =<a name="line.147"></a>
+<span class="sourceLineNo">148</span>      mergeRegionsAndVerifyRegionNum(MASTER, tableName, 1, 2,<a name="line.148"></a>
+<span class="sourceLineNo">149</span>        INITIAL_REGION_NUM - 2);<a name="line.149"></a>
 <span class="sourceLineNo">150</span><a name="line.150"></a>
-<span class="sourceLineNo">151</span>    // Randomly choose one of the two merged regions<a name="line.151"></a>
-<span class="sourceLineNo">152</span>    HRegionInfo hri = RandomUtils.nextBoolean() ?<a name="line.152"></a>
-<span class="sourceLineNo">153</span>      mergedRegions.getFirst() : mergedRegions.getSecond();<a name="line.153"></a>
-<span class="sourceLineNo">154</span>    MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();<a name="line.154"></a>
-<span class="sourceLineNo">155</span>    AssignmentManager am = cluster.getMaster().getAssignmentManager();<a name="line.155"></a>
-<span class="sourceLineNo">156</span>    RegionStates regionStates = am.getRegionStates();<a name="line.156"></a>
-<span class="sourceLineNo">157</span>    long start = EnvironmentEdgeManager.currentTime();<a name="line.157"></a>
-<span class="sourceLineNo">158</span>    while (!regionStates.isRegionInState(hri, State.MERGED)) {<a name="line.158"></a>
-<span class="sourceLineNo">159</span>      assertFalse("Timed out in waiting one merged region to be in state MERGED",<a name="line.159"></a>
-<span class="sourceLineNo">160</span>        EnvironmentEdgeManager.currentTime() - start &gt; 60000);<a name="line.160"></a>
-<span class="sourceLineNo">161</span>      Thread.sleep(500);<a name="line.161"></a>
-<span class="sourceLineNo">162</span>    }<a name="line.162"></a>
-<span class="sourceLineNo">163</span><a name="line.163"></a>
-<span class="sourceLineNo">164</span>    // We should not be able to assign it again<a name="line.164"></a>
-<span class="sourceLineNo">165</span>    am.assign(hri, true);<a name="line.165"></a>
-<span class="sourceLineNo">166</span>    assertFalse("Merged region can't be assigned",<a name="line.166"></a>
-<span class="sourceLineNo">167</span>      regionStates.isRegionInTransition(hri));<a name="line.167"></a>
-<span class="sourceLineNo">168</span>    assertTrue(regionStates.isRegionInState(hri, State.MERGED));<a name="line.168"></a>
-<span class="sourceLineNo">169</span><a name="line.169"></a>
-<span class="sourceLineNo">170</span>    // We should not be able to unassign it either<a name="line.170"></a>
-<span class="sourceLineNo">171</span>    am.unassign(hri, null);<a name="line.171"></a>
-<span class="sourceLineNo">172</span>    assertFalse("Merged region can't be unassigned",<a name="line.172"></a>
-<span class="sourceLineNo">173</span>      regionStates.isRegionInTransition(hri));<a name="line.173"></a>
-<span class="sourceLineNo">174</span>    assertTrue(regionStates.isRegionInState(hri, State.MERGED));<a name="line.174"></a>
-<span class="sourceLineNo">175</span><a name="line.175"></a>
-<span class="sourceLineNo">176</span>    table.close();<a name="line.176"></a>
-<span class="sourceLineNo">177</span>  }<a name="line.177"></a>
-<span class="sourceLineNo">178</span><a name="line.178"></a>
-<span class="sourceLineNo">179</span>  /**<a name="line.179"></a>
-<span class="sourceLineNo">180</span>   * Not really restarting the master. Simulate it by clear of new region<a name="line.180"></a>
-<span class="sourceLineNo">181</span>   * state since it is not persisted, will be lost after master restarts.<a name="line.181"></a>
-<span class="sourceLineNo">182</span>   */<a name="line.182"></a>
-<span class="sourceLineNo">183</span>  @Test<a name="line.183"></a>
-<span class="sourceLineNo">184</span>  public void testMergeAndRestartingMaster() throws Exception {<a name="line.184"></a>
-<span class="sourceLineNo">185</span>    LOG.info("Starting testMergeAndRestartingMaster");<a name="line.185"></a>
-<span class="sourceLineNo">186</span>    final TableName tableName = TableName.valueOf("testMergeAndRestartingMaster");<a name="line.186"></a>
-<span class="sourceLineNo">187</span><a name="line.187"></a>
-<span class="sourceLineNo">188</span>    // Create table and load data.<a name="line.188"></a>
-<span class="sourceLineNo">189</span>    Table table = createTableAndLoadData(MASTER, tableName);<a name="line.189"></a>
-<span class="sourceLineNo">190</span><a name="line.190"></a>
-<span class="sourceLineNo">191</span>    try {<a name="line.191"></a>
-<span class="sourceLineNo">192</span>      MyMasterRpcServices.enabled.set(true);<a name="line.192"></a>
-<span class="sourceLineNo">193</span><a name="line.193"></a>
-<span class="sourceLineNo">194</span>      // Merge 1st and 2nd region<a name="line.194"></a>
-<span class="sourceLineNo">195</span>      mergeRegionsAndVerifyRegionNum(MASTER, tableName, 0, 1, INITIAL_REGION_NUM - 1);<a name="line.195"></a>
-<span class="sourceLineNo">196</span>    } finally {<a name="line.196"></a>
-<span class="sourceLineNo">197</span>      MyMasterRpcServices.enabled.set(false);<a name="line.197"></a>
-<span class="sourceLineNo">198</span>    }<a name="line.198"></a>
-<span class="sourceLineNo">199</span><a name="line.199"></a>
-<span class="sourceLineNo">200</span>    table.close();<a name="line.200"></a>
-<span class="sourceLineNo">201</span>  }<a name="line.201"></a>
-<span class="sourceLineNo">202</span><a name="line.202"></a>
-<span class="sourceLineNo">203</span>  @Test<a name="line.203"></a>
-<span class="sourceLineNo">204</span>  public void testCleanMergeReference() throws Exception {<a name="line.204"></a>
-<span class="sourceLineNo">205</span>    LOG.info("Starting testCleanMergeReference");<a name="line.205"></a>
-<span class="sourceLineNo">206</span>    ADMIN.enableCatalogJanitor(false);<a name="line.206"></a>
-<span class="sourceLineNo">207</span>    try {<a name="line.207"></a>
-<span class="sourceLineNo">208</span>      final TableName tableName =<a name="line.208"></a>
-<span class="sourceLineNo">209</span>          TableName.valueOf("testCleanMergeReference");<a name="line.209"></a>
-<span class="sourceLineNo">210</span>      // Create table and load data.<a name="line.210"></a>
-<span class="sourceLineNo">211</span>      Table table = createTableAndLoadData(MASTER, tableName);<a name="line.211"></a>
-<span class="sourceLineNo">212</span>      // Merge 1st and 2nd region<a name="line.212"></a>
-<span class="sourceLineNo">213</span>      mergeRegionsAndVerifyRegionNum(MASTER, tableName, 0, 1,<a name="line.213"></a>
-<span class="sourceLineNo">214</span>          INITIAL_REGION_NUM - 1);<a name="line.214"></a>
-<span class="sourceLineNo">215</span>      verifyRowCount(table, ROWSIZE);<a name="line.215"></a>
-<span class="sourceLineNo">216</span>      table.close();<a name="line.216"></a>
-<span class="sourceLineNo">217</span><a name="line.217"></a>
-<span class="sourceLineNo">218</span>      List&lt;Pair&lt;HRegionInfo, ServerName&gt;&gt; tableRegions = MetaTableAccessor<a name="line.218"></a>
-<span class="sourceLineNo">219</span>          .getTableRegionsAndLocations(MASTER.getConnection(), tableName);<a name="line.219"></a>
-<span class="sourceLineNo">220</span>      HRegionInfo mergedRegionInfo = tableRegions.get(0).getFirst();<a name="line.220"></a>
-<span class="sourceLineNo">221</span>      HTableDescriptor tableDescriptor = MASTER.getTableDescriptors().get(<a name="line.221"></a>
-<span class="sourceLineNo">222</span>          tableName);<a name="line.222"></a>
-<span class="sourceLineNo">223</span>      Result mergedRegionResult = MetaTableAccessor.getRegionResult(<a name="line.223"></a>
-<span class="sourceLineNo">224</span>        MASTER.getConnection(), mergedRegionInfo.getRegionName());<a name="line.224"></a>
-<span class="sourceLineNo">225</span><a name="line.225"></a>
-<span class="sourceLineNo">226</span>      // contains merge reference in META<a name="line.226"></a>
-<span class="sourceLineNo">227</span>      assertTrue(mergedRegionResult.getValue(HConstants.CATALOG_FAMILY,<a name="line.227"></a>
-<span class="sourceLineNo">228</span>          HConstants.MERGEA_QUALIFIER) != null);<a name="line.228"></a>
-<span class="sourceLineNo">229</span>      assertTrue(mergedRegionResult.getValue(HConstants.CATALOG_FAMILY,<a name="line.229"></a>
-<span class="sourceLineNo">230</span>          HConstants.MERGEB_QUALIFIER) != null);<a name="line.230"></a>
-<span class="sourceLineNo">231</span><a name="line.231"></a>
-<span class="sourceLineNo">232</span>      // merging regions' directory are in the file system all the same<a name="line.232"></a>
-<span class="sourceLineNo">233</span>      PairOfSameType&lt;HRegionInfo&gt; p = MetaTableAccessor.getMergeRegions(mergedRegionResult);<a name="line.233"></a>
-<span class="sourceLineNo">234</span>      HRegionInfo regionA = p.getFirst();<a name="line.234"></a>
-<span class="sourceLineNo">235</span>      HRegionInfo regionB = p.getSecond();<a name="line.235"></a>
-<span class="sourceLineNo">236</span>      FileSystem fs = MASTER.getMasterFileSystem().getFileSystem();<a name="line.236"></a>
-<span class="sourceLineNo">237</span>      Path rootDir = MASTER.getMasterFileSystem().getRootDir();<a name="line.237"></a>
-<span class="sourceLineNo">238</span><a name="line.238"></a>
-<span class="sourceLineNo">239</span>      Path tabledir = FSUtils.getTableDir(rootDir, mergedRegionInfo.getTable());<a name="line.239"></a>
-<span class="sourceLineNo">240</span>      Path regionAdir = new Path(tabledir, regionA.getEncodedName());<a name="line.240"></a>
-<span class="sourceLineNo">241</span>      Path regionBdir = new Path(tabledir, regionB.getEncodedName());<a name="line.241"></a>
-<span class="sourceLineNo">242</span>      assertTrue(fs.exists(regionAdir));<a name="line.242"></a>
-<span class="sourceLineNo">243</span>      assertTrue(fs.exists(regionBdir));<a name="line.243"></a>
-<span class="sourceLineNo">244</span><a name="line.244"></a>
-<span class="sourceLineNo">245</span>      HColumnDescriptor[] columnFamilies = tableDescriptor.getColumnFamilies();<a name="line.245"></a>
-<span class="sourceLineNo">246</span>      HRegionFileSystem hrfs = new HRegionFileSystem(<a name="line.246"></a>
-<span class="sourceLineNo">247</span>        TEST_UTIL.getConfiguration(), fs, tabledir, mergedRegionInfo);<a name="line.247"></a>
-<span class="sourceLineNo">248</span>      int count = 0;<a name="line.248"></a>
-<span class="sourceLineNo">249</span>      for(HColumnDescriptor colFamily : columnFamilies) {<a name="line.249"></a>
-<span class="sourceLineNo">250</span>        count += hrfs.getStoreFiles(colFamily.getName()).size();<a name="line.250"></a>
-<span class="sourceLineNo">251</span>      }<a name="line.251"></a>
-<span class="sourceLineNo">252</span>      ADMIN.compactRegion(mergedRegionInfo.getRegionName());<a name="line.252"></a>
-<span class="sourceLineNo">253</span>      // clean up the merged region store files<a name="line.253"></a>
-<span class="sourceLineNo">254</span>      // wait until merged region have reference file<a name="line.254"></a>
-<span class="sourceLineNo">255</span>      long timeout = System.currentTimeMillis() + waitTime;<a name="line.255"></a>
-<span class="sourceLineNo">256</span>      int newcount = 0;<a name="line.256"></a>
-<span class="sourceLineNo">257</span>      while (System.currentTimeMillis() &lt; timeout) {<a name="line.257"></a>
-<span class="sourceLineNo">258</span>        for(HColumnDescriptor colFamily : columnFamilies) {<a name="line.258"></a>
-<span class="sourceLineNo">259</span>          newcount += hrfs.getStoreFiles(colFamily.getName()).size();<a name="line.259"></a>
-<span class="sourceLineNo">260</span>        }<a name="line.260"></a>
-<span class="sourceLineNo">261</span>        if(newcount &gt; count) {<a name="line.261"></a>
-<span class="sourceLineNo">262</span>          break;<a name="line.262"></a>
-<span class="sourceLineNo">263</span>        }<a name="line.263"></a>
-<span class="sourceLineNo">264</span>        Thread.sleep(50);<a name="line.264"></a>
-<span class="sourceLineNo">265</span>      }<a name="line.265"></a>
-<span class="sourceLineNo">266</span>      assertTrue(newcount &gt; count);<a name="line.266"></a>
-<span class="sourceLineNo">267</span>      List&lt;RegionServerThread&gt; regionServerThreads = TEST_UTIL.getHBaseCluster()<a name="line.267"></a>
-<span class="sourceLineNo">268</span>          .getRegionServerThreads();<a name="line.268"></a>
-<span class="sourceLineNo">269</span>      for (RegionServerThread rs : regionServerThreads) {<a name="line.269"></a>
-<span class="sourceLineNo">270</span>        CompactedHFilesDischarger cleaner = new CompactedHFilesDischarger(100, null,<a name="line.270"></a>
-<span class="sourceLineNo">271</span>            rs.getRegionServer(), false);<a name="line.271"></a>
-<span class="sourceLineNo">272</span>        cleaner.chore();<a name="line.272"></a>
-<span class="sourceLineNo">273</span>        Thread.sleep(1000);<a name="line.273"></a>
-<span class="sourceLineNo">274</span>      }<a name="line.274"></a>
-<span class="sourceLineNo">275</span>      while (System.currentTimeMillis() &lt; timeout) {<a name="line.275"></a>
-<span class="sourceLineNo">276</span>        int newcount1 = 0;<a name="line.276"></a>
-<span class="sourceLineNo">277</span>        for(HColumnDescriptor colFamily : columnFamilies) {<a name="line.277"></a>
-<span class="sourceLineNo">278</span>          newcount1 += hrfs.getStoreFiles(colFamily.getName()).size();<a name="line.278"></a>
-<span class="sourceLineNo">279</span>        }<a name="line.279"></a>
-<span class="sourceLineNo">280</span>        if(newcount1 &lt;= 1) {<a name="line.280"></a>
-<span class="sourceLineNo">281</span>          break;<a name="line.281"></a>
-<span class="sourceLineNo">282</span>        }<a name="line.282"></a>
-<span class="sourceLineNo">283</span>        Thread.sleep(50);<a name="line.283"></a>
-<span class="sourceLineNo">284</span>      }<a name="line.284"></a>
-<span class="sourceLineNo">285</span>      // run CatalogJanitor to clean merge references in hbase:meta and archive the<a name="line.285"></a>
-<span class="sourceLineNo">286</span>      // files of merging regions<a name="line.286"></a>
-<span class="sourceLineNo">287</span>      int cleaned = 0;<a name="line.287"></a>
-<span class="sourceLineNo">288</span>      while (cleaned == 0) {<a name="line.288"></a>
-<span class="sourceLineNo">289</span>        cleaned = ADMIN.runCatalogScan();<a name="line.289"></a>
-<span class="sourceLineNo">290</span>        LOG.debug("catalog janitor returned " + cleaned);<a name="line.290"></a>
-<span class="sourceLineNo">291</span>        Thread.sleep(50);<a name="line.291"></a>
-<span class="sourceLineNo">292</span>      }<a name="line.292"></a>
-<span class="sourceLineNo">293</span>      assertFalse(regionAdir.toString(), fs.exists(regionAdir));<a name="line.293"></a>
-<span class="sourceLineNo">294</span>      assertFalse(regionBdir.toString(), fs.exists(regionBdir));<a name="line.294"></a>
-<span class="sourceLineNo">295</span>      assertTrue(cleaned &gt; 0);<a name="line.295"></a>
-<span class="sourceLineNo">296</span><a name="line.296"></a>
-<span class="sourceLineNo">297</span>      mergedRegionResult = MetaTableAccessor.getRegionResult(<a name="line.297"></a>
-<span class="sourceLineNo">298</span>        TEST_UTIL.getConnection(), mergedRegionInfo.getRegionName());<a name="line.298"></a>
-<span class="sourceLineNo">299</span>      assertFalse(mergedRegionResult.getValue(HConstants.CATALOG_FAMILY,<a name="line.299"></a>
-<span class="sourceLineNo">300</span>          HConstants.MERGEA_QUALIFIER) != null);<a name="line.300"></a>
-<span class="sourceLineNo">301</span>      assertFalse(mergedRegionResult.getValue(HConstants.CATALOG_FAMILY,<a name="line.301"></a>
-<span class="sourceLineNo">302</span>          HConstants.MERGEB_QUALIFIER) != null);<a name="line.302"></a>
-<span class="sourceLineNo">303</span><a name="line.303"></a>
-<span class="sourceLineNo">304</span>    } finally {<a name="line.304"></a>
-<span class="sourceLineNo">305</span>      ADMIN.enableCatalogJanitor(true);<a name="line.305"></a>
-<span class="sourceLineNo">306</span>    }<a name="line.306"></a>
-<span class="sourceLineNo">307</span>  }<a name="line.307"></a>
-<span class="sourceLineNo">308</span><a name="line.308"></a>
-<span class="sourceLineNo">309</span>  /**<a name="line.309"></a>
-<span class="sourceLineNo">310</span>   * This test tests 1, merging region not online;<a name="line.310"></a>
-<span class="sourceLineNo">311</span>   * 2, merging same two regions; 3, merging unknown regions.<a name="line.311"></a>
-<span class="sourceLineNo">312</span>   * They are in one test case so that we don't have to create<a name="line.312"></a>
-<span class="sourceLineNo">313</span>   * many tables, and these tests are simple.<a name="line.313"></a>
-<span class="sourceLineNo">314</span>   */<a name="line.314"></a>
-<span class="sourceLineNo">315</span>  @Test<a name="line.315"></a>
-<span class="sourceLineNo">316</span>  public void testMerge() throws Exception {<a name="line.316"></a>
-<span class="sourceLineNo">317</span>    LOG.info("Starting testMerge");<a name="line.317"></a>
-<span class="sourceLineNo">318</span>    final TableName tableName = TableName.valueOf("testMerge");<a name="line.318"></a>
-<span class="sourceLineNo">319</span><a name="line.319"></a>
-<span class="sourceLineNo">320</span>    try {<a name="line.320"></a>
-<span class="sourceLineNo">321</span>      // Create table and load data.<a name="line.321"></a>
-<span class="sourceLineNo">322</span>      Table table = createTableAndLoadData(MASTER, tableName);<a name="line.322"></a>
-<span class="sourceLineNo">323</span>      RegionStates regionStates = MASTER.getAssignmentManager().getRegionStates();<a name="line.323"></a>
-<span class="sourceLineNo">324</span>      List&lt;HRegionInfo&gt; regions = regionStates.getRegionsOfTable(tableName);<a name="line.324"></a>
-<span class="sourceLineNo">325</span>      // Fake offline one region<a name="line.325"></a>
-<span class="sourceLineNo">326</span>      HRegionInfo a = regions.get(0);<a name="line.326"></a>
-<span class="sourceLineNo">327</span>      HRegionInfo b = regions.get(1);<a name="line.327"></a>
-<span class="sourceLineNo">328</span>      regionStates.regionOffline(a);<a name="line.328"></a>
-<span class="sourceLineNo">329</span>      try {<a name="line.329"></a>
-<span class="sourceLineNo">330</span>        // Merge offline region. Region a is offline here<a name="line.330"></a>
-<span class="sourceLineNo">331</span>        ADMIN.mergeRegions(a.getEncodedNameAsBytes(), b.getEncodedNameAsBytes(), false);<a name="line.331"></a>
-<span class="sourceLineNo">332</span>        fail("Offline regions should not be able to merge");<a name="line.332"></a>
-<span class="sourceLineNo">333</span>      } catch (IOException ie) {<a name="line.333"></a>
-<span class="sourceLineNo">334</span>        System.out.println(ie);<a name="line.334"></a>
-<span class="sourceLineNo">335</span>        assertTrue("Exception should mention regions not online",<a name="line.335"></a>
-<span class="sourceLineNo">336</span>          StringUtils.stringifyException(ie).contains("regions not online")<a name="line.336"></a>
-<span class="sourceLineNo">337</span>            &amp;&amp; ie instanceof MergeRegionException);<a name="line.337"></a>
-<span class="sourceLineNo">338</span>      }<a name="line.338"></a>
-<span class="sourceLineNo">339</span>      try {<a name="line.339"></a>
-<span class="sourceLineNo">340</span>        // Merge the same region: b and b.<a name="line.340"></a>
-<span class="sourceLineNo">341</span>        ADMIN.mergeRegions(b.getEncodedNameAsBytes(), b.getEncodedNameAsBytes(), true);<a name="line.341"></a>
-<span class="sourceLineNo">342</span>        fail("A region should not be able to merge with itself, even forcifully");<a name="line.342"></a>
-<span class="sourceLineNo">343</span>      } catch (IOException ie) {<a name="line.343"></a>
-<span class="sourceLineNo">344</span>        assertTrue("Exception should mention regions not online",<a name="line.344"></a>
-<span class="sourceLineNo">345</span>          StringUtils.stringifyException(ie).contains("region to itself")<a name="line.345"></a>
-<span class="sourceLineNo">346</span>            &amp;&amp; ie instanceof MergeRegionException);<a name="line.346"></a>
-<span class="sourceLineNo">347</span>      }<a name="line.347"></a>
-<span class="sourceLineNo">348</span>      try {<a name="line.348"></a>
-<span class="sourceLineNo">349</span>        // Merge unknown regions<a name="line.349"></a>
-<span class="sourceLineNo">350</span>        ADMIN.mergeRegions(Bytes.toBytes("-f1"), Bytes.toBytes("-f2"), true);<a name="line.350"></a>
-<span class="sourceLineNo">351</span>        fail("Unknown region could not be merged");<a name="line.351"></a>
-<span class="sourceLineNo">352</span>      } catch (IOException ie) {<a name="line.352"></a>
-<span class="sourceLineNo">353</span>        assertTrue("UnknownRegionException should be thrown",<a name="line.353"></a>
-<span class="sourceLineNo">354</span>          ie instanceof UnknownRegionException);<a name="line.354"></a>
-<span class="sourceLineNo">355</span>      }<a name="line.355"></a>
-<span class="sourceLineNo">356</span>      table.close();<a name="line.356"></a>
-<span class="sourceLineNo">357</span>    } finally {<a name="line.357"></a>
-<span class="sourceLineNo">358</span>      TEST_UTIL.deleteTable(tableName);<a name="line.358"></a>
-<span class="sourceLineNo">359</span>    }<a name="line.359"></a>
-<span class="sourceLineNo">360</span>  }<a name="line.360"></a>
-<span class="sourceLineNo">361</span><a name="line.361"></a>
-<span class="sourceLineNo">362</span>  @Test<a name="line.362"></a>
-<span class="sourceLineNo">363</span>  public void testMergeWithReplicas() throws Exception {<a name="line.363"></a>
-<span class="sourceLineNo">364</span>    final TableName tableName = TableName.valueOf("testMergeWithReplicas");<a name="line.364"></a>
-<span class="sourceLineNo">365</span>    // Create table and load data.<a name="line.365"></a>
-<span class="sourceLineNo">366</span>    createTableAndLoadData(MASTER, tableName, 5, 2);<a name="line.366"></a>
-<span class="sourceLineNo">367</span>    List&lt;Pair&lt;HRegionInfo, ServerName&gt;&gt; initialRegionToServers =<a name="line.367"></a>
-<span class="sourceLineNo">368</span>        MetaTableAccessor.getTableRegionsAndLocations(<a name="line.368"></a>
-<span class="sourceLineNo">369</span>            TEST_UTIL.getConnection(), tableName);<a name="line.369"></a>
-<span class="sourceLineNo">370</span>    // Merge 1st and 2nd region<a name="line.370"></a>
-<span class="sourceLineNo">371</span>    PairOfSameType&lt;HRegionInfo&gt; mergedRegions = mergeRegionsAndVerifyRegionNum(MASTER, tableName,<a name="line.371"></a>
-<span class="sourceLineNo">372</span>        0, 2, 5 * 2 - 2);<a name="line.372"></a>
-<span class="sourceLineNo">373</span>    List&lt;Pair&lt;HRegionInfo, ServerName&gt;&gt; currentRegionToServers =<a name="line.373"></a>
-<span class="sourceLineNo">374</span>        MetaTableAccessor.getTableRegionsAndLocations(<a name="line.374"></a>
-<span class="sourceLineNo">375</span>            TEST_UTIL.getConnection(), tableName);<a name="line.375"></a>
-<span class="sourceLineNo">376</span>    List&lt;HRegionInfo&gt; initialRegions = new ArrayList&lt;HRegionInfo&gt;();<a name="line.376"></a>
-<span class="sourceLineNo">377</span>    for (Pair&lt;HRegionInfo, ServerName&gt; p : initialRegionToServers) {<a name="line.377"></a>
-<span class="sourceLineNo">378</span>      initialRegions.add(p.getFirst());<a name="line.378"></a>
-<span class="sourceLineNo">379</span>    }<a name="line.379"></a>
-<span class="sourceLineNo">380</span>    List&lt;HRegionInfo&gt; currentRegions = new ArrayList&lt;HRegionInfo&gt;();<a name="line.380"></a>
-<span class="sourceLineNo">381</span>    for (Pair&lt;HRegionInfo, ServerName&gt; p : currentRegionToServers) {<a name="line.381"></a>
-<span class="sourceLineNo">382</span>      currentRegions.add(p.getFirst());<a name="line.382"></a>
-<span class="sourceLineNo">383</span>    }<a name="line.383"></a>
-<span class="sourceLineNo">384</span>    assertTrue(initialRegions.contains(mergedRegions.getFirst())); //this is the first region<a name="line.384"></a>
-<span class="sourceLineNo">385</span>    assertTrue(initialRegions.contains(RegionReplicaUtil.getRegionInfoForReplica(<a name="line.385"></a>
-<span class="sourceLineNo">386</span>        mergedRegions.getFirst(), 1))); //this is the replica of the first region<a name="line.386"></a>
-<span class="sourceLineNo">387</span>    assertTrue(initialRegions.contains(mergedRegions.getSecond())); //this is the second region<a name="line.387"></a>
-<span class="sourceLineNo">388</span>    assertTrue(initialRegions.contains(RegionReplicaUtil.getRegionInfoForReplica(<a name="line.388"></a>
-<span class="sourceLineNo">389</span>        mergedRegions.getSecond(), 1))); //this is the replica of the second region<a name="line.389"></a>
-<span class="sourceLineNo">390</span>    assertTrue(!initialRegions.contains(currentRegions.get(0))); //this is the new region<a name="line.390"></a>
-<span class="sourceLineNo">391</span>    assertTrue(!initialRegions.contains(RegionReplicaUtil.getRegionInfoForReplica(<a name="line.391"></a>
-<span class="sourceLineNo">392</span>        currentRegions.get(0), 1))); //replica of the new region<a name="line.392"></a>
-<span class="sourceLineNo">393</span>    assertTrue(currentRegions.contains(RegionReplicaUtil.getRegionInfoForReplica(<a name="line.393"></a>
-<span class="sourceLineNo">394</span>        currentRegions.get(0), 1))); //replica of the new region<a name="line.394"></a>
-<span class="sourceLineNo">395</span>    assertTrue(!currentRegions.contains(RegionReplicaUtil.getRegionInfoForReplica(<a name="line.395"></a>
-<span class="sourceLineNo">396</span>        mergedRegions.getFirst(), 1))); //replica of the merged region<a name="line.396"></a>
-<span class="sourceLineNo">397</span>    assertTrue(!currentRegions.contains(RegionReplicaUtil.getRegionInfoForReplica(<a name="line.397"></a>
-<span class="sourceLineNo">398</span>        mergedRegions.getSecond(), 1))); //replica of the merged region<a name="line.398"></a>
-<span class="sourceLineNo">399</span>  }<a name="line.399"></a>
-<span class="sourceLineNo">400</span><a name="line.400"></a>
-<span class="sourceLineNo">401</span>  private PairOfSameType&lt;HRegionInfo&gt; mergeRegionsAndVerifyRegionNum(<a name="line.401"></a>
-<span class="sourceLineNo">402</span>      HMaster master, TableName tablename,<a name="line.402"></a>
-<span class="sourceLineNo">403</span>      int regionAnum, int regionBnum, int expectedRegionNum) throws Exception {<a name="line.403"></a>
-<span class="sourceLineNo">404</span>    PairOfSameType&lt;HRegionInfo&gt; mergedRegions =<a name="line.404"></a>
-<span class="sourceLineNo">405</span>      requestMergeRegion(master, tablename, regionAnum, regionBnum);<a name="line.405"></a>
-<span class="sourceLineNo">406</span>    waitAndVerifyRegionNum(master, tablename, expectedRegionNum);<a name="line.406"></a>
-<span class="sourceLineNo">407</span>    return mergedRegions;<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 PairOfSameType&lt;HRegionInfo&gt; requestMergeRegion(<a name="line.410"></a>
-<span class="sourceLineNo">411</span>      HMaster master, TableName tablename,<a name="line.411"></a>
-<span class="sourceLineNo">412</span>      int regionAnum, int regionBnum) throws Exception {<a name="line.412"></a>
-<span class="sourceLineNo">413</span>    List&lt;Pair&lt;HRegionInfo, ServerName&gt;&gt; tableRegions = MetaTableAccessor<a name="line.413"></a>
-<span class="sourceLineNo">414</span>        .getTableRegionsAndLocations(<a name="line.414"></a>
-<span class="sourceLineNo">415</span>            TEST_UTIL.getConnection(), tablename);<a name="line.415"></a>
-<span class="sourceLineNo">416</span>    HRegionInfo regionA = tableRegions.get(regionAnum).getFirst();<a name="line.416"></a>
-<span class="sourceLineNo">417</span>    HRegionInfo regionB = tableRegions.get(regionBnum).getFirst();<a name="line.417"></a>
-<span class="sourceLineNo">418</span>    ADMIN.mergeRegions(<a name="line.418"></a>
-<span class="sourceLineNo">419</span>      regionA.getEncodedNameAsBytes(),<a name="line.419"></a>
-<span class="sourceLineNo">420</span>      regionB.getEncodedNameAsBytes(), false);<a name="line.420"></a>
-<span class="sourceLineNo">421</span>    return new PairOfSameType&lt;HRegionInfo&gt;(regionA, regionB);<a name="line.421"></a>
-<span class="sourceLineNo">422</span>  }<a name="line.422"></a>
-<span class="sourceLineNo">423</span><a name="line.423"></a>
-<span class="sourceLineNo">424</span>  private void waitAndVerifyRegionNum(HMaster master, TableName tablename,<a name="line.424"></a>
-<span class="sourceLineNo">425</span>      int expectedRegionNum) throws Exception {<a name="line.425"></a>
-<span class="sourceLineNo">426</span>    List&lt;Pair&lt;HRegionInfo, ServerName&gt;&gt; tableRegionsInMeta;<a name="line.426"></a>
-<span class="sourceLineNo">427</span>    List&lt;HRegionInfo&gt; tableRegionsInMaster;<a name="line.427"></a>
-<span class="sourceLineNo">428</span>    long timeout = System.currentTimeMillis() + waitTime;<a name="line.428"></a>
-<span class="sourceLineNo">429</span>    while (System.currentTimeMillis() &lt; timeout) {<a name="line.429"></a>
-<span class="sourceLineNo">430</span>      tableRegionsInMeta = MetaTableAccessor.getTableRegionsAndLocations(<a name="line.430"></a>
-<span class="sourceLineNo">431</span>        TEST_UTIL.getConnection(), tablename);<a name="line.431"></a>
-<span class="sourceLineNo">432</span>      tableRegionsInMaster = master.getAssignmentManager().getRegionStates()<a name="line.432"></a>
-<span class="sourceLineNo">433</span>          .getRegionsOfTable(tablename);<a name="line.433"></a>
-<span class="sourceLineNo">434</span>      if (tableRegionsInMeta.size() == expectedRegionNum<a name="line.434"></a>
-<span class="sourceLineNo">435</span>          &amp;&amp; tableRegionsInMaster.size() == expectedRegionNum) {<a name="line.435"></a>
-<span class="sourceLineNo">436</span>        break;<a name="line.436"></a>
-<span class="sourceLineNo">437</span>      }<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>    tableRegionsInMeta = MetaTableAccessor.getTableRegionsAndLocations(<a name="line.441"></a>
-<span class="sourceLineNo">442</span>        TEST_UTIL.getConnection(), tablename);<a name="line.442"></a>
-<span class="sourceLineNo">443</span>    LOG.info("Regions after merge:" + Joiner.on(',').join(tableRegionsInMeta));<a name="line.443"></a>
-<span class="sourceLineNo">444</span>    assertEquals(expectedRegionNum, tableRegionsInMeta.size());<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 Table createTableAndLoadData(HMaster master, TableName tablename)<a name="line.447"></a>
-<span class="sourceLineNo">448</span>      throws Exception {<a name="line.448"></a>
-<span class="sourceLineNo">449</span>    return createTableAndLoadData(master, tablename, INITIAL_REGION_NUM, 1);<a name="line.449"></a>
-<span class="sourceLineNo">450</span>  }<a name="line.450"></a>
-<span class="sourceLineNo">451</span><a name="line.451"></a>
-<span class="sourceLineNo">452</span>  private Table createTableAndLoadData(HMaster master, TableName tablename,<a name="line.452"></a>
-<span class="sourceLineNo">453</span>      int numRegions, int replication) throws Exception {<a name="line.453"></a>
-<span class="sourceLineNo">454</span>    assertTrue("ROWSIZE must &gt; numregions:" + numRegions, ROWSIZE &gt; numRegions);<a name="line.454"></a>
-<span class="sourceLineNo">455</span>    byte[][] splitRows = new byte[numRegions - 1][];<a name="line.455"></a>
-<span class="sourceLineNo">456</span>    for (int i = 0; i &lt; splitRows.length; i++) {<a name="line.456"></a>
-<span class="sourceLineNo">457</span>      splitRows[i] = ROWS[(i + 1) * ROWSIZE / numRegions];<a name="line.457"></a>
-<span class="sourceLineNo">458</span>    }<a name="line.458"></a>
-<span class="sourceLineNo">459</span><a name="line.459"></a>
-<span class="sourceLineNo">460</span>    Table table = TEST_UTIL.createTable(tablename, FAMILYNAME, splitRows);<a name="line.460"></a>
-<span class="sourceLineNo">461</span>    if (replication &gt; 1) {<a name="line.461"></a>
-<span class="sourceLineNo">462</span>      HBaseTestingUtility.setReplicas(ADMIN, tablename, replication);<a name="line.462"></a>
-<span class="sourceLineNo">463</span>    }<a name="line.463"></a>
-<span class="sourceLineNo">464</span>    loadData(table);<a name="line.464"></a>
-<span class="sourceLineNo">465</span>    verifyRowCount(table, ROWSIZE);<a name="line.465"></a>
-<span class="sourceLineNo">466</span><a name="line.466"></a>
-<span class="sourceLineNo">467</span>    // sleep here is an ugly hack to allow region transitions to finish<a name="line.467"></a>
-<span class="sourceLineNo">468</span>    long timeout = System.currentTimeMillis() + waitTime;<a name="line.468"></a>
-<span class="sourceLineNo">469</span>    List&lt;Pair&lt;HRegionInfo, ServerName&gt;&gt; tableRegions;<a name="line.469"></a>
-<span class="sourceLineNo">470</span>    while (System.currentTimeMillis() &lt; timeout) {<a name="line.470"></a>
-<span class="sourceLineNo">471</span>      tableRegions = MetaTableAccessor.getTableRegionsAndLocations(<a name="line.471"></a>
-<span class="sourceLineNo">472</span>          TEST_UTIL.getConnection(), tablename);<a name="line.472"></a>
-<span class="sourceLineNo">473</span>      if (tableRegions.size() == numRegions * replication)<a name="line.473"></a>
-<span class="sourceLineNo">474</span>        break;<a name="line.474"></a>
-<span class="sourceLineNo">475</span>      Thread.sleep(250);<a name="line.475"></a>
-<span class="sourceLineNo">476</span>    }<a name="line.476"></a>
-<span class="sourceLineNo">477</span><a name="line.477"></a>
-<span class="sourceLineNo">478</span>    tableRegions = MetaTableAccessor.getTableRegionsAndLocations(<a name="line.478"></a>
-<span class="sourceLineNo">479</span>        TEST_UTIL.getConnection(), tablename);<a name="line.479"></a>
-<span class="sourceLineNo">480</span>    LOG.info("Regions after load: " + Joiner.on(',').join(tableRegions));<a name="line.480"></a>
-<span class="sourceLineNo">481</span>    assertEquals(numRegions * replication, tableRegions.size());<a name="line.481"></a>
-<span class="sourceLineNo">482</span>    return table;<a name="line.482"></a>
-<span class="sourceLineNo">483</span>  }<a name="line.483"></a>
-<span class="sourceLineNo">484</span><a name="line.484"></a>
-<span class="sourceLineNo">485</span>  private static byte[][] makeN(byte[] base, int n) {<a name="line.485"></a>
-<span class="sourceLineNo">486</span>    byte[][] ret = new byte[n][];<a name="line.486"></a>
-<span class="sourceLineNo">487</span>    for (int i = 0; i &lt; n; i++) {<a name="line.487"></a>
-<span class="sourceLineNo">488</span>      ret[i] = Bytes.add(base, Bytes.toBytes(String.format("%04d", i)));<a name="line.488"></a>
-<span class="sourceLineNo">489</span>    }<a name="line.489"></a>
-<span class="sourceLineNo">490</span>    return ret;<a name="line.490"></a>
-<span class="sourceLineNo">491</span>  }<a name="line.491"></a>
-<span class="sourceLineNo">492</span><a name="line.492"></a>
-<span class="sourceLineNo">493</span>  private void loadData(Table table) throws IOException {<a name="line.493"></a>
-<span class="sourceLineNo">494</span>    for (int i = 0; i &lt; ROWSIZE; i++) {<a name="line.494"></a>
-<span class="sourceLineNo">495</span>      Put put = new Put(ROWS[i]);<a name="line.495"></a>
-<span class="sourceLineNo">496</span>      put.addColumn(FAMILYNAME, QUALIFIER, Bytes.toBytes(i));<a name="line.496"></a>
-<span class="sourceLineNo">497</span>      table.put(put);<a name="line.497"></a>
-<span class="sourceLineNo">498</span>    }<a name="line.498"></a>
-<span class="sourceLineNo">499</span>  }<a name="line.499"></a>
-<span class="sourceLineNo">500</span><a name="line.500"></a>
-<span class="sourceLineNo">501</span>  private void verifyRowCount(Table table, int expectedRegionNum)<a name="line.501"></a>
-<span class="sourceLineNo">502</span>      throws IOException {<a name="line.502"></a>
-<span class="sourceLineNo">503</span>    ResultScanner scanner = table.getScanner(new Scan());<a name="line.503"></a>
-<span class="sourceLineNo">504</span>    int rowCount = 0;<a name="line.504"></a>
-<span class="sourceLineNo">505</span>    while (scanner.next() != null) {<a name="line.505"></a>
-<span class="sourceLineNo">506</span>      rowCount++;<a name="line.506"></a>
-<span class="sourceLineNo">507</span>    }<a name="line.507"></a>
-<span class="sourceLineNo">508</span>    assertEquals(expectedRegionNum, rowCount);<a name="line.508"></a>
-<span class="sourceLineNo">509</span>    scanner.close();<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>  // Make it public so that JVMClusterUtil can access it.<a name="line.512"></a>
-<span class="sourceLineNo">513</span>  public static class MyMaster extends HMaster {<a name="line.513"></a>
-<span class="sourceLineNo">514</span>    public MyMaster(Configuration conf, CoordinatedStateManager cp)<a name="line.514"></a>
-<span class="sourceLineNo">515</span>      throws IOException, KeeperException,<a name="line.515"></a>
-<span class="sourceLineNo">516</span>        InterruptedException {<a name="line.516"></a>
-<span class="sourceLineNo">517</span>      super(conf, cp);<a name="line.517"></a>
-<span class="sourceLineNo">518</span>    }<a name="line.518"></a>
-<span class="sourceLineNo">519</span><a name="line.519"></a>
-<span class="sourceLineNo">520</span>    @Override<a name="line.520"></a>
-<span class="sourceLineNo">521</span>    protected RSRpcServices createRpcServices() throws IOException {<a name="line.521"></a>
-<span class="sourceLineNo">522</span>      return new MyMasterRpcServices(this);<a name="line.522"></a>
+<span class="sourceLineNo">151</span>    verifyRowCount(table, ROWSIZE);<a name="line.151"></a>
+<span class="sourceLineNo">152</span><a name="line.152"></a>
+<span class="sourceLineNo">153</span>    // Randomly choose one of the two merged regions<a name="line.153"></a>
+<span class="sourceLineNo">154</span>    HRegionInfo hri = RandomUtils.nextBoolean() ?<a name="line.154"></a>
+<span class="sourceLineNo">155</span>      mergedRegions.getFirst() : mergedRegions.getSecond();<a name="line.155"></a>
+<span class="sourceLineNo">156</span>    MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();<a name="line.156"></a>
+<span class="sourceLineNo">157</span>    AssignmentManager am = cluster.getMaster().getAssignmentManager();<a name="line.157"></a>
+<span class="sourceLineNo">158</span>    RegionStates regionStates = am.getRegionStates();<a name="line.158"></a>
+<span class="sourceLineNo">159</span>    long start = EnvironmentEdgeManager.currentTime();<a name="line.159"></a>
+<span class="sourceLineNo">160</span>    while (!regionStates.isRegionInState(hri, State.MERGED)) {<a name="line.160"></a>
+<span class="sourceLineNo">161</span>      assertFalse("Timed out in waiting one merged region to be in state MERGED",<a name="line.161"></a>
+<span class="sourceLineNo">162</span>        EnvironmentEdgeManager.currentTime() - start &gt; 60000);<a name="line.162"></a>
+<span class="sourceLineNo">163</span>      Thread.sleep(500);<a name="line.163"></a>
+<span class="sourceLineNo">164</span>    }<a name="line.164"></a>
+<span class="sourceLineNo">165</span><a name="line.165"></a>
+<span class="sourceLineNo">166</span>    // We should not be able to assign it again<a name="line.166"></a>
+<span class="sourceLineNo">167</span>    am.assign(hri, true);<a name="line.167"></a>
+<span class="sourceLineNo">168</span>    assertFalse("Merged region can't be assigned",<a name="line.168"></a>
+<span class="sourceLineNo">169</span>      regionStates.isRegionInTransition(hri));<a name="line.169"></a>
+<span class="sourceLineNo">170</span>    assertTrue(regionStates.isRegionInState(hri, State.MERGED));<a name="line.170"></a>
+<span class="sourceLineNo">171</span><a name="line.171"></a>
+<span class="sourceLineNo">172</span>    // We should not be able to unassign it either<a name="line.172"></a>
+<span class="sourceLineNo">173</span>    am.unassign(hri, null);<a name="line.173"></a>
+<span class="sourceLineNo">174</span>    assertFalse("Merged region can't be unassigned",<a name="line.174"></a>
+<span class="sourceLineNo">175</span>      regionStates.isRegionInTransition(hri));<a name="line.175"></a>
+<span class="sourceLineNo">176</span>    assertTrue(regionStates.isRegionInState(hri, State.MERGED));<a name="line.176"></a>
+<span class="sourceLineNo">177</span><a name="line.177"></a>
+<span class="sourceLineNo">178</span>    table.close();<a name="line.178"></a>
+<span class="sourceLineNo">179</span>  }<a name="line.179"></a>
+<span class="sourceLineNo">180</span><a name="line.180"></a>
+<span class="sourceLineNo">181</span>  /**<a name="line.181"></a>
+<span class="sourceLineNo">182</span>   * Not really restarting the master. Simulate it by clear of new region<a name="line.182"></a>
+<span class="sourceLineNo">183</span>   * state since it is not persisted, will be lost after master restarts.<a name="line.183"></a>
+<span class="sourceLineNo">184</span>   */<a name="line.184"></a>
+<span class="sourceLineNo">185</span>  @Test<a name="line.185"></a>
+<span class="sourceLineNo">186</span>  public void testMergeAndRestartingMaster() throws Exception {<a name="line.186"></a>
+<span class="sourceLineNo">187</span>    final TableName tableName = TableName.valueOf("testMergeAndRestartingMaster");<a name="line.187"></a>
+<span class="sourceLineNo">188</span><a name="line.188"></a>
+<span class="sourceLineNo">189</span>    // Create table and load data.<a name="line.189"></a>
+<span class="sourceLineNo">190</span>    Table table = createTableAndLoadData(MASTER, tableName);<a name="line.190"></a>
+<span class="sourceLineNo">191</span><a name="line.191"></a>
+<span class="sourceLineNo">192</span>    try {<a name="line.192"></a>
+<span class="sourceLineNo">193</span>      MyMasterRpcServices.enabled.set(true);<a name="line.193"></a>
+<span class="sourceLineNo">194</span><a name="line.194"></a>
+<span class="sourceLineNo">195</span>      // Merge 1st and 2nd region<a name="line.195"></a>
+<span class="sourceLineNo">196</span>      mergeRegionsAndVerifyRegionNum(MASTER, tableName, 0, 1, INITIAL_REGION_NUM - 1);<a name="line.196"></a>
+<span class="sourceLineNo">197</span>    } finally {<a name="line.197"></a>
+<span class="sourceLineNo">198</span>      MyMasterRpcServices.enabled.set(false);<a name="line.198"></a>
+<span class="sourceLineNo">199</span>    }<a name="line.199"></a>
+<span class="sourceLineNo">200</span><a name="line.200"></a>
+<span class="sourceLineNo">201</span>    table.close();<a name="line.201"></a>
+<span class="sourceLineNo">202</span>  }<a name="line.202"></a>
+<span class="sourceLineNo">203</span><a name="line.203"></a>
+<span class="sourceLineNo">204</span>  @Test<a name="line.204"></a>
+<span class="sourceLineNo">205</span>  public void testCleanMergeReference() throws Exception {<a name="line.205"></a>
+<span class="sourceLineNo">206</span>    LOG.info("Starting testCleanMergeReference");<a name="line.206"></a>
+<span class="sourceLineNo">207</span>    ADMIN.enableCatalogJanitor(false);<a name="line.207"></a>
+<span class="sourceLineNo">208</span>    try {<a name="line.208"></a>
+<span class="sourceLineNo">209</span>      final TableName tableName =<a name="line.209"></a>
+<span class="sourceLineNo">210</span>          TableName.valueOf("testCleanMergeReference");<a name="line.210"></a>
+<span class="sourceLineNo">211</span>      // Create table and load data.<a name="line.211"></a>
+<span class="sourceLineNo">212</span>      Table table = createTableAndLoadData(MASTER, tableName);<a name="line.212"></a>
+<span class="sourceLineNo">213</span>      // Merge 1st and 2nd region<a name="line.213"></a>
+<span class="sourceLineNo">214</span>      mergeRegionsAndVerifyRegionNum(MASTER, tableName, 0, 1,<a name="line.214"></a>
+<span class="sourceLineNo">215</span>          INITIAL_REGION_NUM - 1);<a name="line.215"></a>
+<span class="sourceLineNo">216</span>      verifyRowCount(table, ROWSIZE);<a name="line.216"></a>
+<span class="sourceLineNo">217</span>      table.close();<a name="line.217"></a>
+<span class="sourceLineNo">218</span><a name="line.218"></a>
+<span class="sourceLineNo">219</span>      List&lt;Pair&lt;HRegionInfo, ServerName&gt;&gt; tableRegions = MetaTableAccessor<a name="line.219"></a>
+<span class="sourceLineNo">220</span>          .getTableRegionsAndLocations(MASTER.getConnection(), tableName);<a name="line.220"></a>
+<span class="sourceLineNo">221</span>      HRegionInfo mergedRegionInfo = tableRegions.get(0).getFirst();<a name="line.221"></a>
+<span class="sourceLineNo">222</span>      HTableDescriptor tableDescriptor = MASTER.getTableDescriptors().get(<a name="line.222"></a>
+<span class="sourceLineNo">223</span>          tableName);<a name="line.223"></a>
+<span class="sourceLineNo">224</span>      Result mergedRegionResult = MetaTableAccessor.getRegionResult(<a name="line.224"></a>
+<span class="sourceLineNo">225</span>        MASTER.getConnection(), mergedRegionInfo.getRegionName());<a name="line.225"></a>
+<span class="sourceLineNo">226</span><a name="line.226"></a>
+<span class="sourceLineNo">227</span>      // contains merge reference in META<a name="line.227"></a>
+<span class="sourceLineNo">228</span>      assertTrue(mergedRegionResult.getValue(HConstants.CATALOG_FAMILY,<a name="line.228"></a>
+<span class="sourceLineNo">229</span>          HConstants.MERGEA_QUALIFIER) != null);<a name="line.229"></a>
+<span class="sourceLineNo">230</span>      assertTrue(mergedRegionResult.getValue(HConstants.CATALOG_FAMILY,<a name="line.230"></a>
+<span class="sourceLineNo">231</span>          HConstants.MERGEB_QUALIFIER) != null);<a name="line.231"></a>
+<span class="sourceLineNo">232</span><a name="line.232"></a>
+<span class="sourceLineNo">233</span>      // merging regions' directory are in the file system all the same<a name="line.233"></a>
+<span class="sourceLineNo">234</span>      PairOfSameType&lt;HRegionInfo&gt; p = MetaTableAccessor.getMergeRegions(mergedRegionResult);<a name="line.234"></a>
+<span class="sourceLineNo">235</span>      HRegionInfo regionA = p.getFirst();<a name="line.235"></a>
+<span class="sourceLineNo">236</span>      HRegionInfo regionB = p.getSecond();<a name="line.236"></a>
+<span class="sourceLineNo">237</span>      FileSystem fs = MASTER.getMasterFileSystem().getFileSystem();<a name="line.237"></a>
+<span class="sourceLineNo">238</span>      Path rootDir = MASTER.getMasterFileSystem().getRootDir();<a name="line.238"></a>
+<span class="sourceLineNo">239</span><a name="line.239"></a>
+<span class="sourceLineNo">240</span>      Path tabledir = FSUtils.getTableDir(rootDir, mergedRegionInfo.getTable());<a name="line.240"></a>
+<span class="sourceLineNo">241</span>      Path regionAdir = new Path(tabledir, regionA.getEncodedName());<a name="line.241"></a>
+<span class="sourceLineNo">242</span>      Path regionBdir = new Path(tabledir, regionB.getEncodedName());<a name="line.242"></a>
+<span class="sourceLineNo">243</span>      assertTrue(fs.exists(regionAdir));<a name="line.243"></a>
+<span class="sourceLineNo">244</span>      assertTrue(fs.exists(regionBdir));<a name="line.244"></a>
+<span class="sourceLineNo">245</span><a name="line.245"></a>
+<span class="sourceLineNo">246</span>      HColumnDescriptor[] columnFamilies = tableDescriptor.getColumnFamilies();<a name="line.246"></a>
+<span class="sourceLineNo">247</span>      HRegionFileSystem hrfs = new HRegionFileSystem(<a name="line.247"></a>
+<span class="sourceLineNo">248</span>        TEST_UTIL.getConfiguration(), fs, tabledir, mergedRegionInfo);<a name="line.248"></a>
+<span class="sourceLineNo">249</span>      int count = 0;<a name="line.249"></a>
+<span class="sourceLineNo">250</span>      for(HColumnDescriptor colFamily : columnFamilies) {<a name="line.250"></a>
+<span class="sourceLineNo">251</span>        count += hrfs.getStoreFiles(colFamily.getName()).size();<a name="line.251"></a>
+<span class="sourceLineNo">252</span>      }<a name="line.252"></a>
+<span class="sourceLineNo">253</span>      ADMIN.compactRegion(mergedRegionInfo.getRegionName());<a name="line.253"></a>
+<span class="sourceLineNo">254</span>      // clean up the merged region store files<a name="line.254"></a>
+<span class="sourceLineNo">255</span>      // wait until merged region have reference file<a name="line.255"></a>
+<span class="sourceLineNo">256</span>      long timeout = System.currentTimeMillis() + waitTime;<a name="line.256"></a>
+<span class="sourceLineNo">257</span>      int newcount = 0;<a name="line.257"></a>
+<span class="sourceLineNo">258</span>      while (System.currentTimeMillis() &lt; timeout) {<a name="line.258"></a>
+<span class="sourceLineNo">259</span>        for(HColumnDescriptor colFamily : columnFamilies) {<a name="line.259"></a>
+<span class="sourceLineNo">260</span>          newcount += hrfs.getStoreFiles(colFamily.getName()).size();<a name="line.260"></a>
+<span class="sourceLineNo">261</span>        }<a name="line.261"></a>
+<span class="sourceLineNo">262</span>        if(newcount &gt; count) {<a name="line.262"></a>
+<span class="sourceLineNo">263</span>          break;<a name="line.263"></a>
+<span class="sourceLineNo">264</span>        }<a name="line.264"></a>
+<span class="sourceLineNo">265</span>        Thread.sleep(50);<a name="line.265"></a>
+<span class="sourceLineNo">266</span>      }<a name="line.266"></a>
+<span class="sourceLineNo">267</span>      assertTrue(newcount &gt; count);<a name="line.267"></a>
+<span class="sourceLineNo">268</span>      List&lt;RegionServerThread&gt; regionServerThreads = TEST_UTIL.getHBaseCluster()<a name="line.268"></a>
+<span class="sourceLineNo">269</span>          .getRegionServerThreads();<a name="line.269"></a>
+<span class="sourceLineNo">270</span>      for (RegionServerThread rs : regionServerThreads) {<a name="line.270"></a>
+<span class="sourceLineNo">271</span>        CompactedHFilesDischarger cleaner = new CompactedHFilesDischarger(100, null,<a name="line.271"></a>
+<span class="sourceLineNo">272</span>            rs.getRegionServer(), false);<a name="line.272"></a>
+<span class="sourceLineNo">273</span>        cleaner.chore();<a name="line.273"></a>
+<span class="sourceLineNo">274</span>        Thread.sleep(1000);<a name="line.274"></a>
+<span class="sourceLineNo">275</span>      }<a name="line.275"></a>
+<span class="sourceLineNo">276</span>      while (System.currentTimeMillis() &lt; timeout) {<a name="line.276"></a>
+<span class="sourceLineNo">277</span>        int newcount1 = 0;<a name="line.277"></a>
+<span class="sourceLineNo">278</span>        for(HColumnDescriptor colFamily : columnFamilies) {<a name="line.278"></a>
+<span class="sourceLineNo">279</span>          newcount1 += hrfs.getStoreFiles(colFamily.getName()).size();<a name="line.279"></a>
+<span class="sourceLineNo">280</span>        }<a name="line.280"></a>
+<span class="sourceLineNo">281</span>        if(newcount1 &lt;= 1) {<a name="line.281"></a>
+<span class="sourceLineNo">282</span>          break;<a name="line.282"></a>
+<span class="sourceLineNo">283</span>        }<a name="line.283"></a>
+<span class="sourceLineNo">284</span>        Thread.sleep(50);<a name="line.284"></a>
+<span class="sourceLineNo">285</span>      }<a name="line.285"></a>
+<span class="sourceLineNo">286</span>      // run CatalogJanitor to clean merge references in hbase:meta and archive the<a name="line.286"></a>
+<span class="sourceLineNo">287</span>      // files of merging regions<a name="line.287"></a>
+<span class="sourceLineNo">288</span>      int cleaned = 0;<a name="line.288"></a>
+<span class="sourceLineNo">289</span>      while (cleaned == 0) {<a name="line.289"></a>
+<span class="sourceLineNo">290</span>        cleaned = ADMIN.runCatalogScan();<a name="line.290"></a>
+<span class="sourceLineNo">291</span>        LOG.debug("catalog janitor returned " + cleaned);<a name="line.291"></a>
+<span class="sourceLineNo">292</span>        Thread.sleep(50);<a name="line.292"></a>
+<span class="sourceLineNo">293</span>      }<a name="line.293"></a>
+<span class="sourceLineNo">294</span>      assertFalse(regionAdir.toString(), fs.exists(regionAdir));<a name="line.294"></a>
+<span class="sourceLineNo">295</span>      assertFalse(regionBdir.toString(), fs.exists(regionBdir));<a name="line.295"></a>
+<span class="sourceLineNo">296</span>      assertTrue(cleaned &gt; 0);<a name="line.296"></a>
+<span class="sourceLineNo">297</span><a name="line.297"></a>
+<span class="sourceLineNo">298</span>      mergedRegionResult = MetaTableAccessor.getRegionResult(<a name="line.298"></a>
+<span class="sourceLineNo">299</span>        TEST_UTIL.getConnection(), mergedRegionInfo.getRegionName());<a name="line.299"></a>
+<span class="sourceLineNo">300</span>      assertFalse(mergedRegionResult.getValue(HConstants.CATALOG_FAMILY,<a name="line.300"></a>
+<span class="sourceLineNo">301</span>          HConstants.MERGEA_QUALIFIER) != null);<a name="line.301"></a>
+<span class="sourceLineNo">302</span>      assertFalse(mergedRegionResult.getValue(HConstants.CATALOG_FAMILY,<a name="line.302"></a>
+<span class="sourceLineNo">303</span>          HConstants.MERGEB_QUALIFIER) != null);<a name="line.303"></a>
+<span class="sourceLineNo">304</span><a name="line.304"></a>
+<span class="sourceLineNo">305</span>    } finally {<a name="line.305"></a>
+<span class="sourceLineNo">306</span>      ADMIN.enableCatalogJanitor(true);<a name="line.306"></a>
+<span class="sourceLineNo">307</span>    }<a name="line.307"></a>
+<span class="sourceLineNo">308</span>  }<a name="line.308"></a>
+<span class="sourceLineNo">309</span><a name="line.309"></a>
+<span class="sourceLineNo">310</span>  /**<a name="line.310"></a>
+<span class="sourceLineNo">311</span>   * This test tests 1, merging region not online;<a name="line.311"></a>
+<span class="sourceLineNo">312</span>   * 2, merging same two regions; 3, merging unknown regions.<a name="line.312"></a>
+<span class="sourceLineNo">313</span>   * They are in one test case so that we don't have to create<a name="line.313"></a>
+<span class="sourceLineNo">314</span>   * many tables, and these tests are simple.<a name="line.314"></a>
+<span class="sourceLineNo">315</span>   */<a name="line.315"></a>
+<span class="sourceLineNo">316</span>  @Test<a name="line.316"></a>
+<span class="sourceLineNo">317</span>  public void testMerge() throws Exception {<a name="line.317"></a>
+<span class="sourceLineNo">318</span>    LOG.info("Starting testMerge");<a name="line.318"></a>
+<span class="sourceLineNo">319</span>    final TableName tableName = TableName.valueOf("testMerge");<a name="line.319"></a>
+<span class="sourceLineNo">320</span><a name="line.320"></a>
+<span class="sourceLineNo">321</span>    try {<a name="line.321"></a>
+<span class="sourceLineNo">322</span>      // Create table and load data.<a name="line.322"></a>
+<span class="sourceLineNo">323</span>      Table table = createTableAndLoadData(MASTER, tableName);<a name="line.323"></a>
+<span class="sourceLineNo">324</span>      RegionStates regionStates = MASTER.getAssignmentManager().getRegionStates();<a name="line.324"></a>
+<span class="sourceLineNo">325</span>      List&lt;HRegionInfo&gt; regions = regionStates.getRegionsOfTable(tableName);<a name="line.325"></a>
+<span class="sourceLineNo">326</span>      // Fake offline one region<a name="line.326"></a>
+<span class="sourceLineNo">327</span>      HRegionInfo a = regions.get(0);<a name="line.327"></a>
+<span class="sourceLineNo">328</span>      HRegionInfo b = regions.get(1);<a name="line.328"></a>
+<span class="sourceLineNo">329</span>      regionStates.regionOffline(a);<a name="line.329"></a>
+<span class="sourceLineNo">330</span>      try {<a name="line.330"></a>
+<span class="sourceLineNo">331</span>        // Merge offline region. Region a is offline here<a name="line.331"></a>
+<span class="sourceLineNo">332</span>        ADMIN.mergeRegions(a.getEncodedNameAsBytes(), b.getEncodedNameAsBytes(), false);<a name="line.332"></a>
+<span class="sourceLineNo">333</span>        fail("Offline regions should not be able to merge");<a name="line.333"></a>
+<span class="sourceLineNo">334</span>      } catch (IOException ie) {<a name="line.334"></a>
+<span class="sourceLineNo">335</span>        System.out.println(ie);<a name="line.335"></a>
+<span class="sourceLineNo">336</span>        assertTrue("Exception should mention regions not online",<a name="line.336"></a>
+<span class="sourceLineNo">337</span>          StringUtils.stringifyException(ie).contains("regions not online")<a name="line.337"></a>
+<span class="sourceLineNo">338</span>            &amp;&amp; ie instanceof MergeRegionException);<a name="line.338"></a>
+<span class="sourceLineNo">339</span>      }<a name="line.339"></a>
+<span class="sourceLineNo">340</span>      try {<a name="line.340"></a>
+<span class="sourceLineNo">341</span>        // Merge the same region: b and b.<a name="line.341"></a>
+<span class="sourceLineNo">342</span>        ADMIN.mergeRegions(b.getEncodedNameAsBytes(), b.getEncodedNameAsBytes(), true);<a name="line.342"></a>
+<span class="sourceLineNo">343</span>        fail("A region should not be able to merge with itself, even forcifully");<a name="line.343"></a>
+<span class="sourceLineNo">344</span>      } catch (IOException ie) {<a name="line.344"></a>
+<span class="sourceLineNo">345</span>        assertTrue("Exception should mention regions not online",<a name="line.345"></a>
+<span class="sourceLineNo">346</span>          StringUtils.stringifyException(ie).contains("region to itself")<a name="line.346"></a>
+<span class="sourceLineNo">347</span>            &amp;&amp; ie instanceof MergeRegionException);<a name="line.347"></a>
+<span class="sourceLineNo">348</span>      }<a name="line.348"></a>
+<span class="sourceLineNo">349</span>      try {<a name="line.349"></a>
+<span class="sourceLineNo">350</span>        // Merge unknown regions<a name="line.350"></a>
+<span class="sourceLineNo">351</span>        ADMIN.mergeRegions(Bytes.toBytes("-f1"), Bytes.toBytes("-f2"), true);<a name="line.351"></a>
+<span class="sourceLineNo">352</span>        fail("Unknown region could not be merged");<a name="line.352"></a>
+<span class="sourceLineNo">353</span>      } catch (IOException ie) {<a name="line.353"></a>
+<span class="sourceLineNo">354</span>        assertTrue("UnknownRegionException should be thrown",<a name="line.354"></a>
+<span class="sourceLineNo">355</span>          ie instanceof UnknownRegionException);<a name="line.355"></a>
+<span class="sourceLineNo">356</span>      }<a name="line.356"></a>
+<span class="sourceLineNo">357</span>      table.close();<a name="line.357"></a>
+<span class="sourceLineNo">358</span>    } finally {<a name="line.358"></a>
+<span class="sourceLineNo">359</span>      TEST_UTIL.deleteTable(tableName);<a name="line.359"></a>
+<span class="sourceLineNo">360</span>    }<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>  @Test<a name="line.363"></a>
+<span class="sourceLineNo">364</span>  public void testMergeWithReplicas() throws Exception {<a name="line.364"></a>
+<span class="sourceLineNo">365</span>    final TableName tableName = TableName.valueOf("testMergeWithReplicas");<a name="line.365"></a>
+<span class="sourceLineNo">366</span>    // Create table and load data.<a name="line.366"></a>
+<span class="sourceLineNo">367</span>    createTableAndLoadData(MASTER, tableName, 5, 2);<a name="line.367"></a>
+<span class="sourceLineNo">368</span>    List&lt;Pair&lt;HRegionInfo, ServerName&gt;&gt; initialRegionToServers =<a name="line.368"></a>
+<span class="sourceLineNo">369</span>        MetaTableAccessor.getTableRegionsAndLocations(<a name="line.369"></a>
+<span class="sourceLineNo">370</span>            TEST_UTIL.getConnection(), tableName);<a name="line.370"></a>
+<span class="sourceLineNo">371</span>    // Merge 1st and 2nd region<a name="line.371"></a>
+<span class="sourceLineNo">372</span>    PairOfSameType&lt;HRegionInfo&gt; mergedRegions = mergeRegionsAndVerifyRegionNum(MASTER, tableName,<a name="line.372"></a>
+<span class="sourceLineNo">373</span>        0, 2, 5 * 2 - 2);<a name="line.373"></a>
+<span class="sourceLineNo">374</span>    List&lt;Pair&lt;HRegionInfo, ServerName&gt;&gt; currentRegionToServers =<a name="line.374"></a>
+<span class="sourceLineNo">375</span>        MetaTableAccessor.getTableRegionsAndLocations(<a name="line.375"></a>
+<span class="sourceLineNo">376</span>            TEST_UTIL.getConnection(), tableName);<a name="line.376"></a>
+<span class="sourceLineNo">377</span>    List&lt;HRegionInfo&gt; initialRegions = new ArrayList&lt;HRegionInfo&gt;();<a name="line.377"></a>
+<span class="sourceLineNo">378</span>    for (Pair&lt;HRegionInfo, ServerName&gt; p : initialRegionToServers) {<a name="line.378"></a>
+<span class="sourceLineNo">379</span>      initialRegions.add(p.getFirst());<a name="line.379"></a>
+<span class="sourceLineNo">380</span>    }<a name="line.380"></a>
+<span class="sourceLineNo">381</span>    List&lt;HRegionInfo&gt; currentRegions = new ArrayList&lt;HRegionInfo&gt;();<a name="line.381"></a>
+<span class="sourceLineNo">382</span>    for (Pair&lt;HRegionInfo, ServerName&gt; p : currentRegionToServers) {<a name="line.382"></a>
+<span class="sourceLineNo">383</span>      currentRegions.add(p.getFirst());<a name="line.383"></a>
+<span class="sourceLineNo">384</span>    }<a name="line.384"></a>
+<span class="sourceLineNo">385</span>    assertTrue(initialRegions.contains(mergedRegions.getFirst())); //this is the first region<a name="line.385"></a>
+<span class="sourceLineNo">386</span>    assertTrue(initialRegions.contains(RegionReplicaUtil.getRegionInfoForReplica(<a name="line.386"></a>
+<span class="sourceLineNo">387</span>        mergedRegions.getFirst(), 1))); //this is the replica of the first region<a name="line.387"></a>
+<span class="sourceLineNo">388</span>    assertTrue(initialRegions.contains(mergedRegions.getSecond())); //this is the second region<a name="line.388"></a>
+<span class="sourceLineNo">389</span>    assertTrue(initialRegions.contains(RegionReplicaUtil.getRegionInfoForReplica(<a name="line.389"></a>
+<span class="sourceLineNo">390</span>        mergedRegions.getSecond(), 1))); //this is the replica of the second region<a name="line.390"></a>
+<span class="sourceLineNo">391</span>    assertTrue(!initialRegions.contains(currentRegions.get(0))); //this is the new region<a name="line.391"></a>
+<span class="sourceLineNo">392</span>    assertTrue(!initialRegions.contains(RegionReplicaUtil.getRegionInfoForReplica(<a name="line.392"></a>
+<span class="sourceLineNo">393</span>        currentRegions.get(0), 1))); //replica of the new region<a name="line.393"></a>
+<span class="sourceLineNo">394</span>    assertTrue(currentRegions.contains(RegionReplicaUtil.getRegionInfoForReplica(<a name="line.394"></a>
+<span class="sourceLineNo">395</span>        currentRegions.get(0), 1))); //replica of the new region<a name="line.395"></a>
+<span class="sourceLineNo">396</span>    assertTrue(!currentRegions.contains(RegionReplicaUtil.getRegionInfoForReplica(<a name="line.396"></a>
+<span class="sourceLineNo">397</span>        mergedRegions.getFirst(), 1))); //replica of the merged region<a name="line.397"></a>
+<span class="sourceLineNo">398</span>    assertTrue(!currentRegions.contains(RegionReplicaUtil.getRegionInfoForReplica(<a name="line.398"></a>
+<span class="sourceLineNo">399</span>        mergedRegions.getSecond(), 1))); //replica of the merged region<a name="line.399"></a>
+<span class="sourceLineNo">400</span>  }<a name="line.400"></a>
+<span class="sourceLineNo">401</span><a name="line.401"></a>
+<span class="sourceLineNo">402</span>  private PairOfSameType&lt;HRegionInfo&gt; mergeRegionsAndVerifyRegionNum(<a name="line.402"></a>
+<span class="sourceLineNo">403</span>      HMaster master, TableName tablename,<a name="line.403"></a>
+<span class="sourceLineNo">404</span>      int regionAnum, int regionBnum, int expectedRegionNum) throws Exception {<a name="line.404"></a>
+<span class="sourceLineNo">405</span>    PairOfSameType&lt;HRegionInfo&gt; mergedRegions =<a name="line.405"></a>
+<span class="sourceLineNo">406</span>      requestMergeRegion(master, tablename, regionAnum, regionBnum);<a name="line.406"></a>
+<span class="sourceLineNo">407</span>    waitAndVerifyRegionNum(master, tablename, expectedRegionNum);<a name="line.407"></a>
+<span class="sourceLineNo">408</span>    return mergedRegions;<a name="line.408"></a>
+<span class="sourceLineNo">409</span>  }<a name="line.409"></a>
+<span class="sourceLineNo">410</span><a name="line.410"></a>
+<span class="sourceLineNo">411</span>  private PairOfSameType&lt;HRegionInfo&gt; requestMergeRegion(<a name="line.411"></a>
+<span class="sourceLineNo">412</span>      HMaster master, TableName tablename,<a name="line.412"></a>
+<span class="sourceLineNo">413</span>      int regionAnum, int regionBnum) throws Exception {<a name="line.413"></a>
+<span class="sourceLineNo">414</span>    List&lt;Pair&lt;HRegionInfo, ServerName&gt;&gt; tableRegions = MetaTableAccessor<a name="line.414"></a>
+<span class="sourceLineNo">415</span>        .getTableRegionsAndLocations(<a name="line.415"></a>
+<span class="sourceLineNo">416</span>            TEST_UTIL.getConnection(), tablename);<a name="line.416"></a>
+<span class="sourceLineNo">417</span>    HRegionInfo regionA = tableRegions.get(regionAnum).getFirst();<a name="line.417"></a>
+<span class="sourceLineNo">418</span>    HRegionInfo regionB = tableRegions.get(regionBnum).getFirst();<a name="line.418"></a>
+<span class="sourceLineNo">419</span>    ADMIN.mergeRegions(<a name="line.419"></a>
+<span class="sourceLineNo">420</span>      regionA.getEncodedNameAsBytes(),<a name="line.420"></a>
+<span class="sourceLineNo">421</span>      regionB.getEncodedNameAsBytes(), false);<a name="line.421"></a>
+<span class="sourceLineNo">422</span>    return new PairOfSameType&lt;HRegionInfo&gt;(regionA, regionB);<a name="line.422"></a>
+<span class="sourceLineNo">423</span>  }<a name="line.423"></a>
+<span class="sourceLineNo">424</span><a name="line.424"></a>
+<span class="sourceLineNo">425</span>  private void waitAndVerifyRegionNum(HMaster master, TableName tablename,<a name="line.425"></a>
+<span class="sourceLineNo">426</span>      int expectedRegionNum) throws Exception {<a name="line.426"></a>
+<span class="sourceLineNo">427</span>    List&lt;Pair&lt;HRegionInfo, ServerName&gt;&gt; tableRegionsInMeta;<a name="line.427"></a>
+<span class="sourceLineNo">428</span>    List&lt;HRegionInfo&gt; tableRegionsInMaster;<a name="line.428"></a>
+<span class="sourceLineNo">429</span>    long timeout = System.currentTimeMillis() + waitTime;<a name="line.429"></a>
+<span class="sourceLineNo">430</span>    while (System.currentTimeMillis() &lt; timeout) {<a name="line.430"></a>
+<span class="sourceLineNo">431</span>      tableRegionsInMeta = MetaTableAccessor.getTableRegionsAndLocations(<a name="line.431"></a>
+<span class="sourceLineNo">432</span>        TEST_UTIL.getConnection(), tablename);<a name="line.432"></a>
+<span class="sourceLineNo">433</span>      tableRegionsInMaster = master.getAssignmentManager().getRegionStates()<a name="line.433"></a>
+<span class="sourceLineNo">434</span>          .getRegionsOfTable(tablename);<a name="line.434"></a>
+<span class="sourceLineNo">435</span>      if (tableRegionsInMeta.size() == expectedRegionNum<a name="line.435"></a>
+<span class="sourceLineNo">436</span>          &amp;&amp; tableRegionsInMaster.size() == expectedRegionNum) {<a name="line.436"></a>
+<span class="sourceLineNo">437</span>        break;<a name="line.437"></a>
+<span class="sourceLineNo">438</span>      }<a name="line.438"></a>
+<span class="sourceLineNo">439</span>      Thread.sleep(250);<a name="line.439"></a>
+<span class="sourceLineNo">440</span>    }<a name="line.440"></a>
+<span class="sourceLineNo">441</span><a name="line.441"></a>
+<span class="sourceLineNo">442</span>    tableRegionsInMeta = MetaTableAccessor.getTableRegionsAndLocations(<a name="line.442"></a>
+<span class="sourceLineNo">443</span>        TEST_UTIL.getConnection(), tablename);<a name="line.443"></a>
+<span class="sourceLineNo">444</span>    LOG.info("Regions after merge:" + Joiner.on(',').join(tableRegionsInMeta));<a name="line.444"></a>
+<span class="sourceLineNo">445</span>    assertEquals(expectedRegionNum, tableRegionsInMeta.size());<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 Table createTableAndLoadData(HMaster master, TableName tablename)<a name="line.448"></a>
+<span class="sourceLineNo">449</span>      throws Exception {<a name="line.449"></a>
+<span class="sourceLineNo">450</span>    return createTableAndLoadData(master, tablename, INITIAL_REGION_NUM, 1);<a name="line.450"></a>
+<span class="sourceLineNo">451</span>  }<a name="line.451"></a>
+<span class="sourceLineNo">452</span><a name="line.452"></a>
+<span class="sourceLineNo">453</span>  private Table createTableAndLoadData(HMaster master, TableName tablename,<a name="line.453"></a>
+<span class="sourceLineNo">454</span>      int numRegions, int replication) throws Exception {<a name="line.454"></a>
+<span class="sourceLineNo">455</span>    assertTrue("ROWSIZE must &gt; numregions:" + numRegions, ROWSIZE &gt; numRegions);<a name="line.455"></a>
+<span class="sourceLineNo">456</span>    byte[][] splitRows = new byte[numRegions - 1][];<a name="line.456"></a>
+<span class="sourceLineNo">457</span>    for (int i = 0; i &lt; splitRows.length; i++) {<a name="line.457"></a>
+<span class="sourceLineNo">458</span>      splitRows[i] = ROWS[(i + 1) * ROWSIZE / numRegions];<a name="line.458"></a>
+<span class="sourceLineNo">459</span>    }<a name="line.459"></a>
+<span class="sourceLineNo">460</span><a name="line.460"></a>
+<span class="sourceLineNo">461</span>    Table table = TEST_UTIL.createTable(tablename, FAMILYNAME, splitRows);<a name="line.461"></a>
+<span class="sourceLineNo">462</span>    LOG.info("Created " + table.getName());<a name="line.462"></a>
+<span class="sourceLineNo">463</span>    if (replication &gt; 1) {<a name="line.463"></a>
+<span class="sourceLineNo">464</span>      HBaseTestingUtility.setReplicas(ADMIN, tablename, replication);<a name="line.464"></a>
+<span class="sourceLineNo">465</span>      LOG.info("Set replication of " + replication + " on " + table.getName());<a name="line.465"></a>
+<span class="sourceLineNo">466</span>    }<a name="line.466"></a>
+<span class="sourceLineNo">467</span>    loadData(table);<a name="line.467"></a>
+<span class="sourceLineNo">468</span>    LOG.info("Loaded " + table.getName());<a name="line.468"></a>
+<span class="sourceLineNo">469</span>    verifyRowCount(table, ROWSIZE);<a name="line.469"></a>
+<span class="sourceLineNo">470</span>    LOG.info("Verified " + table.getName());<a name="line.470"></a>
+<span class="sourceLineNo">471</span><a name="line.471"></a>
+<span class="sourceLineNo">472</span>    // sleep here is an ugly hack to allow region transitions to finish<a name="line.472"></a>
+<span class="sourceLineNo">473</span>    long timeout = System.currentTimeMillis() + waitTime;<a name="line.473"></a>
+<span class="sourceLineNo">474</span>    List&lt;Pair&lt;HRegionInfo, ServerName&gt;&gt; tableRegions;<a name="line.474"></a>
+<span class="sourceLineNo">475</span>    while (System.currentTimeMillis() &lt; timeout) {<a name="line.475"></a>
+<span class="sourceLineNo">476</span>      tableRegions = MetaTableAccessor.getTableRegionsAndLocations(<a name="line.476"></a>
+<span class="sourceLineNo">477</span>          TEST_UTIL.getConnection(), tablename);<a name="line.477"></a>
+<span class="sourceLineNo">478</span>      if (tableRegions.size() == numRegions * replication)<a name="line.478"></a>
+<span class="sourceLineNo">479</span>        break;<a name="line.479"></a>
+<span class="sourceLineNo">480</span>      Thread.sleep(250);<a name="line.480"></a>
+<span class="sourceLineNo">481</span>    }<a name="line.481"></a>
+<span class="sourceLineNo">482</span>    LOG.info("Getting regions of " + table.getName());<a name="line.482"></a>
+<span class="sourceLineNo">483</span>    tableRegions = MetaTableAccessor.getTableRegionsAndLocations(<a name="line.483"></a>
+<span class="sourceLineNo">484</span>        TEST_UTIL.getConnection(), tablename);<a name="line.484"></a>
+<span class="sourceLineNo">485</span>    LOG.info("Regions after load: " + Joiner.on(',').join(tableRegions));<a name="line.485"></a>
+<span class="sourceLineNo">486</span>    assertEquals(numRegions * replication, tableRegions.size());<a name="line.486"></a>
+<span class="sourceLineNo">487</span>    return table;<a name="line.487"></a>
+<span class="sourceLineNo">488</span>  }<a name="line.488"></a>
+<span class="sourceLineNo">489</span><a name="line.489"></a>
+<span class="sourceLineNo">490</span>  private static byte[][] makeN(byte[] base, int n) {<a name="line.490"></a>
+<span class="sourceLineNo">491</span>    byte[][] ret = new byte[n][];<a name="line.491"></a>
+<span class="sourceLineNo">492</span>    for (int i = 0; i &lt; n; i++) {<a name="line.492"></a>
+<span class="sourceLineNo">493</span>      ret[i] = Bytes.add(base, Bytes.toBytes(String.format("%04d", i)));<a name="line.493"></a>
+<span class="sourceLineNo">494</span>    }<a name="line.494"></a>
+<span class="sourceLineNo">495</span>    return ret;<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>  private void loadData(Table table) throws IOException {<a name="line.498"></a>
+<span class="sourceLineNo">499</span>    for (int i = 0; i &lt; ROWSIZE; i++) {<a name="line.499"></a>
+<span class="sourceLineNo">500</span>      Put put = new Put(ROWS[i]);<a name="line.500"></a>
+<span class="sourc

<TRUNCATED>

Mime
View raw message