Fix SSTable unintentionally loads BF in batch mode patch by yukim; reviewed by jbellis for CASSANDRA-5938
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/f5c9b4a8 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/f5c9b4a8 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/f5c9b4a8 Branch: refs/heads/cassandra-2.0.0 Commit: f5c9b4a8b9a7cabfd99e1f9b3978498a6bd55c39 Parents: 625d43f Author: Yuki Morishita <[email protected]> Authored: Mon Aug 26 11:37:32 2013 -0500 Committer: Yuki Morishita <[email protected]> Committed: Mon Aug 26 11:40:29 2013 -0500 ---------------------------------------------------------------------- CHANGES.txt | 1 + .../cassandra/io/sstable/SSTableReader.java | 12 ++++------ .../cassandra/utils/AlwaysPresentFilter.java | 24 +++++++++----------- .../apache/cassandra/utils/FilterFactory.java | 8 ++----- .../org/apache/cassandra/utils/IFilter.java | 8 ++++--- .../cassandra/utils/Murmur3BloomFilter.java | 6 +++++ 6 files changed, 30 insertions(+), 29 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/f5c9b4a8/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index 5e1caf7..cfc4845 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -2,6 +2,7 @@ * Fix thrift validation when inserting into CQL3 tables (CASSANDRA-5138) * Fix periodic memtable flushing behavior with clean memtables (CASSANDRA-5931) * Fix dateOf() function for pre-2.0 timestamp columns (CASSANDRA-5928) + * Fix SSTable unintentionally loads BF when opened for batch (CASSANDRA-5938) Merged from 1.2: * Fix getBloomFilterDiskSpaceUsed for AlwaysPresentFilter (CASSANDRA-5900) * Don't announce schema version until we've loaded the changes locally http://git-wip-us.apache.org/repos/asf/cassandra/blob/f5c9b4a8/src/java/org/apache/cassandra/io/sstable/SSTableReader.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/io/sstable/SSTableReader.java b/src/java/org/apache/cassandra/io/sstable/SSTableReader.java index 814790a..e593dfe 100644 --- a/src/java/org/apache/cassandra/io/sstable/SSTableReader.java +++ b/src/java/org/apache/cassandra/io/sstable/SSTableReader.java @@ -163,9 +163,9 @@ public class SSTableReader extends SSTable partitioner, System.currentTimeMillis(), sstableMetadata); - sstable.bf = new AlwaysPresentFilter(); // don't save index summary to disk if we needed to build one - sstable.load(true, false); + sstable.load(false, false); + sstable.bf = FilterFactory.AlwaysPresent; return sstable; } @@ -353,7 +353,7 @@ public class SSTableReader extends SSTable { // bf is disabled. load(false, true); - bf = new AlwaysPresentFilter(); + bf = FilterFactory.AlwaysPresent; } else if (!components.contains(Component.FILTER)) { @@ -580,7 +580,7 @@ public class SSTableReader extends SSTable */ public void forceFilterFailures() { - bf = new AlwaysPresentFilter(); + bf = FilterFactory.AlwaysPresent; } public IFilter getBloomFilter() @@ -590,9 +590,7 @@ public class SSTableReader extends SSTable public long getBloomFilterSerializedSize() { - if (bf instanceof AlwaysPresentFilter) - return 0; - return FilterFactory.serializedSize(bf); + return bf.serializedSize(); } /** http://git-wip-us.apache.org/repos/asf/cassandra/blob/f5c9b4a8/src/java/org/apache/cassandra/utils/AlwaysPresentFilter.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/utils/AlwaysPresentFilter.java b/src/java/org/apache/cassandra/utils/AlwaysPresentFilter.java index 67ac111..0f5136b 100644 --- a/src/java/org/apache/cassandra/utils/AlwaysPresentFilter.java +++ b/src/java/org/apache/cassandra/utils/AlwaysPresentFilter.java @@ -1,6 +1,4 @@ -package org.apache.cassandra.utils; /* - * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -8,18 +6,16 @@ package org.apache.cassandra.utils; * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ - +package org.apache.cassandra.utils; import java.io.IOException; import java.nio.ByteBuffer; @@ -36,4 +32,6 @@ public class AlwaysPresentFilter implements IFilter public void clear() { } public void close() throws IOException { } + + public long serializedSize() { return 0; } } http://git-wip-us.apache.org/repos/asf/cassandra/blob/f5c9b4a8/src/java/org/apache/cassandra/utils/FilterFactory.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/utils/FilterFactory.java b/src/java/org/apache/cassandra/utils/FilterFactory.java index c8b7b5d..e50cbda 100644 --- a/src/java/org/apache/cassandra/utils/FilterFactory.java +++ b/src/java/org/apache/cassandra/utils/FilterFactory.java @@ -31,8 +31,9 @@ import org.slf4j.LoggerFactory; public class FilterFactory { + public static final IFilter AlwaysPresent = new AlwaysPresentFilter(); + private static final Logger logger = LoggerFactory.getLogger(FilterFactory.class); - private static final TypeSizes TYPE_SIZES = TypeSizes.NATIVE; private static final long BITSET_EXCESS = 20; public static void serialize(IFilter bf, DataOutput output) throws IOException @@ -45,11 +46,6 @@ public class FilterFactory return Murmur3BloomFilter.serializer.deserialize(input, offheap); } - public static long serializedSize(IFilter bf) - { - return Murmur3BloomFilter.serializer.serializedSize((Murmur3BloomFilter) bf, TYPE_SIZES); - } - /** * @return A BloomFilter with the lowest practical false positive * probability for the given number of elements. http://git-wip-us.apache.org/repos/asf/cassandra/blob/f5c9b4a8/src/java/org/apache/cassandra/utils/IFilter.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/utils/IFilter.java b/src/java/org/apache/cassandra/utils/IFilter.java index 5e88155..10f6df2 100644 --- a/src/java/org/apache/cassandra/utils/IFilter.java +++ b/src/java/org/apache/cassandra/utils/IFilter.java @@ -22,9 +22,11 @@ import java.nio.ByteBuffer; public interface IFilter extends Closeable { - public abstract void add(ByteBuffer key); + void add(ByteBuffer key); - public abstract boolean isPresent(ByteBuffer key); + boolean isPresent(ByteBuffer key); - public abstract void clear(); + void clear(); + + long serializedSize(); } http://git-wip-us.apache.org/repos/asf/cassandra/blob/f5c9b4a8/src/java/org/apache/cassandra/utils/Murmur3BloomFilter.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/utils/Murmur3BloomFilter.java b/src/java/org/apache/cassandra/utils/Murmur3BloomFilter.java index ebd506c..2c0c45b 100644 --- a/src/java/org/apache/cassandra/utils/Murmur3BloomFilter.java +++ b/src/java/org/apache/cassandra/utils/Murmur3BloomFilter.java @@ -19,6 +19,7 @@ package org.apache.cassandra.utils; import java.nio.ByteBuffer; +import org.apache.cassandra.db.TypeSizes; import org.apache.cassandra.utils.obs.IBitSet; public class Murmur3BloomFilter extends BloomFilter @@ -30,6 +31,11 @@ public class Murmur3BloomFilter extends BloomFilter super(hashes, bs); } + public long serializedSize() + { + return serializer.serializedSize(this, TypeSizes.NATIVE); + } + protected long[] hash(ByteBuffer b, int position, int remaining, long seed) { return MurmurHash.hash3_x64_128(b, b.position(), b.remaining(), seed);
