You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by bl...@apache.org on 2015/09/10 21:56:46 UTC

[3/3] cassandra git commit: Deprecate v1 and v2 protocol

Deprecate v1 and v2 protocol

patch by Benjamin Lerer; reviewed by Sylvain Lebresne for CASSANDRA-10146


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

Branch: refs/heads/cassandra-2.2
Commit: a64bcfd731fae39a620b884a828dd144360f65dd
Parents: 67ebf66
Author: blerer <be...@datastax.com>
Authored: Thu Sep 10 21:53:10 2015 +0200
Committer: blerer <be...@datastax.com>
Committed: Thu Sep 10 21:54:50 2015 +0200

----------------------------------------------------------------------
 NEWS.txt                                        |  6 ++++
 .../org/apache/cassandra/transport/Frame.java   | 27 +++++++++-----
 .../cassandra/transport/ProtocolErrorTest.java  | 37 ++++++--------------
 3 files changed, 35 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/a64bcfd7/NEWS.txt
----------------------------------------------------------------------
diff --git a/NEWS.txt b/NEWS.txt
index 4c2c52e..198e8e9 100644
--- a/NEWS.txt
+++ b/NEWS.txt
@@ -17,6 +17,12 @@ using the provided 'sstableupgrade' tool.
 2.2.2
 =====
 
+Upgrading
+---------
+    - Version 1 and 2 of the native protocol are now deprecated and support
+      will be removed in Cassandra 3.0. You are encouraged to upgrade to a
+      client driver using version 3 of the native protocol.
+
 Changed Defaults
 ----------------
    - commitlog_total_space_in_mb will use the smaller of 8192, and 1/4

http://git-wip-us.apache.org/repos/asf/cassandra/blob/a64bcfd7/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 14fe589..66df3e7 100644
--- a/src/java/org/apache/cassandra/transport/Frame.java
+++ b/src/java/org/apache/cassandra/transport/Frame.java
@@ -22,24 +22,33 @@ import java.io.IOException;
 import java.util.EnumSet;
 import java.util.List;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import io.netty.buffer.ByteBuf;
 import io.netty.channel.*;
 import io.netty.handler.codec.ByteToMessageDecoder;
 import io.netty.handler.codec.MessageToMessageDecoder;
 import io.netty.handler.codec.MessageToMessageEncoder;
