cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject [1/2] git commit: Fix execution of LOCAL_QUORUM queries with SimpleStrategy
Date Wed, 08 Jan 2014 16:23:08 GMT
Updated Branches:
  refs/heads/cassandra-2.0 5fa605510 -> f8fd7db67


Fix execution of LOCAL_QUORUM queries with SimpleStrategy

patch by alexliu68; reviewed by slebresne for CASSANDRA-6545


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

Branch: refs/heads/cassandra-2.0
Commit: 32d7cb5066050ef6123f50a25c6e9b4c9e180ea0
Parents: 2a7c20e
Author: Sylvain Lebresne <sylvain@datastax.com>
Authored: Wed Jan 8 17:14:58 2014 +0100
Committer: Sylvain Lebresne <sylvain@datastax.com>
Committed: Wed Jan 8 17:15:20 2014 +0100

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../apache/cassandra/db/ConsistencyLevel.java   | 60 +++++++++++++-------
 .../locator/AbstractReplicationStrategy.java    |  2 +-
 3 files changed, 42 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/32d7cb50/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 5a85977..cba97d0 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -8,6 +8,7 @@
  * fsync compression metadata (CASSANDRA-6531)
  * Validate CF existence on execution for prepared statement (CASSANDRA-6535)
  * Add ability to throttle batchlog replay (CASSANDRA-6550)
+ * Fix executing LOCAL_QUORUM with SimpleStrategy (CASSANDRA-6545)
 
 
 1.2.13

http://git-wip-us.apache.org/repos/asf/cassandra/blob/32d7cb50/src/java/org/apache/cassandra/db/ConsistencyLevel.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/ConsistencyLevel.java b/src/java/org/apache/cassandra/db/ConsistencyLevel.java
index 4d72767..3737c73 100644
--- a/src/java/org/apache/cassandra/db/ConsistencyLevel.java
+++ b/src/java/org/apache/cassandra/db/ConsistencyLevel.java
@@ -88,9 +88,16 @@ public enum ConsistencyLevel
         return codeIdx[code];
     }
 
+    private int quorumFor(Table table)
+    {
+        return (table.getReplicationStrategy().getReplicationFactor() / 2) + 1;
+    }
+
     private int localQuorumFor(Table table, String dc)
     {
-        return (((NetworkTopologyStrategy) table.getReplicationStrategy()).getReplicationFactor(dc)
/ 2) + 1;
+        return (table.getReplicationStrategy() instanceof NetworkTopologyStrategy)
+             ? (((NetworkTopologyStrategy) table.getReplicationStrategy()).getReplicationFactor(dc)
/ 2) + 1
+             : quorumFor(table);
     }
 
     public int blockFor(Table table)
@@ -107,17 +114,24 @@ public enum ConsistencyLevel
             case THREE:
                 return 3;
             case QUORUM:
-                return (table.getReplicationStrategy().getReplicationFactor() / 2) + 1;
+                return quorumFor(table);
             case ALL:
                 return table.getReplicationStrategy().getReplicationFactor();
             case LOCAL_QUORUM:
                 return localQuorumFor(table, DatabaseDescriptor.getLocalDataCenter());
             case EACH_QUORUM:
-                NetworkTopologyStrategy strategy = (NetworkTopologyStrategy) table.getReplicationStrategy();
-                int n = 0;
-                for (String dc : strategy.getDatacenters())
-                    n += localQuorumFor(table, dc);
-                return n;
+                if (table.getReplicationStrategy() instanceof NetworkTopologyStrategy)
+                {
+                    NetworkTopologyStrategy strategy = (NetworkTopologyStrategy) table.getReplicationStrategy();
+                    int n = 0;
+                    for (String dc : strategy.getDatacenters())
+                        n += localQuorumFor(table, dc);
+                    return n;
+                }
+                else
+                {
+                    return quorumFor(table);
+                }
             default:
                 throw new UnsupportedOperationException("Invalid consistency level: " + toString());
         }
