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
This commit is contained in:
Michael Stack 2009-01-20 06:37:29 +00:00
parent 781b10724f
commit 7fccb0258e
3 changed files with 6 additions and 14 deletions

View File

@ -5,6 +5,8 @@ Release 0.20.0 - Unreleased
BUG FIXES BUG FIXES
HBASE-1140 "ant clean test" fails (Nitay Joffe via Stack) HBASE-1140 "ant clean test" fails (Nitay Joffe via Stack)
HBASE-1129 Master won't go down; stuck joined on rootScanner HBASE-1129 Master won't go down; stuck joined on rootScanner
HBASE-1136 HashFunction inadvertently destroys some randomness
(Jonathan Ellis via Stack)
IMPROVEMENTS IMPROVEMENTS
HBASE-1089 Add count of regions on filesystem to master UI; add percentage HBASE-1089 Add count of regions on filesystem to master UI; add percentage

View File

@ -118,7 +118,8 @@ public final class HashFunction {
} }
int[] result = new int[nbHash]; int[] result = new int[nbHash];
for (int i = 0, initval = 0; i < nbHash; i++) { 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; return result;
}//end hash() }//end hash()

View File

@ -266,7 +266,7 @@ public class TestFilter extends TestCase {
* @throws UnsupportedEncodingException * @throws UnsupportedEncodingException
*/ */
public void testCountingBloomFilter() 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 key = new StringKey("toto");
Key k2 = new StringKey("lulu"); Key k2 = new StringKey("lulu");
Key k3 = new StringKey("mama"); Key k3 = new StringKey("mama");
@ -274,7 +274,6 @@ public class TestFilter extends TestCase {
bf.add(k2); bf.add(k2);
bf.add(k3); bf.add(k3);
assertTrue(bf.membershipTest(key)); assertTrue(bf.membershipTest(key));
assertTrue(bf.membershipTest(new StringKey("graknyl")));
assertFalse(bf.membershipTest(new StringKey("xyzzy"))); assertFalse(bf.membershipTest(new StringKey("xyzzy")));
assertFalse(bf.membershipTest(new StringKey("abcd"))); assertFalse(bf.membershipTest(new StringKey("abcd")));
@ -282,15 +281,6 @@ public class TestFilter extends TestCase {
((CountingBloomFilter)bf).delete(key); ((CountingBloomFilter)bf).delete(key);
assertFalse(bf.membershipTest(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, // to test for overflows, add 'key' enough times to overflow a 4bit bucket,
// while asserting that it stays a member // while asserting that it stays a member
for(int i = 0; i < 16; i++){ for(int i = 0; i < 16; i++){
@ -319,7 +309,7 @@ public class TestFilter extends TestCase {
* @throws UnsupportedEncodingException * @throws UnsupportedEncodingException
*/ */
public void testDynamicBloomFilter() 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 key = new StringKey("toto");
Key k2 = new StringKey("lulu"); Key k2 = new StringKey("lulu");
Key k3 = new StringKey("mama"); Key k3 = new StringKey("mama");
@ -327,7 +317,6 @@ public class TestFilter extends TestCase {
bf.add(k2); bf.add(k2);
bf.add(k3); bf.add(k3);
assertTrue(bf.membershipTest(key)); assertTrue(bf.membershipTest(key));
assertTrue(bf.membershipTest(new StringKey("graknyl")));
assertFalse(bf.membershipTest(new StringKey("xyzzy"))); assertFalse(bf.membershipTest(new StringKey("xyzzy")));
assertFalse(bf.membershipTest(new StringKey("abcd"))); assertFalse(bf.membershipTest(new StringKey("abcd")));
} }