cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r1041250 - in /cassandra/branches/cassandra-0.7: ./ src/java/org/apache/cassandra/config/ src/java/org/apache/cassandra/locator/ src/java/org/apache/cassandra/service/ test/unit/org/apache/cassandra/dht/ test/unit/org/apache/cassandra/locat...
Date Thu, 02 Dec 2010 01:48:19 GMT
Author: jbellis
Date: Thu Dec  2 01:48:18 2010
New Revision: 1041250

URL: http://svn.apache.org/viewvc?rev=1041250&view=rev
Log:
fix consistencylevel calculations forNetworkTopologyStrategy
patch by jbellis; reviewed by Jon Hermes for CASSANDRA-1804

Modified:
    cassandra/branches/cassandra-0.7/CHANGES.txt
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/locator/AbstractReplicationStrategy.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/QuorumResponseHandler.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/StorageService.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/WriteResponseHandler.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/dht/BootStrapperTest.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/locator/OldNetworkTopologyStrategyTest.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/locator/SimpleStrategyTest.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/service/AntiEntropyServiceTest.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/service/MoveTest.java

Modified: cassandra/branches/cassandra-0.7/CHANGES.txt
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/CHANGES.txt?rev=1041250&r1=1041249&r2=1041250&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/CHANGES.txt (original)
+++ cassandra/branches/cassandra-0.7/CHANGES.txt Thu Dec  2 01:48:18 2010
@@ -23,6 +23,8 @@ dev
  * close file handle used for post-flush truncate (CASSANDRA-1790)
  * various code cleanup (CASSANDRA-1793, -1794, -1795)
  * fix range queries against wrapped range (CASSANDRA-1781)
+ * fix consistencylevel calculations for NetworkTopologyStrategy
+   (CASSANDRA-1804)
 
 
 0.7.0-rc1

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/config/DatabaseDescriptor.java?rev=1041250&r1=1041249&r2=1041250&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
(original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
Thu Dec  2 01:48:18 2010
@@ -815,11 +815,6 @@ public class    DatabaseDescriptor
         return conf.rpc_port;
     }
 
