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 2015/08/07 16:25:01 UTC

cassandra git commit: Fix bug in merging of collections

Repository: cassandra
Updated Branches:
  refs/heads/cassandra-3.0 605bcdcf1 -> 6818ba9ba


Fix bug in merging of collections

Patch by Stefania Alborghetti; reviewed by tjake for CASSANDRA-10001


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

Branch: refs/heads/cassandra-3.0
Commit: 6818ba9ba141006396e88e9d2425f9ecba629969
Parents: 605bcdc
Author: Stefania Alborghetti <st...@datastax.com>
Authored: Fri Aug 7 12:14:05 2015 +0800
Committer: T Jake Luciani <ja...@apache.org>
Committed: Fri Aug 7 10:24:42 2015 -0400

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 src/java/org/apache/cassandra/db/rows/Cell.java |  2 +-
 src/java/org/apache/cassandra/db/rows/Row.java  |  2 +-
 .../org/apache/cassandra/cql3/CQLTester.java    | 13 +---
 .../validation/entities/CollectionsTest.java    | 73 ++++++++++++++++++++
 5 files changed, 79 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/6818ba9b/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 9aca2ce..caf6fb4 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 3.0.0-beta1
+ * Fix bug in merging of collections (CASSANDRA-10001)
  * Optimize batchlog replay to avoid full scans (CASSANDRA-7237)
  * Repair improvements when using vnodes (CASSANDRA-5220)
  * Disable scripted UDFs by default (CASSANDRA-9889)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/6818ba9b/src/java/org/apache/cassandra/db/rows/Cell.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/rows/Cell.java b/src/java/org/apache/cassandra/db/rows/Cell.java
index 1820de2..73d9e44 100644
--- a/src/java/org/apache/cassandra/db/rows/Cell.java
+++ b/src/java/org/apache/cassandra/db/rows/Cell.java
@@ -41,7 +41,7 @@ public abstract class Cell extends ColumnData
     public static final int NO_TTL = 0;
     public static final int NO_DELETION_TIME = Integer.MAX_VALUE;
 
-    public final Comparator<Cell> comparator = (c1, c2) ->
+    public final static Comparator<Cell> comparator = (c1, c2) ->
     {
         int cmp = c1.column().compareTo(c2.column());
         if (cmp != 0)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/6818ba9b/src/java/org/apache/cassandra/db/rows/Row.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/rows/Row.java b/src/java/org/apache/cassandra/db/rows/Row.java
index 929a5fb..0c3dc2d 100644
--- a/src/java/org/apache/cassandra/db/rows/Row.java
+++ b/src/java/org/apache/cassandra/db/rows/Row.java
@@ -465,7 +465,7 @@ public interface Row extends Unfiltered, Iterable<ColumnData>
                         cellReducer.setActiveDeletion(activeDeletion);
                     }
 
