hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From git-site-r...@apache.org
Subject [05/51] [partial] hbase-site git commit: Published site at 82d554e3783372cc6b05489452c815b57c06f6cd.
Date Thu, 11 May 2017 14:59:21 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/1241ee85/testdevapidocs/src-html/org/apache/hadoop/hbase/TestIOFencing.CompactionBlockerRegion.html
----------------------------------------------------------------------
diff --git a/testdevapidocs/src-html/org/apache/hadoop/hbase/TestIOFencing.CompactionBlockerRegion.html b/testdevapidocs/src-html/org/apache/hadoop/hbase/TestIOFencing.CompactionBlockerRegion.html
index 157e668..e3058d6 100644
--- a/testdevapidocs/src-html/org/apache/hadoop/hbase/TestIOFencing.CompactionBlockerRegion.html
+++ b/testdevapidocs/src-html/org/apache/hadoop/hbase/TestIOFencing.CompactionBlockerRegion.html
@@ -25,350 +25,367 @@
 <span class="sourceLineNo">017</span> */<a name="line.17"></a>
 <span class="sourceLineNo">018</span>package org.apache.hadoop.hbase;<a name="line.18"></a>
 <span class="sourceLineNo">019</span><a name="line.19"></a>
-<span class="sourceLineNo">020</span>import java.io.IOException;<a name="line.20"></a>
-<span class="sourceLineNo">021</span>import java.util.Collection;<a name="line.21"></a>
-<span class="sourceLineNo">022</span>import java.util.List;<a name="line.22"></a>
-<span class="sourceLineNo">023</span>import java.util.concurrent.CountDownLatch;<a name="line.23"></a>
+<span class="sourceLineNo">020</span>import static org.junit.Assert.assertEquals;<a name="line.20"></a>
+<span class="sourceLineNo">021</span>import static org.junit.Assert.assertTrue;<a name="line.21"></a>
+<span class="sourceLineNo">022</span><a name="line.22"></a>
+<span class="sourceLineNo">023</span>import com.google.common.collect.Lists;<a name="line.23"></a>
 <span class="sourceLineNo">024</span><a name="line.24"></a>