-
 import org.apache.cassandra.config.DatabaseDescriptor;
 import org.apache.cassandra.exceptions.InvalidRequestException;
 import org.apache.cassandra.transport.messages.ErrorMessage;
 
 public class Frame
 {
+    private static final Logger logger = LoggerFactory.getLogger(Frame.class);
+
     public static final byte PROTOCOL_VERSION_MASK = 0x7f;
 
     public final Header header;
     public final ByteBuf body;
 
     /**
+     * <code>true</code> if the deprecation warning for protocol versions 1 and 2 has been logged.
+     */
+    private static boolean hasLoggedDeprecationWarning;
+
+    /**
      * An on-wire frame consists of a header and a body.
      *
      * The header is defined the following way in native protocol version 3 and later:
@@ -188,6 +197,15 @@ public class Frame
                 throw new ProtocolException(String.format("Invalid or unsupported protocol version (%d); highest supported is %d ",
                                                           version, Server.CURRENT_VERSION));
 
+            if (version < Server.VERSION_3 && !hasLoggedDeprecationWarning)
+            {
+                hasLoggedDeprecationWarning = true;
+                logger.warn("Detected connection using native protocol version {}. Both version 1 and 2"
+                          + " of the native protocol are now deprecated and support will be removed in Cassandra 3.0."
+                          + " You are encouraged to upgrade to a client driver using version 3 of the native protocol",
+                            version);
+            }
+
             // Wait until we have the complete V3+ header
             if (version >= Server.VERSION_3 && buffer.readableBytes() < Header.MODERN_LENGTH)
                 return;
@@ -221,13 +239,6 @@ public class Frame
 
             long bodyLength = buffer.getUnsignedInt(idx);
             idx += Header.BODY_LENGTH_SIZE;
-
-            if (bodyLength < 0)
-            {
-                buffer.skipBytes(headerLength);
-                throw ErrorMessage.wrap(new ProtocolException("Invalid frame body length: " + bodyLength), streamId);
-            }
-
             long frameLength = bodyLength + headerLength;
             if (frameLength > MAX_FRAME_LENGTH)
             {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/a64bcfd7/test/unit/org/apache/cassandra/transport/ProtocolErrorTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/transport/ProtocolErrorTest.java b/test/unit/org/apache/cassandra/transport/ProtocolErrorTest.java
index 9910167..11b0ebd 100644
--- a/test/unit/org/apache/cassandra/transport/ProtocolErrorTest.java
+++ b/test/unit/org/apache/cassandra/transport/ProtocolErrorTest.java
@@ -26,6 +26,8 @@ import org.junit.Test;
 import java.util.ArrayList;
 import java.util.List;
 
+import static org.apache.cassandra.transport.Message.Direction.*;
+
 public class ProtocolErrorTest {
 
     @Test
@@ -52,6 +54,7 @@ public class ProtocolErrorTest {
             dec.decode(null, buf, results);
             Assert.fail("Expected protocol error");
         } catch (ProtocolException e) {
+            Assert.assertTrue(e.getMessage().contains("Invalid or unsupported protocol version"));
         }
     }
 
@@ -64,7 +67,7 @@ public class ProtocolErrorTest {
         // should generate a protocol exception for using a response frame with
         // a prepare op, ensure that it comes back with stream ID 1
         byte[] frame = new byte[] {
-                (byte) 0x82,  // direction & version
+                (byte) RESPONSE.addToVersion(Server.VERSION_2),  // direction & version
                 0x00,  // flags
                 0x01,  // stream ID
                 0x09,  // opcode
@@ -82,29 +85,7 @@ public class ProtocolErrorTest {
         } catch (ErrorMessage.WrappedException e) {
             // make sure the exception has the correct stream ID
             Assert.assertEquals(1, e.getStreamId());
-        }
-    }
-
-    @Test
-    public void testNegativeBodyLength() throws Exception
-    {
-        Frame.Decoder dec = new Frame.Decoder(null);
-
-        List<Object> results = new ArrayList<>();
-        byte[] frame = new byte[] {
-                (byte) 0x82,  // direction & version
-                0x00,  // flags
-                0x01,  // stream ID
-                0x09,  // opcode
-                (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,  // body length (-1)
-        };
-        ByteBuf buf = Unpooled.wrappedBuffer(frame);
-        try {
-            dec.decode(null, buf, results);
-            Assert.fail("Expected protocol error");
-        } catch (ErrorMessage.WrappedException e) {
-            // make sure the exception has the correct stream ID
-            Assert.assertEquals(1, e.getStreamId());
+            Assert.assertTrue(e.getMessage().contains("Wrong protocol direction"));
         }
     }
 
@@ -115,19 +96,21 @@ public class ProtocolErrorTest {
 
         List<Object> results = new ArrayList<>();
         byte[] frame = new byte[] {
-                (byte) 0x82,  // direction & version
+                (byte) REQUEST.addToVersion(Server.VERSION_2),  // direction & version
                 0x00,  // flags
                 0x01,  // stream ID
                 0x09,  // opcode
-                0x7f, (byte) 0xff, (byte) 0xff, (byte) 0xff,  // body length
+                0x10, (byte) 0x00, (byte) 0x00, (byte) 0x00,  // body length
         };
-        ByteBuf buf = Unpooled.wrappedBuffer(frame);
+        byte[] body = new byte[0x10000000];
+        ByteBuf buf = Unpooled.wrappedBuffer(frame, body);
         try {
             dec.decode(null, buf, results);
             Assert.fail("Expected protocol error");
         } catch (ErrorMessage.WrappedException e) {
             // make sure the exception has the correct stream ID
             Assert.assertEquals(1, e.getStreamId());
+            Assert.assertTrue(e.getMessage().contains("Request is too big"));
         }
     }
 }