cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From marc...@apache.org
Subject cassandra git commit: Avoid using DatabaseDescriptor in ProtocolVersion
Date Thu, 04 Oct 2018 06:31:11 GMT
Repository: cassandra
Updated Branches:
  refs/heads/trunk 47a10649d -> bd0cef9a3


Avoid using DatabaseDescriptor in ProtocolVersion

Patch by marcuse; reviewed by Sam Tunnicliffe for CASSANDRA-14800


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

Branch: refs/heads/trunk
Commit: bd0cef9a369ae9245b45040796a6e10f51e522ce
Parents: 47a1064
Author: Marcus Eriksson <marcuse@apache.org>
Authored: Wed Oct 3 10:12:54 2018 +0200
Committer: Marcus Eriksson <marcuse@apache.org>
Committed: Thu Oct 4 08:23:49 2018 +0200

----------------------------------------------------------------------
 src/java/org/apache/cassandra/transport/Client.java       |  2 +-
 src/java/org/apache/cassandra/transport/Frame.java        |  2 +-
 .../org/apache/cassandra/transport/ProtocolVersion.java   |  6 ++----
 .../org/apache/cassandra/audit/FullQueryLoggerTest.java   |  4 ++--
 .../apache/cassandra/transport/ProtocolVersionTest.java   | 10 +++++-----
 .../src/org/apache/cassandra/fqltool/FQLQueryReader.java  |  2 +-
 .../src/org/apache/cassandra/fqltool/commands/Dump.java   |  2 +-
 7 files changed, 13 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/bd0cef9a/src/java/org/apache/cassandra/transport/Client.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/transport/Client.java b/src/java/org/apache/cassandra/transport/Client.java
index f7ed272..eacd5a9 100644
--- a/src/java/org/apache/cassandra/transport/Client.java
+++ b/src/java/org/apache/cassandra/transport/Client.java
@@ -292,7 +292,7 @@ public class Client extends SimpleClient
         // Parse options.
         String host = args[0];
         int port = Integer.parseInt(args[1]);