@@ -208,16 +222,20 @@ public enum ConsistencyLevel
                 // local hint is acceptable, and local node is always live
                 return true;
             case LOCAL_ONE:
-                    return countLocalEndpoints(liveEndpoints) >= 1;
+                return countLocalEndpoints(liveEndpoints) >= 1;
             case LOCAL_QUORUM:
                 return countLocalEndpoints(liveEndpoints) >= blockFor(table);
             case EACH_QUORUM:
-                for (Map.Entry<String, Integer> entry : countPerDCEndpoints(table,
liveEndpoints).entrySet())
+                if (table.getReplicationStrategy() instanceof NetworkTopologyStrategy)
                 {
-                    if (entry.getValue() < localQuorumFor(table, entry.getKey()))
-                        return false;
+                    for (Map.Entry<String, Integer> entry : countPerDCEndpoints(table,
liveEndpoints).entrySet())
+                    {
+                        if (entry.getValue() < localQuorumFor(table, entry.getKey()))
+                            return false;
+                    }
+                    return true;
                 }
-                return true;
+                // Fallthough on purpose for SimpleStrategy
             default:
                 return Iterables.size(liveEndpoints) >= blockFor(table);
         }
@@ -250,14 +268,18 @@ public enum ConsistencyLevel
                 }
                 break;
             case EACH_QUORUM:
-                for (Map.Entry<String, Integer> entry : countPerDCEndpoints(table,
liveEndpoints).entrySet())
+                if (table.getReplicationStrategy() instanceof NetworkTopologyStrategy)
                 {
-                    int dcBlockFor = localQuorumFor(table, entry.getKey());
-                    int dcLive = entry.getValue();
-                    if (dcLive < dcBlockFor)
-                        throw new UnavailableException(this, dcBlockFor, dcLive);
+                    for (Map.Entry<String, Integer> entry : countPerDCEndpoints(table,
liveEndpoints).entrySet())
+                    {
+                        int dcBlockFor = localQuorumFor(table, entry.getKey());
+                        int dcLive = entry.getValue();
+                        if (dcLive < dcBlockFor)
+                            throw new UnavailableException(this, dcBlockFor, dcLive);
+                    }
+                    break;
                 }
-                break;
+                // Fallthough on purpose for SimpleStrategy
             default:
                 int live = Iterables.size(liveEndpoints);
                 if (live < blockFor)
@@ -282,8 +304,6 @@ public enum ConsistencyLevel
 
     public void validateForWrite(String table) throws InvalidRequestException
     {
-        if(this == EACH_QUORUM)
-            requireNetworkTopologyStrategy(table);
     }
 
     public void validateCounterForWrite(CFMetaData metadata) throws InvalidRequestException

http://git-wip-us.apache.org/repos/asf/cassandra/blob/32d7cb50/src/java/org/apache/cassandra/locator/AbstractReplicationStrategy.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/locator/AbstractReplicationStrategy.java b/src/java/org/apache/cassandra/locator/AbstractReplicationStrategy.java
index a48bec9..e4dd422 100644
--- a/src/java/org/apache/cassandra/locator/AbstractReplicationStrategy.java
+++ b/src/java/org/apache/cassandra/locator/AbstractReplicationStrategy.java
@@ -134,7 +134,7 @@ public abstract class AbstractReplicationStrategy
             // block for in this context will be localnodes block.
             return new DatacenterWriteResponseHandler(naturalEndpoints, pendingEndpoints,
consistency_level, getTable(), callback, writeType);
         }
-        else if (consistency_level == ConsistencyLevel.EACH_QUORUM)
+        else if (consistency_level == ConsistencyLevel.EACH_QUORUM && (this instanceof
NetworkTopologyStrategy))
         {
             return new DatacenterSyncWriteResponseHandler(naturalEndpoints, pendingEndpoints,
consistency_level, getTable(), callback, writeType);
         }


Mime
View raw message