cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tylerho...@apache.org
Subject [1/3] cassandra git commit: Respond with pre-v3 header for unsupported low proto versions
Date Wed, 20 Jul 2016 20:41:16 GMT
Repository: cassandra
Updated Branches:
  refs/heads/trunk e8907c16a -> 5d9aab276


Respond with pre-v3 header for unsupported low proto versions

Patch by Tyler Hobbs; reviewed by Sandeep Tamhankar for CASSANDRA-11464


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

Branch: refs/heads/trunk
Commit: 904137c38419c75b9e0393d8ff4dfcf13b4710b6
Parents: 979e559
Author: Tyler Hobbs <tylerlhobbs@gmail.com>
Authored: Wed Jul 20 15:37:50 2016 -0500
Committer: Tyler Hobbs <tylerlhobbs@gmail.com>
Committed: Wed Jul 20 15:37:50 2016 -0500

----------------------------------------------------------------------
 CHANGES.txt                                       |  2 ++
 .../org/apache/cassandra/transport/Frame.java     |  5 ++++-
 .../org/apache/cassandra/transport/Message.java   |  8 +++++++-
 .../cassandra/transport/ProtocolException.java    | 18 ++++++++++++++++++
 .../transport/messages/ErrorMessage.java          | 13 ++++++++++++-
 5 files changed, 43 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/904137c3/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 6ea39cd..9acd89e 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,6 @@
 3.0.9
+ * Respond with v1/v2 protocol header when responding to driver that attempts
+   to connect with too low of a protocol version (CASSANDRA-11464)
  * NullPointerExpception when reading/compacting table (CASSANDRA-11988)
  * Fix problem with undeleteable rows on upgrade to new sstable format (CASSANDRA-12144)
  * Fix paging logic for deleted partitions with static columns (CASSANDRA-12107)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/904137c3/src/java/org/apache/cassandra/transport/Frame.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/transport/Frame.java b/src/java/org/apache/cassandra/transport/Frame.java
index 363ff76..3940b47 100644
--- a/src/java/org/apache/cassandra/transport/Frame.java
+++ b/src/java/org/apache/cassandra/transport/Frame.java
@@ -175,7 +175,8 @@ public class Frame
             int version = firstByte & PROTOCOL_VERSION_MASK;
             if (version < Server.MIN_SUPPORTED_VERSION || version > Server.CURRENT_VERSION)
                 throw new ProtocolException(String.format("Invalid or unsupported protocol
version (%d); the lowest supported version is %d and the greatest is %d",
-                                                          version, Server.MIN_SUPPORTED_VERSION,
Server.CURRENT_VERSION));
+                                                          version, Server.MIN_SUPPORTED_VERSION,
Server.CURRENT_VERSION),
+                                            version);
 
             // Wait until we have the complete header
             if (readableBytes < Header.LENGTH)
@@ -273,6 +274,8 @@ public class Frame
             header.writeByte(type.direction.addToVersion(frame.header.version));
             header.writeByte(Header.Flag.serialize(frame.header.flags));
 
+            // Continue to support writing pre-v3 headers so that we can give proper error
messages to drivers that
+            // connect with the v1/v2 protocol. See CASSANDRA-11464.
             if (frame.header.version >= Server.VERSION_3)
                 header.writeShort(frame.header.streamId);
             else

http://git-wip-us.apache.org/repos/asf/cassandra/blob/904137c3/src/java/org/apache/cassandra/transport/Message.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/transport/Message.java b/src/java/org/apache/cassandra/transport/Message.java
index 01a0794..7bfa194 100644
--- a/src/java/org/apache/cassandra/transport/Message.java
+++ b/src/java/org/apache/cassandra/transport/Message.java
@@ -150,6 +150,7 @@ public abstract class Message
     private int streamId;
     private Frame sourceFrame;
     private Map<String, ByteBuffer> customPayload;
+    protected Integer forcedProtocolVersion = null;
 
     protected Message(Type type)
     {
@@ -389,7 +390,12 @@ public abstract class Message
                     throw e;
                 }
 
-                results.add(Frame.create(message.type, message.getStreamId(), version, flags,
body));
+                // if the driver attempted to connect with a protocol version lower than
the minimum supported
+                // version, respond with a protocol error message with the correct frame
header for that version
+                int responseVersion = message.forcedProtocolVersion == null
+                                    ? version
+                                    : message.forcedProtocolVersion;
+                results.add(Frame.create(message.type, message.getStreamId(), responseVersion,
flags, body));
             }
             catch (Throwable e)
             {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/904137c3/src/java/org/apache/cassandra/transport/ProtocolException.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/transport/ProtocolException.java b/src/java/org/apache/cassandra/transport/ProtocolException.java
index 9af9dc0..a589e9b 100644
--- a/src/java/org/apache/cassandra/transport/ProtocolException.java
+++ b/src/java/org/apache/cassandra/transport/ProtocolException.java
@@ -25,13 +25,31 @@ import org.apache.cassandra.exceptions.TransportException;
  */
 public class ProtocolException extends RuntimeException implements TransportException
 {
+    private final Integer attemptedLowProtocolVersion;
+
     public ProtocolException(String msg)
     {
+        this(msg, null);
+    }
+
+    public ProtocolException(String msg, Integer attemptedLowProtocolVersion)
+    {
         super(msg);
+        this.attemptedLowProtocolVersion = attemptedLowProtocolVersion;
     }
 
     public ExceptionCode code()
     {
         return ExceptionCode.PROTOCOL_ERROR;
     }
+
+    /**
+     * If the ProtocolException is due to a connection being made with a protocol version
that is lower
+     * than Server.MIN_SUPPORTED_VERSION, this will return that unsupported protocol version.
 Otherwise,
+     * null is returned.
+     */
+    public Integer getAttemptedLowProtocolVersion()
+    {
+        return attemptedLowProtocolVersion;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/904137c3/src/java/org/apache/cassandra/transport/messages/ErrorMessage.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/transport/messages/ErrorMessage.java b/src/java/org/apache/cassandra/transport/messages/ErrorMessage.java
index 021db5a..8f45d4d 100644
--- a/src/java/org/apache/cassandra/transport/messages/ErrorMessage.java
+++ b/src/java/org/apache/cassandra/transport/messages/ErrorMessage.java
@@ -331,7 +331,18 @@ public class ErrorMessage extends Message.Response
         }
 
         if (e instanceof TransportException)
-            return new ErrorMessage((TransportException)e, streamId);
+        {
+            ErrorMessage message = new ErrorMessage((TransportException) e, streamId);
+            if (e instanceof ProtocolException)
+            {
+                // if the driver attempted to connect with a protocol version lower than
the minimum supported
+                // version, respond with a protocol error message with the correct frame
header for that version
+                Integer attemptedLowProtocolVersion = ((ProtocolException) e).getAttemptedLowProtocolVersion();
+                if (attemptedLowProtocolVersion != null)
+                    message.forcedProtocolVersion = attemptedLowProtocolVersion;
+            }
+            return message;
+        }
 
         // Unexpected exception
         if (unexpectedExceptionHandler == null || !unexpectedExceptionHandler.apply(e))


Mime
View raw message