You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by ad...@apache.org on 2017/05/10 10:47:36 UTC
[2/9] cassandra git commit: Fix 2ndary indexes on primary key columns
to don't create expiring entries (CASSANDRA-13412)
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/trunk
Commit: b0db519b79701cecac92a7a2c93101cf17fb928d
Parents: 572fef8
Author: adelapena <a....@gmail.com>
Authored: Fri Apr 21 09:33:16 2017 +0100
Committer: adelapena <a....@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