mirror of https://github.com/apache/cassandra
make default OPP non-collating (compare is faster).
patch by jbellis; reviewed by Sammy Yu for CASSANDRA-339 git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/trunk@802186 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e24925d49e
commit
fa53f58871
|
|
@ -86,8 +86,11 @@
|
|||
<!-- Partitioner: any IPartitioner may be used, including your own
|
||||
as long as it is on the classpath. Out of the box,
|
||||
Cassandra provides
|
||||
org.apache.cassandra.dht.RandomPartitioner and
|
||||
org.apache.cassandra.dht.OrderPreservingPartitioner.
|
||||
org.apache.cassandra.dht.RandomPartitioner,
|
||||
org.apache.cassandra.dht.OrderPreservingPartitioner, and
|
||||
org.apache.cassandra.dht.CollatingOrderPreservingPartitioner.
|
||||
(CollatingOPP colates according to EN,US rules, not naive byte ordering.
|
||||
Use this as an example if you need locale-aware collation.)
|
||||
Range queries require using OrderPreservingPartitioner or a subclass.
|
||||
|
||||
Achtung! Changing this parameter requires wiping your data directories,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,55 @@
|
|||
/**
|
||||
* 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
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.apache.cassandra.dht;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.text.Collator;
|
||||
import java.util.Comparator;
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
|
||||
public class CollatingOrderPreservingPartitioner extends OrderPreservingPartitioner
|
||||
{
|
||||
static final Collator collator = Collator.getInstance(new Locale("en", "US"));
|
||||
|
||||
private static final Comparator<String> comparator = new Comparator<String>() {
|
||||
public int compare(String o1, String o2)
|
||||
{
|
||||
return collator.compare(o1, o2);
|
||||
}
|
||||
};
|
||||
private static final Comparator<String> reverseComparator = new Comparator<String>() {
|
||||
public int compare(String o1, String o2)
|
||||
{
|
||||
return -comparator.compare(o1, o2);
|
||||
}
|
||||
};
|
||||
|
||||
public Comparator<String> getDecoratedKeyComparator()
|
||||
{
|
||||
return comparator;
|
||||
}
|
||||
|
||||
public Comparator<String> getReverseDecoratedKeyComparator()
|
||||
{
|
||||
return reverseComparator;
|
||||
}
|
||||
}
|
||||
|
|
@ -19,29 +19,23 @@
|
|||
package org.apache.cassandra.dht;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.text.Collator;
|
||||
import java.util.Comparator;
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
|
||||
public class OrderPreservingPartitioner implements IPartitioner
|
||||
{
|
||||
// TODO make locale configurable. But don't just leave it up to the OS or you could really screw
|
||||
// people over if they deploy on nodes with different OS locales.
|
||||
static final Collator collator = Collator.getInstance(new Locale("en", "US"));
|
||||
|
||||
private static final Comparator<String> comparator = new Comparator<String>() {
|
||||
public int compare(String o1, String o2)
|
||||
{
|
||||
return collator.compare(o1, o2);
|
||||
return o1.compareTo(o2);
|
||||
}
|
||||
};
|
||||
private static final Comparator<String> reverseComparator = new Comparator<String>() {
|
||||
public int compare(String o1, String o2)
|
||||
{
|
||||
return -comparator.compare(o1, o2);
|
||||
return o2.compareTo(o1);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -126,4 +120,4 @@ public class OrderPreservingPartitioner implements IPartitioner
|
|||
{
|
||||
return new StringToken(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -18,6 +18,8 @@
|
|||
*/
|
||||
package org.apache.cassandra.dht;
|
||||
|
||||
import org.apache.cassandra.service.StorageService;
|
||||
|
||||
public class StringToken extends Token<String>
|
||||
{
|
||||
public StringToken(String token)
|
||||
|
|
@ -27,6 +29,7 @@ public class StringToken extends Token<String>
|
|||
|
||||
public int compareTo(Token<String> o)
|
||||
{
|
||||
return OrderPreservingPartitioner.collator.compare(this.token, o.token);
|
||||
assert StorageService.getPartitioner() instanceof OrderPreservingPartitioner;
|
||||
return StorageService.getPartitioner().getDecoratedKeyComparator().compare(this.token, o.token);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue