cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [1/3] cassandra git commit: Correctly identify partition deletions for index transactions
Date Wed, 16 Sep 2015 08:42:39 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-3.0 0d4e0cd22 -> c694cd62a
  refs/heads/trunk 61ce1b9a7 -> 48da81dc4


Correctly identify partition deletions for index transactions

Patch by Sam Tunnicliffe; reviewed by Sylvain Lebresne for
CASSANDRA-10343


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

Branch: refs/heads/cassandra-3.0
Commit: c694cd62af6f404ea0900e6e15410cbb8681841f
Parents: 0d4e0cd
Author: Sam Tunnicliffe <sam@beobal.com>
Authored: Tue Sep 15 16:01:36 2015 +0100
Committer: Sam Tunnicliffe <sam@beobal.com>
Committed: Wed Sep 16 09:37:15 2015 +0100

----------------------------------------------------------------------
 .../db/partitions/AtomicBTreePartition.java     |  2 +-
 .../org/apache/cassandra/index/StubIndex.java   | 14 ++++++----
 .../index/internal/CustomIndexTest.java         | 29 ++++++++++++++++++++
 3 files changed, 38 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/c694cd62/src/java/org/apache/cassandra/db/partitions/AtomicBTreePartition.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/partitions/AtomicBTreePartition.java b/src/java/org/apache/cassandra/db/partitions/AtomicBTreePartition.java
index ae8a1c3..2be882e 100644
--- a/src/java/org/apache/cassandra/db/partitions/AtomicBTreePartition.java
+++ b/src/java/org/apache/cassandra/db/partitions/AtomicBTreePartition.java
@@ -127,7 +127,7 @@ public class AtomicBTreePartition extends AbstractBTreePartition
                 updater.ref = current;
                 updater.reset();
 
-                if (!update.deletionInfo().isLive())
+                if (!update.deletionInfo().getPartitionDeletion().isLive())
                     indexer.onPartitionDeletion(update.deletionInfo().getPartitionDeletion());
 
                 if (update.deletionInfo().hasRanges())

http://git-wip-us.apache.org/repos/asf/cassandra/blob/c694cd62/test/unit/org/apache/cassandra/index/StubIndex.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/index/StubIndex.java b/test/unit/org/apache/cassandra/index/StubIndex.java
index 0d3cf47..0ea03dc 100644
--- a/test/unit/org/apache/cassandra/index/StubIndex.java
+++ b/test/unit/org/apache/cassandra/index/StubIndex.java
@@ -38,6 +38,8 @@ import org.apache.cassandra.utils.concurrent.OpOrder;
 
 public class StubIndex implements Index
 {
+    public List<DeletionTime> partitionDeletions = new ArrayList<>();
+    public List<RangeTombstone> rangeTombstones = new ArrayList<>();
     public List<Row> rowsInserted = new ArrayList<>();
     public List<Row> rowsDeleted = new ArrayList<>();
     public List<Pair<Row,Row>> rowsUpdated = new ArrayList<>();
@@ -48,6 +50,8 @@ public class StubIndex implements Index
     {
         rowsInserted.clear();
         rowsDeleted.clear();
+        partitionDeletions.clear();
+        rangeTombstones.clear();
     }
 
     public StubIndex(ColumnFamilyStore baseCfs, IndexMetadata metadata)
@@ -58,11 +62,7 @@ public class StubIndex implements Index
 
     public boolean indexes(PartitionColumns columns)
     {
-        for (ColumnDefinition col : columns)
-            for (ColumnIdentifier indexed : indexMetadata.columns)
-                if (indexed.equals(col.name))
-                    return true;
-        return false;
+        return true;
     }
 
     public boolean shouldBuildBlocking()
@@ -80,7 +80,7 @@ public class StubIndex implements Index
         return filter;
     }
 
-    public Indexer indexerFor(DecoratedKey key,
+    public Indexer indexerFor(final DecoratedKey key,
                               int nowInSec,
                               OpOrder.Group opGroup,
                               IndexTransaction.Type transactionType)
@@ -93,10 +93,12 @@ public class StubIndex implements Index
 
             public void partitionDelete(DeletionTime deletionTime)
             {
+                partitionDeletions.add(deletionTime);
             }
 
             public void rangeTombstone(RangeTombstone tombstone)
             {
+                rangeTombstones.add(tombstone);
             }
 
             public void insertRow(Row row)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/c694cd62/test/unit/org/apache/cassandra/index/internal/CustomIndexTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/index/internal/CustomIndexTest.java b/test/unit/org/apache/cassandra/index/internal/CustomIndexTest.java
index 255af4b..2f7a10b 100644
--- a/test/unit/org/apache/cassandra/index/internal/CustomIndexTest.java
+++ b/test/unit/org/apache/cassandra/index/internal/CustomIndexTest.java
@@ -57,6 +57,35 @@ public class CustomIndexTest extends CQLTester
         assertTrue(excluded.rowsInserted.isEmpty());
     }
 
+    @Test
+    public void indexReceivesWriteTimeDeletionsCorrectly() throws Throwable
+    {
+        createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a, b, c))");
+        String indexName = "test_index";
+        createIndex(String.format("CREATE CUSTOM INDEX %s ON %%s(d) USING '%s'",
+                                  indexName, StubIndex.class.getName()));
+
+        execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 0, 0, 0);
+        execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 0, 1, 1);
+        execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 0, 2, 2);
+        execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 1, 3, 3);
+
+        SecondaryIndexManager indexManager = getCurrentColumnFamilyStore().indexManager;
+        StubIndex index = (StubIndex)indexManager.getIndexByName(indexName);
+        assertEquals(4, index.rowsInserted.size());
+        assertTrue(index.partitionDeletions.isEmpty());
+        assertTrue(index.rangeTombstones.isEmpty());
+
+        execute("DELETE FROM %s WHERE a=0 AND b=0");
+        assertTrue(index.partitionDeletions.isEmpty());
+        assertEquals(1, index.rangeTombstones.size());
+
+        execute("DELETE FROM %s WHERE a=0");
+        assertEquals(1, index.partitionDeletions.size());
+        assertEquals(1, index.rangeTombstones.size());
+    }
+
+
     public static final class IndexIncludedInBuild extends StubIndex
     {
         public IndexIncludedInBuild(ColumnFamilyStore baseCfs, IndexMetadata metadata)


Mime
View raw message