hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From git-site-r...@apache.org
Subject [01/26] hbase-site git commit: Published site at 6f15cecaed2f1f76bfe1880b7c578ed369daa5d5.
Date Tue, 27 Nov 2018 14:52:33 GMT
Repository: hbase-site
Updated Branches:
  refs/heads/asf-site 3d72455c6 -> dccdd2743


http://git-wip-us.apache.org/repos/asf/hbase-site/blob/dccdd274/testdevapidocs/src-html/org/apache/hadoop/hbase/regionserver/TestCompoundBloomFilter.html
----------------------------------------------------------------------
diff --git a/testdevapidocs/src-html/org/apache/hadoop/hbase/regionserver/TestCompoundBloomFilter.html b/testdevapidocs/src-html/org/apache/hadoop/hbase/regionserver/TestCompoundBloomFilter.html
index 1890d8b..755ceef 100644
--- a/testdevapidocs/src-html/org/apache/hadoop/hbase/regionserver/TestCompoundBloomFilter.html
+++ b/testdevapidocs/src-html/org/apache/hadoop/hbase/regionserver/TestCompoundBloomFilter.html
@@ -147,243 +147,244 @@
 <span class="sourceLineNo">139</span><a name="line.139"></a>
 <span class="sourceLineNo">140</span>    fs = FileSystem.get(conf);<a name="line.140"></a>
 <span class="sourceLineNo">141</span><a name="line.141"></a>
