| <!DOCTYPE HTML> |
| <html lang="en"> |
| <head> |
| <!-- Generated by javadoc (17) --> |
| <title>Source code</title> |
| <meta name="viewport" content="width=device-width, initial-scale=1"> |
| <meta name="description" content="source: package: org.apache.hadoop.hbase.client, class: TestBlockEvictionFromClient, class: ScanThread"> |
| <meta name="generator" content="javadoc/SourceToHTMLConverter"> |
| <link rel="stylesheet" type="text/css" href="../../../../../../stylesheet.css" title="Style"> |
| </head> |
| <body class="source-page"> |
| <main role="main"> |
| <div class="source-container"> |
| <pre><span class="source-line-no">001</span><span id="line-1">/*</span> |
| <span class="source-line-no">002</span><span id="line-2"> * Licensed to the Apache Software Foundation (ASF) under one</span> |
| <span class="source-line-no">003</span><span id="line-3"> * or more contributor license agreements. See the NOTICE file</span> |
| <span class="source-line-no">004</span><span id="line-4"> * distributed with this work for additional information</span> |
| <span class="source-line-no">005</span><span id="line-5"> * regarding copyright ownership. The ASF licenses this file</span> |
| <span class="source-line-no">006</span><span id="line-6"> * to you under the Apache License, Version 2.0 (the</span> |
| <span class="source-line-no">007</span><span id="line-7"> * "License"); you may not use this file except in compliance</span> |
| <span class="source-line-no">008</span><span id="line-8"> * with the License. You may obtain a copy of the License at</span> |
| <span class="source-line-no">009</span><span id="line-9"> *</span> |
| <span class="source-line-no">010</span><span id="line-10"> * http://www.apache.org/licenses/LICENSE-2.0</span> |
| <span class="source-line-no">011</span><span id="line-11"> *</span> |
| <span class="source-line-no">012</span><span id="line-12"> * Unless required by applicable law or agreed to in writing, software</span> |
| <span class="source-line-no">013</span><span id="line-13"> * distributed under the License is distributed on an "AS IS" BASIS,</span> |
| <span class="source-line-no">014</span><span id="line-14"> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span> |
| <span class="source-line-no">015</span><span id="line-15"> * See the License for the specific language governing permissions and</span> |
| <span class="source-line-no">016</span><span id="line-16"> * limitations under the License.</span> |
| <span class="source-line-no">017</span><span id="line-17"> */</span> |
| <span class="source-line-no">018</span><span id="line-18">package org.apache.hadoop.hbase.client;</span> |
| <span class="source-line-no">019</span><span id="line-19"></span> |
| <span class="source-line-no">020</span><span id="line-20">import static org.junit.Assert.assertEquals;</span> |
| <span class="source-line-no">021</span><span id="line-21">import static org.junit.Assert.assertFalse;</span> |
| <span class="source-line-no">022</span><span id="line-22">import static org.junit.Assert.assertTrue;</span> |
| <span class="source-line-no">023</span><span id="line-23"></span> |
| <span class="source-line-no">024</span><span id="line-24">import java.io.IOException;</span> |
| <span class="source-line-no">025</span><span id="line-25">import java.util.ArrayList;</span> |
| <span class="source-line-no">026</span><span id="line-26">import java.util.Iterator;</span> |
| <span class="source-line-no">027</span><span id="line-27">import java.util.List;</span> |
| <span class="source-line-no">028</span><span id="line-28">import java.util.Optional;</span> |
| <span class="source-line-no">029</span><span id="line-29">import java.util.concurrent.CountDownLatch;</span> |
| <span class="source-line-no">030</span><span id="line-30">import java.util.concurrent.TimeUnit;</span> |
| <span class="source-line-no">031</span><span id="line-31">import java.util.concurrent.atomic.AtomicBoolean;</span> |
| <span class="source-line-no">032</span><span id="line-32">import java.util.concurrent.atomic.AtomicInteger;</span> |
| <span class="source-line-no">033</span><span id="line-33">import java.util.concurrent.atomic.AtomicReference;</span> |
| <span class="source-line-no">034</span><span id="line-34">import org.apache.hadoop.conf.Configuration;</span> |
| <span class="source-line-no">035</span><span id="line-35">import org.apache.hadoop.hbase.Cell;</span> |
| <span class="source-line-no">036</span><span id="line-36">import org.apache.hadoop.hbase.HBaseClassTestRule;</span> |
| <span class="source-line-no">037</span><span id="line-37">import org.apache.hadoop.hbase.HBaseTestingUtil;</span> |
| <span class="source-line-no">038</span><span id="line-38">import org.apache.hadoop.hbase.HConstants;</span> |
| <span class="source-line-no">039</span><span id="line-39">import org.apache.hadoop.hbase.ServerName;</span> |
| <span class="source-line-no">040</span><span id="line-40">import org.apache.hadoop.hbase.TableName;</span> |
| <span class="source-line-no">041</span><span id="line-41">import org.apache.hadoop.hbase.coprocessor.CoprocessorHost;</span> |
| <span class="source-line-no">042</span><span id="line-42">import org.apache.hadoop.hbase.coprocessor.MultiRowMutationEndpoint;</span> |
| <span class="source-line-no">043</span><span id="line-43">import org.apache.hadoop.hbase.coprocessor.ObserverContext;</span> |
| <span class="source-line-no">044</span><span id="line-44">import org.apache.hadoop.hbase.coprocessor.RegionCoprocessor;</span> |
| <span class="source-line-no">045</span><span id="line-45">import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;</span> |
| <span class="source-line-no">046</span><span id="line-46">import org.apache.hadoop.hbase.coprocessor.RegionObserver;</span> |
| <span class="source-line-no">047</span><span id="line-47">import org.apache.hadoop.hbase.io.hfile.BlockCache;</span> |
| <span class="source-line-no">048</span><span id="line-48">import org.apache.hadoop.hbase.io.hfile.BlockCacheKey;</span> |
| <span class="source-line-no">049</span><span id="line-49">import org.apache.hadoop.hbase.io.hfile.CacheConfig;</span> |
| <span class="source-line-no">050</span><span id="line-50">import org.apache.hadoop.hbase.io.hfile.CachedBlock;</span> |
| <span class="source-line-no">051</span><span id="line-51">import org.apache.hadoop.hbase.io.hfile.CombinedBlockCache;</span> |
| <span class="source-line-no">052</span><span id="line-52">import org.apache.hadoop.hbase.io.hfile.bucket.BucketCache;</span> |
| <span class="source-line-no">053</span><span id="line-53">import org.apache.hadoop.hbase.regionserver.BloomType;</span> |
| <span class="source-line-no">054</span><span id="line-54">import org.apache.hadoop.hbase.regionserver.HRegion;</span> |
| <span class="source-line-no">055</span><span id="line-55">import org.apache.hadoop.hbase.regionserver.HStore;</span> |
| <span class="source-line-no">056</span><span id="line-56">import org.apache.hadoop.hbase.regionserver.InternalScanner;</span> |
| <span class="source-line-no">057</span><span id="line-57">import org.apache.hadoop.hbase.regionserver.RegionScanner;</span> |
| <span class="source-line-no">058</span><span id="line-58">import org.apache.hadoop.hbase.regionserver.ScannerContext;</span> |
| <span class="source-line-no">059</span><span id="line-59">import org.apache.hadoop.hbase.testclassification.ClientTests;</span> |
| <span class="source-line-no">060</span><span id="line-60">import org.apache.hadoop.hbase.testclassification.LargeTests;</span> |
| <span class="source-line-no">061</span><span id="line-61">import org.apache.hadoop.hbase.util.Bytes;</span> |
| <span class="source-line-no">062</span><span id="line-62">import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;</span> |
| <span class="source-line-no">063</span><span id="line-63">import org.junit.After;</span> |
| <span class="source-line-no">064</span><span id="line-64">import org.junit.AfterClass;</span> |
| <span class="source-line-no">065</span><span id="line-65">import org.junit.Before;</span> |
| <span class="source-line-no">066</span><span id="line-66">import org.junit.BeforeClass;</span> |
| <span class="source-line-no">067</span><span id="line-67">import org.junit.ClassRule;</span> |
| <span class="source-line-no">068</span><span id="line-68">import org.junit.Rule;</span> |
| <span class="source-line-no">069</span><span id="line-69">import org.junit.Test;</span> |
| <span class="source-line-no">070</span><span id="line-70">import org.junit.experimental.categories.Category;</span> |
| <span class="source-line-no">071</span><span id="line-71">import org.junit.rules.TestName;</span> |
| <span class="source-line-no">072</span><span id="line-72">import org.slf4j.Logger;</span> |
| <span class="source-line-no">073</span><span id="line-73">import org.slf4j.LoggerFactory;</span> |
| <span class="source-line-no">074</span><span id="line-74"></span> |
| <span class="source-line-no">075</span><span id="line-75">import org.apache.hbase.thirdparty.com.google.common.collect.Iterables;</span> |
| <span class="source-line-no">076</span><span id="line-76"></span> |
| <span class="source-line-no">077</span><span id="line-77">@Category({ LargeTests.class, ClientTests.class })</span> |
| <span class="source-line-no">078</span><span id="line-78">@SuppressWarnings("deprecation")</span> |
| <span class="source-line-no">079</span><span id="line-79">public class TestBlockEvictionFromClient {</span> |
| <span class="source-line-no">080</span><span id="line-80"></span> |
| <span class="source-line-no">081</span><span id="line-81"> @ClassRule</span> |
| <span class="source-line-no">082</span><span id="line-82"> public static final HBaseClassTestRule CLASS_RULE =</span> |
| <span class="source-line-no">083</span><span id="line-83"> HBaseClassTestRule.forClass(TestBlockEvictionFromClient.class);</span> |
| <span class="source-line-no">084</span><span id="line-84"></span> |
| <span class="source-line-no">085</span><span id="line-85"> private static final Logger LOG = LoggerFactory.getLogger(TestBlockEvictionFromClient.class);</span> |
| <span class="source-line-no">086</span><span id="line-86"> protected final static HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();</span> |
| <span class="source-line-no">087</span><span id="line-87"> static byte[][] ROWS = new byte[2][];</span> |
| <span class="source-line-no">088</span><span id="line-88"> private static int NO_OF_THREADS = 3;</span> |
| <span class="source-line-no">089</span><span id="line-89"> private static byte[] ROW = Bytes.toBytes("testRow");</span> |
| <span class="source-line-no">090</span><span id="line-90"> private static byte[] ROW1 = Bytes.toBytes("testRow1");</span> |
| <span class="source-line-no">091</span><span id="line-91"> private static byte[] ROW2 = Bytes.toBytes("testRow2");</span> |
| <span class="source-line-no">092</span><span id="line-92"> private static byte[] ROW3 = Bytes.toBytes("testRow3");</span> |
| <span class="source-line-no">093</span><span id="line-93"> private static byte[] FAMILY = Bytes.toBytes("testFamily");</span> |
| <span class="source-line-no">094</span><span id="line-94"> private static byte[][] FAMILIES_1 = new byte[1][0];</span> |
| <span class="source-line-no">095</span><span id="line-95"> private static byte[] QUALIFIER = Bytes.toBytes("testQualifier");</span> |
| <span class="source-line-no">096</span><span id="line-96"> private static byte[] QUALIFIER2 = Bytes.add(QUALIFIER, QUALIFIER);</span> |
| <span class="source-line-no">097</span><span id="line-97"> private static byte[] data = new byte[1000];</span> |
| <span class="source-line-no">098</span><span id="line-98"> private static byte[] data2 = Bytes.add(data, data);</span> |
| <span class="source-line-no">099</span><span id="line-99"> protected static int SLAVES = 1;</span> |
| <span class="source-line-no">100</span><span id="line-100"> private static CountDownLatch latch;</span> |
| <span class="source-line-no">101</span><span id="line-101"> private static CountDownLatch getLatch;</span> |
| <span class="source-line-no">102</span><span id="line-102"> private static CountDownLatch compactionLatch;</span> |
| <span class="source-line-no">103</span><span id="line-103"> private static CountDownLatch exceptionLatch;</span> |
| <span class="source-line-no">104</span><span id="line-104"></span> |
| <span class="source-line-no">105</span><span id="line-105"> @Rule</span> |
| <span class="source-line-no">106</span><span id="line-106"> public TestName name = new TestName();</span> |
| <span class="source-line-no">107</span><span id="line-107"></span> |
| <span class="source-line-no">108</span><span id="line-108"> /**</span> |
| <span class="source-line-no">109</span><span id="line-109"> * @throws java.lang.Exception</span> |
| <span class="source-line-no">110</span><span id="line-110"> */</span> |
| <span class="source-line-no">111</span><span id="line-111"> @BeforeClass</span> |
| <span class="source-line-no">112</span><span id="line-112"> public static void setUpBeforeClass() throws Exception {</span> |
| <span class="source-line-no">113</span><span id="line-113"> ROWS[0] = ROW;</span> |
| <span class="source-line-no">114</span><span id="line-114"> ROWS[1] = ROW1;</span> |
| <span class="source-line-no">115</span><span id="line-115"> Configuration conf = TEST_UTIL.getConfiguration();</span> |
| <span class="source-line-no">116</span><span id="line-116"> conf.setStrings(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY,</span> |
| <span class="source-line-no">117</span><span id="line-117"> MultiRowMutationEndpoint.class.getName());</span> |
| <span class="source-line-no">118</span><span id="line-118"> conf.setInt("hbase.regionserver.handler.count", 20);</span> |
| <span class="source-line-no">119</span><span id="line-119"> conf.setInt("hbase.bucketcache.size", 400);</span> |
| <span class="source-line-no">120</span><span id="line-120"> conf.setStrings(HConstants.BUCKET_CACHE_IOENGINE_KEY, "offheap");</span> |
| <span class="source-line-no">121</span><span id="line-121"> conf.setFloat("hfile.block.cache.size", 0.2f);</span> |
| <span class="source-line-no">122</span><span id="line-122"> conf.setFloat("hbase.regionserver.global.memstore.size", 0.1f);</span> |
| <span class="source-line-no">123</span><span id="line-123"> conf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 0);// do not retry</span> |
| <span class="source-line-no">124</span><span id="line-124"> conf.setInt(HConstants.HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD, 5000);</span> |
| <span class="source-line-no">125</span><span id="line-125"> FAMILIES_1[0] = FAMILY;</span> |
| <span class="source-line-no">126</span><span id="line-126"> TEST_UTIL.startMiniCluster(SLAVES);</span> |
| <span class="source-line-no">127</span><span id="line-127"> }</span> |
| <span class="source-line-no">128</span><span id="line-128"></span> |
| <span class="source-line-no">129</span><span id="line-129"> /**</span> |
| <span class="source-line-no">130</span><span id="line-130"> * @throws java.lang.Exception</span> |
| <span class="source-line-no">131</span><span id="line-131"> */</span> |
| <span class="source-line-no">132</span><span id="line-132"> @AfterClass</span> |
| <span class="source-line-no">133</span><span id="line-133"> public static void tearDownAfterClass() throws Exception {</span> |
| <span class="source-line-no">134</span><span id="line-134"> TEST_UTIL.shutdownMiniCluster();</span> |
| <span class="source-line-no">135</span><span id="line-135"> }</span> |
| <span class="source-line-no">136</span><span id="line-136"></span> |
| <span class="source-line-no">137</span><span id="line-137"> /**</span> |
| <span class="source-line-no">138</span><span id="line-138"> * @throws java.lang.Exception</span> |
| <span class="source-line-no">139</span><span id="line-139"> */</span> |
| <span class="source-line-no">140</span><span id="line-140"> @Before</span> |
| <span class="source-line-no">141</span><span id="line-141"> public void setUp() throws Exception {</span> |
| <span class="source-line-no">142</span><span id="line-142"> CustomInnerRegionObserver.waitForGets.set(false);</span> |
| <span class="source-line-no">143</span><span id="line-143"> CustomInnerRegionObserver.countOfNext.set(0);</span> |
| <span class="source-line-no">144</span><span id="line-144"> CustomInnerRegionObserver.countOfGets.set(0);</span> |
| <span class="source-line-no">145</span><span id="line-145"> }</span> |
| <span class="source-line-no">146</span><span id="line-146"></span> |
| <span class="source-line-no">147</span><span id="line-147"> /**</span> |
| <span class="source-line-no">148</span><span id="line-148"> * @throws java.lang.Exception</span> |
| <span class="source-line-no">149</span><span id="line-149"> */</span> |
| <span class="source-line-no">150</span><span id="line-150"> @After</span> |
| <span class="source-line-no">151</span><span id="line-151"> public void tearDown() throws Exception {</span> |
| <span class="source-line-no">152</span><span id="line-152"> if (latch != null) {</span> |
| <span class="source-line-no">153</span><span id="line-153"> while (latch.getCount() > 0) {</span> |
| <span class="source-line-no">154</span><span id="line-154"> latch.countDown();</span> |
| <span class="source-line-no">155</span><span id="line-155"> }</span> |
| <span class="source-line-no">156</span><span id="line-156"> }</span> |
| <span class="source-line-no">157</span><span id="line-157"> if (getLatch != null) {</span> |
| <span class="source-line-no">158</span><span id="line-158"> getLatch.countDown();</span> |
| <span class="source-line-no">159</span><span id="line-159"> }</span> |
| <span class="source-line-no">160</span><span id="line-160"> if (compactionLatch != null) {</span> |
| <span class="source-line-no">161</span><span id="line-161"> compactionLatch.countDown();</span> |
| <span class="source-line-no">162</span><span id="line-162"> }</span> |
| <span class="source-line-no">163</span><span id="line-163"> if (exceptionLatch != null) {</span> |
| <span class="source-line-no">164</span><span id="line-164"> exceptionLatch.countDown();</span> |
| <span class="source-line-no">165</span><span id="line-165"> }</span> |
| <span class="source-line-no">166</span><span id="line-166"> latch = null;</span> |
| <span class="source-line-no">167</span><span id="line-167"> getLatch = null;</span> |
| <span class="source-line-no">168</span><span id="line-168"> compactionLatch = null;</span> |
| <span class="source-line-no">169</span><span id="line-169"> exceptionLatch = null;</span> |
| <span class="source-line-no">170</span><span id="line-170"> CustomInnerRegionObserver.throwException.set(false);</span> |
| <span class="source-line-no">171</span><span id="line-171"> // Clean up the tables for every test case</span> |
| <span class="source-line-no">172</span><span id="line-172"> TableName[] listTableNames = TEST_UTIL.getAdmin().listTableNames();</span> |
| <span class="source-line-no">173</span><span id="line-173"> for (TableName tableName : listTableNames) {</span> |
| <span class="source-line-no">174</span><span id="line-174"> if (!tableName.isSystemTable()) {</span> |
| <span class="source-line-no">175</span><span id="line-175"> TEST_UTIL.getAdmin().disableTable(tableName);</span> |
| <span class="source-line-no">176</span><span id="line-176"> TEST_UTIL.getAdmin().deleteTable(tableName);</span> |
| <span class="source-line-no">177</span><span id="line-177"> }</span> |
| <span class="source-line-no">178</span><span id="line-178"> }</span> |
| <span class="source-line-no">179</span><span id="line-179"> }</span> |
| <span class="source-line-no">180</span><span id="line-180"></span> |
| <span class="source-line-no">181</span><span id="line-181"> @Test</span> |
| <span class="source-line-no">182</span><span id="line-182"> public void testBlockEvictionWithParallelScans() throws Exception {</span> |
| <span class="source-line-no">183</span><span id="line-183"> Table table = null;</span> |
| <span class="source-line-no">184</span><span id="line-184"> try {</span> |
| <span class="source-line-no">185</span><span id="line-185"> latch = new CountDownLatch(1);</span> |
| <span class="source-line-no">186</span><span id="line-186"> final TableName tableName = TableName.valueOf(name.getMethodName());</span> |
| <span class="source-line-no">187</span><span id="line-187"> // Create a table with block size as 1024</span> |
| <span class="source-line-no">188</span><span id="line-188"> table = TEST_UTIL.createTable(tableName, FAMILIES_1, 1, 1024,</span> |
| <span class="source-line-no">189</span><span id="line-189"> CustomInnerRegionObserver.class.getName());</span> |
| <span class="source-line-no">190</span><span id="line-190"> // get the block cache and region</span> |
| <span class="source-line-no">191</span><span id="line-191"> RegionLocator locator = TEST_UTIL.getConnection().getRegionLocator(tableName);</span> |
| <span class="source-line-no">192</span><span id="line-192"> String regionName = locator.getAllRegionLocations().get(0).getRegion().getEncodedName();</span> |
| <span class="source-line-no">193</span><span id="line-193"> HRegion region = TEST_UTIL.getRSForFirstRegionInTable(tableName).getRegion(regionName);</span> |
| <span class="source-line-no">194</span><span id="line-194"> HStore store = region.getStores().iterator().next();</span> |
| <span class="source-line-no">195</span><span id="line-195"> CacheConfig cacheConf = store.getCacheConfig();</span> |
| <span class="source-line-no">196</span><span id="line-196"> cacheConf.setCacheDataOnWrite(true);</span> |
| <span class="source-line-no">197</span><span id="line-197"> cacheConf.setEvictOnClose(true);</span> |
| <span class="source-line-no">198</span><span id="line-198"> BlockCache cache = cacheConf.getBlockCache().get();</span> |
| <span class="source-line-no">199</span><span id="line-199"></span> |
| <span class="source-line-no">200</span><span id="line-200"> // insert data. 2 Rows are added</span> |
| <span class="source-line-no">201</span><span id="line-201"> Put put = new Put(ROW);</span> |
| <span class="source-line-no">202</span><span id="line-202"> put.addColumn(FAMILY, QUALIFIER, data);</span> |
| <span class="source-line-no">203</span><span id="line-203"> table.put(put);</span> |
| <span class="source-line-no">204</span><span id="line-204"> put = new Put(ROW1);</span> |
| <span class="source-line-no">205</span><span id="line-205"> put.addColumn(FAMILY, QUALIFIER, data);</span> |
| <span class="source-line-no">206</span><span id="line-206"> table.put(put);</span> |
| <span class="source-line-no">207</span><span id="line-207"> assertTrue(Bytes.equals(table.get(new Get(ROW)).value(), data));</span> |
| <span class="source-line-no">208</span><span id="line-208"> // data was in memstore so don't expect any changes</span> |
| <span class="source-line-no">209</span><span id="line-209"> // flush the data</span> |
| <span class="source-line-no">210</span><span id="line-210"> // Should create one Hfile with 2 blocks</span> |
| <span class="source-line-no">211</span><span id="line-211"> region.flush(true);</span> |
| <span class="source-line-no">212</span><span id="line-212"> // Load cache</span> |
| <span class="source-line-no">213</span><span id="line-213"> // Create three sets of scan</span> |
| <span class="source-line-no">214</span><span id="line-214"> ScanThread[] scanThreads = initiateScan(table, false);</span> |
| <span class="source-line-no">215</span><span id="line-215"> Thread.sleep(100);</span> |
| <span class="source-line-no">216</span><span id="line-216"> checkForBlockEviction(cache, false, false);</span> |
| <span class="source-line-no">217</span><span id="line-217"> for (ScanThread thread : scanThreads) {</span> |
| <span class="source-line-no">218</span><span id="line-218"> thread.join();</span> |
| <span class="source-line-no">219</span><span id="line-219"> }</span> |
| <span class="source-line-no">220</span><span id="line-220"> // CustomInnerRegionObserver.sleepTime.set(0);</span> |
| <span class="source-line-no">221</span><span id="line-221"> Iterator<CachedBlock> iterator = cache.iterator();</span> |
| <span class="source-line-no">222</span><span id="line-222"> iterateBlockCache(cache, iterator);</span> |
| <span class="source-line-no">223</span><span id="line-223"> // read the data and expect same blocks, one new hit, no misses</span> |
| <span class="source-line-no">224</span><span id="line-224"> assertTrue(Bytes.equals(table.get(new Get(ROW)).value(), data));</span> |
| <span class="source-line-no">225</span><span id="line-225"> iterator = cache.iterator();</span> |
| <span class="source-line-no">226</span><span id="line-226"> iterateBlockCache(cache, iterator);</span> |
| <span class="source-line-no">227</span><span id="line-227"> // Check how this miss is happening</span> |
| <span class="source-line-no">228</span><span id="line-228"> // insert a second column, read the row, no new blocks, 3 new hits</span> |
| <span class="source-line-no">229</span><span id="line-229"> byte[] QUALIFIER2 = Bytes.add(QUALIFIER, QUALIFIER);</span> |
| <span class="source-line-no">230</span><span id="line-230"> byte[] data2 = Bytes.add(data, data);</span> |
| <span class="source-line-no">231</span><span id="line-231"> put = new Put(ROW);</span> |
| <span class="source-line-no">232</span><span id="line-232"> put.addColumn(FAMILY, QUALIFIER2, data2);</span> |
| <span class="source-line-no">233</span><span id="line-233"> table.put(put);</span> |
| <span class="source-line-no">234</span><span id="line-234"> Result r = table.get(new Get(ROW));</span> |
| <span class="source-line-no">235</span><span id="line-235"> assertTrue(Bytes.equals(r.getValue(FAMILY, QUALIFIER), data));</span> |
| <span class="source-line-no">236</span><span id="line-236"> assertTrue(Bytes.equals(r.getValue(FAMILY, QUALIFIER2), data2));</span> |
| <span class="source-line-no">237</span><span id="line-237"> iterator = cache.iterator();</span> |
| <span class="source-line-no">238</span><span id="line-238"> iterateBlockCache(cache, iterator);</span> |
| <span class="source-line-no">239</span><span id="line-239"> // flush, one new block</span> |
| <span class="source-line-no">240</span><span id="line-240"> System.out.println("Flushing cache");</span> |
| <span class="source-line-no">241</span><span id="line-241"> region.flush(true);</span> |
| <span class="source-line-no">242</span><span id="line-242"> iterator = cache.iterator();</span> |
| <span class="source-line-no">243</span><span id="line-243"> iterateBlockCache(cache, iterator);</span> |
| <span class="source-line-no">244</span><span id="line-244"> // compact, net minus two blocks, two hits, no misses</span> |
| <span class="source-line-no">245</span><span id="line-245"> System.out.println("Compacting");</span> |
| <span class="source-line-no">246</span><span id="line-246"> assertEquals(2, store.getStorefilesCount());</span> |
| <span class="source-line-no">247</span><span id="line-247"> store.triggerMajorCompaction();</span> |
| <span class="source-line-no">248</span><span id="line-248"> region.compact(true);</span> |
| <span class="source-line-no">249</span><span id="line-249"> waitForStoreFileCount(store, 1, 10000); // wait 10 seconds max</span> |
| <span class="source-line-no">250</span><span id="line-250"> assertEquals(1, store.getStorefilesCount());</span> |
| <span class="source-line-no">251</span><span id="line-251"> iterator = cache.iterator();</span> |
| <span class="source-line-no">252</span><span id="line-252"> iterateBlockCache(cache, iterator);</span> |
| <span class="source-line-no">253</span><span id="line-253"> // read the row, this should be a cache miss because we don't cache data</span> |
| <span class="source-line-no">254</span><span id="line-254"> // blocks on compaction</span> |
| <span class="source-line-no">255</span><span id="line-255"> r = table.get(new Get(ROW));</span> |
| <span class="source-line-no">256</span><span id="line-256"> assertTrue(Bytes.equals(r.getValue(FAMILY, QUALIFIER), data));</span> |
| <span class="source-line-no">257</span><span id="line-257"> assertTrue(Bytes.equals(r.getValue(FAMILY, QUALIFIER2), data2));</span> |
| <span class="source-line-no">258</span><span id="line-258"> iterator = cache.iterator();</span> |
| <span class="source-line-no">259</span><span id="line-259"> iterateBlockCache(cache, iterator);</span> |
| <span class="source-line-no">260</span><span id="line-260"> } finally {</span> |
| <span class="source-line-no">261</span><span id="line-261"> if (table != null) {</span> |
| <span class="source-line-no">262</span><span id="line-262"> table.close();</span> |
| <span class="source-line-no">263</span><span id="line-263"> }</span> |
| <span class="source-line-no">264</span><span id="line-264"> }</span> |
| <span class="source-line-no">265</span><span id="line-265"> }</span> |
| <span class="source-line-no">266</span><span id="line-266"></span> |
| <span class="source-line-no">267</span><span id="line-267"> @Test</span> |
| <span class="source-line-no">268</span><span id="line-268"> public void testParallelGetsAndScans() throws IOException, InterruptedException {</span> |
| <span class="source-line-no">269</span><span id="line-269"> Table table = null;</span> |
| <span class="source-line-no">270</span><span id="line-270"> try {</span> |
| <span class="source-line-no">271</span><span id="line-271"> latch = new CountDownLatch(2);</span> |
| <span class="source-line-no">272</span><span id="line-272"> // Check if get() returns blocks on its close() itself</span> |
| <span class="source-line-no">273</span><span id="line-273"> getLatch = new CountDownLatch(1);</span> |
| <span class="source-line-no">274</span><span id="line-274"> final TableName tableName = TableName.valueOf(name.getMethodName());</span> |
| <span class="source-line-no">275</span><span id="line-275"> // Create KV that will give you two blocks</span> |
| <span class="source-line-no">276</span><span id="line-276"> // Create a table with block size as 1024</span> |
| <span class="source-line-no">277</span><span id="line-277"> table = TEST_UTIL.createTable(tableName, FAMILIES_1, 1, 1024,</span> |
| <span class="source-line-no">278</span><span id="line-278"> CustomInnerRegionObserver.class.getName());</span> |
| <span class="source-line-no">279</span><span id="line-279"> // get the block cache and region</span> |
| <span class="source-line-no">280</span><span id="line-280"> RegionLocator locator = TEST_UTIL.getConnection().getRegionLocator(tableName);</span> |
| <span class="source-line-no">281</span><span id="line-281"> String regionName = locator.getAllRegionLocations().get(0).getRegion().getEncodedName();</span> |
| <span class="source-line-no">282</span><span id="line-282"> HRegion region = TEST_UTIL.getRSForFirstRegionInTable(tableName).getRegion(regionName);</span> |
| <span class="source-line-no">283</span><span id="line-283"> HStore store = region.getStores().iterator().next();</span> |
| <span class="source-line-no">284</span><span id="line-284"> CacheConfig cacheConf = store.getCacheConfig();</span> |
| <span class="source-line-no">285</span><span id="line-285"> cacheConf.setCacheDataOnWrite(true);</span> |
| <span class="source-line-no">286</span><span id="line-286"> cacheConf.setEvictOnClose(true);</span> |
| <span class="source-line-no">287</span><span id="line-287"> BlockCache cache = cacheConf.getBlockCache().get();</span> |
| <span class="source-line-no">288</span><span id="line-288"></span> |
| <span class="source-line-no">289</span><span id="line-289"> insertData(table);</span> |
| <span class="source-line-no">290</span><span id="line-290"> // flush the data</span> |
| <span class="source-line-no">291</span><span id="line-291"> System.out.println("Flushing cache");</span> |
| <span class="source-line-no">292</span><span id="line-292"> // Should create one Hfile with 2 blocks</span> |
| <span class="source-line-no">293</span><span id="line-293"> region.flush(true);</span> |
| <span class="source-line-no">294</span><span id="line-294"> // Create three sets of scan</span> |
| <span class="source-line-no">295</span><span id="line-295"> CustomInnerRegionObserver.waitForGets.set(true);</span> |
| <span class="source-line-no">296</span><span id="line-296"> ScanThread[] scanThreads = initiateScan(table, false);</span> |
| <span class="source-line-no">297</span><span id="line-297"> // Create three sets of gets</span> |
| <span class="source-line-no">298</span><span id="line-298"> GetThread[] getThreads = initiateGet(table, false, false);</span> |
| <span class="source-line-no">299</span><span id="line-299"> checkForBlockEviction(cache, false, false);</span> |
| <span class="source-line-no">300</span><span id="line-300"> CustomInnerRegionObserver.waitForGets.set(false);</span> |
| <span class="source-line-no">301</span><span id="line-301"> checkForBlockEviction(cache, false, false);</span> |
| <span class="source-line-no">302</span><span id="line-302"> for (GetThread thread : getThreads) {</span> |
| <span class="source-line-no">303</span><span id="line-303"> thread.join();</span> |
| <span class="source-line-no">304</span><span id="line-304"> }</span> |
| <span class="source-line-no">305</span><span id="line-305"> // Verify whether the gets have returned the blocks that it had</span> |
| <span class="source-line-no">306</span><span id="line-306"> CustomInnerRegionObserver.waitForGets.set(true);</span> |
| <span class="source-line-no">307</span><span id="line-307"> // giving some time for the block to be decremented</span> |
| <span class="source-line-no">308</span><span id="line-308"> checkForBlockEviction(cache, true, false);</span> |
| <span class="source-line-no">309</span><span id="line-309"> getLatch.countDown();</span> |
| <span class="source-line-no">310</span><span id="line-310"> for (ScanThread thread : scanThreads) {</span> |
| <span class="source-line-no">311</span><span id="line-311"> thread.join();</span> |
| <span class="source-line-no">312</span><span id="line-312"> }</span> |
| <span class="source-line-no">313</span><span id="line-313"> System.out.println("Scans should have returned the bloks");</span> |
| <span class="source-line-no">314</span><span id="line-314"> // Check with either true or false</span> |
| <span class="source-line-no">315</span><span id="line-315"> CustomInnerRegionObserver.waitForGets.set(false);</span> |
| <span class="source-line-no">316</span><span id="line-316"> // The scan should also have released the blocks by now</span> |
| <span class="source-line-no">317</span><span id="line-317"> checkForBlockEviction(cache, true, true);</span> |
| <span class="source-line-no">318</span><span id="line-318"> } finally {</span> |
| <span class="source-line-no">319</span><span id="line-319"> if (table != null) {</span> |
| <span class="source-line-no">320</span><span id="line-320"> table.close();</span> |
| <span class="source-line-no">321</span><span id="line-321"> }</span> |
| <span class="source-line-no">322</span><span id="line-322"> }</span> |
| <span class="source-line-no">323</span><span id="line-323"> }</span> |
| <span class="source-line-no">324</span><span id="line-324"></span> |
| <span class="source-line-no">325</span><span id="line-325"> @Test</span> |
| <span class="source-line-no">326</span><span id="line-326"> public void testGetWithCellsInDifferentFiles() throws IOException, InterruptedException {</span> |
| <span class="source-line-no">327</span><span id="line-327"> Table table = null;</span> |
| <span class="source-line-no">328</span><span id="line-328"> try {</span> |
| <span class="source-line-no">329</span><span id="line-329"> latch = new CountDownLatch(1);</span> |
| <span class="source-line-no">330</span><span id="line-330"> // Check if get() returns blocks on its close() itself</span> |
| <span class="source-line-no">331</span><span id="line-331"> getLatch = new CountDownLatch(1);</span> |
| <span class="source-line-no">332</span><span id="line-332"> final TableName tableName = TableName.valueOf(name.getMethodName());</span> |
| <span class="source-line-no">333</span><span id="line-333"> // Create KV that will give you two blocks</span> |
| <span class="source-line-no">334</span><span id="line-334"> // Create a table with block size as 1024</span> |
| <span class="source-line-no">335</span><span id="line-335"> table = TEST_UTIL.createTable(tableName, FAMILIES_1, 1, 1024,</span> |
| <span class="source-line-no">336</span><span id="line-336"> CustomInnerRegionObserver.class.getName());</span> |
| <span class="source-line-no">337</span><span id="line-337"> // get the block cache and region</span> |
| <span class="source-line-no">338</span><span id="line-338"> RegionLocator locator = TEST_UTIL.getConnection().getRegionLocator(tableName);</span> |
| <span class="source-line-no">339</span><span id="line-339"> String regionName = locator.getAllRegionLocations().get(0).getRegion().getEncodedName();</span> |
| <span class="source-line-no">340</span><span id="line-340"> HRegion region = TEST_UTIL.getRSForFirstRegionInTable(tableName).getRegion(regionName);</span> |
| <span class="source-line-no">341</span><span id="line-341"> HStore store = region.getStores().iterator().next();</span> |
| <span class="source-line-no">342</span><span id="line-342"> CacheConfig cacheConf = store.getCacheConfig();</span> |
| <span class="source-line-no">343</span><span id="line-343"> cacheConf.setCacheDataOnWrite(true);</span> |
| <span class="source-line-no">344</span><span id="line-344"> cacheConf.setEvictOnClose(true);</span> |
| <span class="source-line-no">345</span><span id="line-345"> BlockCache cache = cacheConf.getBlockCache().get();</span> |
| <span class="source-line-no">346</span><span id="line-346"></span> |
| <span class="source-line-no">347</span><span id="line-347"> Put put = new Put(ROW);</span> |
| <span class="source-line-no">348</span><span id="line-348"> put.addColumn(FAMILY, QUALIFIER, data);</span> |
| <span class="source-line-no">349</span><span id="line-349"> table.put(put);</span> |
| <span class="source-line-no">350</span><span id="line-350"> region.flush(true);</span> |
| <span class="source-line-no">351</span><span id="line-351"> put = new Put(ROW1);</span> |
| <span class="source-line-no">352</span><span id="line-352"> put.addColumn(FAMILY, QUALIFIER, data);</span> |
| <span class="source-line-no">353</span><span id="line-353"> table.put(put);</span> |
| <span class="source-line-no">354</span><span id="line-354"> region.flush(true);</span> |
| <span class="source-line-no">355</span><span id="line-355"> byte[] QUALIFIER2 = Bytes.add(QUALIFIER, QUALIFIER);</span> |
| <span class="source-line-no">356</span><span id="line-356"> put = new Put(ROW);</span> |
| <span class="source-line-no">357</span><span id="line-357"> put.addColumn(FAMILY, QUALIFIER2, data2);</span> |
| <span class="source-line-no">358</span><span id="line-358"> table.put(put);</span> |
| <span class="source-line-no">359</span><span id="line-359"> region.flush(true);</span> |
| <span class="source-line-no">360</span><span id="line-360"> // flush the data</span> |
| <span class="source-line-no">361</span><span id="line-361"> System.out.println("Flushing cache");</span> |
| <span class="source-line-no">362</span><span id="line-362"> // Should create one Hfile with 2 blocks</span> |
| <span class="source-line-no">363</span><span id="line-363"> CustomInnerRegionObserver.waitForGets.set(true);</span> |
| <span class="source-line-no">364</span><span id="line-364"> // Create three sets of gets</span> |
| <span class="source-line-no">365</span><span id="line-365"> GetThread[] getThreads = initiateGet(table, false, false);</span> |
| <span class="source-line-no">366</span><span id="line-366"> Thread.sleep(200);</span> |
| <span class="source-line-no">367</span><span id="line-367"> CustomInnerRegionObserver.getCdl().get().countDown();</span> |
| <span class="source-line-no">368</span><span id="line-368"> for (GetThread thread : getThreads) {</span> |
| <span class="source-line-no">369</span><span id="line-369"> thread.join();</span> |
| <span class="source-line-no">370</span><span id="line-370"> }</span> |
| <span class="source-line-no">371</span><span id="line-371"> // Verify whether the gets have returned the blocks that it had</span> |
| <span class="source-line-no">372</span><span id="line-372"> CustomInnerRegionObserver.waitForGets.set(true);</span> |
| <span class="source-line-no">373</span><span id="line-373"> // giving some time for the block to be decremented</span> |
| <span class="source-line-no">374</span><span id="line-374"> checkForBlockEviction(cache, true, false);</span> |
| <span class="source-line-no">375</span><span id="line-375"> getLatch.countDown();</span> |
| <span class="source-line-no">376</span><span id="line-376"> System.out.println("Gets should have returned the bloks");</span> |
| <span class="source-line-no">377</span><span id="line-377"> } finally {</span> |
| <span class="source-line-no">378</span><span id="line-378"> if (table != null) {</span> |
| <span class="source-line-no">379</span><span id="line-379"> table.close();</span> |
| <span class="source-line-no">380</span><span id="line-380"> }</span> |
| <span class="source-line-no">381</span><span id="line-381"> }</span> |
| <span class="source-line-no">382</span><span id="line-382"> }</span> |
| <span class="source-line-no">383</span><span id="line-383"></span> |
| <span class="source-line-no">384</span><span id="line-384"> @Test</span> |
| <span class="source-line-no">385</span><span id="line-385"> // TODO : check how block index works here</span> |
| <span class="source-line-no">386</span><span id="line-386"> public void testGetsWithMultiColumnsAndExplicitTracker()</span> |
| <span class="source-line-no">387</span><span id="line-387"> throws IOException, InterruptedException {</span> |
| <span class="source-line-no">388</span><span id="line-388"> Table table = null;</span> |
| <span class="source-line-no">389</span><span id="line-389"> try {</span> |
| <span class="source-line-no">390</span><span id="line-390"> latch = new CountDownLatch(1);</span> |
| <span class="source-line-no">391</span><span id="line-391"> // Check if get() returns blocks on its close() itself</span> |
| <span class="source-line-no">392</span><span id="line-392"> getLatch = new CountDownLatch(1);</span> |
| <span class="source-line-no">393</span><span id="line-393"> final TableName tableName = TableName.valueOf(name.getMethodName());</span> |
| <span class="source-line-no">394</span><span id="line-394"> // Create KV that will give you two blocks</span> |
| <span class="source-line-no">395</span><span id="line-395"> // Create a table with block size as 1024</span> |
| <span class="source-line-no">396</span><span id="line-396"> table = TEST_UTIL.createTable(tableName, FAMILIES_1, 1, 1024,</span> |
| <span class="source-line-no">397</span><span id="line-397"> CustomInnerRegionObserver.class.getName());</span> |
| <span class="source-line-no">398</span><span id="line-398"> // get the block cache and region</span> |
| <span class="source-line-no">399</span><span id="line-399"> RegionLocator locator = TEST_UTIL.getConnection().getRegionLocator(tableName);</span> |
| <span class="source-line-no">400</span><span id="line-400"> String regionName = locator.getAllRegionLocations().get(0).getRegion().getEncodedName();</span> |
| <span class="source-line-no">401</span><span id="line-401"> HRegion region = TEST_UTIL.getRSForFirstRegionInTable(tableName).getRegion(regionName);</span> |
| <span class="source-line-no">402</span><span id="line-402"> BlockCache cache = setCacheProperties(region);</span> |
| <span class="source-line-no">403</span><span id="line-403"> Put put = new Put(ROW);</span> |
| <span class="source-line-no">404</span><span id="line-404"> put.addColumn(FAMILY, QUALIFIER, data);</span> |
| <span class="source-line-no">405</span><span id="line-405"> table.put(put);</span> |
| <span class="source-line-no">406</span><span id="line-406"> region.flush(true);</span> |
| <span class="source-line-no">407</span><span id="line-407"> put = new Put(ROW1);</span> |
| <span class="source-line-no">408</span><span id="line-408"> put.addColumn(FAMILY, QUALIFIER, data);</span> |
| <span class="source-line-no">409</span><span id="line-409"> table.put(put);</span> |
| <span class="source-line-no">410</span><span id="line-410"> region.flush(true);</span> |
| <span class="source-line-no">411</span><span id="line-411"> for (int i = 1; i < 10; i++) {</span> |
| <span class="source-line-no">412</span><span id="line-412"> put = new Put(ROW);</span> |
| <span class="source-line-no">413</span><span id="line-413"> put.addColumn(FAMILY, Bytes.toBytes("testQualifier" + i), data2);</span> |
| <span class="source-line-no">414</span><span id="line-414"> table.put(put);</span> |
| <span class="source-line-no">415</span><span id="line-415"> if (i % 2 == 0) {</span> |
| <span class="source-line-no">416</span><span id="line-416"> region.flush(true);</span> |
| <span class="source-line-no">417</span><span id="line-417"> }</span> |
| <span class="source-line-no">418</span><span id="line-418"> }</span> |
| <span class="source-line-no">419</span><span id="line-419"> byte[] QUALIFIER2 = Bytes.add(QUALIFIER, QUALIFIER);</span> |
| <span class="source-line-no">420</span><span id="line-420"> put = new Put(ROW);</span> |
| <span class="source-line-no">421</span><span id="line-421"> put.addColumn(FAMILY, QUALIFIER2, data2);</span> |
| <span class="source-line-no">422</span><span id="line-422"> table.put(put);</span> |
| <span class="source-line-no">423</span><span id="line-423"> region.flush(true);</span> |
| <span class="source-line-no">424</span><span id="line-424"> // flush the data</span> |
| <span class="source-line-no">425</span><span id="line-425"> System.out.println("Flushing cache");</span> |
| <span class="source-line-no">426</span><span id="line-426"> // Should create one Hfile with 2 blocks</span> |
| <span class="source-line-no">427</span><span id="line-427"> CustomInnerRegionObserver.waitForGets.set(true);</span> |
| <span class="source-line-no">428</span><span id="line-428"> // Create three sets of gets</span> |
| <span class="source-line-no">429</span><span id="line-429"> GetThread[] getThreads = initiateGet(table, true, false);</span> |
| <span class="source-line-no">430</span><span id="line-430"> Thread.sleep(200);</span> |
| <span class="source-line-no">431</span><span id="line-431"> Iterator<CachedBlock> iterator = cache.iterator();</span> |
| <span class="source-line-no">432</span><span id="line-432"> boolean usedBlocksFound = false;</span> |
| <span class="source-line-no">433</span><span id="line-433"> int refCount = 0;</span> |
| <span class="source-line-no">434</span><span id="line-434"> int noOfBlocksWithRef = 0;</span> |
| <span class="source-line-no">435</span><span id="line-435"> while (iterator.hasNext()) {</span> |
| <span class="source-line-no">436</span><span id="line-436"> CachedBlock next = iterator.next();</span> |
| <span class="source-line-no">437</span><span id="line-437"> BlockCacheKey cacheKey = new BlockCacheKey(next.getFilename(), next.getOffset());</span> |
| <span class="source-line-no">438</span><span id="line-438"> if (cache instanceof BucketCache) {</span> |
| <span class="source-line-no">439</span><span id="line-439"> refCount = ((BucketCache) cache).getRpcRefCount(cacheKey);</span> |
| <span class="source-line-no">440</span><span id="line-440"> } else if (cache instanceof CombinedBlockCache) {</span> |
| <span class="source-line-no">441</span><span id="line-441"> refCount = ((CombinedBlockCache) cache).getRpcRefCount(cacheKey);</span> |
| <span class="source-line-no">442</span><span id="line-442"> } else {</span> |
| <span class="source-line-no">443</span><span id="line-443"> continue;</span> |
| <span class="source-line-no">444</span><span id="line-444"> }</span> |
| <span class="source-line-no">445</span><span id="line-445"> if (refCount != 0) {</span> |
| <span class="source-line-no">446</span><span id="line-446"> // Blocks will be with count 3</span> |
| <span class="source-line-no">447</span><span id="line-447"> System.out.println("The refCount is " + refCount);</span> |
| <span class="source-line-no">448</span><span id="line-448"> assertEquals(NO_OF_THREADS, refCount);</span> |
| <span class="source-line-no">449</span><span id="line-449"> usedBlocksFound = true;</span> |
| <span class="source-line-no">450</span><span id="line-450"> noOfBlocksWithRef++;</span> |
| <span class="source-line-no">451</span><span id="line-451"> }</span> |
| <span class="source-line-no">452</span><span id="line-452"> }</span> |
| <span class="source-line-no">453</span><span id="line-453"> assertTrue(usedBlocksFound);</span> |
| <span class="source-line-no">454</span><span id="line-454"> // the number of blocks referred</span> |
| <span class="source-line-no">455</span><span id="line-455"> assertEquals(10, noOfBlocksWithRef);</span> |
| <span class="source-line-no">456</span><span id="line-456"> CustomInnerRegionObserver.getCdl().get().countDown();</span> |
| <span class="source-line-no">457</span><span id="line-457"> for (GetThread thread : getThreads) {</span> |
| <span class="source-line-no">458</span><span id="line-458"> thread.join();</span> |
| <span class="source-line-no">459</span><span id="line-459"> }</span> |
| <span class="source-line-no">460</span><span id="line-460"> // Verify whether the gets have returned the blocks that it had</span> |
| <span class="source-line-no">461</span><span id="line-461"> CustomInnerRegionObserver.waitForGets.set(true);</span> |
| <span class="source-line-no">462</span><span id="line-462"> // giving some time for the block to be decremented</span> |
| <span class="source-line-no">463</span><span id="line-463"> checkForBlockEviction(cache, true, false);</span> |
| <span class="source-line-no">464</span><span id="line-464"> getLatch.countDown();</span> |
| <span class="source-line-no">465</span><span id="line-465"> System.out.println("Gets should have returned the bloks");</span> |
| <span class="source-line-no">466</span><span id="line-466"> } finally {</span> |
| <span class="source-line-no">467</span><span id="line-467"> if (table != null) {</span> |
| <span class="source-line-no">468</span><span id="line-468"> table.close();</span> |
| <span class="source-line-no">469</span><span id="line-469"> }</span> |
| <span class="source-line-no">470</span><span id="line-470"> }</span> |
| <span class="source-line-no">471</span><span id="line-471"> }</span> |
| <span class="source-line-no">472</span><span id="line-472"></span> |
| <span class="source-line-no">473</span><span id="line-473"> @Test</span> |
| <span class="source-line-no">474</span><span id="line-474"> public void testGetWithMultipleColumnFamilies() throws IOException, InterruptedException {</span> |
| <span class="source-line-no">475</span><span id="line-475"> Table table = null;</span> |
| <span class="source-line-no">476</span><span id="line-476"> try {</span> |
| <span class="source-line-no">477</span><span id="line-477"> latch = new CountDownLatch(1);</span> |
| <span class="source-line-no">478</span><span id="line-478"> // Check if get() returns blocks on its close() itself</span> |
| <span class="source-line-no">479</span><span id="line-479"> getLatch = new CountDownLatch(1);</span> |
| <span class="source-line-no">480</span><span id="line-480"> final TableName tableName = TableName.valueOf(name.getMethodName());</span> |
| <span class="source-line-no">481</span><span id="line-481"> // Create KV that will give you two blocks</span> |
| <span class="source-line-no">482</span><span id="line-482"> // Create a table with block size as 1024</span> |
| <span class="source-line-no">483</span><span id="line-483"> byte[][] fams = new byte[10][];</span> |
| <span class="source-line-no">484</span><span id="line-484"> fams[0] = FAMILY;</span> |
| <span class="source-line-no">485</span><span id="line-485"> for (int i = 1; i < 10; i++) {</span> |
| <span class="source-line-no">486</span><span id="line-486"> fams[i] = (Bytes.toBytes("testFamily" + i));</span> |
| <span class="source-line-no">487</span><span id="line-487"> }</span> |
| <span class="source-line-no">488</span><span id="line-488"> table =</span> |
| <span class="source-line-no">489</span><span id="line-489"> TEST_UTIL.createTable(tableName, fams, 1, 1024, CustomInnerRegionObserver.class.getName());</span> |
| <span class="source-line-no">490</span><span id="line-490"> // get the block cache and region</span> |
| <span class="source-line-no">491</span><span id="line-491"> RegionLocator locator = TEST_UTIL.getConnection().getRegionLocator(tableName);</span> |
| <span class="source-line-no">492</span><span id="line-492"> String regionName = locator.getAllRegionLocations().get(0).getRegion().getEncodedName();</span> |
| <span class="source-line-no">493</span><span id="line-493"> HRegion region = TEST_UTIL.getRSForFirstRegionInTable(tableName).getRegion(regionName);</span> |
| <span class="source-line-no">494</span><span id="line-494"> BlockCache cache = setCacheProperties(region);</span> |
| <span class="source-line-no">495</span><span id="line-495"></span> |
| <span class="source-line-no">496</span><span id="line-496"> Put put = new Put(ROW);</span> |
| <span class="source-line-no">497</span><span id="line-497"> put.addColumn(FAMILY, QUALIFIER, data);</span> |
| <span class="source-line-no">498</span><span id="line-498"> table.put(put);</span> |
| <span class="source-line-no">499</span><span id="line-499"> region.flush(true);</span> |
| <span class="source-line-no">500</span><span id="line-500"> put = new Put(ROW1);</span> |
| <span class="source-line-no">501</span><span id="line-501"> put.addColumn(FAMILY, QUALIFIER, data);</span> |
| <span class="source-line-no">502</span><span id="line-502"> table.put(put);</span> |
| <span class="source-line-no">503</span><span id="line-503"> region.flush(true);</span> |
| <span class="source-line-no">504</span><span id="line-504"> for (int i = 1; i < 10; i++) {</span> |
| <span class="source-line-no">505</span><span id="line-505"> put = new Put(ROW);</span> |
| <span class="source-line-no">506</span><span id="line-506"> put.addColumn(Bytes.toBytes("testFamily" + i), Bytes.toBytes("testQualifier" + i), data2);</span> |
| <span class="source-line-no">507</span><span id="line-507"> table.put(put);</span> |
| <span class="source-line-no">508</span><span id="line-508"> if (i % 2 == 0) {</span> |
| <span class="source-line-no">509</span><span id="line-509"> region.flush(true);</span> |
| <span class="source-line-no">510</span><span id="line-510"> }</span> |
| <span class="source-line-no">511</span><span id="line-511"> }</span> |
| <span class="source-line-no">512</span><span id="line-512"> region.flush(true);</span> |
| <span class="source-line-no">513</span><span id="line-513"> byte[] QUALIFIER2 = Bytes.add(QUALIFIER, QUALIFIER);</span> |
| <span class="source-line-no">514</span><span id="line-514"> put = new Put(ROW);</span> |
| <span class="source-line-no">515</span><span id="line-515"> put.addColumn(FAMILY, QUALIFIER2, data2);</span> |
| <span class="source-line-no">516</span><span id="line-516"> table.put(put);</span> |
| <span class="source-line-no">517</span><span id="line-517"> region.flush(true);</span> |
| <span class="source-line-no">518</span><span id="line-518"> // flush the data</span> |
| <span class="source-line-no">519</span><span id="line-519"> System.out.println("Flushing cache");</span> |
| <span class="source-line-no">520</span><span id="line-520"> // Should create one Hfile with 2 blocks</span> |
| <span class="source-line-no">521</span><span id="line-521"> CustomInnerRegionObserver.waitForGets.set(true);</span> |
| <span class="source-line-no">522</span><span id="line-522"> // Create three sets of gets</span> |
| <span class="source-line-no">523</span><span id="line-523"> GetThread[] getThreads = initiateGet(table, true, true);</span> |
| <span class="source-line-no">524</span><span id="line-524"> Thread.sleep(200);</span> |
| <span class="source-line-no">525</span><span id="line-525"> Iterator<CachedBlock> iterator = cache.iterator();</span> |
| <span class="source-line-no">526</span><span id="line-526"> boolean usedBlocksFound = false;</span> |
| <span class="source-line-no">527</span><span id="line-527"> int refCount = 0;</span> |
| <span class="source-line-no">528</span><span id="line-528"> int noOfBlocksWithRef = 0;</span> |
| <span class="source-line-no">529</span><span id="line-529"> while (iterator.hasNext()) {</span> |
| <span class="source-line-no">530</span><span id="line-530"> CachedBlock next = iterator.next();</span> |
| <span class="source-line-no">531</span><span id="line-531"> BlockCacheKey cacheKey = new BlockCacheKey(next.getFilename(), next.getOffset());</span> |
| <span class="source-line-no">532</span><span id="line-532"> if (cache instanceof BucketCache) {</span> |
| <span class="source-line-no">533</span><span id="line-533"> refCount = ((BucketCache) cache).getRpcRefCount(cacheKey);</span> |
| <span class="source-line-no">534</span><span id="line-534"> } else if (cache instanceof CombinedBlockCache) {</span> |
| <span class="source-line-no">535</span><span id="line-535"> refCount = ((CombinedBlockCache) cache).getRpcRefCount(cacheKey);</span> |
| <span class="source-line-no">536</span><span id="line-536"> } else {</span> |
| <span class="source-line-no">537</span><span id="line-537"> continue;</span> |
| <span class="source-line-no">538</span><span id="line-538"> }</span> |
| <span class="source-line-no">539</span><span id="line-539"> if (refCount != 0) {</span> |
| <span class="source-line-no">540</span><span id="line-540"> // Blocks will be with count 3</span> |
| <span class="source-line-no">541</span><span id="line-541"> System.out.println("The refCount is " + refCount);</span> |
| <span class="source-line-no">542</span><span id="line-542"> assertEquals(NO_OF_THREADS, refCount);</span> |
| <span class="source-line-no">543</span><span id="line-543"> usedBlocksFound = true;</span> |
| <span class="source-line-no">544</span><span id="line-544"> noOfBlocksWithRef++;</span> |
| <span class="source-line-no">545</span><span id="line-545"> }</span> |
| <span class="source-line-no">546</span><span id="line-546"> }</span> |
| <span class="source-line-no">547</span><span id="line-547"> assertTrue(usedBlocksFound);</span> |
| <span class="source-line-no">548</span><span id="line-548"> // the number of blocks referred</span> |
| <span class="source-line-no">549</span><span id="line-549"> assertEquals(3, noOfBlocksWithRef);</span> |
| <span class="source-line-no">550</span><span id="line-550"> CustomInnerRegionObserver.getCdl().get().countDown();</span> |
| <span class="source-line-no">551</span><span id="line-551"> for (GetThread thread : getThreads) {</span> |
| <span class="source-line-no">552</span><span id="line-552"> thread.join();</span> |
| <span class="source-line-no">553</span><span id="line-553"> }</span> |
| <span class="source-line-no">554</span><span id="line-554"> // Verify whether the gets have returned the blocks that it had</span> |
| <span class="source-line-no">555</span><span id="line-555"> CustomInnerRegionObserver.waitForGets.set(true);</span> |
| <span class="source-line-no">556</span><span id="line-556"> // giving some time for the block to be decremented</span> |
| <span class="source-line-no">557</span><span id="line-557"> checkForBlockEviction(cache, true, false);</span> |
| <span class="source-line-no">558</span><span id="line-558"> getLatch.countDown();</span> |
| <span class="source-line-no">559</span><span id="line-559"> System.out.println("Gets should have returned the bloks");</span> |
| <span class="source-line-no">560</span><span id="line-560"> } finally {</span> |
| <span class="source-line-no">561</span><span id="line-561"> if (table != null) {</span> |
| <span class="source-line-no">562</span><span id="line-562"> table.close();</span> |
| <span class="source-line-no">563</span><span id="line-563"> }</span> |
| <span class="source-line-no">564</span><span id="line-564"> }</span> |
| <span class="source-line-no">565</span><span id="line-565"> }</span> |
| <span class="source-line-no">566</span><span id="line-566"></span> |
| <span class="source-line-no">567</span><span id="line-567"> @Test</span> |
| <span class="source-line-no">568</span><span id="line-568"> public void testBlockRefCountAfterSplits() throws IOException, InterruptedException {</span> |
| <span class="source-line-no">569</span><span id="line-569"> Table table = null;</span> |
| <span class="source-line-no">570</span><span id="line-570"> try {</span> |
| <span class="source-line-no">571</span><span id="line-571"> final TableName tableName = TableName.valueOf(name.getMethodName());</span> |
| <span class="source-line-no">572</span><span id="line-572"> TableDescriptor desc = TEST_UTIL.createTableDescriptor(tableName);</span> |
| <span class="source-line-no">573</span><span id="line-573"> // This test expects rpc refcount of cached data blocks to be 0 after split. After split,</span> |
| <span class="source-line-no">574</span><span id="line-574"> // two daughter regions are opened and a compaction is scheduled to get rid of reference</span> |
| <span class="source-line-no">575</span><span id="line-575"> // of the parent region hfiles. Compaction will increase refcount of cached data blocks by 1.</span> |
| <span class="source-line-no">576</span><span id="line-576"> // It is flakey since compaction can kick in anytime. To solve this issue, table is created</span> |
| <span class="source-line-no">577</span><span id="line-577"> // with compaction disabled.</span> |
| <span class="source-line-no">578</span><span id="line-578"> table = TEST_UTIL.createTable(</span> |
| <span class="source-line-no">579</span><span id="line-579"> TableDescriptorBuilder.newBuilder(desc).setCompactionEnabled(false).build(), FAMILIES_1,</span> |
| <span class="source-line-no">580</span><span id="line-580"> null, BloomType.ROW, 1024, null);</span> |
| <span class="source-line-no">581</span><span id="line-581"> // get the block cache and region</span> |
| <span class="source-line-no">582</span><span id="line-582"> RegionLocator locator = TEST_UTIL.getConnection().getRegionLocator(tableName);</span> |
| <span class="source-line-no">583</span><span id="line-583"> String regionName = locator.getAllRegionLocations().get(0).getRegion().getEncodedName();</span> |
| <span class="source-line-no">584</span><span id="line-584"> HRegion region = TEST_UTIL.getRSForFirstRegionInTable(tableName).getRegion(regionName);</span> |
| <span class="source-line-no">585</span><span id="line-585"> HStore store = region.getStores().iterator().next();</span> |
| <span class="source-line-no">586</span><span id="line-586"> CacheConfig cacheConf = store.getCacheConfig();</span> |
| <span class="source-line-no">587</span><span id="line-587"> cacheConf.setEvictOnClose(true);</span> |
| <span class="source-line-no">588</span><span id="line-588"> BlockCache cache = cacheConf.getBlockCache().get();</span> |
| <span class="source-line-no">589</span><span id="line-589"></span> |
| <span class="source-line-no">590</span><span id="line-590"> Put put = new Put(ROW);</span> |
| <span class="source-line-no">591</span><span id="line-591"> put.addColumn(FAMILY, QUALIFIER, data);</span> |
| <span class="source-line-no">592</span><span id="line-592"> table.put(put);</span> |
| <span class="source-line-no">593</span><span id="line-593"> region.flush(true);</span> |
| <span class="source-line-no">594</span><span id="line-594"> put = new Put(ROW1);</span> |
| <span class="source-line-no">595</span><span id="line-595"> put.addColumn(FAMILY, QUALIFIER, data);</span> |
| <span class="source-line-no">596</span><span id="line-596"> table.put(put);</span> |
| <span class="source-line-no">597</span><span id="line-597"> region.flush(true);</span> |
| <span class="source-line-no">598</span><span id="line-598"> byte[] QUALIFIER2 = Bytes.add(QUALIFIER, QUALIFIER);</span> |
| <span class="source-line-no">599</span><span id="line-599"> put = new Put(ROW2);</span> |
| <span class="source-line-no">600</span><span id="line-600"> put.addColumn(FAMILY, QUALIFIER2, data2);</span> |
| <span class="source-line-no">601</span><span id="line-601"> table.put(put);</span> |
| <span class="source-line-no">602</span><span id="line-602"> put = new Put(ROW3);</span> |
| <span class="source-line-no">603</span><span id="line-603"> put.addColumn(FAMILY, QUALIFIER2, data2);</span> |
| <span class="source-line-no">604</span><span id="line-604"> table.put(put);</span> |
| <span class="source-line-no">605</span><span id="line-605"> region.flush(true);</span> |
| <span class="source-line-no">606</span><span id="line-606"> ServerName rs = Iterables.getOnlyElement(TEST_UTIL.getAdmin().getRegionServers());</span> |
| <span class="source-line-no">607</span><span id="line-607"> int regionCount = TEST_UTIL.getAdmin().getRegions(rs).size();</span> |
| <span class="source-line-no">608</span><span id="line-608"> LOG.info("About to SPLIT on {} {}, count={}", Bytes.toString(ROW1), region.getRegionInfo(),</span> |
| <span class="source-line-no">609</span><span id="line-609"> regionCount);</span> |
| <span class="source-line-no">610</span><span id="line-610"> TEST_UTIL.getAdmin().split(tableName, ROW1);</span> |
| <span class="source-line-no">611</span><span id="line-611"> // Wait for splits</span> |
| <span class="source-line-no">612</span><span id="line-612"> TEST_UTIL.waitFor(60000, () -> TEST_UTIL.getAdmin().getRegions(rs).size() > regionCount);</span> |
| <span class="source-line-no">613</span><span id="line-613"> region.compact(true);</span> |
| <span class="source-line-no">614</span><span id="line-614"> List<HRegion> regions = TEST_UTIL.getMiniHBaseCluster().getRegionServer(rs).getRegions();</span> |
| <span class="source-line-no">615</span><span id="line-615"> for (HRegion r : regions) {</span> |
| <span class="source-line-no">616</span><span id="line-616"> LOG.info("" + r.getCompactionState());</span> |
| <span class="source-line-no">617</span><span id="line-617"> TEST_UTIL.waitFor(30000, () -> r.getCompactionState().equals(CompactionState.NONE));</span> |
| <span class="source-line-no">618</span><span id="line-618"> }</span> |
| <span class="source-line-no">619</span><span id="line-619"> LOG.info("Split finished, is region closed {} {}", region.isClosed(), cache);</span> |
| <span class="source-line-no">620</span><span id="line-620"> Iterator<CachedBlock> iterator = cache.iterator();</span> |
| <span class="source-line-no">621</span><span id="line-621"> // Though the split had created the HalfStorefileReader - the firstkey and lastkey scanners</span> |
| <span class="source-line-no">622</span><span id="line-622"> // should be closed inorder to return those blocks</span> |
| <span class="source-line-no">623</span><span id="line-623"> iterateBlockCache(cache, iterator);</span> |
| <span class="source-line-no">624</span><span id="line-624"> } finally {</span> |
| <span class="source-line-no">625</span><span id="line-625"> if (table != null) {</span> |
| <span class="source-line-no">626</span><span id="line-626"> table.close();</span> |
| <span class="source-line-no">627</span><span id="line-627"> }</span> |
| <span class="source-line-no">628</span><span id="line-628"> }</span> |
| <span class="source-line-no">629</span><span id="line-629"> }</span> |
| <span class="source-line-no">630</span><span id="line-630"></span> |
| <span class="source-line-no">631</span><span id="line-631"> @Test</span> |
| <span class="source-line-no">632</span><span id="line-632"> public void testMultiGets() throws IOException, InterruptedException {</span> |
| <span class="source-line-no">633</span><span id="line-633"> Table table = null;</span> |
| <span class="source-line-no">634</span><span id="line-634"> try {</span> |
| <span class="source-line-no">635</span><span id="line-635"> latch = new CountDownLatch(2);</span> |
| <span class="source-line-no">636</span><span id="line-636"> // Check if get() returns blocks on its close() itself</span> |
| <span class="source-line-no">637</span><span id="line-637"> getLatch = new CountDownLatch(1);</span> |
| <span class="source-line-no">638</span><span id="line-638"> final TableName tableName = TableName.valueOf(name.getMethodName());</span> |
| <span class="source-line-no">639</span><span id="line-639"> // Create KV that will give you two blocks</span> |
| <span class="source-line-no">640</span><span id="line-640"> // Create a table with block size as 1024</span> |
| <span class="source-line-no">641</span><span id="line-641"> table = TEST_UTIL.createTable(tableName, FAMILIES_1, 1, 1024,</span> |
| <span class="source-line-no">642</span><span id="line-642"> CustomInnerRegionObserver.class.getName());</span> |
| <span class="source-line-no">643</span><span id="line-643"> // get the block cache and region</span> |
| <span class="source-line-no">644</span><span id="line-644"> RegionLocator locator = TEST_UTIL.getConnection().getRegionLocator(tableName);</span> |
| <span class="source-line-no">645</span><span id="line-645"> String regionName = locator.getAllRegionLocations().get(0).getRegion().getEncodedName();</span> |
| <span class="source-line-no">646</span><span id="line-646"> HRegion region = TEST_UTIL.getRSForFirstRegionInTable(tableName).getRegion(regionName);</span> |
| <span class="source-line-no">647</span><span id="line-647"> HStore store = region.getStores().iterator().next();</span> |
| <span class="source-line-no">648</span><span id="line-648"> CacheConfig cacheConf = store.getCacheConfig();</span> |
| <span class="source-line-no">649</span><span id="line-649"> cacheConf.setCacheDataOnWrite(true);</span> |
| <span class="source-line-no">650</span><span id="line-650"> cacheConf.setEvictOnClose(true);</span> |
| <span class="source-line-no">651</span><span id="line-651"> BlockCache cache = cacheConf.getBlockCache().get();</span> |
| <span class="source-line-no">652</span><span id="line-652"></span> |
| <span class="source-line-no">653</span><span id="line-653"> Put put = new Put(ROW);</span> |
| <span class="source-line-no">654</span><span id="line-654"> put.addColumn(FAMILY, QUALIFIER, data);</span> |
| <span class="source-line-no">655</span><span id="line-655"> table.put(put);</span> |
| <span class="source-line-no">656</span><span id="line-656"> region.flush(true);</span> |
| <span class="source-line-no">657</span><span id="line-657"> put = new Put(ROW1);</span> |
| <span class="source-line-no">658</span><span id="line-658"> put.addColumn(FAMILY, QUALIFIER, data);</span> |
| <span class="source-line-no">659</span><span id="line-659"> table.put(put);</span> |
| <span class="source-line-no">660</span><span id="line-660"> region.flush(true);</span> |
| <span class="source-line-no">661</span><span id="line-661"> byte[] QUALIFIER2 = Bytes.add(QUALIFIER, QUALIFIER);</span> |
| <span class="source-line-no">662</span><span id="line-662"> put = new Put(ROW);</span> |
| <span class="source-line-no">663</span><span id="line-663"> put.addColumn(FAMILY, QUALIFIER2, data2);</span> |
| <span class="source-line-no">664</span><span id="line-664"> table.put(put);</span> |
| <span class="source-line-no">665</span><span id="line-665"> region.flush(true);</span> |
| <span class="source-line-no">666</span><span id="line-666"> // flush the data</span> |
| <span class="source-line-no">667</span><span id="line-667"> System.out.println("Flushing cache");</span> |
| <span class="source-line-no">668</span><span id="line-668"> // Should create one Hfile with 2 blocks</span> |
| <span class="source-line-no">669</span><span id="line-669"> CustomInnerRegionObserver.waitForGets.set(true);</span> |
| <span class="source-line-no">670</span><span id="line-670"> // Create three sets of gets</span> |
| <span class="source-line-no">671</span><span id="line-671"> MultiGetThread[] getThreads = initiateMultiGet(table);</span> |
| <span class="source-line-no">672</span><span id="line-672"> Thread.sleep(200);</span> |
| <span class="source-line-no">673</span><span id="line-673"> int refCount;</span> |
| <span class="source-line-no">674</span><span id="line-674"> Iterator<CachedBlock> iterator = cache.iterator();</span> |
| <span class="source-line-no">675</span><span id="line-675"> boolean foundNonZeroBlock = false;</span> |
| <span class="source-line-no">676</span><span id="line-676"> while (iterator.hasNext()) {</span> |
| <span class="source-line-no">677</span><span id="line-677"> CachedBlock next = iterator.next();</span> |
| <span class="source-line-no">678</span><span id="line-678"> BlockCacheKey cacheKey = new BlockCacheKey(next.getFilename(), next.getOffset());</span> |
| <span class="source-line-no">679</span><span id="line-679"> if (cache instanceof BucketCache) {</span> |
| <span class="source-line-no">680</span><span id="line-680"> refCount = ((BucketCache) cache).getRpcRefCount(cacheKey);</span> |
| <span class="source-line-no">681</span><span id="line-681"> } else if (cache instanceof CombinedBlockCache) {</span> |
| <span class="source-line-no">682</span><span id="line-682"> refCount = ((CombinedBlockCache) cache).getRpcRefCount(cacheKey);</span> |
| <span class="source-line-no">683</span><span id="line-683"> } else {</span> |
| <span class="source-line-no">684</span><span id="line-684"> continue;</span> |
| <span class="source-line-no">685</span><span id="line-685"> }</span> |
| <span class="source-line-no">686</span><span id="line-686"> if (refCount != 0) {</span> |
| <span class="source-line-no">687</span><span id="line-687"> assertEquals(NO_OF_THREADS, refCount);</span> |
| <span class="source-line-no">688</span><span id="line-688"> foundNonZeroBlock = true;</span> |
| <span class="source-line-no">689</span><span id="line-689"> }</span> |
| <span class="source-line-no">690</span><span id="line-690"> }</span> |
| <span class="source-line-no">691</span><span id="line-691"> assertTrue("Should have found nonzero ref count block", foundNonZeroBlock);</span> |
| <span class="source-line-no">692</span><span id="line-692"> CustomInnerRegionObserver.getCdl().get().countDown();</span> |
| <span class="source-line-no">693</span><span id="line-693"> CustomInnerRegionObserver.getCdl().get().countDown();</span> |
| <span class="source-line-no">694</span><span id="line-694"> for (MultiGetThread thread : getThreads) {</span> |
| <span class="source-line-no">695</span><span id="line-695"> thread.join();</span> |
| <span class="source-line-no">696</span><span id="line-696"> }</span> |
| <span class="source-line-no">697</span><span id="line-697"> // Verify whether the gets have returned the blocks that it had</span> |
| <span class="source-line-no">698</span><span id="line-698"> CustomInnerRegionObserver.waitForGets.set(true);</span> |
| <span class="source-line-no">699</span><span id="line-699"> // giving some time for the block to be decremented</span> |
| <span class="source-line-no">700</span><span id="line-700"> iterateBlockCache(cache, iterator);</span> |
| <span class="source-line-no">701</span><span id="line-701"> getLatch.countDown();</span> |
| <span class="source-line-no">702</span><span id="line-702"> System.out.println("Gets should have returned the bloks");</span> |
| <span class="source-line-no">703</span><span id="line-703"> } finally {</span> |
| <span class="source-line-no">704</span><span id="line-704"> if (table != null) {</span> |
| <span class="source-line-no">705</span><span id="line-705"> table.close();</span> |
| <span class="source-line-no">706</span><span id="line-706"> }</span> |
| <span class="source-line-no">707</span><span id="line-707"> }</span> |
| <span class="source-line-no">708</span><span id="line-708"> }</span> |
| <span class="source-line-no">709</span><span id="line-709"></span> |
| <span class="source-line-no">710</span><span id="line-710"> @Test</span> |
| <span class="source-line-no">711</span><span id="line-711"> public void testScanWithMultipleColumnFamilies() throws IOException, InterruptedException {</span> |
| <span class="source-line-no">712</span><span id="line-712"> Table table = null;</span> |
| <span class="source-line-no">713</span><span id="line-713"> try {</span> |
| <span class="source-line-no">714</span><span id="line-714"> latch = new CountDownLatch(1);</span> |
| <span class="source-line-no">715</span><span id="line-715"> // Check if get() returns blocks on its close() itself</span> |
| <span class="source-line-no">716</span><span id="line-716"> final TableName tableName = TableName.valueOf(name.getMethodName());</span> |
| <span class="source-line-no">717</span><span id="line-717"> // Create KV that will give you two blocks</span> |
| <span class="source-line-no">718</span><span id="line-718"> // Create a table with block size as 1024</span> |
| <span class="source-line-no">719</span><span id="line-719"> byte[][] fams = new byte[10][];</span> |
| <span class="source-line-no">720</span><span id="line-720"> fams[0] = FAMILY;</span> |
| <span class="source-line-no">721</span><span id="line-721"> for (int i = 1; i < 10; i++) {</span> |
| <span class="source-line-no">722</span><span id="line-722"> fams[i] = (Bytes.toBytes("testFamily" + i));</span> |
| <span class="source-line-no">723</span><span id="line-723"> }</span> |
| <span class="source-line-no">724</span><span id="line-724"> table =</span> |
| <span class="source-line-no">725</span><span id="line-725"> TEST_UTIL.createTable(tableName, fams, 1, 1024, CustomInnerRegionObserver.class.getName());</span> |
| <span class="source-line-no">726</span><span id="line-726"> // get the block cache and region</span> |
| <span class="source-line-no">727</span><span id="line-727"> RegionLocator locator = TEST_UTIL.getConnection().getRegionLocator(tableName);</span> |
| <span class="source-line-no">728</span><span id="line-728"> String regionName = locator.getAllRegionLocations().get(0).getRegion().getEncodedName();</span> |
| <span class="source-line-no">729</span><span id="line-729"> HRegion region = TEST_UTIL.getRSForFirstRegionInTable(tableName).getRegion(regionName);</span> |
| <span class="source-line-no">730</span><span id="line-730"> BlockCache cache = setCacheProperties(region);</span> |
| <span class="source-line-no">731</span><span id="line-731"></span> |
| <span class="source-line-no">732</span><span id="line-732"> Put put = new Put(ROW);</span> |
| <span class="source-line-no">733</span><span id="line-733"> put.addColumn(FAMILY, QUALIFIER, data);</span> |
| <span class="source-line-no">734</span><span id="line-734"> table.put(put);</span> |
| <span class="source-line-no">735</span><span id="line-735"> region.flush(true);</span> |
| <span class="source-line-no">736</span><span id="line-736"> put = new Put(ROW1);</span> |
| <span class="source-line-no">737</span><span id="line-737"> put.addColumn(FAMILY, QUALIFIER, data);</span> |
| <span class="source-line-no">738</span><span id="line-738"> table.put(put);</span> |
| <span class="source-line-no">739</span><span id="line-739"> region.flush(true);</span> |
| <span class="source-line-no">740</span><span id="line-740"> for (int i = 1; i < 10; i++) {</span> |
| <span class="source-line-no">741</span><span id="line-741"> put = new Put(ROW);</span> |
| <span class="source-line-no">742</span><span id="line-742"> put.addColumn(Bytes.toBytes("testFamily" + i), Bytes.toBytes("testQualifier" + i), data2);</span> |
| <span class="source-line-no">743</span><span id="line-743"> table.put(put);</span> |
| <span class="source-line-no">744</span><span id="line-744"> if (i % 2 == 0) {</span> |
| <span class="source-line-no">745</span><span id="line-745"> region.flush(true);</span> |
| <span class="source-line-no">746</span><span id="line-746"> }</span> |
| <span class="source-line-no">747</span><span id="line-747"> }</span> |
| <span class="source-line-no">748</span><span id="line-748"> region.flush(true);</span> |
| <span class="source-line-no">749</span><span id="line-749"> byte[] QUALIFIER2 = Bytes.add(QUALIFIER, QUALIFIER);</span> |
| <span class="source-line-no">750</span><span id="line-750"> put = new Put(ROW);</span> |
| <span class="source-line-no">751</span><span id="line-751"> put.addColumn(FAMILY, QUALIFIER2, data2);</span> |
| <span class="source-line-no">752</span><span id="line-752"> table.put(put);</span> |
| <span class="source-line-no">753</span><span id="line-753"> region.flush(true);</span> |
| <span class="source-line-no">754</span><span id="line-754"> // flush the data</span> |
| <span class="source-line-no">755</span><span id="line-755"> System.out.println("Flushing cache");</span> |
| <span class="source-line-no">756</span><span id="line-756"> // Should create one Hfile with 2 blocks</span> |
| <span class="source-line-no">757</span><span id="line-757"> // Create three sets of gets</span> |
| <span class="source-line-no">758</span><span id="line-758"> ScanThread[] scanThreads = initiateScan(table, true);</span> |
| <span class="source-line-no">759</span><span id="line-759"> Thread.sleep(200);</span> |
| <span class="source-line-no">760</span><span id="line-760"> Iterator<CachedBlock> iterator = cache.iterator();</span> |
| <span class="source-line-no">761</span><span id="line-761"> boolean usedBlocksFound = false;</span> |
| <span class="source-line-no">762</span><span id="line-762"> int refCount = 0;</span> |
| <span class="source-line-no">763</span><span id="line-763"> int noOfBlocksWithRef = 0;</span> |
| <span class="source-line-no">764</span><span id="line-764"> while (iterator.hasNext()) {</span> |
| <span class="source-line-no">765</span><span id="line-765"> CachedBlock next = iterator.next();</span> |
| <span class="source-line-no">766</span><span id="line-766"> BlockCacheKey cacheKey = new BlockCacheKey(next.getFilename(), next.getOffset());</span> |
| <span class="source-line-no">767</span><span id="line-767"> if (cache instanceof BucketCache) {</span> |
| <span class="source-line-no">768</span><span id="line-768"> refCount = ((BucketCache) cache).getRpcRefCount(cacheKey);</span> |
| <span class="source-line-no">769</span><span id="line-769"> } else if (cache instanceof CombinedBlockCache) {</span> |
| <span class="source-line-no">770</span><span id="line-770"> refCount = ((CombinedBlockCache) cache).getRpcRefCount(cacheKey);</span> |
| <span class="source-line-no">771</span><span id="line-771"> } else {</span> |
| <span class="source-line-no">772</span><span id="line-772"> continue;</span> |
| <span class="source-line-no">773</span><span id="line-773"> }</span> |
| <span class="source-line-no">774</span><span id="line-774"> if (refCount != 0) {</span> |
| <span class="source-line-no">775</span><span id="line-775"> // Blocks will be with count 3</span> |
| <span class="source-line-no">776</span><span id="line-776"> System.out.println("The refCount is " + refCount);</span> |
| <span class="source-line-no">777</span><span id="line-777"> assertEquals(NO_OF_THREADS, refCount);</span> |
| <span class="source-line-no">778</span><span id="line-778"> usedBlocksFound = true;</span> |
| <span class="source-line-no">779</span><span id="line-779"> noOfBlocksWithRef++;</span> |
| <span class="source-line-no">780</span><span id="line-780"> }</span> |
| <span class="source-line-no">781</span><span id="line-781"> }</span> |
| <span class="source-line-no">782</span><span id="line-782"> assertTrue(usedBlocksFound);</span> |
| <span class="source-line-no">783</span><span id="line-783"> // the number of blocks referred</span> |
| <span class="source-line-no">784</span><span id="line-784"> assertEquals(12, noOfBlocksWithRef);</span> |
| <span class="source-line-no">785</span><span id="line-785"> CustomInnerRegionObserver.getCdl().get().countDown();</span> |
| <span class="source-line-no">786</span><span id="line-786"> for (ScanThread thread : scanThreads) {</span> |
| <span class="source-line-no">787</span><span id="line-787"> thread.join();</span> |
| <span class="source-line-no">788</span><span id="line-788"> }</span> |
| <span class="source-line-no">789</span><span id="line-789"> // giving some time for the block to be decremented</span> |
| <span class="source-line-no">790</span><span id="line-790"> checkForBlockEviction(cache, true, false);</span> |
| <span class="source-line-no">791</span><span id="line-791"> } finally {</span> |
| <span class="source-line-no">792</span><span id="line-792"> if (table != null) {</span> |
| <span class="source-line-no">793</span><span id="line-793"> table.close();</span> |
| <span class="source-line-no">794</span><span id="line-794"> }</span> |
| <span class="source-line-no">795</span><span id="line-795"> }</span> |
| <span class="source-line-no">796</span><span id="line-796"> }</span> |
| <span class="source-line-no">797</span><span id="line-797"></span> |
| <span class="source-line-no">798</span><span id="line-798"> private BlockCache setCacheProperties(HRegion region) {</span> |
| <span class="source-line-no">799</span><span id="line-799"> Iterator<HStore> strItr = region.getStores().iterator();</span> |
| <span class="source-line-no">800</span><span id="line-800"> BlockCache cache = null;</span> |
| <span class="source-line-no">801</span><span id="line-801"> while (strItr.hasNext()) {</span> |
| <span class="source-line-no">802</span><span id="line-802"> HStore store = strItr.next();</span> |
| <span class="source-line-no">803</span><span id="line-803"> CacheConfig cacheConf = store.getCacheConfig();</span> |
| <span class="source-line-no">804</span><span id="line-804"> cacheConf.setCacheDataOnWrite(true);</span> |
| <span class="source-line-no">805</span><span id="line-805"> cacheConf.setEvictOnClose(true);</span> |
| <span class="source-line-no">806</span><span id="line-806"> // Use the last one</span> |
| <span class="source-line-no">807</span><span id="line-807"> cache = cacheConf.getBlockCache().get();</span> |
| <span class="source-line-no">808</span><span id="line-808"> }</span> |
| <span class="source-line-no">809</span><span id="line-809"> return cache;</span> |
| <span class="source-line-no">810</span><span id="line-810"> }</span> |
| <span class="source-line-no">811</span><span id="line-811"></span> |
| <span class="source-line-no">812</span><span id="line-812"> @Test</span> |
| <span class="source-line-no">813</span><span id="line-813"> public void testParallelGetsAndScanWithWrappedRegionScanner()</span> |
| <span class="source-line-no">814</span><span id="line-814"> throws IOException, InterruptedException {</span> |
| <span class="source-line-no">815</span><span id="line-815"> Table table = null;</span> |
| <span class="source-line-no">816</span><span id="line-816"> try {</span> |
| <span class="source-line-no">817</span><span id="line-817"> latch = new CountDownLatch(2);</span> |
| <span class="source-line-no">818</span><span id="line-818"> // Check if get() returns blocks on its close() itself</span> |
| <span class="source-line-no">819</span><span id="line-819"> getLatch = new CountDownLatch(1);</span> |
| <span class="source-line-no">820</span><span id="line-820"> final TableName tableName = TableName.valueOf(name.getMethodName());</span> |
| <span class="source-line-no">821</span><span id="line-821"> // Create KV that will give you two blocks</span> |
| <span class="source-line-no">822</span><span id="line-822"> // Create a table with block size as 1024</span> |
| <span class="source-line-no">823</span><span id="line-823"> table = TEST_UTIL.createTable(tableName, FAMILIES_1, 1, 1024,</span> |
| <span class="source-line-no">824</span><span id="line-824"> CustomInnerRegionObserverWrapper.class.getName());</span> |
| <span class="source-line-no">825</span><span id="line-825"> // get the block cache and region</span> |
| <span class="source-line-no">826</span><span id="line-826"> RegionLocator locator = TEST_UTIL.getConnection().getRegionLocator(tableName);</span> |
| <span class="source-line-no">827</span><span id="line-827"> String regionName = locator.getAllRegionLocations().get(0).getRegion().getEncodedName();</span> |
| <span class="source-line-no">828</span><span id="line-828"> HRegion region = TEST_UTIL.getRSForFirstRegionInTable(tableName).getRegion(regionName);</span> |
| <span class="source-line-no">829</span><span id="line-829"> HStore store = region.getStores().iterator().next();</span> |
| <span class="source-line-no">830</span><span id="line-830"> CacheConfig cacheConf = store.getCacheConfig();</span> |
| <span class="source-line-no">831</span><span id="line-831"> cacheConf.setCacheDataOnWrite(true);</span> |
| <span class="source-line-no">832</span><span id="line-832"> cacheConf.setEvictOnClose(true);</span> |
| <span class="source-line-no">833</span><span id="line-833"> BlockCache cache = cacheConf.getBlockCache().get();</span> |
| <span class="source-line-no">834</span><span id="line-834"></span> |
| <span class="source-line-no">835</span><span id="line-835"> // insert data. 2 Rows are added</span> |
| <span class="source-line-no">836</span><span id="line-836"> insertData(table);</span> |
| <span class="source-line-no">837</span><span id="line-837"> // flush the data</span> |
| <span class="source-line-no">838</span><span id="line-838"> System.out.println("Flushing cache");</span> |
| <span class="source-line-no">839</span><span id="line-839"> // Should create one Hfile with 2 blocks</span> |
| <span class="source-line-no">840</span><span id="line-840"> region.flush(true);</span> |
| <span class="source-line-no">841</span><span id="line-841"> // CustomInnerRegionObserver.sleepTime.set(5000);</span> |
| <span class="source-line-no">842</span><span id="line-842"> // Create three sets of scan</span> |
| <span class="source-line-no">843</span><span id="line-843"> CustomInnerRegionObserver.waitForGets.set(true);</span> |
| <span class="source-line-no">844</span><span id="line-844"> ScanThread[] scanThreads = initiateScan(table, false);</span> |
| <span class="source-line-no">845</span><span id="line-845"> // Create three sets of gets</span> |
| <span class="source-line-no">846</span><span id="line-846"> GetThread[] getThreads = initiateGet(table, false, false);</span> |
| <span class="source-line-no">847</span><span id="line-847"> // The block would have been decremented for the scan case as it was</span> |
| <span class="source-line-no">848</span><span id="line-848"> // wrapped</span> |
| <span class="source-line-no">849</span><span id="line-849"> // before even the postNext hook gets executed.</span> |
| <span class="source-line-no">850</span><span id="line-850"> // giving some time for the block to be decremented</span> |
| <span class="source-line-no">851</span><span id="line-851"> Thread.sleep(100);</span> |
| <span class="source-line-no">852</span><span id="line-852"> CustomInnerRegionObserver.waitForGets.set(false);</span> |
| <span class="source-line-no">853</span><span id="line-853"> checkForBlockEviction(cache, false, false);</span> |
| <span class="source-line-no">854</span><span id="line-854"> // countdown the latch</span> |
| <span class="source-line-no">855</span><span id="line-855"> CustomInnerRegionObserver.getCdl().get().countDown();</span> |
| <span class="source-line-no">856</span><span id="line-856"> for (GetThread thread : getThreads) {</span> |
| <span class="source-line-no">857</span><span id="line-857"> thread.join();</span> |
| <span class="source-line-no">858</span><span id="line-858"> }</span> |
| <span class="source-line-no">859</span><span id="line-859"> getLatch.countDown();</span> |
| <span class="source-line-no">860</span><span id="line-860"> for (ScanThread thread : scanThreads) {</span> |
| <span class="source-line-no">861</span><span id="line-861"> thread.join();</span> |
| <span class="source-line-no">862</span><span id="line-862"> }</span> |
| <span class="source-line-no">863</span><span id="line-863"> } finally {</span> |
| <span class="source-line-no">864</span><span id="line-864"> if (table != null) {</span> |
| <span class="source-line-no">865</span><span id="line-865"> table.close();</span> |
| <span class="source-line-no">866</span><span id="line-866"> }</span> |
| <span class="source-line-no">867</span><span id="line-867"> }</span> |
| <span class="source-line-no">868</span><span id="line-868"> }</span> |
| <span class="source-line-no">869</span><span id="line-869"></span> |
| <span class="source-line-no">870</span><span id="line-870"> @Test</span> |
| <span class="source-line-no">871</span><span id="line-871"> public void testScanWithCompaction() throws IOException, InterruptedException {</span> |
| <span class="source-line-no">872</span><span id="line-872"> testScanWithCompactionInternals(name.getMethodName(), false);</span> |
| <span class="source-line-no">873</span><span id="line-873"> }</span> |
| <span class="source-line-no">874</span><span id="line-874"></span> |
| <span class="source-line-no">875</span><span id="line-875"> @Test</span> |
| <span class="source-line-no">876</span><span id="line-876"> public void testReverseScanWithCompaction() throws IOException, InterruptedException {</span> |
| <span class="source-line-no">877</span><span id="line-877"> testScanWithCompactionInternals(name.getMethodName(), true);</span> |
| <span class="source-line-no">878</span><span id="line-878"> }</span> |
| <span class="source-line-no">879</span><span id="line-879"></span> |
| <span class="source-line-no">880</span><span id="line-880"> private void testScanWithCompactionInternals(String tableNameStr, boolean reversed)</span> |
| <span class="source-line-no">881</span><span id="line-881"> throws IOException, InterruptedException {</span> |
| <span class="source-line-no">882</span><span id="line-882"> Table table = null;</span> |
| <span class="source-line-no">883</span><span id="line-883"> try {</span> |
| <span class="source-line-no">884</span><span id="line-884"> latch = new CountDownLatch(1);</span> |
| <span class="source-line-no">885</span><span id="line-885"> compactionLatch = new CountDownLatch(1);</span> |
| <span class="source-line-no">886</span><span id="line-886"> TableName tableName = TableName.valueOf(tableNameStr);</span> |
| <span class="source-line-no">887</span><span id="line-887"> // Create a table with block size as 1024</span> |
| <span class="source-line-no">888</span><span id="line-888"> table = TEST_UTIL.createTable(tableName, FAMILIES_1, 1, 1024,</span> |
| <span class="source-line-no">889</span><span id="line-889"> CustomInnerRegionObserverWrapper.class.getName());</span> |
| <span class="source-line-no">890</span><span id="line-890"> // get the block cache and region</span> |
| <span class="source-line-no">891</span><span id="line-891"> RegionLocator locator = TEST_UTIL.getConnection().getRegionLocator(tableName);</span> |
| <span class="source-line-no">892</span><span id="line-892"> String regionName = locator.getAllRegionLocations().get(0).getRegion().getEncodedName();</span> |
| <span class="source-line-no">893</span><span id="line-893"> HRegion region = TEST_UTIL.getRSForFirstRegionInTable(tableName).getRegion(regionName);</span> |
| <span class="source-line-no">894</span><span id="line-894"> HStore store = region.getStores().iterator().next();</span> |
| <span class="source-line-no">895</span><span id="line-895"> CacheConfig cacheConf = store.getCacheConfig();</span> |
| <span class="source-line-no">896</span><span id="line-896"> cacheConf.setCacheDataOnWrite(true);</span> |
| <span class="source-line-no">897</span><span id="line-897"> cacheConf.setEvictOnClose(true);</span> |
| <span class="source-line-no">898</span><span id="line-898"> BlockCache cache = cacheConf.getBlockCache().get();</span> |
| <span class="source-line-no">899</span><span id="line-899"></span> |
| <span class="source-line-no">900</span><span id="line-900"> // insert data. 2 Rows are added</span> |
| <span class="source-line-no">901</span><span id="line-901"> Put put = new Put(ROW);</span> |
| <span class="source-line-no">902</span><span id="line-902"> put.addColumn(FAMILY, QUALIFIER, data);</span> |
| <span class="source-line-no">903</span><span id="line-903"> table.put(put);</span> |
| <span class="source-line-no">904</span><span id="line-904"> put = new Put(ROW1);</span> |
| <span class="source-line-no">905</span><span id="line-905"> put.addColumn(FAMILY, QUALIFIER, data);</span> |
| <span class="source-line-no">906</span><span id="line-906"> table.put(put);</span> |
| <span class="source-line-no">907</span><span id="line-907"> assertTrue(Bytes.equals(table.get(new Get(ROW)).value(), data));</span> |
| <span class="source-line-no">908</span><span id="line-908"> // Should create one Hfile with 2 blocks</span> |
| <span class="source-line-no">909</span><span id="line-909"> region.flush(true);</span> |
| <span class="source-line-no">910</span><span id="line-910"> // read the data and expect same blocks, one new hit, no misses</span> |
| <span class="source-line-no">911</span><span id="line-911"> int refCount = 0;</span> |
| <span class="source-line-no">912</span><span id="line-912"> // Check how this miss is happening</span> |
| <span class="source-line-no">913</span><span id="line-913"> // insert a second column, read the row, no new blocks, 3 new hits</span> |
| <span class="source-line-no">914</span><span id="line-914"> byte[] QUALIFIER2 = Bytes.add(QUALIFIER, QUALIFIER);</span> |
| <span class="source-line-no">915</span><span id="line-915"> byte[] data2 = Bytes.add(data, data);</span> |
| <span class="source-line-no">916</span><span id="line-916"> put = new Put(ROW);</span> |
| <span class="source-line-no">917</span><span id="line-917"> put.addColumn(FAMILY, QUALIFIER2, data2);</span> |
| <span class="source-line-no">918</span><span id="line-918"> table.put(put);</span> |
| <span class="source-line-no">919</span><span id="line-919"> // flush, one new block</span> |
| <span class="source-line-no">920</span><span id="line-920"> System.out.println("Flushing cache");</span> |
| <span class="source-line-no">921</span><span id="line-921"> region.flush(true);</span> |
| <span class="source-line-no">922</span><span id="line-922"> Iterator<CachedBlock> iterator = cache.iterator();</span> |
| <span class="source-line-no">923</span><span id="line-923"> iterateBlockCache(cache, iterator);</span> |
| <span class="source-line-no">924</span><span id="line-924"> // Create three sets of scan</span> |
| <span class="source-line-no">925</span><span id="line-925"> ScanThread[] scanThreads = initiateScan(table, reversed);</span> |
| <span class="source-line-no">926</span><span id="line-926"> Thread.sleep(100);</span> |
| <span class="source-line-no">927</span><span id="line-927"> iterator = cache.iterator();</span> |
| <span class="source-line-no">928</span><span id="line-928"> boolean usedBlocksFound = false;</span> |
| <span class="source-line-no">929</span><span id="line-929"> while (iterator.hasNext()) {</span> |
| <span class="source-line-no">930</span><span id="line-930"> CachedBlock next = iterator.next();</span> |
| <span class="source-line-no">931</span><span id="line-931"> BlockCacheKey cacheKey = new BlockCacheKey(next.getFilename(), next.getOffset());</span> |
| <span class="source-line-no">932</span><span id="line-932"> if (cache instanceof BucketCache) {</span> |
| <span class="source-line-no">933</span><span id="line-933"> refCount = ((BucketCache) cache).getRpcRefCount(cacheKey);</span> |
| <span class="source-line-no">934</span><span id="line-934"> } else if (cache instanceof CombinedBlockCache) {</span> |
| <span class="source-line-no">935</span><span id="line-935"> refCount = ((CombinedBlockCache) cache).getRpcRefCount(cacheKey);</span> |
| <span class="source-line-no">936</span><span id="line-936"> } else {</span> |
| <span class="source-line-no">937</span><span id="line-937"> continue;</span> |
| <span class="source-line-no">938</span><span id="line-938"> }</span> |
| <span class="source-line-no">939</span><span id="line-939"> if (refCount != 0) {</span> |
| <span class="source-line-no">940</span><span id="line-940"> // Blocks will be with count 3</span> |
| <span class="source-line-no">941</span><span id="line-941"> assertEquals(NO_OF_THREADS, refCount);</span> |
| <span class="source-line-no">942</span><span id="line-942"> usedBlocksFound = true;</span> |
| <span class="source-line-no">943</span><span id="line-943"> }</span> |
| <span class="source-line-no">944</span><span id="line-944"> }</span> |
| <span class="source-line-no">945</span><span id="line-945"> assertTrue("Blocks with non zero ref count should be found ", usedBlocksFound);</span> |
| <span class="source-line-no">946</span><span id="line-946"> usedBlocksFound = false;</span> |
| <span class="source-line-no">947</span><span id="line-947"> System.out.println("Compacting");</span> |
| <span class="source-line-no">948</span><span id="line-948"> assertEquals(2, store.getStorefilesCount());</span> |
| <span class="source-line-no">949</span><span id="line-949"> store.triggerMajorCompaction();</span> |
| <span class="source-line-no">950</span><span id="line-950"> region.compact(true);</span> |
| <span class="source-line-no">951</span><span id="line-951"> waitForStoreFileCount(store, 1, 10000); // wait 10 seconds max</span> |
| <span class="source-line-no">952</span><span id="line-952"> assertEquals(1, store.getStorefilesCount());</span> |
| <span class="source-line-no">953</span><span id="line-953"> // Even after compaction is done we will have some blocks that cannot</span> |
| <span class="source-line-no">954</span><span id="line-954"> // be evicted this is because the scan is still referencing them</span> |
| <span class="source-line-no">955</span><span id="line-955"> iterator = cache.iterator();</span> |
| <span class="source-line-no">956</span><span id="line-956"> while (iterator.hasNext()) {</span> |
| <span class="source-line-no">957</span><span id="line-957"> CachedBlock next = iterator.next();</span> |
| <span class="source-line-no">958</span><span id="line-958"> BlockCacheKey cacheKey = new BlockCacheKey(next.getFilename(), next.getOffset());</span> |
| <span class="source-line-no">959</span><span id="line-959"> if (cache instanceof BucketCache) {</span> |
| <span class="source-line-no">960</span><span id="line-960"> refCount = ((BucketCache) cache).getRpcRefCount(cacheKey);</span> |
| <span class="source-line-no">961</span><span id="line-961"> } else if (cache instanceof CombinedBlockCache) {</span> |
| <span class="source-line-no">962</span><span id="line-962"> refCount = ((CombinedBlockCache) cache).getRpcRefCount(cacheKey);</span> |
| <span class="source-line-no">963</span><span id="line-963"> } else {</span> |
| <span class="source-line-no">964</span><span id="line-964"> continue;</span> |
| <span class="source-line-no">965</span><span id="line-965"> }</span> |
| <span class="source-line-no">966</span><span id="line-966"> if (refCount != 0) {</span> |
| <span class="source-line-no">967</span><span id="line-967"> // Blocks will be with count 3 as they are not yet cleared</span> |
| <span class="source-line-no">968</span><span id="line-968"> assertEquals(NO_OF_THREADS, refCount);</span> |
| <span class="source-line-no">969</span><span id="line-969"> usedBlocksFound = true;</span> |
| <span class="source-line-no">970</span><span id="line-970"> }</span> |
| <span class="source-line-no">971</span><span id="line-971"> }</span> |
| <span class="source-line-no">972</span><span id="line-972"> assertTrue("Blocks with non zero ref count should be found ", usedBlocksFound);</span> |
| <span class="source-line-no">973</span><span id="line-973"> // Should not throw exception</span> |
| <span class="source-line-no">974</span><span id="line-974"> compactionLatch.countDown();</span> |
| <span class="source-line-no">975</span><span id="line-975"> latch.countDown();</span> |
| <span class="source-line-no">976</span><span id="line-976"> for (ScanThread thread : scanThreads) {</span> |
| <span class="source-line-no">977</span><span id="line-977"> thread.join();</span> |
| <span class="source-line-no">978</span><span id="line-978"> }</span> |
| <span class="source-line-no">979</span><span id="line-979"> // by this time all blocks should have been evicted</span> |
| <span class="source-line-no">980</span><span id="line-980"> iterator = cache.iterator();</span> |
| <span class="source-line-no">981</span><span id="line-981"> iterateBlockCache(cache, iterator);</span> |
| <span class="source-line-no">982</span><span id="line-982"> Result r = table.get(new Get(ROW));</span> |
| <span class="source-line-no">983</span><span id="line-983"> assertTrue(Bytes.equals(r.getValue(FAMILY, QUALIFIER), data));</span> |
| <span class="source-line-no">984</span><span id="line-984"> assertTrue(Bytes.equals(r.getValue(FAMILY, QUALIFIER2), data2));</span> |
| <span class="source-line-no">985</span><span id="line-985"> // The gets would be working on new blocks</span> |
| <span class="source-line-no">986</span><span id="line-986"> iterator = cache.iterator();</span> |
| <span class="source-line-no">987</span><span id="line-987"> iterateBlockCache(cache, iterator);</span> |
| <span class="source-line-no">988</span><span id="line-988"> } finally {</span> |
| <span class="source-line-no">989</span><span id="line-989"> if (table != null) {</span> |
| <span class="source-line-no">990</span><span id="line-990"> table.close();</span> |
| <span class="source-line-no">991</span><span id="line-991"> }</span> |
| <span class="source-line-no">992</span><span id="line-992"> }</span> |
| <span class="source-line-no">993</span><span id="line-993"> }</span> |
| <span class="source-line-no">994</span><span id="line-994"></span> |
| <span class="source-line-no">995</span><span id="line-995"> @Test</span> |
| <span class="source-line-no">996</span><span id="line-996"> public void testBlockEvictionAfterHBASE13082WithCompactionAndFlush()</span> |
| <span class="source-line-no">997</span><span id="line-997"> throws IOException, InterruptedException {</span> |
| <span class="source-line-no">998</span><span id="line-998"> // do flush and scan in parallel</span> |
| <span class="source-line-no">999</span><span id="line-999"> Table table = null;</span> |
| <span class="source-line-no">1000</span><span id="line-1000"> try {</span> |
| <span class="source-line-no">1001</span><span id="line-1001"> latch = new CountDownLatch(1);</span> |
| <span class="source-line-no">1002</span><span id="line-1002"> compactionLatch = new CountDownLatch(1);</span> |
| <span class="source-line-no">1003</span><span id="line-1003"> final TableName tableName = TableName.valueOf(name.getMethodName());</span> |
| <span class="source-line-no">1004</span><span id="line-1004"> // Create a table with block size as 1024</span> |
| <span class="source-line-no">1005</span><span id="line-1005"> table = TEST_UTIL.createTable(tableName, FAMILIES_1, 1, 1024,</span> |
| <span class="source-line-no">1006</span><span id="line-1006"> CustomInnerRegionObserverWrapper.class.getName());</span> |
| <span class="source-line-no">1007</span><span id="line-1007"> // get the block cache and region</span> |
| <span class="source-line-no">1008</span><span id="line-1008"> RegionLocator locator = TEST_UTIL.getConnection().getRegionLocator(tableName);</span> |
| <span class="source-line-no">1009</span><span id="line-1009"> String regionName = locator.getAllRegionLocations().get(0).getRegion().getEncodedName();</span> |
| <span class="source-line-no">1010</span><span id="line-1010"> HRegion region = TEST_UTIL.getRSForFirstRegionInTable(tableName).getRegion(regionName);</span> |
| <span class="source-line-no">1011</span><span id="line-1011"> HStore store = region.getStores().iterator().next();</span> |
| <span class="source-line-no">1012</span><span id="line-1012"> CacheConfig cacheConf = store.getCacheConfig();</span> |
| <span class="source-line-no">1013</span><span id="line-1013"> cacheConf.setCacheDataOnWrite(true);</span> |
| <span class="source-line-no">1014</span><span id="line-1014"> cacheConf.setEvictOnClose(true);</span> |
| <span class="source-line-no">1015</span><span id="line-1015"> BlockCache cache = cacheConf.getBlockCache().get();</span> |
| <span class="source-line-no">1016</span><span id="line-1016"></span> |
| <span class="source-line-no">1017</span><span id="line-1017"> // insert data. 2 Rows are added</span> |
| <span class="source-line-no">1018</span><span id="line-1018"> Put put = new Put(ROW);</span> |
| <span class="source-line-no">1019</span><span id="line-1019"> put.addColumn(FAMILY, QUALIFIER, data);</span> |
| <span class="source-line-no">1020</span><span id="line-1020"> table.put(put);</span> |
| <span class="source-line-no">1021</span><span id="line-1021"> put = new Put(ROW1);</span> |
| <span class="source-line-no">1022</span><span id="line-1022"> put.addColumn(FAMILY, QUALIFIER, data);</span> |
| <span class="source-line-no">1023</span><span id="line-1023"> table.put(put);</span> |
| <span class="source-line-no">1024</span><span id="line-1024"> assertTrue(Bytes.equals(table.get(new Get(ROW)).value(), data));</span> |
| <span class="source-line-no">1025</span><span id="line-1025"> // Should create one Hfile with 2 blocks</span> |
| <span class="source-line-no">1026</span><span id="line-1026"> region.flush(true);</span> |
| <span class="source-line-no">1027</span><span id="line-1027"> // read the data and expect same blocks, one new hit, no misses</span> |
| <span class="source-line-no">1028</span><span id="line-1028"> int refCount = 0;</span> |
| <span class="source-line-no">1029</span><span id="line-1029"> // Check how this miss is happening</span> |
| <span class="source-line-no">1030</span><span id="line-1030"> // insert a second column, read the row, no new blocks, 3 new hits</span> |
| <span class="source-line-no">1031</span><span id="line-1031"> byte[] QUALIFIER2 = Bytes.add(QUALIFIER, QUALIFIER);</span> |
| <span class="source-line-no">1032</span><span id="line-1032"> byte[] data2 = Bytes.add(data, data);</span> |
| <span class="source-line-no">1033</span><span id="line-1033"> put = new Put(ROW);</span> |
| <span class="source-line-no">1034</span><span id="line-1034"> put.addColumn(FAMILY, QUALIFIER2, data2);</span> |
| <span class="source-line-no">1035</span><span id="line-1035"> table.put(put);</span> |
| <span class="source-line-no">1036</span><span id="line-1036"> // flush, one new block</span> |
| <span class="source-line-no">1037</span><span id="line-1037"> System.out.println("Flushing cache");</span> |
| <span class="source-line-no">1038</span><span id="line-1038"> region.flush(true);</span> |
| <span class="source-line-no">1039</span><span id="line-1039"> Iterator<CachedBlock> iterator = cache.iterator();</span> |
| <span class="source-line-no">1040</span><span id="line-1040"> iterateBlockCache(cache, iterator);</span> |
| <span class="source-line-no">1041</span><span id="line-1041"> // Create three sets of scan</span> |
| <span class="source-line-no">1042</span><span id="line-1042"> ScanThread[] scanThreads = initiateScan(table, false);</span> |
| <span class="source-line-no">1043</span><span id="line-1043"> Thread.sleep(100);</span> |
| <span class="source-line-no">1044</span><span id="line-1044"> iterator = cache.iterator();</span> |
| <span class="source-line-no">1045</span><span id="line-1045"> boolean usedBlocksFound = false;</span> |
| <span class="source-line-no">1046</span><span id="line-1046"> while (iterator.hasNext()) {</span> |
| <span class="source-line-no">1047</span><span id="line-1047"> CachedBlock next = iterator.next();</span> |
| <span class="source-line-no">1048</span><span id="line-1048"> BlockCacheKey cacheKey = new BlockCacheKey(next.getFilename(), next.getOffset());</span> |
| <span class="source-line-no">1049</span><span id="line-1049"> if (cache instanceof BucketCache) {</span> |
| <span class="source-line-no">1050</span><span id="line-1050"> refCount = ((BucketCache) cache).getRpcRefCount(cacheKey);</span> |
| <span class="source-line-no">1051</span><span id="line-1051"> } else if (cache instanceof CombinedBlockCache) {</span> |
| <span class="source-line-no">1052</span><span id="line-1052"> refCount = ((CombinedBlockCache) cache).getRpcRefCount(cacheKey);</span> |
| <span class="source-line-no">1053</span><span id="line-1053"> } else {</span> |
| <span class="source-line-no">1054</span><span id="line-1054"> continue;</span> |
| <span class="source-line-no">1055</span><span id="line-1055"> }</span> |
| <span class="source-line-no">1056</span><span id="line-1056"> if (refCount != 0) {</span> |
| <span class="source-line-no">1057</span><span id="line-1057"> // Blocks will be with count 3</span> |
| <span class="source-line-no">1058</span><span id="line-1058"> assertEquals(NO_OF_THREADS, refCount);</span> |
| <span class="source-line-no">1059</span><span id="line-1059"> usedBlocksFound = true;</span> |
| <span class="source-line-no">1060</span><span id="line-1060"> }</span> |
| <span class="source-line-no">1061</span><span id="line-1061"> }</span> |
| <span class="source-line-no">1062</span><span id="line-1062"> // Make a put and do a flush</span> |
| <span class="source-line-no">1063</span><span id="line-1063"> QUALIFIER2 = Bytes.add(QUALIFIER, QUALIFIER);</span> |
| <span class="source-line-no">1064</span><span id="line-1064"> data2 = Bytes.add(data, data);</span> |
| <span class="source-line-no">1065</span><span id="line-1065"> put = new Put(ROW1);</span> |
| <span class="source-line-no">1066</span><span id="line-1066"> put.addColumn(FAMILY, QUALIFIER2, data2);</span> |
| <span class="source-line-no">1067</span><span id="line-1067"> table.put(put);</span> |
| <span class="source-line-no">1068</span><span id="line-1068"> // flush, one new block</span> |
| <span class="source-line-no">1069</span><span id="line-1069"> System.out.println("Flushing cache");</span> |
| <span class="source-line-no">1070</span><span id="line-1070"> region.flush(true);</span> |
| <span class="source-line-no">1071</span><span id="line-1071"> assertTrue("Blocks with non zero ref count should be found ", usedBlocksFound);</span> |
| <span class="source-line-no">1072</span><span id="line-1072"> usedBlocksFound = false;</span> |
| <span class="source-line-no">1073</span><span id="line-1073"> System.out.println("Compacting");</span> |
| <span class="source-line-no">1074</span><span id="line-1074"> assertEquals(3, store.getStorefilesCount());</span> |
| <span class="source-line-no">1075</span><span id="line-1075"> store.triggerMajorCompaction();</span> |
| <span class="source-line-no">1076</span><span id="line-1076"> region.compact(true);</span> |
| <span class="source-line-no">1077</span><span id="line-1077"> waitForStoreFileCount(store, 1, 10000); // wait 10 seconds max</span> |
| <span class="source-line-no">1078</span><span id="line-1078"> assertEquals(1, store.getStorefilesCount());</span> |
| <span class="source-line-no">1079</span><span id="line-1079"> // Even after compaction is done we will have some blocks that cannot</span> |
| <span class="source-line-no">1080</span><span id="line-1080"> // be evicted this is because the scan is still referencing them</span> |
| <span class="source-line-no">1081</span><span id="line-1081"> iterator = cache.iterator();</span> |
| <span class="source-line-no">1082</span><span id="line-1082"> while (iterator.hasNext()) {</span> |
| <span class="source-line-no">1083</span><span id="line-1083"> CachedBlock next = iterator.next();</span> |
| <span class="source-line-no">1084</span><span id="line-1084"> BlockCacheKey cacheKey = new BlockCacheKey(next.getFilename(), next.getOffset());</span> |
| <span class="source-line-no">1085</span><span id="line-1085"> if (cache instanceof BucketCache) {</span> |
| <span class="source-line-no">1086</span><span id="line-1086"> refCount = ((BucketCache) cache).getRpcRefCount(cacheKey);</span> |
| <span class="source-line-no">1087</span><span id="line-1087"> } else if (cache instanceof CombinedBlockCache) {</span> |
| <span class="source-line-no">1088</span><span id="line-1088"> refCount = ((CombinedBlockCache) cache).getRpcRefCount(cacheKey);</span> |
| <span class="source-line-no">1089</span><span id="line-1089"> } else {</span> |
| <span class="source-line-no">1090</span><span id="line-1090"> continue;</span> |
| <span class="source-line-no">1091</span><span id="line-1091"> }</span> |
| <span class="source-line-no">1092</span><span id="line-1092"> if (refCount != 0) {</span> |
| <span class="source-line-no">1093</span><span id="line-1093"> // Blocks will be with count 3 as they are not yet cleared</span> |
| <span class="source-line-no">1094</span><span id="line-1094"> assertEquals(NO_OF_THREADS, refCount);</span> |
| <span class="source-line-no">1095</span><span id="line-1095"> usedBlocksFound = true;</span> |
| <span class="source-line-no">1096</span><span id="line-1096"> }</span> |
| <span class="source-line-no">1097</span><span id="line-1097"> }</span> |
| <span class="source-line-no">1098</span><span id="line-1098"> assertTrue("Blocks with non zero ref count should be found ", usedBlocksFound);</span> |
| <span class="source-line-no">1099</span><span id="line-1099"> // Should not throw exception</span> |
| <span class="source-line-no">1100</span><span id="line-1100"> compactionLatch.countDown();</span> |
| <span class="source-line-no">1101</span><span id="line-1101"> latch.countDown();</span> |
| <span class="source-line-no">1102</span><span id="line-1102"> for (ScanThread thread : scanThreads) {</span> |
| <span class="source-line-no">1103</span><span id="line-1103"> thread.join();</span> |
| <span class="source-line-no">1104</span><span id="line-1104"> }</span> |
| <span class="source-line-no">1105</span><span id="line-1105"> // by this time all blocks should have been evicted</span> |
| <span class="source-line-no">1106</span><span id="line-1106"> iterator = cache.iterator();</span> |
| <span class="source-line-no">1107</span><span id="line-1107"> // Since a flush and compaction happened after a scan started</span> |
| <span class="source-line-no">1108</span><span id="line-1108"> // we need to ensure that all the original blocks of the compacted file</span> |
| <span class="source-line-no">1109</span><span id="line-1109"> // is also removed.</span> |
| <span class="source-line-no">1110</span><span id="line-1110"> iterateBlockCache(cache, iterator);</span> |
| <span class="source-line-no">1111</span><span id="line-1111"> Result r = table.get(new Get(ROW));</span> |
| <span class="source-line-no">1112</span><span id="line-1112"> assertTrue(Bytes.equals(r.getValue(FAMILY, QUALIFIER), data));</span> |
| <span class="source-line-no">1113</span><span id="line-1113"> assertTrue(Bytes.equals(r.getValue(FAMILY, QUALIFIER2), data2));</span> |
| <span class="source-line-no">1114</span><span id="line-1114"> // The gets would be working on new blocks</span> |
| <span class="source-line-no">1115</span><span id="line-1115"> iterator = cache.iterator();</span> |
| <span class="source-line-no">1116</span><span id="line-1116"> iterateBlockCache(cache, iterator);</span> |
| <span class="source-line-no">1117</span><span id="line-1117"> } finally {</span> |
| <span class="source-line-no">1118</span><span id="line-1118"> if (table != null) {</span> |
| <span class="source-line-no">1119</span><span id="line-1119"> table.close();</span> |
| <span class="source-line-no">1120</span><span id="line-1120"> }</span> |
| <span class="source-line-no">1121</span><span id="line-1121"> }</span> |
| <span class="source-line-no">1122</span><span id="line-1122"> }</span> |
| <span class="source-line-no">1123</span><span id="line-1123"></span> |
| <span class="source-line-no">1124</span><span id="line-1124"> @Test</span> |
| <span class="source-line-no">1125</span><span id="line-1125"> public void testScanWithException() throws IOException, InterruptedException {</span> |
| <span class="source-line-no">1126</span><span id="line-1126"> Table table = null;</span> |
| <span class="source-line-no">1127</span><span id="line-1127"> try {</span> |
| <span class="source-line-no">1128</span><span id="line-1128"> latch = new CountDownLatch(1);</span> |
| <span class="source-line-no">1129</span><span id="line-1129"> exceptionLatch = new CountDownLatch(1);</span> |
| <span class="source-line-no">1130</span><span id="line-1130"> final TableName tableName = TableName.valueOf(name.getMethodName());</span> |
| <span class="source-line-no">1131</span><span id="line-1131"> // Create KV that will give you two blocks</span> |
| <span class="source-line-no">1132</span><span id="line-1132"> // Create a table with block size as 1024</span> |
| <span class="source-line-no">1133</span><span id="line-1133"> table = TEST_UTIL.createTable(tableName, FAMILIES_1, 1, 1024,</span> |
| <span class="source-line-no">1134</span><span id="line-1134"> CustomInnerRegionObserverWrapper.class.getName());</span> |
| <span class="source-line-no">1135</span><span id="line-1135"> // get the block cache and region</span> |
| <span class="source-line-no">1136</span><span id="line-1136"> RegionLocator locator = TEST_UTIL.getConnection().getRegionLocator(tableName);</span> |
| <span class="source-line-no">1137</span><span id="line-1137"> String regionName = locator.getAllRegionLocations().get(0).getRegion().getEncodedName();</span> |
| <span class="source-line-no">1138</span><span id="line-1138"> HRegion region = TEST_UTIL.getRSForFirstRegionInTable(tableName).getRegion(regionName);</span> |
| <span class="source-line-no">1139</span><span id="line-1139"> HStore store = region.getStores().iterator().next();</span> |
| <span class="source-line-no">1140</span><span id="line-1140"> CacheConfig cacheConf = store.getCacheConfig();</span> |
| <span class="source-line-no">1141</span><span id="line-1141"> cacheConf.setCacheDataOnWrite(true);</span> |
| <span class="source-line-no">1142</span><span id="line-1142"> cacheConf.setEvictOnClose(true);</span> |
| <span class="source-line-no">1143</span><span id="line-1143"> BlockCache cache = cacheConf.getBlockCache().get();</span> |
| <span class="source-line-no">1144</span><span id="line-1144"> // insert data. 2 Rows are added</span> |
| <span class="source-line-no">1145</span><span id="line-1145"> insertData(table);</span> |
| <span class="source-line-no">1146</span><span id="line-1146"> // flush the data</span> |
| <span class="source-line-no">1147</span><span id="line-1147"> System.out.println("Flushing cache");</span> |
| <span class="source-line-no">1148</span><span id="line-1148"> // Should create one Hfile with 2 blocks</span> |
| <span class="source-line-no">1149</span><span id="line-1149"> region.flush(true);</span> |
| <span class="source-line-no">1150</span><span id="line-1150"> // CustomInnerRegionObserver.sleepTime.set(5000);</span> |
| <span class="source-line-no">1151</span><span id="line-1151"> CustomInnerRegionObserver.throwException.set(true);</span> |
| <span class="source-line-no">1152</span><span id="line-1152"> ScanThread[] scanThreads = initiateScan(table, false);</span> |
| <span class="source-line-no">1153</span><span id="line-1153"> // The block would have been decremented for the scan case as it was</span> |
| <span class="source-line-no">1154</span><span id="line-1154"> // wrapped</span> |
| <span class="source-line-no">1155</span><span id="line-1155"> // before even the postNext hook gets executed.</span> |
| <span class="source-line-no">1156</span><span id="line-1156"> // giving some time for the block to be decremented</span> |
| <span class="source-line-no">1157</span><span id="line-1157"> Thread.sleep(100);</span> |
| <span class="source-line-no">1158</span><span id="line-1158"> Iterator<CachedBlock> iterator = cache.iterator();</span> |
| <span class="source-line-no">1159</span><span id="line-1159"> boolean usedBlocksFound = false;</span> |
| <span class="source-line-no">1160</span><span id="line-1160"> int refCount = 0;</span> |
| <span class="source-line-no">1161</span><span id="line-1161"> while (iterator.hasNext()) {</span> |
| <span class="source-line-no">1162</span><span id="line-1162"> CachedBlock next = iterator.next();</span> |
| <span class="source-line-no">1163</span><span id="line-1163"> BlockCacheKey cacheKey = new BlockCacheKey(next.getFilename(), next.getOffset());</span> |
| <span class="source-line-no">1164</span><span id="line-1164"> if (cache instanceof BucketCache) {</span> |
| <span class="source-line-no">1165</span><span id="line-1165"> refCount = ((BucketCache) cache).getRpcRefCount(cacheKey);</span> |
| <span class="source-line-no">1166</span><span id="line-1166"> } else if (cache instanceof CombinedBlockCache) {</span> |
| <span class="source-line-no">1167</span><span id="line-1167"> refCount = ((CombinedBlockCache) cache).getRpcRefCount(cacheKey);</span> |
| <span class="source-line-no">1168</span><span id="line-1168"> } else {</span> |
| <span class="source-line-no">1169</span><span id="line-1169"> continue;</span> |
| <span class="source-line-no">1170</span><span id="line-1170"> }</span> |
| <span class="source-line-no">1171</span><span id="line-1171"> if (refCount != 0) {</span> |
| <span class="source-line-no">1172</span><span id="line-1172"> // Blocks will be with count 3</span> |
| <span class="source-line-no">1173</span><span id="line-1173"> assertEquals(NO_OF_THREADS, refCount);</span> |
| <span class="source-line-no">1174</span><span id="line-1174"> usedBlocksFound = true;</span> |
| <span class="source-line-no">1175</span><span id="line-1175"> }</span> |
| <span class="source-line-no">1176</span><span id="line-1176"> }</span> |
| <span class="source-line-no">1177</span><span id="line-1177"> assertTrue(usedBlocksFound);</span> |
| <span class="source-line-no">1178</span><span id="line-1178"> exceptionLatch.countDown();</span> |
| <span class="source-line-no">1179</span><span id="line-1179"> // countdown the latch</span> |
| <span class="source-line-no">1180</span><span id="line-1180"> CustomInnerRegionObserver.getCdl().get().countDown();</span> |
| <span class="source-line-no">1181</span><span id="line-1181"> for (ScanThread thread : scanThreads) {</span> |
| <span class="source-line-no">1182</span><span id="line-1182"> thread.join();</span> |
| <span class="source-line-no">1183</span><span id="line-1183"> }</span> |
| <span class="source-line-no">1184</span><span id="line-1184"> iterator = cache.iterator();</span> |
| <span class="source-line-no">1185</span><span id="line-1185"> usedBlocksFound = false;</span> |
| <span class="source-line-no">1186</span><span id="line-1186"> refCount = 0;</span> |
| <span class="source-line-no">1187</span><span id="line-1187"> while (iterator.hasNext()) {</span> |
| <span class="source-line-no">1188</span><span id="line-1188"> CachedBlock next = iterator.next();</span> |
| <span class="source-line-no">1189</span><span id="line-1189"> BlockCacheKey cacheKey = new BlockCacheKey(next.getFilename(), next.getOffset());</span> |
| <span class="source-line-no">1190</span><span id="line-1190"> if (cache instanceof BucketCache) {</span> |
| <span class="source-line-no">1191</span><span id="line-1191"> refCount = ((BucketCache) cache).getRpcRefCount(cacheKey);</span> |
| <span class="source-line-no">1192</span><span id="line-1192"> } else if (cache instanceof CombinedBlockCache) {</span> |
| <span class="source-line-no">1193</span><span id="line-1193"> refCount = ((CombinedBlockCache) cache).getRpcRefCount(cacheKey);</span> |
| <span class="source-line-no">1194</span><span id="line-1194"> } else {</span> |
| <span class="source-line-no">1195</span><span id="line-1195"> continue;</span> |
| <span class="source-line-no">1196</span><span id="line-1196"> }</span> |
| <span class="source-line-no">1197</span><span id="line-1197"> if (refCount != 0) {</span> |
| <span class="source-line-no">1198</span><span id="line-1198"> // Blocks will be with count 3</span> |
| <span class="source-line-no">1199</span><span id="line-1199"> assertEquals(NO_OF_THREADS, refCount);</span> |
| <span class="source-line-no">1200</span><span id="line-1200"> usedBlocksFound = true;</span> |
| <span class="source-line-no">1201</span><span id="line-1201"> }</span> |
| <span class="source-line-no">1202</span><span id="line-1202"> }</span> |
| <span class="source-line-no">1203</span><span id="line-1203"> assertFalse(usedBlocksFound);</span> |
| <span class="source-line-no">1204</span><span id="line-1204"> // you should always see 0 ref count. since after HBASE-16604 we always recreate the scanner</span> |
| <span class="source-line-no">1205</span><span id="line-1205"> assertEquals(0, refCount);</span> |
| <span class="source-line-no">1206</span><span id="line-1206"> } finally {</span> |
| <span class="source-line-no">1207</span><span id="line-1207"> if (table != null) {</span> |
| <span class="source-line-no">1208</span><span id="line-1208"> table.close();</span> |
| <span class="source-line-no">1209</span><span id="line-1209"> }</span> |
| <span class="source-line-no">1210</span><span id="line-1210"> }</span> |
| <span class="source-line-no">1211</span><span id="line-1211"> }</span> |
| <span class="source-line-no">1212</span><span id="line-1212"></span> |
| <span class="source-line-no">1213</span><span id="line-1213"> private void iterateBlockCache(BlockCache cache, Iterator<CachedBlock> iterator) {</span> |
| <span class="source-line-no">1214</span><span id="line-1214"> int refCount;</span> |
| <span class="source-line-no">1215</span><span id="line-1215"> while (iterator.hasNext()) {</span> |
| <span class="source-line-no">1216</span><span id="line-1216"> CachedBlock next = iterator.next();</span> |
| <span class="source-line-no">1217</span><span id="line-1217"> BlockCacheKey cacheKey = new BlockCacheKey(next.getFilename(), next.getOffset());</span> |
| <span class="source-line-no">1218</span><span id="line-1218"> if (cache instanceof BucketCache) {</span> |
| <span class="source-line-no">1219</span><span id="line-1219"> refCount = ((BucketCache) cache).getRpcRefCount(cacheKey);</span> |
| <span class="source-line-no">1220</span><span id="line-1220"> LOG.info("BucketCache {} {}", cacheKey, refCount);</span> |
| <span class="source-line-no">1221</span><span id="line-1221"> } else if (cache instanceof CombinedBlockCache) {</span> |
| <span class="source-line-no">1222</span><span id="line-1222"> refCount = ((CombinedBlockCache) cache).getRpcRefCount(cacheKey);</span> |
| <span class="source-line-no">1223</span><span id="line-1223"> LOG.info("CombinedBlockCache {} {}", cacheKey, refCount);</span> |
| <span class="source-line-no">1224</span><span id="line-1224"> } else {</span> |
| <span class="source-line-no">1225</span><span id="line-1225"> continue;</span> |
| <span class="source-line-no">1226</span><span id="line-1226"> }</span> |
| <span class="source-line-no">1227</span><span id="line-1227"> assertEquals(0, refCount);</span> |
| <span class="source-line-no">1228</span><span id="line-1228"> }</span> |
| <span class="source-line-no">1229</span><span id="line-1229"> }</span> |
| <span class="source-line-no">1230</span><span id="line-1230"></span> |
| <span class="source-line-no">1231</span><span id="line-1231"> private void insertData(Table table) throws IOException {</span> |
| <span class="source-line-no">1232</span><span id="line-1232"> Put put = new Put(ROW);</span> |
| <span class="source-line-no">1233</span><span id="line-1233"> put.addColumn(FAMILY, QUALIFIER, data);</span> |
| <span class="source-line-no">1234</span><span id="line-1234"> table.put(put);</span> |
| <span class="source-line-no">1235</span><span id="line-1235"> put = new Put(ROW1);</span> |
| <span class="source-line-no">1236</span><span id="line-1236"> put.addColumn(FAMILY, QUALIFIER, data);</span> |
| <span class="source-line-no">1237</span><span id="line-1237"> table.put(put);</span> |
| <span class="source-line-no">1238</span><span id="line-1238"> byte[] QUALIFIER2 = Bytes.add(QUALIFIER, QUALIFIER);</span> |
| <span class="source-line-no">1239</span><span id="line-1239"> put = new Put(ROW);</span> |
| <span class="source-line-no">1240</span><span id="line-1240"> put.addColumn(FAMILY, QUALIFIER2, data2);</span> |
| <span class="source-line-no">1241</span><span id="line-1241"> table.put(put);</span> |
| <span class="source-line-no">1242</span><span id="line-1242"> }</span> |
| <span class="source-line-no">1243</span><span id="line-1243"></span> |
| <span class="source-line-no">1244</span><span id="line-1244"> private ScanThread[] initiateScan(Table table, boolean reverse)</span> |
| <span class="source-line-no">1245</span><span id="line-1245"> throws IOException, InterruptedException {</span> |
| <span class="source-line-no">1246</span><span id="line-1246"> ScanThread[] scanThreads = new ScanThread[NO_OF_THREADS];</span> |
| <span class="source-line-no">1247</span><span id="line-1247"> for (int i = 0; i < NO_OF_THREADS; i++) {</span> |
| <span class="source-line-no">1248</span><span id="line-1248"> scanThreads[i] = new ScanThread(table, reverse);</span> |
| <span class="source-line-no">1249</span><span id="line-1249"> }</span> |
| <span class="source-line-no">1250</span><span id="line-1250"> for (ScanThread thread : scanThreads) {</span> |
| <span class="source-line-no">1251</span><span id="line-1251"> thread.start();</span> |
| <span class="source-line-no">1252</span><span id="line-1252"> }</span> |
| <span class="source-line-no">1253</span><span id="line-1253"> return scanThreads;</span> |
| <span class="source-line-no">1254</span><span id="line-1254"> }</span> |
| <span class="source-line-no">1255</span><span id="line-1255"></span> |
| <span class="source-line-no">1256</span><span id="line-1256"> private GetThread[] initiateGet(Table table, boolean tracker, boolean multipleCFs)</span> |
| <span class="source-line-no">1257</span><span id="line-1257"> throws IOException, InterruptedException {</span> |
| <span class="source-line-no">1258</span><span id="line-1258"> GetThread[] getThreads = new GetThread[NO_OF_THREADS];</span> |
| <span class="source-line-no">1259</span><span id="line-1259"> for (int i = 0; i < NO_OF_THREADS; i++) {</span> |
| <span class="source-line-no">1260</span><span id="line-1260"> getThreads[i] = new GetThread(table, tracker, multipleCFs);</span> |
| <span class="source-line-no">1261</span><span id="line-1261"> }</span> |
| <span class="source-line-no">1262</span><span id="line-1262"> for (GetThread thread : getThreads) {</span> |
| <span class="source-line-no">1263</span><span id="line-1263"> thread.start();</span> |
| <span class="source-line-no">1264</span><span id="line-1264"> }</span> |
| <span class="source-line-no">1265</span><span id="line-1265"> return getThreads;</span> |
| <span class="source-line-no">1266</span><span id="line-1266"> }</span> |
| <span class="source-line-no">1267</span><span id="line-1267"></span> |
| <span class="source-line-no">1268</span><span id="line-1268"> private MultiGetThread[] initiateMultiGet(Table table) throws IOException, InterruptedException {</span> |
| <span class="source-line-no">1269</span><span id="line-1269"> MultiGetThread[] multiGetThreads = new MultiGetThread[NO_OF_THREADS];</span> |
| <span class="source-line-no">1270</span><span id="line-1270"> for (int i = 0; i < NO_OF_THREADS; i++) {</span> |
| <span class="source-line-no">1271</span><span id="line-1271"> multiGetThreads[i] = new MultiGetThread(table);</span> |
| <span class="source-line-no">1272</span><span id="line-1272"> }</span> |
| <span class="source-line-no">1273</span><span id="line-1273"> for (MultiGetThread thread : multiGetThreads) {</span> |
| <span class="source-line-no">1274</span><span id="line-1274"> thread.start();</span> |
| <span class="source-line-no">1275</span><span id="line-1275"> }</span> |
| <span class="source-line-no">1276</span><span id="line-1276"> return multiGetThreads;</span> |
| <span class="source-line-no">1277</span><span id="line-1277"> }</span> |
| <span class="source-line-no">1278</span><span id="line-1278"></span> |
| <span class="source-line-no">1279</span><span id="line-1279"> private void checkForBlockEviction(BlockCache cache, boolean getClosed, boolean expectOnlyZero)</span> |
| <span class="source-line-no">1280</span><span id="line-1280"> throws InterruptedException {</span> |
| <span class="source-line-no">1281</span><span id="line-1281"> int counter = NO_OF_THREADS;</span> |
| <span class="source-line-no">1282</span><span id="line-1282"> if (CustomInnerRegionObserver.waitForGets.get()) {</span> |
| <span class="source-line-no">1283</span><span id="line-1283"> // Because only one row is selected, it has only 2 blocks</span> |
| <span class="source-line-no">1284</span><span id="line-1284"> counter = counter - 1;</span> |
| <span class="source-line-no">1285</span><span id="line-1285"> while (CustomInnerRegionObserver.countOfGets.get() < NO_OF_THREADS) {</span> |
| <span class="source-line-no">1286</span><span id="line-1286"> Thread.sleep(100);</span> |
| <span class="source-line-no">1287</span><span id="line-1287"> }</span> |
| <span class="source-line-no">1288</span><span id="line-1288"> } else {</span> |
| <span class="source-line-no">1289</span><span id="line-1289"> while (CustomInnerRegionObserver.countOfNext.get() < NO_OF_THREADS) {</span> |
| <span class="source-line-no">1290</span><span id="line-1290"> Thread.sleep(100);</span> |
| <span class="source-line-no">1291</span><span id="line-1291"> }</span> |
| <span class="source-line-no">1292</span><span id="line-1292"> }</span> |
| <span class="source-line-no">1293</span><span id="line-1293"> Iterator<CachedBlock> iterator = cache.iterator();</span> |
| <span class="source-line-no">1294</span><span id="line-1294"> int refCount = 0;</span> |
| <span class="source-line-no">1295</span><span id="line-1295"> while (iterator.hasNext()) {</span> |
| <span class="source-line-no">1296</span><span id="line-1296"> CachedBlock next = iterator.next();</span> |
| <span class="source-line-no">1297</span><span id="line-1297"> BlockCacheKey cacheKey = new BlockCacheKey(next.getFilename(), next.getOffset());</span> |
| <span class="source-line-no">1298</span><span id="line-1298"> if (cache instanceof BucketCache) {</span> |
| <span class="source-line-no">1299</span><span id="line-1299"> refCount = ((BucketCache) cache).getRpcRefCount(cacheKey);</span> |
| <span class="source-line-no">1300</span><span id="line-1300"> } else if (cache instanceof CombinedBlockCache) {</span> |
| <span class="source-line-no">1301</span><span id="line-1301"> refCount = ((CombinedBlockCache) cache).getRpcRefCount(cacheKey);</span> |
| <span class="source-line-no">1302</span><span id="line-1302"> } else {</span> |
| <span class="source-line-no">1303</span><span id="line-1303"> continue;</span> |
| <span class="source-line-no">1304</span><span id="line-1304"> }</span> |
| <span class="source-line-no">1305</span><span id="line-1305"> System.out.println(" the refcount is " + refCount + " block is " + cacheKey);</span> |
| <span class="source-line-no">1306</span><span id="line-1306"> if (CustomInnerRegionObserver.waitForGets.get()) {</span> |
| <span class="source-line-no">1307</span><span id="line-1307"> if (expectOnlyZero) {</span> |
| <span class="source-line-no">1308</span><span id="line-1308"> assertTrue(refCount == 0);</span> |
| <span class="source-line-no">1309</span><span id="line-1309"> }</span> |
| <span class="source-line-no">1310</span><span id="line-1310"> if (refCount != 0) {</span> |
| <span class="source-line-no">1311</span><span id="line-1311"> // Because the scan would have also touched up on these blocks but</span> |
| <span class="source-line-no">1312</span><span id="line-1312"> // it</span> |
| <span class="source-line-no">1313</span><span id="line-1313"> // would have touched</span> |
| <span class="source-line-no">1314</span><span id="line-1314"> // all 3</span> |
| <span class="source-line-no">1315</span><span id="line-1315"> if (getClosed) {</span> |
| <span class="source-line-no">1316</span><span id="line-1316"> // If get has closed only the scan's blocks would be available</span> |
| <span class="source-line-no">1317</span><span id="line-1317"> assertEquals(refCount, CustomInnerRegionObserver.countOfGets.get());</span> |
| <span class="source-line-no">1318</span><span id="line-1318"> } else {</span> |
| <span class="source-line-no">1319</span><span id="line-1319"> assertEquals(refCount, CustomInnerRegionObserver.countOfGets.get() + (NO_OF_THREADS));</span> |
| <span class="source-line-no">1320</span><span id="line-1320"> }</span> |
| <span class="source-line-no">1321</span><span id="line-1321"> }</span> |
| <span class="source-line-no">1322</span><span id="line-1322"> } else {</span> |
| <span class="source-line-no">1323</span><span id="line-1323"> // Because the get would have also touched up on these blocks but it</span> |
| <span class="source-line-no">1324</span><span id="line-1324"> // would have touched</span> |
| <span class="source-line-no">1325</span><span id="line-1325"> // upon only 2 additionally</span> |
| <span class="source-line-no">1326</span><span id="line-1326"> if (expectOnlyZero) {</span> |
| <span class="source-line-no">1327</span><span id="line-1327"> assertTrue(refCount == 0);</span> |
| <span class="source-line-no">1328</span><span id="line-1328"> }</span> |
| <span class="source-line-no">1329</span><span id="line-1329"> if (refCount != 0) {</span> |
| <span class="source-line-no">1330</span><span id="line-1330"> if (getLatch == null) {</span> |
| <span class="source-line-no">1331</span><span id="line-1331"> assertEquals(refCount, CustomInnerRegionObserver.countOfNext.get());</span> |
| <span class="source-line-no">1332</span><span id="line-1332"> } else {</span> |
| <span class="source-line-no">1333</span><span id="line-1333"> assertEquals(refCount, CustomInnerRegionObserver.countOfNext.get() + (NO_OF_THREADS));</span> |
| <span class="source-line-no">1334</span><span id="line-1334"> }</span> |
| <span class="source-line-no">1335</span><span id="line-1335"> }</span> |
| <span class="source-line-no">1336</span><span id="line-1336"> }</span> |
| <span class="source-line-no">1337</span><span id="line-1337"> }</span> |
| <span class="source-line-no">1338</span><span id="line-1338"> CustomInnerRegionObserver.getCdl().get().countDown();</span> |
| <span class="source-line-no">1339</span><span id="line-1339"> }</span> |
| <span class="source-line-no">1340</span><span id="line-1340"></span> |
| <span class="source-line-no">1341</span><span id="line-1341"> private static class MultiGetThread extends Thread {</span> |
| <span class="source-line-no">1342</span><span id="line-1342"> private final Table table;</span> |
| <span class="source-line-no">1343</span><span id="line-1343"> private final List<Get> gets = new ArrayList<>();</span> |
| <span class="source-line-no">1344</span><span id="line-1344"></span> |
| <span class="source-line-no">1345</span><span id="line-1345"> public MultiGetThread(Table table) {</span> |
| <span class="source-line-no">1346</span><span id="line-1346"> this.table = table;</span> |
| <span class="source-line-no">1347</span><span id="line-1347"> }</span> |
| <span class="source-line-no">1348</span><span id="line-1348"></span> |
| <span class="source-line-no">1349</span><span id="line-1349"> @Override</span> |
| <span class="source-line-no">1350</span><span id="line-1350"> public void run() {</span> |
| <span class="source-line-no">1351</span><span id="line-1351"> gets.add(new Get(ROW));</span> |
| <span class="source-line-no">1352</span><span id="line-1352"> gets.add(new Get(ROW1));</span> |
| <span class="source-line-no">1353</span><span id="line-1353"> try {</span> |
| <span class="source-line-no">1354</span><span id="line-1354"> CustomInnerRegionObserver.getCdl().set(latch);</span> |
| <span class="source-line-no">1355</span><span id="line-1355"> Result[] r = table.get(gets);</span> |
| <span class="source-line-no">1356</span><span id="line-1356"> assertTrue(Bytes.equals(r[0].getRow(), ROW));</span> |
| <span class="source-line-no">1357</span><span id="line-1357"> assertTrue(Bytes.equals(r[1].getRow(), ROW1));</span> |
| <span class="source-line-no">1358</span><span id="line-1358"> } catch (IOException e) {</span> |
| <span class="source-line-no">1359</span><span id="line-1359"> }</span> |
| <span class="source-line-no">1360</span><span id="line-1360"> }</span> |
| <span class="source-line-no">1361</span><span id="line-1361"> }</span> |
| <span class="source-line-no">1362</span><span id="line-1362"></span> |
| <span class="source-line-no">1363</span><span id="line-1363"> private static class GetThread extends Thread {</span> |
| <span class="source-line-no">1364</span><span id="line-1364"> private final Table table;</span> |
| <span class="source-line-no">1365</span><span id="line-1365"> private final boolean tracker;</span> |
| <span class="source-line-no">1366</span><span id="line-1366"> private final boolean multipleCFs;</span> |
| <span class="source-line-no">1367</span><span id="line-1367"></span> |
| <span class="source-line-no">1368</span><span id="line-1368"> public GetThread(Table table, boolean tracker, boolean multipleCFs) {</span> |
| <span class="source-line-no">1369</span><span id="line-1369"> this.table = table;</span> |
| <span class="source-line-no">1370</span><span id="line-1370"> this.tracker = tracker;</span> |
| <span class="source-line-no">1371</span><span id="line-1371"> this.multipleCFs = multipleCFs;</span> |
| <span class="source-line-no">1372</span><span id="line-1372"> }</span> |
| <span class="source-line-no">1373</span><span id="line-1373"></span> |
| <span class="source-line-no">1374</span><span id="line-1374"> @Override</span> |
| <span class="source-line-no">1375</span><span id="line-1375"> public void run() {</span> |
| <span class="source-line-no">1376</span><span id="line-1376"> try {</span> |
| <span class="source-line-no">1377</span><span id="line-1377"> initiateGet(table);</span> |
| <span class="source-line-no">1378</span><span id="line-1378"> } catch (IOException e) {</span> |
| <span class="source-line-no">1379</span><span id="line-1379"> // do nothing</span> |
| <span class="source-line-no">1380</span><span id="line-1380"> }</span> |
| <span class="source-line-no">1381</span><span id="line-1381"> }</span> |
| <span class="source-line-no">1382</span><span id="line-1382"></span> |
| <span class="source-line-no">1383</span><span id="line-1383"> private void initiateGet(Table table) throws IOException {</span> |
| <span class="source-line-no">1384</span><span id="line-1384"> Get get = new Get(ROW);</span> |
| <span class="source-line-no">1385</span><span id="line-1385"> if (tracker) {</span> |
| <span class="source-line-no">1386</span><span id="line-1386"> // Change this</span> |
| <span class="source-line-no">1387</span><span id="line-1387"> if (!multipleCFs) {</span> |
| <span class="source-line-no">1388</span><span id="line-1388"> get.addColumn(FAMILY, Bytes.toBytes("testQualifier" + 3));</span> |
| <span class="source-line-no">1389</span><span id="line-1389"> get.addColumn(FAMILY, Bytes.toBytes("testQualifier" + 8));</span> |
| <span class="source-line-no">1390</span><span id="line-1390"> get.addColumn(FAMILY, Bytes.toBytes("testQualifier" + 9));</span> |
| <span class="source-line-no">1391</span><span id="line-1391"> // Unknown key</span> |
| <span class="source-line-no">1392</span><span id="line-1392"> get.addColumn(FAMILY, Bytes.toBytes("testQualifier" + 900));</span> |
| <span class="source-line-no">1393</span><span id="line-1393"> } else {</span> |
| <span class="source-line-no">1394</span><span id="line-1394"> get.addColumn(Bytes.toBytes("testFamily" + 3), Bytes.toBytes("testQualifier" + 3));</span> |
| <span class="source-line-no">1395</span><span id="line-1395"> get.addColumn(Bytes.toBytes("testFamily" + 8), Bytes.toBytes("testQualifier" + 8));</span> |
| <span class="source-line-no">1396</span><span id="line-1396"> get.addColumn(Bytes.toBytes("testFamily" + 9), Bytes.toBytes("testQualifier" + 9));</span> |
| <span class="source-line-no">1397</span><span id="line-1397"> // Unknown key</span> |
| <span class="source-line-no">1398</span><span id="line-1398"> get.addColumn(Bytes.toBytes("testFamily" + 9), Bytes.toBytes("testQualifier" + 900));</span> |
| <span class="source-line-no">1399</span><span id="line-1399"> }</span> |
| <span class="source-line-no">1400</span><span id="line-1400"> }</span> |
| <span class="source-line-no">1401</span><span id="line-1401"> CustomInnerRegionObserver.getCdl().set(latch);</span> |
| <span class="source-line-no">1402</span><span id="line-1402"> Result r = table.get(get);</span> |
| <span class="source-line-no">1403</span><span id="line-1403"> System.out.println(r);</span> |
| <span class="source-line-no">1404</span><span id="line-1404"> if (!tracker) {</span> |
| <span class="source-line-no">1405</span><span id="line-1405"> assertTrue(Bytes.equals(r.getValue(FAMILY, QUALIFIER), data));</span> |
| <span class="source-line-no">1406</span><span id="line-1406"> assertTrue(Bytes.equals(r.getValue(FAMILY, QUALIFIER2), data2));</span> |
| <span class="source-line-no">1407</span><span id="line-1407"> } else {</span> |
| <span class="source-line-no">1408</span><span id="line-1408"> if (!multipleCFs) {</span> |
| <span class="source-line-no">1409</span><span id="line-1409"> assertTrue(Bytes.equals(r.getValue(FAMILY, Bytes.toBytes("testQualifier" + 3)), data2));</span> |
| <span class="source-line-no">1410</span><span id="line-1410"> assertTrue(Bytes.equals(r.getValue(FAMILY, Bytes.toBytes("testQualifier" + 8)), data2));</span> |
| <span class="source-line-no">1411</span><span id="line-1411"> assertTrue(Bytes.equals(r.getValue(FAMILY, Bytes.toBytes("testQualifier" + 9)), data2));</span> |
| <span class="source-line-no">1412</span><span id="line-1412"> } else {</span> |
| <span class="source-line-no">1413</span><span id="line-1413"> assertTrue(Bytes.equals(</span> |
| <span class="source-line-no">1414</span><span id="line-1414"> r.getValue(Bytes.toBytes("testFamily" + 3), Bytes.toBytes("testQualifier" + 3)),</span> |
| <span class="source-line-no">1415</span><span id="line-1415"> data2));</span> |
| <span class="source-line-no">1416</span><span id="line-1416"> assertTrue(Bytes.equals(</span> |
| <span class="source-line-no">1417</span><span id="line-1417"> r.getValue(Bytes.toBytes("testFamily" + 8), Bytes.toBytes("testQualifier" + 8)),</span> |
| <span class="source-line-no">1418</span><span id="line-1418"> data2));</span> |
| <span class="source-line-no">1419</span><span id="line-1419"> assertTrue(Bytes.equals(</span> |
| <span class="source-line-no">1420</span><span id="line-1420"> r.getValue(Bytes.toBytes("testFamily" + 9), Bytes.toBytes("testQualifier" + 9)),</span> |
| <span class="source-line-no">1421</span><span id="line-1421"> data2));</span> |
| <span class="source-line-no">1422</span><span id="line-1422"> }</span> |
| <span class="source-line-no">1423</span><span id="line-1423"> }</span> |
| <span class="source-line-no">1424</span><span id="line-1424"> }</span> |
| <span class="source-line-no">1425</span><span id="line-1425"> }</span> |
| <span class="source-line-no">1426</span><span id="line-1426"></span> |
| <span class="source-line-no">1427</span><span id="line-1427"> private static class ScanThread extends Thread {</span> |
| <span class="source-line-no">1428</span><span id="line-1428"> private final Table table;</span> |
| <span class="source-line-no">1429</span><span id="line-1429"> private final boolean reverse;</span> |
| <span class="source-line-no">1430</span><span id="line-1430"></span> |
| <span class="source-line-no">1431</span><span id="line-1431"> public ScanThread(Table table, boolean reverse) {</span> |
| <span class="source-line-no">1432</span><span id="line-1432"> this.table = table;</span> |
| <span class="source-line-no">1433</span><span id="line-1433"> this.reverse = reverse;</span> |
| <span class="source-line-no">1434</span><span id="line-1434"> }</span> |
| <span class="source-line-no">1435</span><span id="line-1435"></span> |
| <span class="source-line-no">1436</span><span id="line-1436"> @Override</span> |
| <span class="source-line-no">1437</span><span id="line-1437"> public void run() {</span> |
| <span class="source-line-no">1438</span><span id="line-1438"> try {</span> |
| <span class="source-line-no">1439</span><span id="line-1439"> initiateScan(table);</span> |
| <span class="source-line-no">1440</span><span id="line-1440"> } catch (IOException e) {</span> |
| <span class="source-line-no">1441</span><span id="line-1441"> // do nothing</span> |
| <span class="source-line-no">1442</span><span id="line-1442"> }</span> |
| <span class="source-line-no">1443</span><span id="line-1443"> }</span> |
| <span class="source-line-no">1444</span><span id="line-1444"></span> |
| <span class="source-line-no">1445</span><span id="line-1445"> private void initiateScan(Table table) throws IOException {</span> |
| <span class="source-line-no">1446</span><span id="line-1446"> Scan scan = new Scan();</span> |
| <span class="source-line-no">1447</span><span id="line-1447"> if (reverse) {</span> |
| <span class="source-line-no">1448</span><span id="line-1448"> scan.setReversed(true);</span> |
| <span class="source-line-no">1449</span><span id="line-1449"> }</span> |
| <span class="source-line-no">1450</span><span id="line-1450"> CustomInnerRegionObserver.getCdl().set(latch);</span> |
| <span class="source-line-no">1451</span><span id="line-1451"> ResultScanner resScanner = table.getScanner(scan);</span> |
| <span class="source-line-no">1452</span><span id="line-1452"> int i = (reverse ? ROWS.length - 1 : 0);</span> |
| <span class="source-line-no">1453</span><span id="line-1453"> boolean resultFound = false;</span> |
| <span class="source-line-no">1454</span><span id="line-1454"> for (Result result : resScanner) {</span> |
| <span class="source-line-no">1455</span><span id="line-1455"> resultFound = true;</span> |
| <span class="source-line-no">1456</span><span id="line-1456"> System.out.println(result);</span> |
| <span class="source-line-no">1457</span><span id="line-1457"> if (!reverse) {</span> |
| <span class="source-line-no">1458</span><span id="line-1458"> assertTrue(Bytes.equals(result.getRow(), ROWS[i]));</span> |
| <span class="source-line-no">1459</span><span id="line-1459"> i++;</span> |
| <span class="source-line-no">1460</span><span id="line-1460"> } else {</span> |
| <span class="source-line-no">1461</span><span id="line-1461"> assertTrue(Bytes.equals(result.getRow(), ROWS[i]));</span> |
| <span class="source-line-no">1462</span><span id="line-1462"> i--;</span> |
| <span class="source-line-no">1463</span><span id="line-1463"> }</span> |
| <span class="source-line-no">1464</span><span id="line-1464"> }</span> |
| <span class="source-line-no">1465</span><span id="line-1465"> assertTrue(resultFound);</span> |
| <span class="source-line-no">1466</span><span id="line-1466"> }</span> |
| <span class="source-line-no">1467</span><span id="line-1467"> }</span> |
| <span class="source-line-no">1468</span><span id="line-1468"></span> |
| <span class="source-line-no">1469</span><span id="line-1469"> private void waitForStoreFileCount(HStore store, int count, int timeout)</span> |
| <span class="source-line-no">1470</span><span id="line-1470"> throws InterruptedException {</span> |
| <span class="source-line-no">1471</span><span id="line-1471"> long start = EnvironmentEdgeManager.currentTime();</span> |
| <span class="source-line-no">1472</span><span id="line-1472"> while (</span> |
| <span class="source-line-no">1473</span><span id="line-1473"> start + timeout > EnvironmentEdgeManager.currentTime() && store.getStorefilesCount() != count</span> |
| <span class="source-line-no">1474</span><span id="line-1474"> ) {</span> |
| <span class="source-line-no">1475</span><span id="line-1475"> Thread.sleep(100);</span> |
| <span class="source-line-no">1476</span><span id="line-1476"> }</span> |
| <span class="source-line-no">1477</span><span id="line-1477"> System.out.println("start=" + start + ", now=" + EnvironmentEdgeManager.currentTime() + ", cur="</span> |
| <span class="source-line-no">1478</span><span id="line-1478"> + store.getStorefilesCount());</span> |
| <span class="source-line-no">1479</span><span id="line-1479"> assertEquals(count, store.getStorefilesCount());</span> |
| <span class="source-line-no">1480</span><span id="line-1480"> }</span> |
| <span class="source-line-no">1481</span><span id="line-1481"></span> |
| <span class="source-line-no">1482</span><span id="line-1482"> private static class CustomScanner implements RegionScanner {</span> |
| <span class="source-line-no">1483</span><span id="line-1483"></span> |
| <span class="source-line-no">1484</span><span id="line-1484"> private RegionScanner delegate;</span> |
| <span class="source-line-no">1485</span><span id="line-1485"></span> |
| <span class="source-line-no">1486</span><span id="line-1486"> public CustomScanner(RegionScanner delegate) {</span> |
| <span class="source-line-no">1487</span><span id="line-1487"> this.delegate = delegate;</span> |
| <span class="source-line-no">1488</span><span id="line-1488"> }</span> |
| <span class="source-line-no">1489</span><span id="line-1489"></span> |
| <span class="source-line-no">1490</span><span id="line-1490"> @Override</span> |
| <span class="source-line-no">1491</span><span id="line-1491"> public boolean next(List<Cell> results) throws IOException {</span> |
| <span class="source-line-no">1492</span><span id="line-1492"> return delegate.next(results);</span> |
| <span class="source-line-no">1493</span><span id="line-1493"> }</span> |
| <span class="source-line-no">1494</span><span id="line-1494"></span> |
| <span class="source-line-no">1495</span><span id="line-1495"> @Override</span> |
| <span class="source-line-no">1496</span><span id="line-1496"> public boolean next(List<Cell> result, ScannerContext scannerContext) throws IOException {</span> |
| <span class="source-line-no">1497</span><span id="line-1497"> return delegate.next(result, scannerContext);</span> |
| <span class="source-line-no">1498</span><span id="line-1498"> }</span> |
| <span class="source-line-no">1499</span><span id="line-1499"></span> |
| <span class="source-line-no">1500</span><span id="line-1500"> @Override</span> |
| <span class="source-line-no">1501</span><span id="line-1501"> public boolean nextRaw(List<Cell> result) throws IOException {</span> |
| <span class="source-line-no">1502</span><span id="line-1502"> return delegate.nextRaw(result);</span> |
| <span class="source-line-no">1503</span><span id="line-1503"> }</span> |
| <span class="source-line-no">1504</span><span id="line-1504"></span> |
| <span class="source-line-no">1505</span><span id="line-1505"> @Override</span> |
| <span class="source-line-no">1506</span><span id="line-1506"> public boolean nextRaw(List<Cell> result, ScannerContext context) throws IOException {</span> |
| <span class="source-line-no">1507</span><span id="line-1507"> boolean nextRaw = delegate.nextRaw(result, context);</span> |
| <span class="source-line-no">1508</span><span id="line-1508"> if (compactionLatch != null && compactionLatch.getCount() > 0) {</span> |
| <span class="source-line-no">1509</span><span id="line-1509"> try {</span> |
| <span class="source-line-no">1510</span><span id="line-1510"> compactionLatch.await();</span> |
| <span class="source-line-no">1511</span><span id="line-1511"> } catch (InterruptedException ie) {</span> |
| <span class="source-line-no">1512</span><span id="line-1512"> }</span> |
| <span class="source-line-no">1513</span><span id="line-1513"> }</span> |
| <span class="source-line-no">1514</span><span id="line-1514"></span> |
| <span class="source-line-no">1515</span><span id="line-1515"> if (CustomInnerRegionObserver.throwException.get()) {</span> |
| <span class="source-line-no">1516</span><span id="line-1516"> if (exceptionLatch.getCount() > 0) {</span> |
| <span class="source-line-no">1517</span><span id="line-1517"> try {</span> |
| <span class="source-line-no">1518</span><span id="line-1518"> exceptionLatch.await();</span> |
| <span class="source-line-no">1519</span><span id="line-1519"> } catch (InterruptedException e) {</span> |
| <span class="source-line-no">1520</span><span id="line-1520"> }</span> |
| <span class="source-line-no">1521</span><span id="line-1521"> throw new IOException("throw exception");</span> |
| <span class="source-line-no">1522</span><span id="line-1522"> }</span> |
| <span class="source-line-no">1523</span><span id="line-1523"> }</span> |
| <span class="source-line-no">1524</span><span id="line-1524"> return nextRaw;</span> |
| <span class="source-line-no">1525</span><span id="line-1525"> }</span> |
| <span class="source-line-no">1526</span><span id="line-1526"></span> |
| <span class="source-line-no">1527</span><span id="line-1527"> @Override</span> |
| <span class="source-line-no">1528</span><span id="line-1528"> public void close() throws IOException {</span> |
| <span class="source-line-no">1529</span><span id="line-1529"> delegate.close();</span> |
| <span class="source-line-no">1530</span><span id="line-1530"> }</span> |
| <span class="source-line-no">1531</span><span id="line-1531"></span> |
| <span class="source-line-no">1532</span><span id="line-1532"> @Override</span> |
| <span class="source-line-no">1533</span><span id="line-1533"> public RegionInfo getRegionInfo() {</span> |
| <span class="source-line-no">1534</span><span id="line-1534"> return delegate.getRegionInfo();</span> |
| <span class="source-line-no">1535</span><span id="line-1535"> }</span> |
| <span class="source-line-no">1536</span><span id="line-1536"></span> |
| <span class="source-line-no">1537</span><span id="line-1537"> @Override</span> |
| <span class="source-line-no">1538</span><span id="line-1538"> public boolean isFilterDone() throws IOException {</span> |
| <span class="source-line-no">1539</span><span id="line-1539"> return delegate.isFilterDone();</span> |
| <span class="source-line-no">1540</span><span id="line-1540"> }</span> |
| <span class="source-line-no">1541</span><span id="line-1541"></span> |
| <span class="source-line-no">1542</span><span id="line-1542"> @Override</span> |
| <span class="source-line-no">1543</span><span id="line-1543"> public boolean reseek(byte[] row) throws IOException {</span> |
| <span class="source-line-no">1544</span><span id="line-1544"> return false;</span> |
| <span class="source-line-no">1545</span><span id="line-1545"> }</span> |
| <span class="source-line-no">1546</span><span id="line-1546"></span> |
| <span class="source-line-no">1547</span><span id="line-1547"> @Override</span> |
| <span class="source-line-no">1548</span><span id="line-1548"> public long getMaxResultSize() {</span> |
| <span class="source-line-no">1549</span><span id="line-1549"> return delegate.getMaxResultSize();</span> |
| <span class="source-line-no">1550</span><span id="line-1550"> }</span> |
| <span class="source-line-no">1551</span><span id="line-1551"></span> |
| <span class="source-line-no">1552</span><span id="line-1552"> @Override</span> |
| <span class="source-line-no">1553</span><span id="line-1553"> public long getMvccReadPoint() {</span> |
| <span class="source-line-no">1554</span><span id="line-1554"> return delegate.getMvccReadPoint();</span> |
| <span class="source-line-no">1555</span><span id="line-1555"> }</span> |
| <span class="source-line-no">1556</span><span id="line-1556"></span> |
| <span class="source-line-no">1557</span><span id="line-1557"> @Override</span> |
| <span class="source-line-no">1558</span><span id="line-1558"> public int getBatch() {</span> |
| <span class="source-line-no">1559</span><span id="line-1559"> return delegate.getBatch();</span> |
| <span class="source-line-no">1560</span><span id="line-1560"> }</span> |
| <span class="source-line-no">1561</span><span id="line-1561"> }</span> |
| <span class="source-line-no">1562</span><span id="line-1562"></span> |
| <span class="source-line-no">1563</span><span id="line-1563"> public static class CustomInnerRegionObserverWrapper extends CustomInnerRegionObserver {</span> |
| <span class="source-line-no">1564</span><span id="line-1564"> @Override</span> |
| <span class="source-line-no">1565</span><span id="line-1565"> public RegionScanner postScannerOpen(ObserverContext<RegionCoprocessorEnvironment> e, Scan scan,</span> |
| <span class="source-line-no">1566</span><span id="line-1566"> RegionScanner s) throws IOException {</span> |
| <span class="source-line-no">1567</span><span id="line-1567"> return new CustomScanner(s);</span> |
| <span class="source-line-no">1568</span><span id="line-1568"> }</span> |
| <span class="source-line-no">1569</span><span id="line-1569"> }</span> |
| <span class="source-line-no">1570</span><span id="line-1570"></span> |
| <span class="source-line-no">1571</span><span id="line-1571"> public static class CustomInnerRegionObserver implements RegionCoprocessor, RegionObserver {</span> |
| <span class="source-line-no">1572</span><span id="line-1572"> static final AtomicInteger countOfNext = new AtomicInteger(0);</span> |
| <span class="source-line-no">1573</span><span id="line-1573"> static final AtomicInteger countOfGets = new AtomicInteger(0);</span> |
| <span class="source-line-no">1574</span><span id="line-1574"> static final AtomicBoolean waitForGets = new AtomicBoolean(false);</span> |
| <span class="source-line-no">1575</span><span id="line-1575"> static final AtomicBoolean throwException = new AtomicBoolean(false);</span> |
| <span class="source-line-no">1576</span><span id="line-1576"> private static final AtomicReference<CountDownLatch> cdl =</span> |
| <span class="source-line-no">1577</span><span id="line-1577"> new AtomicReference<>(new CountDownLatch(0));</span> |
| <span class="source-line-no">1578</span><span id="line-1578"></span> |
| <span class="source-line-no">1579</span><span id="line-1579"> @Override</span> |
| <span class="source-line-no">1580</span><span id="line-1580"> public Optional<RegionObserver> getRegionObserver() {</span> |
| <span class="source-line-no">1581</span><span id="line-1581"> return Optional.of(this);</span> |
| <span class="source-line-no">1582</span><span id="line-1582"> }</span> |
| <span class="source-line-no">1583</span><span id="line-1583"></span> |
| <span class="source-line-no">1584</span><span id="line-1584"> @Override</span> |
| <span class="source-line-no">1585</span><span id="line-1585"> public boolean postScannerNext(ObserverContext<RegionCoprocessorEnvironment> e,</span> |
| <span class="source-line-no">1586</span><span id="line-1586"> InternalScanner s, List<Result> results, int limit, boolean hasMore) throws IOException {</span> |
| <span class="source-line-no">1587</span><span id="line-1587"> slowdownCode(e, false);</span> |
| <span class="source-line-no">1588</span><span id="line-1588"> if (getLatch != null && getLatch.getCount() > 0) {</span> |
| <span class="source-line-no">1589</span><span id="line-1589"> try {</span> |
| <span class="source-line-no">1590</span><span id="line-1590"> getLatch.await();</span> |
| <span class="source-line-no">1591</span><span id="line-1591"> } catch (InterruptedException e1) {</span> |
| <span class="source-line-no">1592</span><span id="line-1592"> }</span> |
| <span class="source-line-no">1593</span><span id="line-1593"> }</span> |
| <span class="source-line-no">1594</span><span id="line-1594"> return hasMore;</span> |
| <span class="source-line-no">1595</span><span id="line-1595"> }</span> |
| <span class="source-line-no">1596</span><span id="line-1596"></span> |
| <span class="source-line-no">1597</span><span id="line-1597"> @Override</span> |
| <span class="source-line-no">1598</span><span id="line-1598"> public void postGetOp(ObserverContext<RegionCoprocessorEnvironment> e, Get get,</span> |
| <span class="source-line-no">1599</span><span id="line-1599"> List<Cell> results) throws IOException {</span> |
| <span class="source-line-no">1600</span><span id="line-1600"> slowdownCode(e, true);</span> |
| <span class="source-line-no">1601</span><span id="line-1601"> }</span> |
| <span class="source-line-no">1602</span><span id="line-1602"></span> |
| <span class="source-line-no">1603</span><span id="line-1603"> public static AtomicReference<CountDownLatch> getCdl() {</span> |
| <span class="source-line-no">1604</span><span id="line-1604"> return cdl;</span> |
| <span class="source-line-no">1605</span><span id="line-1605"> }</span> |
| <span class="source-line-no">1606</span><span id="line-1606"></span> |
| <span class="source-line-no">1607</span><span id="line-1607"> private void slowdownCode(final ObserverContext<RegionCoprocessorEnvironment> e,</span> |
| <span class="source-line-no">1608</span><span id="line-1608"> boolean isGet) {</span> |
| <span class="source-line-no">1609</span><span id="line-1609"> CountDownLatch latch = getCdl().get();</span> |
| <span class="source-line-no">1610</span><span id="line-1610"> try {</span> |
| <span class="source-line-no">1611</span><span id="line-1611"> System.out.println(latch.getCount() + " is the count " + isGet);</span> |
| <span class="source-line-no">1612</span><span id="line-1612"> if (latch.getCount() > 0) {</span> |
| <span class="source-line-no">1613</span><span id="line-1613"> if (isGet) {</span> |
| <span class="source-line-no">1614</span><span id="line-1614"> countOfGets.incrementAndGet();</span> |
| <span class="source-line-no">1615</span><span id="line-1615"> } else {</span> |
| <span class="source-line-no">1616</span><span id="line-1616"> countOfNext.incrementAndGet();</span> |
| <span class="source-line-no">1617</span><span id="line-1617"> }</span> |
| <span class="source-line-no">1618</span><span id="line-1618"> LOG.info("Waiting for the counterCountDownLatch");</span> |
| <span class="source-line-no">1619</span><span id="line-1619"> latch.await(2, TimeUnit.MINUTES); // To help the tests to finish.</span> |
| <span class="source-line-no">1620</span><span id="line-1620"> if (latch.getCount() > 0) {</span> |
| <span class="source-line-no">1621</span><span id="line-1621"> throw new RuntimeException("Can't wait more");</span> |
| <span class="source-line-no">1622</span><span id="line-1622"> }</span> |
| <span class="source-line-no">1623</span><span id="line-1623"> }</span> |
| <span class="source-line-no">1624</span><span id="line-1624"> } catch (InterruptedException e1) {</span> |
| <span class="source-line-no">1625</span><span id="line-1625"> LOG.error(e1.toString(), e1);</span> |
| <span class="source-line-no">1626</span><span id="line-1626"> }</span> |
| <span class="source-line-no">1627</span><span id="line-1627"> }</span> |
| <span class="source-line-no">1628</span><span id="line-1628"> }</span> |
| <span class="source-line-no">1629</span><span id="line-1629">}</span> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| </pre> |
| </div> |
| </main> |
| </body> |
| </html> |