From 7fccb0258ea1bc8fa952a5ebd629d1808ee4e6ee Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Tue, 20 Jan 2009 06:37:29 +0000 Subject: [PATCH] HBASE-1134 HashFunction inadvertently destroys some randomness git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@735947 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 2 ++ src/java/org/onelab/filter/HashFunction.java | 3 ++- src/test/org/onelab/test/TestFilter.java | 15 ++------------- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index ebe750ee122..f414e543846 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -5,6 +5,8 @@ Release 0.20.0 - Unreleased BUG FIXES HBASE-1140 "ant clean test" fails (Nitay Joffe via Stack) HBASE-1129 Master won't go down; stuck joined on rootScanner + HBASE-1136 HashFunction inadvertently destroys some randomness + (Jonathan Ellis via Stack) IMPROVEMENTS HBASE-1089 Add count of regions on filesystem to master UI; add percentage diff --git a/src/java/org/onelab/filter/HashFunction.java b/src/java/org/onelab/filter/HashFunction.java index a0c26964e2f..cf97c7bcaa2 100644 --- a/src/java/org/onelab/filter/HashFunction.java +++ b/src/java/org/onelab/filter/HashFunction.java @@ -118,7 +118,8 @@ public final class HashFunction { } int[] result = new int[nbHash]; for (int i = 0, initval = 0; i < nbHash; i++) { - initval = result[i] = Math.abs(hashFunction.hash(b, initval) % maxValue); + initval = hashFunction.hash(b, initval); + result[i] = Math.abs(initval) % maxValue; } return result; }//end hash() diff --git a/src/test/org/onelab/test/TestFilter.java b/src/test/org/onelab/test/TestFilter.java index 6c88c1ab33f..eb04d1afd84 100644 --- a/src/test/org/onelab/test/TestFilter.java +++ b/src/test/org/onelab/test/TestFilter.java @@ -266,7 +266,7 @@ public class TestFilter extends TestCase { * @throws UnsupportedEncodingException */ public void testCountingBloomFilter() throws UnsupportedEncodingException { - Filter bf = new CountingBloomFilter(8, 2, Hash.JENKINS_HASH); + Filter bf = new CountingBloomFilter(128, 2, Hash.JENKINS_HASH); Key key = new StringKey("toto"); Key k2 = new StringKey("lulu"); Key k3 = new StringKey("mama"); @@ -274,7 +274,6 @@ public class TestFilter extends TestCase { bf.add(k2); bf.add(k3); assertTrue(bf.membershipTest(key)); - assertTrue(bf.membershipTest(new StringKey("graknyl"))); assertFalse(bf.membershipTest(new StringKey("xyzzy"))); assertFalse(bf.membershipTest(new StringKey("abcd"))); @@ -282,15 +281,6 @@ public class TestFilter extends TestCase { ((CountingBloomFilter)bf).delete(key); assertFalse(bf.membershipTest(key)); - // OR 'key' back into the filter - Filter bf2 = new CountingBloomFilter(8, 2, Hash.JENKINS_HASH); - bf2.add(key); - bf.or(bf2); - assertTrue(bf.membershipTest(key)); - assertTrue(bf.membershipTest(new StringKey("graknyl"))); - assertFalse(bf.membershipTest(new StringKey("xyzzy"))); - assertFalse(bf.membershipTest(new StringKey("abcd"))); - // to test for overflows, add 'key' enough times to overflow a 4bit bucket, // while asserting that it stays a member for(int i = 0; i < 16; i++){ @@ -319,7 +309,7 @@ public class TestFilter extends TestCase { * @throws UnsupportedEncodingException */ public void testDynamicBloomFilter() throws UnsupportedEncodingException { - Filter bf = new DynamicBloomFilter(8, 2, Hash.JENKINS_HASH, 2); + Filter bf = new DynamicBloomFilter(128, 2, Hash.JENKINS_HASH, 2); Key key = new StringKey("toto"); Key k2 = new StringKey("lulu"); Key k3 = new StringKey("mama"); @@ -327,7 +317,6 @@ public class TestFilter extends TestCase { bf.add(k2); bf.add(k3); assertTrue(bf.membershipTest(key)); - assertTrue(bf.membershipTest(new StringKey("graknyl"))); assertFalse(bf.membershipTest(new StringKey("xyzzy"))); assertFalse(bf.membershipTest(new StringKey("abcd"))); }