You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by ja...@apache.org on 2016/03/11 20:26:33 UTC

[02/14] cassandra git commit: Fix intra-node serialization issue for multicolumn-restrictions

Fix intra-node serialization issue for multicolumn-restrictions

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


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

Branch: refs/heads/trunk
Commit: 11b7dc113ff5f73b1bbf889f306ad2aa72d01160
Parents: b9ff7fe
Author: Benjamin Lerer <b....@gmail.com>
Authored: Fri Mar 11 16:58:36 2016 +0100
Committer: Benjamin Lerer <b....@gmail.com>
Committed: Fri Mar 11 17:03:29 2016 +0100

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../restrictions/PrimaryKeyRestrictionSet.java  | 22 +++++++++++++++++++-
 .../PrimaryKeyRestrictionSetTest.java           |  3 ++-
 3 files changed, 24 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/11b7dc11/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 045b867..87bb0c0 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 2.2.6
+ * Fix intra-node serialization issue for multicolumn-restrictions (CASSANDRA-11196)
  * Non-obsoleting compaction operations over compressed files can impose rate limit on normal reads (CASSANDRA-11301)
  * Add missing newline at end of bin/cqlsh (CASSANDRA-11325)
  * Fix AE in nodetool cfstats (backport CASSANDRA-10859) (CASSANDRA-11297)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/11b7dc11/src/java/org/apache/cassandra/cql3/restrictions/PrimaryKeyRestrictionSet.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/restrictions/PrimaryKeyRestrictionSet.java b/src/java/org/apache/cassandra/cql3/restrictions/PrimaryKeyRestrictionSet.java
index 936dbd6..7ce228c 100644
--- a/src/java/org/apache/cassandra/cql3/restrictions/PrimaryKeyRestrictionSet.java
+++ b/src/java/org/apache/cassandra/cql3/restrictions/PrimaryKeyRestrictionSet.java
@@ -20,6 +20,8 @@ package org.apache.cassandra.cql3.restrictions;
 import java.nio.ByteBuffer;
 import java.util.*;
 
+import com.google.common.collect.Lists;
+
 import org.apache.cassandra.db.composites.Composite;
 import org.apache.cassandra.config.ColumnDefinition;
 import org.apache.cassandra.cql3.QueryOptions;
@@ -201,7 +203,24 @@ final class PrimaryKeyRestrictionSet extends AbstractPrimaryKeyRestrictions
             if (r.isSlice())
             {
                 r.appendBoundTo(builder, bound, options);
-                return filterAndSort(setEocs(r, bound, builder.build()));
+
+                // Since CASSANDRA-7281, the composites might not end with the same components and it is possible
+                // that one of the composites is an empty one. Unfortunatly, AbstractCType will always sort
+                // Composites.EMPTY before all the other components due to its EOC, even if it is not the desired
+                // behaviour in some cases. To avoid that problem the code will use normal composites for the empty
+                // ones until the composites are properly sorted. They will then be replaced by Composites.EMPTY as
+                // it is what is expected by the intra-node serialization.
+                // It is clearly a hack but it does not make a lot of sense to refactor 2.2 for that as the problem is
+                // already solved in 3.0.
+                List<Composite> composites = filterAndSort(setEocs(r, bound, builder.build()));
+                return Lists.transform(composites, new com.google.common.base.Function<Composite, Composite>()
+                {
+                    @Override
+                    public Composite apply(Composite composite)
+                    {
+                        return composite.isEmpty() ? Composites.EMPTY: composite;
+                    }
+                });
             }
 
             r.appendBoundTo(builder, bound, options);
@@ -234,6 +253,7 @@ final class PrimaryKeyRestrictionSet extends AbstractPrimaryKeyRestrictions
 
         TreeSet<Composite> set = new TreeSet<Composite>(ctype);
         set.addAll(composites);
+
         return new ArrayList<>(set);
     }
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/11b7dc11/test/unit/org/apache/cassandra/cql3/restrictions/PrimaryKeyRestrictionSetTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/restrictions/PrimaryKeyRestrictionSetTest.java b/test/unit/org/apache/cassandra/cql3/restrictions/PrimaryKeyRestrictionSetTest.java
index 1deeb9e..bf5128f 100644
--- a/test/unit/org/apache/cassandra/cql3/restrictions/PrimaryKeyRestrictionSetTest.java
+++ b/test/unit/org/apache/cassandra/cql3/restrictions/PrimaryKeyRestrictionSetTest.java
@@ -31,6 +31,7 @@ import org.apache.cassandra.cql3.statements.Bound;
 import org.apache.cassandra.db.ColumnFamilyType;
 import org.apache.cassandra.db.composites.Composite;
 import org.apache.cassandra.db.composites.Composite.EOC;
+import org.apache.cassandra.db.composites.Composites;
 import org.apache.cassandra.db.composites.CompoundSparseCellNameType;
 import org.apache.cassandra.db.marshal.AbstractType;
 import org.apache.cassandra.db.marshal.Int32Type;
@@ -1682,7 +1683,7 @@ public class PrimaryKeyRestrictionSetTest
      */
     private static void assertEmptyComposite(Composite composite)
     {
-        assertTrue(composite.isEmpty());
+        assertEquals(Composites.EMPTY, composite);
     }
 
     /**