cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eev...@apache.org
Subject svn commit: r932073 - in /cassandra/trunk: src/java/org/apache/cassandra/client/RingCache.java src/java/org/apache/cassandra/config/DatabaseDescriptor.java test/unit/org/apache/cassandra/client/TestRingCache.java
Date Thu, 08 Apr 2010 19:27:34 GMT
Author: eevans
Date: Thu Apr  8 19:27:34 2010
New Revision: 932073

URL: http://svn.apache.org/viewvc?rev=932073&view=rev
Log:
RingCache fixups in the wake of CASSANDRA-44

 * invoke DatabaseDescriptor.loadSchemas from RingCache ctor (needed
   now to populate DD's table list).
 * improved error handling in DD.getReplicaPlacementStrategyClass so that
   any future failures to call loadSchemas are easier to spot.
 * updated TestRingCache. This was never runnable as a unit test, (it
   requires a running instance), and doing static initialization is
   problematic now that RingCache's ctor throws IOExceptions.

Patch by eevans

Modified:
    cassandra/trunk/src/java/org/apache/cassandra/client/RingCache.java
    cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
    cassandra/trunk/test/unit/org/apache/cassandra/client/TestRingCache.java

Modified: cassandra/trunk/src/java/org/apache/cassandra/client/RingCache.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/client/RingCache.java?rev=932073&r1=932072&r2=932073&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/client/RingCache.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/client/RingCache.java Thu Apr  8 19:27:34
2010
@@ -24,6 +24,8 @@ import org.apache.cassandra.dht.IPartiti
 import org.apache.cassandra.dht.Token;
 import org.apache.cassandra.locator.AbstractReplicationStrategy;
 import org.apache.cassandra.locator.TokenMetadata;
+
+import java.io.IOException;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 
@@ -53,13 +55,16 @@ public class RingCache
     private final String keyspace;
     private TokenMetadata tokenMetadata;
 
-    public RingCache(String keyspace)
+    public RingCache(String keyspace) throws IOException
     {
         for (InetAddress seed : DatabaseDescriptor.getSeeds())
         {
             seeds_.add(seed.getHostAddress());
         }
+        
         this.keyspace = keyspace;
+        
+        DatabaseDescriptor.loadSchemas();
         refreshEndPointMap();
     }
 

Modified: cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java?rev=932073&r1=932072&r2=932073&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java Thu Apr 
8 19:27:34 2010
@@ -865,7 +865,10 @@ public class DatabaseDescriptor
 
     public static Class<? extends AbstractReplicationStrategy> getReplicaPlacementStrategyClass(String
table)
     {
-        return tables.get(table).strategyClass;
+    	KSMetaData meta = tables.get(table);
+    	if (meta == null)
+            throw new RuntimeException(table + " not found. Failure to call loadSchemas()
perhaps?");
+        return meta.strategyClass;
     }
     
     public static String getJobTrackerAddress()

Modified: cassandra/trunk/test/unit/org/apache/cassandra/client/TestRingCache.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/client/TestRingCache.java?rev=932073&r1=932072&r2=932073&view=diff
==============================================================================
--- cassandra/trunk/test/unit/org/apache/cassandra/client/TestRingCache.java (original)
+++ cassandra/trunk/test/unit/org/apache/cassandra/client/TestRingCache.java Thu Apr  8 19:27:34
2010
@@ -17,6 +17,7 @@
  */
 package org.apache.cassandra.client;
 
+import java.io.IOException;
 import java.net.InetAddress;
 import java.util.List;
 
@@ -35,16 +36,15 @@ import org.apache.thrift.transport.TTran
  */
 public class TestRingCache
 {
-    private static RingCache ringCache;
-    private static String keyspace = "Keyspace1";
-    private static Cassandra.Client thriftClient;
+    private RingCache ringCache;
+    private Cassandra.Client thriftClient;
 
-    static
+    public TestRingCache(String keyspace) throws IOException
     {
-        ringCache = new RingCache(keyspace);
+    	ringCache = new RingCache(keyspace);
     }
-
-    private static void setup(String server, int port) throws Exception
+    
+    private void setup(String server, int port) throws Exception
     {
         /* Establish a thrift connection to the cassandra instance */
         TSocket socket = new TSocket(server, port);
@@ -68,7 +68,7 @@ public class TestRingCache
     {
         int minRow;
         int maxRow;
-        String rowPrefix;
+        String rowPrefix, keyspace = "Keyspace1";
         if (args.length > 0)
         {
             keyspace = args[0];
@@ -82,22 +82,24 @@ public class TestRingCache
             maxRow = 10;
             rowPrefix = "row";
         }
+        
+        TestRingCache tester = new TestRingCache(keyspace);
 
         for (int nRows = minRow; nRows < maxRow; nRows++)
         {
             String row = rowPrefix + nRows;
             ColumnPath col = new ColumnPath("Standard1").setSuper_column(null).setColumn("col1".getBytes());
 
-            List<InetAddress> endPoints = ringCache.getEndPoint(row);
+            List<InetAddress> endPoints = tester.ringCache.getEndPoint(row);
             String hosts="";
             for (int i = 0; i < endPoints.size(); i++)
                 hosts = hosts + ((i > 0) ? "," : "") + endPoints.get(i);
             System.out.println("hosts with key " + row + " : " + hosts + "; choose " + endPoints.get(0));
 
             // now, read the row back directly from the host owning the row locally
-            setup(endPoints.get(0).getHostAddress(), DatabaseDescriptor.getRpcPort());
-            thriftClient.insert(keyspace, row, col, "val1".getBytes(), 1, ConsistencyLevel.ONE);
-            Column column=thriftClient.get(keyspace, row, col, ConsistencyLevel.ONE).column;
+            tester.setup(endPoints.get(0).getHostAddress(), DatabaseDescriptor.getRpcPort());
+            tester.thriftClient.insert(keyspace, row, col, "val1".getBytes(), 1, ConsistencyLevel.ONE);
+            Column column = tester.thriftClient.get(keyspace, row, col, ConsistencyLevel.ONE).column;
             System.out.println("read row " + row + " " + new String(column.name) + ":" +
new String(column.value) + ":" + column.timestamp);
         }
 



Mime
View raw message