You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by sl...@apache.org on 2014/04/02 14:29:03 UTC

[1/2] git commit: Fix error with super columns in mixed 1.2-2.0 cluster

Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.1 8afe1090b -> ef08e6258


Fix error with super columns in mixed 1.2-2.0 cluster

patch by slebresne; reviewed by iamaleksey for CASSANDRA-6966


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

Branch: refs/heads/cassandra-2.1
Commit: e1a90936c709d0da1a601ef418d9b97a14ff5bb2
Parents: b42feea
Author: Sylvain Lebresne <sy...@datastax.com>
Authored: Wed Apr 2 14:26:14 2014 +0200
Committer: Sylvain Lebresne <sy...@datastax.com>
Committed: Wed Apr 2 14:26:14 2014 +0200

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../org/apache/cassandra/db/SuperColumns.java   | 24 ++++++++------------
 2 files changed, 11 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/e1a90936/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 9d27ebf..483ee0b 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -39,6 +39,7 @@
  * Make sure upgradesstables keeps sstable level (CASSANDRA-6958)
  * Fix LIMT with static columns (CASSANDRA-6956)
  * Fix clash with CQL column name in thrift validation (CASSANDRA-6892)
+ * Fix error with super columns in mixed 1.2-2.0 clusters (CASSANDRA-6966)
 Merged from 1.2:
  * Add UNLOGGED, COUNTER options to BATCH documentation (CASSANDRA-6816)
  * add extra SSL cipher suites (CASSANDRA-6613)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e1a90936/src/java/org/apache/cassandra/db/SuperColumns.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/SuperColumns.java b/src/java/org/apache/cassandra/db/SuperColumns.java
index 513db38..0f74587 100644
--- a/src/java/org/apache/cassandra/db/SuperColumns.java
+++ b/src/java/org/apache/cassandra/db/SuperColumns.java
@@ -260,21 +260,13 @@ public class SuperColumns
 
     public static SCFilter namesFilterToSC(CompositeType type, NamesQueryFilter filter)
     {
-        ByteBuffer scName = null;
-        SortedSet<ByteBuffer> newColumns = new TreeSet<ByteBuffer>(filter.columns.comparator());
+        SortedSet<ByteBuffer> newColumns = new TreeSet<>(type.types.get(1));
+        ByteBuffer scName = scName(filter.columns.first());
         for (ByteBuffer name : filter.columns)
         {
-            ByteBuffer newScName = scName(name);
-
-            if (scName == null)
-            {
-                scName = newScName;
-            }
-            else if (type.types.get(0).compare(scName, newScName) != 0)
-            {
-                // If we're selecting column across multiple SC, it's not something we can translate for an old node
+            // If we're selecting column across multiple SC, it's not something we can translate for an old node
+            if (type.types.get(0).compare(scName, scName(name)) != 0)
                 throw new RuntimeException("Cannot convert filter to old super column format. Update all nodes to Cassandra 2.0 first.");
-            }
 
             newColumns.add(subName(name));
         }
@@ -331,10 +323,14 @@ public class SuperColumns
                     return new SCFilter(null, new SliceQueryFilter(scName(start), scName(finish), reversed, filter.count));
                 }
             }
-            else if (filter.compositesToGroup == 0 && type.types.get(0).compare(scName(start), scName(finish)) == 0)
+            else if (filter.compositesToGroup == -1 && type.types.get(0).compare(scName(start), scName(finish)) == 0)
             {
                 // A slice of subcolumns
-                return new SCFilter(scName(start), filter.withUpdatedSlice(subName(start), subName(finish)));
+                ByteBuffer newStart = subName(start);
+                ByteBuffer newFinish = subName(finish);
+                return new SCFilter(scName(start),
+                                    filter.withUpdatedSlice(newStart  == null ? ByteBufferUtil.EMPTY_BYTE_BUFFER : newStart,
+                                                            newFinish == null ? ByteBufferUtil.EMPTY_BYTE_BUFFER : newFinish));
             }
         }
         else if (!reversed)


[2/2] git commit: Merge branch 'cassandra-2.0' into cassandra-2.1

Posted by sl...@apache.org.
Merge branch 'cassandra-2.0' into cassandra-2.1

Conflicts:
	src/java/org/apache/cassandra/db/SuperColumns.java


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

Branch: refs/heads/cassandra-2.1
Commit: ef08e62589f9a27c76f610058373780ce36a7d89
Parents: 8afe109 e1a9093
Author: Sylvain Lebresne <sy...@datastax.com>
Authored: Wed Apr 2 14:28:54 2014 +0200
Committer: Sylvain Lebresne <sy...@datastax.com>
Committed: Wed Apr 2 14:28:54 2014 +0200

