cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject [1/4] git commit: Warn when a read collection has > 64k elements
Date Tue, 03 Dec 2013 13:57:13 GMT
Updated Branches:
  refs/heads/trunk d12a0d7b0 -> b34d43f97


Warn when a read collection has > 64k elements

patch by slebresne; reviewed by iamaleksey for CASSANDRA-5428


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

Branch: refs/heads/trunk
Commit: f634ac7eae468b944d22951fc7c9d05aa6c7f447
Parents: ecd9422
Author: Sylvain Lebresne <sylvain@datastax.com>
Authored: Tue Dec 3 14:53:33 2013 +0100
Committer: Sylvain Lebresne <sylvain@datastax.com>
Committed: Tue Dec 3 14:53:33 2013 +0100

----------------------------------------------------------------------
 CHANGES.txt                                        |  1 +
 .../cassandra/db/marshal/CollectionType.java       | 17 +++++++++++++++++
 .../org/apache/cassandra/db/marshal/ListType.java  |  2 ++
 .../org/apache/cassandra/db/marshal/MapType.java   |  2 ++
 .../org/apache/cassandra/db/marshal/SetType.java   |  2 ++
 5 files changed, 24 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/f634ac7e/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index c80a00a..8e6cffa 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -8,6 +8,7 @@
  * Throw IRE if a prepared has more markers than supported (CASSANDRA-5598)
  * Expose Thread metrics for the native protocol server (CASSANDRA-6234)
  * Change snapshot response message verb (CASSANDRA-6415)
+ * Warn when collection read has > 65K elements (CASSANDRA-5428)
 
 
 1.2.12

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f634ac7e/src/java/org/apache/cassandra/db/marshal/CollectionType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/CollectionType.java b/src/java/org/apache/cassandra/db/marshal/CollectionType.java
index ad2ea67..a34a2b7 100644
--- a/src/java/org/apache/cassandra/db/marshal/CollectionType.java
+++ b/src/java/org/apache/cassandra/db/marshal/CollectionType.java
@@ -20,6 +20,9 @@ package org.apache.cassandra.db.marshal;
 import java.nio.ByteBuffer;
 import java.util.List;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import org.apache.cassandra.cql3.CQL3Type;
 import org.apache.cassandra.db.IColumn;
 import org.apache.cassandra.utils.ByteBufferUtil;
@@ -33,6 +36,10 @@ import org.apache.cassandra.utils.Pair;
  */
 public abstract class CollectionType<T> extends AbstractType<T>
 {
+    private static final Logger logger = LoggerFactory.getLogger(CollectionType.class);
+
+    public static final int MAX_ELEMENTS = 65535;
+
     public enum Kind
     {
         MAP, SET, LIST
@@ -105,6 +112,16 @@ public abstract class CollectionType<T> extends AbstractType<T>
         return (ByteBuffer)result.flip();
     }
 
+    protected List<Pair<ByteBuffer, IColumn>> enforceLimit(List<Pair<ByteBuffer,
IColumn>> columns)
+    {
+        if (columns.size() <= MAX_ELEMENTS)
+            return columns;
+
+        logger.error("Detected collection with {} elements, more than the {} limit. Only
the first {} elements will be returned to the client. "
+                   + "Please see http://cassandra.apache.org/doc/cql3/CQL.html#collections
for more details.", columns.size(), MAX_ELEMENTS, MAX_ELEMENTS);
+        return columns.subList(0, MAX_ELEMENTS);
+    }
+
     public static ByteBuffer pack(List<ByteBuffer> buffers, int elements)
     {
         int size = 0;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f634ac7e/src/java/org/apache/cassandra/db/marshal/ListType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/ListType.java b/src/java/org/apache/cassandra/db/marshal/ListType.java
index b6613ae..b219af1 100644
--- a/src/java/org/apache/cassandra/db/marshal/ListType.java
+++ b/src/java/org/apache/cassandra/db/marshal/ListType.java
@@ -120,6 +120,8 @@ public class ListType<T> extends CollectionType<List<T>>
 
     public ByteBuffer serialize(List<Pair<ByteBuffer, IColumn>> columns)
     {
+        columns = enforceLimit(columns);
+
         List<ByteBuffer> bbs = new ArrayList<ByteBuffer>(columns.size());
         int size = 0;
         for (Pair<ByteBuffer, IColumn> p : columns)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f634ac7e/src/java/org/apache/cassandra/db/marshal/MapType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/MapType.java b/src/java/org/apache/cassandra/db/marshal/MapType.java
index 19310df..750851e 100644
--- a/src/java/org/apache/cassandra/db/marshal/MapType.java
+++ b/src/java/org/apache/cassandra/db/marshal/MapType.java
@@ -137,6 +137,8 @@ public class MapType<K, V> extends CollectionType<Map<K, V>>
      */
     public ByteBuffer serialize(List<Pair<ByteBuffer, IColumn>> columns)
     {
+        columns = enforceLimit(columns);
+
         List<ByteBuffer> bbs = new ArrayList<ByteBuffer>(2 * columns.size());
         int size = 0;
         for (Pair<ByteBuffer, IColumn> p : columns)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f634ac7e/src/java/org/apache/cassandra/db/marshal/SetType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/SetType.java b/src/java/org/apache/cassandra/db/marshal/SetType.java
index 73f25e0..a1ba74d 100644
--- a/src/java/org/apache/cassandra/db/marshal/SetType.java
+++ b/src/java/org/apache/cassandra/db/marshal/SetType.java
@@ -120,6 +120,8 @@ public class SetType<T> extends CollectionType<Set<T>>
 
     public ByteBuffer serialize(List<Pair<ByteBuffer, IColumn>> columns)
     {
+        columns = enforceLimit(columns);
+
         List<ByteBuffer> bbs = new ArrayList<ByteBuffer>(columns.size());
         int size = 0;
         for (Pair<ByteBuffer, IColumn> p : columns)


Mime
View raw message