cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject cassandra git commit: Re-introduce the use of Verb.RANGE_SLICE for range queries explanation
Date Fri, 21 Aug 2015 07:59:29 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-3.0 9ed272773 -> be45eb6be


Re-introduce the use of Verb.RANGE_SLICE for range queries
explanation

patch by slebresne; reviewed by aweisberg for CASSANDRA-10125


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

Branch: refs/heads/cassandra-3.0
Commit: be45eb6bea4a0419dd058e1787a482263b2ff198
Parents: 9ed2727
Author: Sylvain Lebresne <sylvain@datastax.com>
Authored: Wed Aug 19 11:52:18 2015 +0200
Committer: Sylvain Lebresne <sylvain@datastax.com>
Committed: Fri Aug 21 09:58:32 2015 +0200

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../cassandra/db/PartitionRangeReadCommand.java | 13 ++++---
 .../cassandra/db/RangeSliceVerbHandler.java     |  2 +-
 .../org/apache/cassandra/db/ReadCommand.java    | 40 +++++++++++++++-----
 .../org/apache/cassandra/db/ReadResponse.java   | 30 +++++++++++++++
 .../db/SinglePartitionReadCommand.java          |  4 +-
 .../apache/cassandra/net/MessagingService.java  |  6 +--
 7 files changed, 75 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/be45eb6b/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index cea8c73..47fea8b 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 3.0.0-beta1
+ * Fix throwing ReadFailure instead of ReadTimeout on range queries (CASSANDRA-10125)
  * Rewrite hinted handoff (CASSANDRA-6230)
  * Fix query on static compact tables (CASSANDRA-10093)
  * Fix race during construction of commit log (CASSANDRA-10049)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/be45eb6b/src/java/org/apache/cassandra/db/PartitionRangeReadCommand.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/PartitionRangeReadCommand.java b/src/java/org/apache/cassandra/db/PartitionRangeReadCommand.java
index e7288cc..42d5425 100644
--- a/src/java/org/apache/cassandra/db/PartitionRangeReadCommand.java
+++ b/src/java/org/apache/cassandra/db/PartitionRangeReadCommand.java
@@ -237,13 +237,14 @@ public class PartitionRangeReadCommand extends ReadCommand
         };
     }
 
-    @SuppressWarnings("deprecation")
-    protected MessageOut<ReadCommand> createLegacyMessage()
+    public MessageOut<ReadCommand> createMessage(int version)
     {
-        if (this.dataRange.isPaging())
-            return new MessageOut<>(MessagingService.Verb.PAGED_RANGE, this, legacyPagedRangeCommandSerializer);
-        else
-            return new MessageOut<>(MessagingService.Verb.RANGE_SLICE, this, legacyRangeSliceCommandSerializer);
+        if (version >= MessagingService.VERSION_30)
+            return new MessageOut<>(MessagingService.Verb.RANGE_SLICE, this, serializer);
+
+        return dataRange().isPaging()
+             ? new MessageOut<>(MessagingService.Verb.PAGED_RANGE, this, legacyPagedRangeCommandSerializer)
+             : new MessageOut<>(MessagingService.Verb.RANGE_SLICE, this, legacyRangeSliceCommandSerializer);
     }
 
     protected void appendCQLWhereClause(StringBuilder sb)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/be45eb6b/src/java/org/apache/cassandra/db/RangeSliceVerbHandler.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/RangeSliceVerbHandler.java b/src/java/org/apache/cassandra/db/RangeSliceVerbHandler.java
index 3f1d660..55826f5 100644
--- a/src/java/org/apache/cassandra/db/RangeSliceVerbHandler.java
+++ b/src/java/org/apache/cassandra/db/RangeSliceVerbHandler.java
@@ -24,6 +24,6 @@ public class RangeSliceVerbHandler extends ReadCommandVerbHandler
     @Override
     protected IVersionedSerializer<ReadResponse> serializer()
     {
-        return ReadResponse.legacyRangeSliceReplySerializer;
+        return ReadResponse.rangeSliceSerializer;
     }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/be45eb6b/src/java/org/apache/cassandra/db/ReadCommand.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/ReadCommand.java b/src/java/org/apache/cassandra/db/ReadCommand.java
