cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r1080709 - in /cassandra/branches/cassandra-0.7: ./ src/java/org/apache/cassandra/locator/ test/unit/org/apache/cassandra/locator/
Date Fri, 11 Mar 2011 18:17:10 GMT
Author: jbellis
Date: Fri Mar 11 18:17:10 2011
New Revision: 1080709

URL: http://svn.apache.org/viewvc?rev=1080709&view=rev
Log:
allow zero replicas in a NTSdatacenter
patch by slebresne; reviewed by jbellis for CASSANDRA-1924

Modified:
    cassandra/branches/cassandra-0.7/CHANGES.txt
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/locator/TokenMetadata.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/locator/NetworkTopologyStrategyTest.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/locator/TokenMetadataTest.java

Modified: cassandra/branches/cassandra-0.7/CHANGES.txt
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/CHANGES.txt?rev=1080709&r1=1080708&r2=1080709&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/CHANGES.txt (original)
+++ cassandra/branches/cassandra-0.7/CHANGES.txt Fri Mar 11 18:17:10 2011
@@ -21,6 +21,7 @@
  * fix fd leak in sstable2json with non-mmap'd i/o (CASSANDRA-2304)
  * reduce memory use during streaming of multiple sstables (CASSANDRA-2301)
  * purge tombstoned rows from cache after GCGraceSeconds (CASSANDRA-2305)
+ * allow zero replicas in a NTS datacenter (CASSANDRA-1924)
 
 
 0.7.3

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/locator/TokenMetadata.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/locator/TokenMetadata.java?rev=1080709&r1=1080708&r2=1080709&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/locator/TokenMetadata.java
(original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/locator/TokenMetadata.java
Fri Mar 11 18:17:10 2011
@@ -410,6 +410,10 @@ public class TokenMetadata
      */
     public static Iterator<Token> ringIterator(final ArrayList<Token> ring, Token
start, boolean includeMin)
     {
+        if (ring.isEmpty())
+            return includeMin ? Iterators.singletonIterator(StorageService.getPartitioner().getMinimumToken())
+                              : Iterators.<Token>emptyIterator();
+
         final boolean insertMin = (includeMin && !ring.get(0).equals(StorageService.getPartitioner().getMinimumToken()))
? true : false;
         final int startIndex = firstTokenIndex(ring, start, insertMin);
         return new AbstractIterator<Token>()

Modified: cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/locator/NetworkTopologyStrategyTest.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/locator/NetworkTopologyStrategyTest.java?rev=1080709&r1=1080708&r2=1080709&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/locator/NetworkTopologyStrategyTest.java
(original)
+++ cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/locator/NetworkTopologyStrategyTest.java
Fri Mar 11 18:17:10 2011
@@ -44,7 +44,7 @@ public class NetworkTopologyStrategyTest
     {
         IEndpointSnitch snitch = new PropertyFileSnitch();
         TokenMetadata metadata = new TokenMetadata();
-        createDummyTokens(metadata);
+        createDummyTokens(metadata, true);
 
         Map<String, String> configOptions = new HashMap<String, String>();
         configOptions.put("DC1", "3");
@@ -62,7 +62,30 @@ public class NetworkTopologyStrategyTest
         assert 6 == new HashSet<InetAddress>(endpoints).size(); // ensure uniqueness
     }
 
-    public void createDummyTokens(TokenMetadata metadata) throws UnknownHostException
+    @Test
+    public void testPropertiesWithEmptyDC() throws IOException, ParserConfigurationException,
SAXException, ConfigurationException
+    {
+        IEndpointSnitch snitch = new PropertyFileSnitch();
+        TokenMetadata metadata = new TokenMetadata();
+        createDummyTokens(metadata, false);
+
+        Map<String, String> configOptions = new HashMap<String, String>();
+        configOptions.put("DC1", "3");
+        configOptions.put("DC2", "3");
+        configOptions.put("DC3", "0");
+
+        // Set the localhost to the tokenmetadata. Embedded cassandra way?
+        NetworkTopologyStrategy strategy = new NetworkTopologyStrategy(table, metadata, snitch,
configOptions);
+        assert strategy.getReplicationFactor("DC1") == 3;
+        assert strategy.getReplicationFactor("DC2") == 3;
+        assert strategy.getReplicationFactor("DC3") == 0;
+        // Query for the natural hosts
+        ArrayList<InetAddress> endpoints = strategy.getNaturalEndpoints(new StringToken("123"));
+        assert 6 == endpoints.size();
+        assert 6 == new HashSet<InetAddress>(endpoints).size(); // ensure uniqueness
+    }
+
+    public void createDummyTokens(TokenMetadata metadata, boolean populateDC3) throws UnknownHostException
     {
         // DC 1
         tokenFactory(metadata, "123", new byte[]{ 10, 0, 0, 10 });
@@ -72,11 +95,15 @@ public class NetworkTopologyStrategyTest
         tokenFactory(metadata, "789", new byte[]{ 10, 20, 114, 10 });
         tokenFactory(metadata, "890", new byte[]{ 10, 20, 114, 11 });
         //tokens for DC3
-        tokenFactory(metadata, "456", new byte[]{ 10, 21, 119, 13 });
-        tokenFactory(metadata, "567", new byte[]{ 10, 21, 119, 10 });
+        if (populateDC3)
+        {
+            tokenFactory(metadata, "456", new byte[]{ 10, 21, 119, 13 });
+            tokenFactory(metadata, "567", new byte[]{ 10, 21, 119, 10 });
+        }
         // Extra Tokens
         tokenFactory(metadata, "90A", new byte[]{ 10, 0, 0, 13 });
-        tokenFactory(metadata, "0AB", new byte[]{ 10, 21, 119, 14 });
+        if (populateDC3)
+            tokenFactory(metadata, "0AB", new byte[]{ 10, 21, 119, 14 });
         tokenFactory(metadata, "ABC", new byte[]{ 10, 20, 114, 15 });
     }
 

Modified: cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/locator/TokenMetadataTest.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/locator/TokenMetadataTest.java?rev=1080709&r1=1080708&r2=1080709&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/locator/TokenMetadataTest.java
(original)
+++ cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/locator/TokenMetadataTest.java
Fri Mar 11 18:17:10 2011
@@ -77,4 +77,11 @@ public class TokenMetadataTest
         testRingIterator("0", true, "1", "6", "");
         testRingIterator("", true, "1", "6", "");
     }
+
+    @Test
+    public void testRingIteratorEmptyRing()
+    {
+        RING.clear();
+        testRingIterator("2", false);
+    }
 }



Mime
View raw message