cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [3/6] cassandra git commit: Ensure stale index entries are purged on read
Date Thu, 14 Jan 2016 14:16:42 GMT
Ensure stale index entries are purged on read

Patch by Sam Tunnicliffe; reviewed by Benedict Elliot Smith for
CASSANDRA-11013


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

Branch: refs/heads/trunk
Commit: 06960d752ab6748ee87ac6743f0d34004e73468a
Parents: 94e7ef1
Author: Sam Tunnicliffe <sam@beobal.com>
Authored: Thu Jan 14 11:39:30 2016 +0000
Committer: Sam Tunnicliffe <sam@beobal.com>
Committed: Thu Jan 14 14:06:43 2016 +0000

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../internal/composites/CompositesSearcher.java |  2 +-
 test/unit/org/apache/cassandra/Util.java        | 32 ++++++++++++++++++++
 .../apache/cassandra/db/SecondaryIndexTest.java | 18 +++++++++++
 .../org/apache/cassandra/index/StubIndex.java   | 27 ++---------------
 5 files changed, 54 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/06960d75/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index a37ec99..143ed2d 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 3.0.3
+ * Ensure stale index entries are purged during reads (CASSANDRA-11013)
  * Fix AssertionError when removing from list using UPDATE (CASSANDRA-10954)
  * Fix UnsupportedOperationException when reading old sstable with range
    tombstone (CASSANDRA-10743)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/06960d75/src/java/org/apache/cassandra/index/internal/composites/CompositesSearcher.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/index/internal/composites/CompositesSearcher.java
b/src/java/org/apache/cassandra/index/internal/composites/CompositesSearcher.java
index b8ed800..765ae4d 100644
--- a/src/java/org/apache/cassandra/index/internal/composites/CompositesSearcher.java
+++ b/src/java/org/apache/cassandra/index/internal/composites/CompositesSearcher.java
@@ -242,7 +242,7 @@ public class CompositesSearcher extends CassandraIndexSearcher
             }
 
             @Override
-            public void onClose()
+            public void onPartitionClose()
             {
                 deleteAllEntries(staleEntries, writeOp, nowInSec);
             }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/06960d75/test/unit/org/apache/cassandra/Util.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/Util.java b/test/unit/org/apache/cassandra/Util.java
index 8658ff3..7ce8f04 100644
--- a/test/unit/org/apache/cassandra/Util.java
+++ b/test/unit/org/apache/cassandra/Util.java
@@ -57,6 +57,7 @@ import org.apache.cassandra.service.StorageService;
 import org.apache.cassandra.utils.ByteBufferUtil;
 import org.apache.cassandra.utils.CounterId;
 import org.apache.cassandra.utils.FBUtilities;
+import org.apache.cassandra.utils.concurrent.OpOrder;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
@@ -563,4 +564,35 @@ public class Util
             return content.hasNext() ? content.next() : endOfData();
         }
     }
+
+    public static UnfilteredPartitionIterator executeLocally(PartitionRangeReadCommand command,
+                                                             ColumnFamilyStore cfs,
+                                                             ReadOrderGroup orderGroup)
+    {
+        return new InternalPartitionRangeReadCommand(command).queryStorageInternal(cfs, orderGroup);
+    }
+
+    private static final class InternalPartitionRangeReadCommand extends PartitionRangeReadCommand
+    {
+
+        private InternalPartitionRangeReadCommand(PartitionRangeReadCommand original)
+        {
+            super(original.isDigestQuery(),
+                  original.digestVersion(),
+                  original.isForThrift(),
+                  original.metadata(),
+                  original.nowInSec(),
+                  original.columnFilter(),
+                  original.rowFilter(),
+                  original.limits(),
+                  original.dataRange(),
+                  Optional.empty());
+        }
+
+        private UnfilteredPartitionIterator queryStorageInternal(ColumnFamilyStore cfs,
+                                                                 ReadOrderGroup orderGroup)
+        {
+            return queryStorage(cfs, orderGroup);
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/06960d75/test/unit/org/apache/cassandra/db/SecondaryIndexTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/SecondaryIndexTest.java b/test/unit/org/apache/cassandra/db/SecondaryIndexTest.java
index 55ab574..bbccc48 100644
--- a/test/unit/org/apache/cassandra/db/SecondaryIndexTest.java
+++ b/test/unit/org/apache/cassandra/db/SecondaryIndexTest.java
@@ -37,8 +37,10 @@ import org.apache.cassandra.cql3.statements.IndexTarget;
 import org.apache.cassandra.db.marshal.AbstractType;
 import org.apache.cassandra.db.partitions.*;
 import org.apache.cassandra.db.rows.Row;
+import org.apache.cassandra.db.rows.RowIterator;
 import org.apache.cassandra.exceptions.ConfigurationException;
 import org.apache.cassandra.index.Index;
+import org.apache.cassandra.index.internal.CassandraIndex;
 import org.apache.cassandra.schema.IndexMetadata;
 import org.apache.cassandra.schema.KeyspaceParams;
 import org.apache.cassandra.utils.ByteBufferUtil;
@@ -315,6 +317,8 @@ public class SecondaryIndexTest
                        true,
                        false);
         assertIndexedNone(cfs, col, 1L);
+        ColumnFamilyStore indexCfs = cfs.indexManager.getAllIndexColumnFamilyStores().iterator().next();
+        assertIndexCfsIsEmpty(indexCfs);
     }
 
     @Test
