Skip to content

Commit

Permalink
[BLOOM] Fix Bloom filter ram usage calculation
Browse files Browse the repository at this point in the history
BloomFilter actually returned the size of the bitset as the
size in bytes so off by factor 8 plus a constant :)

Closes elastic#8564
  • Loading branch information
s1monw committed Nov 20, 2014
1 parent bb5c0ab commit da1331e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/main/java/org/elasticsearch/common/util/BloomFilter.java
Expand Up @@ -23,6 +23,7 @@
import org.apache.lucene.store.DataInput;
import org.apache.lucene.store.DataOutput;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.RamUsageEstimator;
import org.elasticsearch.ElasticsearchIllegalArgumentException;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Strings;
Expand Down Expand Up @@ -255,7 +256,7 @@ public int getNumHashFunctions() {
}

public long getSizeInBytes() {
return bits.bitSize() + 8;
return bits.ramBytesUsed();
}

@Override
Expand Down Expand Up @@ -376,6 +377,10 @@ void putAll(BitArray array) {
@Override public int hashCode() {
return Arrays.hashCode(data);
}

public long ramBytesUsed() {
return RamUsageEstimator.NUM_BYTES_LONG * data.length + RamUsageEstimator.NUM_BYTES_ARRAY_HEADER + 16;
}
}

static enum Hashing {
Expand Down
Expand Up @@ -24,10 +24,13 @@
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite;
import org.apache.lucene.codecs.Codec;
import org.apache.lucene.codecs.PostingsFormat;
import org.apache.lucene.index.BasePostingsFormatTestCase;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.TestUtil;
import org.apache.lucene.util.TimeUnits;
import org.elasticsearch.common.util.BloomFilter;
import org.elasticsearch.index.codec.postingsformat.BloomFilterPostingsFormat;
import org.elasticsearch.index.codec.postingsformat.Elasticsearch090PostingsFormat;
import org.elasticsearch.test.ElasticsearchThreadFilter;
import org.elasticsearch.test.junit.listeners.ReproduceInfoPrinter;
Expand All @@ -44,7 +47,9 @@ public class ElasticsearchPostingsFormatTest extends BasePostingsFormatTestCase

@Override
protected Codec getCodec() {
return TestUtil.alwaysPostingsFormat(new Elasticsearch090PostingsFormat());
return random().nextBoolean() ?
TestUtil.alwaysPostingsFormat(new Elasticsearch090PostingsFormat())
: TestUtil.alwaysPostingsFormat(new BloomFilterPostingsFormat(PostingsFormat.forName("Lucene41"), BloomFilter.Factory.DEFAULT));
}

}

0 comments on commit da1331e

Please sign in to comment.