Repository: hbase-site Updated Branches: refs/heads/asf-site 93f7e17c1 -> b9b09fecf
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/b9b09fec/testdevapidocs/src-html/org/apache/hadoop/hbase/master/procedure/TestMasterProcedureEvents.html ---------------------------------------------------------------------- diff --git a/testdevapidocs/src-html/org/apache/hadoop/hbase/master/procedure/TestMasterProcedureEvents.html b/testdevapidocs/src-html/org/apache/hadoop/hbase/master/procedure/TestMasterProcedureEvents.html index 522bf52..dc23ae9 100644 --- a/testdevapidocs/src-html/org/apache/hadoop/hbase/master/procedure/TestMasterProcedureEvents.html +++ b/testdevapidocs/src-html/org/apache/hadoop/hbase/master/procedure/TestMasterProcedureEvents.html @@ -27,140 +27,147 @@ <span class="sourceLineNo">019</span><a name="line.19"></a> <span class="sourceLineNo">020</span>import static org.junit.Assert.assertEquals;<a name="line.20"></a> <span class="sourceLineNo">021</span><a name="line.21"></a> -<span class="sourceLineNo">022</span>import org.apache.hadoop.conf.Configuration;<a name="line.22"></a> -<span class="sourceLineNo">023</span>import org.apache.hadoop.hbase.HBaseClassTestRule;<a name="line.23"></a> -<span class="sourceLineNo">024</span>import org.apache.hadoop.hbase.HBaseTestingUtility;<a name="line.24"></a> -<span class="sourceLineNo">025</span>import org.apache.hadoop.hbase.TableName;<a name="line.25"></a> -<span class="sourceLineNo">026</span>import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;<a name="line.26"></a> -<span class="sourceLineNo">027</span>import org.apache.hadoop.hbase.client.RegionInfo;<a name="line.27"></a> -<span class="sourceLineNo">028</span>import org.apache.hadoop.hbase.client.RegionInfoBuilder;<a name="line.28"></a> -<span class="sourceLineNo">029</span>import org.apache.hadoop.hbase.client.TableDescriptor;<a name="line.29"></a> -<span class="sourceLineNo">030</span>import org.apache.hadoop.hbase.client.TableDescriptorBuilder;<a name="line.30"></a> -<span class="sourceLineNo">031</span>import org.apache.hadoop.hbase.master.HMaster;<a name="line.31"></a> -<span class="sourceLineNo">032</span>import org.apache.hadoop.hbase.procedure2.Procedure;<a name="line.32"></a> -<span class="sourceLineNo">033</span>import org.apache.hadoop.hbase.procedure2.ProcedureEvent;<a name="line.33"></a> -<span class="sourceLineNo">034</span>import org.apache.hadoop.hbase.procedure2.ProcedureExecutor;<a name="line.34"></a> -<span class="sourceLineNo">035</span>import org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility;<a name="line.35"></a> -<span class="sourceLineNo">036</span>import org.apache.hadoop.hbase.procedure2.store.wal.WALProcedureStore;<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.junit.After;<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 TestMasterProcedureEvents {<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(TestMasterProcedureEvents.class);<a name="line.55"></a> +<span class="sourceLineNo">022</span>import java.io.IOException;<a name="line.22"></a> +<span class="sourceLineNo">023</span><a name="line.23"></a> +<span class="sourceLineNo">024</span>import org.apache.hadoop.conf.Configuration;<a name="line.24"></a> +<span class="sourceLineNo">025</span>import org.apache.hadoop.fs.Path;<a name="line.25"></a> +<span class="sourceLineNo">026</span>import org.apache.hadoop.hbase.HBaseClassTestRule;<a name="line.26"></a> +<span class="sourceLineNo">027</span>import org.apache.hadoop.hbase.HBaseTestingUtility;<a name="line.27"></a> +<span class="sourceLineNo">028</span>import org.apache.hadoop.hbase.TableName;<a name="line.28"></a> +<span class="sourceLineNo">029</span>import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;<a name="line.29"></a> +<span class="sourceLineNo">030</span>import org.apache.hadoop.hbase.client.RegionInfo;<a name="line.30"></a> +<span class="sourceLineNo">031</span>import org.apache.hadoop.hbase.client.RegionInfoBuilder;<a name="line.31"></a> +<span class="sourceLineNo">032</span>import org.apache.hadoop.hbase.client.TableDescriptor;<a name="line.32"></a> +<span class="sourceLineNo">033</span>import org.apache.hadoop.hbase.client.TableDescriptorBuilder;<a name="line.33"></a> +<span class="sourceLineNo">034</span>import org.apache.hadoop.hbase.master.HMaster;<a name="line.34"></a> +<span class="sourceLineNo">035</span>import org.apache.hadoop.hbase.procedure2.Procedure;<a name="line.35"></a> +<span class="sourceLineNo">036</span>import org.apache.hadoop.hbase.procedure2.ProcedureEvent;<a name="line.36"></a> +<span class="sourceLineNo">037</span>import org.apache.hadoop.hbase.procedure2.ProcedureExecutor;<a name="line.37"></a> +<span class="sourceLineNo">038</span>import org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility;<a name="line.38"></a> +<span class="sourceLineNo">039</span>import org.apache.hadoop.hbase.procedure2.store.wal.WALProcedureStore;<a name="line.39"></a> +<span class="sourceLineNo">040</span>import org.apache.hadoop.hbase.testclassification.MasterTests;<a name="line.40"></a> +<span class="sourceLineNo">041</span>import org.apache.hadoop.hbase.testclassification.MediumTests;<a name="line.41"></a> +<span class="sourceLineNo">042</span>import org.apache.hadoop.hbase.util.CommonFSUtils;<a name="line.42"></a> +<span class="sourceLineNo">043</span>import org.junit.After;<a name="line.43"></a> +<span class="sourceLineNo">044</span>import org.junit.AfterClass;<a name="line.44"></a> +<span class="sourceLineNo">045</span>import org.junit.BeforeClass;<a name="line.45"></a> +<span class="sourceLineNo">046</span>import org.junit.ClassRule;<a name="line.46"></a> +<span class="sourceLineNo">047</span>import org.junit.Rule;<a name="line.47"></a> +<span class="sourceLineNo">048</span>import org.junit.Test;<a name="line.48"></a> +<span class="sourceLineNo">049</span>import org.junit.experimental.categories.Category;<a name="line.49"></a> +<span class="sourceLineNo">050</span>import org.junit.rules.TestName;<a name="line.50"></a> +<span class="sourceLineNo">051</span>import org.slf4j.Logger;<a name="line.51"></a> +<span class="sourceLineNo">052</span>import org.slf4j.LoggerFactory;<a name="line.52"></a> +<span class="sourceLineNo">053</span><a name="line.53"></a> +<span class="sourceLineNo">054</span>@Category({MasterTests.class, MediumTests.class})<a name="line.54"></a> +<span class="sourceLineNo">055</span>public class TestMasterProcedureEvents {<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(TestCreateTableProcedure.class);<a name="line.57"></a> -<span class="sourceLineNo">058</span><a name="line.58"></a> -<span class="sourceLineNo">059</span> protected static final HBaseTestingUtility UTIL = new HBaseTestingUtility();<a name="line.59"></a> +<span class="sourceLineNo">057</span> @ClassRule<a name="line.57"></a> +<span class="sourceLineNo">058</span> public static final HBaseClassTestRule CLASS_RULE =<a name="line.58"></a> +<span class="sourceLineNo">059</span> HBaseClassTestRule.forClass(TestMasterProcedureEvents.class);<a name="line.59"></a> <span class="sourceLineNo">060</span><a name="line.60"></a> -<span class="sourceLineNo">061</span> @Rule<a name="line.61"></a> -<span class="sourceLineNo">062</span> public TestName name = new TestName();<a name="line.62"></a> -<span class="sourceLineNo">063</span><a name="line.63"></a> -<span class="sourceLineNo">064</span> private static void setupConf(Configuration conf) {<a name="line.64"></a> -<span class="sourceLineNo">065</span> conf.setInt(MasterProcedureConstants.MASTER_PROCEDURE_THREADS, 1);<a name="line.65"></a> -<span class="sourceLineNo">066</span> conf.setBoolean(WALProcedureStore.USE_HSYNC_CONF_KEY, false);<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> @BeforeClass<a name="line.69"></a> -<span class="sourceLineNo">070</span> public static void setupCluster() throws Exception {<a name="line.70"></a> -<span class="sourceLineNo">071</span> setupConf(UTIL.getConfiguration());<a name="line.71"></a> -<span class="sourceLineNo">072</span> UTIL.startMiniCluster(2);<a name="line.72"></a> -<span class="sourceLineNo">073</span> UTIL.waitUntilNoRegionsInTransition();<a name="line.73"></a> -<span class="sourceLineNo">074</span> }<a name="line.74"></a> -<span class="sourceLineNo">075</span><a name="line.75"></a> -<span class="sourceLineNo">076</span> @AfterClass<a name="line.76"></a> -<span class="sourceLineNo">077</span> public static void cleanupTest() throws Exception {<a name="line.77"></a> -<span class="sourceLineNo">078</span> try {<a name="line.78"></a> -<span class="sourceLineNo">079</span> UTIL.shutdownMiniCluster();<a name="line.79"></a> -<span class="sourceLineNo">080</span> } catch (Exception e) {<a name="line.80"></a> -<span class="sourceLineNo">081</span> LOG.warn("failure shutting down cluster", e);<a name="line.81"></a> -<span class="sourceLineNo">082</span> }<a name="line.82"></a> -<span class="sourceLineNo">083</span> }<a name="line.83"></a> -<span class="sourceLineNo">084</span><a name="line.84"></a> -<span class="sourceLineNo">085</span> @After<a name="line.85"></a> -<span class="sourceLineNo">086</span> public void tearDown() throws Exception {<a name="line.86"></a> -<span class="sourceLineNo">087</span> for (TableDescriptor htd: UTIL.getAdmin().listTableDescriptors()) {<a name="line.87"></a> -<span class="sourceLineNo">088</span> LOG.info("Tear down, remove table=" + htd.getTableName());<a name="line.88"></a> -<span class="sourceLineNo">089</span> UTIL.deleteTable(htd.getTableName());<a name="line.89"></a> -<span class="sourceLineNo">090</span> }<a name="line.90"></a> -<span class="sourceLineNo">091</span> }<a name="line.91"></a> -<span class="sourceLineNo">092</span><a name="line.92"></a> -<span class="sourceLineNo">093</span> @Test<a name="line.93"></a> -<span class="sourceLineNo">094</span> public void testMasterInitializedEvent() throws Exception {<a name="line.94"></a> -<span class="sourceLineNo">095</span> final TableName tableName = TableName.valueOf(name.getMethodName());<a name="line.95"></a> -<span class="sourceLineNo">096</span> HMaster master = UTIL.getMiniHBaseCluster().getMaster();<a name="line.96"></a> -<span class="sourceLineNo">097</span> ProcedureExecutor<MasterProcedureEnv> procExec = master.getMasterProcedureExecutor();<a name="line.97"></a> -<span class="sourceLineNo">098</span><a name="line.98"></a> -<span class="sourceLineNo">099</span> RegionInfo hri = RegionInfoBuilder.newBuilder(tableName).build();<a name="line.99"></a> -<span class="sourceLineNo">100</span> TableDescriptor htd = TableDescriptorBuilder.newBuilder(tableName)<a name="line.100"></a> -<span class="sourceLineNo">101</span> .setColumnFamily(ColumnFamilyDescriptorBuilder.of("f")).build();<a name="line.101"></a> -<span class="sourceLineNo">102</span><a name="line.102"></a> -<span class="sourceLineNo">103</span> while (!master.isInitialized()) {<a name="line.103"></a> -<span class="sourceLineNo">104</span> Thread.sleep(250);<a name="line.104"></a> -<span class="sourceLineNo">105</span> }<a name="line.105"></a> -<span class="sourceLineNo">106</span> master.setInitialized(false); // fake it, set back later<a name="line.106"></a> -<span class="sourceLineNo">107</span><a name="line.107"></a> -<span class="sourceLineNo">108</span> // check event wait/wake<a name="line.108"></a> -<span class="sourceLineNo">109</span> testProcedureEventWaitWake(master, master.getInitializedEvent(),<a name="line.109"></a> -<span class="sourceLineNo">110</span> new CreateTableProcedure(procExec.getEnvironment(), htd, new RegionInfo[] { hri }));<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> private void testProcedureEventWaitWake(final HMaster master, final ProcedureEvent<?> event,<a name="line.113"></a> -<span class="sourceLineNo">114</span> final Procedure<MasterProcedureEnv> proc) throws Exception {<a name="line.114"></a> -<span class="sourceLineNo">115</span> final ProcedureExecutor<MasterProcedureEnv> procExec = master.getMasterProcedureExecutor();<a name="line.115"></a> -<span class="sourceLineNo">116</span> final MasterProcedureScheduler procSched = procExec.getEnvironment().getProcedureScheduler();<a name="line.116"></a> -<span class="sourceLineNo">117</span><a name="line.117"></a> -<span class="sourceLineNo">118</span> final long startPollCalls = procSched.getPollCalls();<a name="line.118"></a> -<span class="sourceLineNo">119</span> final long startNullPollCalls = procSched.getNullPollCalls();<a name="line.119"></a> -<span class="sourceLineNo">120</span><a name="line.120"></a> -<span class="sourceLineNo">121</span> // check that nothing is in the event queue<a name="line.121"></a> -<span class="sourceLineNo">122</span> LOG.debug("checking " + event);<a name="line.122"></a> -<span class="sourceLineNo">123</span> assertEquals(false, event.isReady());<a name="line.123"></a> -<span class="sourceLineNo">124</span> assertEquals(0, event.getSuspendedProcedures().size());<a name="line.124"></a> -<span class="sourceLineNo">125</span><a name="line.125"></a> -<span class="sourceLineNo">126</span> // submit the procedure<a name="line.126"></a> -<span class="sourceLineNo">127</span> LOG.debug("submit " + proc);<a name="line.127"></a> -<span class="sourceLineNo">128</span> long procId = procExec.submitProcedure(proc);<a name="line.128"></a> -<span class="sourceLineNo">129</span><a name="line.129"></a> -<span class="sourceLineNo">130</span> // wait until the event is in the queue (proc executed and got into suspended state)<a name="line.130"></a> -<span class="sourceLineNo">131</span> LOG.debug("wait procedure suspended on " + event);<a name="line.131"></a> -<span class="sourceLineNo">132</span> while (event.getSuspendedProcedures().size() < 1) Thread.sleep(25);<a name="line.132"></a> -<span class="sourceLineNo">133</span><a name="line.133"></a> -<span class="sourceLineNo">134</span> // check that the proc is in the event queue<a name="line.134"></a> -<span class="sourceLineNo">135</span> LOG.debug("checking " + event + " size=" + event.getSuspendedProcedures().size());<a name="line.135"></a> -<span class="sourceLineNo">136</span> assertEquals(false, event.isReady());<a name="line.136"></a> -<span class="sourceLineNo">137</span> assertEquals(1, event.getSuspendedProcedures().size());<a name="line.137"></a> -<span class="sourceLineNo">138</span><a name="line.138"></a> -<span class="sourceLineNo">139</span> // wake the event<a name="line.139"></a> -<span class="sourceLineNo">140</span> LOG.debug("wake " + event);<a name="line.140"></a> -<span class="sourceLineNo">141</span> event.wake(procSched);<a name="line.141"></a> -<span class="sourceLineNo">142</span> assertEquals(true, event.isReady());<a name="line.142"></a> -<span class="sourceLineNo">143</span><a name="line.143"></a> -<span class="sourceLineNo">144</span> // wait until proc completes<a name="line.144"></a> -<span class="sourceLineNo">145</span> LOG.debug("waiting " + proc);<a name="line.145"></a> -<span class="sourceLineNo">146</span> ProcedureTestingUtility.waitProcedure(procExec, procId);<a name="line.146"></a> -<span class="sourceLineNo">147</span><a name="line.147"></a> -<span class="sourceLineNo">148</span> // check that nothing is in the event queue and the event is not suspended<a name="line.148"></a> +<span class="sourceLineNo">061</span> private static final Logger LOG = LoggerFactory.getLogger(TestCreateTableProcedure.class);<a name="line.61"></a> +<span class="sourceLineNo">062</span><a name="line.62"></a> +<span class="sourceLineNo">063</span> protected static final HBaseTestingUtility UTIL = new HBaseTestingUtility();<a name="line.63"></a> +<span class="sourceLineNo">064</span><a name="line.64"></a> +<span class="sourceLineNo">065</span> @Rule<a name="line.65"></a> +<span class="sourceLineNo">066</span> public TestName name = new TestName();<a name="line.66"></a> +<span class="sourceLineNo">067</span><a name="line.67"></a> +<span class="sourceLineNo">068</span> private static void setupConf(Configuration conf) throws IOException {<a name="line.68"></a> +<span class="sourceLineNo">069</span> conf.setInt(MasterProcedureConstants.MASTER_PROCEDURE_THREADS, 1);<a name="line.69"></a> +<span class="sourceLineNo">070</span> conf.setBoolean(WALProcedureStore.USE_HSYNC_CONF_KEY, false);<a name="line.70"></a> +<span class="sourceLineNo">071</span> }<a name="line.71"></a> +<span class="sourceLineNo">072</span><a name="line.72"></a> +<span class="sourceLineNo">073</span> @BeforeClass<a name="line.73"></a> +<span class="sourceLineNo">074</span> public static void setupCluster() throws Exception {<a name="line.74"></a> +<span class="sourceLineNo">075</span> Configuration conf = UTIL.getConfiguration();<a name="line.75"></a> +<span class="sourceLineNo">076</span> setupConf(UTIL.getConfiguration());<a name="line.76"></a> +<span class="sourceLineNo">077</span> UTIL.startMiniDFSCluster(3);<a name="line.77"></a> +<span class="sourceLineNo">078</span> CommonFSUtils.setWALRootDir(conf, new Path(conf.get("fs.defaultFS"), "/tmp/wal"));<a name="line.78"></a> +<span class="sourceLineNo">079</span> UTIL.startMiniCluster(2);<a name="line.79"></a> +<span class="sourceLineNo">080</span> UTIL.waitUntilNoRegionsInTransition();<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> @AfterClass<a name="line.83"></a> +<span class="sourceLineNo">084</span> public static void cleanupTest() throws Exception {<a name="line.84"></a> +<span class="sourceLineNo">085</span> try {<a name="line.85"></a> +<span class="sourceLineNo">086</span> UTIL.shutdownMiniCluster();<a name="line.86"></a> +<span class="sourceLineNo">087</span> } catch (Exception e) {<a name="line.87"></a> +<span class="sourceLineNo">088</span> LOG.warn("failure shutting down cluster", e);<a name="line.88"></a> +<span class="sourceLineNo">089</span> }<a name="line.89"></a> +<span class="sourceLineNo">090</span> }<a name="line.90"></a> +<span class="sourceLineNo">091</span><a name="line.91"></a> +<span class="sourceLineNo">092</span> @After<a name="line.92"></a> +<span class="sourceLineNo">093</span> public void tearDown() throws Exception {<a name="line.93"></a> +<span class="sourceLineNo">094</span> for (TableDescriptor htd: UTIL.getAdmin().listTableDescriptors()) {<a name="line.94"></a> +<span class="sourceLineNo">095</span> LOG.info("Tear down, remove table=" + htd.getTableName());<a name="line.95"></a> +<span class="sourceLineNo">096</span> UTIL.deleteTable(htd.getTableName());<a name="line.96"></a> +<span class="sourceLineNo">097</span> }<a name="line.97"></a> +<span class="sourceLineNo">098</span> }<a name="line.98"></a> +<span class="sourceLineNo">099</span><a name="line.99"></a> +<span class="sourceLineNo">100</span> @Test<a name="line.100"></a> +<span class="sourceLineNo">101</span> public void testMasterInitializedEvent() throws Exception {<a name="line.101"></a> +<span class="sourceLineNo">102</span> final TableName tableName = TableName.valueOf(name.getMethodName());<a name="line.102"></a> +<span class="sourceLineNo">103</span> HMaster master = UTIL.getMiniHBaseCluster().getMaster();<a name="line.103"></a> +<span class="sourceLineNo">104</span> ProcedureExecutor<MasterProcedureEnv> procExec = master.getMasterProcedureExecutor();<a name="line.104"></a> +<span class="sourceLineNo">105</span><a name="line.105"></a> +<span class="sourceLineNo">106</span> RegionInfo hri = RegionInfoBuilder.newBuilder(tableName).build();<a name="line.106"></a> +<span class="sourceLineNo">107</span> TableDescriptor htd = TableDescriptorBuilder.newBuilder(tableName)<a name="line.107"></a> +<span class="sourceLineNo">108</span> .setColumnFamily(ColumnFamilyDescriptorBuilder.of("f")).build();<a name="line.108"></a> +<span class="sourceLineNo">109</span><a name="line.109"></a> +<span class="sourceLineNo">110</span> while (!master.isInitialized()) {<a name="line.110"></a> +<span class="sourceLineNo">111</span> Thread.sleep(250);<a name="line.111"></a> +<span class="sourceLineNo">112</span> }<a name="line.112"></a> +<span class="sourceLineNo">113</span> master.setInitialized(false); // fake it, set back later<a name="line.113"></a> +<span class="sourceLineNo">114</span><a name="line.114"></a> +<span class="sourceLineNo">115</span> // check event wait/wake<a name="line.115"></a> +<span class="sourceLineNo">116</span> testProcedureEventWaitWake(master, master.getInitializedEvent(),<a name="line.116"></a> +<span class="sourceLineNo">117</span> new CreateTableProcedure(procExec.getEnvironment(), htd, new RegionInfo[] { hri }));<a name="line.117"></a> +<span class="sourceLineNo">118</span> }<a name="line.118"></a> +<span class="sourceLineNo">119</span><a name="line.119"></a> +<span class="sourceLineNo">120</span> private void testProcedureEventWaitWake(final HMaster master, final ProcedureEvent<?> event,<a name="line.120"></a> +<span class="sourceLineNo">121</span> final Procedure<MasterProcedureEnv> proc) throws Exception {<a name="line.121"></a> +<span class="sourceLineNo">122</span> final ProcedureExecutor<MasterProcedureEnv> procExec = master.getMasterProcedureExecutor();<a name="line.122"></a> +<span class="sourceLineNo">123</span> final MasterProcedureScheduler procSched = procExec.getEnvironment().getProcedureScheduler();<a name="line.123"></a> +<span class="sourceLineNo">124</span><a name="line.124"></a> +<span class="sourceLineNo">125</span> final long startPollCalls = procSched.getPollCalls();<a name="line.125"></a> +<span class="sourceLineNo">126</span> final long startNullPollCalls = procSched.getNullPollCalls();<a name="line.126"></a> +<span class="sourceLineNo">127</span><a name="line.127"></a> +<span class="sourceLineNo">128</span> // check that nothing is in the event queue<a name="line.128"></a> +<span class="sourceLineNo">129</span> LOG.debug("checking " + event);<a name="line.129"></a> +<span class="sourceLineNo">130</span> assertEquals(false, event.isReady());<a name="line.130"></a> +<span class="sourceLineNo">131</span> assertEquals(0, event.getSuspendedProcedures().size());<a name="line.131"></a> +<span class="sourceLineNo">132</span><a name="line.132"></a> +<span class="sourceLineNo">133</span> // submit the procedure<a name="line.133"></a> +<span class="sourceLineNo">134</span> LOG.debug("submit " + proc);<a name="line.134"></a> +<span class="sourceLineNo">135</span> long procId = procExec.submitProcedure(proc);<a name="line.135"></a> +<span class="sourceLineNo">136</span><a name="line.136"></a> +<span class="sourceLineNo">137</span> // wait until the event is in the queue (proc executed and got into suspended state)<a name="line.137"></a> +<span class="sourceLineNo">138</span> LOG.debug("wait procedure suspended on " + event);<a name="line.138"></a> +<span class="sourceLineNo">139</span> while (event.getSuspendedProcedures().size() < 1) Thread.sleep(25);<a name="line.139"></a> +<span class="sourceLineNo">140</span><a name="line.140"></a> +<span class="sourceLineNo">141</span> // check that the proc is in the event queue<a name="line.141"></a> +<span class="sourceLineNo">142</span> LOG.debug("checking " + event + " size=" + event.getSuspendedProcedures().size());<a name="line.142"></a> +<span class="sourceLineNo">143</span> assertEquals(false, event.isReady());<a name="line.143"></a> +<span class="sourceLineNo">144</span> assertEquals(1, event.getSuspendedProcedures().size());<a name="line.144"></a> +<span class="sourceLineNo">145</span><a name="line.145"></a> +<span class="sourceLineNo">146</span> // wake the event<a name="line.146"></a> +<span class="sourceLineNo">147</span> LOG.debug("wake " + event);<a name="line.147"></a> +<span class="sourceLineNo">148</span> event.wake(procSched);<a name="line.148"></a> <span class="sourceLineNo">149</span> assertEquals(true, event.isReady());<a name="line.149"></a> -<span class="sourceLineNo">150</span> assertEquals(0, event.getSuspendedProcedures().size());<a name="line.150"></a> -<span class="sourceLineNo">151</span> LOG.debug("completed execution of " + proc +<a name="line.151"></a> -<span class="sourceLineNo">152</span> " pollCalls=" + (procSched.getPollCalls() - startPollCalls) +<a name="line.152"></a> -<span class="sourceLineNo">153</span> " nullPollCalls=" + (procSched.getNullPollCalls() - startNullPollCalls));<a name="line.153"></a> -<span class="sourceLineNo">154</span> }<a name="line.154"></a> -<span class="sourceLineNo">155</span>}<a name="line.155"></a> +<span class="sourceLineNo">150</span><a name="line.150"></a> +<span class="sourceLineNo">151</span> // wait until proc completes<a name="line.151"></a> +<span class="sourceLineNo">152</span> LOG.debug("waiting " + proc);<a name="line.152"></a> +<span class="sourceLineNo">153</span> ProcedureTestingUtility.waitProcedure(procExec, procId);<a name="line.153"></a> +<span class="sourceLineNo">154</span><a name="line.154"></a> +<span class="sourceLineNo">155</span> // check that nothing is in the event queue and the event is not suspended<a name="line.155"></a> +<span class="sourceLineNo">156</span> assertEquals(true, event.isReady());<a name="line.156"></a> +<span class="sourceLineNo">157</span> assertEquals(0, event.getSuspendedProcedures().size());<a name="line.157"></a> +<span class="sourceLineNo">158</span> LOG.debug("completed execution of " + proc +<a name="line.158"></a> +<span class="sourceLineNo">159</span> " pollCalls=" + (procSched.getPollCalls() - startPollCalls) +<a name="line.159"></a> +<span class="sourceLineNo">160</span> " nullPollCalls=" + (procSched.getNullPollCalls() - startNullPollCalls));<a name="line.160"></a> +<span class="sourceLineNo">161</span> }<a name="line.161"></a> +<span class="sourceLineNo">162</span>}<a name="line.162"></a> http://git-wip-us.apache.org/repos/asf/hbase-site/blob/b9b09fec/testdevapidocs/src-html/org/apache/hadoop/hbase/master/procedure/TestWALProcedureStoreOnHDFS.html ---------------------------------------------------------------------- diff --git a/testdevapidocs/src-html/org/apache/hadoop/hbase/master/procedure/TestWALProcedureStoreOnHDFS.html b/testdevapidocs/src-html/org/apache/hadoop/hbase/master/procedure/TestWALProcedureStoreOnHDFS.html index e5b71af..0e9d7bc 100644 --- a/testdevapidocs/src-html/org/apache/hadoop/hbase/master/procedure/TestWALProcedureStoreOnHDFS.html +++ b/testdevapidocs/src-html/org/apache/hadoop/hbase/master/procedure/TestWALProcedureStoreOnHDFS.html @@ -41,174 +41,177 @@ <span class="sourceLineNo">033</span>import org.apache.hadoop.hbase.procedure2.store.wal.WALProcedureStore;<a name="line.33"></a> <span class="sourceLineNo">034</span>import org.apache.hadoop.hbase.testclassification.LargeTests;<a name="line.34"></a> <span class="sourceLineNo">035</span>import org.apache.hadoop.hbase.testclassification.MasterTests;<a name="line.35"></a> -<span class="sourceLineNo">036</span>import org.apache.hadoop.hbase.util.Threads;<a name="line.36"></a> -<span class="sourceLineNo">037</span>import org.apache.hadoop.hdfs.MiniDFSCluster;<a name="line.37"></a> -<span class="sourceLineNo">038</span>import org.apache.hadoop.hdfs.server.datanode.DataNode;<a name="line.38"></a> -<span class="sourceLineNo">039</span>import org.junit.Before;<a name="line.39"></a> -<span class="sourceLineNo">040</span>import org.junit.ClassRule;<a name="line.40"></a> -<span class="sourceLineNo">041</span>import org.junit.Test;<a name="line.41"></a> -<span class="sourceLineNo">042</span>import org.junit.experimental.categories.Category;<a name="line.42"></a> -<span class="sourceLineNo">043</span>import org.slf4j.Logger;<a name="line.43"></a> -<span class="sourceLineNo">044</span>import org.slf4j.LoggerFactory;<a name="line.44"></a> -<span class="sourceLineNo">045</span><a name="line.45"></a> -<span class="sourceLineNo">046</span>@Category({MasterTests.class, LargeTests.class})<a name="line.46"></a> -<span class="sourceLineNo">047</span>public class TestWALProcedureStoreOnHDFS {<a name="line.47"></a> -<span class="sourceLineNo">048</span><a name="line.48"></a> -<span class="sourceLineNo">049</span> @ClassRule<a name="line.49"></a> -<span class="sourceLineNo">050</span> public static final HBaseClassTestRule CLASS_RULE =<a name="line.50"></a> -<span class="sourceLineNo">051</span> HBaseClassTestRule.forClass(TestWALProcedureStoreOnHDFS.class);<a name="line.51"></a> -<span class="sourceLineNo">052</span><a name="line.52"></a> -<span class="sourceLineNo">053</span> private static final Logger LOG = LoggerFactory.getLogger(TestWALProcedureStoreOnHDFS.class);<a name="line.53"></a> -<span class="sourceLineNo">054</span><a name="line.54"></a> -<span class="sourceLineNo">055</span> protected static final 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 WALProcedureStore store;<a name="line.57"></a> -<span class="sourceLineNo">058</span><a name="line.58"></a> -<span class="sourceLineNo">059</span> private ProcedureStore.ProcedureStoreListener stopProcedureListener = new ProcedureStore.ProcedureStoreListener() {<a name="line.59"></a> -<span class="sourceLineNo">060</span> @Override<a name="line.60"></a> -<span class="sourceLineNo">061</span> public void postSync() {}<a name="line.61"></a> -<span class="sourceLineNo">062</span><a name="line.62"></a> -<span class="sourceLineNo">063</span> @Override<a name="line.63"></a> -<span class="sourceLineNo">064</span> public void abortProcess() {<a name="line.64"></a> -<span class="sourceLineNo">065</span> LOG.error(HBaseMarkers.FATAL, "Abort the Procedure Store");<a name="line.65"></a> -<span class="sourceLineNo">066</span> store.stop(true);<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><a name="line.69"></a> -<span class="sourceLineNo">070</span> @Before<a name="line.70"></a> -<span class="sourceLineNo">071</span> public void initConfig() {<a name="line.71"></a> -<span class="sourceLineNo">072</span> Configuration conf = UTIL.getConfiguration();<a name="line.72"></a> -<span class="sourceLineNo">073</span><a name="line.73"></a> -<span class="sourceLineNo">074</span> conf.setInt("dfs.replication", 3);<a name="line.74"></a> -<span class="sourceLineNo">075</span> conf.setInt("dfs.namenode.replication.min", 3);<a name="line.75"></a> -<span class="sourceLineNo">076</span><a name="line.76"></a> -<span class="sourceLineNo">077</span> // increase the value for slow test-env<a name="line.77"></a> -<span class="sourceLineNo">078</span> conf.setInt(WALProcedureStore.WAIT_BEFORE_ROLL_CONF_KEY, 1000);<a name="line.78"></a> -<span class="sourceLineNo">079</span> conf.setInt(WALProcedureStore.ROLL_RETRIES_CONF_KEY, 10);<a name="line.79"></a> -<span class="sourceLineNo">080</span> conf.setInt(WALProcedureStore.MAX_SYNC_FAILURE_ROLL_CONF_KEY, 10);<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> // No @Before because some tests need to do additional config first<a name="line.83"></a> -<span class="sourceLineNo">084</span> private void setupDFS() throws Exception {<a name="line.84"></a> -<span class="sourceLineNo">085</span> MiniDFSCluster dfs = UTIL.startMiniDFSCluster(3);<a name="line.85"></a> -<span class="sourceLineNo">086</span><a name="line.86"></a> -<span class="sourceLineNo">087</span> Path logDir = new Path(new Path(dfs.getFileSystem().getUri()), "/test-logs");<a name="line.87"></a> -<span class="sourceLineNo">088</span> store = ProcedureTestingUtility.createWalStore(UTIL.getConfiguration(), logDir);<a name="line.88"></a> -<span class="sourceLineNo">089</span> store.registerListener(stopProcedureListener);<a name="line.89"></a> -<span class="sourceLineNo">090</span> store.start(8);<a name="line.90"></a> -<span class="sourceLineNo">091</span> store.recoverLease();<a name="line.91"></a> -<span class="sourceLineNo">092</span> }<a name="line.92"></a> -<span class="sourceLineNo">093</span><a name="line.93"></a> -<span class="sourceLineNo">094</span> // No @After<a name="line.94"></a> -<span class="sourceLineNo">095</span> @SuppressWarnings("JUnit4TearDownNotRun")<a name="line.95"></a> -<span class="sourceLineNo">096</span> public void tearDown() throws Exception {<a name="line.96"></a> -<span class="sourceLineNo">097</span> store.stop(false);<a name="line.97"></a> -<span class="sourceLineNo">098</span> UTIL.getDFSCluster().getFileSystem().delete(store.getWALDir(), true);<a name="line.98"></a> -<span class="sourceLineNo">099</span><a name="line.99"></a> -<span class="sourceLineNo">100</span> try {<a name="line.100"></a> -<span class="sourceLineNo">101</span> UTIL.shutdownMiniCluster();<a name="line.101"></a> -<span class="sourceLineNo">102</span> } catch (Exception e) {<a name="line.102"></a> -<span class="sourceLineNo">103</span> LOG.warn("failure shutting down cluster", e);<a name="line.103"></a> -<span class="sourceLineNo">104</span> }<a name="line.104"></a> -<span class="sourceLineNo">105</span> }<a name="line.105"></a> -<span class="sourceLineNo">106</span><a name="line.106"></a> -<span class="sourceLineNo">107</span> @Test(expected=RuntimeException.class)<a name="line.107"></a> -<span class="sourceLineNo">108</span> public void testWalAbortOnLowReplication() throws Exception {<a name="line.108"></a> -<span class="sourceLineNo">109</span> setupDFS();<a name="line.109"></a> -<span class="sourceLineNo">110</span><a name="line.110"></a> -<span class="sourceLineNo">111</span> assertEquals(3, UTIL.getDFSCluster().getDataNodes().size());<a name="line.111"></a> -<span class="sourceLineNo">112</span><a name="line.112"></a> -<span class="sourceLineNo">113</span> LOG.info("Stop DataNode");<a name="line.113"></a> -<span class="sourceLineNo">114</span> UTIL.getDFSCluster().stopDataNode(0);<a name="line.114"></a> -<span class="sourceLineNo">115</span> assertEquals(2, UTIL.getDFSCluster().getDataNodes().size());<a name="line.115"></a> -<span class="sourceLineNo">116</span><a name="line.116"></a> -<span class="sourceLineNo">117</span> store.insert(new TestProcedure(1, -1), null);<a name="line.117"></a> -<span class="sourceLineNo">118</span> for (long i = 2; store.isRunning(); ++i) {<a name="line.118"></a> -<span class="sourceLineNo">119</span> assertEquals(2, UTIL.getDFSCluster().getDataNodes().size());<a name="line.119"></a> -<span class="sourceLineNo">120</span> store.insert(new TestProcedure(i, -1), null);<a name="line.120"></a> -<span class="sourceLineNo">121</span> Thread.sleep(100);<a name="line.121"></a> -<span class="sourceLineNo">122</span> }<a name="line.122"></a> -<span class="sourceLineNo">123</span> assertFalse(store.isRunning());<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> @Test<a name="line.126"></a> -<span class="sourceLineNo">127</span> public void testWalAbortOnLowReplicationWithQueuedWriters() throws Exception {<a name="line.127"></a> -<span class="sourceLineNo">128</span> setupDFS();<a name="line.128"></a> -<span class="sourceLineNo">129</span><a name="line.129"></a> -<span class="sourceLineNo">130</span> assertEquals(3, UTIL.getDFSCluster().getDataNodes().size());<a name="line.130"></a> -<span class="sourceLineNo">131</span> store.registerListener(new ProcedureStore.ProcedureStoreListener() {<a name="line.131"></a> -<span class="sourceLineNo">132</span> @Override<a name="line.132"></a> -<span class="sourceLineNo">133</span> public void postSync() { Threads.sleepWithoutInterrupt(2000); }<a name="line.133"></a> -<span class="sourceLineNo">134</span><a name="line.134"></a> +<span class="sourceLineNo">036</span>import org.apache.hadoop.hbase.util.CommonFSUtils;<a name="line.36"></a> +<span class="sourceLineNo">037</span>import org.apache.hadoop.hbase.util.Threads;<a name="line.37"></a> +<span class="sourceLineNo">038</span>import org.apache.hadoop.hdfs.MiniDFSCluster;<a name="line.38"></a> +<span class="sourceLineNo">039</span>import org.apache.hadoop.hdfs.server.datanode.DataNode;<a name="line.39"></a> +<span class="sourceLineNo">040</span>import org.junit.Before;<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 TestWALProcedureStoreOnHDFS {<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(TestWALProcedureStoreOnHDFS.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(TestWALProcedureStoreOnHDFS.class);<a name="line.54"></a> +<span class="sourceLineNo">055</span><a name="line.55"></a> +<span class="sourceLineNo">056</span> protected static final 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 WALProcedureStore store;<a name="line.58"></a> +<span class="sourceLineNo">059</span><a name="line.59"></a> +<span class="sourceLineNo">060</span> private ProcedureStore.ProcedureStoreListener stopProcedureListener = new ProcedureStore.ProcedureStoreListener() {<a name="line.60"></a> +<span class="sourceLineNo">061</span> @Override<a name="line.61"></a> +<span class="sourceLineNo">062</span> public void postSync() {}<a name="line.62"></a> +<span class="sourceLineNo">063</span><a name="line.63"></a> +<span class="sourceLineNo">064</span> @Override<a name="line.64"></a> +<span class="sourceLineNo">065</span> public void abortProcess() {<a name="line.65"></a> +<span class="sourceLineNo">066</span> LOG.error(HBaseMarkers.FATAL, "Abort the Procedure Store");<a name="line.66"></a> +<span class="sourceLineNo">067</span> store.stop(true);<a name="line.67"></a> +<span class="sourceLineNo">068</span> }<a name="line.68"></a> +<span class="sourceLineNo">069</span> };<a name="line.69"></a> +<span class="sourceLineNo">070</span><a name="line.70"></a> +<span class="sourceLineNo">071</span> @Before<a name="line.71"></a> +<span class="sourceLineNo">072</span> public void initConfig() {<a name="line.72"></a> +<span class="sourceLineNo">073</span> Configuration conf = UTIL.getConfiguration();<a name="line.73"></a> +<span class="sourceLineNo">074</span><a name="line.74"></a> +<span class="sourceLineNo">075</span> conf.setInt("dfs.replication", 3);<a name="line.75"></a> +<span class="sourceLineNo">076</span> conf.setInt("dfs.namenode.replication.min", 3);<a name="line.76"></a> +<span class="sourceLineNo">077</span><a name="line.77"></a> +<span class="sourceLineNo">078</span> // increase the value for slow test-env<a name="line.78"></a> +<span class="sourceLineNo">079</span> conf.setInt(WALProcedureStore.WAIT_BEFORE_ROLL_CONF_KEY, 1000);<a name="line.79"></a> +<span class="sourceLineNo">080</span> conf.setInt(WALProcedureStore.ROLL_RETRIES_CONF_KEY, 10);<a name="line.80"></a> +<span class="sourceLineNo">081</span> conf.setInt(WALProcedureStore.MAX_SYNC_FAILURE_ROLL_CONF_KEY, 10);<a name="line.81"></a> +<span class="sourceLineNo">082</span> }<a name="line.82"></a> +<span class="sourceLineNo">083</span><a name="line.83"></a> +<span class="sourceLineNo">084</span> // No @Before because some tests need to do additional config first<a name="line.84"></a> +<span class="sourceLineNo">085</span> private void setupDFS() throws Exception {<a name="line.85"></a> +<span class="sourceLineNo">086</span> Configuration conf = UTIL.getConfiguration();<a name="line.86"></a> +<span class="sourceLineNo">087</span> MiniDFSCluster dfs = UTIL.startMiniDFSCluster(3);<a name="line.87"></a> +<span class="sourceLineNo">088</span> CommonFSUtils.setWALRootDir(conf, new Path(conf.get("fs.defaultFS"), "/tmp/wal"));<a name="line.88"></a> +<span class="sourceLineNo">089</span><a name="line.89"></a> +<span class="sourceLineNo">090</span> Path logDir = new Path(new Path(dfs.getFileSystem().getUri()), "/test-logs");<a name="line.90"></a> +<span class="sourceLineNo">091</span> store = ProcedureTestingUtility.createWalStore(conf, logDir);<a name="line.91"></a> +<span class="sourceLineNo">092</span> store.registerListener(stopProcedureListener);<a name="line.92"></a> +<span class="sourceLineNo">093</span> store.start(8);<a name="line.93"></a> +<span class="sourceLineNo">094</span> store.recoverLease();<a name="line.94"></a> +<span class="sourceLineNo">095</span> }<a name="line.95"></a> +<span class="sourceLineNo">096</span><a name="line.96"></a> +<span class="sourceLineNo">097</span> // No @After<a name="line.97"></a> +<span class="sourceLineNo">098</span> @SuppressWarnings("JUnit4TearDownNotRun")<a name="line.98"></a> +<span class="sourceLineNo">099</span> public void tearDown() throws Exception {<a name="line.99"></a> +<span class="sourceLineNo">100</span> store.stop(false);<a name="line.100"></a> +<span class="sourceLineNo">101</span> UTIL.getDFSCluster().getFileSystem().delete(store.getWALDir(), true);<a name="line.101"></a> +<span class="sourceLineNo">102</span><a name="line.102"></a> +<span class="sourceLineNo">103</span> try {<a name="line.103"></a> +<span class="sourceLineNo">104</span> UTIL.shutdownMiniCluster();<a name="line.104"></a> +<span class="sourceLineNo">105</span> } catch (Exception e) {<a name="line.105"></a> +<span class="sourceLineNo">106</span> LOG.warn("failure shutting down cluster", e);<a name="line.106"></a> +<span class="sourceLineNo">107</span> }<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> @Test(expected=RuntimeException.class)<a name="line.110"></a> +<span class="sourceLineNo">111</span> public void testWalAbortOnLowReplication() throws Exception {<a name="line.111"></a> +<span class="sourceLineNo">112</span> setupDFS();<a name="line.112"></a> +<span class="sourceLineNo">113</span><a name="line.113"></a> +<span class="sourceLineNo">114</span> assertEquals(3, UTIL.getDFSCluster().getDataNodes().size());<a name="line.114"></a> +<span class="sourceLineNo">115</span><a name="line.115"></a> +<span class="sourceLineNo">116</span> LOG.info("Stop DataNode");<a name="line.116"></a> +<span class="sourceLineNo">117</span> UTIL.getDFSCluster().stopDataNode(0);<a name="line.117"></a> +<span class="sourceLineNo">118</span> assertEquals(2, UTIL.getDFSCluster().getDataNodes().size());<a name="line.118"></a> +<span class="sourceLineNo">119</span><a name="line.119"></a> +<span class="sourceLineNo">120</span> store.insert(new TestProcedure(1, -1), null);<a name="line.120"></a> +<span class="sourceLineNo">121</span> for (long i = 2; store.isRunning(); ++i) {<a name="line.121"></a> +<span class="sourceLineNo">122</span> assertEquals(2, UTIL.getDFSCluster().getDataNodes().size());<a name="line.122"></a> +<span class="sourceLineNo">123</span> store.insert(new TestProcedure(i, -1), null);<a name="line.123"></a> +<span class="sourceLineNo">124</span> Thread.sleep(100);<a name="line.124"></a> +<span class="sourceLineNo">125</span> }<a name="line.125"></a> +<span class="sourceLineNo">126</span> assertFalse(store.isRunning());<a name="line.126"></a> +<span class="sourceLineNo">127</span> }<a name="line.127"></a> +<span class="sourceLineNo">128</span><a name="line.128"></a> +<span class="sourceLineNo">129</span> @Test<a name="line.129"></a> +<span class="sourceLineNo">130</span> public void testWalAbortOnLowReplicationWithQueuedWriters() throws Exception {<a name="line.130"></a> +<span class="sourceLineNo">131</span> setupDFS();<a name="line.131"></a> +<span class="sourceLineNo">132</span><a name="line.132"></a> +<span class="sourceLineNo">133</span> assertEquals(3, UTIL.getDFSCluster().getDataNodes().size());<a name="line.133"></a> +<span class="sourceLineNo">134</span> store.registerListener(new ProcedureStore.ProcedureStoreListener() {<a name="line.134"></a> <span class="sourceLineNo">135</span> @Override<a name="line.135"></a> -<span class="sourceLineNo">136</span> public void abortProcess() {}<a name="line.136"></a> -<span class="sourceLineNo">137</span> });<a name="line.137"></a> -<span class="sourceLineNo">138</span><a name="line.138"></a> -<span class="sourceLineNo">139</span> final AtomicInteger reCount = new AtomicInteger(0);<a name="line.139"></a> -<span class="sourceLineNo">140</span> Thread[] thread = new Thread[store.getNumThreads() * 2 + 1];<a name="line.140"></a> -<span class="sourceLineNo">141</span> for (int i = 0; i < thread.length; ++i) {<a name="line.141"></a> -<span class="sourceLineNo">142</span> final long procId = i + 1L;<a name="line.142"></a> -<span class="sourceLineNo">143</span> thread[i] = new Thread(() -> {<a name="line.143"></a> -<span class="sourceLineNo">144</span> try {<a name="line.144"></a> -<span class="sourceLineNo">145</span> LOG.debug("[S] INSERT " + procId);<a name="line.145"></a> -<span class="sourceLineNo">146</span> store.insert(new TestProcedure(procId, -1), null);<a name="line.146"></a> -<span class="sourceLineNo">147</span> LOG.debug("[E] INSERT " + procId);<a name="line.147"></a> -<span class="sourceLineNo">148</span> } catch (RuntimeException e) {<a name="line.148"></a> -<span class="sourceLineNo">149</span> reCount.incrementAndGet();<a name="line.149"></a> -<span class="sourceLineNo">150</span> LOG.debug("[F] INSERT " + procId + ": " + e.getMessage());<a name="line.150"></a> -<span class="sourceLineNo">151</span> }<a name="line.151"></a> -<span class="sourceLineNo">152</span> });<a name="line.152"></a> -<span class="sourceLineNo">153</span> thread[i].start();<a name="line.153"></a> -<span class="sourceLineNo">154</span> }<a name="line.154"></a> -<span class="sourceLineNo">155</span><a name="line.155"></a> -<span class="sourceLineNo">156</span> Thread.sleep(1000);<a name="line.156"></a> -<span class="sourceLineNo">157</span> LOG.info("Stop DataNode");<a name="line.157"></a> -<span class="sourceLineNo">158</span> UTIL.getDFSCluster().stopDataNode(0);<a name="line.158"></a> -<span class="sourceLineNo">159</span> assertEquals(2, UTIL.getDFSCluster().getDataNodes().size());<a name="line.159"></a> -<span class="sourceLineNo">160</span><a name="line.160"></a> -<span class="sourceLineNo">161</span> for (int i = 0; i < thread.length; ++i) {<a name="line.161"></a> -<span class="sourceLineNo">162</span> thread[i].join();<a name="line.162"></a> -<span class="sourceLineNo">163</span> }<a name="line.163"></a> -<span class="sourceLineNo">164</span><a name="line.164"></a> -<span class="sourceLineNo">165</span> assertFalse(store.isRunning());<a name="line.165"></a> -<span class="sourceLineNo">166</span> assertTrue(reCount.toString(), reCount.get() >= store.getNumThreads() &&<a name="line.166"></a> -<span class="sourceLineNo">167</span> reCount.get() < thread.length);<a name="line.167"></a> -<span class="sourceLineNo">168</span> }<a name="line.168"></a> -<span class="sourceLineNo">169</span><a name="line.169"></a> -<span class="sourceLineNo">170</span> @Test<a name="line.170"></a> -<span class="sourceLineNo">171</span> public void testWalRollOnLowReplication() throws Exception {<a name="line.171"></a> -<span class="sourceLineNo">172</span> UTIL.getConfiguration().setInt("dfs.namenode.replication.min", 1);<a name="line.172"></a> -<span class="sourceLineNo">173</span> setupDFS();<a name="line.173"></a> -<span class="sourceLineNo">174</span><a name="line.174"></a> -<span class="sourceLineNo">175</span> int dnCount = 0;<a name="line.175"></a> -<span class="sourceLineNo">176</span> store.insert(new TestProcedure(1, -1), null);<a name="line.176"></a> -<span class="sourceLineNo">177</span> UTIL.getDFSCluster().restartDataNode(dnCount);<a name="line.177"></a> -<span class="sourceLineNo">178</span> for (long i = 2; i < 100; ++i) {<a name="line.178"></a> -<span class="sourceLineNo">179</span> store.insert(new TestProcedure(i, -1), null);<a name="line.179"></a> -<span class="sourceLineNo">180</span> waitForNumReplicas(3);<a name="line.180"></a> -<span class="sourceLineNo">181</span> Thread.sleep(100);<a name="line.181"></a> -<span class="sourceLineNo">182</span> if ((i % 30) == 0) {<a name="line.182"></a> -<span class="sourceLineNo">183</span> LOG.info("Restart Data Node");<a name="line.183"></a> -<span class="sourceLineNo">184</span> UTIL.getDFSCluster().restartDataNode(++dnCount % 3);<a name="line.184"></a> -<span class="sourceLineNo">185</span> }<a name="line.185"></a> -<span class="sourceLineNo">186</span> }<a name="line.186"></a> -<span class="sourceLineNo">187</span> assertTrue(store.isRunning());<a name="line.187"></a> -<span class="sourceLineNo">188</span> }<a name="line.188"></a> -<span class="sourceLineNo">189</span><a name="line.189"></a> -<span class="sourceLineNo">190</span> public void waitForNumReplicas(int numReplicas) throws Exception {<a name="line.190"></a> -<span class="sourceLineNo">191</span> while (UTIL.getDFSCluster().getDataNodes().size() < numReplicas) {<a name="line.191"></a> -<span class="sourceLineNo">192</span> Thread.sleep(100);<a name="line.192"></a> -<span class="sourceLineNo">193</span> }<a name="line.193"></a> -<span class="sourceLineNo">194</span><a name="line.194"></a> -<span class="sourceLineNo">195</span> for (int i = 0; i < numReplicas; ++i) {<a name="line.195"></a> -<span class="sourceLineNo">196</span> for (DataNode dn: UTIL.getDFSCluster().getDataNodes()) {<a name="line.196"></a> -<span class="sourceLineNo">197</span> while (!dn.isDatanodeFullyStarted()) {<a name="line.197"></a> -<span class="sourceLineNo">198</span> Thread.sleep(100);<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> }<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">136</span> public void postSync() { Threads.sleepWithoutInterrupt(2000); }<a name="line.136"></a> +<span class="sourceLineNo">137</span><a name="line.137"></a> +<span class="sourceLineNo">138</span> @Override<a name="line.138"></a> +<span class="sourceLineNo">139</span> public void abortProcess() {}<a name="line.139"></a> +<span class="sourceLineNo">140</span> });<a name="line.140"></a> +<span class="sourceLineNo">141</span><a name="line.141"></a> +<span class="sourceLineNo">142</span> final AtomicInteger reCount = new AtomicInteger(0);<a name="line.142"></a> +<span class="sourceLineNo">143</span> Thread[] thread = new Thread[store.getNumThreads() * 2 + 1];<a name="line.143"></a> +<span class="sourceLineNo">144</span> for (int i = 0; i < thread.length; ++i) {<a name="line.144"></a> +<span class="sourceLineNo">145</span> final long procId = i + 1L;<a name="line.145"></a> +<span class="sourceLineNo">146</span> thread[i] = new Thread(() -> {<a name="line.146"></a> +<span class="sourceLineNo">147</span> try {<a name="line.147"></a> +<span class="sourceLineNo">148</span> LOG.debug("[S] INSERT " + procId);<a name="line.148"></a> +<span class="sourceLineNo">149</span> store.insert(new TestProcedure(procId, -1), null);<a name="line.149"></a> +<span class="sourceLineNo">150</span> LOG.debug("[E] INSERT " + procId);<a name="line.150"></a> +<span class="sourceLineNo">151</span> } catch (RuntimeException e) {<a name="line.151"></a> +<span class="sourceLineNo">152</span> reCount.incrementAndGet();<a name="line.152"></a> +<span class="sourceLineNo">153</span> LOG.debug("[F] INSERT " + procId + ": " + e.getMessage());<a name="line.153"></a> +<span class="sourceLineNo">154</span> }<a name="line.154"></a> +<span class="sourceLineNo">155</span> });<a name="line.155"></a> +<span class="sourceLineNo">156</span> thread[i].start();<a name="line.156"></a> +<span class="sourceLineNo">157</span> }<a name="line.157"></a> +<span class="sourceLineNo">158</span><a name="line.158"></a> +<span class="sourceLineNo">159</span> Thread.sleep(1000);<a name="line.159"></a> +<span class="sourceLineNo">160</span> LOG.info("Stop DataNode");<a name="line.160"></a> +<span class="sourceLineNo">161</span> UTIL.getDFSCluster().stopDataNode(0);<a name="line.161"></a> +<span class="sourceLineNo">162</span> assertEquals(2, UTIL.getDFSCluster().getDataNodes().size());<a name="line.162"></a> +<span class="sourceLineNo">163</span><a name="line.163"></a> +<span class="sourceLineNo">164</span> for (int i = 0; i < thread.length; ++i) {<a name="line.164"></a> +<span class="sourceLineNo">165</span> thread[i].join();<a name="line.165"></a> +<span class="sourceLineNo">166</span> }<a name="line.166"></a> +<span class="sourceLineNo">167</span><a name="line.167"></a> +<span class="sourceLineNo">168</span> assertFalse(store.isRunning());<a name="line.168"></a> +<span class="sourceLineNo">169</span> assertTrue(reCount.toString(), reCount.get() >= store.getNumThreads() &&<a name="line.169"></a> +<span class="sourceLineNo">170</span> reCount.get() < thread.length);<a name="line.170"></a> +<span class="sourceLineNo">171</span> }<a name="line.171"></a> +<span class="sourceLineNo">172</span><a name="line.172"></a> +<span class="sourceLineNo">173</span> @Test<a name="line.173"></a> +<span class="sourceLineNo">174</span> public void testWalRollOnLowReplication() throws Exception {<a name="line.174"></a> +<span class="sourceLineNo">175</span> UTIL.getConfiguration().setInt("dfs.namenode.replication.min", 1);<a name="line.175"></a> +<span class="sourceLineNo">176</span> setupDFS();<a name="line.176"></a> +<span class="sourceLineNo">177</span><a name="line.177"></a> +<span class="sourceLineNo">178</span> int dnCount = 0;<a name="line.178"></a> +<span class="sourceLineNo">179</span> store.insert(new TestProcedure(1, -1), null);<a name="line.179"></a> +<span class="sourceLineNo">180</span> UTIL.getDFSCluster().restartDataNode(dnCount);<a name="line.180"></a> +<span class="sourceLineNo">181</span> for (long i = 2; i < 100; ++i) {<a name="line.181"></a> +<span class="sourceLineNo">182</span> store.insert(new TestProcedure(i, -1), null);<a name="line.182"></a> +<span class="sourceLineNo">183</span> waitForNumReplicas(3);<a name="line.183"></a> +<span class="sourceLineNo">184</span> Thread.sleep(100);<a name="line.184"></a> +<span class="sourceLineNo">185</span> if ((i % 30) == 0) {<a name="line.185"></a> +<span class="sourceLineNo">186</span> LOG.info("Restart Data Node");<a name="line.186"></a> +<span class="sourceLineNo">187</span> UTIL.getDFSCluster().restartDataNode(++dnCount % 3);<a name="line.187"></a> +<span class="sourceLineNo">188</span> }<a name="line.188"></a> +<span class="sourceLineNo">189</span> }<a name="line.189"></a> +<span class="sourceLineNo">190</span> assertTrue(store.isRunning());<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> public void waitForNumReplicas(int numReplicas) throws Exception {<a name="line.193"></a> +<span class="sourceLineNo">194</span> while (UTIL.getDFSCluster().getDataNodes().size() < numReplicas) {<a name="line.194"></a> +<span class="sourceLineNo">195</span> Thread.sleep(100);<a name="line.195"></a> +<span class="sourceLineNo">196</span> }<a name="line.196"></a> +<span class="sourceLineNo">197</span><a name="line.197"></a> +<span class="sourceLineNo">198</span> for (int i = 0; i < numReplicas; ++i) {<a name="line.198"></a> +<span class="sourceLineNo">199</span> for (DataNode dn: UTIL.getDFSCluster().getDataNodes()) {<a name="line.199"></a> +<span class="sourceLineNo">200</span> while (!dn.isDatanodeFullyStarted()) {<a name="line.200"></a> +<span class="sourceLineNo">201</span> Thread.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> }<a name="line.204"></a> +<span class="sourceLineNo">205</span> }<a name="line.205"></a> +<span class="sourceLineNo">206</span>}<a name="line.206"></a>