-<span class="sourceLineNo">142</span>    cacheConf = new CacheConfig(conf);<a name="line.142"></a>
-<span class="sourceLineNo">143</span>    blockCache = cacheConf.getBlockCache();<a name="line.143"></a>
-<span class="sourceLineNo">144</span>    assertNotNull(blockCache);<a name="line.144"></a>
-<span class="sourceLineNo">145</span>  }<a name="line.145"></a>
-<span class="sourceLineNo">146</span><a name="line.146"></a>
-<span class="sourceLineNo">147</span>  private List&lt;KeyValue&gt; createSortedKeyValues(Random rand, int n) {<a name="line.147"></a>
-<span class="sourceLineNo">148</span>    List&lt;KeyValue&gt; kvList = new ArrayList&lt;&gt;(n);<a name="line.148"></a>
-<span class="sourceLineNo">149</span>    for (int i = 0; i &lt; n; ++i)<a name="line.149"></a>
-<span class="sourceLineNo">150</span>      kvList.add(RandomKeyValueUtil.randomKeyValue(rand));<a name="line.150"></a>
-<span class="sourceLineNo">151</span>    Collections.sort(kvList, CellComparatorImpl.COMPARATOR);<a name="line.151"></a>
-<span class="sourceLineNo">152</span>    return kvList;<a name="line.152"></a>
-<span class="sourceLineNo">153</span>  }<a name="line.153"></a>
-<span class="sourceLineNo">154</span><a name="line.154"></a>
-<span class="sourceLineNo">155</span>  @Test<a name="line.155"></a>
-<span class="sourceLineNo">156</span>  public void testCompoundBloomFilter() throws IOException {<a name="line.156"></a>
-<span class="sourceLineNo">157</span>    conf.setBoolean(BloomFilterFactory.IO_STOREFILE_BLOOM_ENABLED, true);<a name="line.157"></a>
-<span class="sourceLineNo">158</span>    for (int t = 0; t &lt; NUM_TESTS; ++t) {<a name="line.158"></a>
-<span class="sourceLineNo">159</span>      conf.setFloat(BloomFilterFactory.IO_STOREFILE_BLOOM_ERROR_RATE,<a name="line.159"></a>
-<span class="sourceLineNo">160</span>          (float) TARGET_ERROR_RATES[t]);<a name="line.160"></a>
-<span class="sourceLineNo">161</span><a name="line.161"></a>
-<span class="sourceLineNo">162</span>      testIdMsg = "in test #" + t + ":";<a name="line.162"></a>
-<span class="sourceLineNo">163</span>      Random generationRand = new Random(GENERATION_SEED);<a name="line.163"></a>
-<span class="sourceLineNo">164</span>      List&lt;KeyValue&gt; kvs = createSortedKeyValues(generationRand, NUM_KV[t]);<a name="line.164"></a>
-<span class="sourceLineNo">165</span>      BloomType bt = BLOOM_TYPES[t];<a name="line.165"></a>
-<span class="sourceLineNo">166</span>      Path sfPath = writeStoreFile(t, bt, kvs);<a name="line.166"></a>
-<span class="sourceLineNo">167</span>      readStoreFile(t, bt, kvs, sfPath);<a name="line.167"></a>
-<span class="sourceLineNo">168</span>    }<a name="line.168"></a>
-<span class="sourceLineNo">169</span>  }<a name="line.169"></a>
-<span class="sourceLineNo">170</span><a name="line.170"></a>
-<span class="sourceLineNo">171</span>  /**<a name="line.171"></a>
-<span class="sourceLineNo">172</span>   * Validates the false positive ratio by computing its z-value and comparing<a name="line.172"></a>
-<span class="sourceLineNo">173</span>   * it to the provided threshold.<a name="line.173"></a>
-<span class="sourceLineNo">174</span>   *<a name="line.174"></a>
-<span class="sourceLineNo">175</span>   * @param falsePosRate experimental positive rate<a name="line.175"></a>
-<span class="sourceLineNo">176</span>   * @param nTrials the number of Bloom filter checks<a name="line.176"></a>
-<span class="sourceLineNo">177</span>   * @param zValueBoundary z-value boundary, positive for an upper bound and<a name="line.177"></a>
-<span class="sourceLineNo">178</span>   *          negative for a lower bound<a name="line.178"></a>
-<span class="sourceLineNo">179</span>   * @param cbf the compound Bloom filter we are using<a name="line.179"></a>
-<span class="sourceLineNo">180</span>   * @param additionalMsg additional message to include in log output and<a name="line.180"></a>
-<span class="sourceLineNo">181</span>   *          assertion failures<a name="line.181"></a>
-<span class="sourceLineNo">182</span>   */<a name="line.182"></a>
-<span class="sourceLineNo">183</span>  private void validateFalsePosRate(double falsePosRate, int nTrials,<a name="line.183"></a>
-<span class="sourceLineNo">184</span>      double zValueBoundary, CompoundBloomFilter cbf, String additionalMsg) {<a name="line.184"></a>
-<span class="sourceLineNo">185</span>    double p = BloomFilterFactory.getErrorRate(conf);<a name="line.185"></a>
-<span class="sourceLineNo">186</span>    double zValue = (falsePosRate - p) / Math.sqrt(p * (1 - p) / nTrials);<a name="line.186"></a>
-<span class="sourceLineNo">187</span><a name="line.187"></a>
-<span class="sourceLineNo">188</span>    String assortedStatsStr = " (targetErrorRate=" + p + ", falsePosRate="<a name="line.188"></a>
-<span class="sourceLineNo">189</span>        + falsePosRate + ", nTrials=" + nTrials + ")";<a name="line.189"></a>
-<span class="sourceLineNo">190</span>    LOG.info("z-value is " + zValue + assortedStatsStr);<a name="line.190"></a>
-<span class="sourceLineNo">191</span><a name="line.191"></a>
-<span class="sourceLineNo">192</span>    boolean isUpperBound = zValueBoundary &gt; 0;<a name="line.192"></a>
-<span class="sourceLineNo">193</span><a name="line.193"></a>
-<span class="sourceLineNo">194</span>    if (isUpperBound &amp;&amp; zValue &gt; zValueBoundary ||<a name="line.194"></a>
-<span class="sourceLineNo">195</span>        !isUpperBound &amp;&amp; zValue &lt; zValueBoundary) {<a name="line.195"></a>
-<span class="sourceLineNo">196</span>      String errorMsg = "False positive rate z-value " + zValue + " is "<a name="line.196"></a>
-<span class="sourceLineNo">197</span>          + (isUpperBound ? "higher" : "lower") + " than " + zValueBoundary<a name="line.197"></a>
-<span class="sourceLineNo">198</span>          + assortedStatsStr + ". Per-chunk stats:\n"<a name="line.198"></a>
-<span class="sourceLineNo">199</span>          + cbf.formatTestingStats();<a name="line.199"></a>
-<span class="sourceLineNo">200</span>      fail(errorMsg + additionalMsg);<a name="line.200"></a>
-<span class="sourceLineNo">201</span>    }<a name="line.201"></a>
-<span class="sourceLineNo">202</span>  }<a name="line.202"></a>
-<span class="sourceLineNo">203</span><a name="line.203"></a>
-<span class="sourceLineNo">204</span>  private void readStoreFile(int t, BloomType bt, List&lt;KeyValue&gt; kvs,<a name="line.204"></a>
-<span class="sourceLineNo">205</span>      Path sfPath) throws IOException {<a name="line.205"></a>
-<span class="sourceLineNo">206</span>    HStoreFile sf = new HStoreFile(fs, sfPath, conf, cacheConf, bt, true);<a name="line.206"></a>
-<span class="sourceLineNo">207</span>    sf.initReader();<a name="line.207"></a>
-<span class="sourceLineNo">208</span>    StoreFileReader r = sf.getReader();<a name="line.208"></a>
-<span class="sourceLineNo">209</span>    final boolean pread = true; // does not really matter<a name="line.209"></a>
-<span class="sourceLineNo">210</span>    StoreFileScanner scanner = r.getStoreFileScanner(true, pread, false, 0, 0, false);<a name="line.210"></a>
-<span class="sourceLineNo">211</span><a name="line.211"></a>
-<span class="sourceLineNo">212</span>    {<a name="line.212"></a>
-<span class="sourceLineNo">213</span>      // Test for false negatives (not allowed).<a name="line.213"></a>
-<span class="sourceLineNo">214</span>      int numChecked = 0;<a name="line.214"></a>
-<span class="sourceLineNo">215</span>      for (KeyValue kv : kvs) {<a name="line.215"></a>
-<span class="sourceLineNo">216</span>        byte[] row = CellUtil.cloneRow(kv);<a name="line.216"></a>
-<span class="sourceLineNo">217</span>        boolean present = isInBloom(scanner, row, CellUtil.cloneQualifier(kv));<a name="line.217"></a>
-<span class="sourceLineNo">218</span>        assertTrue(testIdMsg + " Bloom filter false negative on row "<a name="line.218"></a>
-<span class="sourceLineNo">219</span>            + Bytes.toStringBinary(row) + " after " + numChecked<a name="line.219"></a>
-<span class="sourceLineNo">220</span>            + " successful checks", present);<a name="line.220"></a>
-<span class="sourceLineNo">221</span>        ++numChecked;<a name="line.221"></a>
-<span class="sourceLineNo">222</span>      }<a name="line.222"></a>
-<span class="sourceLineNo">223</span>    }<a name="line.223"></a>
-<span class="sourceLineNo">224</span><a name="line.224"></a>
-<span class="sourceLineNo">225</span>    // Test for false positives (some percentage allowed). We test in two modes:<a name="line.225"></a>
-<span class="sourceLineNo">226</span>    // "fake lookup" which ignores the key distribution, and production mode.<a name="line.226"></a>
-<span class="sourceLineNo">227</span>    for (boolean fakeLookupEnabled : new boolean[] { true, false }) {<a name="line.227"></a>
-<span class="sourceLineNo">228</span>      if (fakeLookupEnabled) {<a name="line.228"></a>
-<span class="sourceLineNo">229</span>        BloomFilterUtil.setRandomGeneratorForTest(new Random(283742987L));<a name="line.229"></a>
-<span class="sourceLineNo">230</span>      }<a name="line.230"></a>
-<span class="sourceLineNo">231</span>      try {<a name="line.231"></a>
-<span class="sourceLineNo">232</span>        String fakeLookupModeStr = ", fake lookup is " + (fakeLookupEnabled ?<a name="line.232"></a>
-<span class="sourceLineNo">233</span>            "enabled" : "disabled");<a name="line.233"></a>
-<span class="sourceLineNo">234</span>        CompoundBloomFilter cbf = (CompoundBloomFilter) r.getGeneralBloomFilter();<a name="line.234"></a>
-<span class="sourceLineNo">235</span>        cbf.enableTestingStats();<a name="line.235"></a>
-<span class="sourceLineNo">236</span>        int numFalsePos = 0;<a name="line.236"></a>
-<span class="sourceLineNo">237</span>        Random rand = new Random(EVALUATION_SEED);<a name="line.237"></a>
-<span class="sourceLineNo">238</span>        int nTrials = NUM_KV[t] * 10;<a name="line.238"></a>
-<span class="sourceLineNo">239</span>        for (int i = 0; i &lt; nTrials; ++i) {<a name="line.239"></a>
-<span class="sourceLineNo">240</span>          byte[] query = RandomKeyValueUtil.randomRowOrQualifier(rand);<a name="line.240"></a>
-<span class="sourceLineNo">241</span>          if (isInBloom(scanner, query, bt, rand)) {<a name="line.241"></a>
-<span class="sourceLineNo">242</span>            numFalsePos += 1;<a name="line.242"></a>
-<span class="sourceLineNo">243</span>          }<a name="line.243"></a>
-<span class="sourceLineNo">244</span>        }<a name="line.244"></a>
-<span class="sourceLineNo">245</span>        double falsePosRate = numFalsePos * 1.0 / nTrials;<a name="line.245"></a>
-<span class="sourceLineNo">246</span>        LOG.debug(String.format(testIdMsg<a name="line.246"></a>
-<span class="sourceLineNo">247</span>            + " False positives: %d out of %d (%f)",<a name="line.247"></a>
-<span class="sourceLineNo">248</span>            numFalsePos, nTrials, falsePosRate) + fakeLookupModeStr);<a name="line.248"></a>
-<span class="sourceLineNo">249</span><a name="line.249"></a>
-<span class="sourceLineNo">250</span>        // Check for obvious Bloom filter crashes.<a name="line.250"></a>
-<span class="sourceLineNo">251</span>        assertTrue("False positive is too high: " + falsePosRate + " (greater "<a name="line.251"></a>
-<span class="sourceLineNo">252</span>            + "than " + TOO_HIGH_ERROR_RATE + ")" + fakeLookupModeStr,<a name="line.252"></a>
-<span class="sourceLineNo">253</span>            falsePosRate &lt; TOO_HIGH_ERROR_RATE);<a name="line.253"></a>
-<span class="sourceLineNo">254</span><a name="line.254"></a>
-<span class="sourceLineNo">255</span>        // Now a more precise check to see if the false positive rate is not<a name="line.255"></a>
-<span class="sourceLineNo">256</span>        // too high. The reason we use a relaxed restriction for the real-world<a name="line.256"></a>
-<span class="sourceLineNo">257</span>        // case as opposed to the "fake lookup" case is that our hash functions<a name="line.257"></a>
-<span class="sourceLineNo">258</span>        // are not completely independent.<a name="line.258"></a>
-<span class="sourceLineNo">259</span><a name="line.259"></a>
-<span class="sourceLineNo">260</span>        double maxZValue = fakeLookupEnabled ? 1.96 : 2.5;<a name="line.260"></a>
-<span class="sourceLineNo">261</span>        validateFalsePosRate(falsePosRate, nTrials, maxZValue, cbf,<a name="line.261"></a>
-<span class="sourceLineNo">262</span>            fakeLookupModeStr);<a name="line.262"></a>
-<span class="sourceLineNo">263</span><a name="line.263"></a>
-<span class="sourceLineNo">264</span>        // For checking the lower bound we need to eliminate the last chunk,<a name="line.264"></a>
-<span class="sourceLineNo">265</span>        // because it is frequently smaller and the false positive rate in it<a name="line.265"></a>
-<span class="sourceLineNo">266</span>        // is too low. This does not help if there is only one under-sized<a name="line.266"></a>
-<span class="sourceLineNo">267</span>        // chunk, though.<a name="line.267"></a>
-<span class="sourceLineNo">268</span>        int nChunks = cbf.getNumChunks();<a name="line.268"></a>
-<span class="sourceLineNo">269</span>        if (nChunks &gt; 1) {<a name="line.269"></a>
-<span class="sourceLineNo">270</span>          numFalsePos -= cbf.getNumPositivesForTesting(nChunks - 1);<a name="line.270"></a>
-<span class="sourceLineNo">271</span>          nTrials -= cbf.getNumQueriesForTesting(nChunks - 1);<a name="line.271"></a>
-<span class="sourceLineNo">272</span>          falsePosRate = numFalsePos * 1.0 / nTrials;<a name="line.272"></a>
-<span class="sourceLineNo">273</span>          LOG.info(testIdMsg + " False positive rate without last chunk is " +<a name="line.273"></a>
-<span class="sourceLineNo">274</span>              falsePosRate + fakeLookupModeStr);<a name="line.274"></a>
-<span class="sourceLineNo">275</span>        }<a name="line.275"></a>
-<span class="sourceLineNo">276</span><a name="line.276"></a>
-<span class="sourceLineNo">277</span>        validateFalsePosRate(falsePosRate, nTrials, -2.58, cbf,<a name="line.277"></a>
-<span class="sourceLineNo">278</span>            fakeLookupModeStr);<a name="line.278"></a>
-<span class="sourceLineNo">279</span>      } finally {<a name="line.279"></a>
-<span class="sourceLineNo">280</span>        BloomFilterUtil.setRandomGeneratorForTest(null);<a name="line.280"></a>
-<span class="sourceLineNo">281</span>      }<a name="line.281"></a>
-<span class="sourceLineNo">282</span>    }<a name="line.282"></a>
-<span class="sourceLineNo">283</span><a name="line.283"></a>
-<span class="sourceLineNo">284</span>    r.close(true); // end of test so evictOnClose<a name="line.284"></a>
-<span class="sourceLineNo">285</span>  }<a name="line.285"></a>
-<span class="sourceLineNo">286</span><a name="line.286"></a>
-<span class="sourceLineNo">287</span>  private boolean isInBloom(StoreFileScanner scanner, byte[] row, BloomType bt,<a name="line.287"></a>
-<span class="sourceLineNo">288</span>      Random rand) {<a name="line.288"></a>
-<span class="sourceLineNo">289</span>    return isInBloom(scanner, row, RandomKeyValueUtil.randomRowOrQualifier(rand));<a name="line.289"></a>
-<span class="sourceLineNo">290</span>  }<a name="line.290"></a>
-<span class="sourceLineNo">291</span><a name="line.291"></a>
-<span class="sourceLineNo">292</span>  private boolean isInBloom(StoreFileScanner scanner, byte[] row,<a name="line.292"></a>
-<span class="sourceLineNo">293</span>      byte[] qualifier) {<a name="line.293"></a>
-<span class="sourceLineNo">294</span>    Scan scan = new Scan().withStartRow(row).withStopRow(row, true);<a name="line.294"></a>
-<span class="sourceLineNo">295</span>    scan.addColumn(Bytes.toBytes(RandomKeyValueUtil.COLUMN_FAMILY_NAME), qualifier);<a name="line.295"></a>
-<span class="sourceLineNo">296</span>    HStore store = mock(HStore.class);<a name="line.296"></a>
-<span class="sourceLineNo">297</span>    when(store.getColumnFamilyDescriptor())<a name="line.297"></a>
-<span class="sourceLineNo">298</span>        .thenReturn(ColumnFamilyDescriptorBuilder.of(RandomKeyValueUtil.COLUMN_FAMILY_NAME));<a name="line.298"></a>
-<span class="sourceLineNo">299</span>    return scanner.shouldUseScanner(scan, store, Long.MIN_VALUE);<a name="line.299"></a>
-<span class="sourceLineNo">300</span>  }<a name="line.300"></a>
-<span class="sourceLineNo">301</span><a name="line.301"></a>
-<span class="sourceLineNo">302</span>  private Path writeStoreFile(int t, BloomType bt, List&lt;KeyValue&gt; kvs)<a name="line.302"></a>
-<span class="sourceLineNo">303</span>      throws IOException {<a name="line.303"></a>
-<span class="sourceLineNo">304</span>    conf.setInt(BloomFilterFactory.IO_STOREFILE_BLOOM_BLOCK_SIZE,<a name="line.304"></a>
-<span class="sourceLineNo">305</span>        BLOOM_BLOCK_SIZES[t]);<a name="line.305"></a>
-<span class="sourceLineNo">306</span>    conf.setBoolean(CacheConfig.CACHE_BLOCKS_ON_WRITE_KEY, true);<a name="line.306"></a>
-<span class="sourceLineNo">307</span>    cacheConf = new CacheConfig(conf);<a name="line.307"></a>
-<span class="sourceLineNo">308</span>    HFileContext meta = new HFileContextBuilder().withBlockSize(BLOCK_SIZES[t]).build();<a name="line.308"></a>
-<span class="sourceLineNo">309</span>    StoreFileWriter w = new StoreFileWriter.Builder(conf, cacheConf, fs)<a name="line.309"></a>
-<span class="sourceLineNo">310</span>            .withOutputDir(TEST_UTIL.getDataTestDir())<a name="line.310"></a>
-<span class="sourceLineNo">311</span>            .withBloomType(bt)<a name="line.311"></a>
-<span class="sourceLineNo">312</span>            .withFileContext(meta)<a name="line.312"></a>
-<span class="sourceLineNo">313</span>            .build();<a name="line.313"></a>
-<span class="sourceLineNo">314</span><a name="line.314"></a>
-<span class="sourceLineNo">315</span>    assertTrue(w.hasGeneralBloom());<a name="line.315"></a>
-<span class="sourceLineNo">316</span>    assertTrue(w.getGeneralBloomWriter() instanceof CompoundBloomFilterWriter);<a name="line.316"></a>
-<span class="sourceLineNo">317</span>    CompoundBloomFilterWriter cbbf =<a name="line.317"></a>
-<span class="sourceLineNo">318</span>        (CompoundBloomFilterWriter) w.getGeneralBloomWriter();<a name="line.318"></a>
-<span class="sourceLineNo">319</span><a name="line.319"></a>
-<span class="sourceLineNo">320</span>    int keyCount = 0;<a name="line.320"></a>
-<span class="sourceLineNo">321</span>    KeyValue prev = null;<a name="line.321"></a>
-<span class="sourceLineNo">322</span>    LOG.debug("Total keys/values to insert: " + kvs.size());<a name="line.322"></a>
-<span class="sourceLineNo">323</span>    for (KeyValue kv : kvs) {<a name="line.323"></a>
-<span class="sourceLineNo">324</span>      w.append(kv);<a name="line.324"></a>
-<span class="sourceLineNo">325</span><a name="line.325"></a>
-<span class="sourceLineNo">326</span>      // Validate the key count in the Bloom filter.<a name="line.326"></a>
-<span class="sourceLineNo">327</span>      boolean newKey = true;<a name="line.327"></a>
-<span class="sourceLineNo">328</span>      if (prev != null) {<a name="line.328"></a>
-<span class="sourceLineNo">329</span>        newKey = !(bt == BloomType.ROW ? CellUtil.matchingRows(kv,<a name="line.329"></a>
-<span class="sourceLineNo">330</span>            prev) : CellUtil.matchingRowColumn(kv, prev));<a name="line.330"></a>
-<span class="sourceLineNo">331</span>      }<a name="line.331"></a>
-<span class="sourceLineNo">332</span>      if (newKey)<a name="line.332"></a>
-<span class="sourceLineNo">333</span>        ++keyCount;<a name="line.333"></a>
-<span class="sourceLineNo">334</span>      assertEquals(keyCount, cbbf.getKeyCount());<a name="line.334"></a>
-<span class="sourceLineNo">335</span><a name="line.335"></a>
-<span class="sourceLineNo">336</span>      prev = kv;<a name="line.336"></a>
-<span class="sourceLineNo">337</span>    }<a name="line.337"></a>
-<span class="sourceLineNo">338</span>    w.close();<a name="line.338"></a>
-<span class="sourceLineNo">339</span><a name="line.339"></a>
-<span class="sourceLineNo">340</span>    return w.getPath();<a name="line.340"></a>
-<span class="sourceLineNo">341</span>  }<a name="line.341"></a>
-<span class="sourceLineNo">342</span><a name="line.342"></a>
-<span class="sourceLineNo">343</span>  @Test<a name="line.343"></a>
-<span class="sourceLineNo">344</span>  public void testCompoundBloomSizing() {<a name="line.344"></a>
-<span class="sourceLineNo">345</span>    int bloomBlockByteSize = 4096;<a name="line.345"></a>
-<span class="sourceLineNo">346</span>    int bloomBlockBitSize = bloomBlockByteSize * 8;<a name="line.346"></a>
-<span class="sourceLineNo">347</span>    double targetErrorRate = 0.01;<a name="line.347"></a>
-<span class="sourceLineNo">348</span>    long maxKeysPerChunk = BloomFilterUtil.idealMaxKeys(bloomBlockBitSize,<a name="line.348"></a>
-<span class="sourceLineNo">349</span>        targetErrorRate);<a name="line.349"></a>
-<span class="sourceLineNo">350</span><a name="line.350"></a>
-<span class="sourceLineNo">351</span>    long bloomSize1 = bloomBlockByteSize * 8;<a name="line.351"></a>
-<span class="sourceLineNo">352</span>    long bloomSize2 = BloomFilterUtil.computeBitSize(maxKeysPerChunk,<a name="line.352"></a>
-<span class="sourceLineNo">353</span>        targetErrorRate);<a name="line.353"></a>
-<span class="sourceLineNo">354</span><a name="line.354"></a>
-<span class="sourceLineNo">355</span>    double bloomSizeRatio = (bloomSize2 * 1.0 / bloomSize1);<a name="line.355"></a>
-<span class="sourceLineNo">356</span>    assertTrue(Math.abs(bloomSizeRatio - 0.9999) &lt; 0.0001);<a name="line.356"></a>
-<span class="sourceLineNo">357</span>  }<a name="line.357"></a>
-<span class="sourceLineNo">358</span><a name="line.358"></a>
-<span class="sourceLineNo">359</span>  @Test<a name="line.359"></a>
-<span class="sourceLineNo">360</span>  public void testCreateKey() {<a name="line.360"></a>
-<span class="sourceLineNo">361</span>    byte[] row = "myRow".getBytes();<a name="line.361"></a>
-<span class="sourceLineNo">362</span>    byte[] qualifier = "myQualifier".getBytes();<a name="line.362"></a>
-<span class="sourceLineNo">363</span>    // Mimic what Storefile.createBloomKeyValue() does<a name="line.363"></a>
-<span class="sourceLineNo">364</span>    byte[] rowKey = KeyValueUtil.createFirstOnRow(row, 0, row.length, new byte[0], 0, 0, row, 0, 0).getKey();<a name="line.364"></a>
-<span class="sourceLineNo">365</span>    byte[] rowColKey = KeyValueUtil.createFirstOnRow(row, 0, row.length,<a name="line.365"></a>
-<span class="sourceLineNo">366</span>        new byte[0], 0, 0, qualifier, 0, qualifier.length).getKey();<a name="line.366"></a>
-<span class="sourceLineNo">367</span>    KeyValue rowKV = KeyValueUtil.createKeyValueFromKey(rowKey);<a name="line.367"></a>
-<span class="sourceLineNo">368</span>    KeyValue rowColKV = KeyValueUtil.createKeyValueFromKey(rowColKey);<a name="line.368"></a>
-<span class="sourceLineNo">369</span>    assertEquals(rowKV.getTimestamp(), rowColKV.getTimestamp());<a name="line.369"></a>
-<span class="sourceLineNo">370</span>    assertEquals(Bytes.toStringBinary(rowKV.getRowArray(), rowKV.getRowOffset(),<a name="line.370"></a>
-<span class="sourceLineNo">371</span>      rowKV.getRowLength()), Bytes.toStringBinary(rowColKV.getRowArray(), rowColKV.getRowOffset(),<a name="line.371"></a>
-<span class="sourceLineNo">372</span>      rowColKV.getRowLength()));<a name="line.372"></a>
-<span class="sourceLineNo">373</span>    assertEquals(0, rowKV.getQualifierLength());<a name="line.373"></a>
-<span class="sourceLineNo">374</span>  }<a name="line.374"></a>
-<span class="sourceLineNo">375</span><a name="line.375"></a>
+<span class="sourceLineNo">142</span>    CacheConfig.instantiateBlockCache(conf);<a name="line.142"></a>
+<span class="sourceLineNo">143</span>    cacheConf = new CacheConfig(conf);<a name="line.143"></a>
+<span class="sourceLineNo">144</span>    blockCache = cacheConf.getBlockCache();<a name="line.144"></a>
+<span class="sourceLineNo">145</span>    assertNotNull(blockCache);<a name="line.145"></a>
+<span class="sourceLineNo">146</span>  }<a name="line.146"></a>
+<span class="sourceLineNo">147</span><a name="line.147"></a>
+<span class="sourceLineNo">148</span>  private List&lt;KeyValue&gt; createSortedKeyValues(Random rand, int n) {<a name="line.148"></a>
+<span class="sourceLineNo">149</span>    List&lt;KeyValue&gt; kvList = new ArrayList&lt;&gt;(n);<a name="line.149"></a>
+<span class="sourceLineNo">150</span>    for (int i = 0; i &lt; n; ++i)<a name="line.150"></a>
+<span class="sourceLineNo">151</span>      kvList.add(RandomKeyValueUtil.randomKeyValue(rand));<a name="line.151"></a>
+<span class="sourceLineNo">152</span>    Collections.sort(kvList, CellComparatorImpl.COMPARATOR);<a name="line.152"></a>
+<span class="sourceLineNo">153</span>    return kvList;<a name="line.153"></a>
+<span class="sourceLineNo">154</span>  }<a name="line.154"></a>
+<span class="sourceLineNo">155</span><a name="line.155"></a>
+<span class="sourceLineNo">156</span>  @Test<a name="line.156"></a>
+<span class="sourceLineNo">157</span>  public void testCompoundBloomFilter() throws IOException {<a name="line.157"></a>
+<span class="sourceLineNo">158</span>    conf.setBoolean(BloomFilterFactory.IO_STOREFILE_BLOOM_ENABLED, true);<a name="line.158"></a>
+<span class="sourceLineNo">159</span>    for (int t = 0; t &lt; NUM_TESTS; ++t) {<a name="line.159"></a>
+<span class="sourceLineNo">160</span>      conf.setFloat(BloomFilterFactory.IO_STOREFILE_BLOOM_ERROR_RATE,<a name="line.160"></a>
+<span class="sourceLineNo">161</span>          (float) TARGET_ERROR_RATES[t]);<a name="line.161"></a>
+<span class="sourceLineNo">162</span><a name="line.162"></a>
+<span class="sourceLineNo">163</span>      testIdMsg = "in test #" + t + ":";<a name="line.163"></a>
+<span class="sourceLineNo">164</span>      Random generationRand = new Random(GENERATION_SEED);<a name="line.164"></a>
+<span class="sourceLineNo">165</span>      List&lt;KeyValue&gt; kvs = createSortedKeyValues(generationRand, NUM_KV[t]);<a name="line.165"></a>
+<span class="sourceLineNo">166</span>      BloomType bt = BLOOM_TYPES[t];<a name="line.166"></a>
+<span class="sourceLineNo">167</span>      Path sfPath = writeStoreFile(t, bt, kvs);<a name="line.167"></a>
+<span class="sourceLineNo">168</span>      readStoreFile(t, bt, kvs, sfPath);<a name="line.168"></a>
+<span class="sourceLineNo">169</span>    }<a name="line.169"></a>
+<span class="sourceLineNo">170</span>  }<a name="line.170"></a>
+<span class="sourceLineNo">171</span><a name="line.171"></a>
+<span class="sourceLineNo">172</span>  /**<a name="line.172"></a>
+<span class="sourceLineNo">173</span>   * Validates the false positive ratio by computing its z-value and comparing<a name="line.173"></a>
+<span class="sourceLineNo">174</span>   * it to the provided threshold.<a name="line.174"></a>
+<span class="sourceLineNo">175</span>   *<a name="line.175"></a>
+<span class="sourceLineNo">176</span>   * @param falsePosRate experimental positive rate<a name="line.176"></a>
+<span class="sourceLineNo">177</span>   * @param nTrials the number of Bloom filter checks<a name="line.177"></a>
+<span class="sourceLineNo">178</span>   * @param zValueBoundary z-value boundary, positive for an upper bound and<a name="line.178"></a>
+<span class="sourceLineNo">179</span>   *          negative for a lower bound<a name="line.179"></a>
+<span class="sourceLineNo">180</span>   * @param cbf the compound Bloom filter we are using<a name="line.180"></a>
+<span class="sourceLineNo">181</span>   * @param additionalMsg additional message to include in log output and<a name="line.181"></a>
+<span class="sourceLineNo">182</span>   *          assertion failures<a name="line.182"></a>
+<span class="sourceLineNo">183</span>   */<a name="line.183"></a>
+<span class="sourceLineNo">184</span>  private void validateFalsePosRate(double falsePosRate, int nTrials,<a name="line.184"></a>
+<span class="sourceLineNo">185</span>      double zValueBoundary, CompoundBloomFilter cbf, String additionalMsg) {<a name="line.185"></a>
+<span class="sourceLineNo">186</span>    double p = BloomFilterFactory.getErrorRate(conf);<a name="line.186"></a>
+<span class="sourceLineNo">187</span>    double zValue = (falsePosRate - p) / Math.sqrt(p * (1 - p) / nTrials);<a name="line.187"></a>
+<span class="sourceLineNo">188</span><a name="line.188"></a>
+<span class="sourceLineNo">189</span>    String assortedStatsStr = " (targetErrorRate=" + p + ", falsePosRate="<a name="line.189"></a>
+<span class="sourceLineNo">190</span>        + falsePosRate + ", nTrials=" + nTrials + ")";<a name="line.190"></a>
+<span class="sourceLineNo">191</span>    LOG.info("z-value is " + zValue + assortedStatsStr);<a name="line.191"></a>
+<span class="sourceLineNo">192</span><a name="line.192"></a>
+<span class="sourceLineNo">193</span>    boolean isUpperBound = zValueBoundary &gt; 0;<a name="line.193"></a>
+<span class="sourceLineNo">194</span><a name="line.194"></a>
+<span class="sourceLineNo">195</span>    if (isUpperBound &amp;&amp; zValue &gt; zValueBoundary ||<a name="line.195"></a>
+<span class="sourceLineNo">196</span>        !isUpperBound &amp;&amp; zValue &lt; zValueBoundary) {<a name="line.196"></a>
+<span class="sourceLineNo">197</span>      String errorMsg = "False positive rate z-value " + zValue + " is "<a name="line.197"></a>
+<span class="sourceLineNo">198</span>          + (isUpperBound ? "higher" : "lower") + " than " + zValueBoundary<a name="line.198"></a>
+<span class="sourceLineNo">199</span>          + assortedStatsStr + ". Per-chunk stats:\n"<a name="line.199"></a>
+<span class="sourceLineNo">200</span>          + cbf.formatTestingStats();<a name="line.200"></a>
+<span class="sourceLineNo">201</span>      fail(errorMsg + additionalMsg);<a name="line.201"></a>
+<span class="sourceLineNo">202</span>    }<a name="line.202"></a>
+<span class="sourceLineNo">203</span>  }<a name="line.203"></a>
+<span class="sourceLineNo">204</span><a name="line.204"></a>
+<span class="sourceLineNo">205</span>  private void readStoreFile(int t, BloomType bt, List&lt;KeyValue&gt; kvs,<a name="line.205"></a>
+<span class="sourceLineNo">206</span>      Path sfPath) throws IOException {<a name="line.206"></a>
+<span class="sourceLineNo">207</span>    HStoreFile sf = new HStoreFile(fs, sfPath, conf, cacheConf, bt, true);<a name="line.207"></a>
+<span class="sourceLineNo">208</span>    sf.initReader();<a name="line.208"></a>
+<span class="sourceLineNo">209</span>    StoreFileReader r = sf.getReader();<a name="line.209"></a>
+<span class="sourceLineNo">210</span>    final boolean pread = true; // does not really matter<a name="line.210"></a>
+<span class="sourceLineNo">211</span>    StoreFileScanner scanner = r.getStoreFileScanner(true, pread, false, 0, 0, false);<a name="line.211"></a>
+<span class="sourceLineNo">212</span><a name="line.212"></a>
+<span class="sourceLineNo">213</span>    {<a name="line.213"></a>
+<span class="sourceLineNo">214</span>      // Test for false negatives (not allowed).<a name="line.214"></a>
+<span class="sourceLineNo">215</span>      int numChecked = 0;<a name="line.215"></a>
+<span class="sourceLineNo">216</span>      for (KeyValue kv : kvs) {<a name="line.216"></a>
+<span class="sourceLineNo">217</span>        byte[] row = CellUtil.cloneRow(kv);<a name="line.217"></a>
+<span class="sourceLineNo">218</span>        boolean present = isInBloom(scanner, row, CellUtil.cloneQualifier(kv));<a name="line.218"></a>
+<span class="sourceLineNo">219</span>        assertTrue(testIdMsg + " Bloom filter false negative on row "<a name="line.219"></a>
+<span class="sourceLineNo">220</span>            + Bytes.toStringBinary(row) + " after " + numChecked<a name="line.220"></a>
+<span class="sourceLineNo">221</span>            + " successful checks", present);<a name="line.221"></a>
+<span class="sourceLineNo">222</span>        ++numChecked;<a name="line.222"></a>
+<span class="sourceLineNo">223</span>      }<a name="line.223"></a>
+<span class="sourceLineNo">224</span>    }<a name="line.224"></a>
+<span class="sourceLineNo">225</span><a name="line.225"></a>
+<span class="sourceLineNo">226</span>    // Test for false positives (some percentage allowed). We test in two modes:<a name="line.226"></a>
+<span class="sourceLineNo">227</span>    // "fake lookup" which ignores the key distribution, and production mode.<a name="line.227"></a>
+<span class="sourceLineNo">228</span>    for (boolean fakeLookupEnabled : new boolean[] { true, false }) {<a name="line.228"></a>
+<span class="sourceLineNo">229</span>      if (fakeLookupEnabled) {<a name="line.229"></a>
+<span class="sourceLineNo">230</span>        BloomFilterUtil.setRandomGeneratorForTest(new Random(283742987L));<a name="line.230"></a>
+<span class="sourceLineNo">231</span>      }<a name="line.231"></a>
+<span class="sourceLineNo">232</span>      try {<a name="line.232"></a>
+<span class="sourceLineNo">233</span>        String fakeLookupModeStr = ", fake lookup is " + (fakeLookupEnabled ?<a name="line.233"></a>
+<span class="sourceLineNo">234</span>            "enabled" : "disabled");<a name="line.234"></a>
+<span class="sourceLineNo">235</span>        CompoundBloomFilter cbf = (CompoundBloomFilter) r.getGeneralBloomFilter();<a name="line.235"></a>
+<span class="sourceLineNo">236</span>        cbf.enableTestingStats();<a name="line.236"></a>
+<span class="sourceLineNo">237</span>        int numFalsePos = 0;<a name="line.237"></a>
+<span class="sourceLineNo">238</span>        Random rand = new Random(EVALUATION_SEED);<a name="line.238"></a>
+<span class="sourceLineNo">239</span>        int nTrials = NUM_KV[t] * 10;<a name="line.239"></a>
+<span class="sourceLineNo">240</span>        for (int i = 0; i &lt; nTrials; ++i) {<a name="line.240"></a>
+<span class="sourceLineNo">241</span>          byte[] query = RandomKeyValueUtil.randomRowOrQualifier(rand);<a name="line.241"></a>
+<span class="sourceLineNo">242</span>          if (isInBloom(scanner, query, bt, rand)) {<a name="line.242"></a>
+<span class="sourceLineNo">243</span>            numFalsePos += 1;<a name="line.243"></a>
+<span class="sourceLineNo">244</span>          }<a name="line.244"></a>
+<span class="sourceLineNo">245</span>        }<a name="line.245"></a>
+<span class="sourceLineNo">246</span>        double falsePosRate = numFalsePos * 1.0 / nTrials;<a name="line.246"></a>
+<span class="sourceLineNo">247</span>        LOG.debug(String.format(testIdMsg<a name="line.247"></a>
+<span class="sourceLineNo">248</span>            + " False positives: %d out of %d (%f)",<a name="line.248"></a>
+<span class="sourceLineNo">249</span>            numFalsePos, nTrials, falsePosRate) + fakeLookupModeStr);<a name="line.249"></a>
+<span class="sourceLineNo">250</span><a name="line.250"></a>
+<span class="sourceLineNo">251</span>        // Check for obvious Bloom filter crashes.<a name="line.251"></a>
+<span class="sourceLineNo">252</span>        assertTrue("False positive is too high: " + falsePosRate + " (greater "<a name="line.252"></a>
+<span class="sourceLineNo">253</span>            + "than " + TOO_HIGH_ERROR_RATE + ")" + fakeLookupModeStr,<a name="line.253"></a>
+<span class="sourceLineNo">254</span>            falsePosRate &lt; TOO_HIGH_ERROR_RATE);<a name="line.254"></a>
+<span class="sourceLineNo">255</span><a name="line.255"></a>
+<span class="sourceLineNo">256</span>        // Now a more precise check to see if the false positive rate is not<a name="line.256"></a>
+<span class="sourceLineNo">257</span>        // too high. The reason we use a relaxed restriction for the real-world<a name="line.257"></a>
+<span class="sourceLineNo">258</span>        // case as opposed to the "fake lookup" case is that our hash functions<a name="line.258"></a>
+<span class="sourceLineNo">259</span>        // are not completely independent.<a name="line.259"></a>
+<span class="sourceLineNo">260</span><a name="line.260"></a>
+<span class="sourceLineNo">261</span>        double maxZValue = fakeLookupEnabled ? 1.96 : 2.5;<a name="line.261"></a>
+<span class="sourceLineNo">262</span>        validateFalsePosRate(falsePosRate, nTrials, maxZValue, cbf,<a name="line.262"></a>
+<span class="sourceLineNo">263</span>            fakeLookupModeStr);<a name="line.263"></a>
+<span class="sourceLineNo">264</span><a name="line.264"></a>
+<span class="sourceLineNo">265</span>        // For checking the lower bound we need to eliminate the last chunk,<a name="line.265"></a>
+<span class="sourceLineNo">266</span>        // because it is frequently smaller and the false positive rate in it<a name="line.266"></a>
+<span class="sourceLineNo">267</span>        // is too low. This does not help if there is only one under-sized<a name="line.267"></a>
+<span class="sourceLineNo">268</span>        // chunk, though.<a name="line.268"></a>
+<span class="sourceLineNo">269</span>        int nChunks = cbf.getNumChunks();<a name="line.269"></a>
+<span class="sourceLineNo">270</span>        if (nChunks &gt; 1) {<a name="line.270"></a>
+<span class="sourceLineNo">271</span>          numFalsePos -= cbf.getNumPositivesForTesting(nChunks - 1);<a name="line.271"></a>
+<span class="sourceLineNo">272</span>          nTrials -= cbf.getNumQueriesForTesting(nChunks - 1);<a name="line.272"></a>
+<span class="sourceLineNo">273</span>          falsePosRate = numFalsePos * 1.0 / nTrials;<a name="line.273"></a>
+<span class="sourceLineNo">274</span>          LOG.info(testIdMsg + " False positive rate without last chunk is " +<a name="line.274"></a>
+<span class="sourceLineNo">275</span>              falsePosRate + fakeLookupModeStr);<a name="line.275"></a>
+<span class="sourceLineNo">276</span>        }<a name="line.276"></a>
+<span class="sourceLineNo">277</span><a name="line.277"></a>
+<span class="sourceLineNo">278</span>        validateFalsePosRate(falsePosRate, nTrials, -2.58, cbf,<a name="line.278"></a>
+<span class="sourceLineNo">279</span>            fakeLookupModeStr);<a name="line.279"></a>
+<span class="sourceLineNo">280</span>      } finally {<a name="line.280"></a>
+<span class="sourceLineNo">281</span>        BloomFilterUtil.setRandomGeneratorForTest(null);<a name="line.281"></a>
+<span class="sourceLineNo">282</span>      }<a name="line.282"></a>
+<span class="sourceLineNo">283</span>    }<a name="line.283"></a>
+<span class="sourceLineNo">284</span><a name="line.284"></a>
+<span class="sourceLineNo">285</span>    r.close(true); // end of test so evictOnClose<a name="line.285"></a>
+<span class="sourceLineNo">286</span>  }<a name="line.286"></a>
+<span class="sourceLineNo">287</span><a name="line.287"></a>
+<span class="sourceLineNo">288</span>  private boolean isInBloom(StoreFileScanner scanner, byte[] row, BloomType bt,<a name="line.288"></a>
+<span class="sourceLineNo">289</span>      Random rand) {<a name="line.289"></a>
+<span class="sourceLineNo">290</span>    return isInBloom(scanner, row, RandomKeyValueUtil.randomRowOrQualifier(rand));<a name="line.290"></a>
+<span class="sourceLineNo">291</span>  }<a name="line.291"></a>
+<span class="sourceLineNo">292</span><a name="line.292"></a>
+<span class="sourceLineNo">293</span>  private boolean isInBloom(StoreFileScanner scanner, byte[] row,<a name="line.293"></a>
+<span class="sourceLineNo">294</span>      byte[] qualifier) {<a name="line.294"></a>
+<span class="sourceLineNo">295</span>    Scan scan = new Scan().withStartRow(row).withStopRow(row, true);<a name="line.295"></a>
+<span class="sourceLineNo">296</span>    scan.addColumn(Bytes.toBytes(RandomKeyValueUtil.COLUMN_FAMILY_NAME), qualifier);<a name="line.296"></a>
+<span class="sourceLineNo">297</span>    HStore store = mock(HStore.class);<a name="line.297"></a>
+<span class="sourceLineNo">298</span>    when(store.getColumnFamilyDescriptor())<a name="line.298"></a>
+<span class="sourceLineNo">299</span>        .thenReturn(ColumnFamilyDescriptorBuilder.of(RandomKeyValueUtil.COLUMN_FAMILY_NAME));<a name="line.299"></a>
+<span class="sourceLineNo">300</span>    return scanner.shouldUseScanner(scan, store, Long.MIN_VALUE);<a name="line.300"></a>
+<span class="sourceLineNo">301</span>  }<a name="line.301"></a>
+<span class="sourceLineNo">302</span><a name="line.302"></a>
+<span class="sourceLineNo">303</span>  private Path writeStoreFile(int t, BloomType bt, List&lt;KeyValue&gt; kvs)<a name="line.303"></a>
+<span class="sourceLineNo">304</span>      throws IOException {<a name="line.304"></a>
+<span class="sourceLineNo">305</span>    conf.setInt(BloomFilterFactory.IO_STOREFILE_BLOOM_BLOCK_SIZE,<a name="line.305"></a>
+<span class="sourceLineNo">306</span>        BLOOM_BLOCK_SIZES[t]);<a name="line.306"></a>
+<span class="sourceLineNo">307</span>    conf.setBoolean(CacheConfig.CACHE_BLOCKS_ON_WRITE_KEY, true);<a name="line.307"></a>
+<span class="sourceLineNo">308</span>    cacheConf = new CacheConfig(conf);<a name="line.308"></a>
+<span class="sourceLineNo">309</span>    HFileContext meta = new HFileContextBuilder().withBlockSize(BLOCK_SIZES[t]).build();<a name="line.309"></a>
+<span class="sourceLineNo">310</span>    StoreFileWriter w = new StoreFileWriter.Builder(conf, cacheConf, fs)<a name="line.310"></a>
+<span class="sourceLineNo">311</span>            .withOutputDir(TEST_UTIL.getDataTestDir())<a name="line.311"></a>
+<span class="sourceLineNo">312</span>            .withBloomType(bt)<a name="line.312"></a>
+<span class="sourceLineNo">313</span>            .withFileContext(meta)<a name="line.313"></a>
+<span class="sourceLineNo">314</span>            .build();<a name="line.314"></a>
+<span class="sourceLineNo">315</span><a name="line.315"></a>
+<span class="sourceLineNo">316</span>    assertTrue(w.hasGeneralBloom());<a name="line.316"></a>
+<span class="sourceLineNo">317</span>    assertTrue(w.getGeneralBloomWriter() instanceof CompoundBloomFilterWriter);<a name="line.317"></a>
+<span class="sourceLineNo">318</span>    CompoundBloomFilterWriter cbbf =<a name="line.318"></a>
+<span class="sourceLineNo">319</span>        (CompoundBloomFilterWriter) w.getGeneralBloomWriter();<a name="line.319"></a>
+<span class="sourceLineNo">320</span><a name="line.320"></a>
+<span class="sourceLineNo">321</span>    int keyCount = 0;<a name="line.321"></a>
+<span class="sourceLineNo">322</span>    KeyValue prev = null;<a name="line.322"></a>
+<span class="sourceLineNo">323</span>    LOG.debug("Total keys/values to insert: " + kvs.size());<a name="line.323"></a>
+<span class="sourceLineNo">324</span>    for (KeyValue kv : kvs) {<a name="line.324"></a>
+<span class="sourceLineNo">325</span>      w.append(kv);<a name="line.325"></a>
+<span class="sourceLineNo">326</span><a name="line.326"></a>
+<span class="sourceLineNo">327</span>      // Validate the key count in the Bloom filter.<a name="line.327"></a>
+<span class="sourceLineNo">328</span>      boolean newKey = true;<a name="line.328"></a>
+<span class="sourceLineNo">329</span>      if (prev != null) {<a name="line.329"></a>
+<span class="sourceLineNo">330</span>        newKey = !(bt == BloomType.ROW ? CellUtil.matchingRows(kv,<a name="line.330"></a>
+<span class="sourceLineNo">331</span>            prev) : CellUtil.matchingRowColumn(kv, prev));<a name="line.331"></a>
+<span class="sourceLineNo">332</span>      }<a name="line.332"></a>
+<span class="sourceLineNo">333</span>      if (newKey)<a name="line.333"></a>
+<span class="sourceLineNo">334</span>        ++keyCount;<a name="line.334"></a>
+<span class="sourceLineNo">335</span>      assertEquals(keyCount, cbbf.getKeyCount());<a name="line.335"></a>
+<span class="sourceLineNo">336</span><a name="line.336"></a>
+<span class="sourceLineNo">337</span>      prev = kv;<a name="line.337"></a>
+<span class="sourceLineNo">338</span>    }<a name="line.338"></a>
+<span class="sourceLineNo">339</span>    w.close();<a name="line.339"></a>
+<span class="sourceLineNo">340</span><a name="line.340"></a>
+<span class="sourceLineNo">341</span>    return w.getPath();<a name="line.341"></a>
+<span class="sourceLineNo">342</span>  }<a name="line.342"></a>
+<span class="sourceLineNo">343</span><a name="line.343"></a>
+<span class="sourceLineNo">344</span>  @Test<a name="line.344"></a>
+<span class="sourceLineNo">345</span>  public void testCompoundBloomSizing() {<a name="line.345"></a>
+<span class="sourceLineNo">346</span>    int bloomBlockByteSize = 4096;<a name="line.346"></a>
+<span class="sourceLineNo">347</span>    int bloomBlockBitSize = bloomBlockByteSize * 8;<a name="line.347"></a>
+<span class="sourceLineNo">348</span>    double targetErrorRate = 0.01;<a name="line.348"></a>
+<span class="sourceLineNo">349</span>    long maxKeysPerChunk = BloomFilterUtil.idealMaxKeys(bloomBlockBitSize,<a name="line.349"></a>
+<span class="sourceLineNo">350</span>        targetErrorRate);<a name="line.350"></a>
+<span class="sourceLineNo">351</span><a name="line.351"></a>
+<span class="sourceLineNo">352</span>    long bloomSize1 = bloomBlockByteSize * 8;<a name="line.352"></a>
+<span class="sourceLineNo">353</span>    long bloomSize2 = BloomFilterUtil.computeBitSize(maxKeysPerChunk,<a name="line.353"></a>
+<span class="sourceLineNo">354</span>        targetErrorRate);<a name="line.354"></a>
+<span class="sourceLineNo">355</span><a name="line.355"></a>
+<span class="sourceLineNo">356</span>    double bloomSizeRatio = (bloomSize2 * 1.0 / bloomSize1);<a name="line.356"></a>
+<span class="sourceLineNo">357</span>    assertTrue(Math.abs(bloomSizeRatio - 0.9999) &lt; 0.0001);<a name="line.357"></a>
+<span class="sourceLineNo">358</span>  }<a name="line.358"></a>
+<span class="sourceLineNo">359</span><a name="line.359"></a>
+<span class="sourceLineNo">360</span>  @Test<a name="line.360"></a>
+<span class="sourceLineNo">361</span>  public void testCreateKey() {<a name="line.361"></a>
+<span class="sourceLineNo">362</span>    byte[] row = "myRow".getBytes();<a name="line.362"></a>
+<span class="sourceLineNo">363</span>    byte[] qualifier = "myQualifier".getBytes();<a name="line.363"></a>
+<span class="sourceLineNo">364</span>    // Mimic what Storefile.createBloomKeyValue() does<a name="line.364"></a>
+<span class="sourceLineNo">365</span>    byte[] rowKey = KeyValueUtil.createFirstOnRow(row, 0, row.length, new byte[0], 0, 0, row, 0, 0).getKey();<a name="line.365"></a>
+<span class="sourceLineNo">366</span>    byte[] rowColKey = KeyValueUtil.createFirstOnRow(row, 0, row.length,<a name="line.366"></a>
+<span class="sourceLineNo">367</span>        new byte[0], 0, 0, qualifier, 0, qualifier.length).getKey();<a name="line.367"></a>
+<span class="sourceLineNo">368</span>    KeyValue rowKV = KeyValueUtil.createKeyValueFromKey(rowKey);<a name="line.368"></a>
+<span class="sourceLineNo">369</span>    KeyValue rowColKV = KeyValueUtil.createKeyValueFromKey(rowColKey);<a name="line.369"></a>
+<span class="sourceLineNo">370</span>    assertEquals(rowKV.getTimestamp(), rowColKV.getTimestamp());<a name="line.370"></a>
+<span class="sourceLineNo">371</span>    assertEquals(Bytes.toStringBinary(rowKV.getRowArray(), rowKV.getRowOffset(),<a name="line.371"></a>
+<span class="sourceLineNo">372</span>      rowKV.getRowLength()), Bytes.toStringBinary(rowColKV.getRowArray(), rowColKV.getRowOffset(),<a name="line.372"></a>
+<span class="sourceLineNo">373</span>      rowColKV.getRowLength()));<a name="line.373"></a>
+<span class="sourceLineNo">374</span>    assertEquals(0, rowKV.getQualifierLength());<a name="line.374"></a>
+<span class="sourceLineNo">375</span>  }<a name="line.375"></a>
 <span class="sourceLineNo">376</span><a name="line.376"></a>
