cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r802186 - in /incubator/cassandra/trunk: conf/ src/java/org/apache/cassandra/dht/
Date Fri, 07 Aug 2009 20:57:09 GMT
Author: jbellis
Date: Fri Aug  7 20:57:08 2009
New Revision: 802186

URL: http://svn.apache.org/viewvc?rev=802186&view=rev
Log:
make default OPP non-collating (compare is faster).
patch by jbellis; reviewed by Sammy Yu for CASSANDRA-339

Added:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/dht/CollatingOrderPreservingPartitioner.java
Modified:
    incubator/cassandra/trunk/conf/storage-conf.xml
    incubator/cassandra/trunk/src/java/org/apache/cassandra/dht/OrderPreservingPartitioner.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/dht/StringToken.java

Modified: incubator/cassandra/trunk/conf/storage-conf.xml
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/conf/storage-conf.xml?rev=802186&r1=802185&r2=802186&view=diff
==============================================================================
--- incubator/cassandra/trunk/conf/storage-conf.xml (original)
+++ incubator/cassandra/trunk/conf/storage-conf.xml Fri Aug  7 20:57:08 2009
@@ -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,

Added: 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=802186&view=auto
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/dht/CollatingOrderPreservingPartitioner.java
(added)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/dht/CollatingOrderPreservingPartitioner.java
Fri Aug  7 20:57:08 2009
@@ -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;
+    }
+}

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/dht/OrderPreservingPartitioner.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/dht/OrderPreservingPartitioner.java?rev=802186&r1=802185&r2=802186&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/dht/OrderPreservingPartitioner.java
(original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/dht/OrderPreservingPartitioner.java
Fri Aug  7 20:57:08 2009
@@ -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 @@
     {
         return new StringToken(key);
     }
-}
+}
\ No newline at end of file

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/dht/StringToken.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/dht/StringToken.java?rev=802186&r1=802185&r2=802186&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/dht/StringToken.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/dht/StringToken.java Fri Aug 
7 20:57:08 2009
@@ -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 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);
     }
 }



Mime
View raw message