cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tylerho...@apache.org
Subject [1/2] cassandra git commit: Fix legacy non-compound range tombstone serialization
Date Sun, 05 Jun 2016 23:30:31 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-3.7 5fde342c2 -> 40e4b0b08


Fix legacy non-compound range tombstone serialization

Patch by Tyler Hobbs; reviewed by Aleksey Yeschenko for CASSANDRA-11930


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

Branch: refs/heads/cassandra-3.7
Commit: c98b6484e124982b455455c9cd847e0b36d5074b
Parents: 02f78f6
Author: Tyler Hobbs <tylerlhobbs@gmail.com>
Authored: Sun Jun 5 18:27:52 2016 -0500
Committer: Tyler Hobbs <tylerlhobbs@gmail.com>
Committed: Sun Jun 5 18:27:52 2016 -0500

----------------------------------------------------------------------
 CHANGES.txt                                     |  2 +
 .../org/apache/cassandra/db/LegacyLayout.java   | 77 +++++++++++++++++++-
 2 files changed, 77 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/c98b6484/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 2de1e25..201a36c 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,6 @@
 3.0.7
+ * Fix legacy serialization of Thrift-generated non-compound range tombstones
+   when communicating with 2.x nodes (CASSANDRA-11930)
  * Fix Directories instantiations where CFS.initialDirectories should be used (CASSANDRA-11849)
  * Avoid referencing DatabaseDescriptor in AbstractType (CASSANDRA-11912)
  * Fix sstables not being protected from removal during index build (CASSANDRA-11905)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/c98b6484/src/java/org/apache/cassandra/db/LegacyLayout.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/LegacyLayout.java b/src/java/org/apache/cassandra/db/LegacyLayout.java
index b90151e..495a12a 100644
--- a/src/java/org/apache/cassandra/db/LegacyLayout.java
+++ b/src/java/org/apache/cassandra/db/LegacyLayout.java
@@ -41,6 +41,8 @@ import org.apache.cassandra.io.util.DataInputPlus;
 import org.apache.cassandra.io.util.DataOutputPlus;
 import org.apache.cassandra.net.MessagingService;
 import org.apache.cassandra.utils.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import static org.apache.cassandra.utils.ByteBufferUtil.bytes;
 
@@ -49,6 +51,8 @@ import static org.apache.cassandra.utils.ByteBufferUtil.bytes;
  */
 public abstract class LegacyLayout
 {
+    private static final Logger logger = LoggerFactory.getLogger(LegacyLayout.class);
+
     public final static int MAX_CELL_NAME_LENGTH = FBUtilities.MAX_UNSIGNED_SHORT;
 
     public final static int STATIC_PREFIX = 0xFFFF;
@@ -2199,9 +2203,19 @@ public abstract class LegacyLayout
             if (size == 0)
                 return;
 
+            if (metadata.isCompound())
+                serializeCompound(out, metadata.isDense());
+            else
+                serializeSimple(out);
+        }
+
+        private void serializeCompound(DataOutputPlus out, boolean isDense) throws IOException
+        {
             List<AbstractType<?>> types = new ArrayList<>(comparator.clusteringComparator.subtypes());
-            if (!metadata.isDense())
+
+            if (!isDense)
                 types.add(UTF8Type.instance);
+
             CompositeType type = CompositeType.getInstance(types);
 
             for (int i = 0; i < size; i++)
@@ -2230,6 +2244,30 @@ public abstract class LegacyLayout
             }
         }
 
+        private void serializeSimple(DataOutputPlus out) throws IOException
+        {
+            List<AbstractType<?>> types = new ArrayList<>(comparator.clusteringComparator.subtypes());
+            assert types.size() == 1 : types;
+
+            for (int i = 0; i < size; i++)
+            {
+                LegacyBound start = starts[i];
+                LegacyBound end = ends[i];
+
+                ClusteringPrefix startClustering = start.bound.clustering();
+                ClusteringPrefix endClustering = end.bound.clustering();
+
+                assert startClustering.size() == 1;
+                assert endClustering.size() == 1;
+
+                ByteBufferUtil.writeWithShortLength(startClustering.get(0), out);
+                ByteBufferUtil.writeWithShortLength(endClustering.get(0), out);
+
+                out.writeInt(delTimes[i]);
+                out.writeLong(markedAts[i]);
+            }
+        }
+
         public long serializedSize(CFMetaData metadata)
         {
             long size = 0;
@@ -2238,8 +2276,17 @@ public abstract class LegacyLayout
             if (this.size == 0)
                 return size;
 
+            if (metadata.isCompound())
+                return size + serializedSizeCompound(metadata.isDense());
+            else
+                return size + serializedSizeSimple();
+        }
+
+        private long serializedSizeCompound(boolean isDense)
+        {
+            long size = 0;
             List<AbstractType<?>> types = new ArrayList<>(comparator.clusteringComparator.subtypes());
-            if (!metadata.isDense())
+            if (!isDense)
                 types.add(UTF8Type.instance);
             CompositeType type = CompositeType.getInstance(types);
 
@@ -2269,5 +2316,31 @@ public abstract class LegacyLayout
             }
             return size;
         }
+
+        private long serializedSizeSimple()
+        {
+            long size = 0;
+            List<AbstractType<?>> types = new ArrayList<>(comparator.clusteringComparator.subtypes());
+            assert types.size() == 1 : types;
+
+            for (int i = 0; i < this.size; i++)
+            {
+                LegacyBound start = starts[i];
+                LegacyBound end = ends[i];
+
+                ClusteringPrefix startClustering = start.bound.clustering();
+                ClusteringPrefix endClustering = end.bound.clustering();
+
+                assert startClustering.size() == 1;
+                assert endClustering.size() == 1;
+
+                size += ByteBufferUtil.serializedSizeWithShortLength(startClustering.get(0));
+                size += ByteBufferUtil.serializedSizeWithShortLength(endClustering.get(0));
+
+                size += TypeSizes.sizeof(delTimes[i]);
+                size += TypeSizes.sizeof(markedAts[i]);
+            }
+            return size;
+        }
     }
 }


Mime
View raw message