Author: jbellis
Date: Fri Jan 29 19:31:32 2010
New Revision: 904605
URL: http://svn.apache.org/viewvc?rev=904605&view=rev
Log:
make empty strings always return the MINIMUM token, and DecoratedKeys
containing the MINIMUM token always be considered empty. This is something we
probably should be doing anyway for consistency. (It was already true for OPP,
but not COPP or RP.)
No further special casing should be necessary because we have already
abstracted out code that needs to work across multiple partitioners to use
IPartitioner.isEmpty, including getRangeSlice.
patch by jbellis; reviewed by Stu Hood for CASSANDRA-745
Modified:
incubator/cassandra/trunk/src/java/org/apache/cassandra/db/DecoratedKey.java
incubator/cassandra/trunk/src/java/org/apache/cassandra/dht/CollatingOrderPreservingPartitioner.java
incubator/cassandra/trunk/src/java/org/apache/cassandra/dht/RandomPartitioner.java
incubator/cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java
incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/CompactionsTest.java
Modified:
incubator/cassandra/trunk/src/java/org/apache/cassandra/db/DecoratedKey.java
URL:
http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/DecoratedKey.java?rev=904605&r1=904604&r2=904605&view=diff
==============================================================================
---
incubator/cassandra/trunk/src/java/org/apache/cassandra/db/DecoratedKey.java
(original)
+++
incubator/cassandra/trunk/src/java/org/apache/cassandra/db/DecoratedKey.java
Fri Jan 29 19:31:32 2010
@@ -23,9 +23,11 @@
import java.io.DataInput;
import java.util.Comparator;
+import org.apache.cassandra.dht.IPartitioner;
import org.apache.cassandra.dht.Token;
import org.apache.cassandra.io.ICompactSerializer2;
import org.apache.cassandra.io.util.DataOutputBuffer;
+import org.apache.cassandra.service.StorageService;
import org.apache.cassandra.utils.FBUtilities;
/**
@@ -40,6 +42,7 @@
public class DecoratedKey<T extends Token> implements Comparable<DecoratedKey>
{
private static DecoratedKeySerializer serializer = new
DecoratedKeySerializer();
+ private static IPartitioner partitioner = StorageService.getPartitioner();
public static DecoratedKeySerializer serializer()
{
@@ -68,11 +71,7 @@
@Override
public int hashCode()
{
- final int prime = 31;
- int result = 1;
- result = prime * result + ((key == null) ? 0 : key.hashCode());
- result = prime * result + ((token == null) ? 0 : token.hashCode());
- return result;
+ return token.hashCode();
}
@Override
@@ -96,7 +95,7 @@
public boolean isEmpty()
{
- return key != null && key.isEmpty();
+ return token.equals(partitioner.getMinimumToken());
}
@Override
Modified:
incubator/cassandra/trunk/src/java/org/apache/cassandra/dht/CollatingOrderPreservingPartitioner.java
URL:
http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/dht/CollatingOrderPreservingPartitioner.java?rev=904605&r1=904604&r2=904605&view=diff
==============================================================================
---
incubator/cassandra/trunk/src/java/org/apache/cassandra/dht/CollatingOrderPreservingPartitioner.java
(original)
+++
incubator/cassandra/trunk/src/java/org/apache/cassandra/dht/CollatingOrderPreservingPartitioner.java
Fri Jan 29 19:31:32 2010
@@ -25,6 +25,8 @@
import java.util.Locale;
import java.util.Random;
+import org.apache.commons.lang.ArrayUtils;
+
import org.apache.cassandra.db.DecoratedKey;
import org.apache.cassandra.utils.FBUtilities;
import org.apache.cassandra.utils.Pair;
@@ -33,7 +35,7 @@
{
static final Collator collator = Collator.getInstance(new Locale("en",
"US"));
- public static final BytesToken MINIMUM = new BytesToken(new byte[0]);
+ public static final BytesToken MINIMUM = new
BytesToken(ArrayUtils.EMPTY_BYTE_ARRAY);
public static final BigInteger BYTE_MASK = new BigInteger("255");
@@ -146,6 +148,8 @@
public BytesToken getToken(String key)
{
+ if (key.isEmpty())
+ return MINIMUM;
return new BytesToken(collator.getCollationKey(key).toByteArray());
}
}
Modified:
incubator/cassandra/trunk/src/java/org/apache/cassandra/dht/RandomPartitioner.java
URL:
http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/dht/RandomPartitioner.java?rev=904605&r1=904604&r2=904605&view=diff
==============================================================================
---
incubator/cassandra/trunk/src/java/org/apache/cassandra/dht/RandomPartitioner.java
(original)
+++
incubator/cassandra/trunk/src/java/org/apache/cassandra/dht/RandomPartitioner.java
Fri Jan 29 19:31:32 2010
@@ -113,6 +113,8 @@
public BigIntegerToken getToken(String key)
{
+ if (key.isEmpty())
+ return MINIMUM;
return new BigIntegerToken(FBUtilities.hash(key));
}
}
Modified:
incubator/cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java
URL:
http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java?rev=904605&r1=904604&r2=904605&view=diff
==============================================================================
---
incubator/cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java
(original)
+++
incubator/cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java
Fri Jan 29 19:31:32 2010
@@ -633,10 +633,6 @@
ThriftValidation.validateColumnParent(keyspace, column_parent);
ThriftValidation.validatePredicate(keyspace, column_parent, predicate);
- if (!StorageService.getPartitioner().preservesOrder())
- {
- throw new InvalidRequestException("range queries may only be
performed against an order-preserving partitioner");
- }
if (maxRows <= 0)
{
throw new InvalidRequestException("maxRows must be positive");
Modified:
incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/CompactionsTest.java
URL:
http://svn.apache.org/viewvc/incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/CompactionsTest.java?rev=904605&r1=904604&r2=904605&view=diff
==============================================================================
---
incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/CompactionsTest.java
(original)
+++
incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/CompactionsTest.java
Fri Jan 29 19:31:32 2010
@@ -27,6 +27,7 @@
import java.util.HashSet;
import java.util.Collection;
+import org.apache.cassandra.dht.IPartitioner;
import org.apache.cassandra.service.StorageService;
import org.junit.Test;
@@ -52,6 +53,7 @@
Table table = Table.open(TABLE1);
ColumnFamilyStore store = table.getColumnFamilyStore("Standard1");
DecoratedKey emptyKey =
StorageService.getPartitioner().decorateKey("");
+ assert
emptyKey.token.equals(StorageService.getPartitioner().getMinimumToken());
final int ROWS_PER_SSTABLE = 10;
Set<String> inserted = new HashSet<String>();