|
@@ -19,18 +19,16 @@
|
|
|
*/
|
|
|
package org.apache.hadoop.hbase;
|
|
|
|
|
|
-import org.apache.log4j.Level;
|
|
|
-import org.apache.log4j.Logger;
|
|
|
-
|
|
|
+import org.apache.commons.logging.Log;
|
|
|
+import org.apache.commons.logging.LogFactory;
|
|
|
import org.apache.hadoop.io.Text;
|
|
|
|
|
|
/** Tests per-column bloom filters */
|
|
|
public class TestBloomFilters extends HBaseClusterTestCase {
|
|
|
+ static final Log LOG = LogFactory.getLog(TestBloomFilters.class);
|
|
|
+
|
|
|
private static final Text CONTENTS = new Text("contents:");
|
|
|
|
|
|
- private HTableDescriptor desc = null;
|
|
|
- private HTable table = null;
|
|
|
-
|
|
|
private static final Text[] rows = {
|
|
|
new Text("wmjwjzyv"),
|
|
|
new Text("baietibz"),
|
|
@@ -144,28 +142,40 @@ public class TestBloomFilters extends HBaseClusterTestCase {
|
|
|
/** constructor */
|
|
|
public TestBloomFilters() {
|
|
|
super();
|
|
|
- conf.set("hbase.hregion.maxunflushed", "90"); // flush cache every 100 writes
|
|
|
+ conf.set("hbase.hregion.memcache.flush.size", "100");// flush cache every 100 bytes
|
|
|
conf.set("hbase.regionserver.maxlogentries", "90"); // and roll log too
|
|
|
- Logger.getLogger(HRegion.class).setLevel(Level.DEBUG);
|
|
|
- Logger.getLogger(HStore.class).setLevel(Level.DEBUG);
|
|
|
}
|
|
|
|
|
|
- /** {@inheritDoc} */
|
|
|
- @Override
|
|
|
- public void setUp() {
|
|
|
+ /** Test that specifies explicit parameters for the bloom filter */
|
|
|
+ public void testExplicitParameters() {
|
|
|
+ HTable table = null;
|
|
|
try {
|
|
|
- super.setUp();
|
|
|
- this.desc = new HTableDescriptor("test");
|
|
|
+ // Setup
|
|
|
+ HTableDescriptor desc = new HTableDescriptor(getName());
|
|
|
+ BloomFilterDescriptor bloomFilter =
|
|
|
+ new BloomFilterDescriptor( // if we insert 1000 values
|
|
|
+ BloomFilterDescriptor.BloomFilterType.BLOOMFILTER, // plain old bloom filter
|
|
|
+ 12499, // number of bits
|
|
|
+ 4 // number of hash functions
|
|
|
+ );
|
|
|
+
|
|
|
desc.addFamily(
|
|
|
- new HColumnDescriptor(CONTENTS, 1, HColumnDescriptor.CompressionType.NONE,
|
|
|
- false, Integer.MAX_VALUE,
|
|
|
- new BloomFilterDescriptor( // if we insert 1000 values
|
|
|
- BloomFilterDescriptor.BLOOMFILTER, // plain old bloom filter
|
|
|
- 12499, // number of bits
|
|
|
- 4 // number of hash functions
|
|
|
- ))); // false positive = 0.0000001
|
|
|
+ new HColumnDescriptor(CONTENTS, // Column name
|
|
|
+ 1, // Max versions
|
|
|
+ HColumnDescriptor.CompressionType.NONE, // no compression
|
|
|
+ HColumnDescriptor.DEFAULT_IN_MEMORY, // not in memory
|
|
|
+ HColumnDescriptor.DEFAULT_MAX_VALUE_LENGTH,
|
|
|
+ bloomFilter
|
|
|
+ )
|
|
|
+ );
|
|
|
+
|
|
|
+ // Create the table
|
|
|
+
|
|
|
HBaseAdmin admin = new HBaseAdmin(conf);
|
|
|
admin.createTable(desc);
|
|
|
+
|
|
|
+ // Open table
|
|
|
+
|
|
|
table = new HTable(conf, desc.getName());
|
|
|
|
|
|
// Store some values
|
|
@@ -181,10 +191,78 @@ public class TestBloomFilters extends HBaseClusterTestCase {
|
|
|
e.printStackTrace();
|
|
|
fail();
|
|
|
}
|
|
|
+ try {
|
|
|
+ // Give cache flusher and log roller a chance to run
|
|
|
+ // Otherwise we'll never hit the bloom filter, just the memcache
|
|
|
+ Thread.sleep(conf.getLong(HConstants.THREAD_WAKE_FREQUENCY, 10 * 1000) * 2);
|
|
|
+
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ // ignore
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ try {
|
|
|
+ if (table != null) {
|
|
|
+ for(int i = 0; i < testKeys.length; i++) {
|
|
|
+ byte[] value = table.get(testKeys[i], CONTENTS);
|
|
|
+ if(value != null && value.length != 0) {
|
|
|
+ LOG.info("non existant key: " + testKeys[i] + " returned value: " +
|
|
|
+ new String(value, HConstants.UTF8_ENCODING));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ fail();
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ /** Test that uses computed for the bloom filter */
|
|
|
+ public void testComputedParameters() {
|
|
|
+ HTable table = null;
|
|
|
+ try {
|
|
|
+ // Setup
|
|
|
+ HTableDescriptor desc = new HTableDescriptor(getName());
|
|
|
+
|
|
|
+ BloomFilterDescriptor bloomFilter =
|
|
|
+ new BloomFilterDescriptor(
|
|
|
+ BloomFilterDescriptor.BloomFilterType.BLOOMFILTER, // plain old bloom filter
|
|
|
+ 1000 // estimated number of entries
|
|
|
+ );
|
|
|
+ LOG.info("vector size: " + bloomFilter.vectorSize);
|
|
|
+
|
|
|
+ desc.addFamily(
|
|
|
+ new HColumnDescriptor(CONTENTS, // Column name
|
|
|
+ 1, // Max versions
|
|
|
+ HColumnDescriptor.CompressionType.NONE, // no compression
|
|
|
+ HColumnDescriptor.DEFAULT_IN_MEMORY, // not in memory
|
|
|
+ HColumnDescriptor.DEFAULT_MAX_VALUE_LENGTH,
|
|
|
+ bloomFilter
|
|
|
+ )
|
|
|
+ );
|
|
|
+
|
|
|
+ // Create the table
|
|
|
+
|
|
|
+ HBaseAdmin admin = new HBaseAdmin(conf);
|
|
|
+ admin.createTable(desc);
|
|
|
+
|
|
|
+ // Open table
|
|
|
+
|
|
|
+ table = new HTable(conf, desc.getName());
|
|
|
+
|
|
|
+ // Store some values
|
|
|
|
|
|
- /** the test */
|
|
|
- public void testBloomFilters() {
|
|
|
+ for(int i = 0; i < 100; i++) {
|
|
|
+ Text row = rows[i];
|
|
|
+ String value = row.toString();
|
|
|
+ long lockid = table.startUpdate(rows[i]);
|
|
|
+ table.put(lockid, CONTENTS, value.getBytes(HConstants.UTF8_ENCODING));
|
|
|
+ table.commit(lockid);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ fail();
|
|
|
+ }
|
|
|
try {
|
|
|
// Give cache flusher and log roller a chance to run
|
|
|
// Otherwise we'll never hit the bloom filter, just the memcache
|
|
@@ -195,11 +273,13 @@ public class TestBloomFilters extends HBaseClusterTestCase {
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- for(int i = 0; i < testKeys.length; i++) {
|
|
|
- byte[] value = table.get(testKeys[i], CONTENTS);
|
|
|
- if(value != null && value.length != 0) {
|
|
|
- System.err.println("non existant key: " + testKeys[i] +
|
|
|
- " returned value: " + new String(value, HConstants.UTF8_ENCODING));
|
|
|
+ if (table != null) {
|
|
|
+ for(int i = 0; i < testKeys.length; i++) {
|
|
|
+ byte[] value = table.get(testKeys[i], CONTENTS);
|
|
|
+ if(value != null && value.length != 0) {
|
|
|
+ LOG.info("non existant key: " + testKeys[i] + " returned value: " +
|
|
|
+ new String(value, HConstants.UTF8_ENCODING));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|