-<span class="sourceLineNo">025</span>import com.google.common.collect.Lists;<a name="line.25"></a>
-<span class="sourceLineNo">026</span>import org.apache.commons.logging.Log;<a name="line.26"></a>
-<span class="sourceLineNo">027</span>import org.apache.commons.logging.LogFactory;<a name="line.27"></a>
-<span class="sourceLineNo">028</span>import org.apache.hadoop.conf.Configuration;<a name="line.28"></a>
-<span class="sourceLineNo">029</span>import org.apache.hadoop.fs.FileSystem;<a name="line.29"></a>
-<span class="sourceLineNo">030</span>import org.apache.hadoop.fs.Path;<a name="line.30"></a>
-<span class="sourceLineNo">031</span>import org.apache.hadoop.hbase.client.Admin;<a name="line.31"></a>
-<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.regionserver.CompactingMemStore;<a name="line.33"></a>
-<span class="sourceLineNo">034</span>import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;<a name="line.34"></a>
-<span class="sourceLineNo">035</span>import org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.CompactionDescriptor;<a name="line.35"></a>
-<span class="sourceLineNo">036</span>import org.apache.hadoop.hbase.regionserver.ConstantSizeRegionSplitPolicy;<a name="line.36"></a>
-<span class="sourceLineNo">037</span>import org.apache.hadoop.hbase.regionserver.HRegion;<a name="line.37"></a>
-<span class="sourceLineNo">038</span>import org.apache.hadoop.hbase.regionserver.HRegionServer;<a name="line.38"></a>
-<span class="sourceLineNo">039</span>import org.apache.hadoop.hbase.regionserver.HStore;<a name="line.39"></a>
-<span class="sourceLineNo">040</span>import org.apache.hadoop.hbase.regionserver.Region;<a name="line.40"></a>
-<span class="sourceLineNo">041</span>import org.apache.hadoop.hbase.regionserver.RegionServerServices;<a name="line.41"></a>
-<span class="sourceLineNo">042</span>import org.apache.hadoop.hbase.regionserver.Store;<a name="line.42"></a>
-<span class="sourceLineNo">043</span>import org.apache.hadoop.hbase.regionserver.StoreFile;<a name="line.43"></a>
-<span class="sourceLineNo">044</span>import org.apache.hadoop.hbase.regionserver.compactions.CompactionContext;<a name="line.44"></a>
-<span class="sourceLineNo">045</span>import org.apache.hadoop.hbase.regionserver.throttle.ThroughputController;<a name="line.45"></a>
-<span class="sourceLineNo">046</span>import org.apache.hadoop.hbase.regionserver.wal.WALUtil;<a name="line.46"></a>
-<span class="sourceLineNo">047</span>import org.apache.hadoop.hbase.security.User;<a name="line.47"></a>
-<span class="sourceLineNo">048</span>import org.apache.hadoop.hbase.testclassification.MediumTests;<a name="line.48"></a>
-<span class="sourceLineNo">049</span>import org.apache.hadoop.hbase.testclassification.MiscTests;<a name="line.49"></a>
-<span class="sourceLineNo">050</span>import org.apache.hadoop.hbase.util.Bytes;<a name="line.50"></a>
-<span class="sourceLineNo">051</span>import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread;<a name="line.51"></a>
-<span class="sourceLineNo">052</span>import org.apache.hadoop.hbase.wal.WAL;<a name="line.52"></a>
-<span class="sourceLineNo">053</span>import org.junit.Test;<a name="line.53"></a>
-<span class="sourceLineNo">054</span>import org.junit.experimental.categories.Category;<a name="line.54"></a>
-<span class="sourceLineNo">055</span><a name="line.55"></a>
-<span class="sourceLineNo">056</span>import static org.junit.Assert.assertEquals;<a name="line.56"></a>
-<span class="sourceLineNo">057</span>import static org.junit.Assert.assertTrue;<a name="line.57"></a>
-<span class="sourceLineNo">058</span><a name="line.58"></a>
-<span class="sourceLineNo">059</span>/**<a name="line.59"></a>
-<span class="sourceLineNo">060</span> * Test for the case where a regionserver going down has enough cycles to do damage to regions<a name="line.60"></a>
-<span class="sourceLineNo">061</span> * that have actually been assigned elsehwere.<a name="line.61"></a>
-<span class="sourceLineNo">062</span> *<a name="line.62"></a>
-<span class="sourceLineNo">063</span> * &lt;p&gt;If we happen to assign a region before it fully done with in its old location -- i.e. it is on two servers at the<a name="line.63"></a>
-<span class="sourceLineNo">064</span> * same time -- all can work fine until the case where the region on the dying server decides to compact or otherwise<a name="line.64"></a>
-<span class="sourceLineNo">065</span> * change the region file set.  The region in its new location will then get a surprise when it tries to do something<a name="line.65"></a>
-<span class="sourceLineNo">066</span> * w/ a file removed by the region in its old location on dying server.<a name="line.66"></a>
-<span class="sourceLineNo">067</span> *<a name="line.67"></a>
-<span class="sourceLineNo">068</span> * &lt;p&gt;Making a test for this case is a little tough in that even if a file is deleted up on the namenode,<a name="line.68"></a>
-<span class="sourceLineNo">069</span> * if the file was opened before the delete, it will continue to let reads happen until something changes the<a name="line.69"></a>
-<span class="sourceLineNo">070</span> * state of cached blocks in the dfsclient that was already open (a block from the deleted file is cleaned<a name="line.70"></a>
-<span class="sourceLineNo">071</span> * from the datanode by NN).<a name="line.71"></a>
-<span class="sourceLineNo">072</span> *<a name="line.72"></a>
-<span class="sourceLineNo">073</span> * &lt;p&gt;What we will do below is do an explicit check for existence on the files listed in the region that<a name="line.73"></a>
-<span class="sourceLineNo">074</span> * has had some files removed because of a compaction.  This sort of hurry's along and makes certain what is a chance<a name="line.74"></a>
-<span class="sourceLineNo">075</span> * occurance.<a name="line.75"></a>
-<span class="sourceLineNo">076</span> */<a name="line.76"></a>
-<span class="sourceLineNo">077</span>@Category({MiscTests.class, MediumTests.class})<a name="line.77"></a>
-<span class="sourceLineNo">078</span>public class TestIOFencing {<a name="line.78"></a>
-<span class="sourceLineNo">079</span>  private static final Log LOG = LogFactory.getLog(TestIOFencing.class);<a name="line.79"></a>
-<span class="sourceLineNo">080</span>  static {<a name="line.80"></a>
-<span class="sourceLineNo">081</span>    // Uncomment the following lines if more verbosity is needed for<a name="line.81"></a>
-<span class="sourceLineNo">082</span>    // debugging (see HBASE-12285 for details).<a name="line.82"></a>
-<span class="sourceLineNo">083</span>    //((Log4JLogger)FSNamesystem.LOG).getLogger().setLevel(Level.ALL);<a name="line.83"></a>
-<span class="sourceLineNo">084</span>    //((Log4JLogger)DataNode.LOG).getLogger().setLevel(Level.ALL);<a name="line.84"></a>
-<span class="sourceLineNo">085</span>    //((Log4JLogger)LeaseManager.LOG).getLogger().setLevel(Level.ALL);<a name="line.85"></a>
-<span class="sourceLineNo">086</span>    //((Log4JLogger)LogFactory.getLog("org.apache.hadoop.hdfs.server.namenode.FSNamesystem"))<a name="line.86"></a>
-<span class="sourceLineNo">087</span>    //    .getLogger().setLevel(Level.ALL);<a name="line.87"></a>
-<span class="sourceLineNo">088</span>    //((Log4JLogger)DFSClient.LOG).getLogger().setLevel(Level.ALL);<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>  public abstract static class CompactionBlockerRegion extends HRegion {<a name="line.91"></a>
-<span class="sourceLineNo">092</span>    volatile int compactCount = 0;<a name="line.92"></a>
-<span class="sourceLineNo">093</span>    volatile CountDownLatch compactionsBlocked = new CountDownLatch(0);<a name="line.93"></a>
-<span class="sourceLineNo">094</span>    volatile CountDownLatch compactionsWaiting = new CountDownLatch(0);<a name="line.94"></a>
-<span class="sourceLineNo">095</span><a name="line.95"></a>
-<span class="sourceLineNo">096</span>    @SuppressWarnings("deprecation")<a name="line.96"></a>
-<span class="sourceLineNo">097</span>    public CompactionBlockerRegion(Path tableDir, WAL log,<a name="line.97"></a>
-<span class="sourceLineNo">098</span>        FileSystem fs, Configuration confParam, HRegionInfo info,<a name="line.98"></a>
-<span class="sourceLineNo">099</span>        HTableDescriptor htd, RegionServerServices rsServices) {<a name="line.99"></a>
-<span class="sourceLineNo">100</span>      super(tableDir, log, fs, confParam, info, htd, rsServices);<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>    public void stopCompactions() {<a name="line.103"></a>
-<span class="sourceLineNo">104</span>      compactionsBlocked = new CountDownLatch(1);<a name="line.104"></a>
-<span class="sourceLineNo">105</span>      compactionsWaiting = new CountDownLatch(1);<a name="line.105"></a>
-<span class="sourceLineNo">106</span>    }<a name="line.106"></a>
-<span class="sourceLineNo">107</span><a name="line.107"></a>
-<span class="sourceLineNo">108</span>    public void allowCompactions() {<a name="line.108"></a>
-<span class="sourceLineNo">109</span>      LOG.debug("allowing compactions");<a name="line.109"></a>
-<span class="sourceLineNo">110</span>      compactionsBlocked.countDown();<a name="line.110"></a>
-<span class="sourceLineNo">111</span>    }<a name="line.111"></a>
-<span class="sourceLineNo">112</span>    public void waitForCompactionToBlock() throws IOException {<a name="line.112"></a>
-<span class="sourceLineNo">113</span>      try {<a name="line.113"></a>
-<span class="sourceLineNo">114</span>        LOG.debug("waiting for compaction to block");<a name="line.114"></a>
-<span class="sourceLineNo">115</span>        compactionsWaiting.await();<a name="line.115"></a>
-<span class="sourceLineNo">116</span>        LOG.debug("compaction block reached");<a name="line.116"></a>
-<span class="sourceLineNo">117</span>      } catch (InterruptedException ex) {<a name="line.117"></a>
-<span class="sourceLineNo">118</span>        throw new IOException(ex);<a name="line.118"></a>
-<span class="sourceLineNo">119</span>      }<a name="line.119"></a>
-<span class="sourceLineNo">120</span>    }<a name="line.120"></a>
-<span class="sourceLineNo">121</span><a name="line.121"></a>
-<span class="sourceLineNo">122</span>    @Override<a name="line.122"></a>
-<span class="sourceLineNo">123</span>    public boolean compact(CompactionContext compaction, Store store,<a name="line.123"></a>
-<span class="sourceLineNo">124</span>        ThroughputController throughputController) throws IOException {<a name="line.124"></a>
-<span class="sourceLineNo">125</span>      try {<a name="line.125"></a>
-<span class="sourceLineNo">126</span>        return super.compact(compaction, store, throughputController);<a name="line.126"></a>
-<span class="sourceLineNo">127</span>      } finally {<a name="line.127"></a>
-<span class="sourceLineNo">128</span>        compactCount++;<a name="line.128"></a>
-<span class="sourceLineNo">129</span>      }<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>    @Override<a name="line.132"></a>
-<span class="sourceLineNo">133</span>    public boolean compact(CompactionContext compaction, Store store,<a name="line.133"></a>
-<span class="sourceLineNo">134</span>        ThroughputController throughputController, User user) throws IOException {<a name="line.134"></a>
-<span class="sourceLineNo">135</span>      try {<a name="line.135"></a>
-<span class="sourceLineNo">136</span>        return super.compact(compaction, store, throughputController, user);<a name="line.136"></a>
-<span class="sourceLineNo">137</span>      } finally {<a name="line.137"></a>
-<span class="sourceLineNo">138</span>        compactCount++;<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><a name="line.141"></a>
-<span class="sourceLineNo">142</span>    public int countStoreFiles() {<a name="line.142"></a>
-<span class="sourceLineNo">143</span>      int count = 0;<a name="line.143"></a>
-<span class="sourceLineNo">144</span>      for (Store store : stores.values()) {<a name="line.144"></a>
-<span class="sourceLineNo">145</span>        count += store.getStorefilesCount();<a name="line.145"></a>
-<span class="sourceLineNo">146</span>      }<a name="line.146"></a>
-<span class="sourceLineNo">147</span>      return count;<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>
-<span class="sourceLineNo">151</span>  /**<a name="line.151"></a>
-<span class="sourceLineNo">152</span>   * An override of HRegion that allows us park compactions in a holding pattern and<a name="line.152"></a>
-<span class="sourceLineNo">153</span>   * then when appropriate for the test, allow them proceed again.<a name="line.153"></a>
-<span class="sourceLineNo">154</span>   */<a name="line.154"></a>
-<span class="sourceLineNo">155</span>  public static class BlockCompactionsInPrepRegion extends CompactionBlockerRegion {<a name="line.155"></a>
-<span class="sourceLineNo">156</span><a name="line.156"></a>
-<span class="sourceLineNo">157</span>    public BlockCompactionsInPrepRegion(Path tableDir, WAL log,<a name="line.157"></a>
-<span class="sourceLineNo">158</span>        FileSystem fs, Configuration confParam, HRegionInfo info,<a name="line.158"></a>
-<span class="sourceLineNo">159</span>        HTableDescriptor htd, RegionServerServices rsServices) {<a name="line.159"></a>
-<span class="sourceLineNo">160</span>      super(tableDir, log, fs, confParam, info, htd, rsServices);<a name="line.160"></a>
-<span class="sourceLineNo">161</span>    }<a name="line.161"></a>
-<span class="sourceLineNo">162</span>    @Override<a name="line.162"></a>
-<span class="sourceLineNo">163</span>    protected void doRegionCompactionPrep() throws IOException {<a name="line.163"></a>
-<span class="sourceLineNo">164</span>      compactionsWaiting.countDown();<a name="line.164"></a>
-<span class="sourceLineNo">165</span>      try {<a name="line.165"></a>
-<span class="sourceLineNo">166</span>        compactionsBlocked.await();<a name="line.166"></a>
-<span class="sourceLineNo">167</span>      } catch (InterruptedException ex) {<a name="line.167"></a>
-<span class="sourceLineNo">168</span>        throw new IOException();<a name="line.168"></a>
-<span class="sourceLineNo">169</span>      }<a name="line.169"></a>
-<span class="sourceLineNo">170</span>      super.doRegionCompactionPrep();<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><a name="line.173"></a>
-<span class="sourceLineNo">174</span>  /**<a name="line.174"></a>
-<span class="sourceLineNo">175</span>   * An override of HRegion that allows us park compactions in a holding pattern and<a name="line.175"></a>
-<span class="sourceLineNo">176</span>   * then when appropriate for the test, allow them proceed again. This allows the compaction<a name="line.176"></a>
-<span class="sourceLineNo">177</span>   * entry to go the WAL before blocking, but blocks afterwards<a name="line.177"></a>
-<span class="sourceLineNo">178</span>   */<a name="line.178"></a>
-<span class="sourceLineNo">179</span>  public static class BlockCompactionsInCompletionRegion extends CompactionBlockerRegion {<a name="line.179"></a>
-<span class="sourceLineNo">180</span>    public BlockCompactionsInCompletionRegion(Path tableDir, WAL log,<a name="line.180"></a>
-<span class="sourceLineNo">181</span>        FileSystem fs, Configuration confParam, HRegionInfo info,<a name="line.181"></a>
-<span class="sourceLineNo">182</span>        HTableDescriptor htd, RegionServerServices rsServices) {<a name="line.182"></a>
-<span class="sourceLineNo">183</span>      super(tableDir, log, fs, confParam, info, htd, rsServices);<a name="line.183"></a>
-<span class="sourceLineNo">184</span>    }<a name="line.184"></a>
-<span class="sourceLineNo">185</span>    @Override<a name="line.185"></a>
-<span class="sourceLineNo">186</span>    protected HStore instantiateHStore(final HColumnDescriptor family) throws IOException {<a name="line.186"></a>
-<span class="sourceLineNo">187</span>      return new BlockCompactionsInCompletionHStore(this, family, this.conf);<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><a name="line.190"></a>
-<span class="sourceLineNo">191</span>  public static class BlockCompactionsInCompletionHStore extends HStore {<a name="line.191"></a>
-<span class="sourceLineNo">192</span>    CompactionBlockerRegion r;<a name="line.192"></a>
-<span class="sourceLineNo">193</span>    protected BlockCompactionsInCompletionHStore(HRegion region, HColumnDescriptor family,<a name="line.193"></a>
-<span class="sourceLineNo">194</span>        Configuration confParam) throws IOException {<a name="line.194"></a>
-<span class="sourceLineNo">195</span>      super(region, family, confParam);<a name="line.195"></a>
-<span class="sourceLineNo">196</span>      r = (CompactionBlockerRegion) region;<a name="line.196"></a>
-<span class="sourceLineNo">197</span>    }<a name="line.197"></a>
-<span class="sourceLineNo">198</span><a name="line.198"></a>
-<span class="sourceLineNo">199</span>    @Override<a name="line.199"></a>
-<span class="sourceLineNo">200</span>    protected void completeCompaction(Collection&lt;StoreFile&gt; compactedFiles) throws IOException {<a name="line.200"></a>
-<span class="sourceLineNo">201</span>      try {<a name="line.201"></a>
-<span class="sourceLineNo">202</span>        r.compactionsWaiting.countDown();<a name="line.202"></a>
-<span class="sourceLineNo">203</span>        r.compactionsBlocked.await();<a name="line.203"></a>
-<span class="sourceLineNo">204</span>      } catch (InterruptedException ex) {<a name="line.204"></a>
-<span class="sourceLineNo">205</span>        throw new IOException(ex);<a name="line.205"></a>
-<span class="sourceLineNo">206</span>      }<a name="line.206"></a>
-<span class="sourceLineNo">207</span>      super.completeCompaction(compactedFiles);<a name="line.207"></a>
-<span class="sourceLineNo">208</span>    }<a name="line.208"></a>
-<span class="sourceLineNo">209</span>  }<a name="line.209"></a>
-<span class="sourceLineNo">210</span><a name="line.210"></a>
-<span class="sourceLineNo">211</span>  private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();<a name="line.211"></a>
-<span class="sourceLineNo">212</span>  private final static TableName TABLE_NAME =<a name="line.212"></a>
-<span class="sourceLineNo">213</span>      TableName.valueOf("tabletest");<a name="line.213"></a>
-<span class="sourceLineNo">214</span>  private final static byte[] FAMILY = Bytes.toBytes("family");<a name="line.214"></a>
-<span class="sourceLineNo">215</span>  private static final int FIRST_BATCH_COUNT = 4000;<a name="line.215"></a>
-<span class="sourceLineNo">216</span>  private static final int SECOND_BATCH_COUNT = FIRST_BATCH_COUNT;<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">219</span>   * Test that puts up a regionserver, starts a compaction on a loaded region but holds the<a name="line.219"></a>
-<span class="sourceLineNo">220</span>   * compaction until after we have killed the server and the region has come up on<a name="line.220"></a>
-<span class="sourceLineNo">221</span>   * a new regionserver altogether.  This fakes the double assignment case where region in one<a name="line.221"></a>
-<span class="sourceLineNo">222</span>   * location changes the files out from underneath a region being served elsewhere.<a name="line.222"></a>
-<span class="sourceLineNo">223</span>   */<a name="line.223"></a>
-<span class="sourceLineNo">224</span>  @Test<a name="line.224"></a>
-<span class="sourceLineNo">225</span>  public void testFencingAroundCompaction() throws Exception {<a name="line.225"></a>
-<span class="sourceLineNo">226</span>    for(MemoryCompactionPolicy policy : MemoryCompactionPolicy.values()) {<a name="line.226"></a>
-<span class="sourceLineNo">227</span>      doTest(BlockCompactionsInPrepRegion.class, policy);<a name="line.227"></a>
-<span class="sourceLineNo">228</span>    }<a name="line.228"></a>
-<span class="sourceLineNo">229</span>  }<a name="line.229"></a>
-<span class="sourceLineNo">230</span><a name="line.230"></a>
-<span class="sourceLineNo">231</span>  /**<a name="line.231"></a>
-<span class="sourceLineNo">232</span>   * Test that puts up a regionserver, starts a compaction on a loaded region but holds the<a name="line.232"></a>
-<span class="sourceLineNo">233</span>   * compaction completion until after we have killed the server and the region has come up on<a name="line.233"></a>
-<span class="sourceLineNo">234</span>   * a new regionserver altogether.  This fakes the double assignment case where region in one<a name="line.234"></a>
-<span class="sourceLineNo">235</span>   * location changes the files out from underneath a region being served elsewhere.<a name="line.235"></a>
-<span class="sourceLineNo">236</span>   */<a name="line.236"></a>
-<span class="sourceLineNo">237</span>  @Test<a name="line.237"></a>
-<span class="sourceLineNo">238</span>  public void testFencingAroundCompactionAfterWALSync() throws Exception {<a name="line.238"></a>
-<span class="sourceLineNo">239</span>    for(MemoryCompactionPolicy policy : MemoryCompactionPolicy.values()) {<a name="line.239"></a>
-<span class="sourceLineNo">240</span>      doTest(BlockCompactionsInCompletionRegion.class, policy);<a name="line.240"></a>
-<span class="sourceLineNo">241</span>    }<a name="line.241"></a>
-<span class="sourceLineNo">242</span>  }<a name="line.242"></a>
-<span class="sourceLineNo">243</span><a name="line.243"></a>
-<span class="sourceLineNo">244</span>  public void doTest(Class&lt;?&gt; regionClass, MemoryCompactionPolicy policy) throws Exception {<a name="line.244"></a>
-<span class="sourceLineNo">245</span>    Configuration c = TEST_UTIL.getConfiguration();<a name="line.245"></a>
-<span class="sourceLineNo">246</span>    // Insert our custom region<a name="line.246"></a>
-<span class="sourceLineNo">247</span>    c.setClass(HConstants.REGION_IMPL, regionClass, HRegion.class);<a name="line.247"></a>
-<span class="sourceLineNo">248</span>    // Encourage plenty of flushes<a name="line.248"></a>
-<span class="sourceLineNo">249</span>    c.setLong("hbase.hregion.memstore.flush.size", 25000);<a name="line.249"></a>
-<span class="sourceLineNo">250</span>    c.set(HConstants.HBASE_REGION_SPLIT_POLICY_KEY, ConstantSizeRegionSplitPolicy.class.getName());<a name="line.250"></a>
-<span class="sourceLineNo">251</span>    // Only run compaction when we tell it to<a name="line.251"></a>
-<span class="sourceLineNo">252</span>    c.setInt("hbase.hstore.compaction.min",1);<a name="line.252"></a>
-<span class="sourceLineNo">253</span>    c.setInt("hbase.hstore.compactionThreshold", 1000);<a name="line.253"></a>
-<span class="sourceLineNo">254</span>    c.setLong("hbase.hstore.blockingStoreFiles", 1000);<a name="line.254"></a>
-<span class="sourceLineNo">255</span>    // Compact quickly after we tell it to!<a name="line.255"></a>
-<span class="sourceLineNo">256</span>    c.setInt("hbase.regionserver.thread.splitcompactcheckfrequency", 1000);<a name="line.256"></a>
-<span class="sourceLineNo">257</span>    c.set(CompactingMemStore.COMPACTING_MEMSTORE_TYPE_KEY, String.valueOf(policy));<a name="line.257"></a>
-<span class="sourceLineNo">258</span>    LOG.info("Starting mini cluster");<a name="line.258"></a>
-<span class="sourceLineNo">259</span>    TEST_UTIL.startMiniCluster(1);<a name="line.259"></a>
-<span class="sourceLineNo">260</span>    CompactionBlockerRegion compactingRegion = null;<a name="line.260"></a>
-<span class="sourceLineNo">261</span>    Admin admin = null;<a name="line.261"></a>
-<span class="sourceLineNo">262</span>    try {<a name="line.262"></a>
-<span class="sourceLineNo">263</span>      LOG.info("Creating admin");<a name="line.263"></a>
-<span class="sourceLineNo">264</span>      admin = TEST_UTIL.getConnection().getAdmin();<a name="line.264"></a>
-<span class="sourceLineNo">265</span>      LOG.info("Creating table");<a name="line.265"></a>
-<span class="sourceLineNo">266</span>      TEST_UTIL.createTable(TABLE_NAME, FAMILY);<a name="line.266"></a>
-<span class="sourceLineNo">267</span>      Table table = TEST_UTIL.getConnection().getTable(TABLE_NAME);<a name="line.267"></a>
-<span class="sourceLineNo">268</span>      LOG.info("Loading test table");<a name="line.268"></a>
-<span class="sourceLineNo">269</span>      // Find the region<a name="line.269"></a>
-<span class="sourceLineNo">270</span>      List&lt;HRegion&gt; testRegions = TEST_UTIL.getMiniHBaseCluster().findRegionsForTable(TABLE_NAME);<a name="line.270"></a>
-<span class="sourceLineNo">271</span>      assertEquals(1, testRegions.size());<a name="line.271"></a>
-<span class="sourceLineNo">272</span>      compactingRegion = (CompactionBlockerRegion)testRegions.get(0);<a name="line.272"></a>
-<span class="sourceLineNo">273</span>      LOG.info("Blocking compactions");<a name="line.273"></a>
-<span class="sourceLineNo">274</span>      compactingRegion.stopCompactions();<a name="line.274"></a>
-<span class="sourceLineNo">275</span>      long lastFlushTime = compactingRegion.getEarliestFlushTimeForAllStores();<a name="line.275"></a>
-<span class="sourceLineNo">276</span>      // Load some rows<a name="line.276"></a>
-<span class="sourceLineNo">277</span>      TEST_UTIL.loadNumericRows(table, FAMILY, 0, FIRST_BATCH_COUNT);<a name="line.277"></a>
-<span class="sourceLineNo">278</span><a name="line.278"></a>
-<span class="sourceLineNo">279</span>      // add a compaction from an older (non-existing) region to see whether we successfully skip<a name="line.279"></a>
-<span class="sourceLineNo">280</span>      // those entries<a name="line.280"></a>
-<span class="sourceLineNo">281</span>      HRegionInfo oldHri = new HRegionInfo(table.getName(),<a name="line.281"></a>
-<span class="sourceLineNo">282</span>        HConstants.EMPTY_START_ROW, HConstants.EMPTY_END_ROW);<a name="line.282"></a>
-<span class="sourceLineNo">283</span>      CompactionDescriptor compactionDescriptor = ProtobufUtil.toCompactionDescriptor(oldHri,<a name="line.283"></a>
-<span class="sourceLineNo">284</span>        FAMILY, Lists.newArrayList(new Path("/a")), Lists.newArrayList(new Path("/b")),<a name="line.284"></a>
-<span class="sourceLineNo">285</span>        new Path("store_dir"));<a name="line.285"></a>
-<span class="sourceLineNo">286</span>      WALUtil.writeCompactionMarker(compactingRegion.getWAL(),<a name="line.286"></a>
-<span class="sourceLineNo">287</span>          ((HRegion)compactingRegion).getReplicationScope(),<a name="line.287"></a>
-<span class="sourceLineNo">288</span>        oldHri, compactionDescriptor, compactingRegion.getMVCC());<a name="line.288"></a>
-<span class="sourceLineNo">289</span><a name="line.289"></a>
-<span class="sourceLineNo">290</span>      // Wait till flush has happened, otherwise there won't be multiple store files<a name="line.290"></a>
-<span class="sourceLineNo">291</span>      long startWaitTime = System.currentTimeMillis();<a name="line.291"></a>
-<span class="sourceLineNo">292</span>      while (compactingRegion.getEarliestFlushTimeForAllStores() &lt;= lastFlushTime ||<a name="line.292"></a>
-<span class="sourceLineNo">293</span>          compactingRegion.countStoreFiles() &lt;= 1) {<a name="line.293"></a>
-<span class="sourceLineNo">294</span>        LOG.info("Waiting for the region to flush " +<a name="line.294"></a>
-<span class="sourceLineNo">295</span>          compactingRegion.getRegionInfo().getRegionNameAsString());<a name="line.295"></a>
-<span class="sourceLineNo">296</span>        Thread.sleep(1000);<a name="line.296"></a>
-<span class="sourceLineNo">297</span>        assertTrue("Timed out waiting for the region to flush",<a name="line.297"></a>
-<span class="sourceLineNo">298</span>          System.currentTimeMillis() - startWaitTime &lt; 30000);<a name="line.298"></a>
-<span class="sourceLineNo">299</span>      }<a name="line.299"></a>
-<span class="sourceLineNo">300</span>      assertTrue(compactingRegion.countStoreFiles() &gt; 1);<a name="line.300"></a>
-<span class="sourceLineNo">301</span>      final byte REGION_NAME[] = compactingRegion.getRegionInfo().getRegionName();<a name="line.301"></a>
-<span class="sourceLineNo">302</span>      LOG.info("Asking for compaction");<a name="line.302"></a>
-<span class="sourceLineNo">303</span>      admin.majorCompact(TABLE_NAME);<a name="line.303"></a>
-<span class="sourceLineNo">304</span>      LOG.info("Waiting for compaction to be about to start");<a name="line.304"></a>
-<span class="sourceLineNo">305</span>      compactingRegion.waitForCompactionToBlock();<a name="line.305"></a>
-<span class="sourceLineNo">306</span>      LOG.info("Starting a new server");<a name="line.306"></a>
-<span class="sourceLineNo">307</span>      RegionServerThread newServerThread = TEST_UTIL.getMiniHBaseCluster().startRegionServer();<a name="line.307"></a>
-<span class="sourceLineNo">308</span>      final HRegionServer newServer = newServerThread.getRegionServer();<a name="line.308"></a>
-<span class="sourceLineNo">309</span>      LOG.info("Killing region server ZK lease");<a name="line.309"></a>
-<span class="sourceLineNo">310</span>      TEST_UTIL.expireRegionServerSession(0);<a name="line.310"></a>
-<span class="sourceLineNo">311</span>      CompactionBlockerRegion newRegion = null;<a name="line.311"></a>
-<span class="sourceLineNo">312</span>      startWaitTime = System.currentTimeMillis();<a name="line.312"></a>
-<span class="sourceLineNo">313</span>      LOG.info("Waiting for the new server to pick up the region " + Bytes.toString(REGION_NAME));<a name="line.313"></a>
-<span class="sourceLineNo">314</span><a name="line.314"></a>
-<span class="sourceLineNo">315</span>      // wait for region to be assigned and to go out of log replay if applicable<a name="line.315"></a>
-<span class="sourceLineNo">316</span>      Waiter.waitFor(c, 60000, new Waiter.Predicate&lt;Exception&gt;() {<a name="line.316"></a>
-<span class="sourceLineNo">317</span>        @Override<a name="line.317"></a>
-<span class="sourceLineNo">318</span>        public boolean evaluate() throws Exception {<a name="line.318"></a>
-<span class="sourceLineNo">319</span>          Region newRegion = newServer.getOnlineRegion(REGION_NAME);<a name="line.319"></a>
-<span class="sourceLineNo">320</span>          return newRegion != null &amp;&amp; !newRegion.isRecovering();<a name="line.320"></a>
-<span class="sourceLineNo">321</span>        }<a name="line.321"></a>
-<span class="sourceLineNo">322</span>      });<a name="line.322"></a>
-<span class="sourceLineNo">323</span><a name="line.323"></a>
-<span class="sourceLineNo">324</span>      newRegion = (CompactionBlockerRegion)newServer.getOnlineRegion(REGION_NAME);<a name="line.324"></a>
+<span class="sourceLineNo">025</span>import java.io.IOException;<a name="line.25"></a>
+<span class="sourceLineNo">026</span>import java.util.Collection;<a name="line.26"></a>
+<span class="sourceLineNo">027</span>import java.util.List;<a name="line.27"></a>
+<span class="sourceLineNo">028</span>import java.util.concurrent.CountDownLatch;<a name="line.28"></a>
+<span class="sourceLineNo">029</span><a name="line.29"></a>
+<span class="sourceLineNo">030</span>import org.apache.commons.logging.Log;<a name="line.30"></a>
+<span class="sourceLineNo">031</span>import org.apache.commons.logging.LogFactory;<a name="line.31"></a>
+<span class="sourceLineNo">032</span>import org.apache.hadoop.conf.Configuration;<a name="line.32"></a>
+<span class="sourceLineNo">033</span>import org.apache.hadoop.fs.FileSystem;<a name="line.33"></a>
+<span class="sourceLineNo">034</span>import org.apache.hadoop.fs.Path;<a name="line.34"></a>
+<span class="sourceLineNo">035</span>import org.apache.hadoop.hbase.client.Admin;<a name="line.35"></a>
+<span class="sourceLineNo">036</span>import org.apache.hadoop.hbase.client.Table;<a name="line.36"></a>
+<span class="sourceLineNo">037</span>import org.apache.hadoop.hbase.regionserver.CompactingMemStore;<a name="line.37"></a>
+<span class="sourceLineNo">038</span>import org.apache.hadoop.hbase.regionserver.ConstantSizeRegionSplitPolicy;<a name="line.38"></a>
+<span class="sourceLineNo">039</span>import org.apache.hadoop.hbase.regionserver.HRegion;<a name="line.39"></a>
+<span class="sourceLineNo">040</span>import org.apache.hadoop.hbase.regionserver.HRegionServer;<a name="line.40"></a>
+<span class="sourceLineNo">041</span>import org.apache.hadoop.hbase.regionserver.HStore;<a name="line.41"></a>
+<span class="sourceLineNo">042</span>import org.apache.hadoop.hbase.regionserver.Region;<a name="line.42"></a>
+<span class="sourceLineNo">043</span>import org.apache.hadoop.hbase.regionserver.RegionServerServices;<a name="line.43"></a>
+<span class="sourceLineNo">044</span>import org.apache.hadoop.hbase.regionserver.Store;<a name="line.44"></a>
+<span class="sourceLineNo">045</span>import org.apache.hadoop.hbase.regionserver.StoreFile;<a name="line.45"></a>
+<span class="sourceLineNo">046</span>import org.apache.hadoop.hbase.regionserver.compactions.CompactionContext;<a name="line.46"></a>
+<span class="sourceLineNo">047</span>import org.apache.hadoop.hbase.regionserver.throttle.ThroughputController;<a name="line.47"></a>
+<span class="sourceLineNo">048</span>import org.apache.hadoop.hbase.regionserver.wal.WALUtil;<a name="line.48"></a>
+<span class="sourceLineNo">049</span>import org.apache.hadoop.hbase.security.User;<a name="line.49"></a>
+<span class="sourceLineNo">050</span>import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;<a name="line.50"></a>
+<span class="sourceLineNo">051</span>import org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.CompactionDescriptor;<a name="line.51"></a>
+<span class="sourceLineNo">052</span>import org.apache.hadoop.hbase.testclassification.LargeTests;<a name="line.52"></a>
+<span class="sourceLineNo">053</span>import org.apache.hadoop.hbase.testclassification.MiscTests;<a name="line.53"></a>
+<span class="sourceLineNo">054</span>import org.apache.hadoop.hbase.util.Bytes;<a name="line.54"></a>
+<span class="sourceLineNo">055</span>import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread;<a name="line.55"></a>
+<span class="sourceLineNo">056</span>import org.apache.hadoop.hbase.wal.WAL;<a name="line.56"></a>
+<span class="sourceLineNo">057</span>import org.junit.Test;<a name="line.57"></a>
+<span class="sourceLineNo">058</span>import org.junit.experimental.categories.Category;<a name="line.58"></a>
+<span class="sourceLineNo">059</span><a name="line.59"></a>
+<span class="sourceLineNo">060</span>/**<a name="line.60"></a>
+<span class="sourceLineNo">061</span> * Test for the case where a regionserver going down has enough cycles to do damage to regions that<a name="line.61"></a>
+<span class="sourceLineNo">062</span> * have actually been assigned elsehwere.<a name="line.62"></a>
+<span class="sourceLineNo">063</span> * &lt;p&gt;<a name="line.63"></a>
+<span class="sourceLineNo">064</span> * If we happen to assign a region before it fully done with in its old location -- i.e. it is on<a name="line.64"></a>
+<span class="sourceLineNo">065</span> * two servers at the same time -- all can work fine until the case where the region on the dying<a name="line.65"></a>
+<span class="sourceLineNo">066</span> * server decides to compact or otherwise change the region file set. The region in its new location<a name="line.66"></a>
+<span class="sourceLineNo">067</span> * will then get a surprise when it tries to do something w/ a file removed by the region in its old<a name="line.67"></a>
+<span class="sourceLineNo">068</span> * location on dying server.<a name="line.68"></a>
+<span class="sourceLineNo">069</span> * &lt;p&gt;<a name="line.69"></a>
+<span class="sourceLineNo">070</span> * Making a test for this case is a little tough in that even if a file is deleted up on the<a name="line.70"></a>
+<span class="sourceLineNo">071</span> * namenode, if the file was opened before the delete, it will continue to let reads happen until<a name="line.71"></a>
+<span class="sourceLineNo">072</span> * something changes the state of cached blocks in the dfsclient that was already open (a block from<a name="line.72"></a>
+<span class="sourceLineNo">073</span> * the deleted file is cleaned from the datanode by NN).<a name="line.73"></a>
+<span class="sourceLineNo">074</span> * &lt;p&gt;<a name="line.74"></a>
+<span class="sourceLineNo">075</span> * What we will do below is do an explicit check for existence on the files listed in the region<a name="line.75"></a>
+<span class="sourceLineNo">076</span> * that has had some files removed because of a compaction. This sort of hurry's along and makes<a name="line.76"></a>
+<span class="sourceLineNo">077</span> * certain what is a chance occurance.<a name="line.77"></a>
+<span class="sourceLineNo">078</span> */<a name="line.78"></a>
+<span class="sourceLineNo">079</span>@Category({MiscTests.class, LargeTests.class})<a name="line.79"></a>
+<span class="sourceLineNo">080</span>public class TestIOFencing {<a name="line.80"></a>
+<span class="sourceLineNo">081</span>  private static final Log LOG = LogFactory.getLog(TestIOFencing.class);<a name="line.81"></a>
+<span class="sourceLineNo">082</span>  static {<a name="line.82"></a>
+<span class="sourceLineNo">083</span>    // Uncomment the following lines if more verbosity is needed for<a name="line.83"></a>
+<span class="sourceLineNo">084</span>    // debugging (see HBASE-12285 for details).<a name="line.84"></a>
+<span class="sourceLineNo">085</span>    //((Log4JLogger)FSNamesystem.LOG).getLogger().setLevel(Level.ALL);<a name="line.85"></a>
+<span class="sourceLineNo">086</span>    //((Log4JLogger)DataNode.LOG).getLogger().setLevel(Level.ALL);<a name="line.86"></a>
+<span class="sourceLineNo">087</span>    //((Log4JLogger)LeaseManager.LOG).getLogger().setLevel(Level.ALL);<a name="line.87"></a>
+<span class="sourceLineNo">088</span>    //((Log4JLogger)LogFactory.getLog("org.apache.hadoop.hdfs.server.namenode.FSNamesystem"))<a name="line.88"></a>
+<span class="sourceLineNo">089</span>    //    .getLogger().setLevel(Level.ALL);<a name="line.89"></a>
+<span class="sourceLineNo">090</span>    //((Log4JLogger)DFSClient.LOG).getLogger().setLevel(Level.ALL);<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>  public abstract static class CompactionBlockerRegion extends HRegion {<a name="line.93"></a>
+<span class="sourceLineNo">094</span>    volatile int compactCount = 0;<a name="line.94"></a>
+<span class="sourceLineNo">095</span>    volatile CountDownLatch compactionsBlocked = new CountDownLatch(0);<a name="line.95"></a>
+<span class="sourceLineNo">096</span>    volatile CountDownLatch compactionsWaiting = new CountDownLatch(0);<a name="line.96"></a>
+<span class="sourceLineNo">097</span><a name="line.97"></a>
+<span class="sourceLineNo">098</span>    @SuppressWarnings("deprecation")<a name="line.98"></a>
+<span class="sourceLineNo">099</span>    public CompactionBlockerRegion(Path tableDir, WAL log,<a name="line.99"></a>
+<span class="sourceLineNo">100</span>        FileSystem fs, Configuration confParam, HRegionInfo info,<a name="line.100"></a>
+<span class="sourceLineNo">101</span>        HTableDescriptor htd, RegionServerServices rsServices) {<a name="line.101"></a>
+<span class="sourceLineNo">102</span>      super(tableDir, log, fs, confParam, info, htd, rsServices);<a name="line.102"></a>
+<span class="sourceLineNo">103</span>    }<a name="line.103"></a>
+<span class="sourceLineNo">104</span><a name="line.104"></a>
+<span class="sourceLineNo">105</span>    public void stopCompactions() {<a name="line.105"></a>
+<span class="sourceLineNo">106</span>      compactionsBlocked = new CountDownLatch(1);<a name="line.106"></a>
+<span class="sourceLineNo">107</span>      compactionsWaiting = new CountDownLatch(1);<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>    public void allowCompactions() {<a name="line.110"></a>
+<span class="sourceLineNo">111</span>      LOG.debug("allowing compactions");<a name="line.111"></a>
+<span class="sourceLineNo">112</span>      compactionsBlocked.countDown();<a name="line.112"></a>
+<span class="sourceLineNo">113</span>    }<a name="line.113"></a>
+<span class="sourceLineNo">114</span>    public void waitForCompactionToBlock() throws IOException {<a name="line.114"></a>
+<span class="sourceLineNo">115</span>      try {<a name="line.115"></a>
+<span class="sourceLineNo">116</span>        LOG.debug("waiting for compaction to block");<a name="line.116"></a>
+<span class="sourceLineNo">117</span>        compactionsWaiting.await();<a name="line.117"></a>
+<span class="sourceLineNo">118</span>        LOG.debug("compaction block reached");<a name="line.118"></a>
+<span class="sourceLineNo">119</span>      } catch (InterruptedException ex) {<a name="line.119"></a>
+<span class="sourceLineNo">120</span>        throw new IOException(ex);<a name="line.120"></a>
+<span class="sourceLineNo">121</span>      }<a name="line.121"></a>
+<span class="sourceLineNo">122</span>    }<a name="line.122"></a>
+<span class="sourceLineNo">123</span><a name="line.123"></a>
+<span class="sourceLineNo">124</span>    @Override<a name="line.124"></a>
+<span class="sourceLineNo">125</span>    public boolean compact(CompactionContext compaction, Store store,<a name="line.125"></a>
+<span class="sourceLineNo">126</span>        ThroughputController throughputController) throws IOException {<a name="line.126"></a>
+<span class="sourceLineNo">127</span>      try {<a name="line.127"></a>
+<span class="sourceLineNo">128</span>        return super.compact(compaction, store, throughputController);<a name="line.128"></a>
+<span class="sourceLineNo">129</span>      } finally {<a name="line.129"></a>
+<span class="sourceLineNo">130</span>        compactCount++;<a name="line.130"></a>
+<span class="sourceLineNo">131</span>      }<a name="line.131"></a>
+<span class="sourceLineNo">132</span>    }<a name="line.132"></a>
+<span class="sourceLineNo">133</span><a name="line.133"></a>
+<span class="sourceLineNo">134</span>    @Override<a name="line.134"></a>
+<span class="sourceLineNo">135</span>    public boolean compact(CompactionContext compaction, Store store,<a name="line.135"></a>
+<span class="sourceLineNo">136</span>        ThroughputController throughputController, User user) throws IOException {<a name="line.136"></a>
+<span class="sourceLineNo">137</span>      try {<a name="line.137"></a>
+<span class="sourceLineNo">138</span>        return super.compact(compaction, store, throughputController, user);<a name="line.138"></a>
+<span class="sourceLineNo">139</span>      } finally {<a name="line.139"></a>
+<span class="sourceLineNo">140</span>        compactCount++;<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><a name="line.143"></a>
+<span class="sourceLineNo">144</span>    public int countStoreFiles() {<a name="line.144"></a>
+<span class="sourceLineNo">145</span>      int count = 0;<a name="line.145"></a>
+<span class="sourceLineNo">146</span>      for (Store store : stores.values()) {<a name="line.146"></a>
+<span class="sourceLineNo">147</span>        count += store.getStorefilesCount();<a name="line.147"></a>
+<span class="sourceLineNo">148</span>      }<a name="line.148"></a>
+<span class="sourceLineNo">149</span>      return count;<a name="line.149"></a>
+<span class="sourceLineNo">150</span>    }<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>  /**<a name="line.153"></a>
+<span class="sourceLineNo">154</span>   * An override of HRegion that allows us park compactions in a holding pattern and<a name="line.154"></a>
+<span class="sourceLineNo">155</span>   * then when appropriate for the test, allow them proceed again.<a name="line.155"></a>
+<span class="sourceLineNo">156</span>   */<a name="line.156"></a>
+<span class="sourceLineNo">157</span>  public static class BlockCompactionsInPrepRegion extends CompactionBlockerRegion {<a name="line.157"></a>
+<span class="sourceLineNo">158</span><a name="line.158"></a>
+<span class="sourceLineNo">159</span>    public BlockCompactionsInPrepRegion(Path tableDir, WAL log,<a name="line.159"></a>
+<span class="sourceLineNo">160</span>        FileSystem fs, Configuration confParam, HRegionInfo info,<a name="line.160"></a>
+<span class="sourceLineNo">161</span>        HTableDescriptor htd, RegionServerServices rsServices) {<a name="line.161"></a>
+<span class="sourceLineNo">162</span>      super(tableDir, log, fs, confParam, info, htd, rsServices);<a name="line.162"></a>
+<span class="sourceLineNo">163</span>    }<a name="line.163"></a>
+<span class="sourceLineNo">164</span>    @Override<a name="line.164"></a>
+<span class="sourceLineNo">165</span>    protected void doRegionCompactionPrep() throws IOException {<a name="line.165"></a>
+<span class="sourceLineNo">166</span>      compactionsWaiting.countDown();<a name="line.166"></a>
+<span class="sourceLineNo">167</span>      try {<a name="line.167"></a>
+<span class="sourceLineNo">168</span>        compactionsBlocked.await();<a name="line.168"></a>
+<span class="sourceLineNo">169</span>      } catch (InterruptedException ex) {<a name="line.169"></a>
+<span class="sourceLineNo">170</span>        throw new IOException();<a name="line.170"></a>
+<span class="sourceLineNo">171</span>      }<a name="line.171"></a>
+<span class="sourceLineNo">172</span>      super.doRegionCompactionPrep();<a name="line.172"></a>
+<span class="sourceLineNo">173</span>    }<a name="line.173"></a>
+<span class="sourceLineNo">174</span>  }<a name="line.174"></a>
+<span class="sourceLineNo">175</span><a name="line.175"></a>
+<span class="sourceLineNo">176</span>  /**<a name="line.176"></a>
+<span class="sourceLineNo">177</span>   * An override of HRegion that allows us park compactions in a holding pattern and<a name="line.177"></a>
+<span class="sourceLineNo">178</span>   * then when appropriate for the test, allow them proceed again. This allows the compaction<a name="line.178"></a>
+<span class="sourceLineNo">179</span>   * entry to go the WAL before blocking, but blocks afterwards<a name="line.179"></a>
+<span class="sourceLineNo">180</span>   */<a name="line.180"></a>
+<span class="sourceLineNo">181</span>  public static class BlockCompactionsInCompletionRegion extends CompactionBlockerRegion {<a name="line.181"></a>
+<span class="sourceLineNo">182</span>    public BlockCompactionsInCompletionRegion(Path tableDir, WAL log,<a name="line.182"></a>
+<span class="sourceLineNo">183</span>        FileSystem fs, Configuration confParam, HRegionInfo info,<a name="line.183"></a>
+<span class="sourceLineNo">184</span>        HTableDescriptor htd, RegionServerServices rsServices) {<a name="line.184"></a>
+<span class="sourceLineNo">185</span>      super(tableDir, log, fs, confParam, info, htd, rsServices);<a name="line.185"></a>
+<span class="sourceLineNo">186</span>    }<a name="line.186"></a>
+<span class="sourceLineNo">187</span>    @Override<a name="line.187"></a>
+<span class="sourceLineNo">188</span>    protected HStore instantiateHStore(final HColumnDescriptor family) throws IOException {<a name="line.188"></a>
+<span class="sourceLineNo">189</span>      return new BlockCompactionsInCompletionHStore(this, family, this.conf);<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><a name="line.192"></a>
+<span class="sourceLineNo">193</span>  public static class BlockCompactionsInCompletionHStore extends HStore {<a name="line.193"></a>
+<span class="sourceLineNo">194</span>    CompactionBlockerRegion r;<a name="line.194"></a>
+<span class="sourceLineNo">195</span>    protected BlockCompactionsInCompletionHStore(HRegion region, HColumnDescriptor family,<a name="line.195"></a>
+<span class="sourceLineNo">196</span>        Configuration confParam) throws IOException {<a name="line.196"></a>
+<span class="sourceLineNo">197</span>      super(region, family, confParam);<a name="line.197"></a>
+<span class="sourceLineNo">198</span>      r = (CompactionBlockerRegion) region;<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>    @Override<a name="line.201"></a>
+<span class="sourceLineNo">202</span>    protected void completeCompaction(Collection&lt;StoreFile&gt; compactedFiles) throws IOException {<a name="line.202"></a>
+<span class="sourceLineNo">203</span>      try {<a name="line.203"></a>
+<span class="sourceLineNo">204</span>        r.compactionsWaiting.countDown();<a name="line.204"></a>
+<span class="sourceLineNo">205</span>        r.compactionsBlocked.await();<a name="line.205"></a>
+<span class="sourceLineNo">206</span>      } catch (InterruptedException ex) {<a name="line.206"></a>
+<span class="sourceLineNo">207</span>        throw new IOException(ex);<a name="line.207"></a>
+<span class="sourceLineNo">208</span>      }<a name="line.208"></a>
+<span class="sourceLineNo">209</span>      super.completeCompaction(compactedFiles);<a name="line.209"></a>
+<span class="sourceLineNo">210</span>    }<a name="line.210"></a>
+<span class="sourceLineNo">211</span>  }<a name="line.211"></a>
+<span class="sourceLineNo">212</span><a name="line.212"></a>
+<span class="sourceLineNo">213</span>  private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();<a name="line.213"></a>
+<span class="sourceLineNo">214</span>  private final static TableName TABLE_NAME =<a name="line.214"></a>
+<span class="sourceLineNo">215</span>      TableName.valueOf("tabletest");<a name="line.215"></a>
+<span class="sourceLineNo">216</span>  private final static byte[] FAMILY = Bytes.toBytes("family");<a name="line.216"></a>
+<span class="sourceLineNo">217</span>  private static final int FIRST_BATCH_COUNT = 4000;<a name="line.217"></a>
+<span class="sourceLineNo">218</span>  private static final int SECOND_BATCH_COUNT = FIRST_BATCH_COUNT;<a name="line.218"></a>
+<span class="sourceLineNo">219</span><a name="line.219"></a>
+<span class="sourceLineNo">220</span>  /**<a name="line.220"></a>
+<span class="sourceLineNo">221</span>   * Test that puts up a regionserver, starts a compaction on a loaded region but holds the<a name="line.221"></a>
+<span class="sourceLineNo">222</span>   * compaction until after we have killed the server and the region has come up on<a name="line.222"></a>
+<span class="sourceLineNo">223</span>   * a new regionserver altogether.  This fakes the double assignment case where region in one<a name="line.223"></a>
+<span class="sourceLineNo">224</span>   * location changes the files out from underneath a region being served elsewhere.<a name="line.224"></a>
+<span class="sourceLineNo">225</span>   */<a name="line.225"></a>
+<span class="sourceLineNo">226</span>  @Test<a name="line.226"></a>
+<span class="sourceLineNo">227</span>  public void testFencingAroundCompaction() throws Exception {<a name="line.227"></a>
+<span class="sourceLineNo">228</span>    for(MemoryCompactionPolicy policy : MemoryCompactionPolicy.values()) {<a name="line.228"></a>
+<span class="sourceLineNo">229</span>      doTest(BlockCompactionsInPrepRegion.class, policy);<a name="line.229"></a>
+<span class="sourceLineNo">230</span>    }<a name="line.230"></a>
+<span class="sourceLineNo">231</span>  }<a name="line.231"></a>
+<span class="sourceLineNo">232</span><a name="line.232"></a>
+<span class="sourceLineNo">233</span>  /**<a name="line.233"></a>
+<span class="sourceLineNo">234</span>   * Test that puts up a regionserver, starts a compaction on a loaded region but holds the<a name="line.234"></a>
+<span class="sourceLineNo">235</span>   * compaction completion until after we have killed the server and the region has come up on<a name="line.235"></a>
+<span class="sourceLineNo">236</span>   * a new regionserver altogether.  This fakes the double assignment case where region in one<a name="line.236"></a>
+<span class="sourceLineNo">237</span>   * location changes the files out from underneath a region being served elsewhere.<a name="line.237"></a>
+<span class="sourceLineNo">238</span>   */<a name="line.238"></a>
+<span class="sourceLineNo">239</span>  @Test<a name="line.239"></a>
+<span class="sourceLineNo">240</span>  public void testFencingAroundCompactionAfterWALSync() throws Exception {<a name="line.240"></a>
+<span class="sourceLineNo">241</span>    for(MemoryCompactionPolicy policy : MemoryCompactionPolicy.values()) {<a name="line.241"></a>
+<span class="sourceLineNo">242</span>      doTest(BlockCompactionsInCompletionRegion.class, policy);<a name="line.242"></a>
+<span class="sourceLineNo">243</span>    }<a name="line.243"></a>
+<span class="sourceLineNo">244</span>  }<a name="line.244"></a>
+<span class="sourceLineNo">245</span><a name="line.245"></a>
+<span class="sourceLineNo">246</span>  public void doTest(Class&lt;?&gt; regionClass, MemoryCompactionPolicy policy) throws Exception {<a name="line.246"></a>
+<span class="sourceLineNo">247</span>    Configuration c = TEST_UTIL.getConfiguration();<a name="line.247"></a>
+<span class="sourceLineNo">248</span>    // Insert our custom region<a name="line.248"></a>
+<span class="sourceLineNo">249</span>    c.setClass(HConstants.REGION_IMPL, regionClass, HRegion.class);<a name="line.249"></a>
+<span class="sourceLineNo">250</span>    // Encourage plenty of flushes<a name="line.250"></a>
+<span class="sourceLineNo">251</span>    c.setLong("hbase.hregion.memstore.flush.size", 25000);<a name="line.251"></a>
+<span class="sourceLineNo">252</span>    c.set(HConstants.HBASE_REGION_SPLIT_POLICY_KEY, ConstantSizeRegionSplitPolicy.class.getName());<a name="line.252"></a>
+<span class="sourceLineNo">253</span>    // Only run compaction when we tell it to<a name="line.253"></a>
+<span class="sourceLineNo">254</span>    c.setInt("hbase.hstore.compaction.min",1);<a name="line.254"></a>
+<span class="sourceLineNo">255</span>    c.setInt("hbase.hstore.compactionThreshold", 1000);<a name="line.255"></a>
+<span class="sourceLineNo">256</span>    c.setLong("hbase.hstore.blockingStoreFiles", 1000);<a name="line.256"></a>
+<span class="sourceLineNo">257</span>    // Compact quickly after we tell it to!<a name="line.257"></a>
+<span class="sourceLineNo">258</span>    c.setInt("hbase.regionserver.thread.splitcompactcheckfrequency", 1000);<a name="line.258"></a>
+<span class="sourceLineNo">259</span>    c.set(CompactingMemStore.COMPACTING_MEMSTORE_TYPE_KEY, String.valueOf(policy));<a name="line.259"></a>
+<span class="sourceLineNo">260</span>    LOG.info("Starting mini cluster");<a name="line.260"></a>
+<span class="sourceLineNo">261</span>    TEST_UTIL.startMiniCluster(1);<a name="line.261"></a>
+<span class="sourceLineNo">262</span>    CompactionBlockerRegion compactingRegion = null;<a name="line.262"></a>
+<span class="sourceLineNo">263</span>    Admin admin = null;<a name="line.263"></a>
+<span class="sourceLineNo">264</span>    try {<a name="line.264"></a>
+<span class="sourceLineNo">265</span>      LOG.info("Creating admin");<a name="line.265"></a>
+<span class="sourceLineNo">266</span>      admin = TEST_UTIL.getConnection().getAdmin();<a name="line.266"></a>
+<span class="sourceLineNo">267</span>      LOG.info("Creating table");<a name="line.267"></a>
+<span class="sourceLineNo">268</span>      TEST_UTIL.createTable(TABLE_NAME, FAMILY);<a name="line.268"></a>
+<span class="sourceLineNo">269</span>      Table table = TEST_UTIL.getConnection().getTable(TABLE_NAME);<a name="line.269"></a>
+<span class="sourceLineNo">270</span>      LOG.info("Loading test table");<a name="line.270"></a>
+<span class="sourceLineNo">271</span>      // Find the region<a name="line.271"></a>
+<span class="sourceLineNo">272</span>      List&lt;HRegion&gt; testRegions = TEST_UTIL.getMiniHBaseCluster().findRegionsForTable(TABLE_NAME);<a name="line.272"></a>
+<span class="sourceLineNo">273</span>      assertEquals(1, testRegions.size());<a name="line.273"></a>
+<span class="sourceLineNo">274</span>      compactingRegion = (CompactionBlockerRegion)testRegions.get(0);<a name="line.274"></a>
+<span class="sourceLineNo">275</span>      LOG.info("Blocking compactions");<a name="line.275"></a>
+<span class="sourceLineNo">276</span>      compactingRegion.stopCompactions();<a name="line.276"></a>
+<span class="sourceLineNo">277</span>      long lastFlushTime = compactingRegion.getEarliestFlushTimeForAllStores();<a name="line.277"></a>
+<span class="sourceLineNo">278</span>      // Load some rows<a name="line.278"></a>
+<span class="sourceLineNo">279</span>      TEST_UTIL.loadNumericRows(table, FAMILY, 0, FIRST_BATCH_COUNT);<a name="line.279"></a>
+<span class="sourceLineNo">280</span><a name="line.280"></a>
+<span class="sourceLineNo">281</span>      // add a compaction from an older (non-existing) region to see whether we successfully skip<a name="line.281"></a>
+<span class="sourceLineNo">282</span>      // those entries<a name="line.282"></a>
+<span class="sourceLineNo">283</span>      HRegionInfo oldHri = new HRegionInfo(table.getName(),<a name="line.283"></a>
+<span class="sourceLineNo">284</span>        HConstants.EMPTY_START_ROW, HConstants.EMPTY_END_ROW);<a name="line.284"></a>
+<span class="sourceLineNo">285</span>      CompactionDescriptor compactionDescriptor = ProtobufUtil.toCompactionDescriptor(oldHri,<a name="line.285"></a>
+<span class="sourceLineNo">286</span>        FAMILY, Lists.newArrayList(new Path("/a")), Lists.newArrayList(new Path("/b")),<a name="line.286"></a>
+<span class="sourceLineNo">287</span>        new Path("store_dir"));<a name="line.287"></a>
+<span class="sourceLineNo">288</span>      WALUtil.writeCompactionMarker(compactingRegion.getWAL(),<a name="line.288"></a>
+<span class="sourceLineNo">289</span>          ((HRegion)compactingRegion).getReplicationScope(),<a name="line.289"></a>
+<span class="sourceLineNo">290</span>        oldHri, compactionDescriptor, compactingRegion.getMVCC());<a name="line.290"></a>
+<span class="sourceLineNo">291</span><a name="line.291"></a>
+<span class="sourceLineNo">292</span>      // Wait till flush has happened, otherwise there won't be multiple store files<a name="line.292"></a>
+<span class="sourceLineNo">293</span>      long startWaitTime = System.currentTimeMillis();<a name="line.293"></a>
+<span class="sourceLineNo">294</span>      while (compactingRegion.getEarliestFlushTimeForAllStores() &lt;= lastFlushTime ||<a name="line.294"></a>
+<span class="sourceLineNo">295</span>          compactingRegion.countStoreFiles() &lt;= 1) {<a name="line.295"></a>
+<span class="sourceLineNo">296</span>        LOG.info("Waiting for the region to flush " +<a name="line.296"></a>
+<span class="sourceLineNo">297</span>          compactingRegion.getRegionInfo().getRegionNameAsString());<a name="line.297"></a>
+<span class="sourceLineNo">298</span>        Thread.sleep(1000);<a name="line.298"></a>
+<span class="sourceLineNo">299</span>        assertTrue("Timed out waiting for the region to flush",<a name="line.299"></a>
+<span class="sourceLineNo">300</span>          System.currentTimeMillis() - startWaitTime &lt; 30000);<a name="line.300"></a>
+<span class="sourceLineNo">301</span>      }<a name="line.301"></a>
+<span class="sourceLineNo">302</span>      assertTrue(compactingRegion.countStoreFiles() &gt; 1);<a name="line.302"></a>
+<span class="sourceLineNo">303</span>      final byte REGION_NAME[] = compactingRegion.getRegionInfo().getRegionName();<a name="line.303"></a>
+<span class="sourceLineNo">304</span>      LOG.info("Asking for compaction");<a name="line.304"></a>
+<span class="sourceLineNo">305</span>      admin.majorCompact(TABLE_NAME);<a name="line.305"></a>
+<span class="sourceLineNo">306</span>      LOG.info("Waiting for compaction to be about to start");<a name="line.306"></a>
+<span class="sourceLineNo">307</span>      compactingRegion.waitForCompactionToBlock();<a name="line.307"></a>
+<span class="sourceLineNo">308</span>      LOG.info("Starting a new server");<a name="line.308"></a>
+<span class="sourceLineNo">309</span>      RegionServerThread newServerThread = TEST_UTIL.getMiniHBaseCluster().startRegionServer();<a name="line.309"></a>
+<span class="sourceLineNo">310</span>      final HRegionServer newServer = newServerThread.getRegionServer();<a name="line.310"></a>
+<span class="sourceLineNo">311</span>      LOG.info("Killing region server ZK lease");<a name="line.311"></a>
+<span class="sourceLineNo">312</span>      TEST_UTIL.expireRegionServerSession(0);<a name="line.312"></a>
+<span class="sourceLineNo">313</span>      CompactionBlockerRegion newRegion = null;<a name="line.313"></a>
+<span class="sourceLineNo">314</span>      startWaitTime = System.currentTimeMillis();<a name="line.314"></a>
+<span class="sourceLineNo">315</span>      LOG.info("Waiting for the new server to pick up the region " + Bytes.toString(REGION_NAME));<a name="line.315"></a>
+<span class="sourceLineNo">316</span><a name="line.316"></a>
+<span class="sourceLineNo">317</span>      // wait for region to be assigned and to go out of log replay if applicable<a name="line.317"></a>
+<span class="sourceLineNo">318</span>      Waiter.waitFor(c, 60000, new Waiter.Predicate&lt;Exception&gt;() {<a name="line.318"></a>
+<span class="sourceLineNo">319</span>        @Override<a name="line.319"></a>
+<span class="sourceLineNo">320</span>        public boolean evaluate() throws Exception {<a name="line.320"></a>
+<span class="sourceLineNo">321</span>          Region newRegion = newServer.getOnlineRegion(REGION_NAME);<a name="line.321"></a>
+<span class="sourceLineNo">322</span>          return newRegion != null &amp;&amp; !newRegion.isRecovering();<a name="line.322"></a>
+<span class="sourceLineNo">323</span>        }<a name="line.323"></a>
+<span class="sourceLineNo">324</span>      });<a name="line.324"></a>
 <span class="sourceLineNo">325</span><a name="line.325"></a>
-<span class="sourceLineNo">326</span>      // After compaction of old region finishes on the server that was going down, make sure that<a name="line.326"></a>
-<span class="sourceLineNo">327</span>      // all the files we expect are still working when region is up in new location.<a name="line.327"></a>
-<span class="sourceLineNo">328</span>      FileSystem fs = newRegion.getFilesystem();<a name="line.328"></a>
-<span class="sourceLineNo">329</span>      for (String f: newRegion.getStoreFileList(new byte [][] {FAMILY})) {<a name="line.329"></a>
-<span class="sourceLineNo">330</span>        assertTrue("After compaction, does not exist: " + f, fs.exists(new Path(f)));<a name="line.330"></a>
-<span class="sourceLineNo">331</span>      }<a name="line.331"></a>
-<span class="sourceLineNo">332</span>      LOG.info("Allowing compaction to proceed");<a name="line.332"></a>
-<span class="sourceLineNo">333</span>      compactingRegion.allowCompactions();<a name="line.333"></a>
-<span class="sourceLineNo">334</span>      while (compactingRegion.compactCount == 0) {<a name="line.334"></a>
-<span class="sourceLineNo">335</span>        Thread.sleep(1000);<a name="line.335"></a>
-<span class="sourceLineNo">336</span>      }<a name="line.336"></a>
-<span class="sourceLineNo">337</span>      // The server we killed stays up until the compaction that was started before it was killed completes.  In logs<a name="line.337"></a>
-<span class="sourceLineNo">338</span>      // you should see the old regionserver now going down.<a name="line.338"></a>
-<span class="sourceLineNo">339</span>      LOG.info("Compaction finished");<a name="line.339"></a>
-<span class="sourceLineNo">340</span><a name="line.340"></a>
-<span class="sourceLineNo">341</span>      // If we survive the split keep going...<a name="line.341"></a>
-<span class="sourceLineNo">342</span>      // Now we make sure that the region isn't totally confused.  Load up more rows.<a name="line.342"></a>
-<span class="sourceLineNo">343</span>      TEST_UTIL.loadNumericRows(table, FAMILY, FIRST_BATCH_COUNT, FIRST_BATCH_COUNT + SECOND_BATCH_COUNT);<a name="line.343"></a>
-<span class="sourceLineNo">344</span>      admin.majorCompact(TABLE_NAME);<a name="line.344"></a>
-<span class="sourceLineNo">345</span>      startWaitTime = System.currentTimeMillis();<a name="line.345"></a>
-<span class="sourceLineNo">346</span>      while (newRegion.compactCount == 0) {<a name="line.346"></a>
-<span class="sourceLineNo">347</span>        Thread.sleep(1000);<a name="line.347"></a>
-<span class="sourceLineNo">348</span>        assertTrue("New region never compacted", System.currentTimeMillis() - startWaitTime &lt; 180000);<a name="line.348"></a>
-<span class="sourceLineNo">349</span>      }<a name="line.349"></a>
-<span class="sourceLineNo">350</span>      if(policy == MemoryCompactionPolicy.EAGER) {<a name="line.350"></a>
-<span class="sourceLineNo">351</span>        assertTrue(FIRST_BATCH_COUNT + SECOND_BATCH_COUNT &gt;= TEST_UTIL.countRows(table));<a name="line.351"></a>
-<span class="sourceLineNo">352</span>      } else {<a name="line.352"></a>
-<span class="sourceLineNo">353</span>        assertEquals(FIRST_BATCH_COUNT + SECOND_BATCH_COUNT, TEST_UTIL.countRows(table));<a name="line.353"></a>
-<span class="sourceLineNo">354</span>      }<a name="line.354"></a>
-<span class="sourceLineNo">355</span>    } finally {<a name="line.355"></a>
-<span class="sourceLineNo">356</span>      if (compactingRegion != null) {<a name="line.356"></a>
-<span class="sourceLineNo">357</span>        compactingRegion.allowCompactions();<a name="line.357"></a>
-<span class="sourceLineNo">358</span>      }<a name="line.358"></a>
-<span class="sourceLineNo">359</span>      admin.close();<a name="line.359"></a>
-<span class="sourceLineNo">360</span>      TEST_UTIL.shutdownMiniCluster();<a name="line.360"></a>
-<span class="sourceLineNo">361</span>    }<a name="line.361"></a>
-<span class="sourceLineNo">362</span>  }<a name="line.362"></a>
-<span class="sourceLineNo">363</span>}<a name="line.363"></a>
+<span class="sourceLineNo">326</span>      newRegion = (CompactionBlockerRegion)newServer.getOnlineRegion(REGION_NAME);<a name="line.326"></a>
+<span class="sourceLineNo">327</span><a name="line.327"></a>
+<span class="sourceLineNo">328</span>      // After compaction of old region finishes on the server that was going down, make sure that<a name="line.328"></a>
+<span class="sourceLineNo">329</span>      // all the files we expect are still working when region is up in new location.<a name="line.329"></a>
+<span class="sourceLineNo">330</span>      FileSystem fs = newRegion.getFilesystem();<a name="line.330"></a>
+<span class="sourceLineNo">331</span>      for (String f: newRegion.getStoreFileList(new byte [][] {FAMILY})) {<a name="line.331"></a>
+<span class="sourceLineNo">332</span>        assertTrue("After compaction, does not exist: " + f, fs.exists(new Path(f)));<a name="line.332"></a>
+<span class="sourceLineNo">333</span>      }<a name="line.333"></a>
+<span class="sourceLineNo">334</span>      LOG.info("Allowing compaction to proceed");<a name="line.334"></a>
+<span class="sourceLineNo">335</span>      compactingRegion.allowCompactions();<a name="line.335"></a>
+<span class="sourceLineNo">336</span>      while (compactingRegion.compactCount == 0) {<a name="line.336"></a>
+<span class="sourceLineNo">337</span>        Thread.sleep(1000);<a name="line.337"></a>
+<span class="sourceLineNo">338</span>      }<a name="line.338"></a>
+<span class="sourceLineNo">339</span>      // The server we killed stays up until the compaction that was started before it was killed<a name="line.339"></a>
+<span class="sourceLineNo">340</span>      // completes. In logs you should see the old regionserver now going down.<a name="line.340"></a>
+<span class="sourceLineNo">341</span>      LOG.info("Compaction finished");<a name="line.341"></a>
+<span class="sourceLineNo">342</span><a name="line.342"></a>
+<span class="sourceLineNo">343</span>      // If we survive the split keep going...<a name="line.343"></a>
+<span class="sourceLineNo">344</span>      // Now we make sure that the region isn't totally confused.  Load up more rows.<a name="line.344"></a>
+<span class="sourceLineNo">345</span>      TEST_UTIL.loadNumericRows(table, FAMILY, FIRST_BATCH_COUNT,<a name="line.345"></a>
+<span class="sourceLineNo">346</span>        FIRST_BATCH_COUNT + SECOND_BATCH_COUNT);<a name="line.346"></a>
+<span class="sourceLineNo">347</span>      admin.majorCompact(TABLE_NAME);<a name="line.347"></a>
+<span class="sourceLineNo">348</span>      startWaitTime = System.currentTimeMillis();<a name="line.348"></a>
+<span class="sourceLineNo">349</span>      while (newRegion.compactCount == 0) {<a name="line.349"></a>
+<span class="sourceLineNo">350</span>        Thread.sleep(1000);<a name="line.350"></a>
+<span class="sourceLineNo">351</span>        assertTrue("New region never compacted",<a name="line.351"></a>
+<span class="sourceLineNo">352</span>          System.currentTimeMillis() - startWaitTime &lt; 180000);<a name="line.352"></a>
+<span class="sourceLineNo">353</span>      }<a name="line.353"></a>
+<span class="sourceLineNo">354</span>      int count;<a name="line.354"></a>
+<span class="sourceLineNo">355</span>      for (int i = 0;; i++) {<a name="line.355"></a>
+<span class="sourceLineNo">356</span>        try {<a name="line.356"></a>
+<span class="sourceLineNo">357</span>          count = TEST_UTIL.countRows(table);<a name="line.357"></a>
+<span class="sourceLineNo">358</span>          break;<a name="line.358"></a>
+<span class="sourceLineNo">359</span>        } catch (DoNotRetryIOException e) {<a name="line.359"></a>
+<span class="sourceLineNo">360</span>          // wait up to 30s<a name="line.360"></a>
+<span class="sourceLineNo">361</span>          if (i &gt;= 30 || !e.getMessage().contains("File does not exist")) {<a name="line.361"></a>
+<span class="sourceLineNo">362</span>            throw e;<a name="line.362"></a>
+<span class="sourceLineNo">363</span>          }<a name="line.363"></a>
+<span class="sourceLineNo">364</span>          Thread.sleep(1000);<a name="line.364"></a>
+<span class="sourceLineNo">365</span>        }<a name="line.365"></a>
+<span class="sourceLineNo">366</span>      }<a name="line.366"></a>
+<span class="sourceLineNo">367</span>      if (policy == MemoryCompactionPolicy.EAGER) {<a name="line.367"></a>
+<span class="sourceLineNo">368</span>        assertTrue(FIRST_BATCH_COUNT + SECOND_BATCH_COUNT &gt;= count);<a name="line.368"></a>
+<span class="sourceLineNo">369</span>      } else {<a name="line.369"></a>
+<span class="sourceLineNo">370</span>        assertEquals(FIRST_BATCH_COUNT + SECOND_BATCH_COUNT, count);<a name="line.370"></a>
+<span class="sourceLineNo">371</span>      }<a name="line.371"></a>
+<span class="sourceLineNo">372</span>    } finally {<a name="line.372"></a>
+<span class="sourceLineNo">373</span>      if (compactingRegion != null) {<a name="line.373"></a>
+<span class="sourceLineNo">374</span>        compactingRegion.allowCompactions();<a name="line.374"></a>
+<span class="sourceLineNo">375</span>      }<a name="line.375"></a>
+<span class="sourceLineNo">376</span>      admin.close();<a name="line.376"></a>
+<span class="sourceLineNo">377</span>      TEST_UTIL.shutdownMiniCluster();<a name="line.377"></a>
+<span class="sourceLineNo">378</span>    }<a name="line.378"></a>
+<span class="sourceLineNo">379</span>  }<a name="line.379"></a>
+<span class="sourceLineNo">380</span>}<a name="line.380"></a>
 
 
 


Mime
View raw message