index 4830124..d63a832 100644
--- a/src/java/org/apache/cassandra/db/ReadCommand.java
+++ b/src/java/org/apache/cassandra/db/ReadCommand.java
@@ -59,6 +59,9 @@ public abstract class ReadCommand implements ReadQuery
     protected static final Logger logger = LoggerFactory.getLogger(ReadCommand.class);
 
     public static final IVersionedSerializer<ReadCommand> serializer = new Serializer();
+    // For RANGE_SLICE verb: will either dispatch on 'serializer' for 3.0 or 'legacyRangeSliceCommandSerializer'
for earlier version.
+    // Can be removed (and replaced by 'serializer') once we drop pre-3.0 backward compatibility.
+    public static final IVersionedSerializer<ReadCommand> rangeSliceSerializer = new
RangeSliceSerializer();
 
     public static final IVersionedSerializer<ReadCommand> legacyRangeSliceCommandSerializer
= new LegacyRangeSliceCommandSerializer();
     public static final IVersionedSerializer<ReadCommand> legacyPagedRangeCommandSerializer
= new LegacyPagedRangeCommandSerializer();
@@ -411,15 +414,7 @@ public abstract class ReadCommand implements ReadQuery
     /**
      * Creates a message for this command.
      */
-    public MessageOut<ReadCommand> createMessage(int version)
-    {
-        if (version >= MessagingService.VERSION_30)
-            return new MessageOut<>(MessagingService.Verb.READ, this, serializer);
-
-        return createLegacyMessage();
-    }
-
-    protected abstract MessageOut<ReadCommand> createLegacyMessage();
+    public abstract MessageOut<ReadCommand> createMessage(int version);
 
     protected abstract void appendCQLWhereClause(StringBuilder sb);
 
@@ -529,6 +524,33 @@ public abstract class ReadCommand implements ReadQuery
         }
     }
 
+    // Dispatch to either Serializer or LegacyRangeSliceCommandSerializer. Only useful as
long as we maintain pre-3.0
+    // compatibility
+    private static class RangeSliceSerializer implements IVersionedSerializer<ReadCommand>
+    {
+        public void serialize(ReadCommand command, DataOutputPlus out, int version) throws
IOException
+        {
+            if (version < MessagingService.VERSION_30)
+                legacyRangeSliceCommandSerializer.serialize(command, out, version);
+            else
+                serializer.serialize(command, out, version);
+        }
+
+        public ReadCommand deserialize(DataInputPlus in, int version) throws IOException
+        {
+            return version < MessagingService.VERSION_30
+                 ? legacyRangeSliceCommandSerializer.deserialize(in, version)
+                 : serializer.deserialize(in, version);
+        }
+
+        public long serializedSize(ReadCommand command, int version)
+        {
+            return version < MessagingService.VERSION_30
+                 ? legacyRangeSliceCommandSerializer.serializedSize(command, version)
+                 : serializer.serializedSize(command, version);
+        }
+    }
+
     private enum LegacyType
     {
         GET_BY_NAMES((byte)1),

http://git-wip-us.apache.org/repos/asf/cassandra/blob/be45eb6b/src/java/org/apache/cassandra/db/ReadResponse.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/ReadResponse.java b/src/java/org/apache/cassandra/db/ReadResponse.java
index 5f40210..21f6106 100644
--- a/src/java/org/apache/cassandra/db/ReadResponse.java
+++ b/src/java/org/apache/cassandra/db/ReadResponse.java
@@ -42,7 +42,12 @@ import org.apache.cassandra.utils.FBUtilities;
 
 public abstract class ReadResponse
 {
+    // Serializer for single partition read response
     public static final IVersionedSerializer<ReadResponse> serializer = new Serializer();
+    // Serializer for partition range read response (this actually delegate to 'serializer'
in 3.0 and to
+    // 'legacyRangeSliceReplySerializer' in older version.
+    public static final IVersionedSerializer<ReadResponse> rangeSliceSerializer = new
RangeSliceSerializer();
+    // Serializer for the pre-3.0 rang slice responses.
     public static final IVersionedSerializer<ReadResponse> legacyRangeSliceReplySerializer
= new LegacyRangeSliceReplySerializer();
 
     // This is used only when serializing data responses and we can't it easily in other
cases. So this can be null, which is slighly
@@ -397,6 +402,31 @@ public abstract class ReadResponse
         }
     }
 