-        ProtocolVersion version = args.length == 3 ? ProtocolVersion.decode(Integer.parseInt(args[2]))
: ProtocolVersion.CURRENT;
+        ProtocolVersion version = args.length == 3 ? ProtocolVersion.decode(Integer.parseInt(args[2]),
DatabaseDescriptor.getNativeTransportAllowOlderProtocols()) : ProtocolVersion.CURRENT;
 
         EncryptionOptions encryptionOptions = new EncryptionOptions();
         System.out.println("CQL binary protocol console " + host + "@" + port + " using native
protocol version " + version);

http://git-wip-us.apache.org/repos/asf/cassandra/blob/bd0cef9a/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 d6a1cbc..d3c810b 100644
--- a/src/java/org/apache/cassandra/transport/Frame.java
+++ b/src/java/org/apache/cassandra/transport/Frame.java
@@ -174,7 +174,7 @@ public class Frame
             int firstByte = buffer.getByte(idx++);
             Message.Direction direction = Message.Direction.extractFromVersion(firstByte);
             int versionNum = firstByte & PROTOCOL_VERSION_MASK;
-            ProtocolVersion version = ProtocolVersion.decode(versionNum);
+            ProtocolVersion version = ProtocolVersion.decode(versionNum, DatabaseDescriptor.getNativeTransportAllowOlderProtocols());
 
             // Wait until we have the complete header
             if (readableBytes < Header.LENGTH)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/bd0cef9a/src/java/org/apache/cassandra/transport/ProtocolVersion.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/transport/ProtocolVersion.java b/src/java/org/apache/cassandra/transport/ProtocolVersion.java
index e1f634c..546983f 100644
--- a/src/java/org/apache/cassandra/transport/ProtocolVersion.java
+++ b/src/java/org/apache/cassandra/transport/ProtocolVersion.java
@@ -26,8 +26,6 @@ import java.util.Optional;
 
 import org.apache.commons.lang3.ArrayUtils;
 
-import org.apache.cassandra.config.DatabaseDescriptor;
-
 /**
  * The native (CQL binary) protocol version.
  *
@@ -95,7 +93,7 @@ public enum ProtocolVersion implements Comparable<ProtocolVersion>
         return versions;
     }
 
-    public static ProtocolVersion decode(int versionNum)
+    public static ProtocolVersion decode(int versionNum, boolean allowOlderProtocols)
     {
         ProtocolVersion ret = versionNum >= MIN_SUPPORTED_VERSION.num && versionNum
<= MAX_SUPPORTED_VERSION.num
                               ? SUPPORTED_VERSIONS[versionNum - MIN_SUPPORTED_VERSION.num]
@@ -116,7 +114,7 @@ public enum ProtocolVersion implements Comparable<ProtocolVersion>
             throw new ProtocolException(invalidVersionMessage(versionNum), MAX_SUPPORTED_VERSION);
         }
 
-        if (!DatabaseDescriptor.getNativeTransportAllowOlderProtocols() && ret.isSmallerThan(CURRENT))
+        if (!allowOlderProtocols && ret.isSmallerThan(CURRENT))
             throw new ProtocolException(String.format("Rejecting Protocol Version %s <
%s.", ret, ProtocolVersion.CURRENT));
 
         return ret;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/bd0cef9a/test/unit/org/apache/cassandra/audit/FullQueryLoggerTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/audit/FullQueryLoggerTest.java b/test/unit/org/apache/cassandra/audit/FullQueryLoggerTest.java
index 376bde5..5fe078a 100644
--- a/test/unit/org/apache/cassandra/audit/FullQueryLoggerTest.java
+++ b/test/unit/org/apache/cassandra/audit/FullQueryLoggerTest.java
@@ -443,7 +443,7 @@ public class FullQueryLoggerTest extends CQLTester
 
                 assertEquals(1L, wire.read(QUERY_START_TIME).int64());
 
-                ProtocolVersion protocolVersion = ProtocolVersion.decode(wire.read(PROTOCOL_VERSION).int32());
+                ProtocolVersion protocolVersion = ProtocolVersion.decode(wire.read(PROTOCOL_VERSION).int32(),
true);
                 assertEquals(ProtocolVersion.CURRENT, protocolVersion);
 
                 QueryOptions queryOptions = QueryOptions.codec.decode(Unpooled.wrappedBuffer(wire.read(QUERY_OPTIONS).bytes()),
protocolVersion);
@@ -517,7 +517,7 @@ public class FullQueryLoggerTest extends CQLTester
 
                 assertEquals(1L, wire.read(QUERY_START_TIME).int64());
 
-                ProtocolVersion protocolVersion = ProtocolVersion.decode(wire.read(PROTOCOL_VERSION).int32());
+                ProtocolVersion protocolVersion = ProtocolVersion.decode(wire.read(PROTOCOL_VERSION).int32(),
true);
                 assertEquals(ProtocolVersion.CURRENT, protocolVersion);
 
                 QueryOptions queryOptions = QueryOptions.codec.decode(Unpooled.wrappedBuffer(wire.read(QUERY_OPTIONS).bytes()),
protocolVersion);

http://git-wip-us.apache.org/repos/asf/cassandra/blob/bd0cef9a/test/unit/org/apache/cassandra/transport/ProtocolVersionTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/transport/ProtocolVersionTest.java b/test/unit/org/apache/cassandra/transport/ProtocolVersionTest.java
index 2057998..74bc407 100644
--- a/test/unit/org/apache/cassandra/transport/ProtocolVersionTest.java
+++ b/test/unit/org/apache/cassandra/transport/ProtocolVersionTest.java
@@ -46,13 +46,13 @@ public class ProtocolVersionTest
     public void testDecode()
     {
         for (ProtocolVersion version : ProtocolVersion.SUPPORTED)
-            Assert.assertEquals(version, ProtocolVersion.decode(version.asInt()));
+            Assert.assertEquals(version, ProtocolVersion.decode(version.asInt(), DatabaseDescriptor.getNativeTransportAllowOlderProtocols()));
 
         for (ProtocolVersion version : ProtocolVersion.UNSUPPORTED)
         { // unsupported old versions
             try
             {
-                Assert.assertEquals(version, ProtocolVersion.decode(version.asInt()));
+                Assert.assertEquals(version, ProtocolVersion.decode(version.asInt(), DatabaseDescriptor.getNativeTransportAllowOlderProtocols()));
                 Assert.fail("Expected invalid protocol exception");
             }
             catch (ProtocolException ex)
@@ -64,7 +64,7 @@ public class ProtocolVersionTest
 
         try
         { // unsupported newer version
-            Assert.assertEquals(null, ProtocolVersion.decode(63));
+            Assert.assertEquals(null, ProtocolVersion.decode(63, DatabaseDescriptor.getNativeTransportAllowOlderProtocols()));
             Assert.fail("Expected invalid protocol exception");
         }
         catch (ProtocolException ex)
@@ -133,7 +133,7 @@ public class ProtocolVersionTest
         {
             try
             {
-                ProtocolVersion.decode(version.asInt());
+                ProtocolVersion.decode(version.asInt(), DatabaseDescriptor.getNativeTransportAllowOlderProtocols());
                 Assert.fail("Expected invalid protocol exception");
             }
             catch (ProtocolException ex)
@@ -141,6 +141,6 @@ public class ProtocolVersionTest
             }
         }
 
-        Assert.assertEquals(ProtocolVersion.CURRENT, ProtocolVersion.decode(ProtocolVersion.CURRENT.asInt()));
+        Assert.assertEquals(ProtocolVersion.CURRENT, ProtocolVersion.decode(ProtocolVersion.CURRENT.asInt(),
DatabaseDescriptor.getNativeTransportAllowOlderProtocols()));
     }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/bd0cef9a/tools/fqltool/src/org/apache/cassandra/fqltool/FQLQueryReader.java
----------------------------------------------------------------------
diff --git a/tools/fqltool/src/org/apache/cassandra/fqltool/FQLQueryReader.java b/tools/fqltool/src/org/apache/cassandra/fqltool/FQLQueryReader.java
index fd5073c..0c18b79 100644
--- a/tools/fqltool/src/org/apache/cassandra/fqltool/FQLQueryReader.java
+++ b/tools/fqltool/src/org/apache/cassandra/fqltool/FQLQueryReader.java
@@ -57,7 +57,7 @@ public class FQLQueryReader implements ReadMarshallable
         String type = wireIn.read(TYPE).text();
         long queryStartTime = wireIn.read(QUERY_START_TIME).int64();
         int protocolVersion = wireIn.read(PROTOCOL_VERSION).int32();
-        QueryOptions queryOptions = QueryOptions.codec.decode(Unpooled.wrappedBuffer(wireIn.read(QUERY_OPTIONS).bytes()),
ProtocolVersion.decode(protocolVersion));
+        QueryOptions queryOptions = QueryOptions.codec.decode(Unpooled.wrappedBuffer(wireIn.read(QUERY_OPTIONS).bytes()),
ProtocolVersion.decode(protocolVersion, true));
         long generatedTimestamp = wireIn.read(GENERATED_TIMESTAMP).int64();
         int generatedNowInSeconds = wireIn.read(GENERATED_NOW_IN_SECONDS).int32();
         String keyspace = wireIn.read(KEYSPACE).text();

http://git-wip-us.apache.org/repos/asf/cassandra/blob/bd0cef9a/tools/fqltool/src/org/apache/cassandra/fqltool/commands/Dump.java
----------------------------------------------------------------------
diff --git a/tools/fqltool/src/org/apache/cassandra/fqltool/commands/Dump.java b/tools/fqltool/src/org/apache/cassandra/fqltool/commands/Dump.java
index 1263a11..b3e1f22 100644
--- a/tools/fqltool/src/org/apache/cassandra/fqltool/commands/Dump.java
+++ b/tools/fqltool/src/org/apache/cassandra/fqltool/commands/Dump.java
@@ -94,7 +94,7 @@ public class Dump implements Runnable
 
             QueryOptions options =
                 QueryOptions.codec.decode(Unpooled.wrappedBuffer(wireIn.read(FullQueryLogger.QUERY_OPTIONS).bytes()),
-                                          ProtocolVersion.decode(protocolVersion));
+                                          ProtocolVersion.decode(protocolVersion, true));
 
             long generatedTimestamp = wireIn.read(FullQueryLogger.GENERATED_TIMESTAMP).int64();
             sb.append("Generated timestamp:")


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org


Mime
View raw message