-<span class="sourceLineNo">377</span>}<a name="line.377"></a>
-<span class="sourceLineNo">378</span><a name="line.378"></a>
+<span class="sourceLineNo">377</span><a name="line.377"></a>
+<span class="sourceLineNo">378</span>}<a name="line.378"></a>
+<span class="sourceLineNo">379</span><a name="line.379"></a>
 
 
 

http://git-wip-us.apache.org/repos/asf/hbase-site/blob/dccdd274/testdevapidocs/src-html/org/apache/hadoop/hbase/regionserver/TestHStoreFile.html
----------------------------------------------------------------------
diff --git a/testdevapidocs/src-html/org/apache/hadoop/hbase/regionserver/TestHStoreFile.html b/testdevapidocs/src-html/org/apache/hadoop/hbase/regionserver/TestHStoreFile.html
index a0a5cea7..a08c89e 100644
--- a/testdevapidocs/src-html/org/apache/hadoop/hbase/regionserver/TestHStoreFile.html
+++ b/testdevapidocs/src-html/org/apache/hadoop/hbase/regionserver/TestHStoreFile.html
@@ -932,17 +932,17 @@
 <span class="sourceLineNo">924</span>    scan.setTimeRange(27, 50);<a name="line.924"></a>
 <span class="sourceLineNo">925</span>    scan.setColumnFamilyTimeRange(family, 7, 50);<a name="line.925"></a>
 <span class="sourceLineNo">926</span>    assertTrue(scanner.shouldUseScanner(scan, store, Long.MIN_VALUE));<a name="line.926"></a>