----------------------------------------------------------------------
 CHANGES.txt                                        | 1 +
 src/java/org/apache/cassandra/db/SuperColumns.java | 1 -
 2 files changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/ef08e625/CHANGES.txt
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cassandra/blob/ef08e625/src/java/org/apache/cassandra/db/SuperColumns.java
----------------------------------------------------------------------
diff --cc src/java/org/apache/cassandra/db/SuperColumns.java
index 46c5577,0f74587..bab46eb
--- a/src/java/org/apache/cassandra/db/SuperColumns.java
+++ b/src/java/org/apache/cassandra/db/SuperColumns.java
@@@ -124,52 -205,155 +124,51 @@@ public class SuperColumn
          }
      }
  
 -    public static AbstractType<?> getComparatorFor(CFMetaData metadata, ByteBuffer superColumn)
 -    {
 -        return getComparatorFor(metadata, superColumn != null);
 -    }
 -
 -    public static AbstractType<?> getComparatorFor(CFMetaData metadata, boolean subColumn)
 +    private static CellNameType subType(CellNameType type)
      {
 -        return metadata.isSuper()
 -             ? ((CompositeType)metadata.comparator).types.get(subColumn ? 1 : 0)
 -             : metadata.comparator;
 +        return new SimpleDenseCellNameType(type.subtype(1));
      }
  
 -    // Extract the first component of a columnName, i.e. the super column name
 -    public static ByteBuffer scName(ByteBuffer columnName)
 +    public static CellNameType scNameType(CellNameType type)
      {
 -        return CompositeType.extractComponent(columnName, 0);
 +        return new SimpleDenseCellNameType(type.subtype(0));
      }
  
 -    // Extract the 2nd component of a columnName, i.e. the sub-column name
 -    public static ByteBuffer subName(ByteBuffer columnName)
 +    public static AbstractType<?> getComparatorFor(CFMetaData metadata, ByteBuffer superColumn)
      {
 -        return CompositeType.extractComponent(columnName, 1);
 +        return getComparatorFor(metadata, superColumn != null);
      }
  
 -    // We don't use CompositeType.Builder mostly because we want to avoid having to provide the comparator.
 -    public static ByteBuffer startOf(ByteBuffer scName)
 +    public static AbstractType<?> getComparatorFor(CFMetaData metadata, boolean subColumn)
      {
 -        int length = scName.remaining();
 -        ByteBuffer bb = ByteBuffer.allocate(2 + length + 1);
 -
 -        bb.put((byte) ((length >> 8) & 0xFF));
 -        bb.put((byte) (length & 0xFF));
 -        bb.put(scName.duplicate());
 -        bb.put((byte) 0);
 -        bb.flip();
 -        return bb;
 +        return metadata.isSuper()
 +             ? metadata.comparator.subtype(subColumn ? 1 : 0)
 +             : metadata.comparator.asAbstractType();
      }
  
 -    public static ByteBuffer endOf(ByteBuffer scName)
 +    // Extract the first component of a columnName, i.e. the super column name
 +    public static ByteBuffer scName(Composite columnName)
      {
 -        ByteBuffer bb = startOf(scName);
 -        bb.put(bb.remaining() - 1, (byte)1);
 -        return bb;
 +        return columnName.get(0);
      }
  
 -    public static SCFilter filterToSC(CompositeType type, IDiskAtomFilter filter)
 +    // Extract the 2nd component of a columnName, i.e. the sub-column name
 +    public static ByteBuffer subName(Composite columnName)
      {
 -        if (filter instanceof NamesQueryFilter)
 -            return namesFilterToSC(type, (NamesQueryFilter)filter);
 -        else
 -            return sliceFilterToSC(type, (SliceQueryFilter)filter);
 +        return columnName.get(1);
      }
  
 -    public static SCFilter namesFilterToSC(CompositeType type, NamesQueryFilter filter)
 +    public static Composite startOf(ByteBuffer scName)
      {
 -        SortedSet<ByteBuffer> newColumns = new TreeSet<>(type.types.get(1));
 -        ByteBuffer scName = scName(filter.columns.first());
 -        for (ByteBuffer name : filter.columns)
 -        {
 -            // If we're selecting column across multiple SC, it's not something we can translate for an old node
 -            if (type.types.get(0).compare(scName, scName(name)) != 0)
 -                throw new RuntimeException("Cannot convert filter to old super column format. Update all nodes to Cassandra 2.0 first.");
 -
 -            newColumns.add(subName(name));
 -        }
 -        return new SCFilter(scName, new NamesQueryFilter(newColumns));
 +        return CellNames.compositeDense(scName).start();
      }
  
 -    public static SCFilter sliceFilterToSC(CompositeType type, SliceQueryFilter filter)
 +    public static Composite endOf(ByteBuffer scName)
      {
 -        /*
 -         * There is 3 main cases that we can translate back into super column
 -         * queries:
 -         *   1) We have only one slice where the first component of start and
 -         *   finish is the same, we translate as a slice query on one SC.
 -         *   2) We have only one slice, neither the start and finish have a 2nd
 -         *   component, and end has the 'end of component' set, we translate
 -         *   as a slice of SCs.
 -         *   3) Each slice has the same first component for start and finish, no
 -         *   2nd component and each finish has the 'end of component' set, we
 -         *   translate as a names query of SCs (the filter must then not be reversed).
 -         * Otherwise, we can't do much.
 -         */
 -
 -        boolean reversed = filter.reversed;
 -        if (filter.slices.length == 1)
 -        {
 -            ByteBuffer start = filter.slices[0].start;
 -            ByteBuffer finish = filter.slices[0].start;
 -
 -            if (filter.compositesToGroup == 1)
 -            {
 -                // Note: all the resulting filter must have compositeToGroup == 0 because this
 -                // make no sense for super column on the destination node otherwise
 -                if (start.remaining() == 0)
 -                {
 -                    if (finish.remaining() == 0)
 -                        // An 'IdentityFilter', keep as is (except for the compositeToGroup)
 -                        return new SCFilter(null, new SliceQueryFilter(filter.start(), filter.finish(), reversed, filter.count));
 -
 -                    if (subName(finish) == null
 -                            && ((!reversed && !firstEndOfComponent(finish)) || (reversed && firstEndOfComponent(finish))))
 -                        return new SCFilter(null, new SliceQueryFilter(ByteBufferUtil.EMPTY_BYTE_BUFFER, scName(finish), reversed, filter.count));
 -                }
 -                else if (finish.remaining() == 0)
 -                {
 -                    if (subName(start) == null
 -                            && ((!reversed && firstEndOfComponent(start)) || (reversed && !firstEndOfComponent(start))))
 -                        return new SCFilter(null, new SliceQueryFilter(scName(start), ByteBufferUtil.EMPTY_BYTE_BUFFER, reversed, filter.count));
 -                }
 -                else if (subName(start) == null && subName(finish) == null
 -                        && ((   reversed && !firstEndOfComponent(start) &&  firstEndOfComponent(finish))
 -                            || (!reversed &&  firstEndOfComponent(start) && !firstEndOfComponent(finish))))
 -                {
 -                    // A slice of supercolumns
 -                    return new SCFilter(null, new SliceQueryFilter(scName(start), scName(finish), reversed, filter.count));
 -                }
 -            }
 -            else if (filter.compositesToGroup == -1 && type.types.get(0).compare(scName(start), scName(finish)) == 0)
 -            {
 -                // A slice of subcolumns
 -                ByteBuffer newStart = subName(start);
 -                ByteBuffer newFinish = subName(finish);
 -                return new SCFilter(scName(start),
 -                                    filter.withUpdatedSlice(newStart  == null ? ByteBufferUtil.EMPTY_BYTE_BUFFER : newStart,
 -                                                            newFinish == null ? ByteBufferUtil.EMPTY_BYTE_BUFFER : newFinish));
 -            }
 -        }
 -        else if (!reversed)
 -        {
 -            SortedSet<ByteBuffer> columns = new TreeSet<ByteBuffer>(type.types.get(0));
 -            for (int i = 0; i < filter.slices.length; ++i)
 -            {
 -                ByteBuffer start = filter.slices[i].start;
 -                ByteBuffer finish = filter.slices[i].finish;
 -
 -                if (subName(start) != null || subName(finish) != null
 -                  || type.types.get(0).compare(scName(start), scName(finish)) != 0
 -                  || firstEndOfComponent(start) || !firstEndOfComponent(finish))
 -                    throw new RuntimeException("Cannot convert filter to old super column format. Update all nodes to Cassandra 2.0 first.");
 -
 -                columns.add(scName(start));
 -            }
 -            return new SCFilter(null, new NamesQueryFilter(columns));
 -        }
 -        throw new RuntimeException("Cannot convert filter to old super column format. Update all nodes to Cassandra 2.0 first.");
 +        return CellNames.compositeDense(scName).end();
      }
  
- 
 -    public static IDiskAtomFilter fromSCFilter(CompositeType type, ByteBuffer scName, IDiskAtomFilter filter)
 +    public static IDiskAtomFilter fromSCFilter(CellNameType type, ByteBuffer scName, IDiskAtomFilter filter)
      {
          if (filter instanceof NamesQueryFilter)
              return fromSCNamesFilter(type, scName, (NamesQueryFilter)filter);