cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject [1/2] cassandra git commit: Fix paging with multi-partition IN queries
Date Fri, 19 Dec 2014 17:02:10 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.1 58529c77f -> 7c6993f82


Fix paging with multi-partition IN queries

patch by thobbs; reviewed by slebresne for CASSANDRA-8408


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

Branch: refs/heads/cassandra-2.1
Commit: 621899355a23eca6c503aa2ced2e944ff6a5fe66
Parents: d8bce50
Author: Sylvain Lebresne <sylvain@datastax.com>
Authored: Fri Dec 19 17:53:46 2014 +0100
Committer: Sylvain Lebresne <sylvain@datastax.com>
Committed: Fri Dec 19 17:53:46 2014 +0100

----------------------------------------------------------------------
 CHANGES.txt                                          |  1 +
 .../cassandra/cql3/statements/SelectStatement.java   |  2 +-
 .../cassandra/service/pager/MultiPartitionPager.java | 15 ++++-----------
 .../org/apache/cassandra/service/pager/Pageable.java |  5 ++++-
 .../apache/cassandra/service/pager/QueryPagers.java  |  7 +------
 .../org/apache/cassandra/service/QueryPagerTest.java |  2 +-
 6 files changed, 12 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/62189935/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index bad24e7..516b4a2 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 2.0.12:
+ * Fix paging for multi-partition IN queries (CASSANDRA-8408)
  * Fix MOVED_NODE topology event never being emitted when a node
    moves its token (CASSANDRA-8373)
  * Fix validation of indexes in COMPACT tables (CASSANDRA-8156)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/62189935/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
index db25716..f08f6b8 100644
--- a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
@@ -212,7 +212,7 @@ public class SelectStatement implements CQLStatement, MeasurableForPreparedCache
         else
         {
             List<ReadCommand> commands = getSliceCommands(variables, limitForQuery,
now);
-            command = commands == null ? null : new Pageable.ReadCommands(commands);
+            command = commands == null ? null : new Pageable.ReadCommands(commands, limitForQuery);
         }
 
         int pageSize = options.getPageSize();

http://git-wip-us.apache.org/repos/asf/cassandra/blob/62189935/src/java/org/apache/cassandra/service/pager/MultiPartitionPager.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/service/pager/MultiPartitionPager.java b/src/java/org/apache/cassandra/service/pager/MultiPartitionPager.java
index 35d6752..e478d3a 100644
--- a/src/java/org/apache/cassandra/service/pager/MultiPartitionPager.java
+++ b/src/java/org/apache/cassandra/service/pager/MultiPartitionPager.java
@@ -46,7 +46,7 @@ class MultiPartitionPager implements QueryPager
     private int remaining;
     private int current;
 
-    MultiPartitionPager(List<ReadCommand> commands, ConsistencyLevel consistencyLevel,
boolean localQuery, PagingState state)
+    MultiPartitionPager(List<ReadCommand> commands, ConsistencyLevel consistencyLevel,
boolean localQuery, PagingState state, int limitForQuery)
     {
         int i = 0;
         // If it's not the beginning (state != null), we need to find where we were and skip
previous commands
@@ -76,7 +76,8 @@ class MultiPartitionPager implements QueryPager
                 throw new IllegalArgumentException("All commands must have the same timestamp
or weird results may happen.");
             pagers[j - i] = makePager(command, consistencyLevel, localQuery, null);
         }
-        remaining = state == null ? computeRemaining(pagers) : state.remaining;
+
+        remaining = state == null ? limitForQuery : state.remaining;
     }
 
     private static SinglePartitionPager makePager(ReadCommand command, ConsistencyLevel consistencyLevel,
boolean localQuery, PagingState state)
@@ -86,14 +87,6 @@ class MultiPartitionPager implements QueryPager
              : new NamesQueryPager((SliceByNamesReadCommand)command, consistencyLevel, localQuery);
     }
 
-    private static int computeRemaining(SinglePartitionPager[] pagers)
-    {
-        long remaining = 0;
-        for (SinglePartitionPager pager : pagers)
-            remaining += pager.maxRemaining();
-        return remaining > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int)remaining;
-    }
-
     public PagingState state()
     {
         // Sets current to the first non-exhausted pager
@@ -123,7 +116,7 @@ class MultiPartitionPager implements QueryPager
     {
         List<Row> result = new ArrayList<Row>();
 
-        int remainingThisQuery = pageSize;
+        int remainingThisQuery = Math.min(remaining, pageSize);
         while (remainingThisQuery > 0 && !isExhausted())
         {
             // isExhausted has set us on the first non-exhausted pager

http://git-wip-us.apache.org/repos/asf/cassandra/blob/62189935/src/java/org/apache/cassandra/service/pager/Pageable.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/service/pager/Pageable.java b/src/java/org/apache/cassandra/service/pager/Pageable.java
index 3a69bf4..d4986f7 100644
--- a/src/java/org/apache/cassandra/service/pager/Pageable.java
+++ b/src/java/org/apache/cassandra/service/pager/Pageable.java
@@ -30,9 +30,12 @@ public interface Pageable
     {
         public final List<ReadCommand> commands;
 
-        public ReadCommands(List<ReadCommand> commands)
+        public final int limitForQuery;
+
+        public ReadCommands(List<ReadCommand> commands, int limitForQuery)
         {
             this.commands = commands;
+            this.limitForQuery = limitForQuery;
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/62189935/src/java/org/apache/cassandra/service/pager/QueryPagers.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/service/pager/QueryPagers.java b/src/java/org/apache/cassandra/service/pager/QueryPagers.java
index 65112aa..72d76fe 100644
--- a/src/java/org/apache/cassandra/service/pager/QueryPagers.java
+++ b/src/java/org/apache/cassandra/service/pager/QueryPagers.java
@@ -98,7 +98,7 @@ public class QueryPagers
             if (commands.size() == 1)
                 return pager(commands.get(0), consistencyLevel, local, state);
 
-            return new MultiPartitionPager(commands, consistencyLevel, local, state);
+            return new MultiPartitionPager(commands, consistencyLevel, local, state, ((Pageable.ReadCommands)
command).limitForQuery);
         }
         else if (command instanceof ReadCommand)
         {
@@ -115,11 +115,6 @@ public class QueryPagers
         }
     }
 
-    public static QueryPager pager(Pageable command, ConsistencyLevel consistencyLevel)
-    {
-        return pager(command, consistencyLevel, false, null);
-    }
-
     public static QueryPager pager(Pageable command, ConsistencyLevel consistencyLevel, PagingState
state)
     {
         return pager(command, consistencyLevel, false, state);

http://git-wip-us.apache.org/repos/asf/cassandra/blob/62189935/test/unit/org/apache/cassandra/service/QueryPagerTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/service/QueryPagerTest.java b/test/unit/org/apache/cassandra/service/QueryPagerTest.java
index 0645433..7dbd7b9 100644
--- a/test/unit/org/apache/cassandra/service/QueryPagerTest.java
+++ b/test/unit/org/apache/cassandra/service/QueryPagerTest.java
@@ -236,7 +236,7 @@ public class QueryPagerTest extends SchemaLoader
         QueryPager pager = QueryPagers.localPager(new Pageable.ReadCommands(new ArrayList<ReadCommand>()
{{
             add(sliceQuery("k1", "c2", "c6", 10));
             add(sliceQuery("k4", "c3", "c5", 10));
-        }}));
+        }}, 10));
 
         List<Row> page;
 


Mime
View raw message