-<span class="sourceLineNo">927</span><a name="line.927"></a>
-<span class="sourceLineNo">928</span>  }<a name="line.928"></a>
-<span class="sourceLineNo">929</span><a name="line.929"></a>
-<span class="sourceLineNo">930</span>  @Test<a name="line.930"></a>
-<span class="sourceLineNo">931</span>  public void testCacheOnWriteEvictOnClose() throws Exception {<a name="line.931"></a>
-<span class="sourceLineNo">932</span>    Configuration conf = this.conf;<a name="line.932"></a>
-<span class="sourceLineNo">933</span><a name="line.933"></a>
-<span class="sourceLineNo">934</span>    // Find a home for our files (regiondir ("7e0102") and familyname).<a name="line.934"></a>
-<span class="sourceLineNo">935</span>    Path baseDir = new Path(new Path(testDir, "7e0102"),"twoCOWEOC");<a name="line.935"></a>
-<span class="sourceLineNo">936</span><a name="line.936"></a>
-<span class="sourceLineNo">937</span>    // Grab the block cache and get the initial hit/miss counts<a name="line.937"></a>
+<span class="sourceLineNo">927</span>  }<a name="line.927"></a>
+<span class="sourceLineNo">928</span><a name="line.928"></a>
+<span class="sourceLineNo">929</span>  @Test<a name="line.929"></a>
+<span class="sourceLineNo">930</span>  public void testCacheOnWriteEvictOnClose() throws Exception {<a name="line.930"></a>
+<span class="sourceLineNo">931</span>    Configuration conf = this.conf;<a name="line.931"></a>
+<span class="sourceLineNo">932</span><a name="line.932"></a>
+<span class="sourceLineNo">933</span>    // Find a home for our files (regiondir ("7e0102") and familyname).<a name="line.933"></a>
+<span class="sourceLineNo">934</span>    Path baseDir = new Path(new Path(testDir, "7e0102"),"twoCOWEOC");<a name="line.934"></a>
+<span class="sourceLineNo">935</span><a name="line.935"></a>
+<span class="sourceLineNo">936</span>    // Grab the block cache and get the initial hit/miss counts<a name="line.936"></a>
+<span class="sourceLineNo">937</span>    CacheConfig.instantiateBlockCache(conf);<a name="line.937"></a>
 <span class="sourceLineNo">938</span>    BlockCache bc = new CacheConfig(conf).getBlockCache();<a name="line.938"></a>
 <span class="sourceLineNo">939</span>    assertNotNull(bc);<a name="line.939"></a>
 <span class="sourceLineNo">940</span>    CacheStats cs = bc.getStats();<a name="line.940"></a>

http://git-wip-us.apache.org/repos/asf/hbase-site/blob/dccdd274/testdevapidocs/src-html/org/apache/hadoop/hbase/regionserver/TestRecoveredEdits.html
----------------------------------------------------------------------
diff --git a/testdevapidocs/src-html/org/apache/hadoop/hbase/regionserver/TestRecoveredEdits.html b/testdevapidocs/src-html/org/apache/hadoop/hbase/regionserver/TestRecoveredEdits.html
index 89cf09c..25308a1 100644
--- a/testdevapidocs/src-html/org/apache/hadoop/hbase/regionserver/TestRecoveredEdits.html
+++ b/testdevapidocs/src-html/org/apache/hadoop/hbase/regionserver/TestRecoveredEdits.html
@@ -48,175 +48,177 @@
 <span class="sourceLineNo">040</span>import org.apache.hadoop.hbase.TableName;<a name="line.40"></a>
 <span class="sourceLineNo">041</span>import org.apache.hadoop.hbase.client.Get;<a name="line.41"></a>
 <span class="sourceLineNo">042</span>import org.apache.hadoop.hbase.client.Result;<a name="line.42"></a>
-<span class="sourceLineNo">043</span>import org.apache.hadoop.hbase.testclassification.MediumTests;<a name="line.43"></a>
-<span class="sourceLineNo">044</span>import org.apache.hadoop.hbase.util.Bytes;<a name="line.44"></a>
-<span class="sourceLineNo">045</span>import org.apache.hadoop.hbase.util.FSUtils;<a name="line.45"></a>
-<span class="sourceLineNo">046</span>import org.apache.hadoop.hbase.wal.WAL;<a name="line.46"></a>
-<span class="sourceLineNo">047</span>import org.apache.hadoop.hbase.wal.WALEdit;<a name="line.47"></a>
-<span class="sourceLineNo">048</span>import org.apache.hadoop.hbase.wal.WALFactory;<a name="line.48"></a>
-<span class="sourceLineNo">049</span>import org.apache.hadoop.hbase.wal.WALKey;<a name="line.49"></a>
-<span class="sourceLineNo">050</span>import org.apache.hadoop.hbase.wal.WALSplitter;<a name="line.50"></a>
-<span class="sourceLineNo">051</span>import org.junit.ClassRule;<a name="line.51"></a>
-<span class="sourceLineNo">052</span>import org.junit.Rule;<a name="line.52"></a>
-<span class="sourceLineNo">053</span>import org.junit.Test;<a name="line.53"></a>
-<span class="sourceLineNo">054</span>import org.junit.experimental.categories.Category;<a name="line.54"></a>
-<span class="sourceLineNo">055</span>import org.junit.rules.TestName;<a name="line.55"></a>
-<span class="sourceLineNo">056</span>import org.slf4j.Logger;<a name="line.56"></a>
-<span class="sourceLineNo">057</span>import org.slf4j.LoggerFactory;<a name="line.57"></a>
-<span class="sourceLineNo">058</span><a name="line.58"></a>
-<span class="sourceLineNo">059</span>/**<a name="line.59"></a>
-<span class="sourceLineNo">060</span> * Tests around replay of recovered.edits content.<a name="line.60"></a>
-<span class="sourceLineNo">061</span> */<a name="line.61"></a>
-<span class="sourceLineNo">062</span>@Category({MediumTests.class})<a name="line.62"></a>
-<span class="sourceLineNo">063</span>public class TestRecoveredEdits {<a name="line.63"></a>
-<span class="sourceLineNo">064</span><a name="line.64"></a>
-<span class="sourceLineNo">065</span>  @ClassRule<a name="line.65"></a>
-<span class="sourceLineNo">066</span>  public static final HBaseClassTestRule CLASS_RULE =<a name="line.66"></a>
-<span class="sourceLineNo">067</span>      HBaseClassTestRule.forClass(TestRecoveredEdits.class);<a name="line.67"></a>
-<span class="sourceLineNo">068</span><a name="line.68"></a>
-<span class="sourceLineNo">069</span>  private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();<a name="line.69"></a>
-<span class="sourceLineNo">070</span>  private static final Logger LOG = LoggerFactory.getLogger(TestRecoveredEdits.class);<a name="line.70"></a>
-<span class="sourceLineNo">071</span>  @Rule public TestName testName = new TestName();<a name="line.71"></a>
-<span class="sourceLineNo">072</span><a name="line.72"></a>
-<span class="sourceLineNo">073</span>  /**<a name="line.73"></a>
-<span class="sourceLineNo">074</span>   * HBASE-12782 ITBLL fails for me if generator does anything but 5M per maptask.<a name="line.74"></a>
-<span class="sourceLineNo">075</span>   * Create a region. Close it. Then copy into place a file to replay, one that is bigger than<a name="line.75"></a>
-<span class="sourceLineNo">076</span>   * configured flush size so we bring on lots of flushes.  Then reopen and confirm all edits<a name="line.76"></a>
-<span class="sourceLineNo">077</span>   * made it in.<a name="line.77"></a>
-<span class="sourceLineNo">078</span>   * @throws IOException<a name="line.78"></a>
-<span class="sourceLineNo">079</span>   */<a name="line.79"></a>
-<span class="sourceLineNo">080</span>  @Test<a name="line.80"></a>
-<span class="sourceLineNo">081</span>  public void testReplayWorksThoughLotsOfFlushing() throws<a name="line.81"></a>
-<span class="sourceLineNo">082</span>      IOException {<a name="line.82"></a>
-<span class="sourceLineNo">083</span>    for(MemoryCompactionPolicy policy : MemoryCompactionPolicy.values()) {<a name="line.83"></a>
-<span class="sourceLineNo">084</span>      testReplayWorksWithMemoryCompactionPolicy(policy);<a name="line.84"></a>
-<span class="sourceLineNo">085</span>    }<a name="line.85"></a>
-<span class="sourceLineNo">086</span>  }<a name="line.86"></a>
-<span class="sourceLineNo">087</span><a name="line.87"></a>
-<span class="sourceLineNo">088</span>  private void testReplayWorksWithMemoryCompactionPolicy(MemoryCompactionPolicy policy) throws<a name="line.88"></a>
-<span class="sourceLineNo">089</span>    IOException {<a name="line.89"></a>
-<span class="sourceLineNo">090</span>    Configuration conf = new Configuration(TEST_UTIL.getConfiguration());<a name="line.90"></a>
-<span class="sourceLineNo">091</span>    // Set it so we flush every 1M or so.  Thats a lot.<a name="line.91"></a>
-<span class="sourceLineNo">092</span>    conf.setInt(HConstants.HREGION_MEMSTORE_FLUSH_SIZE, 1024*1024);<a name="line.92"></a>
-<span class="sourceLineNo">093</span>    conf.set(CompactingMemStore.COMPACTING_MEMSTORE_TYPE_KEY, String.valueOf(policy).toLowerCase());<a name="line.93"></a>
-<span class="sourceLineNo">094</span>    // The file of recovered edits has a column family of 'meta'. Also has an encoded regionname<a name="line.94"></a>
-<span class="sourceLineNo">095</span>    // of 4823016d8fca70b25503ee07f4c6d79f which needs to match on replay.<a name="line.95"></a>
-<span class="sourceLineNo">096</span>    final String encodedRegionName = "4823016d8fca70b25503ee07f4c6d79f";<a name="line.96"></a>
-<span class="sourceLineNo">097</span>    HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(testName.getMethodName()));<a name="line.97"></a>
-<span class="sourceLineNo">098</span>    final String columnFamily = "meta";<a name="line.98"></a>
-<span class="sourceLineNo">099</span>    byte [][] columnFamilyAsByteArray = new byte [][] {Bytes.toBytes(columnFamily)};<a name="line.99"></a>
-<span class="sourceLineNo">100</span>    htd.addFamily(new HColumnDescriptor(columnFamily));<a name="line.100"></a>
-<span class="sourceLineNo">101</span>    HRegionInfo hri = new HRegionInfo(htd.getTableName()) {<a name="line.101"></a>
-<span class="sourceLineNo">102</span>      @Override<a name="line.102"></a>
-<span class="sourceLineNo">103</span>      public synchronized String getEncodedName() {<a name="line.103"></a>
-<span class="sourceLineNo">104</span>        return encodedRegionName;<a name="line.104"></a>
-<span class="sourceLineNo">105</span>      }<a name="line.105"></a>
-<span class="sourceLineNo">106</span><a name="line.106"></a>
-<span class="sourceLineNo">107</span>      // Cache the name because lots of lookups.<a name="line.107"></a>
-<span class="sourceLineNo">108</span>      private byte [] encodedRegionNameAsBytes = null;<a name="line.108"></a>
-<span class="sourceLineNo">109</span>      @Override<a name="line.109"></a>
-<span class="sourceLineNo">110</span>      public synchronized byte[] getEncodedNameAsBytes() {<a name="line.110"></a>
-<span class="sourceLineNo">111</span>        if (encodedRegionNameAsBytes == null) {<a name="line.111"></a>
-<span class="sourceLineNo">112</span>          this.encodedRegionNameAsBytes = Bytes.toBytes(getEncodedName());<a name="line.112"></a>
-<span class="sourceLineNo">113</span>        }<a name="line.113"></a>
-<span class="sourceLineNo">114</span>        return this.encodedRegionNameAsBytes;<a name="line.114"></a>
-<span class="sourceLineNo">115</span>      }<a name="line.115"></a>
-<span class="sourceLineNo">116</span>    };<a name="line.116"></a>
-<span class="sourceLineNo">117</span>    Path hbaseRootDir = TEST_UTIL.getDataTestDir();<a name="line.117"></a>
-<span class="sourceLineNo">118</span>    ChunkCreator.initialize(MemStoreLABImpl.CHUNK_SIZE_DEFAULT, false, 0, 0, 0, null);<a name="line.118"></a>
-<span class="sourceLineNo">119</span>    FileSystem fs = FileSystem.get(TEST_UTIL.getConfiguration());<a name="line.119"></a>
-<span class="sourceLineNo">120</span>    Path tableDir = FSUtils.getTableDir(hbaseRootDir, htd.getTableName());<a name="line.120"></a>
-<span class="sourceLineNo">121</span>    HRegionFileSystem hrfs =<a name="line.121"></a>
-<span class="sourceLineNo">122</span>        new HRegionFileSystem(TEST_UTIL.getConfiguration(), fs, tableDir, hri);<a name="line.122"></a>
-<span class="sourceLineNo">123</span>    if (fs.exists(hrfs.getRegionDir())) {<a name="line.123"></a>
-<span class="sourceLineNo">124</span>      LOG.info("Region directory already exists. Deleting.");<a name="line.124"></a>
-<span class="sourceLineNo">125</span>      fs.delete(hrfs.getRegionDir(), true);<a name="line.125"></a>
-<span class="sourceLineNo">126</span>    }<a name="line.126"></a>
-<span class="sourceLineNo">127</span>    HRegion region = HRegion.createHRegion(hri, hbaseRootDir, conf, htd, null);<a name="line.127"></a>
-<span class="sourceLineNo">128</span>    assertEquals(encodedRegionName, region.getRegionInfo().getEncodedName());<a name="line.128"></a>
-<span class="sourceLineNo">129</span>    List&lt;String&gt; storeFiles = region.getStoreFileList(columnFamilyAsByteArray);<a name="line.129"></a>
-<span class="sourceLineNo">130</span>    // There should be no store files.<a name="line.130"></a>
-<span class="sourceLineNo">131</span>    assertTrue(storeFiles.isEmpty());<a name="line.131"></a>
-<span class="sourceLineNo">132</span>    region.close();<a name="line.132"></a>
-<span class="sourceLineNo">133</span>    Path regionDir = region.getRegionDir(hbaseRootDir, hri);<a name="line.133"></a>
-<span class="sourceLineNo">134</span>    Path recoveredEditsDir = WALSplitter.getRegionDirRecoveredEditsDir(regionDir);<a name="line.134"></a>
-<span class="sourceLineNo">135</span>    // This is a little fragile getting this path to a file of 10M of edits.<a name="line.135"></a>
-<span class="sourceLineNo">136</span>    Path recoveredEditsFile = new Path(<a name="line.136"></a>
-<span class="sourceLineNo">137</span>      System.getProperty("test.build.classes", "target/test-classes"),<a name="line.137"></a>
-<span class="sourceLineNo">138</span>        "0000000000000016310");<a name="line.138"></a>
-<span class="sourceLineNo">139</span>    // Copy this file under the region's recovered.edits dir so it is replayed on reopen.<a name="line.139"></a>
-<span class="sourceLineNo">140</span>    Path destination = new Path(recoveredEditsDir, recoveredEditsFile.getName());<a name="line.140"></a>
-<span class="sourceLineNo">141</span>    fs.copyToLocalFile(recoveredEditsFile, destination);<a name="line.141"></a>
-<span class="sourceLineNo">142</span>    assertTrue(fs.exists(destination));<a name="line.142"></a>
-<span class="sourceLineNo">143</span>    // Now the file 0000000000000016310 is under recovered.edits, reopen the region to replay.<a name="line.143"></a>
-<span class="sourceLineNo">144</span>    region = HRegion.openHRegion(region, null);<a name="line.144"></a>
-<span class="sourceLineNo">145</span>    assertEquals(encodedRegionName, region.getRegionInfo().getEncodedName());<a name="line.145"></a>
-<span class="sourceLineNo">146</span>    storeFiles = region.getStoreFileList(columnFamilyAsByteArray);<a name="line.146"></a>
-<span class="sourceLineNo">147</span>    // Our 0000000000000016310 is 10MB. Most of the edits are for one region. Lets assume that if<a name="line.147"></a>
-<span class="sourceLineNo">148</span>    // we flush at 1MB, that there are at least 3 flushed files that are there because of the<a name="line.148"></a>
-<span class="sourceLineNo">149</span>    // replay of edits.<a name="line.149"></a>
-<span class="sourceLineNo">150</span>    if(policy == MemoryCompactionPolicy.EAGER || policy == MemoryCompactionPolicy.ADAPTIVE) {<a name="line.150"></a>
-<span class="sourceLineNo">151</span>      assertTrue("Files count=" + storeFiles.size(), storeFiles.size() &gt;= 1);<a name="line.151"></a>
-<span class="sourceLineNo">152</span>    } else {<a name="line.152"></a>
-<span class="sourceLineNo">153</span>      assertTrue("Files count=" + storeFiles.size(), storeFiles.size() &gt; 10);<a name="line.153"></a>
-<span class="sourceLineNo">154</span>    }<a name="line.154"></a>
-<span class="sourceLineNo">155</span>    // Now verify all edits made it into the region.<a name="line.155"></a>
-<span class="sourceLineNo">156</span>    int count = verifyAllEditsMadeItIn(fs, conf, recoveredEditsFile, region);<a name="line.156"></a>
-<span class="sourceLineNo">157</span>    LOG.info("Checked " + count + " edits made it in");<a name="line.157"></a>
-<span class="sourceLineNo">158</span>  }<a name="line.158"></a>
-<span class="sourceLineNo">159</span><a name="line.159"></a>
-<span class="sourceLineNo">160</span>  /**<a name="line.160"></a>
-<span class="sourceLineNo">161</span>   * @param fs<a name="line.161"></a>
-<span class="sourceLineNo">162</span>   * @param conf<a name="line.162"></a>
-<span class="sourceLineNo">163</span>   * @param edits<a name="line.163"></a>
-<span class="sourceLineNo">164</span>   * @param region<a name="line.164"></a>
-<span class="sourceLineNo">165</span>   * @return Return how many edits seen.<a name="line.165"></a>
-<span class="sourceLineNo">166</span>   * @throws IOException<a name="line.166"></a>
-<span class="sourceLineNo">167</span>   */<a name="line.167"></a>
-<span class="sourceLineNo">168</span>  private int verifyAllEditsMadeItIn(final FileSystem fs, final Configuration conf,<a name="line.168"></a>
-<span class="sourceLineNo">169</span>      final Path edits, final HRegion region)<a name="line.169"></a>
-<span class="sourceLineNo">170</span>  throws IOException {<a name="line.170"></a>
-<span class="sourceLineNo">171</span>    int count = 0;<a name="line.171"></a>
-<span class="sourceLineNo">172</span>    // Based on HRegion#replayRecoveredEdits<a name="line.172"></a>
-<span class="sourceLineNo">173</span>    WAL.Reader reader = null;<a name="line.173"></a>
-<span class="sourceLineNo">174</span>    try {<a name="line.174"></a>
-<span class="sourceLineNo">175</span>      reader = WALFactory.createReader(fs, edits, conf);<a name="line.175"></a>
-<span class="sourceLineNo">176</span>      WAL.Entry entry;<a name="line.176"></a>
-<span class="sourceLineNo">177</span>      while ((entry = reader.next()) != null) {<a name="line.177"></a>
-<span class="sourceLineNo">178</span>        WALKey key = entry.getKey();<a name="line.178"></a>
-<span class="sourceLineNo">179</span>        WALEdit val = entry.getEdit();<a name="line.179"></a>
-<span class="sourceLineNo">180</span>        count++;<a name="line.180"></a>
-<span class="sourceLineNo">181</span>        // Check this edit is for this region.<a name="line.181"></a>
-<span class="sourceLineNo">182</span>        if (!Bytes.equals(key.getEncodedRegionName(),<a name="line.182"></a>
-<span class="sourceLineNo">183</span>            region.getRegionInfo().getEncodedNameAsBytes())) {<a name="line.183"></a>
-<span class="sourceLineNo">184</span>          continue;<a name="line.184"></a>
-<span class="sourceLineNo">185</span>        }<a name="line.185"></a>
-<span class="sourceLineNo">186</span>        Cell previous = null;<a name="line.186"></a>
-<span class="sourceLineNo">187</span>        for (Cell cell: val.getCells()) {<a name="line.187"></a>
-<span class="sourceLineNo">188</span>          if (CellUtil.matchingFamily(cell, WALEdit.METAFAMILY)) continue;<a name="line.188"></a>
-<span class="sourceLineNo">189</span>          if (previous != null &amp;&amp; CellComparatorImpl.COMPARATOR.compareRows(previous, cell) == 0)<a name="line.189"></a>
-<span class="sourceLineNo">190</span>            continue;<a name="line.190"></a>
-<span class="sourceLineNo">191</span>          previous = cell;<a name="line.191"></a>
-<span class="sourceLineNo">192</span>          Get g = new Get(CellUtil.cloneRow(cell));<a name="line.192"></a>
-<span class="sourceLineNo">193</span>          Result r = region.get(g);<a name="line.193"></a>
-<span class="sourceLineNo">194</span>          boolean found = false;<a name="line.194"></a>
-<span class="sourceLineNo">195</span>          for (CellScanner scanner = r.cellScanner(); scanner.advance();) {<a name="line.195"></a>
-<span class="sourceLineNo">196</span>            Cell current = scanner.current();<a name="line.196"></a>
-<span class="sourceLineNo">197</span>            if (PrivateCellUtil.compareKeyIgnoresMvcc(CellComparatorImpl.COMPARATOR, cell,<a name="line.197"></a>
-<span class="sourceLineNo">198</span>              current) == 0) {<a name="line.198"></a>
-<span class="sourceLineNo">199</span>              found = true;<a name="line.199"></a>
-<span class="sourceLineNo">200</span>              break;<a name="line.200"></a>
-<span class="sourceLineNo">201</span>            }<a name="line.201"></a>
-<span class="sourceLineNo">202</span>          }<a name="line.202"></a>
-<span class="sourceLineNo">203</span>          assertTrue("Failed to find " + cell, found);<a name="line.203"></a>
-<span class="sourceLineNo">204</span>        }<a name="line.204"></a>
-<span class="sourceLineNo">205</span>      }<a name="line.205"></a>
-<span class="sourceLineNo">206</span>    } finally {<a name="line.206"></a>
-<span class="sourceLineNo">207</span>      if (reader != null) reader.close();<a name="line.207"></a>
-<span class="sourceLineNo">208</span>    }<a name="line.208"></a>
-<span class="sourceLineNo">209</span>    return count;<a name="line.209"></a>
-<span class="sourceLineNo">210</span>  }<a name="line.210"></a>
-<span class="sourceLineNo">211</span>}<a name="line.211"></a>
+<span class="sourceLineNo">043</span>import org.apache.hadoop.hbase.io.hfile.CacheConfig;<a name="line.43"></a>
+<span class="sourceLineNo">044</span>import org.apache.hadoop.hbase.testclassification.MediumTests;<a name="line.44"></a>
+<span class="sourceLineNo">045</span>import org.apache.hadoop.hbase.util.Bytes;<a name="line.45"></a>
+<span class="sourceLineNo">046</span>import org.apache.hadoop.hbase.util.FSUtils;<a name="line.46"></a>
+<span class="sourceLineNo">047</span>import org.apache.hadoop.hbase.wal.WAL;<a name="line.47"></a>
+<span class="sourceLineNo">048</span>import org.apache.hadoop.hbase.wal.WALEdit;<a name="line.48"></a>
+<span class="sourceLineNo">049</span>import org.apache.hadoop.hbase.wal.WALFactory;<a name="line.49"></a>
+<span class="sourceLineNo">050</span>import org.apache.hadoop.hbase.wal.WALKey;<a name="line.50"></a>
+<span class="sourceLineNo">051</span>import org.apache.hadoop.hbase.wal.WALSplitter;<a name="line.51"></a>
+<span class="sourceLineNo">052</span>import org.junit.ClassRule;<a name="line.52"></a>
+<span class="sourceLineNo">053</span>import org.junit.Rule;<a name="line.53"></a>
+<span class="sourceLineNo">054</span>import org.junit.Test;<a name="line.54"></a>
+<span class="sourceLineNo">055</span>import org.junit.experimental.categories.Category;<a name="line.55"></a>
+<span class="sourceLineNo">056</span>import org.junit.rules.TestName;<a name="line.56"></a>
+<span class="sourceLineNo">057</span>import org.slf4j.Logger;<a name="line.57"></a>
+<span class="sourceLineNo">058</span>import org.slf4j.LoggerFactory;<a name="line.58"></a>
+<span class="sourceLineNo">059</span><a name="line.59"></a>
+<span class="sourceLineNo">060</span>/**<a name="line.60"></a>
+<span class="sourceLineNo">061</span> * Tests around replay of recovered.edits content.<a name="line.61"></a>
+<span class="sourceLineNo">062</span> */<a name="line.62"></a>
+<span class="sourceLineNo">063</span>@Category({MediumTests.class})<a name="line.63"></a>
+<span class="sourceLineNo">064</span>public class TestRecoveredEdits {<a name="line.64"></a>
+<span class="sourceLineNo">065</span><a name="line.65"></a>
+<span class="sourceLineNo">066</span>  @ClassRule<a name="line.66"></a>
+<span class="sourceLineNo">067</span>  public static final HBaseClassTestRule CLASS_RULE =<a name="line.67"></a>
+<span class="sourceLineNo">068</span>      HBaseClassTestRule.forClass(TestRecoveredEdits.class);<a name="line.68"></a>
+<span class="sourceLineNo">069</span><a name="line.69"></a>
+<span class="sourceLineNo">070</span>  private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();<a name="line.70"></a>
+<span class="sourceLineNo">071</span>  private static final Logger LOG = LoggerFactory.getLogger(TestRecoveredEdits.class);<a name="line.71"></a>
+<span class="sourceLineNo">072</span>  @Rule public TestName testName = new TestName();<a name="line.72"></a>
+<span class="sourceLineNo">073</span><a name="line.73"></a>
+<span class="sourceLineNo">074</span>  /**<a name="line.74"></a>
+<span class="sourceLineNo">075</span>   * HBASE-12782 ITBLL fails for me if generator does anything but 5M per maptask.<a name="line.75"></a>
+<span class="sourceLineNo">076</span>   * Create a region. Close it. Then copy into place a file to replay, one that is bigger than<a name="line.76"></a>
+<span class="sourceLineNo">077</span>   * configured flush size so we bring on lots of flushes.  Then reopen and confirm all edits<a name="line.77"></a>
+<span class="sourceLineNo">078</span>   * made it in.<a name="line.78"></a>
+<span class="sourceLineNo">079</span>   * @throws IOException<a name="line.79"></a>
+<span class="sourceLineNo">080</span>   */<a name="line.80"></a>
+<span class="sourceLineNo">081</span>  @Test<a name="line.81"></a>
+<span class="sourceLineNo">082</span>  public void testReplayWorksThoughLotsOfFlushing() throws<a name="line.82"></a>
+<span class="sourceLineNo">083</span>      IOException {<a name="line.83"></a>
+<span class="sourceLineNo">084</span>    CacheConfig.instantiateBlockCache(TEST_UTIL.getConfiguration());<a name="line.84"></a>
+<span class="sourceLineNo">085</span>    for(MemoryCompactionPolicy policy : MemoryCompactionPolicy.values()) {<a name="line.85"></a>
+<span class="sourceLineNo">086</span>      testReplayWorksWithMemoryCompactionPolicy(policy);<a name="line.86"></a>
+<span class="sourceLineNo">087</span>    }<a name="line.87"></a>
+<span class="sourceLineNo">088</span>  }<a name="line.88"></a>
+<span class="sourceLineNo">089</span><a name="line.89"></a>
+<span class="sourceLineNo">090</span>  private void testReplayWorksWithMemoryCompactionPolicy(MemoryCompactionPolicy policy) throws<a name="line.90"></a>
+<span class="sourceLineNo">091</span>    IOException {<a name="line.91"></a>
+<span class="sourceLineNo">092</span>    Configuration conf = new Configuration(TEST_UTIL.getConfiguration());<a name="line.92"></a>
+<span class="sourceLineNo">093</span>    // Set it so we flush every 1M or so.  Thats a lot.<a name="line.93"></a>
+<span class="sourceLineNo">094</span>    conf.setInt(HConstants.HREGION_MEMSTORE_FLUSH_SIZE, 1024*1024);<a name="line.94"></a>
+<span class="sourceLineNo">095</span>    conf.set(CompactingMemStore.COMPACTING_MEMSTORE_TYPE_KEY, String.valueOf(policy).toLowerCase());<a name="line.95"></a>
+<span class="sourceLineNo">096</span>    // The file of recovered edits has a column family of 'meta'. Also has an encoded regionname<a name="line.96"></a>
+<span class="sourceLineNo">097</span>    // of 4823016d8fca70b25503ee07f4c6d79f which needs to match on replay.<a name="line.97"></a>
+<span class="sourceLineNo">098</span>    final String encodedRegionName = "4823016d8fca70b25503ee07f4c6d79f";<a name="line.98"></a>
+<span class="sourceLineNo">099</span>    HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(testName.getMethodName()));<a name="line.99"></a>
+<span class="sourceLineNo">100</span>    final String columnFamily = "meta";<a name="line.100"></a>
+<span class="sourceLineNo">101</span>    byte [][] columnFamilyAsByteArray = new byte [][] {Bytes.toBytes(columnFamily)};<a name="line.101"></a>
+<span class="sourceLineNo">102</span>    htd.addFamily(new HColumnDescriptor(columnFamily));<a name="line.102"></a>
+<span class="sourceLineNo">103</span>    HRegionInfo hri = new HRegionInfo(htd.getTableName()) {<a name="line.103"></a>
+<span class="sourceLineNo">104</span>      @Override<a name="line.104"></a>
+<span class="sourceLineNo">105</span>      public synchronized String getEncodedName() {<a name="line.105"></a>
+<span class="sourceLineNo">106</span>        return encodedRegionName;<a name="line.106"></a>
+<span class="sourceLineNo">107</span>      }<a name="line.107"></a>
+<span class="sourceLineNo">108</span><a name="line.108"></a>
+<span class="sourceLineNo">109</span>      // Cache the name because lots of lookups.<a name="line.109"></a>
+<span class="sourceLineNo">110</span>      private byte [] encodedRegionNameAsBytes = null;<a name="line.110"></a>
+<span class="sourceLineNo">111</span>      @Override<a name="line.111"></a>
+<span class="sourceLineNo">112</span>      public synchronized byte[] getEncodedNameAsBytes() {<a name="line.112"></a>
+<span class="sourceLineNo">113</span>        if (encodedRegionNameAsBytes == null) {<a name="line.113"></a>
+<span class="sourceLineNo">114</span>          this.encodedRegionNameAsBytes = Bytes.toBytes(getEncodedName());<a name="line.114"></a>
+<span class="sourceLineNo">115</span>        }<a name="line.115"></a>
+<span class="sourceLineNo">116</span>        return this.encodedRegionNameAsBytes;<a name="line.116"></a>
+<span class="sourceLineNo">117</span>      }<a name="line.117"></a>
+<span class="sourceLineNo">118</span>    };<a name="line.118"></a>
+<span class="sourceLineNo">119</span>    Path hbaseRootDir = TEST_UTIL.getDataTestDir();<a name="line.119"></a>
+<span class="sourceLineNo">120</span>    ChunkCreator.initialize(MemStoreLABImpl.CHUNK_SIZE_DEFAULT, false, 0, 0, 0, null);<a name="line.120"></a>
+<span class="sourceLineNo">121</span>    FileSystem fs = FileSystem.get(TEST_UTIL.getConfiguration());<a name="line.121"></a>
+<span class="sourceLineNo">122</span>    Path tableDir = FSUtils.getTableDir(hbaseRootDir, htd.getTableName());<a name="line.122"></a>
+<span class="sourceLineNo">123</span>    HRegionFileSystem hrfs =<a name="line.123"></a>
+<span class="sourceLineNo">124</span>        new HRegionFileSystem(TEST_UTIL.getConfiguration(), fs, tableDir, hri);<a name="line.124"></a>
+<span class="sourceLineNo">125</span>    if (fs.exists(hrfs.getRegionDir())) {<a name="line.125"></a>
+<span class="sourceLineNo">126</span>      LOG.info("Region directory already exists. Deleting.");<a name="line.126"></a>
+<span class="sourceLineNo">127</span>      fs.delete(hrfs.getRegionDir(), true);<a name="line.127"></a>
+<span class="sourceLineNo">128</span>    }<a name="line.128"></a>
+<span class="sourceLineNo">129</span>    HRegion region = HRegion.createHRegion(hri, hbaseRootDir, conf, htd, null);<a name="line.129"></a>
+<span class="sourceLineNo">130</span>    assertEquals(encodedRegionName, region.getRegionInfo().getEncodedName());<a name="line.130"></a>
+<span class="sourceLineNo">131</span>    List&lt;String&gt; storeFiles = region.getStoreFileList(columnFamilyAsByteArray);<a name="line.131"></a>
+<span class="sourceLineNo">132</span>    // There should be no store files.<a name="line.132"></a>
+<span class="sourceLineNo">133</span>    assertTrue(storeFiles.isEmpty());<a name="line.133"></a>
+<span class="sourceLineNo">134</span>    region.close();<a name="line.134"></a>
+<span class="sourceLineNo">135</span>    Path regionDir = region.getRegionDir(hbaseRootDir, hri);<a name="line.135"></a>
+<span class="sourceLineNo">136</span>    Path recoveredEditsDir = WALSplitter.getRegionDirRecoveredEditsDir(regionDir);<a name="line.136"></a>
+<span class="sourceLineNo">137</span>    // This is a little fragile getting this path to a file of 10M of edits.<a name="line.137"></a>
+<span class="sourceLineNo">138</span>    Path recoveredEditsFile = new Path(<a name="line.138"></a>
+<span class="sourceLineNo">139</span>      System.getProperty("test.build.classes", "target/test-classes"),<a name="line.139"></a>
+<span class="sourceLineNo">140</span>        "0000000000000016310");<a name="line.140"></a>
+<span class="sourceLineNo">141</span>    // Copy this file under the region's recovered.edits dir so it is replayed on reopen.<a name="line.141"></a>
+<span class="sourceLineNo">142</span>    Path destination = new Path(recoveredEditsDir, recoveredEditsFile.getName());<a name="line.142"></a>
+<span class="sourceLineNo">143</span>    fs.copyToLocalFile(recoveredEditsFile, destination);<a name="line.143"></a>
+<span class="sourceLineNo">144</span>    assertTrue(fs.exists(destination));<a name="line.144"></a>
+<span class="sourceLineNo">145</span>    // Now the file 0000000000000016310 is under recovered.edits, reopen the region to replay.<a name="line.145"></a>
+<span class="sourceLineNo">146</span>    region = HRegion.openHRegion(region, null);<a name="line.146"></a>
+<span class="sourceLineNo">147</span>    assertEquals(encodedRegionName, region.getRegionInfo().getEncodedName());<a name="line.147"></a>
+<span class="sourceLineNo">148</span>    storeFiles = region.getStoreFileList(columnFamilyAsByteArray);<a name="line.148"></a>
+<span class="sourceLineNo">149</span>    // Our 0000000000000016310 is 10MB. Most of the edits are for one region. Lets assume that if<a name="line.149"></a>
+<span class="sourceLineNo">150</span>    // we flush at 1MB, that there are at least 3 flushed files that are there because of the<a name="line.150"></a>
+<span class="sourceLineNo">151</span>    // replay of edits.<a name="line.151"></a>
+<span class="sourceLineNo">152</span>    if(policy == MemoryCompactionPolicy.EAGER || policy == MemoryCompactionPolicy.ADAPTIVE) {<a name="line.152"></a>
+<span class="sourceLineNo">153</span>      assertTrue("Files count=" + storeFiles.size(), storeFiles.size() &gt;= 1);<a name="line.153"></a>
+<span class="sourceLineNo">154</span>    } else {<a name="line.154"></a>
+<span class="sourceLineNo">155</span>      assertTrue("Files count=" + storeFiles.size(), storeFiles.size() &gt; 10);<a name="line.155"></a>
+<span class="sourceLineNo">156</span>    }<a name="line.156"></a>
+<span class="sourceLineNo">157</span>    // Now verify all edits made it into the region.<a name="line.157"></a>
+<span class="sourceLineNo">158</span>    int count = verifyAllEditsMadeItIn(fs, conf, recoveredEditsFile, region);<a name="line.158"></a>
+<span class="sourceLineNo">159</span>    LOG.info("Checked " + count + " edits made it in");<a name="line.159"></a>
+<span class="sourceLineNo">160</span>  }<a name="line.160"></a>
+<span class="sourceLineNo">161</span><a name="line.161"></a>
+<span class="sourceLineNo">162</span>  /**<a name="line.162"></a>
+<span class="sourceLineNo">163</span>   * @param fs<a name="line.163"></a>
+<span class="sourceLineNo">164</span>   * @param conf<a name="line.164"></a>
+<span class="sourceLineNo">165</span>   * @param edits<a name="line.165"></a>
+<span class="sourceLineNo">166</span>   * @param region<a name="line.166"></a>
+<span class="sourceLineNo">167</span>   * @return Return how many edits seen.<a name="line.167"></a>
+<span class="sourceLineNo">168</span>   * @throws IOException<a name="line.168"></a>
+<span class="sourceLineNo">169</span>   */<a name="line.169"></a>
+<span class="sourceLineNo">170</span>  private int verifyAllEditsMadeItIn(final FileSystem fs, final Configuration conf,<a name="line.170"></a>
+<span class="sourceLineNo">171</span>      final Path edits, final HRegion region)<a name="line.171"></a>
+<span class="sourceLineNo">172</span>  throws IOException {<a name="line.172"></a>
+<span class="sourceLineNo">173</span>    int count = 0;<a name="line.173"></a>
+<span class="sourceLineNo">174</span>    // Based on HRegion#replayRecoveredEdits<a name="line.174"></a>
+<span class="sourceLineNo">175</span>    WAL.Reader reader = null;<a name="line.175"></a>
+<span class="sourceLineNo">176</span>    try {<a name="line.176"></a>
+<span class="sourceLineNo">177</span>      reader = WALFactory.createReader(fs, edits, conf);<a name="line.177"></a>
+<span class="sourceLineNo">178</span>      WAL.Entry entry;<a name="line.178"></a>
+<span class="sourceLineNo">179</span>      while ((entry = reader.next()) != null) {<a name="line.179"></a>
+<span class="sourceLineNo">180</span>        WALKey key = entry.getKey();<a name="line.180"></a>
+<span class="sourceLineNo">181</span>        WALEdit val = entry.getEdit();<a name="line.181"></a>
+<span class="sourceLineNo">182</span>        count++;<a name="line.182"></a>
+<span class="sourceLineNo">183</span>        // Check this edit is for this region.<a name="line.183"></a>
+<span class="sourceLineNo">184</span>        if (!Bytes.equals(key.getEncodedRegionName(),<a name="line.184"></a>
+<span class="sourceLineNo">185</span>            region.getRegionInfo().getEncodedNameAsBytes())) {<a name="line.185"></a>
+<span class="sourceLineNo">186</span>          continue;<a name="line.186"></a>
+<span class="sourceLineNo">187</span>        }<a name="line.187"></a>
+<span class="sourceLineNo">188</span>        Cell previous = null;<a name="line.188"></a>
+<span class="sourceLineNo">189</span>        for (Cell cell: val.getCells()) {<a name="line.189"></a>
+<span class="sourceLineNo">190</span>          if (CellUtil.matchingFamily(cell, WALEdit.METAFAMILY)) continue;<a name="line.190"></a>
+<span class="sourceLineNo">191</span>          if (previous != null &amp;&amp; CellComparatorImpl.COMPARATOR.compareRows(previous, cell) == 0)<a name="line.191"></a>
+<span class="sourceLineNo">192</span>            continue;<a name="line.192"></a>
+<span class="sourceLineNo">193</span>          previous = cell;<a name="line.193"></a>
+<span class="sourceLineNo">194</span>          Get g = new Get(CellUtil.cloneRow(cell));<a name="line.194"></a>
+<span class="sourceLineNo">195</span>          Result r = region.get(g);<a name="line.195"></a>
+<span class="sourceLineNo">196</span>          boolean found = false;<a name="line.196"></a>
+<span class="sourceLineNo">197</span>          for (CellScanner scanner = r.cellScanner(); scanner.advance();) {<a name="line.197"></a>
+<span class="sourceLineNo">198</span>            Cell current = scanner.current();<a name="line.198"></a>
+<span class="sourceLineNo">199</span>            if (PrivateCellUtil.compareKeyIgnoresMvcc(CellComparatorImpl.COMPARATOR, cell,<a name="line.199"></a>
+<span class="sourceLineNo">200</span>              current) == 0) {<a name="line.200"></a>
+<span class="sourceLineNo">201</span>              found = true;<a name="line.201"></a>
+<span class="sourceLineNo">202</span>              break;<a name="line.202"></a>
+<span class="sourceLineNo">203</span>            }<a name="line.203"></a>
+<span class="sourceLineNo">204</span>          }<a name="line.204"></a>
+<span class="sourceLineNo">205</span>          assertTrue("Failed to find " + cell, found);<a name="line.205"></a>
+<span class="sourceLineNo">206</span>        }<a name="line.206"></a>
+<span class="sourceLineNo">207</span>      }<a name="line.207"></a>
+<span class="sourceLineNo">208</span>    } finally {<a name="line.208"></a>
+<span class="sourceLineNo">209</span>      if (reader != null) reader.close();<a name="line.209"></a>
+<span class="sourceLineNo">210</span>    }<a name="line.210"></a>
+<span class="sourceLineNo">211</span>    return count;<a name="line.211"></a>
+<span class="sourceLineNo">212</span>  }<a name="line.212"></a>
+<span class="sourceLineNo">213</span>}<a name="line.213"></a>
 
 
 


Mime
View raw message