+    private static class RangeSliceSerializer implements IVersionedSerializer<ReadResponse>
+    {
+        public void serialize(ReadResponse response, DataOutputPlus out, int version) throws
IOException
+        {
+            if (version < MessagingService.VERSION_30)
+                legacyRangeSliceReplySerializer.serialize(response, out, version);
+            else
+                serializer.serialize(response, out, version);
+        }
+
+        public ReadResponse deserialize(DataInputPlus in, int version) throws IOException
+        {
+            return version < MessagingService.VERSION_30
+                 ? legacyRangeSliceReplySerializer.deserialize(in, version)
+                 : serializer.deserialize(in, version);
+        }
+
+        public long serializedSize(ReadResponse response, int version)
+        {
+            return version < MessagingService.VERSION_30
+                 ? legacyRangeSliceReplySerializer.serializedSize(response, version)
+                 : serializer.serializedSize(response, version);
+        }
+    }
+
     private static class LegacyRangeSliceReplySerializer implements IVersionedSerializer<ReadResponse>
     {
         public void serialize(ReadResponse response, DataOutputPlus out, int version) throws
IOException

http://git-wip-us.apache.org/repos/asf/cassandra/blob/be45eb6b/src/java/org/apache/cassandra/db/SinglePartitionReadCommand.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/SinglePartitionReadCommand.java b/src/java/org/apache/cassandra/db/SinglePartitionReadCommand.java
index d9b0e2b..ca135f8 100644
--- a/src/java/org/apache/cassandra/db/SinglePartitionReadCommand.java
+++ b/src/java/org/apache/cassandra/db/SinglePartitionReadCommand.java
@@ -395,9 +395,9 @@ public abstract class SinglePartitionReadCommand<F extends ClusteringIndexFilter
                              nowInSec());
     }
 
-    protected MessageOut<ReadCommand> createLegacyMessage()
+    public MessageOut<ReadCommand> createMessage(int version)
     {
-        return new MessageOut<>(MessagingService.Verb.READ, this, legacyReadCommandSerializer);
+        return new MessageOut<>(MessagingService.Verb.READ, this, version < MessagingService.VERSION_30
? legacyReadCommandSerializer : serializer);
     }
 
     protected void appendCQLWhereClause(StringBuilder sb)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/be45eb6b/src/java/org/apache/cassandra/net/MessagingService.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/net/MessagingService.java b/src/java/org/apache/cassandra/net/MessagingService.java
index 13632ac..e59cd58 100644
--- a/src/java/org/apache/cassandra/net/MessagingService.java
+++ b/src/java/org/apache/cassandra/net/MessagingService.java
@@ -107,7 +107,7 @@ public final class MessagingService implements MessagingServiceMBean
         @Deprecated STREAM_INITIATE_DONE,
         @Deprecated STREAM_REPLY,
         @Deprecated STREAM_REQUEST,
-        @Deprecated RANGE_SLICE,
+        RANGE_SLICE,
         @Deprecated BOOTSTRAP_TOKEN,
         @Deprecated TREE_REQUEST,
         @Deprecated TREE_RESPONSE,
@@ -212,7 +212,7 @@ public final class MessagingService implements MessagingServiceMBean
         put(Verb.BATCHLOG_MUTATION, Mutation.serializer);
         put(Verb.READ_REPAIR, Mutation.serializer);
         put(Verb.READ, ReadCommand.serializer);
-        put(Verb.RANGE_SLICE, ReadCommand.legacyRangeSliceCommandSerializer);
+        put(Verb.RANGE_SLICE, ReadCommand.rangeSliceSerializer);
         put(Verb.PAGED_RANGE, ReadCommand.legacyPagedRangeCommandSerializer);
         put(Verb.BOOTSTRAP_TOKEN, BootStrapper.StringSerializer.instance);
         put(Verb.REPAIR_MESSAGE, RepairMessage.serializer);
@@ -241,7 +241,7 @@ public final class MessagingService implements MessagingServiceMBean
         put(Verb.BATCHLOG_MUTATION, WriteResponse.serializer);
         put(Verb.READ_REPAIR, WriteResponse.serializer);
         put(Verb.COUNTER_MUTATION, WriteResponse.serializer);
-        put(Verb.RANGE_SLICE, ReadResponse.legacyRangeSliceReplySerializer);
+        put(Verb.RANGE_SLICE, ReadResponse.rangeSliceSerializer);
         put(Verb.PAGED_RANGE, ReadResponse.legacyRangeSliceReplySerializer);
         put(Verb.READ, ReadResponse.serializer);
         put(Verb.TRUNCATE, TruncateResponse.serializer);


Mime
View raw message