You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by jb...@apache.org on 2009/03/27 03:45:18 UTC

svn commit: r759004 - in /incubator/cassandra/trunk: conf/storage-conf.xml src/org/apache/cassandra/config/DatabaseDescriptor.java src/org/apache/cassandra/service/StorageService.java

Author: jbellis
Date: Fri Mar 27 02:45:18 2009
New Revision: 759004

URL: http://svn.apache.org/viewvc?rev=759004&view=rev
Log:
allow user-specified Partitioners

Modified:
    incubator/cassandra/trunk/conf/storage-conf.xml
    incubator/cassandra/trunk/src/org/apache/cassandra/config/DatabaseDescriptor.java
    incubator/cassandra/trunk/src/org/apache/cassandra/service/StorageService.java

Modified: incubator/cassandra/trunk/conf/storage-conf.xml
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/conf/storage-conf.xml?rev=759004&r1=759003&r2=759004&view=diff
==============================================================================
--- incubator/cassandra/trunk/conf/storage-conf.xml (original)
+++ incubator/cassandra/trunk/conf/storage-conf.xml Fri Mar 27 02:45:18 2009
@@ -1,6 +1,12 @@
 <Storage>
    <ClusterName>Test Cluster</ClusterName>
-   <HashingStrategy>RANDOM</HashingStrategy>
+   <!-- 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.
+        Range queries require using OrderPreservingPartitioner or a subclass. -->
+   <Partitioner>org.apache.cassandra.dht.RandomPartitioner</Partitioner>
    <RackAware>false</RackAware>
    <MulticastChannel>230.0.0.1</MulticastChannel>
    <ReplicationFactor>1</ReplicationFactor>

Modified: incubator/cassandra/trunk/src/org/apache/cassandra/config/DatabaseDescriptor.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/org/apache/cassandra/config/DatabaseDescriptor.java?rev=759004&r1=759003&r2=759004&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/org/apache/cassandra/config/DatabaseDescriptor.java (original)
+++ incubator/cassandra/trunk/src/org/apache/cassandra/config/DatabaseDescriptor.java Fri Mar 27 02:45:18 2009
@@ -89,7 +89,7 @@
     */
     private static Map<String, Map<String, CFMetaData>> tableToCFMetaDataMap_;
     /* Hashing strategy Random or OPHF */
-    private static String hashingStrategy_ = DatabaseDescriptor.random_;
+    private static String partitionerClass_;
     /* if the size of columns or super-columns are more than this, indexing will kick in */
     private static int columnIndexSizeInKB_;
     /* Size of touch key cache */
@@ -138,7 +138,7 @@
             zkAddress_ = xmlUtils.getNodeValue("/Storage/ZookeeperAddress");
 
             /* Hashing strategy */
-            hashingStrategy_ = xmlUtils.getNodeValue("/Storage/HashingStrategy");
+            partitionerClass_ = xmlUtils.getNodeValue("/Storage/Partitioner");
             /* Callout location */
             calloutLocation_ = xmlUtils.getNodeValue("/Storage/CalloutLocation");
 
@@ -469,9 +469,9 @@
 
 
     
-    public static String getHashingStrategy()
+    public static String getPartitionerClass()
     {
-        return hashingStrategy_;
+        return partitionerClass_;
     }
     
     public static String getZkAddress()

Modified: incubator/cassandra/trunk/src/org/apache/cassandra/service/StorageService.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/org/apache/cassandra/service/StorageService.java?rev=759004&r1=759003&r2=759004&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/org/apache/cassandra/service/StorageService.java (original)
+++ incubator/cassandra/trunk/src/org/apache/cassandra/service/StorageService.java Fri Mar 27 02:45:18 2009
@@ -21,6 +21,7 @@
 import java.io.File;
 import java.io.IOException;
 import java.lang.management.ManagementFactory;
+import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -434,14 +435,14 @@
 
     static
     {
-        String hashingStrategy = DatabaseDescriptor.getHashingStrategy();
-        if (DatabaseDescriptor.ophf_.equalsIgnoreCase(hashingStrategy))
+        try
         {
-            partitioner_ = new OrderPreservingPartitioner();
-        }        
-        else
+            Class cls = Class.forName(DatabaseDescriptor.getPartitionerClass());
+            partitioner_ = (IPartitioner) cls.getConstructor().newInstance();
+        }
+        catch (Exception e)
         {
-            partitioner_ = new RandomPartitioner();
+            throw new RuntimeException(e);
         }
     }