You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by ja...@apache.org on 2013/10/17 23:09:32 UTC

[3/7] git commit: apply local_one changes to 2.0

apply local_one changes to 2.0


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

Branch: refs/heads/cassandra-2.0
Commit: c9528f9c9c6c53779959419625ac6aaf3ed86025
Parents: b8b56c9
Author: Jason Brown <ja...@gmail.com>
Authored: Wed Oct 16 15:09:07 2013 -0700
Committer: Jason Brown <ja...@gmail.com>
Committed: Wed Oct 16 15:44:33 2013 -0700

----------------------------------------------------------------------
 bin/cqlsh                                       |  3 +-
 doc/cql3/CQL.textile                            |  1 +
 doc/native_protocol_v1.spec                     |  1 +
 doc/native_protocol_v2.spec                     |  1 +
 interface/cassandra.thrift                      |  5 +++-
 .../cassandra/thrift/ConsistencyLevel.java      |  7 ++++-
 .../cassandra/thrift/cassandraConstants.java    |  2 +-
 .../apache/cassandra/db/ConsistencyLevel.java   | 29 ++++++++++++++++----
 .../locator/AbstractReplicationStrategy.java    |  2 +-
 .../service/DatacenterWriteResponseHandler.java |  2 +-
 .../apache/cassandra/service/ReadCallback.java  |  2 +-
 .../cassandra/thrift/ThriftConversion.java      |  1 +
 12 files changed, 44 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/c9528f9c/bin/cqlsh