-                    Iterator<Cell> cells = MergeIterator.get(complexCells, ColumnData.comparator, cellReducer);
+                    Iterator<Cell> cells = MergeIterator.get(complexCells, Cell.comparator, cellReducer);
                     while (cells.hasNext())
                     {
                         Cell merged = cells.next();

http://git-wip-us.apache.org/repos/asf/cassandra/blob/6818ba9b/test/unit/org/apache/cassandra/cql3/CQLTester.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/CQLTester.java b/test/unit/org/apache/cassandra/cql3/CQLTester.java
index 458d7dd..918e10d 100644
--- a/test/unit/org/apache/cassandra/cql3/CQLTester.java
+++ b/test/unit/org/apache/cassandra/cql3/CQLTester.java
@@ -359,16 +359,9 @@ public abstract class CQLTester
 
     public void flush()
     {
-        try
-        {
-            ColumnFamilyStore store = getCurrentColumnFamilyStore();
-            if (store != null)
-                store.forceFlush().get();
-        }
-        catch (InterruptedException | ExecutionException e)
-        {
-            throw new RuntimeException(e);
-        }
+        ColumnFamilyStore store = getCurrentColumnFamilyStore();
+        if (store != null)
+            store.forceBlockingFlush();
     }
 
     public void compact()

http://git-wip-us.apache.org/repos/asf/cassandra/blob/6818ba9b/test/unit/org/apache/cassandra/cql3/validation/entities/CollectionsTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/entities/CollectionsTest.java b/test/unit/org/apache/cassandra/cql3/validation/entities/CollectionsTest.java
index fdd3dfa..088b9cf 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/entities/CollectionsTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/entities/CollectionsTest.java
@@ -17,12 +17,17 @@
  */
 package org.apache.cassandra.cql3.validation.entities;
 
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
 import java.util.UUID;
 
 import org.junit.Test;
 
 import org.apache.cassandra.cql3.CQLTester;
 
+import static org.junit.Assert.assertEquals;
+
 public class CollectionsTest extends CQLTester
 {
     @Test
@@ -594,4 +599,72 @@ public class CollectionsTest extends CQLTester
         execute("alter table %s drop v");
         execute("alter table %s add v set<int>");
     }
+
+    @Test
+    public void testMapWithLargePartition() throws Throwable
+    {
+        Random r = new Random();
+        long seed = System.nanoTime();
+        System.out.println("Seed " + seed);
+        r.setSeed(seed);
+
+        int len = (1024 * 1024)/100;
+        createTable("CREATE TABLE %s (userid text PRIMARY KEY, properties map<int, text>) with compression = {}");
+
+        final int numKeys = 200;
+        for (int i = 0; i < numKeys; i++)
+        {
+            byte[] b = new byte[len];
+            r.nextBytes(b);
+            execute("UPDATE %s SET properties[?] = ? WHERE userid = 'user'", i, new String(b));
+        }
+
+        flush();
+
+        Object[][] rows = getRows(execute("SELECT properties from %s where userid = 'user'"));
+        assertEquals(1, rows.length);
+        assertEquals(numKeys, ((Map) rows[0][0]).size());
+    }
+
+    @Test
+    public void testMapWithTwoSStables() throws Throwable
+    {
+        createTable("CREATE TABLE %s (userid text PRIMARY KEY, properties map<int, text>) with compression = {}");
+
+        final int numKeys = 100;
+        for (int i = 0; i < numKeys; i++)
+            execute("UPDATE %s SET properties[?] = ? WHERE userid = 'user'", i, "prop_" + Integer.toString(i));
+
+        flush();
+
+        for (int i = numKeys; i < 2*numKeys; i++)
+            execute("UPDATE %s SET properties[?] = ? WHERE userid = 'user'", i, "prop_" + Integer.toString(i));
+
+        flush();
+
+        Object[][] rows = getRows(execute("SELECT properties from %s where userid = 'user'"));
+        assertEquals(1, rows.length);
+        assertEquals(numKeys * 2, ((Map) rows[0][0]).size());
+    }
+
+    @Test
+    public void testSetWithTwoSStables() throws Throwable
+    {
+        createTable("CREATE TABLE %s (userid text PRIMARY KEY, properties set<text>) with compression = {}");
+
+        final int numKeys = 100;
+        for (int i = 0; i < numKeys; i++)
+            execute("UPDATE %s SET properties = properties + ? WHERE userid = 'user'", set("prop_" + Integer.toString(i)));
+
+        flush();
+
+        for (int i = numKeys; i < 2*numKeys; i++)
+            execute("UPDATE %s SET properties = properties + ? WHERE userid = 'user'", set("prop_" + Integer.toString(i)));
+
+        flush();
+
+        Object[][] rows = getRows(execute("SELECT properties from %s where userid = 'user'"));
+        assertEquals(1, rows.length);
+        assertEquals(numKeys * 2, ((Set) rows[0][0]).size());
+    }
 }