hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From git-site-r...@apache.org
Subject [05/32] hbase-site git commit: Published site at 82d554e3783372cc6b05489452c815b57c06f6cd.
Date Fri, 26 May 2017 14:59:55 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/be6f38d2/testdevapidocs/src-html/org/apache/hadoop/hbase/regionserver/TestMemStoreLAB.html
----------------------------------------------------------------------
diff --git a/testdevapidocs/src-html/org/apache/hadoop/hbase/regionserver/TestMemStoreLAB.html b/testdevapidocs/src-html/org/apache/hadoop/hbase/regionserver/TestMemStoreLAB.html
index 8043566..e563799 100644
--- a/testdevapidocs/src-html/org/apache/hadoop/hbase/regionserver/TestMemStoreLAB.html
+++ b/testdevapidocs/src-html/org/apache/hadoop/hbase/regionserver/TestMemStoreLAB.html
@@ -48,268 +48,276 @@
 <span class="sourceLineNo">040</span>import org.apache.hadoop.hbase.testclassification.RegionServerTests;<a name="line.40"></a>
 <span class="sourceLineNo">041</span>import org.apache.hadoop.hbase.testclassification.SmallTests;<a name="line.41"></a>
 <span class="sourceLineNo">042</span>import org.apache.hadoop.hbase.util.Bytes;<a name="line.42"></a>
