cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [01/22] cassandra git commit: Fix 2ndary indexes on primary key columns to don't create expiring entries (CASSANDRA-13412)
Date Thu, 18 May 2017 17:48:25 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.2 486b82a6b -> dd6aa991b
  refs/heads/cassandra-3.0 95635f312 -> 7db6a3b3c
  refs/heads/cassandra-3.11 9723db271 -> 83c9ac313
  refs/heads/trunk d8836d485 -> 4a12dabef


Fix 2ndary indexes on primary key columns to don't create expiring entries (CASSANDRA-13412)


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

Branch: refs/heads/cassandra-3.0
Commit: b0db519b79701cecac92a7a2c93101cf17fb928d
Parents: 572fef8
Author: adelapena <a.penya.garcia@gmail.com>
Authored: Fri Apr 21 09:33:16 2017 +0100
Committer: adelapena <a.penya.garcia@gmail.com>
Committed: Wed May 10 10:52:50 2017 +0100

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../AbstractSimplePerColumnSecondaryIndex.java  |  2 +-
 .../validation/entities/SecondaryIndexTest.java | 42 ++++++++++++++++++++
 3 files changed, 44 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/b0db519b/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 2517432..f62f162 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 2.1.18
+ * Fix 2ndary indexes on primary key columns to don't create expiring entries (CASSANDRA-13412)
  * Set javac encoding to utf-8 (CASSANDRA-13466)
  * Fix 2ndary index queries on partition keys for tables with static columns (CASSANDRA-13147)
  * Fix ParseError unhashable type list in cqlsh copy from (CASSANDRA-13364)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b0db519b/src/java/org/apache/cassandra/db/index/AbstractSimplePerColumnSecondaryIndex.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/index/AbstractSimplePerColumnSecondaryIndex.java
b/src/java/org/apache/cassandra/db/index/AbstractSimplePerColumnSecondaryIndex.java
index e80c7bd..d7a1d8a 100644
--- a/src/java/org/apache/cassandra/db/index/AbstractSimplePerColumnSecondaryIndex.java
+++ b/src/java/org/apache/cassandra/db/index/AbstractSimplePerColumnSecondaryIndex.java
@@ -116,7 +116,7 @@ public abstract class AbstractSimplePerColumnSecondaryIndex extends PerColumnSec
         DecoratedKey valueKey = getIndexKeyFor(getIndexedValue(rowKey, cell));
         ColumnFamily cfi = ArrayBackedSortedColumns.factory.create(indexCfs.metadata, false,
1);
         CellName name = makeIndexColumnName(rowKey, cell);
-        if (cell instanceof ExpiringCell)
+        if (!columnDef.isPrimaryKeyColumn() && cell instanceof ExpiringCell)
         {
             ExpiringCell ec = (ExpiringCell) cell;
             cfi.addColumn(new BufferExpiringCell(name, ByteBufferUtil.EMPTY_BYTE_BUFFER,
ec.timestamp(), ec.getTimeToLive(), ec.getLocalDeletionTime()));

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b0db519b/test/unit/org/apache/cassandra/cql3/validation/entities/SecondaryIndexTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/entities/SecondaryIndexTest.java
b/test/unit/org/apache/cassandra/cql3/validation/entities/SecondaryIndexTest.java
index b723f60..1e63e3a 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/entities/SecondaryIndexTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/entities/SecondaryIndexTest.java
@@ -819,4 +819,46 @@ public class SecondaryIndexTest extends CQLTester
         assertRows(execute("SELECT * FROM %s WHERE v = ?", 1),
                    row(1, 1, 9, 1));
     }
+
+    @Test
+    public void testIndexOnPartitionKeyInsertExpiringColumn() throws Throwable
+    {
+        createTable("CREATE TABLE %s (k1 int, k2 int, a int, b int, PRIMARY KEY ((k1, k2)))");
+        createIndex("CREATE INDEX on %s(k1)");
+        execute("INSERT INTO %s (k1, k2, a, b) VALUES (1, 2, 3, 4)");
+        assertRows(execute("SELECT * FROM %s WHERE k1 = 1"), row(1, 2, 3, 4));
+        execute("UPDATE %s USING TTL 1 SET b = 10 WHERE k1 = 1 AND k2 = 2");
+        Thread.sleep(1000);
+        assertRows(execute("SELECT * FROM %s WHERE k1 = 1"), row(1, 2, 3, null));
+    }
+
+    @Test
+    public void testIndexOnClusteringKeyInsertExpiringColumn() throws Throwable
+    {
+        createTable("CREATE TABLE %s (pk int, ck int, a int, b int, PRIMARY KEY (pk, ck))");
+        createIndex("CREATE INDEX on %s(ck)");
+        execute("INSERT INTO %s (pk, ck, a, b) VALUES (1, 2, 3, 4)");
+        assertRows(execute("SELECT * FROM %s WHERE ck = 2"), row(1, 2, 3, 4));
+        execute("UPDATE %s USING TTL 1 SET b = 10 WHERE pk = 1 AND ck = 2");
+        Thread.sleep(1000);
+        assertRows(execute("SELECT * FROM %s WHERE ck = 2"), row(1, 2, 3, null));
+    }
+
+    @Test
+    public void testIndexOnRegularColumnInsertExpiringColumn() throws Throwable
+    {
+        createTable("CREATE TABLE %s (pk int, ck int, a int, b int, PRIMARY KEY (pk, ck))");
+        createIndex("CREATE INDEX on %s(a)");
+        execute("INSERT INTO %s (pk, ck, a, b) VALUES (1, 2, 3, 4)");
+        assertRows(execute("SELECT * FROM %s WHERE a = 3"), row(1, 2, 3, 4));
+
+        execute("UPDATE %s USING TTL 1 SET b = 10 WHERE pk = 1 AND ck = 2");
+        Thread.sleep(1000);
+        assertRows(execute("SELECT * FROM %s WHERE a = 3"), row(1, 2, 3, null));
+
+        execute("UPDATE %s USING TTL 1 SET a = 5 WHERE pk = 1 AND ck = 2");
+        Thread.sleep(1000);
+        assertEmpty(execute("SELECT * FROM %s WHERE a = 3"));
+        assertEmpty(execute("SELECT * FROM %s WHERE a = 5"));
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org


Mime
View raw message