-    public static int getReplicationFactor(String table)
-    {
-        return tables.get(table).replicationFactor;
-    }
-
     public static long getRpcTimeout()
     {
         return conf.rpc_timeout_in_ms;

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/locator/AbstractReplicationStrategy.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/locator/AbstractReplicationStrategy.java?rev=1041250&r1=1041249&r2=1041250&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/locator/AbstractReplicationStrategy.java
(original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/locator/AbstractReplicationStrategy.java
Thu Dec  2 01:48:18 2010
@@ -125,10 +125,9 @@ public abstract class AbstractReplicatio
         return WriteResponseHandler.create(writeEndpoints, hintedEndpoints, consistencyLevel,
table);
     }
 
-    // instance method so test subclasses can override it
-    int getReplicationFactor()
+    public int getReplicationFactor()
     {
-       return DatabaseDescriptor.getReplicationFactor(table);
+        return DatabaseDescriptor.getTableDefinition(table).replicationFactor;
     }
 
     /**

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/QuorumResponseHandler.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/QuorumResponseHandler.java?rev=1041250&r1=1041249&r2=1041250&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/QuorumResponseHandler.java
(original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/QuorumResponseHandler.java
Thu Dec  2 01:48:18 2010
@@ -25,6 +25,7 @@ import java.util.concurrent.TimeoutExcep
 import java.io.IOException;
 
 import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.db.Table;
 import org.apache.cassandra.net.IAsyncCallback;
 import org.apache.cassandra.net.Message;
 import org.apache.cassandra.net.MessagingService;
@@ -110,9 +111,9 @@ public class QuorumResponseHandler<T> im
             case ANY:
                 return 1;
             case QUORUM:
-                return (DatabaseDescriptor.getReplicationFactor(table) / 2) + 1;
+                return (Table.open(table).getReplicationStrategy().getReplicationFactor()
/ 2) + 1;
             case ALL:
-                return DatabaseDescriptor.getReplicationFactor(table);
+                return Table.open(table).getReplicationStrategy().getReplicationFactor();
             default:
                 throw new UnsupportedOperationException("invalid consistency level: " + table.toString());
         }

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/StorageService.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/StorageService.java?rev=1041250&r1=1041249&r2=1041250&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/StorageService.java
(original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/StorageService.java
Thu Dec  2 01:48:18 2010
@@ -1738,7 +1738,7 @@ public class StorageService implements I
         for (String table : DatabaseDescriptor.getNonSystemTables())
         {
             // if the replication factor is 1 the data is lost so we shouldn't wait for confirmation
-            if (DatabaseDescriptor.getReplicationFactor(table) == 1)
+            if (Table.open(table).getReplicationStrategy().getReplicationFactor() == 1)
                 continue;
 
             // get all ranges that change ownership (that is, a node needs

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/WriteResponseHandler.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/WriteResponseHandler.java?rev=1041250&r1=1041249&r2=1041250&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/WriteResponseHandler.java
(original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/service/WriteResponseHandler.java
Thu Dec  2 01:48:18 2010
@@ -26,6 +26,7 @@ import java.util.concurrent.atomic.Atomi
 import com.google.common.collect.ImmutableMultimap;
 import com.google.common.collect.Multimap;
 import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.db.Table;
 import org.apache.cassandra.net.Message;
 import org.apache.cassandra.thrift.ConsistencyLevel;
 import org.apache.cassandra.thrift.UnavailableException;
@@ -93,9 +94,9 @@ public class WriteResponseHandler extend
         }
         // at most one node per range can bootstrap at a time, and these will be added to
the write until
         // bootstrap finishes (at which point we no longer need to write to the old ones).
-        assert 1 <= blockFor && blockFor <= 2 * DatabaseDescriptor.getReplicationFactor(table)
+        assert 1 <= blockFor && blockFor <= 2 * Table.open(table).getReplicationStrategy().getReplicationFactor()
             : String.format("invalid response count %d for replication factor %d",
-                            blockFor, DatabaseDescriptor.getReplicationFactor(table));
+                            blockFor, Table.open(table).getReplicationStrategy().getReplicationFactor());
         return blockFor;
     }
 

Modified: cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/dht/BootStrapperTest.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/dht/BootStrapperTest.java?rev=1041250&r1=1041249&r2=1041250&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/dht/BootStrapperTest.java
(original)
+++ cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/dht/BootStrapperTest.java
Thu Dec  2 01:48:18 2010
@@ -33,6 +33,7 @@ import org.junit.Test;
 
 import com.google.common.collect.Multimap;
 
+import org.apache.cassandra.db.Table;
 import org.apache.cassandra.gms.ApplicationState;
 import org.apache.cassandra.gms.IFailureDetectionEventListener;
 import org.apache.cassandra.gms.IFailureDetector;
@@ -146,7 +147,7 @@ public class BootStrapperTest extends Cl
         final int[] clusterSizes = new int[] { 1, 3, 5, 10, 100};
         for (String table : DatabaseDescriptor.getNonSystemTables())
         {
-            int replicationFactor = DatabaseDescriptor.getReplicationFactor(table);
+            int replicationFactor = Table.open(table).getReplicationStrategy().getReplicationFactor();
             for (int clusterSize : clusterSizes)
                 if (clusterSize >= replicationFactor)
                     testSourceTargetComputation(table, clusterSize, replicationFactor);

Modified: cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/locator/OldNetworkTopologyStrategyTest.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/locator/OldNetworkTopologyStrategyTest.java?rev=1041250&r1=1041249&r2=1041250&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/locator/OldNetworkTopologyStrategyTest.java
(original)
+++ cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/locator/OldNetworkTopologyStrategyTest.java
Thu Dec  2 01:48:18 2010
@@ -30,11 +30,12 @@ import org.junit.Before;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
-import org.apache.cassandra.config.DatabaseDescriptor;
+
+import org.apache.cassandra.SchemaLoader;
 import org.apache.cassandra.dht.BigIntegerToken;
 import org.apache.cassandra.dht.Token;
 
-public class OldNetworkTopologyStrategyTest
+public class OldNetworkTopologyStrategyTest extends SchemaLoader
 {
     private List<Token> endpointTokens;
     private List<Token> keyTokens;
@@ -71,7 +72,7 @@ public class OldNetworkTopologyStrategyT
         expectedResults.put("25", buildResult("254.0.0.4", "254.0.0.1", "254.0.0.2"));
         expectedResults.put("35", buildResult("254.0.0.1", "254.0.0.2", "254.0.0.3"));
 
-        runTestForReplicatedTables(strategy);
+        testGetEndpoints(strategy, keyTokens.toArray(new Token[0]));
     }
 
     /**
@@ -96,7 +97,7 @@ public class OldNetworkTopologyStrategyT
         expectedResults.put("25", buildResult("254.0.0.4", "254.1.0.3", "254.0.0.1"));
         expectedResults.put("35", buildResult("254.0.0.1", "254.1.0.3", "254.0.0.2"));
 
-        runTestForReplicatedTables(strategy);
+        testGetEndpoints(strategy, keyTokens.toArray(new Token[0]));
     }
 
     /**
@@ -122,16 +123,7 @@ public class OldNetworkTopologyStrategyT
         expectedResults.put("25", buildResult("254.1.0.4", "254.0.0.1", "254.0.0.2"));
         expectedResults.put("35", buildResult("254.0.0.1", "254.0.1.3", "254.1.0.4"));
 
-        runTestForReplicatedTables(strategy);
-    }
-
-    private void runTestForReplicatedTables(AbstractReplicationStrategy strategy) throws
UnknownHostException
-    {
-        for (String table : DatabaseDescriptor.getNonSystemTables())
-        {
-            if (DatabaseDescriptor.getReplicationFactor(table) == 3)
-                testGetEndpoints(strategy, keyTokens.toArray(new Token[0]), table);
-        }
+        testGetEndpoints(strategy, keyTokens.toArray(new Token[0]));
     }
 
     private ArrayList<InetAddress> buildResult(String... addresses) throws UnknownHostException
@@ -156,7 +148,7 @@ public class OldNetworkTopologyStrategyT
         tmd.updateNormalToken(endpointToken, ep);
     }
 
-    private void testGetEndpoints(AbstractReplicationStrategy strategy, Token[] keyTokens,
String table) throws UnknownHostException
+    private void testGetEndpoints(AbstractReplicationStrategy strategy, Token[] keyTokens)
throws UnknownHostException
     {
         for (Token keyToken : keyTokens)
         {

Modified: cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/locator/SimpleStrategyTest.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/locator/SimpleStrategyTest.java?rev=1041250&r1=1041249&r2=1041250&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/locator/SimpleStrategyTest.java
(original)
+++ cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/locator/SimpleStrategyTest.java
Thu Dec  2 01:48:18 2010
@@ -94,7 +94,7 @@ public class SimpleStrategyTest extends 
             for (int i = 0; i < keyTokens.length; i++)
             {
                 List<InetAddress> endpoints = strategy.getNaturalEndpoints(keyTokens[i]);
-                assertEquals(DatabaseDescriptor.getReplicationFactor(table), endpoints.size());
+                assertEquals(strategy.getReplicationFactor(), endpoints.size());
                 List<InetAddress> correctEndpoints = new ArrayList<InetAddress>();
                 for (int j = 0; j < endpoints.size(); j++)
                     correctEndpoints.add(hosts.get((i + j + 1) % hosts.size()));
@@ -140,7 +140,7 @@ public class SimpleStrategyTest extends 
 
             StorageService.calculatePendingRanges(strategy, table);
 
-            int replicationFactor = DatabaseDescriptor.getReplicationFactor(table);
+            int replicationFactor = strategy.getReplicationFactor();
 
             for (int i = 0; i < keyTokens.length; i++)
             {

Modified: cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/service/AntiEntropyServiceTest.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/service/AntiEntropyServiceTest.java?rev=1041250&r1=1041249&r2=1041250&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/service/AntiEntropyServiceTest.java
(original)
+++ cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/service/AntiEntropyServiceTest.java
Thu Dec  2 01:48:18 2010
@@ -171,7 +171,7 @@ public class AntiEntropyServiceTest exte
     public void testGetNeighborsPlusOne() throws Throwable
     {
         // generate rf+1 nodes, and ensure that all nodes are returned
-        Set<InetAddress> expected = addTokens(1 + DatabaseDescriptor.getReplicationFactor(tablename));
+        Set<InetAddress> expected = addTokens(1 + Table.open(tablename).getReplicationStrategy().getReplicationFactor());
         expected.remove(FBUtilities.getLocalAddress());
         assertEquals(expected, AntiEntropyService.getNeighbors(tablename));
     }
@@ -182,7 +182,7 @@ public class AntiEntropyServiceTest exte
         TokenMetadata tmd = StorageService.instance.getTokenMetadata();
 
         // generate rf*2 nodes, and ensure that only neighbors specified by the ARS are returned
-        addTokens(2 * DatabaseDescriptor.getReplicationFactor(tablename));
+        addTokens(2 * Table.open(tablename).getReplicationStrategy().getReplicationFactor());
         AbstractReplicationStrategy ars = Table.open(tablename).getReplicationStrategy();
         Set<InetAddress> expected = new HashSet<InetAddress>();
         for (Range replicaRange : ars.getAddressRanges().get(FBUtilities.getLocalAddress()))

Modified: cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/service/MoveTest.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/service/MoveTest.java?rev=1041250&r1=1041249&r2=1041250&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/service/MoveTest.java
(original)
+++ cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/service/MoveTest.java
Thu Dec  2 01:48:18 2010
@@ -92,7 +92,7 @@ public class MoveTest extends CleanupHel
             strategy = getStrategy(table, tmd);
             for (Token token : keyTokens)
             {
-                int replicationFactor = DatabaseDescriptor.getReplicationFactor(table);
+                int replicationFactor = strategy.getReplicationFactor();
 
                 HashSet<InetAddress> actual = new HashSet<InetAddress>(tmd.getWriteEndpoints(token,
table, strategy.calculateNaturalEndpoints(token, tmd)));
                 HashSet<InetAddress> expected = new HashSet<InetAddress>();
@@ -217,7 +217,7 @@ public class MoveTest extends CleanupHel
             }
 
             // just to be sure that things still work according to the old tests, run them:
-            if (DatabaseDescriptor.getReplicationFactor(table) != 3)
+            if (strategy.getReplicationFactor() != 3)
                 continue;
             // tokens 5, 15 and 25 should go three nodes
             for (int i=0; i<3; ++i)
@@ -334,7 +334,7 @@ public class MoveTest extends CleanupHel
                 assertTrue(expectedEndpoints.get(table).get(keyTokens.get(i)).containsAll(endpoints));
             }
 
-            if (DatabaseDescriptor.getReplicationFactor(table) != 3)
+            if (strategy.getReplicationFactor() != 3)
                 continue;
             // leave this stuff in to guarantee the old tests work the way they were supposed
to.
             // tokens 5, 15 and 25 should go three nodes



Mime
View raw message