cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alek...@apache.org
Subject [5/7] cassandra git commit: NoReplicationTokenAllocator should support zero replication factor
Date Sun, 05 Feb 2017 17:02:06 GMT
NoReplicationTokenAllocator should support zero replication factor

Patch by Dikang Gu; reviewed by Branimir Lambov for CASSANDRA-12983


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/67cda763
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/67cda763
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/67cda763

Branch: refs/heads/cassandra-3.11
Commit: 67cda763b270a56bf5a7c73c6b30c3f9d651daab
Parents: a2dffc2
Author: Dikang Gu <dikang85@gmail.com>
Authored: Thu Dec 1 18:02:29 2016 -0800
Committer: Aleksey Yeschenko <aleksey@apache.org>
Committed: Sun Feb 5 16:59:08 2017 +0000

----------------------------------------------------------------------
 CHANGES.txt                                               |  1 +
 .../dht/tokenallocator/TokenAllocatorFactory.java         | 10 +++++++++-
 .../tokenallocator/NoReplicationTokenAllocatorTest.java   |  9 +++++++++
 3 files changed, 19 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/67cda763/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index d81d472..1851e62 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -3,6 +3,7 @@
  * nodetool stopdaemon errors out (CASSANDRA-13030)
  * Tables in system_distributed should not use gcgs of 0 (CASSANDRA-12954)
  * Fix primary index calculation for SASI (CASSANDRA-12910)
+ * NoReplicationTokenAllocator should work with zero replication factor (CASSANDRA-12983)
 Merged from 3.0:
  * Fix handling of partition with partition-level deletion plus
    live rows in sstabledump (CASSANDRA-13177)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/67cda763/src/java/org/apache/cassandra/dht/tokenallocator/TokenAllocatorFactory.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/dht/tokenallocator/TokenAllocatorFactory.java b/src/java/org/apache/cassandra/dht/tokenallocator/TokenAllocatorFactory.java
index f8c972d..d20de8f 100644
--- a/src/java/org/apache/cassandra/dht/tokenallocator/TokenAllocatorFactory.java
+++ b/src/java/org/apache/cassandra/dht/tokenallocator/TokenAllocatorFactory.java
@@ -21,17 +21,25 @@ package org.apache.cassandra.dht.tokenallocator;
 import java.net.InetAddress;
 import java.util.NavigableMap;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import org.apache.cassandra.dht.IPartitioner;
 import org.apache.cassandra.dht.Token;
 
 public class TokenAllocatorFactory
 {
+    private static final Logger logger = LoggerFactory.getLogger(TokenAllocatorFactory.class);
     public static TokenAllocator<InetAddress> createTokenAllocator(NavigableMap<Token,
InetAddress> sortedTokens,
                                                      ReplicationStrategy<InetAddress>
strategy,
                                                      IPartitioner partitioner)
     {
-        if(strategy.replicas() == 1)
+        if(strategy.replicas() == 1 || strategy.replicas() == 0)
+        {
+            logger.info("Using NoReplicationTokenAllocator.");
             return new NoReplicationTokenAllocator<>(sortedTokens, strategy, partitioner);
+        }
+        logger.info("Using ReplicationAwareTokenAllocator.");
         return new ReplicationAwareTokenAllocator<>(sortedTokens, strategy, partitioner);
     }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/67cda763/test/long/org/apache/cassandra/dht/tokenallocator/NoReplicationTokenAllocatorTest.java
----------------------------------------------------------------------
diff --git a/test/long/org/apache/cassandra/dht/tokenallocator/NoReplicationTokenAllocatorTest.java
b/test/long/org/apache/cassandra/dht/tokenallocator/NoReplicationTokenAllocatorTest.java
index fdcc6b8..c53f788 100644
--- a/test/long/org/apache/cassandra/dht/tokenallocator/NoReplicationTokenAllocatorTest.java
+++ b/test/long/org/apache/cassandra/dht/tokenallocator/NoReplicationTokenAllocatorTest.java
@@ -55,6 +55,7 @@ public class NoReplicationTokenAllocatorTest extends TokenAllocatorTestBase
         for (int perUnitCount = 1; perUnitCount <= MAX_VNODE_COUNT; perUnitCount *= 4)
         {
             testNewCluster(perUnitCount, fixedTokenCount, new NoReplicationStrategy(), partitioner);
+            testNewCluster(perUnitCount, fixedTokenCount, new ZeroReplicationStrategy(),
partitioner);
         }
     }
 
@@ -87,6 +88,7 @@ public class NoReplicationTokenAllocatorTest extends TokenAllocatorTestBase
         for (int perUnitCount = 1; perUnitCount <= MAX_VNODE_COUNT; perUnitCount *= 4)
         {
             testExistingCluster(perUnitCount, fixedTokenCount, new NoReplicationStrategy(),
partitioner);
+            testExistingCluster(perUnitCount, fixedTokenCount, new ZeroReplicationStrategy(),
partitioner);
         }
     }
 
@@ -246,4 +248,11 @@ public class NoReplicationTokenAllocatorTest extends TokenAllocatorTestBase
         }
     }
 
+    static class ZeroReplicationStrategy extends NoReplicationStrategy
+    {
+        public int replicas()
+        {
+            return 0;
+        }
+    }
 }


Mime
View raw message