Repository: hbase-site Updated Branches: refs/heads/asf-site 5f66dfcf3 -> 473b2db23
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/473b2db2/testdevapidocs/src-html/org/apache/hadoop/hbase/master/TestAssignmentManagerMetrics.html ---------------------------------------------------------------------- diff --git a/testdevapidocs/src-html/org/apache/hadoop/hbase/master/TestAssignmentManagerMetrics.html b/testdevapidocs/src-html/org/apache/hadoop/hbase/master/TestAssignmentManagerMetrics.html index 90c268c..64adee1 100644 --- a/testdevapidocs/src-html/org/apache/hadoop/hbase/master/TestAssignmentManagerMetrics.html +++ b/testdevapidocs/src-html/org/apache/hadoop/hbase/master/TestAssignmentManagerMetrics.html @@ -40,36 +40,36 @@ <span class="sourceLineNo">032</span>import org.apache.hadoop.hbase.client.Table;<a name="line.32"></a> <span class="sourceLineNo">033</span>import org.apache.hadoop.hbase.client.TableDescriptor;<a name="line.33"></a> <span class="sourceLineNo">034</span>import org.apache.hadoop.hbase.client.TableDescriptorBuilder;<a name="line.34"></a> -<span class="sourceLineNo">035</span>import org.apache.hadoop.hbase.test.MetricsAssertHelper;<a name="line.35"></a> -<span class="sourceLineNo">036</span>import org.apache.hadoop.hbase.testclassification.MasterTests;<a name="line.36"></a> -<span class="sourceLineNo">037</span>import org.apache.hadoop.hbase.testclassification.MediumTests;<a name="line.37"></a> -<span class="sourceLineNo">038</span>import org.apache.hadoop.hbase.util.Bytes;<a name="line.38"></a> -<span class="sourceLineNo">039</span>import org.junit.AfterClass;<a name="line.39"></a> -<span class="sourceLineNo">040</span>import org.junit.BeforeClass;<a name="line.40"></a> -<span class="sourceLineNo">041</span>import org.junit.ClassRule;<a name="line.41"></a> -<span class="sourceLineNo">042</span>import org.junit.Rule;<a name="line.42"></a> -<span class="sourceLineNo">043</span>import org.junit.Test;<a name="line.43"></a> -<span class="sourceLineNo">044</span>import org.junit.experimental.categories.Category;<a name="line.44"></a> -<span class="sourceLineNo">045</span>import org.junit.rules.TestName;<a name="line.45"></a> -<span class="sourceLineNo">046</span>import org.slf4j.Logger;<a name="line.46"></a> -<span class="sourceLineNo">047</span>import org.slf4j.LoggerFactory;<a name="line.47"></a> -<span class="sourceLineNo">048</span><a name="line.48"></a> -<span class="sourceLineNo">049</span>@Category({ MasterTests.class, MediumTests.class })<a name="line.49"></a> -<span class="sourceLineNo">050</span>public class TestAssignmentManagerMetrics {<a name="line.50"></a> -<span class="sourceLineNo">051</span><a name="line.51"></a> -<span class="sourceLineNo">052</span> @ClassRule<a name="line.52"></a> -<span class="sourceLineNo">053</span> public static final HBaseClassTestRule CLASS_RULE =<a name="line.53"></a> -<span class="sourceLineNo">054</span> HBaseClassTestRule.forClass(TestAssignmentManagerMetrics.class);<a name="line.54"></a> -<span class="sourceLineNo">055</span><a name="line.55"></a> -<span class="sourceLineNo">056</span> private static final Logger LOG = LoggerFactory.getLogger(TestAssignmentManagerMetrics.class);<a name="line.56"></a> -<span class="sourceLineNo">057</span> private static final MetricsAssertHelper metricsHelper = CompatibilityFactory<a name="line.57"></a> -<span class="sourceLineNo">058</span> .getInstance(MetricsAssertHelper.class);<a name="line.58"></a> -<span class="sourceLineNo">059</span><a name="line.59"></a> -<span class="sourceLineNo">060</span> private static MiniHBaseCluster cluster;<a name="line.60"></a> -<span class="sourceLineNo">061</span> private static HMaster master;<a name="line.61"></a> -<span class="sourceLineNo">062</span> private static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();<a name="line.62"></a> -<span class="sourceLineNo">063</span> private static Configuration conf;<a name="line.63"></a> -<span class="sourceLineNo">064</span> private static final int msgInterval = 1000;<a name="line.64"></a> +<span class="sourceLineNo">035</span>import org.apache.hadoop.hbase.master.assignment.AssignmentManager;<a name="line.35"></a> +<span class="sourceLineNo">036</span>import org.apache.hadoop.hbase.test.MetricsAssertHelper;<a name="line.36"></a> +<span class="sourceLineNo">037</span>import org.apache.hadoop.hbase.testclassification.MasterTests;<a name="line.37"></a> +<span class="sourceLineNo">038</span>import org.apache.hadoop.hbase.testclassification.MediumTests;<a name="line.38"></a> +<span class="sourceLineNo">039</span>import org.apache.hadoop.hbase.util.Bytes;<a name="line.39"></a> +<span class="sourceLineNo">040</span>import org.junit.AfterClass;<a name="line.40"></a> +<span class="sourceLineNo">041</span>import org.junit.BeforeClass;<a name="line.41"></a> +<span class="sourceLineNo">042</span>import org.junit.ClassRule;<a name="line.42"></a> +<span class="sourceLineNo">043</span>import org.junit.Rule;<a name="line.43"></a> +<span class="sourceLineNo">044</span>import org.junit.Test;<a name="line.44"></a> +<span class="sourceLineNo">045</span>import org.junit.experimental.categories.Category;<a name="line.45"></a> +<span class="sourceLineNo">046</span>import org.junit.rules.TestName;<a name="line.46"></a> +<span class="sourceLineNo">047</span>import org.slf4j.Logger;<a name="line.47"></a> +<span class="sourceLineNo">048</span>import org.slf4j.LoggerFactory;<a name="line.48"></a> +<span class="sourceLineNo">049</span><a name="line.49"></a> +<span class="sourceLineNo">050</span>@Category({ MasterTests.class, MediumTests.class })<a name="line.50"></a> +<span class="sourceLineNo">051</span>public class TestAssignmentManagerMetrics {<a name="line.51"></a> +<span class="sourceLineNo">052</span><a name="line.52"></a> +<span class="sourceLineNo">053</span> @ClassRule<a name="line.53"></a> +<span class="sourceLineNo">054</span> public static final HBaseClassTestRule CLASS_RULE =<a name="line.54"></a> +<span class="sourceLineNo">055</span> HBaseClassTestRule.forClass(TestAssignmentManagerMetrics.class);<a name="line.55"></a> +<span class="sourceLineNo">056</span><a name="line.56"></a> +<span class="sourceLineNo">057</span> private static final Logger LOG = LoggerFactory.getLogger(TestAssignmentManagerMetrics.class);<a name="line.57"></a> +<span class="sourceLineNo">058</span> private static final MetricsAssertHelper METRICS_HELPER = CompatibilityFactory<a name="line.58"></a> +<span class="sourceLineNo">059</span> .getInstance(MetricsAssertHelper.class);<a name="line.59"></a> +<span class="sourceLineNo">060</span><a name="line.60"></a> +<span class="sourceLineNo">061</span> private static MiniHBaseCluster CLUSTER;<a name="line.61"></a> +<span class="sourceLineNo">062</span> private static HMaster MASTER;<a name="line.62"></a> +<span class="sourceLineNo">063</span> private static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();<a name="line.63"></a> +<span class="sourceLineNo">064</span> private static final int MSG_INTERVAL = 1000;<a name="line.64"></a> <span class="sourceLineNo">065</span><a name="line.65"></a> <span class="sourceLineNo">066</span> @Rule<a name="line.66"></a> <span class="sourceLineNo">067</span> public TestName name = new TestName();<a name="line.67"></a> @@ -77,7 +77,7 @@ <span class="sourceLineNo">069</span> @BeforeClass<a name="line.69"></a> <span class="sourceLineNo">070</span> public static void startCluster() throws Exception {<a name="line.70"></a> <span class="sourceLineNo">071</span> LOG.info("Starting cluster");<a name="line.71"></a> -<span class="sourceLineNo">072</span> conf = TEST_UTIL.getConfiguration();<a name="line.72"></a> +<span class="sourceLineNo">072</span> Configuration conf = TEST_UTIL.getConfiguration();<a name="line.72"></a> <span class="sourceLineNo">073</span><a name="line.73"></a> <span class="sourceLineNo">074</span> // Disable sanity check for coprocessor<a name="line.74"></a> <span class="sourceLineNo">075</span> conf.setBoolean("hbase.table.sanity.checks", false);<a name="line.75"></a> @@ -86,74 +86,76 @@ <span class="sourceLineNo">078</span> conf.setInt(HConstants.METRICS_RIT_STUCK_WARNING_THRESHOLD, 20);<a name="line.78"></a> <span class="sourceLineNo">079</span><a name="line.79"></a> <span class="sourceLineNo">080</span> // set msgInterval to 1 second<a name="line.80"></a> -<span class="sourceLineNo">081</span> conf.setInt("hbase.regionserver.msginterval", msgInterval);<a name="line.81"></a> +<span class="sourceLineNo">081</span> conf.setInt("hbase.regionserver.msginterval", MSG_INTERVAL);<a name="line.81"></a> <span class="sourceLineNo">082</span><a name="line.82"></a> <span class="sourceLineNo">083</span> // set tablesOnMaster to none<a name="line.83"></a> <span class="sourceLineNo">084</span> conf.set("hbase.balancer.tablesOnMaster", "none");<a name="line.84"></a> <span class="sourceLineNo">085</span><a name="line.85"></a> <span class="sourceLineNo">086</span> // set client sync wait timeout to 5sec<a name="line.86"></a> -<span class="sourceLineNo">087</span> conf.setInt("hbase.client.sync.wait.timeout.msec", 2500);<a name="line.87"></a> +<span class="sourceLineNo">087</span> conf.setInt("hbase.client.sync.wait.timeout.msec", 5000);<a name="line.87"></a> <span class="sourceLineNo">088</span> conf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1);<a name="line.88"></a> <span class="sourceLineNo">089</span> conf.setInt(HConstants.HBASE_CLIENT_OPERATION_TIMEOUT, 2500);<a name="line.89"></a> -<span class="sourceLineNo">090</span><a name="line.90"></a> -<span class="sourceLineNo">091</span> TEST_UTIL.startMiniCluster(1);<a name="line.91"></a> -<span class="sourceLineNo">092</span> cluster = TEST_UTIL.getHBaseCluster();<a name="line.92"></a> -<span class="sourceLineNo">093</span> master = cluster.getMaster();<a name="line.93"></a> -<span class="sourceLineNo">094</span> }<a name="line.94"></a> -<span class="sourceLineNo">095</span><a name="line.95"></a> -<span class="sourceLineNo">096</span> @AfterClass<a name="line.96"></a> -<span class="sourceLineNo">097</span> public static void after() throws Exception {<a name="line.97"></a> -<span class="sourceLineNo">098</span> TEST_UTIL.shutdownMiniCluster();<a name="line.98"></a> -<span class="sourceLineNo">099</span> }<a name="line.99"></a> -<span class="sourceLineNo">100</span><a name="line.100"></a> -<span class="sourceLineNo">101</span> @Test<a name="line.101"></a> -<span class="sourceLineNo">102</span> public void testRITAssignmentManagerMetrics() throws Exception {<a name="line.102"></a> -<span class="sourceLineNo">103</span> final TableName TABLENAME = TableName.valueOf(name.getMethodName());<a name="line.103"></a> -<span class="sourceLineNo">104</span> final byte[] FAMILY = Bytes.toBytes("family");<a name="line.104"></a> -<span class="sourceLineNo">105</span> try (Table table = TEST_UTIL.createTable(TABLENAME, FAMILY)){<a name="line.105"></a> -<span class="sourceLineNo">106</span> final byte[] row = Bytes.toBytes("row");<a name="line.106"></a> -<span class="sourceLineNo">107</span> final byte[] qualifier = Bytes.toBytes("qualifier");<a name="line.107"></a> -<span class="sourceLineNo">108</span> final byte[] value = Bytes.toBytes("value");<a name="line.108"></a> -<span class="sourceLineNo">109</span><a name="line.109"></a> -<span class="sourceLineNo">110</span> Put put = new Put(row);<a name="line.110"></a> -<span class="sourceLineNo">111</span> put.addColumn(FAMILY, qualifier, value);<a name="line.111"></a> -<span class="sourceLineNo">112</span> table.put(put);<a name="line.112"></a> -<span class="sourceLineNo">113</span><a name="line.113"></a> -<span class="sourceLineNo">114</span> // Sleep 3 seconds, wait for doMetrics chore catching up<a name="line.114"></a> -<span class="sourceLineNo">115</span> Thread.sleep(msgInterval * 3);<a name="line.115"></a> -<span class="sourceLineNo">116</span><a name="line.116"></a> -<span class="sourceLineNo">117</span> // check the RIT is 0<a name="line.117"></a> -<span class="sourceLineNo">118</span> MetricsAssignmentManagerSource amSource =<a name="line.118"></a> -<span class="sourceLineNo">119</span> master.getAssignmentManager().getAssignmentManagerMetrics().getMetricsProcSource();<a name="line.119"></a> -<span class="sourceLineNo">120</span><a name="line.120"></a> -<span class="sourceLineNo">121</span> metricsHelper.assertGauge(MetricsAssignmentManagerSource.RIT_COUNT_NAME, 0, amSource);<a name="line.121"></a> -<span class="sourceLineNo">122</span> metricsHelper.assertGauge(MetricsAssignmentManagerSource.RIT_COUNT_OVER_THRESHOLD_NAME, 0,<a name="line.122"></a> -<span class="sourceLineNo">123</span> amSource);<a name="line.123"></a> -<span class="sourceLineNo">124</span><a name="line.124"></a> -<span class="sourceLineNo">125</span> // alter table with a non-existing coprocessor<a name="line.125"></a> +<span class="sourceLineNo">090</span> // set a small interval for updating rit metrics<a name="line.90"></a> +<span class="sourceLineNo">091</span> conf.setInt(AssignmentManager.RIT_CHORE_INTERVAL_MSEC_CONF_KEY, MSG_INTERVAL);<a name="line.91"></a> +<span class="sourceLineNo">092</span><a name="line.92"></a> +<span class="sourceLineNo">093</span> TEST_UTIL.startMiniCluster(1);<a name="line.93"></a> +<span class="sourceLineNo">094</span> CLUSTER = TEST_UTIL.getHBaseCluster();<a name="line.94"></a> +<span class="sourceLineNo">095</span> MASTER = CLUSTER.getMaster();<a name="line.95"></a> +<span class="sourceLineNo">096</span> }<a name="line.96"></a> +<span class="sourceLineNo">097</span><a name="line.97"></a> +<span class="sourceLineNo">098</span> @AfterClass<a name="line.98"></a> +<span class="sourceLineNo">099</span> public static void after() throws Exception {<a name="line.99"></a> +<span class="sourceLineNo">100</span> TEST_UTIL.shutdownMiniCluster();<a name="line.100"></a> +<span class="sourceLineNo">101</span> }<a name="line.101"></a> +<span class="sourceLineNo">102</span><a name="line.102"></a> +<span class="sourceLineNo">103</span> @Test<a name="line.103"></a> +<span class="sourceLineNo">104</span> public void testRITAssignmentManagerMetrics() throws Exception {<a name="line.104"></a> +<span class="sourceLineNo">105</span> final TableName TABLENAME = TableName.valueOf(name.getMethodName());<a name="line.105"></a> +<span class="sourceLineNo">106</span> final byte[] FAMILY = Bytes.toBytes("family");<a name="line.106"></a> +<span class="sourceLineNo">107</span> try (Table table = TEST_UTIL.createTable(TABLENAME, FAMILY)){<a name="line.107"></a> +<span class="sourceLineNo">108</span> final byte[] row = Bytes.toBytes("row");<a name="line.108"></a> +<span class="sourceLineNo">109</span> final byte[] qualifier = Bytes.toBytes("qualifier");<a name="line.109"></a> +<span class="sourceLineNo">110</span> final byte[] value = Bytes.toBytes("value");<a name="line.110"></a> +<span class="sourceLineNo">111</span><a name="line.111"></a> +<span class="sourceLineNo">112</span> Put put = new Put(row);<a name="line.112"></a> +<span class="sourceLineNo">113</span> put.addColumn(FAMILY, qualifier, value);<a name="line.113"></a> +<span class="sourceLineNo">114</span> table.put(put);<a name="line.114"></a> +<span class="sourceLineNo">115</span><a name="line.115"></a> +<span class="sourceLineNo">116</span> // Sleep 3 seconds, wait for doMetrics chore catching up<a name="line.116"></a> +<span class="sourceLineNo">117</span> Thread.sleep(MSG_INTERVAL * 3);<a name="line.117"></a> +<span class="sourceLineNo">118</span><a name="line.118"></a> +<span class="sourceLineNo">119</span> // check the RIT is 0<a name="line.119"></a> +<span class="sourceLineNo">120</span> MetricsAssignmentManagerSource amSource =<a name="line.120"></a> +<span class="sourceLineNo">121</span> MASTER.getAssignmentManager().getAssignmentManagerMetrics().getMetricsProcSource();<a name="line.121"></a> +<span class="sourceLineNo">122</span><a name="line.122"></a> +<span class="sourceLineNo">123</span> METRICS_HELPER.assertGauge(MetricsAssignmentManagerSource.RIT_COUNT_NAME, 0, amSource);<a name="line.123"></a> +<span class="sourceLineNo">124</span> METRICS_HELPER.assertGauge(MetricsAssignmentManagerSource.RIT_COUNT_OVER_THRESHOLD_NAME, 0,<a name="line.124"></a> +<span class="sourceLineNo">125</span> amSource);<a name="line.125"></a> <span class="sourceLineNo">126</span><a name="line.126"></a> -<span class="sourceLineNo">127</span> String spec = "hdfs:///foo.jar|com.foo.FooRegionObserver|1001|arg1=1,arg2=2";<a name="line.127"></a> -<span class="sourceLineNo">128</span> TableDescriptor htd = TableDescriptorBuilder.newBuilder(TABLENAME)<a name="line.128"></a> -<span class="sourceLineNo">129</span> .addColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY)).addCoprocessorWithSpec(spec)<a name="line.129"></a> -<span class="sourceLineNo">130</span> .build();<a name="line.130"></a> -<span class="sourceLineNo">131</span> try {<a name="line.131"></a> -<span class="sourceLineNo">132</span> TEST_UTIL.getAdmin().modifyTable(htd);<a name="line.132"></a> -<span class="sourceLineNo">133</span> fail("Expected region failed to open");<a name="line.133"></a> -<span class="sourceLineNo">134</span> } catch (IOException e) {<a name="line.134"></a> -<span class="sourceLineNo">135</span> // expected, the RS will crash and the assignment will spin forever waiting for a RS<a name="line.135"></a> -<span class="sourceLineNo">136</span> // to assign the region. the region will not go to FAILED_OPEN because in this case<a name="line.136"></a> -<span class="sourceLineNo">137</span> // we have just one RS and it will do one retry.<a name="line.137"></a> -<span class="sourceLineNo">138</span> LOG.info("Expected error", e);<a name="line.138"></a> -<span class="sourceLineNo">139</span> }<a name="line.139"></a> -<span class="sourceLineNo">140</span><a name="line.140"></a> -<span class="sourceLineNo">141</span> // Sleep 3 seconds, wait for doMetrics chore catching up<a name="line.141"></a> -<span class="sourceLineNo">142</span> Thread.sleep(msgInterval * 3);<a name="line.142"></a> -<span class="sourceLineNo">143</span> metricsHelper.assertGauge(MetricsAssignmentManagerSource.RIT_COUNT_NAME, 1, amSource);<a name="line.143"></a> -<span class="sourceLineNo">144</span> metricsHelper.assertGauge(MetricsAssignmentManagerSource.RIT_COUNT_OVER_THRESHOLD_NAME, 1,<a name="line.144"></a> -<span class="sourceLineNo">145</span> amSource);<a name="line.145"></a> -<span class="sourceLineNo">146</span> }<a name="line.146"></a> -<span class="sourceLineNo">147</span> }<a name="line.147"></a> -<span class="sourceLineNo">148</span>}<a name="line.148"></a> +<span class="sourceLineNo">127</span> // alter table with a non-existing coprocessor<a name="line.127"></a> +<span class="sourceLineNo">128</span><a name="line.128"></a> +<span class="sourceLineNo">129</span> String spec = "hdfs:///foo.jar|com.foo.FooRegionObserver|1001|arg1=1,arg2=2";<a name="line.129"></a> +<span class="sourceLineNo">130</span> TableDescriptor htd = TableDescriptorBuilder.newBuilder(TABLENAME)<a name="line.130"></a> +<span class="sourceLineNo">131</span> .addColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY)).addCoprocessorWithSpec(spec)<a name="line.131"></a> +<span class="sourceLineNo">132</span> .build();<a name="line.132"></a> +<span class="sourceLineNo">133</span> try {<a name="line.133"></a> +<span class="sourceLineNo">134</span> TEST_UTIL.getAdmin().modifyTable(htd);<a name="line.134"></a> +<span class="sourceLineNo">135</span> fail("Expected region failed to open");<a name="line.135"></a> +<span class="sourceLineNo">136</span> } catch (IOException e) {<a name="line.136"></a> +<span class="sourceLineNo">137</span> // expected, the RS will crash and the assignment will spin forever waiting for a RS<a name="line.137"></a> +<span class="sourceLineNo">138</span> // to assign the region. the region will not go to FAILED_OPEN because in this case<a name="line.138"></a> +<span class="sourceLineNo">139</span> // we have just one RS and it will do one retry.<a name="line.139"></a> +<span class="sourceLineNo">140</span> LOG.info("Expected error", e);<a name="line.140"></a> +<span class="sourceLineNo">141</span> }<a name="line.141"></a> +<span class="sourceLineNo">142</span><a name="line.142"></a> +<span class="sourceLineNo">143</span> // Sleep 3 seconds, wait for doMetrics chore catching up<a name="line.143"></a> +<span class="sourceLineNo">144</span> Thread.sleep(MSG_INTERVAL * 3);<a name="line.144"></a> +<span class="sourceLineNo">145</span> METRICS_HELPER.assertGauge(MetricsAssignmentManagerSource.RIT_COUNT_NAME, 1, amSource);<a name="line.145"></a> +<span class="sourceLineNo">146</span> METRICS_HELPER.assertGauge(MetricsAssignmentManagerSource.RIT_COUNT_OVER_THRESHOLD_NAME, 1,<a name="line.146"></a> +<span class="sourceLineNo">147</span> amSource);<a name="line.147"></a> +<span class="sourceLineNo">148</span> }<a name="line.148"></a> +<span class="sourceLineNo">149</span> }<a name="line.149"></a> +<span class="sourceLineNo">150</span>}<a name="line.150"></a> http://git-wip-us.apache.org/repos/asf/hbase-site/blob/473b2db2/testdevapidocs/src-html/org/apache/hadoop/hbase/master/TestRestartCluster.html ---------------------------------------------------------------------- diff --git a/testdevapidocs/src-html/org/apache/hadoop/hbase/master/TestRestartCluster.html b/testdevapidocs/src-html/org/apache/hadoop/hbase/master/TestRestartCluster.html index 4c96f29..3cdf150 100644 --- a/testdevapidocs/src-html/org/apache/hadoop/hbase/master/TestRestartCluster.html +++ b/testdevapidocs/src-html/org/apache/hadoop/hbase/master/TestRestartCluster.html @@ -40,190 +40,186 @@ <span class="sourceLineNo">032</span>import org.apache.hadoop.hbase.TableExistsException;<a name="line.32"></a> <span class="sourceLineNo">033</span>import org.apache.hadoop.hbase.TableName;<a name="line.33"></a> <span class="sourceLineNo">034</span>import org.apache.hadoop.hbase.client.RegionInfo;<a name="line.34"></a> -<span class="sourceLineNo">035</span>import org.apache.hadoop.hbase.master.assignment.RegionStates;<a name="line.35"></a> -<span class="sourceLineNo">036</span>import org.apache.hadoop.hbase.testclassification.LargeTests;<a name="line.36"></a> -<span class="sourceLineNo">037</span>import org.apache.hadoop.hbase.testclassification.MasterTests;<a name="line.37"></a> -<span class="sourceLineNo">038</span>import org.apache.hadoop.hbase.util.Bytes;<a name="line.38"></a> -<span class="sourceLineNo">039</span>import org.apache.hadoop.hbase.util.JVMClusterUtil;<a name="line.39"></a> -<span class="sourceLineNo">040</span>import org.apache.hadoop.hbase.util.Threads;<a name="line.40"></a> -<span class="sourceLineNo">041</span>import org.junit.After;<a name="line.41"></a> -<span class="sourceLineNo">042</span>import org.junit.ClassRule;<a name="line.42"></a> -<span class="sourceLineNo">043</span>import org.junit.Test;<a name="line.43"></a> -<span class="sourceLineNo">044</span>import org.junit.experimental.categories.Category;<a name="line.44"></a> -<span class="sourceLineNo">045</span>import org.slf4j.Logger;<a name="line.45"></a> -<span class="sourceLineNo">046</span>import org.slf4j.LoggerFactory;<a name="line.46"></a> -<span class="sourceLineNo">047</span><a name="line.47"></a> -<span class="sourceLineNo">048</span>@Category({MasterTests.class, LargeTests.class})<a name="line.48"></a> -<span class="sourceLineNo">049</span>public class TestRestartCluster {<a name="line.49"></a> -<span class="sourceLineNo">050</span><a name="line.50"></a> -<span class="sourceLineNo">051</span> @ClassRule<a name="line.51"></a> -<span class="sourceLineNo">052</span> public static final HBaseClassTestRule CLASS_RULE =<a name="line.52"></a> -<span class="sourceLineNo">053</span> HBaseClassTestRule.forClass(TestRestartCluster.class);<a name="line.53"></a> -<span class="sourceLineNo">054</span><a name="line.54"></a> -<span class="sourceLineNo">055</span> private static final Logger LOG = LoggerFactory.getLogger(TestRestartCluster.class);<a name="line.55"></a> -<span class="sourceLineNo">056</span> private HBaseTestingUtility UTIL = new HBaseTestingUtility();<a name="line.56"></a> -<span class="sourceLineNo">057</span><a name="line.57"></a> -<span class="sourceLineNo">058</span> private static final TableName[] TABLES = {<a name="line.58"></a> -<span class="sourceLineNo">059</span> TableName.valueOf("restartTableOne"),<a name="line.59"></a> -<span class="sourceLineNo">060</span> TableName.valueOf("restartTableTwo"),<a name="line.60"></a> -<span class="sourceLineNo">061</span> TableName.valueOf("restartTableThree")<a name="line.61"></a> -<span class="sourceLineNo">062</span> };<a name="line.62"></a> -<span class="sourceLineNo">063</span> private static final byte [] FAMILY = Bytes.toBytes("family");<a name="line.63"></a> -<span class="sourceLineNo">064</span><a name="line.64"></a> -<span class="sourceLineNo">065</span> @After public void tearDown() throws Exception {<a name="line.65"></a> -<span class="sourceLineNo">066</span> UTIL.shutdownMiniCluster();<a name="line.66"></a> -<span class="sourceLineNo">067</span> }<a name="line.67"></a> -<span class="sourceLineNo">068</span><a name="line.68"></a> -<span class="sourceLineNo">069</span> @Test<a name="line.69"></a> -<span class="sourceLineNo">070</span> public void testClusterRestart() throws Exception {<a name="line.70"></a> -<span class="sourceLineNo">071</span> UTIL.startMiniCluster(3);<a name="line.71"></a> -<span class="sourceLineNo">072</span> while (!UTIL.getMiniHBaseCluster().getMaster().isInitialized()) {<a name="line.72"></a> -<span class="sourceLineNo">073</span> Threads.sleep(1);<a name="line.73"></a> -<span class="sourceLineNo">074</span> }<a name="line.74"></a> -<span class="sourceLineNo">075</span> LOG.info("\n\nCreating tables");<a name="line.75"></a> -<span class="sourceLineNo">076</span> for(TableName TABLE : TABLES) {<a name="line.76"></a> -<span class="sourceLineNo">077</span> UTIL.createTable(TABLE, FAMILY);<a name="line.77"></a> -<span class="sourceLineNo">078</span> }<a name="line.78"></a> -<span class="sourceLineNo">079</span> for(TableName TABLE : TABLES) {<a name="line.79"></a> -<span class="sourceLineNo">080</span> UTIL.waitTableEnabled(TABLE);<a name="line.80"></a> -<span class="sourceLineNo">081</span> }<a name="line.81"></a> -<span class="sourceLineNo">082</span><a name="line.82"></a> -<span class="sourceLineNo">083</span> List<RegionInfo> allRegions = MetaTableAccessor.getAllRegions(UTIL.getConnection(), false);<a name="line.83"></a> -<span class="sourceLineNo">084</span> assertEquals(4, allRegions.size());<a name="line.84"></a> -<span class="sourceLineNo">085</span><a name="line.85"></a> -<span class="sourceLineNo">086</span> LOG.info("\n\nShutting down cluster");<a name="line.86"></a> -<span class="sourceLineNo">087</span> UTIL.shutdownMiniHBaseCluster();<a name="line.87"></a> -<span class="sourceLineNo">088</span><a name="line.88"></a> -<span class="sourceLineNo">089</span> LOG.info("\n\nSleeping a bit");<a name="line.89"></a> -<span class="sourceLineNo">090</span> Thread.sleep(2000);<a name="line.90"></a> -<span class="sourceLineNo">091</span><a name="line.91"></a> -<span class="sourceLineNo">092</span> LOG.info("\n\nStarting cluster the second time");<a name="line.92"></a> -<span class="sourceLineNo">093</span> UTIL.restartHBaseCluster(3);<a name="line.93"></a> -<span class="sourceLineNo">094</span><a name="line.94"></a> -<span class="sourceLineNo">095</span> // Need to use a new 'Configuration' so we make a new Connection.<a name="line.95"></a> -<span class="sourceLineNo">096</span> // Otherwise we're reusing an Connection that has gone stale because<a name="line.96"></a> -<span class="sourceLineNo">097</span> // the shutdown of the cluster also called shut of the connection.<a name="line.97"></a> -<span class="sourceLineNo">098</span> allRegions = MetaTableAccessor.getAllRegions(UTIL.getConnection(), false);<a name="line.98"></a> -<span class="sourceLineNo">099</span> assertEquals(4, allRegions.size());<a name="line.99"></a> -<span class="sourceLineNo">100</span> LOG.info("\n\nWaiting for tables to be available");<a name="line.100"></a> -<span class="sourceLineNo">101</span> for(TableName TABLE: TABLES) {<a name="line.101"></a> -<span class="sourceLineNo">102</span> try {<a name="line.102"></a> -<span class="sourceLineNo">103</span> UTIL.createTable(TABLE, FAMILY);<a name="line.103"></a> -<span class="sourceLineNo">104</span> assertTrue("Able to create table that should already exist", false);<a name="line.104"></a> -<span class="sourceLineNo">105</span> } catch(TableExistsException tee) {<a name="line.105"></a> -<span class="sourceLineNo">106</span> LOG.info("Table already exists as expected");<a name="line.106"></a> -<span class="sourceLineNo">107</span> }<a name="line.107"></a> -<span class="sourceLineNo">108</span> UTIL.waitTableAvailable(TABLE);<a name="line.108"></a> -<span class="sourceLineNo">109</span> }<a name="line.109"></a> -<span class="sourceLineNo">110</span> }<a name="line.110"></a> -<span class="sourceLineNo">111</span><a name="line.111"></a> -<span class="sourceLineNo">112</span> /**<a name="line.112"></a> -<span class="sourceLineNo">113</span> * This tests retaining assignments on a cluster restart<a name="line.113"></a> -<span class="sourceLineNo">114</span> */<a name="line.114"></a> -<span class="sourceLineNo">115</span> @Test<a name="line.115"></a> -<span class="sourceLineNo">116</span> public void testRetainAssignmentOnRestart() throws Exception {<a name="line.116"></a> -<span class="sourceLineNo">117</span> UTIL.startMiniCluster(2);<a name="line.117"></a> -<span class="sourceLineNo">118</span> while (!UTIL.getMiniHBaseCluster().getMaster().isInitialized()) {<a name="line.118"></a> -<span class="sourceLineNo">119</span> Threads.sleep(1);<a name="line.119"></a> -<span class="sourceLineNo">120</span> }<a name="line.120"></a> -<span class="sourceLineNo">121</span> // Turn off balancer<a name="line.121"></a> -<span class="sourceLineNo">122</span> UTIL.getMiniHBaseCluster().getMaster().<a name="line.122"></a> -<span class="sourceLineNo">123</span> getMasterRpcServices().synchronousBalanceSwitch(false);<a name="line.123"></a> -<span class="sourceLineNo">124</span> LOG.info("\n\nCreating tables");<a name="line.124"></a> -<span class="sourceLineNo">125</span> for(TableName TABLE : TABLES) {<a name="line.125"></a> -<span class="sourceLineNo">126</span> UTIL.createTable(TABLE, FAMILY);<a name="line.126"></a> -<span class="sourceLineNo">127</span> }<a name="line.127"></a> -<span class="sourceLineNo">128</span> for(TableName TABLE : TABLES) {<a name="line.128"></a> -<span class="sourceLineNo">129</span> UTIL.waitTableEnabled(TABLE);<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> HMaster master = UTIL.getMiniHBaseCluster().getMaster();<a name="line.132"></a> -<span class="sourceLineNo">133</span> UTIL.waitUntilNoRegionsInTransition(120000);<a name="line.133"></a> -<span class="sourceLineNo">134</span><a name="line.134"></a> -<span class="sourceLineNo">135</span> // We don't have to use SnapshotOfRegionAssignmentFromMeta.<a name="line.135"></a> -<span class="sourceLineNo">136</span> // We use it here because AM used to use it to load all user region placements<a name="line.136"></a> -<span class="sourceLineNo">137</span> SnapshotOfRegionAssignmentFromMeta snapshot = new SnapshotOfRegionAssignmentFromMeta(<a name="line.137"></a> -<span class="sourceLineNo">138</span> master.getConnection());<a name="line.138"></a> -<span class="sourceLineNo">139</span> snapshot.initialize();<a name="line.139"></a> -<span class="sourceLineNo">140</span> Map<RegionInfo, ServerName> regionToRegionServerMap<a name="line.140"></a> -<span class="sourceLineNo">141</span> = snapshot.getRegionToRegionServerMap();<a name="line.141"></a> -<span class="sourceLineNo">142</span><a name="line.142"></a> -<span class="sourceLineNo">143</span> MiniHBaseCluster cluster = UTIL.getHBaseCluster();<a name="line.143"></a> -<span class="sourceLineNo">144</span> List<JVMClusterUtil.RegionServerThread> threads = cluster.getLiveRegionServerThreads();<a name="line.144"></a> -<span class="sourceLineNo">145</span> assertEquals(2, threads.size());<a name="line.145"></a> -<span class="sourceLineNo">146</span> int[] rsPorts = new int[3];<a name="line.146"></a> -<span class="sourceLineNo">147</span> for (int i = 0; i < 2; i++) {<a name="line.147"></a> -<span class="sourceLineNo">148</span> rsPorts[i] = threads.get(i).getRegionServer().getServerName().getPort();<a name="line.148"></a> -<span class="sourceLineNo">149</span> }<a name="line.149"></a> -<span class="sourceLineNo">150</span> rsPorts[2] = cluster.getMaster().getServerName().getPort();<a name="line.150"></a> -<span class="sourceLineNo">151</span> for (ServerName serverName: regionToRegionServerMap.values()) {<a name="line.151"></a> -<span class="sourceLineNo">152</span> boolean found = false; // Test only, no need to optimize<a name="line.152"></a> -<span class="sourceLineNo">153</span> for (int k = 0; k < 3 && !found; k++) {<a name="line.153"></a> -<span class="sourceLineNo">154</span> found = serverName.getPort() == rsPorts[k];<a name="line.154"></a> -<span class="sourceLineNo">155</span> }<a name="line.155"></a> -<span class="sourceLineNo">156</span> assertTrue(found);<a name="line.156"></a> -<span class="sourceLineNo">157</span> }<a name="line.157"></a> +<span class="sourceLineNo">035</span>import org.apache.hadoop.hbase.testclassification.LargeTests;<a name="line.35"></a> +<span class="sourceLineNo">036</span>import org.apache.hadoop.hbase.testclassification.MasterTests;<a name="line.36"></a> +<span class="sourceLineNo">037</span>import org.apache.hadoop.hbase.util.Bytes;<a name="line.37"></a> +<span class="sourceLineNo">038</span>import org.apache.hadoop.hbase.util.JVMClusterUtil;<a name="line.38"></a> +<span class="sourceLineNo">039</span>import org.apache.hadoop.hbase.util.Threads;<a name="line.39"></a> +<span class="sourceLineNo">040</span>import org.junit.After;<a name="line.40"></a> +<span class="sourceLineNo">041</span>import org.junit.ClassRule;<a name="line.41"></a> +<span class="sourceLineNo">042</span>import org.junit.Test;<a name="line.42"></a> +<span class="sourceLineNo">043</span>import org.junit.experimental.categories.Category;<a name="line.43"></a> +<span class="sourceLineNo">044</span>import org.slf4j.Logger;<a name="line.44"></a> +<span class="sourceLineNo">045</span>import org.slf4j.LoggerFactory;<a name="line.45"></a> +<span class="sourceLineNo">046</span><a name="line.46"></a> +<span class="sourceLineNo">047</span>@Category({ MasterTests.class, LargeTests.class })<a name="line.47"></a> +<span class="sourceLineNo">048</span>public class TestRestartCluster {<a name="line.48"></a> +<span class="sourceLineNo">049</span><a name="line.49"></a> +<span class="sourceLineNo">050</span> @ClassRule<a name="line.50"></a> +<span class="sourceLineNo">051</span> public static final HBaseClassTestRule CLASS_RULE =<a name="line.51"></a> +<span class="sourceLineNo">052</span> HBaseClassTestRule.forClass(TestRestartCluster.class);<a name="line.52"></a> +<span class="sourceLineNo">053</span><a name="line.53"></a> +<span class="sourceLineNo">054</span> private static final Logger LOG = LoggerFactory.getLogger(TestRestartCluster.class);<a name="line.54"></a> +<span class="sourceLineNo">055</span> private HBaseTestingUtility UTIL = new HBaseTestingUtility();<a name="line.55"></a> +<span class="sourceLineNo">056</span><a name="line.56"></a> +<span class="sourceLineNo">057</span> private static final TableName[] TABLES = {<a name="line.57"></a> +<span class="sourceLineNo">058</span> TableName.valueOf("restartTableOne"),<a name="line.58"></a> +<span class="sourceLineNo">059</span> TableName.valueOf("restartTableTwo"),<a name="line.59"></a> +<span class="sourceLineNo">060</span> TableName.valueOf("restartTableThree")<a name="line.60"></a> +<span class="sourceLineNo">061</span> };<a name="line.61"></a> +<span class="sourceLineNo">062</span> private static final byte[] FAMILY = Bytes.toBytes("family");<a name="line.62"></a> +<span class="sourceLineNo">063</span><a name="line.63"></a> +<span class="sourceLineNo">064</span> @After public void tearDown() throws Exception {<a name="line.64"></a> +<span class="sourceLineNo">065</span> UTIL.shutdownMiniCluster();<a name="line.65"></a> +<span class="sourceLineNo">066</span> }<a name="line.66"></a> +<span class="sourceLineNo">067</span><a name="line.67"></a> +<span class="sourceLineNo">068</span> @Test<a name="line.68"></a> +<span class="sourceLineNo">069</span> public void testClusterRestart() throws Exception {<a name="line.69"></a> +<span class="sourceLineNo">070</span> UTIL.startMiniCluster(3);<a name="line.70"></a> +<span class="sourceLineNo">071</span> while (!UTIL.getMiniHBaseCluster().getMaster().isInitialized()) {<a name="line.71"></a> +<span class="sourceLineNo">072</span> Threads.sleep(1);<a name="line.72"></a> +<span class="sourceLineNo">073</span> }<a name="line.73"></a> +<span class="sourceLineNo">074</span> LOG.info("\n\nCreating tables");<a name="line.74"></a> +<span class="sourceLineNo">075</span> for(TableName TABLE : TABLES) {<a name="line.75"></a> +<span class="sourceLineNo">076</span> UTIL.createTable(TABLE, FAMILY);<a name="line.76"></a> +<span class="sourceLineNo">077</span> }<a name="line.77"></a> +<span class="sourceLineNo">078</span> for(TableName TABLE : TABLES) {<a name="line.78"></a> +<span class="sourceLineNo">079</span> UTIL.waitTableEnabled(TABLE);<a name="line.79"></a> +<span class="sourceLineNo">080</span> }<a name="line.80"></a> +<span class="sourceLineNo">081</span><a name="line.81"></a> +<span class="sourceLineNo">082</span> List<RegionInfo> allRegions = MetaTableAccessor.getAllRegions(UTIL.getConnection(), false);<a name="line.82"></a> +<span class="sourceLineNo">083</span> assertEquals(4, allRegions.size());<a name="line.83"></a> +<span class="sourceLineNo">084</span><a name="line.84"></a> +<span class="sourceLineNo">085</span> LOG.info("\n\nShutting down cluster");<a name="line.85"></a> +<span class="sourceLineNo">086</span> UTIL.shutdownMiniHBaseCluster();<a name="line.86"></a> +<span class="sourceLineNo">087</span><a name="line.87"></a> +<span class="sourceLineNo">088</span> LOG.info("\n\nSleeping a bit");<a name="line.88"></a> +<span class="sourceLineNo">089</span> Thread.sleep(2000);<a name="line.89"></a> +<span class="sourceLineNo">090</span><a name="line.90"></a> +<span class="sourceLineNo">091</span> LOG.info("\n\nStarting cluster the second time");<a name="line.91"></a> +<span class="sourceLineNo">092</span> UTIL.restartHBaseCluster(3);<a name="line.92"></a> +<span class="sourceLineNo">093</span><a name="line.93"></a> +<span class="sourceLineNo">094</span> // Need to use a new 'Configuration' so we make a new Connection.<a name="line.94"></a> +<span class="sourceLineNo">095</span> // Otherwise we're reusing an Connection that has gone stale because<a name="line.95"></a> +<span class="sourceLineNo">096</span> // the shutdown of the cluster also called shut of the connection.<a name="line.96"></a> +<span class="sourceLineNo">097</span> allRegions = MetaTableAccessor.getAllRegions(UTIL.getConnection(), false);<a name="line.97"></a> +<span class="sourceLineNo">098</span> assertEquals(4, allRegions.size());<a name="line.98"></a> +<span class="sourceLineNo">099</span> LOG.info("\n\nWaiting for tables to be available");<a name="line.99"></a> +<span class="sourceLineNo">100</span> for(TableName TABLE: TABLES) {<a name="line.100"></a> +<span class="sourceLineNo">101</span> try {<a name="line.101"></a> +<span class="sourceLineNo">102</span> UTIL.createTable(TABLE, FAMILY);<a name="line.102"></a> +<span class="sourceLineNo">103</span> assertTrue("Able to create table that should already exist", false);<a name="line.103"></a> +<span class="sourceLineNo">104</span> } catch(TableExistsException tee) {<a name="line.104"></a> +<span class="sourceLineNo">105</span> LOG.info("Table already exists as expected");<a name="line.105"></a> +<span class="sourceLineNo">106</span> }<a name="line.106"></a> +<span class="sourceLineNo">107</span> UTIL.waitTableAvailable(TABLE);<a name="line.107"></a> +<span class="sourceLineNo">108</span> }<a name="line.108"></a> +<span class="sourceLineNo">109</span> }<a name="line.109"></a> +<span class="sourceLineNo">110</span><a name="line.110"></a> +<span class="sourceLineNo">111</span> /**<a name="line.111"></a> +<span class="sourceLineNo">112</span> * This tests retaining assignments on a cluster restart<a name="line.112"></a> +<span class="sourceLineNo">113</span> */<a name="line.113"></a> +<span class="sourceLineNo">114</span> @Test<a name="line.114"></a> +<span class="sourceLineNo">115</span> public void testRetainAssignmentOnRestart() throws Exception {<a name="line.115"></a> +<span class="sourceLineNo">116</span> UTIL.startMiniCluster(2);<a name="line.116"></a> +<span class="sourceLineNo">117</span> // Turn off balancer<a name="line.117"></a> +<span class="sourceLineNo">118</span> UTIL.getMiniHBaseCluster().getMaster().getMasterRpcServices().synchronousBalanceSwitch(false);<a name="line.118"></a> +<span class="sourceLineNo">119</span> LOG.info("\n\nCreating tables");<a name="line.119"></a> +<span class="sourceLineNo">120</span> for (TableName TABLE : TABLES) {<a name="line.120"></a> +<span class="sourceLineNo">121</span> UTIL.createTable(TABLE, FAMILY);<a name="line.121"></a> +<span class="sourceLineNo">122</span> }<a name="line.122"></a> +<span class="sourceLineNo">123</span> for (TableName TABLE : TABLES) {<a name="line.123"></a> +<span class="sourceLineNo">124</span> UTIL.waitTableEnabled(TABLE);<a name="line.124"></a> +<span class="sourceLineNo">125</span> }<a name="line.125"></a> +<span class="sourceLineNo">126</span><a name="line.126"></a> +<span class="sourceLineNo">127</span> HMaster master = UTIL.getMiniHBaseCluster().getMaster();<a name="line.127"></a> +<span class="sourceLineNo">128</span> UTIL.waitUntilNoRegionsInTransition(120000);<a name="line.128"></a> +<span class="sourceLineNo">129</span><a name="line.129"></a> +<span class="sourceLineNo">130</span> // We don't have to use SnapshotOfRegionAssignmentFromMeta.<a name="line.130"></a> +<span class="sourceLineNo">131</span> // We use it here because AM used to use it to load all user region placements<a name="line.131"></a> +<span class="sourceLineNo">132</span> SnapshotOfRegionAssignmentFromMeta snapshot = new SnapshotOfRegionAssignmentFromMeta(<a name="line.132"></a> +<span class="sourceLineNo">133</span> master.getConnection());<a name="line.133"></a> +<span class="sourceLineNo">134</span> snapshot.initialize();<a name="line.134"></a> +<span class="sourceLineNo">135</span> Map<RegionInfo, ServerName> regionToRegionServerMap<a name="line.135"></a> +<span class="sourceLineNo">136</span> = snapshot.getRegionToRegionServerMap();<a name="line.136"></a> +<span class="sourceLineNo">137</span><a name="line.137"></a> +<span class="sourceLineNo">138</span> MiniHBaseCluster cluster = UTIL.getHBaseCluster();<a name="line.138"></a> +<span class="sourceLineNo">139</span> List<JVMClusterUtil.RegionServerThread> threads = cluster.getLiveRegionServerThreads();<a name="line.139"></a> +<span class="sourceLineNo">140</span> assertEquals(2, threads.size());<a name="line.140"></a> +<span class="sourceLineNo">141</span> int[] rsPorts = new int[3];<a name="line.141"></a> +<span class="sourceLineNo">142</span> for (int i = 0; i < 2; i++) {<a name="line.142"></a> +<span class="sourceLineNo">143</span> rsPorts[i] = threads.get(i).getRegionServer().getServerName().getPort();<a name="line.143"></a> +<span class="sourceLineNo">144</span> }<a name="line.144"></a> +<span class="sourceLineNo">145</span> rsPorts[2] = cluster.getMaster().getServerName().getPort();<a name="line.145"></a> +<span class="sourceLineNo">146</span> for (ServerName serverName: regionToRegionServerMap.values()) {<a name="line.146"></a> +<span class="sourceLineNo">147</span> boolean found = false; // Test only, no need to optimize<a name="line.147"></a> +<span class="sourceLineNo">148</span> for (int k = 0; k < 3 && !found; k++) {<a name="line.148"></a> +<span class="sourceLineNo">149</span> found = serverName.getPort() == rsPorts[k];<a name="line.149"></a> +<span class="sourceLineNo">150</span> }<a name="line.150"></a> +<span class="sourceLineNo">151</span> assertTrue(found);<a name="line.151"></a> +<span class="sourceLineNo">152</span> }<a name="line.152"></a> +<span class="sourceLineNo">153</span><a name="line.153"></a> +<span class="sourceLineNo">154</span> LOG.info("\n\nShutting down HBase cluster");<a name="line.154"></a> +<span class="sourceLineNo">155</span> cluster.stopMaster(0);<a name="line.155"></a> +<span class="sourceLineNo">156</span> cluster.shutdown();<a name="line.156"></a> +<span class="sourceLineNo">157</span> cluster.waitUntilShutDown();<a name="line.157"></a> <span class="sourceLineNo">158</span><a name="line.158"></a> -<span class="sourceLineNo">159</span> LOG.info("\n\nShutting down HBase cluster");<a name="line.159"></a> -<span class="sourceLineNo">160</span> cluster.shutdown();<a name="line.160"></a> -<span class="sourceLineNo">161</span> cluster.waitUntilShutDown();<a name="line.161"></a> -<span class="sourceLineNo">162</span><a name="line.162"></a> -<span class="sourceLineNo">163</span> LOG.info("\n\nSleeping a bit");<a name="line.163"></a> -<span class="sourceLineNo">164</span> Thread.sleep(2000);<a name="line.164"></a> -<span class="sourceLineNo">165</span><a name="line.165"></a> -<span class="sourceLineNo">166</span> LOG.info("\n\nStarting cluster the second time with the same ports");<a name="line.166"></a> -<span class="sourceLineNo">167</span> try {<a name="line.167"></a> -<span class="sourceLineNo">168</span> cluster.getConf().setInt(<a name="line.168"></a> -<span class="sourceLineNo">169</span> ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, 3);<a name="line.169"></a> -<span class="sourceLineNo">170</span> master = cluster.startMaster().getMaster();<a name="line.170"></a> -<span class="sourceLineNo">171</span> for (int i = 0; i < 3; i++) {<a name="line.171"></a> -<span class="sourceLineNo">172</span> cluster.getConf().setInt(HConstants.REGIONSERVER_PORT, rsPorts[i]);<a name="line.172"></a> -<span class="sourceLineNo">173</span> cluster.startRegionServer();<a name="line.173"></a> -<span class="sourceLineNo">174</span> }<a name="line.174"></a> -<span class="sourceLineNo">175</span> } finally {<a name="line.175"></a> -<span class="sourceLineNo">176</span> // Reset region server port so as not to conflict with other tests<a name="line.176"></a> -<span class="sourceLineNo">177</span> cluster.getConf().setInt(HConstants.REGIONSERVER_PORT, 0);<a name="line.177"></a> -<span class="sourceLineNo">178</span> cluster.getConf().setInt(<a name="line.178"></a> -<span class="sourceLineNo">179</span> ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, 2);<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> // Make sure live regionservers are on the same host/port<a name="line.182"></a> -<span class="sourceLineNo">183</span> List<ServerName> localServers = master.getServerManager().getOnlineServersList();<a name="line.183"></a> -<span class="sourceLineNo">184</span> assertEquals(3, localServers.size());<a name="line.184"></a> -<span class="sourceLineNo">185</span> for (int i = 0; i < 3; i++) {<a name="line.185"></a> -<span class="sourceLineNo">186</span> boolean found = false;<a name="line.186"></a> -<span class="sourceLineNo">187</span> for (ServerName serverName: localServers) {<a name="line.187"></a> -<span class="sourceLineNo">188</span> if (serverName.getPort() == rsPorts[i]) {<a name="line.188"></a> -<span class="sourceLineNo">189</span> found = true;<a name="line.189"></a> -<span class="sourceLineNo">190</span> break;<a name="line.190"></a> -<span class="sourceLineNo">191</span> }<a name="line.191"></a> -<span class="sourceLineNo">192</span> }<a name="line.192"></a> -<span class="sourceLineNo">193</span> assertTrue(found);<a name="line.193"></a> -<span class="sourceLineNo">194</span> }<a name="line.194"></a> -<span class="sourceLineNo">195</span><a name="line.195"></a> -<span class="sourceLineNo">196</span> // Wait till master is initialized and all regions are assigned<a name="line.196"></a> -<span class="sourceLineNo">197</span> RegionStates regionStates = master.getAssignmentManager().getRegionStates();<a name="line.197"></a> -<span class="sourceLineNo">198</span> int expectedRegions = regionToRegionServerMap.size() + 1;<a name="line.198"></a> -<span class="sourceLineNo">199</span> while (!master.isInitialized()<a name="line.199"></a> -<span class="sourceLineNo">200</span> || regionStates.getRegionAssignments().size() != expectedRegions) {<a name="line.200"></a> -<span class="sourceLineNo">201</span> Threads.sleep(100);<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> snapshot = new SnapshotOfRegionAssignmentFromMeta(master.getConnection());<a name="line.204"></a> -<span class="sourceLineNo">205</span> snapshot.initialize();<a name="line.205"></a> -<span class="sourceLineNo">206</span> Map<RegionInfo, ServerName> newRegionToRegionServerMap =<a name="line.206"></a> -<span class="sourceLineNo">207</span> snapshot.getRegionToRegionServerMap();<a name="line.207"></a> -<span class="sourceLineNo">208</span> assertEquals(regionToRegionServerMap.size(), newRegionToRegionServerMap.size());<a name="line.208"></a> -<span class="sourceLineNo">209</span> for (Map.Entry<RegionInfo, ServerName> entry: newRegionToRegionServerMap.entrySet()) {<a name="line.209"></a> -<span class="sourceLineNo">210</span> if (TableName.NAMESPACE_TABLE_NAME.equals(entry.getKey().getTable())) continue;<a name="line.210"></a> -<span class="sourceLineNo">211</span> ServerName oldServer = regionToRegionServerMap.get(entry.getKey());<a name="line.211"></a> -<span class="sourceLineNo">212</span> ServerName currentServer = entry.getValue();<a name="line.212"></a> -<span class="sourceLineNo">213</span> LOG.info("Key=" + entry.getKey() + " oldServer=" + oldServer + ", currentServer=" + currentServer);<a name="line.213"></a> -<span class="sourceLineNo">214</span> assertEquals(entry.getKey().toString(), oldServer.getAddress(), currentServer.getAddress());<a name="line.214"></a> -<span class="sourceLineNo">215</span> assertNotEquals(oldServer.getStartcode(), currentServer.getStartcode());<a name="line.215"></a> -<span class="sourceLineNo">216</span> }<a name="line.216"></a> -<span class="sourceLineNo">217</span> }<a name="line.217"></a> -<span class="sourceLineNo">218</span>}<a name="line.218"></a> +<span class="sourceLineNo">159</span> LOG.info("\n\nSleeping a bit");<a name="line.159"></a> +<span class="sourceLineNo">160</span> Thread.sleep(2000);<a name="line.160"></a> +<span class="sourceLineNo">161</span><a name="line.161"></a> +<span class="sourceLineNo">162</span> LOG.info("\n\nStarting cluster the second time with the same ports");<a name="line.162"></a> +<span class="sourceLineNo">163</span> try {<a name="line.163"></a> +<span class="sourceLineNo">164</span> cluster.getConf().setInt(<a name="line.164"></a> +<span class="sourceLineNo">165</span> ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, 3);<a name="line.165"></a> +<span class="sourceLineNo">166</span> master = cluster.startMaster().getMaster();<a name="line.166"></a> +<span class="sourceLineNo">167</span> for (int i = 0; i < 3; i++) {<a name="line.167"></a> +<span class="sourceLineNo">168</span> cluster.getConf().setInt(HConstants.REGIONSERVER_PORT, rsPorts[i]);<a name="line.168"></a> +<span class="sourceLineNo">169</span> cluster.startRegionServer();<a name="line.169"></a> +<span class="sourceLineNo">170</span> }<a name="line.170"></a> +<span class="sourceLineNo">171</span> } finally {<a name="line.171"></a> +<span class="sourceLineNo">172</span> // Reset region server port so as not to conflict with other tests<a name="line.172"></a> +<span class="sourceLineNo">173</span> cluster.getConf().setInt(HConstants.REGIONSERVER_PORT, 0);<a name="line.173"></a> +<span class="sourceLineNo">174</span> cluster.getConf().setInt(<a name="line.174"></a> +<span class="sourceLineNo">175</span> ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, 2);<a name="line.175"></a> +<span class="sourceLineNo">176</span> }<a name="line.176"></a> +<span class="sourceLineNo">177</span><a name="line.177"></a> +<span class="sourceLineNo">178</span> // Make sure live regionservers are on the same host/port<a name="line.178"></a> +<span class="sourceLineNo">179</span> List<ServerName> localServers = master.getServerManager().getOnlineServersList();<a name="line.179"></a> +<span class="sourceLineNo">180</span> assertEquals(3, localServers.size());<a name="line.180"></a> +<span class="sourceLineNo">181</span> for (int i = 0; i < 3; i++) {<a name="line.181"></a> +<span class="sourceLineNo">182</span> boolean found = false;<a name="line.182"></a> +<span class="sourceLineNo">183</span> for (ServerName serverName: localServers) {<a name="line.183"></a> +<span class="sourceLineNo">184</span> if (serverName.getPort() == rsPorts[i]) {<a name="line.184"></a> +<span class="sourceLineNo">185</span> found = true;<a name="line.185"></a> +<span class="sourceLineNo">186</span> break;<a name="line.186"></a> +<span class="sourceLineNo">187</span> }<a name="line.187"></a> +<span class="sourceLineNo">188</span> }<a name="line.188"></a> +<span class="sourceLineNo">189</span> assertTrue(found);<a name="line.189"></a> +<span class="sourceLineNo">190</span> }<a name="line.190"></a> +<span class="sourceLineNo">191</span><a name="line.191"></a> +<span class="sourceLineNo">192</span> // Wait till master is initialized and all regions are assigned<a name="line.192"></a> +<span class="sourceLineNo">193</span> for (TableName TABLE : TABLES) {<a name="line.193"></a> +<span class="sourceLineNo">194</span> UTIL.waitTableAvailable(TABLE);<a name="line.194"></a> +<span class="sourceLineNo">195</span> }<a name="line.195"></a> +<span class="sourceLineNo">196</span><a name="line.196"></a> +<span class="sourceLineNo">197</span> snapshot = new SnapshotOfRegionAssignmentFromMeta(master.getConnection());<a name="line.197"></a> +<span class="sourceLineNo">198</span> snapshot.initialize();<a name="line.198"></a> +<span class="sourceLineNo">199</span> Map<RegionInfo, ServerName> newRegionToRegionServerMap =<a name="line.199"></a> +<span class="sourceLineNo">200</span> snapshot.getRegionToRegionServerMap();<a name="line.200"></a> +<span class="sourceLineNo">201</span> assertEquals(regionToRegionServerMap.size(), newRegionToRegionServerMap.size());<a name="line.201"></a> +<span class="sourceLineNo">202</span> for (Map.Entry<RegionInfo, ServerName> entry : newRegionToRegionServerMap.entrySet()) {<a name="line.202"></a> +<span class="sourceLineNo">203</span> if (TableName.NAMESPACE_TABLE_NAME.equals(entry.getKey().getTable())) {<a name="line.203"></a> +<span class="sourceLineNo">204</span> continue;<a name="line.204"></a> +<span class="sourceLineNo">205</span> }<a name="line.205"></a> +<span class="sourceLineNo">206</span> ServerName oldServer = regionToRegionServerMap.get(entry.getKey());<a name="line.206"></a> +<span class="sourceLineNo">207</span> ServerName currentServer = entry.getValue();<a name="line.207"></a> +<span class="sourceLineNo">208</span> LOG.info(<a name="line.208"></a> +<span class="sourceLineNo">209</span> "Key=" + entry.getKey() + " oldServer=" + oldServer + ", currentServer=" + currentServer);<a name="line.209"></a> +<span class="sourceLineNo">210</span> assertEquals(entry.getKey().toString(), oldServer.getAddress(), currentServer.getAddress());<a name="line.210"></a> +<span class="sourceLineNo">211</span> assertNotEquals(oldServer.getStartcode(), currentServer.getStartcode());<a name="line.211"></a> +<span class="sourceLineNo">212</span> }<a name="line.212"></a> +<span class="sourceLineNo">213</span> }<a name="line.213"></a> +<span class="sourceLineNo">214</span>}<a name="line.214"></a>