-<span class="sourceLineNo">043</span>import org.junit.BeforeClass;<a name="line.43"></a>
-<span class="sourceLineNo">044</span>import org.junit.Test;<a name="line.44"></a>
-<span class="sourceLineNo">045</span><a name="line.45"></a>
-<span class="sourceLineNo">046</span>import com.google.common.collect.Iterables;<a name="line.46"></a>
-<span class="sourceLineNo">047</span>import com.google.common.collect.Lists;<a name="line.47"></a>
-<span class="sourceLineNo">048</span>import com.google.common.collect.Maps;<a name="line.48"></a>
-<span class="sourceLineNo">049</span>import com.google.common.primitives.Ints;<a name="line.49"></a>
-<span class="sourceLineNo">050</span><a name="line.50"></a>
-<span class="sourceLineNo">051</span>import org.junit.experimental.categories.Category;<a name="line.51"></a>
-<span class="sourceLineNo">052</span><a name="line.52"></a>
-<span class="sourceLineNo">053</span>@Category({RegionServerTests.class, SmallTests.class})<a name="line.53"></a>
-<span class="sourceLineNo">054</span>public class TestMemStoreLAB {<a name="line.54"></a>
-<span class="sourceLineNo">055</span><a name="line.55"></a>
-<span class="sourceLineNo">056</span>  private final static Configuration conf = new Configuration();<a name="line.56"></a>
-<span class="sourceLineNo">057</span><a name="line.57"></a>
-<span class="sourceLineNo">058</span>  private static final byte[] rk = Bytes.toBytes("r1");<a name="line.58"></a>
-<span class="sourceLineNo">059</span>  private static final byte[] cf = Bytes.toBytes("f");<a name="line.59"></a>
-<span class="sourceLineNo">060</span>  private static final byte[] q = Bytes.toBytes("q");<a name="line.60"></a>
-<span class="sourceLineNo">061</span><a name="line.61"></a>
-<span class="sourceLineNo">062</span>  @BeforeClass<a name="line.62"></a>
-<span class="sourceLineNo">063</span>  public static void setUpBeforeClass() throws Exception {<a name="line.63"></a>
-<span class="sourceLineNo">064</span>    long globalMemStoreLimit = (long) (ManagementFactory.getMemoryMXBean().getHeapMemoryUsage()<a name="line.64"></a>
-<span class="sourceLineNo">065</span>        .getMax() * MemorySizeUtil.getGlobalMemStoreHeapPercent(conf, false));<a name="line.65"></a>
-<span class="sourceLineNo">066</span>    ChunkCreator.initialize(MemStoreLABImpl.CHUNK_SIZE_DEFAULT, false, globalMemStoreLimit,<a name="line.66"></a>
-<span class="sourceLineNo">067</span>      0.2f, MemStoreLAB.POOL_INITIAL_SIZE_DEFAULT, null);<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>   * Test a bunch of random allocations<a name="line.71"></a>
-<span class="sourceLineNo">072</span>   */<a name="line.72"></a>
-<span class="sourceLineNo">073</span>  @Test<a name="line.73"></a>
-<span class="sourceLineNo">074</span>  public void testLABRandomAllocation() {<a name="line.74"></a>
-<span class="sourceLineNo">075</span>    Random rand = new Random();<a name="line.75"></a>
-<span class="sourceLineNo">076</span>    MemStoreLAB mslab = new MemStoreLABImpl();<a name="line.76"></a>
-<span class="sourceLineNo">077</span>    int expectedOff = 0;<a name="line.77"></a>
-<span class="sourceLineNo">078</span>    ByteBuffer lastBuffer = null;<a name="line.78"></a>
-<span class="sourceLineNo">079</span>    int lastChunkId = -1;<a name="line.79"></a>
-<span class="sourceLineNo">080</span>    // 100K iterations by 0-1K alloc -&gt; 50MB expected<a name="line.80"></a>
-<span class="sourceLineNo">081</span>    // should be reasonable for unit test and also cover wraparound<a name="line.81"></a>
-<span class="sourceLineNo">082</span>    // behavior<a name="line.82"></a>
-<span class="sourceLineNo">083</span>    for (int i = 0; i &lt; 100000; i++) {<a name="line.83"></a>
-<span class="sourceLineNo">084</span>      int valSize = rand.nextInt(1000);<a name="line.84"></a>
-<span class="sourceLineNo">085</span>      KeyValue kv = new KeyValue(rk, cf, q, new byte[valSize]);<a name="line.85"></a>
-<span class="sourceLineNo">086</span>      int size = KeyValueUtil.length(kv);<a name="line.86"></a>
-<span class="sourceLineNo">087</span>      ByteBufferKeyValue newKv = (ByteBufferKeyValue) mslab.copyCellInto(kv);<a name="line.87"></a>
-<span class="sourceLineNo">088</span>      if (newKv.getBuffer() != lastBuffer) {<a name="line.88"></a>
-<span class="sourceLineNo">089</span>        // since we add the chunkID at the 0th offset of the chunk and the<a name="line.89"></a>
-<span class="sourceLineNo">090</span>        // chunkid is an int we need to account for those 4 bytes<a name="line.90"></a>
-<span class="sourceLineNo">091</span>        expectedOff = Bytes.SIZEOF_INT;<a name="line.91"></a>
-<span class="sourceLineNo">092</span>        lastBuffer = newKv.getBuffer();<a name="line.92"></a>
-<span class="sourceLineNo">093</span>        int chunkId = newKv.getBuffer().getInt(0);<a name="line.93"></a>
-<span class="sourceLineNo">094</span>        assertTrue("chunkid should be different", chunkId != lastChunkId);<a name="line.94"></a>
-<span class="sourceLineNo">095</span>        lastChunkId = chunkId;<a name="line.95"></a>
-<span class="sourceLineNo">096</span>      }<a name="line.96"></a>
-<span class="sourceLineNo">097</span>      assertEquals(expectedOff, newKv.getOffset());<a name="line.97"></a>
-<span class="sourceLineNo">098</span>      assertTrue("Allocation overruns buffer",<a name="line.98"></a>
-<span class="sourceLineNo">099</span>          newKv.getOffset() + size &lt;= newKv.getBuffer().capacity());<a name="line.99"></a>
-<span class="sourceLineNo">100</span>      expectedOff += size;<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><a name="line.103"></a>
-<span class="sourceLineNo">104</span>  @Test<a name="line.104"></a>
-<span class="sourceLineNo">105</span>  public void testLABLargeAllocation() {<a name="line.105"></a>
-<span class="sourceLineNo">106</span>    MemStoreLAB mslab = new MemStoreLABImpl();<a name="line.106"></a>
-<span class="sourceLineNo">107</span>    KeyValue kv = new KeyValue(rk, cf, q, new byte[2 * 1024 * 1024]);<a name="line.107"></a>
-<span class="sourceLineNo">108</span>    Cell newCell = mslab.copyCellInto(kv);<a name="line.108"></a>
-<span class="sourceLineNo">109</span>    assertNull("2MB allocation shouldn't be satisfied by LAB.", newCell);<a name="line.109"></a>
+<span class="sourceLineNo">043</span>import org.junit.AfterClass;<a name="line.43"></a>
+<span class="sourceLineNo">044</span>import org.junit.BeforeClass;<a name="line.44"></a>
+<span class="sourceLineNo">045</span>import org.junit.Test;<a name="line.45"></a>
+<span class="sourceLineNo">046</span><a name="line.46"></a>
+<span class="sourceLineNo">047</span>import com.google.common.collect.Iterables;<a name="line.47"></a>
+<span class="sourceLineNo">048</span>import com.google.common.collect.Lists;<a name="line.48"></a>
+<span class="sourceLineNo">049</span>import com.google.common.collect.Maps;<a name="line.49"></a>
+<span class="sourceLineNo">050</span>import com.google.common.primitives.Ints;<a name="line.50"></a>
+<span class="sourceLineNo">051</span><a name="line.51"></a>
+<span class="sourceLineNo">052</span>import org.junit.experimental.categories.Category;<a name="line.52"></a>
+<span class="sourceLineNo">053</span><a name="line.53"></a>
+<span class="sourceLineNo">054</span>@Category({RegionServerTests.class, SmallTests.class})<a name="line.54"></a>
+<span class="sourceLineNo">055</span>public class TestMemStoreLAB {<a name="line.55"></a>
+<span class="sourceLineNo">056</span><a name="line.56"></a>
+<span class="sourceLineNo">057</span>  private final static Configuration conf = new Configuration();<a name="line.57"></a>
+<span class="sourceLineNo">058</span><a name="line.58"></a>
+<span class="sourceLineNo">059</span>  private static final byte[] rk = Bytes.toBytes("r1");<a name="line.59"></a>
+<span class="sourceLineNo">060</span>  private static final byte[] cf = Bytes.toBytes("f");<a name="line.60"></a>
+<span class="sourceLineNo">061</span>  private static final byte[] q = Bytes.toBytes("q");<a name="line.61"></a>
+<span class="sourceLineNo">062</span><a name="line.62"></a>
+<span class="sourceLineNo">063</span>  @BeforeClass<a name="line.63"></a>
+<span class="sourceLineNo">064</span>  public static void setUpBeforeClass() throws Exception {<a name="line.64"></a>
+<span class="sourceLineNo">065</span>    ChunkCreator.initialize(1 * 1024, false, 50*1024000l, 0.2f, MemStoreLAB.POOL_INITIAL_SIZE_DEFAULT,<a name="line.65"></a>
+<span class="sourceLineNo">066</span>      null);<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>  @AfterClass<a name="line.69"></a>
+<span class="sourceLineNo">070</span>  public static void tearDownAfterClass() throws Exception {<a name="line.70"></a>
+<span class="sourceLineNo">071</span>    long globalMemStoreLimit =<a name="line.71"></a>
+<span class="sourceLineNo">072</span>        (long) (ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax()<a name="line.72"></a>
+<span class="sourceLineNo">073</span>            * MemorySizeUtil.getGlobalMemStoreHeapPercent(conf, false));<a name="line.73"></a>
+<span class="sourceLineNo">074</span>    ChunkCreator.initialize(MemStoreLABImpl.CHUNK_SIZE_DEFAULT, false, globalMemStoreLimit, 0.2f,<a name="line.74"></a>
+<span class="sourceLineNo">075</span>      MemStoreLAB.POOL_INITIAL_SIZE_DEFAULT, null);<a name="line.75"></a>
+<span class="sourceLineNo">076</span>  }<a name="line.76"></a>
+<span class="sourceLineNo">077</span><a name="line.77"></a>
+<span class="sourceLineNo">078</span>  /**<a name="line.78"></a>
+<span class="sourceLineNo">079</span>   * Test a bunch of random allocations<a name="line.79"></a>
+<span class="sourceLineNo">080</span>   */<a name="line.80"></a>
+<span class="sourceLineNo">081</span>  @Test<a name="line.81"></a>
+<span class="sourceLineNo">082</span>  public void testLABRandomAllocation() {<a name="line.82"></a>
+<span class="sourceLineNo">083</span>    Random rand = new Random();<a name="line.83"></a>
+<span class="sourceLineNo">084</span>    MemStoreLAB mslab = new MemStoreLABImpl();<a name="line.84"></a>
+<span class="sourceLineNo">085</span>    int expectedOff = 0;<a name="line.85"></a>
+<span class="sourceLineNo">086</span>    ByteBuffer lastBuffer = null;<a name="line.86"></a>
+<span class="sourceLineNo">087</span>    int lastChunkId = -1;<a name="line.87"></a>
+<span class="sourceLineNo">088</span>    // 100K iterations by 0-1K alloc -&gt; 50MB expected<a name="line.88"></a>
+<span class="sourceLineNo">089</span>    // should be reasonable for unit test and also cover wraparound<a name="line.89"></a>
+<span class="sourceLineNo">090</span>    // behavior<a name="line.90"></a>
+<span class="sourceLineNo">091</span>    for (int i = 0; i &lt; 100000; i++) {<a name="line.91"></a>
+<span class="sourceLineNo">092</span>      int valSize = rand.nextInt(3);<a name="line.92"></a>
+<span class="sourceLineNo">093</span>      KeyValue kv = new KeyValue(rk, cf, q, new byte[valSize]);<a name="line.93"></a>
+<span class="sourceLineNo">094</span>      int size = KeyValueUtil.length(kv);<a name="line.94"></a>
+<span class="sourceLineNo">095</span>      ByteBufferKeyValue newKv = (ByteBufferKeyValue) mslab.copyCellInto(kv);<a name="line.95"></a>
+<span class="sourceLineNo">096</span>      if (newKv.getBuffer() != lastBuffer) {<a name="line.96"></a>
+<span class="sourceLineNo">097</span>        // since we add the chunkID at the 0th offset of the chunk and the<a name="line.97"></a>
+<span class="sourceLineNo">098</span>        // chunkid is an int we need to account for those 4 bytes<a name="line.98"></a>
+<span class="sourceLineNo">099</span>        expectedOff = Bytes.SIZEOF_INT;<a name="line.99"></a>
+<span class="sourceLineNo">100</span>        lastBuffer = newKv.getBuffer();<a name="line.100"></a>
+<span class="sourceLineNo">101</span>        int chunkId = newKv.getBuffer().getInt(0);<a name="line.101"></a>
+<span class="sourceLineNo">102</span>        assertTrue("chunkid should be different", chunkId != lastChunkId);<a name="line.102"></a>
+<span class="sourceLineNo">103</span>        lastChunkId = chunkId;<a name="line.103"></a>
+<span class="sourceLineNo">104</span>      }<a name="line.104"></a>
+<span class="sourceLineNo">105</span>      assertEquals(expectedOff, newKv.getOffset());<a name="line.105"></a>
+<span class="sourceLineNo">106</span>      assertTrue("Allocation overruns buffer",<a name="line.106"></a>
+<span class="sourceLineNo">107</span>          newKv.getOffset() + size &lt;= newKv.getBuffer().capacity());<a name="line.107"></a>
+<span class="sourceLineNo">108</span>      expectedOff += size;<a name="line.108"></a>
+<span class="sourceLineNo">109</span>    }<a name="line.109"></a>
 <span class="sourceLineNo">110</span>  }<a name="line.110"></a>
 <span class="sourceLineNo">111</span><a name="line.111"></a>
-<span class="sourceLineNo">112</span>  /**<a name="line.112"></a>
-<span class="sourceLineNo">113</span>   * Test allocation from lots of threads, making sure the results don't<a name="line.113"></a>
-<span class="sourceLineNo">114</span>   * overlap in any way<a name="line.114"></a>
-<span class="sourceLineNo">115</span>   */<a name="line.115"></a>
-<span class="sourceLineNo">116</span>  @Test<a name="line.116"></a>
-<span class="sourceLineNo">117</span>  public void testLABThreading() throws Exception {<a name="line.117"></a>
-<span class="sourceLineNo">118</span>    Configuration conf = new Configuration();<a name="line.118"></a>
-<span class="sourceLineNo">119</span>    MultithreadedTestUtil.TestContext ctx =<a name="line.119"></a>
-<span class="sourceLineNo">120</span>      new MultithreadedTestUtil.TestContext(conf);<a name="line.120"></a>
-<span class="sourceLineNo">121</span>    <a name="line.121"></a>
-<span class="sourceLineNo">122</span>    final AtomicInteger totalAllocated = new AtomicInteger();<a name="line.122"></a>
-<span class="sourceLineNo">123</span>    <a name="line.123"></a>
-<span class="sourceLineNo">124</span>    final MemStoreLAB mslab = new MemStoreLABImpl();<a name="line.124"></a>
-<span class="sourceLineNo">125</span>    List&lt;List&lt;AllocRecord&gt;&gt; allocations = Lists.newArrayList();<a name="line.125"></a>
-<span class="sourceLineNo">126</span>    <a name="line.126"></a>
-<span class="sourceLineNo">127</span>    for (int i = 0; i &lt; 10; i++) {<a name="line.127"></a>
-<span class="sourceLineNo">128</span>      final List&lt;AllocRecord&gt; allocsByThisThread = Lists.newLinkedList();<a name="line.128"></a>
-<span class="sourceLineNo">129</span>      allocations.add(allocsByThisThread);<a name="line.129"></a>
-<span class="sourceLineNo">130</span>      <a name="line.130"></a>
-<span class="sourceLineNo">131</span>      TestThread t = new MultithreadedTestUtil.RepeatingTestThread(ctx) {<a name="line.131"></a>
-<span class="sourceLineNo">132</span>        private Random r = new Random();<a name="line.132"></a>
-<span class="sourceLineNo">133</span>        @Override<a name="line.133"></a>
-<span class="sourceLineNo">134</span>        public void doAnAction() throws Exception {<a name="line.134"></a>
-<span class="sourceLineNo">135</span>          int valSize = r.nextInt(1000);<a name="line.135"></a>
-<span class="sourceLineNo">136</span>          KeyValue kv = new KeyValue(rk, cf, q, new byte[valSize]);<a name="line.136"></a>
-<span class="sourceLineNo">137</span>          int size = KeyValueUtil.length(kv);<a name="line.137"></a>
-<span class="sourceLineNo">138</span>          ByteBufferKeyValue newCell = (ByteBufferKeyValue) mslab.copyCellInto(kv);<a name="line.138"></a>
-<span class="sourceLineNo">139</span>          totalAllocated.addAndGet(size);<a name="line.139"></a>
-<span class="sourceLineNo">140</span>          allocsByThisThread.add(new AllocRecord(newCell.getBuffer(), newCell.getOffset(), size));<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>      ctx.addThread(t);<a name="line.143"></a>
-<span class="sourceLineNo">144</span>    }<a name="line.144"></a>
-<span class="sourceLineNo">145</span><a name="line.145"></a>
-<span class="sourceLineNo">146</span>    ctx.startThreads();<a name="line.146"></a>
-<span class="sourceLineNo">147</span>    while (totalAllocated.get() &lt; 50*1024*1024 &amp;&amp; ctx.shouldRun()) {<a name="line.147"></a>
-<span class="sourceLineNo">148</span>      Thread.sleep(10);<a name="line.148"></a>
-<span class="sourceLineNo">149</span>    }<a name="line.149"></a>
-<span class="sourceLineNo">150</span>    ctx.stop();<a name="line.150"></a>
-<span class="sourceLineNo">151</span>    // Partition the allocations by the actual byte[] they point into,<a name="line.151"></a>
-<span class="sourceLineNo">152</span>    // make sure offsets are unique for each chunk<a name="line.152"></a>
-<span class="sourceLineNo">153</span>    Map&lt;ByteBuffer, Map&lt;Integer, AllocRecord&gt;&gt; mapsByChunk =<a name="line.153"></a>
-<span class="sourceLineNo">154</span>      Maps.newHashMap();<a name="line.154"></a>
-<span class="sourceLineNo">155</span><a name="line.155"></a>
-<span class="sourceLineNo">156</span>    int sizeCounted = 0;<a name="line.156"></a>
-<span class="sourceLineNo">157</span>    for (AllocRecord rec : Iterables.concat(allocations)) {<a name="line.157"></a>
-<span class="sourceLineNo">158</span>      sizeCounted += rec.size;<a name="line.158"></a>
-<span class="sourceLineNo">159</span>      if (rec.size == 0) continue;<a name="line.159"></a>
-<span class="sourceLineNo">160</span>      Map&lt;Integer, AllocRecord&gt; mapForThisByteArray =<a name="line.160"></a>
-<span class="sourceLineNo">161</span>        mapsByChunk.get(rec.alloc);<a name="line.161"></a>
-<span class="sourceLineNo">162</span>      if (mapForThisByteArray == null) {<a name="line.162"></a>
-<span class="sourceLineNo">163</span>        mapForThisByteArray = Maps.newTreeMap();<a name="line.163"></a>
-<span class="sourceLineNo">164</span>        mapsByChunk.put(rec.alloc, mapForThisByteArray);<a name="line.164"></a>
-<span class="sourceLineNo">165</span>      }<a name="line.165"></a>
-<span class="sourceLineNo">166</span>      AllocRecord oldVal = mapForThisByteArray.put(rec.offset, rec);<a name="line.166"></a>
-<span class="sourceLineNo">167</span>      assertNull("Already had an entry " + oldVal + " for allocation " + rec,<a name="line.167"></a>
-<span class="sourceLineNo">168</span>          oldVal);<a name="line.168"></a>
-<span class="sourceLineNo">169</span>    }<a name="line.169"></a>
-<span class="sourceLineNo">170</span>    assertEquals("Sanity check test", sizeCounted, totalAllocated.get());<a name="line.170"></a>
-<span class="sourceLineNo">171</span>    <a name="line.171"></a>
-<span class="sourceLineNo">172</span>    // Now check each byte array to make sure allocations don't overlap<a name="line.172"></a>
-<span class="sourceLineNo">173</span>    for (Map&lt;Integer, AllocRecord&gt; allocsInChunk : mapsByChunk.values()) {<a name="line.173"></a>
-<span class="sourceLineNo">174</span>      // since we add the chunkID at the 0th offset of the chunk and the<a name="line.174"></a>
-<span class="sourceLineNo">175</span>      // chunkid is an int we need to account for those 4 bytes<a name="line.175"></a>
-<span class="sourceLineNo">176</span>      int expectedOff = Bytes.SIZEOF_INT;<a name="line.176"></a>
-<span class="sourceLineNo">177</span>      for (AllocRecord alloc : allocsInChunk.values()) {<a name="line.177"></a>
-<span class="sourceLineNo">178</span>        assertEquals(expectedOff, alloc.offset);<a name="line.178"></a>
-<span class="sourceLineNo">179</span>        assertTrue("Allocation overruns buffer",<a name="line.179"></a>
-<span class="sourceLineNo">180</span>            alloc.offset + alloc.size &lt;= alloc.alloc.capacity());<a name="line.180"></a>
-<span class="sourceLineNo">181</span>        expectedOff += alloc.size;<a name="line.181"></a>
-<span class="sourceLineNo">182</span>      }<a name="line.182"></a>
-<span class="sourceLineNo">183</span>    }<a name="line.183"></a>
-<span class="sourceLineNo">184</span>  }<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>   * Test frequent chunk retirement with chunk pool triggered by lots of threads, making sure<a name="line.187"></a>
-<span class="sourceLineNo">188</span>   * there's no memory leak (HBASE-16195)<a name="line.188"></a>
-<span class="sourceLineNo">189</span>   * @throws Exception if any error occurred<a name="line.189"></a>
-<span class="sourceLineNo">190</span>   */<a name="line.190"></a>
-<span class="sourceLineNo">191</span>  @Test<a name="line.191"></a>
-<span class="sourceLineNo">192</span>  public void testLABChunkQueue() throws Exception {<a name="line.192"></a>
-<span class="sourceLineNo">193</span>    ChunkCreator oldInstance = null;<a name="line.193"></a>
-<span class="sourceLineNo">194</span>    try {<a name="line.194"></a>
-<span class="sourceLineNo">195</span>      MemStoreLABImpl mslab = new MemStoreLABImpl();<a name="line.195"></a>
-<span class="sourceLineNo">196</span>      // by default setting, there should be no chunks initialized in the pool<a name="line.196"></a>
-<span class="sourceLineNo">197</span>      assertTrue(mslab.getPooledChunks().isEmpty());<a name="line.197"></a>
-<span class="sourceLineNo">198</span>      oldInstance = ChunkCreator.INSTANCE;<a name="line.198"></a>
-<span class="sourceLineNo">199</span>      ChunkCreator.INSTANCE = null;<a name="line.199"></a>
-<span class="sourceLineNo">200</span>      // reset mslab with chunk pool<a name="line.200"></a>
-<span class="sourceLineNo">201</span>      Configuration conf = HBaseConfiguration.create();<a name="line.201"></a>
-<span class="sourceLineNo">202</span>      conf.setDouble(MemStoreLAB.CHUNK_POOL_MAXSIZE_KEY, 0.1);<a name="line.202"></a>
-<span class="sourceLineNo">203</span>      // set chunk size to default max alloc size, so we could easily trigger chunk retirement<a name="line.203"></a>
-<span class="sourceLineNo">204</span>      conf.setLong(MemStoreLABImpl.CHUNK_SIZE_KEY, MemStoreLABImpl.MAX_ALLOC_DEFAULT);<a name="line.204"></a>
-<span class="sourceLineNo">205</span>      // reconstruct mslab<a name="line.205"></a>
-<span class="sourceLineNo">206</span>      long globalMemStoreLimit = (long) (ManagementFactory.getMemoryMXBean().getHeapMemoryUsage()<a name="line.206"></a>
-<span class="sourceLineNo">207</span>          .getMax() * MemorySizeUtil.getGlobalMemStoreHeapPercent(conf, false));<a name="line.207"></a>
-<span class="sourceLineNo">208</span>      ChunkCreator.initialize(MemStoreLABImpl.MAX_ALLOC_DEFAULT, false,<a name="line.208"></a>
-<span class="sourceLineNo">209</span>        globalMemStoreLimit, 0.1f, MemStoreLAB.POOL_INITIAL_SIZE_DEFAULT, null);<a name="line.209"></a>
-<span class="sourceLineNo">210</span>      ChunkCreator.clearDisableFlag();<a name="line.210"></a>
-<span class="sourceLineNo">211</span>      mslab = new MemStoreLABImpl(conf);<a name="line.211"></a>
-<span class="sourceLineNo">212</span>      // launch multiple threads to trigger frequent chunk retirement<a name="line.212"></a>
-<span class="sourceLineNo">213</span>      List&lt;Thread&gt; threads = new ArrayList&lt;&gt;();<a name="line.213"></a>
-<span class="sourceLineNo">214</span>      final KeyValue kv = new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("q"),<a name="line.214"></a>
-<span class="sourceLineNo">215</span>          new byte[MemStoreLABImpl.MAX_ALLOC_DEFAULT - 32]);<a name="line.215"></a>
-<span class="sourceLineNo">216</span>      for (int i = 0; i &lt; 10; i++) {<a name="line.216"></a>
-<span class="sourceLineNo">217</span>        threads.add(getChunkQueueTestThread(mslab, "testLABChunkQueue-" + i, kv));<a name="line.217"></a>
-<span class="sourceLineNo">218</span>      }<a name="line.218"></a>
-<span class="sourceLineNo">219</span>      for (Thread thread : threads) {<a name="line.219"></a>
-<span class="sourceLineNo">220</span>        thread.start();<a name="line.220"></a>
-<span class="sourceLineNo">221</span>      }<a name="line.221"></a>
-<span class="sourceLineNo">222</span>      // let it run for some time<a name="line.222"></a>
-<span class="sourceLineNo">223</span>      Thread.sleep(1000);<a name="line.223"></a>
-<span class="sourceLineNo">224</span>      for (Thread thread : threads) {<a name="line.224"></a>
-<span class="sourceLineNo">225</span>        thread.interrupt();<a name="line.225"></a>
+<span class="sourceLineNo">112</span>  @Test<a name="line.112"></a>
+<span class="sourceLineNo">113</span>  public void testLABLargeAllocation() {<a name="line.113"></a>
+<span class="sourceLineNo">114</span>    MemStoreLAB mslab = new MemStoreLABImpl();<a name="line.114"></a>
+<span class="sourceLineNo">115</span>    KeyValue kv = new KeyValue(rk, cf, q, new byte[2 * 1024 * 1024]);<a name="line.115"></a>
+<span class="sourceLineNo">116</span>    Cell newCell = mslab.copyCellInto(kv);<a name="line.116"></a>
+<span class="sourceLineNo">117</span>    assertNull("2MB allocation shouldn't be satisfied by LAB.", newCell);<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>  /**<a name="line.120"></a>
+<span class="sourceLineNo">121</span>   * Test allocation from lots of threads, making sure the results don't<a name="line.121"></a>
+<span class="sourceLineNo">122</span>   * overlap in any way<a name="line.122"></a>
+<span class="sourceLineNo">123</span>   */<a name="line.123"></a>
+<span class="sourceLineNo">124</span>  @Test<a name="line.124"></a>
+<span class="sourceLineNo">125</span>  public void testLABThreading() throws Exception {<a name="line.125"></a>
+<span class="sourceLineNo">126</span>    Configuration conf = new Configuration();<a name="line.126"></a>
+<span class="sourceLineNo">127</span>    MultithreadedTestUtil.TestContext ctx =<a name="line.127"></a>
+<span class="sourceLineNo">128</span>      new MultithreadedTestUtil.TestContext(conf);<a name="line.128"></a>
+<span class="sourceLineNo">129</span>    <a name="line.129"></a>
+<span class="sourceLineNo">130</span>    final AtomicInteger totalAllocated = new AtomicInteger();<a name="line.130"></a>
+<span class="sourceLineNo">131</span>    <a name="line.131"></a>
+<span class="sourceLineNo">132</span>    final MemStoreLAB mslab = new MemStoreLABImpl();<a name="line.132"></a>
+<span class="sourceLineNo">133</span>    List&lt;List&lt;AllocRecord&gt;&gt; allocations = Lists.newArrayList();<a name="line.133"></a>
+<span class="sourceLineNo">134</span>    <a name="line.134"></a>
+<span class="sourceLineNo">135</span>    for (int i = 0; i &lt; 10; i++) {<a name="line.135"></a>
+<span class="sourceLineNo">136</span>      final List&lt;AllocRecord&gt; allocsByThisThread = Lists.newLinkedList();<a name="line.136"></a>
+<span class="sourceLineNo">137</span>      allocations.add(allocsByThisThread);<a name="line.137"></a>
+<span class="sourceLineNo">138</span>      <a name="line.138"></a>
+<span class="sourceLineNo">139</span>      TestThread t = new MultithreadedTestUtil.RepeatingTestThread(ctx) {<a name="line.139"></a>
+<span class="sourceLineNo">140</span>        private Random r = new Random();<a name="line.140"></a>
+<span class="sourceLineNo">141</span>        @Override<a name="line.141"></a>
+<span class="sourceLineNo">142</span>        public void doAnAction() throws Exception {<a name="line.142"></a>
+<span class="sourceLineNo">143</span>          int valSize = r.nextInt(3);<a name="line.143"></a>
+<span class="sourceLineNo">144</span>          KeyValue kv = new KeyValue(rk, cf, q, new byte[valSize]);<a name="line.144"></a>
+<span class="sourceLineNo">145</span>          int size = KeyValueUtil.length(kv);<a name="line.145"></a>
+<span class="sourceLineNo">146</span>          ByteBufferKeyValue newCell = (ByteBufferKeyValue) mslab.copyCellInto(kv);<a name="line.146"></a>
+<span class="sourceLineNo">147</span>          totalAllocated.addAndGet(size);<a name="line.147"></a>
+<span class="sourceLineNo">148</span>          allocsByThisThread.add(new AllocRecord(newCell.getBuffer(), newCell.getOffset(), size));<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>      ctx.addThread(t);<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>    ctx.startThreads();<a name="line.154"></a>
+<span class="sourceLineNo">155</span>    while (totalAllocated.get() &lt; 50*1024*1000 &amp;&amp; ctx.shouldRun()) {<a name="line.155"></a>
+<span class="sourceLineNo">156</span>      Thread.sleep(10);<a name="line.156"></a>
+<span class="sourceLineNo">157</span>    }<a name="line.157"></a>
+<span class="sourceLineNo">158</span>    ctx.stop();<a name="line.158"></a>
+<span class="sourceLineNo">159</span>    // Partition the allocations by the actual byte[] they point into,<a name="line.159"></a>
+<span class="sourceLineNo">160</span>    // make sure offsets are unique for each chunk<a name="line.160"></a>
+<span class="sourceLineNo">161</span>    Map&lt;ByteBuffer, Map&lt;Integer, AllocRecord&gt;&gt; mapsByChunk =<a name="line.161"></a>
+<span class="sourceLineNo">162</span>      Maps.newHashMap();<a name="line.162"></a>
+<span class="sourceLineNo">163</span><a name="line.163"></a>
+<span class="sourceLineNo">164</span>    int sizeCounted = 0;<a name="line.164"></a>
+<span class="sourceLineNo">165</span>    for (AllocRecord rec : Iterables.concat(allocations)) {<a name="line.165"></a>
+<span class="sourceLineNo">166</span>      sizeCounted += rec.size;<a name="line.166"></a>
+<span class="sourceLineNo">167</span>      if (rec.size == 0) continue;<a name="line.167"></a>
+<span class="sourceLineNo">168</span>      Map&lt;Integer, AllocRecord&gt; mapForThisByteArray =<a name="line.168"></a>
+<span class="sourceLineNo">169</span>        mapsByChunk.get(rec.alloc);<a name="line.169"></a>
+<span class="sourceLineNo">170</span>      if (mapForThisByteArray == null) {<a name="line.170"></a>
+<span class="sourceLineNo">171</span>        mapForThisByteArray = Maps.newTreeMap();<a name="line.171"></a>
+<span class="sourceLineNo">172</span>        mapsByChunk.put(rec.alloc, mapForThisByteArray);<a name="line.172"></a>
+<span class="sourceLineNo">173</span>      }<a name="line.173"></a>
+<span class="sourceLineNo">174</span>      AllocRecord oldVal = mapForThisByteArray.put(rec.offset, rec);<a name="line.174"></a>
+<span class="sourceLineNo">175</span>      assertNull("Already had an entry " + oldVal + " for allocation " + rec,<a name="line.175"></a>
+<span class="sourceLineNo">176</span>          oldVal);<a name="line.176"></a>
+<span class="sourceLineNo">177</span>    }<a name="line.177"></a>
+<span class="sourceLineNo">178</span>    assertEquals("Sanity check test", sizeCounted, totalAllocated.get());<a name="line.178"></a>
+<span class="sourceLineNo">179</span>    <a name="line.179"></a>
+<span class="sourceLineNo">180</span>    // Now check each byte array to make sure allocations don't overlap<a name="line.180"></a>
+<span class="sourceLineNo">181</span>    for (Map&lt;Integer, AllocRecord&gt; allocsInChunk : mapsByChunk.values()) {<a name="line.181"></a>
+<span class="sourceLineNo">182</span>      // since we add the chunkID at the 0th offset of the chunk and the<a name="line.182"></a>
+<span class="sourceLineNo">183</span>      // chunkid is an int we need to account for those 4 bytes<a name="line.183"></a>
+<span class="sourceLineNo">184</span>      int expectedOff = Bytes.SIZEOF_INT;<a name="line.184"></a>
+<span class="sourceLineNo">185</span>      for (AllocRecord alloc : allocsInChunk.values()) {<a name="line.185"></a>
+<span class="sourceLineNo">186</span>        assertEquals(expectedOff, alloc.offset);<a name="line.186"></a>
+<span class="sourceLineNo">187</span>        assertTrue("Allocation overruns buffer",<a name="line.187"></a>
+<span class="sourceLineNo">188</span>            alloc.offset + alloc.size &lt;= alloc.alloc.capacity());<a name="line.188"></a>
+<span class="sourceLineNo">189</span>        expectedOff += alloc.size;<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><a name="line.193"></a>
+<span class="sourceLineNo">194</span>  /**<a name="line.194"></a>
+<span class="sourceLineNo">195</span>   * Test frequent chunk retirement with chunk pool triggered by lots of threads, making sure<a name="line.195"></a>
+<span class="sourceLineNo">196</span>   * there's no memory leak (HBASE-16195)<a name="line.196"></a>
+<span class="sourceLineNo">197</span>   * @throws Exception if any error occurred<a name="line.197"></a>
+<span class="sourceLineNo">198</span>   */<a name="line.198"></a>
+<span class="sourceLineNo">199</span>  @Test<a name="line.199"></a>
+<span class="sourceLineNo">200</span>  public void testLABChunkQueue() throws Exception {<a name="line.200"></a>
+<span class="sourceLineNo">201</span>    ChunkCreator oldInstance = null;<a name="line.201"></a>
+<span class="sourceLineNo">202</span>    try {<a name="line.202"></a>
+<span class="sourceLineNo">203</span>      MemStoreLABImpl mslab = new MemStoreLABImpl();<a name="line.203"></a>
+<span class="sourceLineNo">204</span>      // by default setting, there should be no chunks initialized in the pool<a name="line.204"></a>
+<span class="sourceLineNo">205</span>      assertTrue(mslab.getPooledChunks().isEmpty());<a name="line.205"></a>
+<span class="sourceLineNo">206</span>      oldInstance = ChunkCreator.INSTANCE;<a name="line.206"></a>
+<span class="sourceLineNo">207</span>      ChunkCreator.INSTANCE = null;<a name="line.207"></a>
+<span class="sourceLineNo">208</span>      // reset mslab with chunk pool<a name="line.208"></a>
+<span class="sourceLineNo">209</span>      Configuration conf = HBaseConfiguration.create();<a name="line.209"></a>
+<span class="sourceLineNo">210</span>      conf.setDouble(MemStoreLAB.CHUNK_POOL_MAXSIZE_KEY, 0.1);<a name="line.210"></a>
+<span class="sourceLineNo">211</span>      // set chunk size to default max alloc size, so we could easily trigger chunk retirement<a name="line.211"></a>
+<span class="sourceLineNo">212</span>      conf.setLong(MemStoreLABImpl.CHUNK_SIZE_KEY, MemStoreLABImpl.MAX_ALLOC_DEFAULT);<a name="line.212"></a>
+<span class="sourceLineNo">213</span>      // reconstruct mslab<a name="line.213"></a>
+<span class="sourceLineNo">214</span>      long globalMemStoreLimit = (long) (ManagementFactory.getMemoryMXBean().getHeapMemoryUsage()<a name="line.214"></a>
+<span class="sourceLineNo">215</span>          .getMax() * MemorySizeUtil.getGlobalMemStoreHeapPercent(conf, false));<a name="line.215"></a>
+<span class="sourceLineNo">216</span>      ChunkCreator.initialize(MemStoreLABImpl.MAX_ALLOC_DEFAULT, false,<a name="line.216"></a>
+<span class="sourceLineNo">217</span>        globalMemStoreLimit, 0.1f, MemStoreLAB.POOL_INITIAL_SIZE_DEFAULT, null);<a name="line.217"></a>
+<span class="sourceLineNo">218</span>      ChunkCreator.clearDisableFlag();<a name="line.218"></a>
+<span class="sourceLineNo">219</span>      mslab = new MemStoreLABImpl(conf);<a name="line.219"></a>
+<span class="sourceLineNo">220</span>      // launch multiple threads to trigger frequent chunk retirement<a name="line.220"></a>
+<span class="sourceLineNo">221</span>      List&lt;Thread&gt; threads = new ArrayList&lt;&gt;();<a name="line.221"></a>
+<span class="sourceLineNo">222</span>      final KeyValue kv = new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("q"),<a name="line.222"></a>
+<span class="sourceLineNo">223</span>          new byte[MemStoreLABImpl.MAX_ALLOC_DEFAULT - 32]);<a name="line.223"></a>
+<span class="sourceLineNo">224</span>      for (int i = 0; i &lt; 10; i++) {<a name="line.224"></a>
+<span class="sourceLineNo">225</span>        threads.add(getChunkQueueTestThread(mslab, "testLABChunkQueue-" + i, kv));<a name="line.225"></a>
 <span class="sourceLineNo">226</span>      }<a name="line.226"></a>
-<span class="sourceLineNo">227</span>      boolean threadsRunning = true;<a name="line.227"></a>
-<span class="sourceLineNo">228</span>      boolean alive = false;<a name="line.228"></a>
-<span class="sourceLineNo">229</span>      while (threadsRunning) {<a name="line.229"></a>
-<span class="sourceLineNo">230</span>        alive = false;<a name="line.230"></a>
-<span class="sourceLineNo">231</span>        for (Thread thread : threads) {<a name="line.231"></a>
-<span class="sourceLineNo">232</span>          if (thread.isAlive()) {<a name="line.232"></a>
-<span class="sourceLineNo">233</span>            alive = true;<a name="line.233"></a>
-<span class="sourceLineNo">234</span>            break;<a name="line.234"></a>
-<span class="sourceLineNo">235</span>          }<a name="line.235"></a>
-<span class="sourceLineNo">236</span>        }<a name="line.236"></a>
-<span class="sourceLineNo">237</span>        if (!alive) {<a name="line.237"></a>
-<span class="sourceLineNo">238</span>          threadsRunning = false;<a name="line.238"></a>
-<span class="sourceLineNo">239</span>        }<a name="line.239"></a>
-<span class="sourceLineNo">240</span>      }<a name="line.240"></a>
-<span class="sourceLineNo">241</span>      // none of the chunkIds would have been returned back<a name="line.241"></a>
-<span class="sourceLineNo">242</span>      assertTrue("All the chunks must have been cleared", ChunkCreator.INSTANCE.size() != 0);<a name="line.242"></a>
-<span class="sourceLineNo">243</span>      // close the mslab<a name="line.243"></a>
-<span class="sourceLineNo">244</span>      mslab.close();<a name="line.244"></a>
-<span class="sourceLineNo">245</span>      // make sure all chunks reclaimed or removed from chunk queue<a name="line.245"></a>
-<span class="sourceLineNo">246</span>      int queueLength = mslab.getPooledChunks().size();<a name="line.246"></a>
-<span class="sourceLineNo">247</span>      assertTrue("All chunks in chunk queue should be reclaimed or removed"<a name="line.247"></a>
-<span class="sourceLineNo">248</span>          + " after mslab closed but actually: " + queueLength,<a name="line.248"></a>
-<span class="sourceLineNo">249</span>        queueLength == 0);<a name="line.249"></a>
-<span class="sourceLineNo">250</span>    } finally {<a name="line.250"></a>
-<span class="sourceLineNo">251</span>      ChunkCreator.INSTANCE = oldInstance;<a name="line.251"></a>
-<span class="sourceLineNo">252</span>    }<a name="line.252"></a>
-<span class="sourceLineNo">253</span>  }<a name="line.253"></a>
-<span class="sourceLineNo">254</span><a name="line.254"></a>
-<span class="sourceLineNo">255</span>  private Thread getChunkQueueTestThread(final MemStoreLABImpl mslab, String threadName,<a name="line.255"></a>
-<span class="sourceLineNo">256</span>      Cell cellToCopyInto) {<a name="line.256"></a>
-<span class="sourceLineNo">257</span>    Thread thread = new Thread() {<a name="line.257"></a>
-<span class="sourceLineNo">258</span>      volatile boolean stopped = false;<a name="line.258"></a>
-<span class="sourceLineNo">259</span><a name="line.259"></a>
-<span class="sourceLineNo">260</span>      @Override<a name="line.260"></a>
-<span class="sourceLineNo">261</span>      public void run() {<a name="line.261"></a>
-<span class="sourceLineNo">262</span>        while (!stopped) {<a name="line.262"></a>
-<span class="sourceLineNo">263</span>          // keep triggering chunk retirement<a name="line.263"></a>
-<span class="sourceLineNo">264</span>          mslab.copyCellInto(cellToCopyInto);<a name="line.264"></a>
-<span class="sourceLineNo">265</span>        }<a name="line.265"></a>
-<span class="sourceLineNo">266</span>      }<a name="line.266"></a>
+<span class="sourceLineNo">227</span>      for (Thread thread : threads) {<a name="line.227"></a>
+<span class="sourceLineNo">228</span>        thread.start();<a name="line.228"></a>
+<span class="sourceLineNo">229</span>      }<a name="line.229"></a>
+<span class="sourceLineNo">230</span>      // let it run for some time<a name="line.230"></a>
+<span class="sourceLineNo">231</span>      Thread.sleep(1000);<a name="line.231"></a>
+<span class="sourceLineNo">232</span>      for (Thread thread : threads) {<a name="line.232"></a>
+<span class="sourceLineNo">233</span>        thread.interrupt();<a name="line.233"></a>
+<span class="sourceLineNo">234</span>      }<a name="line.234"></a>
+<span class="sourceLineNo">235</span>      boolean threadsRunning = true;<a name="line.235"></a>
+<span class="sourceLineNo">236</span>      boolean alive = false;<a name="line.236"></a>
+<span class="sourceLineNo">237</span>      while (threadsRunning) {<a name="line.237"></a>
+<span class="sourceLineNo">238</span>        alive = false;<a name="line.238"></a>
+<span class="sourceLineNo">239</span>        for (Thread thread : threads) {<a name="line.239"></a>
+<span class="sourceLineNo">240</span>          if (thread.isAlive()) {<a name="line.240"></a>
+<span class="sourceLineNo">241</span>            alive = true;<a name="line.241"></a>
+<span class="sourceLineNo">242</span>            break;<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>        if (!alive) {<a name="line.245"></a>
+<span class="sourceLineNo">246</span>          threadsRunning = false;<a name="line.246"></a>
+<span class="sourceLineNo">247</span>        }<a name="line.247"></a>
+<span class="sourceLineNo">248</span>      }<a name="line.248"></a>
+<span class="sourceLineNo">249</span>      // none of the chunkIds would have been returned back<a name="line.249"></a>
+<span class="sourceLineNo">250</span>      assertTrue("All the chunks must have been cleared", ChunkCreator.INSTANCE.size() != 0);<a name="line.250"></a>
+<span class="sourceLineNo">251</span>      // close the mslab<a name="line.251"></a>
+<span class="sourceLineNo">252</span>      mslab.close();<a name="line.252"></a>
+<span class="sourceLineNo">253</span>      // make sure all chunks reclaimed or removed from chunk queue<a name="line.253"></a>
+<span class="sourceLineNo">254</span>      int queueLength = mslab.getPooledChunks().size();<a name="line.254"></a>
+<span class="sourceLineNo">255</span>      assertTrue("All chunks in chunk queue should be reclaimed or removed"<a name="line.255"></a>
+<span class="sourceLineNo">256</span>          + " after mslab closed but actually: " + queueLength,<a name="line.256"></a>
+<span class="sourceLineNo">257</span>        queueLength == 0);<a name="line.257"></a>
+<span class="sourceLineNo">258</span>    } finally {<a name="line.258"></a>
+<span class="sourceLineNo">259</span>      ChunkCreator.INSTANCE = oldInstance;<a name="line.259"></a>
+<span class="sourceLineNo">260</span>    }<a name="line.260"></a>
+<span class="sourceLineNo">261</span>  }<a name="line.261"></a>
+<span class="sourceLineNo">262</span><a name="line.262"></a>
+<span class="sourceLineNo">263</span>  private Thread getChunkQueueTestThread(final MemStoreLABImpl mslab, String threadName,<a name="line.263"></a>
+<span class="sourceLineNo">264</span>      Cell cellToCopyInto) {<a name="line.264"></a>
+<span class="sourceLineNo">265</span>    Thread thread = new Thread() {<a name="line.265"></a>
+<span class="sourceLineNo">266</span>      volatile boolean stopped = false;<a name="line.266"></a>
 <span class="sourceLineNo">267</span><a name="line.267"></a>
 <span class="sourceLineNo">268</span>      @Override<a name="line.268"></a>
-<span class="sourceLineNo">269</span>      public void interrupt() {<a name="line.269"></a>
-<span class="sourceLineNo">270</span>        this.stopped = true;<a name="line.270"></a>
-<span class="sourceLineNo">271</span>      }<a name="line.271"></a>
-<span class="sourceLineNo">272</span>    };<a name="line.272"></a>
-<span class="sourceLineNo">273</span>    thread.setName(threadName);<a name="line.273"></a>
-<span class="sourceLineNo">274</span>    thread.setDaemon(true);<a name="line.274"></a>
-<span class="sourceLineNo">275</span>    return thread;<a name="line.275"></a>
-<span class="sourceLineNo">276</span>  }<a name="line.276"></a>
-<span class="sourceLineNo">277</span><a name="line.277"></a>
-<span class="sourceLineNo">278</span>  private static class AllocRecord implements Comparable&lt;AllocRecord&gt;{<a name="line.278"></a>
-<span class="sourceLineNo">279</span>    private final ByteBuffer alloc;<a name="line.279"></a>
-<span class="sourceLineNo">280</span>    private final int offset;<a name="line.280"></a>
-<span class="sourceLineNo">281</span>    private final int size;<a name="line.281"></a>
-<span class="sourceLineNo">282</span><a name="line.282"></a>
-<span class="sourceLineNo">283</span>    public AllocRecord(ByteBuffer alloc, int offset, int size) {<a name="line.283"></a>
-<span class="sourceLineNo">284</span>      super();<a name="line.284"></a>
-<span class="sourceLineNo">285</span>      this.alloc = alloc;<a name="line.285"></a>
-<span class="sourceLineNo">286</span>      this.offset = offset;<a name="line.286"></a>
-<span class="sourceLineNo">287</span>      this.size = size;<a name="line.287"></a>
-<span class="sourceLineNo">288</span>    }<a name="line.288"></a>
-<span class="sourceLineNo">289</span><a name="line.289"></a>
-<span class="sourceLineNo">290</span>    @Override<a name="line.290"></a>
-<span class="sourceLineNo">291</span>    public int compareTo(AllocRecord e) {<a name="line.291"></a>
-<span class="sourceLineNo">292</span>      if (alloc != e.alloc) {<a name="line.292"></a>
-<span class="sourceLineNo">293</span>        throw new RuntimeException("Can only compare within a particular array");<a name="line.293"></a>
-<span class="sourceLineNo">294</span>      }<a name="line.294"></a>
-<span class="sourceLineNo">295</span>      return Ints.compare(this.offset, e.offset);<a name="line.295"></a>
+<span class="sourceLineNo">269</span>      public void run() {<a name="line.269"></a>
+<span class="sourceLineNo">270</span>        while (!stopped) {<a name="line.270"></a>
+<span class="sourceLineNo">271</span>          // keep triggering chunk retirement<a name="line.271"></a>
+<span class="sourceLineNo">272</span>          mslab.copyCellInto(cellToCopyInto);<a name="line.272"></a>
+<span class="sourceLineNo">273</span>        }<a name="line.273"></a>
+<span class="sourceLineNo">274</span>      }<a name="line.274"></a>
+<span class="sourceLineNo">275</span><a name="line.275"></a>
+<span class="sourceLineNo">276</span>      @Override<a name="line.276"></a>
+<span class="sourceLineNo">277</span>      public void interrupt() {<a name="line.277"></a>
+<span class="sourceLineNo">278</span>        this.stopped = true;<a name="line.278"></a>
+<span class="sourceLineNo">279</span>      }<a name="line.279"></a>
+<span class="sourceLineNo">280</span>    };<a name="line.280"></a>
+<span class="sourceLineNo">281</span>    thread.setName(threadName);<a name="line.281"></a>
+<span class="sourceLineNo">282</span>    thread.setDaemon(true);<a name="line.282"></a>
+<span class="sourceLineNo">283</span>    return thread;<a name="line.283"></a>
+<span class="sourceLineNo">284</span>  }<a name="line.284"></a>
+<span class="sourceLineNo">285</span><a name="line.285"></a>
+<span class="sourceLineNo">286</span>  private static class AllocRecord implements Comparable&lt;AllocRecord&gt;{<a name="line.286"></a>
+<span class="sourceLineNo">287</span>    private final ByteBuffer alloc;<a name="line.287"></a>
+<span class="sourceLineNo">288</span>    private final int offset;<a name="line.288"></a>
+<span class="sourceLineNo">289</span>    private final int size;<a name="line.289"></a>
+<span class="sourceLineNo">290</span><a name="line.290"></a>
+<span class="sourceLineNo">291</span>    public AllocRecord(ByteBuffer alloc, int offset, int size) {<a name="line.291"></a>
+<span class="sourceLineNo">292</span>      super();<a name="line.292"></a>
+<span class="sourceLineNo">293</span>      this.alloc = alloc;<a name="line.293"></a>
+<span class="sourceLineNo">294</span>      this.offset = offset;<a name="line.294"></a>
+<span class="sourceLineNo">295</span>      this.size = size;<a name="line.295"></a>
 <span class="sourceLineNo">296</span>    }<a name="line.296"></a>
-<span class="sourceLineNo">297</span>    <a name="line.297"></a>
+<span class="sourceLineNo">297</span><a name="line.297"></a>
 <span class="sourceLineNo">298</span>    @Override<a name="line.298"></a>
-<span class="sourceLineNo">299</span>    public String toString() {<a name="line.299"></a>
-<span class="sourceLineNo">300</span>      return "AllocRecord(offset=" + this.offset + ", size=" + size + ")";<a name="line.300"></a>
-<span class="sourceLineNo">301</span>    }<a name="line.301"></a>
-<span class="sourceLineNo">302</span>  }<a name="line.302"></a>
-<span class="sourceLineNo">303</span>}<a name="line.303"></a>
-<span class="sourceLineNo">304</span><a name="line.304"></a>
+<span class="sourceLineNo">299</span>    public int compareTo(AllocRecord e) {<a name="line.299"></a>
+<span class="sourceLineNo">300</span>      if (alloc != e.alloc) {<a name="line.300"></a>
+<span class="sourceLineNo">301</span>        throw new RuntimeException("Can only compare within a particular array");<a name="line.301"></a>
+<span class="sourceLineNo">302</span>      }<a name="line.302"></a>
+<span class="sourceLineNo">303</span>      return Ints.compare(this.offset, e.offset);<a name="line.303"></a>
+<span class="sourceLineNo">304</span>    }<a name="line.304"></a>
+<span class="sourceLineNo">305</span>    <a name="line.305"></a>
+<span class="sourceLineNo">306</span>    @Override<a name="line.306"></a>
+<span class="sourceLineNo">307</span>    public String toString() {<a name="line.307"></a>
+<span class="sourceLineNo">308</span>      return "AllocRecord(offset=" + this.offset + ", size=" + size + ")";<a name="line.308"></a>
+<span class="sourceLineNo">309</span>    }<a name="line.309"></a>
+<span class="sourceLineNo">310</span>  }<a name="line.310"></a>
+<span class="sourceLineNo">311</span>}<a name="line.311"></a>
+<span class="sourceLineNo">312</span><a name="line.312"></a>
 
 
 


Mime
View raw message