----------------------------------------------------------------------
diff --git a/bin/cqlsh b/bin/cqlsh
index 7883f9f..a062dcd 100755
--- a/bin/cqlsh
+++ b/bin/cqlsh
@@ -240,6 +240,7 @@ cqlsh_extra_syntax_rules = r'''
                      | "THREE"
                      | "QUORUM"
                      | "ALL"
+                     | "LOCAL_ONE"
                      | "LOCAL_QUORUM"
                      | "EACH_QUORUM"
                      ;
@@ -1757,7 +1758,7 @@ class Shell(cmd.Cmd):
 
            Valid consistency levels:
 
-           ANY, ONE, TWO, THREE, QUORUM, ALL, LOCAL_QUORUM and EACH_QUORUM.
+           ANY, ONE, TWO, THREE, QUORUM, ALL, LOCAL_ONE, LOCAL_QUORUM and EACH_QUORUM.
 
         CONSISTENCY
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/c9528f9c/doc/cql3/CQL.textile
----------------------------------------------------------------------
diff --git a/doc/cql3/CQL.textile b/doc/cql3/CQL.textile
index 63ec71a..c90b585 100644
--- a/doc/cql3/CQL.textile
+++ b/doc/cql3/CQL.textile
@@ -1039,6 +1039,7 @@ CQL distinguishes between _reserved_ and _non-reserved_ keywords. Reserved keywo
 | @KEYSPACE@     | yes |
 | @LEVEL@        | no  |
 | @LIMIT@        | yes |
+| @LOCAL_ONE@    | yes |
 | @LOCAL_QUORUM@ | yes |
 | @MODIFY@       | yes |
 | @NORECURSIVE@  | yes |

http://git-wip-us.apache.org/repos/asf/cassandra/blob/c9528f9c/doc/native_protocol_v1.spec
----------------------------------------------------------------------
diff --git a/doc/native_protocol_v1.spec b/doc/native_protocol_v1.spec
index b7a1de5..9e77276 100644
--- a/doc/native_protocol_v1.spec
+++ b/doc/native_protocol_v1.spec
@@ -201,6 +201,7 @@ Table of Contents
                      0x0005    ALL
                      0x0006    LOCAL_QUORUM
                      0x0007    EACH_QUORUM
+                     0x0010    EACH_ONE
 
     [string map]      A [short] n, followed by n pair <k><v> where <k> and <v>
                       are [string].

http://git-wip-us.apache.org/repos/asf/cassandra/blob/c9528f9c/doc/native_protocol_v2.spec
----------------------------------------------------------------------
diff --git a/doc/native_protocol_v2.spec b/doc/native_protocol_v2.spec
index b0449bb..28c769a 100644
--- a/doc/native_protocol_v2.spec
+++ b/doc/native_protocol_v2.spec
@@ -220,6 +220,7 @@ Table of Contents
                      0x0007    EACH_QUORUM
                      0x0008    SERIAL
                      0x0009    LOCAL_SERIAL
+                     0x0010    LOCAL_ONE
 
     [string map]      A [short] n, followed by n pair <k><v> where <k> and <v>
                       are [string].

http://git-wip-us.apache.org/repos/asf/cassandra/blob/c9528f9c/interface/cassandra.thrift
----------------------------------------------------------------------
diff --git a/interface/cassandra.thrift b/interface/cassandra.thrift
index c42554d..0948140 100644
--- a/interface/cassandra.thrift
+++ b/interface/cassandra.thrift
@@ -55,7 +55,7 @@ namespace rb CassandraThrift
 # An effort should be made not to break forward-client-compatibility either
 # (e.g. one should avoid removing obsolete fields from the IDL), but no
 # guarantees in this respect are made by the Cassandra project.
-const string VERSION = "19.37.0"
+const string VERSION = "19.38.0"
 
 
 #
@@ -212,6 +212,7 @@ exception SchemaDisagreementException {
  *   TWO          Ensure that the write has been written to at least 2 node's commit log and memory table
  *   THREE        Ensure that the write has been written to at least 3 node's commit log and memory table
  *   QUORUM       Ensure that the write has been written to <ReplicationFactor> / 2 + 1 nodes
+ *   LOCAL_ONE    Ensure that the write has been written to 1 node within the local datacenter (requires NetworkTopologyStrategy)
  *   LOCAL_QUORUM Ensure that the write has been written to <ReplicationFactor> / 2 + 1 nodes, within the local datacenter (requires NetworkTopologyStrategy)
  *   EACH_QUORUM  Ensure that the write has been written to <ReplicationFactor> / 2 + 1 nodes in each datacenter (requires NetworkTopologyStrategy)
  *   ALL          Ensure that the write is written to <code>&lt;ReplicationFactor&gt;</code> nodes before responding to the client.
@@ -222,6 +223,7 @@ exception SchemaDisagreementException {
  *   TWO          Returns the record with the most recent timestamp once two replicas have replied.
  *   THREE        Returns the record with the most recent timestamp once three replicas have replied.
  *   QUORUM       Returns the record with the most recent timestamp once a majority of replicas have replied.
+ *   LOCAL_ONE    Returns the record with the most recent timestamp once a single replica within the local datacenter have replied.
  *   LOCAL_QUORUM Returns the record with the most recent timestamp once a majority of replicas within the local datacenter have replied.
  *   EACH_QUORUM  Returns the record with the most recent timestamp once a majority of replicas within each datacenter have replied.
  *   ALL          Returns the record with the most recent timestamp once all replicas have replied (implies no replica may be down)..
@@ -237,6 +239,7 @@ enum ConsistencyLevel {
     THREE = 8,
     SERIAL = 9,
     LOCAL_SERIAL = 10,
+    LOCAL_ONE = 11,
 }
 
 /**

http://git-wip-us.apache.org/repos/asf/cassandra/blob/c9528f9c/interface/thrift/gen-java/org/apache/cassandra/thrift/ConsistencyLevel.java
----------------------------------------------------------------------
diff --git a/interface/thrift/gen-java/org/apache/cassandra/thrift/ConsistencyLevel.java b/interface/thrift/gen-java/org/apache/cassandra/thrift/ConsistencyLevel.java
index ea92479..ec5080a 100644
--- a/interface/thrift/gen-java/org/apache/cassandra/thrift/ConsistencyLevel.java
+++ b/interface/thrift/gen-java/org/apache/cassandra/thrift/ConsistencyLevel.java
@@ -60,6 +60,7 @@ import org.apache.thrift.TEnum;
  *   TWO          Ensure that the write has been written to at least 2 node's commit log and memory table
  *   THREE        Ensure that the write has been written to at least 3 node's commit log and memory table
  *   QUORUM       Ensure that the write has been written to <ReplicationFactor> / 2 + 1 nodes
+ *   LOCAL_ONE    Ensure that the write has been written to 1 node within the local datacenter (requires NetworkTopologyStrategy)
  *   LOCAL_QUORUM Ensure that the write has been written to <ReplicationFactor> / 2 + 1 nodes, within the local datacenter (requires NetworkTopologyStrategy)
  *   EACH_QUORUM  Ensure that the write has been written to <ReplicationFactor> / 2 + 1 nodes in each datacenter (requires NetworkTopologyStrategy)
  *   ALL          Ensure that the write is written to <code>&lt;ReplicationFactor&gt;</code> nodes before responding to the client.
@@ -70,6 +71,7 @@ import org.apache.thrift.TEnum;
  *   TWO          Returns the record with the most recent timestamp once two replicas have replied.
  *   THREE        Returns the record with the most recent timestamp once three replicas have replied.
  *   QUORUM       Returns the record with the most recent timestamp once a majority of replicas have replied.
+ *   LOCAL_ONE    Returns the record with the most recent timestamp once a single replica within the local datacenter have replied.
  *   LOCAL_QUORUM Returns the record with the most recent timestamp once a majority of replicas within the local datacenter have replied.
  *   EACH_QUORUM  Returns the record with the most recent timestamp once a majority of replicas within each datacenter have replied.
  *   ALL          Returns the record with the most recent timestamp once all replicas have replied (implies no replica may be down)..
@@ -84,7 +86,8 @@ public enum ConsistencyLevel implements org.apache.thrift.TEnum {
   TWO(7),
   THREE(8),
   SERIAL(9),
-  LOCAL_SERIAL(10);
+  LOCAL_SERIAL(10),
+  LOCAL_ONE(11);
 
   private final int value;
 
@@ -125,6 +128,8 @@ public enum ConsistencyLevel implements org.apache.thrift.TEnum {
         return SERIAL;
       case 10:
         return LOCAL_SERIAL;
+      case 11:
+        return LOCAL_ONE;
       default:
         return null;
     }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/c9528f9c/interface/thrift/gen-java/org/apache/cassandra/thrift/cassandraConstants.java
----------------------------------------------------------------------
diff --git a/interface/thrift/gen-java/org/apache/cassandra/thrift/cassandraConstants.java b/interface/thrift/gen-java/org/apache/cassandra/thrift/cassandraConstants.java
index c28519a..a2c482e 100644
--- a/interface/thrift/gen-java/org/apache/cassandra/thrift/cassandraConstants.java
+++ b/interface/thrift/gen-java/org/apache/cassandra/thrift/cassandraConstants.java
@@ -56,6 +56,6 @@ import org.slf4j.LoggerFactory;
 
 public class cassandraConstants {
 
-  public static final String VERSION = "19.37.0";
+  public static final String VERSION = "19.38.0";
 
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/c9528f9c/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 956ab58..5f17907 100644
--- a/src/java/org/apache/cassandra/db/ConsistencyLevel.java
+++ b/src/java/org/apache/cassandra/db/ConsistencyLevel.java
@@ -46,15 +46,17 @@ public enum ConsistencyLevel
     THREE       (3),
     QUORUM      (4),
     ALL         (5),
-    LOCAL_QUORUM(6),
+    LOCAL_QUORUM(6, true),
     EACH_QUORUM (7),
     SERIAL      (8),
-    LOCAL_SERIAL(9);
+    LOCAL_SERIAL(9),
+    LOCAL_ONE   (10, true);
 
     private static final Logger logger = LoggerFactory.getLogger(ConsistencyLevel.class);
 
     // Used by the binary protocol
     public final int code;
+    private final boolean isDCLocal;
     private static final ConsistencyLevel[] codeIdx;
     static
     {
@@ -72,7 +74,13 @@ public enum ConsistencyLevel
 
     private ConsistencyLevel(int code)
     {
+        this(code, false);
+    }
+
+    private ConsistencyLevel(int code, boolean isDCLocal)
+    {
         this.code = code;
+        this.isDCLocal = isDCLocal;
     }
 
     public static ConsistencyLevel fromCode(int code)
@@ -92,6 +100,7 @@ public enum ConsistencyLevel
         switch (this)
         {
             case ONE:
+            case LOCAL_ONE:
                 return 1;
             case ANY:
                 return 1;
@@ -116,6 +125,11 @@ public enum ConsistencyLevel
         }
     }
 
+    public boolean isDatacenterLocal()
+    {
+        return isDCLocal;
+    }
+
     private boolean isLocal(InetAddress endpoint)
     {
         return DatabaseDescriptor.getLocalDataCenter().equals(DatabaseDescriptor.getEndpointSnitch().getDatacenter(endpoint));
@@ -155,11 +169,11 @@ public enum ConsistencyLevel
     {
         /*
          * Endpoints are expected to be restricted to live replicas, sorted by snitch preference.
-         * For LOCAL_QORUM, move local-DC replicas in front first as we need them there whether
+         * For LOCAL_QUORUM, move local-DC replicas in front first as we need them there whether
          * we do read repair (since the first replica gets the data read) or not (since we'll take
          * the blockFor first ones).
          */
-        if (this == LOCAL_QUORUM)
+        if (isDCLocal)
             Collections.sort(liveEndpoints, DatabaseDescriptor.getLocalComparator());
 
         switch (readRepair)
@@ -195,6 +209,8 @@ public enum ConsistencyLevel
             case ANY:
                 // local hint is acceptable, and local node is always live
                 return true;
+            case LOCAL_ONE:
+                return countLocalEndpoints(liveEndpoints) >= 1;
             case LOCAL_QUORUM:
                 return countLocalEndpoints(liveEndpoints) >= blockFor(keyspace);
             case EACH_QUORUM:
@@ -260,6 +276,7 @@ public enum ConsistencyLevel
         switch (this)
         {
             case LOCAL_QUORUM:
+            case LOCAL_ONE:
                 requireNetworkTopologyStrategy(keyspaceName);
                 break;
             case ANY:
@@ -275,6 +292,7 @@ public enum ConsistencyLevel
         {
             case LOCAL_QUORUM:
             case EACH_QUORUM:
+            case LOCAL_ONE:
                 requireNetworkTopologyStrategy(keyspaceName);
                 break;
             case SERIAL:
@@ -290,6 +308,7 @@ public enum ConsistencyLevel
         {
             case LOCAL_QUORUM:
             case EACH_QUORUM:
+            case LOCAL_ONE:
                 requireNetworkTopologyStrategy(keyspaceName);
                 break;
             case SERIAL:
@@ -315,7 +334,7 @@ public enum ConsistencyLevel
         {
             throw new InvalidRequestException("Consistency level ANY is not yet supported for counter columnfamily " + metadata.cfName);
         }
-        else if (!metadata.getReplicateOnWrite() && this != ConsistencyLevel.ONE)
+        else if (!metadata.getReplicateOnWrite() && !(this == ConsistencyLevel.ONE || this == ConsistencyLevel.LOCAL_ONE))
         {
             throw new InvalidRequestException("cannot achieve CL > CL.ONE without replicate_on_write on columnfamily " + metadata.cfName);
         }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/c9528f9c/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 2a01fed..f83c889 100644
--- a/src/java/org/apache/cassandra/locator/AbstractReplicationStrategy.java
+++ b/src/java/org/apache/cassandra/locator/AbstractReplicationStrategy.java
@@ -122,7 +122,7 @@ public abstract class AbstractReplicationStrategy
 
     public AbstractWriteResponseHandler getWriteResponseHandler(Collection<InetAddress> naturalEndpoints, Collection<InetAddress> pendingEndpoints, ConsistencyLevel consistency_level, Runnable callback, WriteType writeType)
     {
-        if (consistency_level == ConsistencyLevel.LOCAL_QUORUM)
+        if (consistency_level.isDatacenterLocal())
         {
             // block for in this context will be localnodes block.
             return new DatacenterWriteResponseHandler(naturalEndpoints, pendingEndpoints, consistency_level, getKeyspace(), callback, writeType);

http://git-wip-us.apache.org/repos/asf/cassandra/blob/c9528f9c/src/java/org/apache/cassandra/service/DatacenterWriteResponseHandler.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/service/DatacenterWriteResponseHandler.java b/src/java/org/apache/cassandra/service/DatacenterWriteResponseHandler.java
index 2455655..5530374 100644
--- a/src/java/org/apache/cassandra/service/DatacenterWriteResponseHandler.java
+++ b/src/java/org/apache/cassandra/service/DatacenterWriteResponseHandler.java
@@ -42,7 +42,7 @@ public class DatacenterWriteResponseHandler extends WriteResponseHandler
                                           WriteType writeType)
     {
         super(naturalEndpoints, pendingEndpoints, consistencyLevel, keyspace, callback, writeType);
-        assert consistencyLevel == ConsistencyLevel.LOCAL_QUORUM;
+        assert consistencyLevel.isDatacenterLocal();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cassandra/blob/c9528f9c/src/java/org/apache/cassandra/service/ReadCallback.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/service/ReadCallback.java b/src/java/org/apache/cassandra/service/ReadCallback.java
index 7f9c192..b7d5380 100644
--- a/src/java/org/apache/cassandra/service/ReadCallback.java
+++ b/src/java/org/apache/cassandra/service/ReadCallback.java
@@ -127,7 +127,7 @@ public class ReadCallback<TMessage, TResolved> implements IAsyncCallback<TMessag
      */
     private boolean waitingFor(MessageIn message)
     {
-        return consistencyLevel == ConsistencyLevel.LOCAL_QUORUM
+        return consistencyLevel.isDatacenterLocal()
              ? DatabaseDescriptor.getLocalDataCenter().equals(DatabaseDescriptor.getEndpointSnitch().getDatacenter(message.from))
              : true;
     }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/c9528f9c/src/java/org/apache/cassandra/thrift/ThriftConversion.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/thrift/ThriftConversion.java b/src/java/org/apache/cassandra/thrift/ThriftConversion.java
index 8a9ab59..0d92641 100644
--- a/src/java/org/apache/cassandra/thrift/ThriftConversion.java
+++ b/src/java/org/apache/cassandra/thrift/ThriftConversion.java
@@ -41,6 +41,7 @@ public class ThriftConversion
             case LOCAL_QUORUM: return org.apache.cassandra.db.ConsistencyLevel.LOCAL_QUORUM;
             case EACH_QUORUM: return org.apache.cassandra.db.ConsistencyLevel.EACH_QUORUM;
             case SERIAL: return org.apache.cassandra.db.ConsistencyLevel.SERIAL;
+            case LOCAL_ONE: return org.apache.cassandra.db.ConsistencyLevel.LOCAL_ONE;
         }
         throw new AssertionError();
     }