From 57a53acad4c7991efbc63ee8c2bc227dd0873c54 Mon Sep 17 00:00:00 2001 From: Jason Lowe Date: Wed, 21 Jan 2015 19:04:29 +0000 Subject: [PATCH] HADOOP-11327. BloomFilter#not() omits the last bit, resulting in an incorrect filter. Contributed by Eric Payne (cherry picked from commit 07b08060369caf34f248745a10bda61fb0a3ef23) --- hadoop-common-project/hadoop-common/CHANGES.txt | 3 +++ .../org/apache/hadoop/util/bloom/BloomFilter.java | 2 +- .../apache/hadoop/util/bloom/TestBloomFilters.java | 11 +++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 7320642336b..91e31e3367c 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -375,6 +375,9 @@ Release 2.7.0 - UNRELEASED HADOOP-10668. TestZKFailoverControllerStress#testExpireBackAndForth occasionally fails. (Ming Ma via cnauroth) + HADOOP-11327. BloomFilter#not() omits the last bit, resulting in an + incorrect filter (Eric Payne via jlowe) + Release 2.6.0 - 2014-11-18 INCOMPATIBLE CHANGES diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/bloom/BloomFilter.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/bloom/BloomFilter.java index e2dea6d368d..f8b95192c82 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/bloom/BloomFilter.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/bloom/BloomFilter.java @@ -157,7 +157,7 @@ public class BloomFilter extends Filter { @Override public void not() { - bits.flip(0, vectorSize - 1); + bits.flip(0, vectorSize); } @Override diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/bloom/TestBloomFilters.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/bloom/TestBloomFilters.java index 93fa6d5195d..6ff854d1fb7 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/bloom/TestBloomFilters.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/bloom/TestBloomFilters.java @@ -23,6 +23,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.util.AbstractCollection; +import java.util.BitSet; import java.util.Iterator; import org.apache.hadoop.util.bloom.BloomFilterCommonTester.BloomFilterTestStrategy; @@ -237,4 +238,14 @@ public class TestBloomFilters { BloomFilterTestStrategy.FILTER_AND_STRATEGY, BloomFilterTestStrategy.FILTER_XOR_STRATEGY)).test(); } + + @Test + public void testNot() { + BloomFilter bf = new BloomFilter(8, 1, Hash.JENKINS_HASH); + bf.bits = BitSet.valueOf(new byte[] { (byte) 0x95 }); + BitSet origBitSet = (BitSet) bf.bits.clone(); + bf.not(); + assertFalse("BloomFilter#not should have inverted all bits", + bf.bits.intersects(origBitSet)); + } }