@@ -354,6 +358,9 @@ public class SecondaryIndexTest
         // TODO: Figure out why this is re-inserting
         keyspace.apply(new RowUpdateBuilder(cfs.metadata, 2, "k1").clustering("c1").add("birthdate",
10l).build(), true, false);
         assertIndexedNone(cfs, col, 20l);
+
+        ColumnFamilyStore indexCfs = cfs.indexManager.getAllIndexColumnFamilyStores().iterator().next();
+        assertIndexCfsIsEmpty(indexCfs);
     }
 
     // See CASSANDRA-6098
@@ -508,4 +515,15 @@ public class SecondaryIndexTest
             assertEquals(count, Util.size(iter));
         }
     }
+
+    private void assertIndexCfsIsEmpty(ColumnFamilyStore indexCfs)
+    {
+        PartitionRangeReadCommand command = (PartitionRangeReadCommand)Util.cmd(indexCfs).build();
+        try (ReadOrderGroup orderGroup = command.startOrderGroup();
+             PartitionIterator iter = UnfilteredPartitionIterators.filter(Util.executeLocally(command,
indexCfs, orderGroup),
+                                                                          FBUtilities.nowInSeconds()))
+        {
+            assertFalse(iter.hasNext());
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/06960d75/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 cd0541f..28ea097 100644
--- a/test/unit/org/apache/cassandra/index/StubIndex.java
+++ b/test/unit/org/apache/cassandra/index/StubIndex.java
@@ -22,6 +22,7 @@ import java.util.*;
 import java.util.concurrent.Callable;
 import java.util.function.BiFunction;
 
+import org.apache.cassandra.Util;
 import org.apache.cassandra.config.ColumnDefinition;
 import org.apache.cassandra.cql3.Operator;
 import org.apache.cassandra.db.*;
@@ -193,35 +194,11 @@ public class StubIndex implements Index
 
     public Searcher searcherFor(final ReadCommand command)
     {
-        return orderGroup -> new InternalPartitionRangeReadCommand((PartitionRangeReadCommand)command)
-                             .queryStorageInternal(baseCfs, orderGroup);
+        return (orderGroup) -> Util.executeLocally((PartitionRangeReadCommand)command,
baseCfs, orderGroup);
     }
 
     public BiFunction<PartitionIterator, ReadCommand, PartitionIterator> postProcessorFor(ReadCommand
readCommand)
     {
         return (iter, command) -> iter;
     }
-
-    private static final class InternalPartitionRangeReadCommand extends PartitionRangeReadCommand
-    {
-
-        private InternalPartitionRangeReadCommand(PartitionRangeReadCommand original)
-        {
-            super(original.isDigestQuery(),
-                  original.digestVersion(),
-                  original.isForThrift(),
-                  original.metadata(),
-                  original.nowInSec(),
-                  original.columnFilter(),
-                  original.rowFilter(),
-                  original.limits(),
-                  original.dataRange(),
-                  Optional.empty());
-        }
-
-        private UnfilteredPartitionIterator queryStorageInternal(ColumnFamilyStore cfs, ReadOrderGroup
orderGroup)
-        {
-            return queryStorage(cfs, orderGroup);
-        }
-    }
 }


Mime
View raw message