Updated Branches: refs/heads/trunk 55df844e0 -> 93685a478
Fix assertion in getRestrictedRange with Murmur3Partitioner patch by slebresne; reviewed by jbellis for CASSANDRA-4621 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/93685a47 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/93685a47 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/93685a47 Branch: refs/heads/trunk Commit: 93685a4780f2b03319f49a6cba17ef98ea22728e Parents: 55df844 Author: Sylvain Lebresne <sylv...@datastax.com> Authored: Tue Sep 11 17:43:08 2012 +0200 Committer: Sylvain Lebresne <sylv...@datastax.com> Committed: Tue Sep 11 17:43:08 2012 +0200 ---------------------------------------------------------------------- CHANGES.txt | 2 +- .../apache/cassandra/dht/Murmur3Partitioner.java | 24 +++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/93685a47/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index 5fcc7a4..58b3272 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -50,7 +50,7 @@ * (cql3) Add support for 2ndary indexes (CASSANDRA-3680) * (cql3) fix defining more than one PK to be invalid (CASSANDRA-4477) * remove schema agreement checking from all external APIs (Thrift, CQL and CQL3) (CASSANDRA-4487) - * add Murmur3Partitioner and make it default for new installations (CASSANDRA-3772) + * add Murmur3Partitioner and make it default for new installations (CASSANDRA-3772, 4621) * (cql3) update pseudo-map syntax to use map syntax (CASSANDRA-4497) * Finer grained exceptions hierarchy and provides error code with exceptions (CASSANDRA-3979) * Adds events push to binary protocol (CASSANDRA-4480) http://git-wip-us.apache.org/repos/asf/cassandra/blob/93685a47/src/java/org/apache/cassandra/dht/Murmur3Partitioner.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/dht/Murmur3Partitioner.java b/src/java/org/apache/cassandra/dht/Murmur3Partitioner.java index 3a3972b..440b159 100644 --- a/src/java/org/apache/cassandra/dht/Murmur3Partitioner.java +++ b/src/java/org/apache/cassandra/dht/Murmur3Partitioner.java @@ -35,7 +35,7 @@ import org.apache.cassandra.utils.MurmurHash; */ public class Murmur3Partitioner extends AbstractPartitioner<LongToken> { - public static final LongToken MINIMUM = new LongToken(0L); + public static final LongToken MINIMUM = new LongToken(Long.MIN_VALUE); public static final long MAXIMUM = Long.MAX_VALUE; public DecoratedKey convertFromDiskFormat(ByteBuffer key) @@ -74,18 +74,30 @@ public class Murmur3Partitioner extends AbstractPartitioner<LongToken> return MINIMUM; } + /** + * Generate the token of a key. + * Note that we need to ensure all generated token are strictly bigger than MINIMUM. + * In particular we don't want MINIMUM to correspond to any key because the range (MINIMUM, X] doesn't + * include MINIMUM but we use such range to select all data whose token is smaller than X. + */ public LongToken getToken(ByteBuffer key) { if (key.remaining() == 0) return MINIMUM; long hash = MurmurHash.hash3_x64_128(key, key.position(), key.remaining(), 0)[0]; - return new LongToken((hash < 0) ? -hash : hash); + return new LongToken(normalize(hash)); } public LongToken getRandomToken() { - return new LongToken(FBUtilities.threadLocalRandom().nextLong()); + return new LongToken(normalize(FBUtilities.threadLocalRandom().nextLong())); + } + + private long normalize(long v) + { + // We exclude the MINIMUM value; see getToken() + return v == Long.MIN_VALUE ? Long.MAX_VALUE : v; } public boolean preservesOrder() @@ -154,12 +166,6 @@ public class Murmur3Partitioner extends AbstractPartitioner<LongToken> try { Long i = Long.valueOf(token); - - if (i.compareTo(MINIMUM.token) < 0) - throw new ConfigurationException("Token must be >= 0"); - - if (i.compareTo(MAXIMUM) > 0) - throw new ConfigurationException("Token must be <= " + Long.MAX_VALUE); } catch (NumberFormatException e) {