You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by sa...@apache.org on 2015/10/28 12:55:09 UTC

[2/3] cassandra git commit: Correctly mark indexes built/removed when rebuilding

Correctly mark indexes built/removed when rebuilding

Patch by Sam Tunnicliffe; reviewed by Benjamin Lerer for CASSANDRA-10601


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

Branch: refs/heads/trunk
Commit: 13e9fd55ff93c26ca339dfa30ed9ac7113894e8e
Parents: 5bc3c4b
Author: Sam Tunnicliffe <sa...@beobal.com>
Authored: Tue Oct 27 15:09:18 2015 +0000
Committer: Sam Tunnicliffe <sa...@beobal.com>
Committed: Wed Oct 28 11:36:44 2015 +0000

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../cassandra/index/SecondaryIndexManager.java  | 11 +++---
 .../index/internal/CassandraIndex.java          | 15 ++------
 .../index/internal/CassandraIndexTest.java      | 20 +++++++++++
 .../index/internal/CustomCassandraIndex.java    | 38 ++------------------
 5 files changed, 31 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/13e9fd55/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index dd7949e..76b1a55 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 3.0
+ * Fix marking of indexes as built and removed (CASSANDRA-10601)
  * Skip initialization of non-registered 2i instances, remove Index::getIndexName (CASSANDRA-10595)
  * Fix batches on multiple tables (CASSANDRA-10554)
  * Ensure compaction options are validated when updating KeyspaceMetadata (CASSANDRA-10569)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/13e9fd55/src/java/org/apache/cassandra/index/SecondaryIndexManager.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/index/SecondaryIndexManager.java b/src/java/org/apache/cassandra/index/SecondaryIndexManager.java
index 7d866df..3ed9714 100644
--- a/src/java/org/apache/cassandra/index/SecondaryIndexManager.java
+++ b/src/java/org/apache/cassandra/index/SecondaryIndexManager.java
@@ -185,8 +185,8 @@ public class SecondaryIndexManager implements IndexRegistry
         Index index = indexes.remove(indexName);
         if (null != index)
         {
+            markIndexRemoved(indexName);
             executeBlocking(index.getInvalidateTask());
-            unregisterIndex(index);
         }
     }
 
@@ -355,14 +355,14 @@ public class SecondaryIndexManager implements IndexRegistry
                     indexes.stream().map(i -> i.getIndexMetadata().name).collect(Collectors.joining(",")));
     }
 
-    private void markIndexBuilt(String indexName)
+    public void markIndexBuilt(String indexName)
     {
-        SystemKeyspace.setIndexBuilt(baseCfs.name, indexName);
+        SystemKeyspace.setIndexBuilt(baseCfs.keyspace.getName(), indexName);
     }
 
-    private void markIndexRemoved(String indexName)
+    public void markIndexRemoved(String indexName)
     {
-        SystemKeyspace.setIndexRemoved(baseCfs.name, indexName);
+        SystemKeyspace.setIndexRemoved(baseCfs.keyspace.getName(), indexName);
     }
 
 
@@ -410,6 +410,7 @@ public class SecondaryIndexManager implements IndexRegistry
      */
     public void invalidateAllIndexesBlocking()
     {
+        markAllIndexesRemoved();
         executeAllBlocking(indexes.values().stream(), Index::getInvalidateTask);
     }
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/13e9fd55/src/java/org/apache/cassandra/index/internal/CassandraIndex.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/index/internal/CassandraIndex.java b/src/java/org/apache/cassandra/index/internal/CassandraIndex.java
index 7b9d18f..5b5b7e4 100644
--- a/src/java/org/apache/cassandra/index/internal/CassandraIndex.java
+++ b/src/java/org/apache/cassandra/index/internal/CassandraIndex.java
@@ -176,7 +176,6 @@ public abstract class CassandraIndex implements Index
     public Callable<?> getInvalidateTask()
     {
         return () -> {
-            markRemoved();
             invalidate();
             return null;
         };
@@ -632,16 +631,6 @@ public abstract class CassandraIndex implements Index
         return SystemKeyspace.isIndexBuilt(baseCfs.keyspace.getName(), metadata.name);
     }
 
-    private void markBuilt()
-    {
-        SystemKeyspace.setIndexBuilt(baseCfs.keyspace.getName(), metadata.name);
-    }
-
-    private void markRemoved()
-    {
-        SystemKeyspace.setIndexRemoved(baseCfs.keyspace.getName(), metadata.name);
-    }
-
     private boolean isPrimaryKeyIndex()
     {
         return indexedColumn.isPrimaryKeyColumn();
@@ -668,7 +657,7 @@ public abstract class CassandraIndex implements Index
                             baseCfs.metadata.ksName,
                             baseCfs.metadata.cfName,
                             metadata.name);
-                markBuilt();
+                baseCfs.indexManager.markIndexBuilt(metadata.name);
                 return;
             }
 
@@ -682,7 +671,7 @@ public abstract class CassandraIndex implements Index
             Future<?> future = CompactionManager.instance.submitIndexBuild(builder);
             FBUtilities.waitOnFuture(future);
             indexCfs.forceBlockingFlush();
-            markBuilt();
+            baseCfs.indexManager.markIndexBuilt(metadata.name);
         }
         logger.info("Index build of {} complete", metadata.name);
     }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/13e9fd55/test/unit/org/apache/cassandra/index/internal/CassandraIndexTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/index/internal/CassandraIndexTest.java b/test/unit/org/apache/cassandra/index/internal/CassandraIndexTest.java
index 34cbe16..2ca858d 100644
--- a/test/unit/org/apache/cassandra/index/internal/CassandraIndexTest.java
+++ b/test/unit/org/apache/cassandra/index/internal/CassandraIndexTest.java
@@ -468,6 +468,26 @@ public class CassandraIndexTest extends CQLTester
         assertRows(execute("SELECT * FROM %s WHERE c = 3"), row(2, 3, 3));
     }
 
+    @Test
+    public void indexCorrectlyMarkedAsBuildAndRemoved() throws Throwable
+    {
+        String indexName = "build_remove_test_idx";
+        String tableName = createTable("CREATE TABLE %s (a int, b int, c int, PRIMARY KEY (a, b))");
+        createIndex(String.format("CREATE INDEX %s ON %%s(c)", indexName));
+        waitForIndex(KEYSPACE, tableName, indexName);
+        // check that there are no other rows in the built indexes table
+        assertRows(execute(String.format("SELECT * FROM %s.\"%s\"", SystemKeyspace.NAME, SystemKeyspace.BUILT_INDEXES)),
+                   row(KEYSPACE, indexName));
+
+        // rebuild the index and verify the built status table
+        getCurrentColumnFamilyStore().rebuildSecondaryIndex(indexName);
+        waitForIndex(KEYSPACE, tableName, indexName);
+
+        // check that there are no other rows in the built indexes table
+        assertRows(execute(String.format("SELECT * FROM %s.\"%s\"", SystemKeyspace.NAME, SystemKeyspace.BUILT_INDEXES)),
+                   row(KEYSPACE, indexName));
+    }
+
     // this is slightly annoying, but we cannot read rows from the methods in Util as
     // ReadCommand#executeInternal uses metadata retrieved via the cfId, which the index
     // CFS inherits from the base CFS. This has the 'wrong' partitioner (the index table

http://git-wip-us.apache.org/repos/asf/cassandra/blob/13e9fd55/test/unit/org/apache/cassandra/index/internal/CustomCassandraIndex.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/index/internal/CustomCassandraIndex.java b/test/unit/org/apache/cassandra/index/internal/CustomCassandraIndex.java
index 2dc9535..0957f74 100644
--- a/test/unit/org/apache/cassandra/index/internal/CustomCassandraIndex.java
+++ b/test/unit/org/apache/cassandra/index/internal/CustomCassandraIndex.java
@@ -121,7 +121,6 @@ public class CustomCassandraIndex implements Index
     public Callable<?> getInvalidateTask()
     {
         return () -> {
-            markRemoved();
             invalidate();
             return null;
         };
@@ -217,29 +216,6 @@ public class CustomCassandraIndex implements Index
     public Index.Searcher searcherFor(ReadCommand command)
     {
         return null;
-        /*
-        Optional<RowFilter.Expression> target = getTargetExpression(command.rowFilter().getExpressions());
-
-        if (target.isPresent())
-        {
-            target.get().validateForIndexing();
-            switch (getIndexMetadata().indexType)
-            {
-                case COMPOSITES:
-                    return new CompositesSearcher(command, target.get(), this);
-                case KEYS:
-                    return new KeysSearcher(command, target.get(), this);
-                default:
-                    throw new IllegalStateException(String.format("Unsupported index type %s for index %s on %s",
-                                                                  metadata.indexType,
-                                                                  metadata.name,
-                                                                  indexedColumn.name.toString()));
-            }
-        }
-
-        return null;
-
-        */
     }
 
     public void validate(PartitionUpdate update) throws InvalidRequestException
@@ -612,16 +588,6 @@ public class CustomCassandraIndex implements Index
         return SystemKeyspace.isIndexBuilt(baseCfs.keyspace.getName(), metadata.name);
     }
 
-    private void markBuilt()
-    {
-        SystemKeyspace.setIndexBuilt(baseCfs.keyspace.getName(), metadata.name);
-    }
-
-    private void markRemoved()
-    {
-        SystemKeyspace.setIndexRemoved(baseCfs.keyspace.getName(), metadata.name);
-    }
-
     private boolean isPrimaryKeyIndex()
     {
         return indexedColumn.isPrimaryKeyColumn();
@@ -648,7 +614,7 @@ public class CustomCassandraIndex implements Index
                             baseCfs.metadata.ksName,
                             baseCfs.metadata.cfName,
                             metadata.name);
-                markBuilt();
+                baseCfs.indexManager.markIndexBuilt(metadata.name);
                 return;
             }
 
@@ -662,7 +628,7 @@ public class CustomCassandraIndex implements Index
             Future<?> future = CompactionManager.instance.submitIndexBuild(builder);
             FBUtilities.waitOnFuture(future);
             indexCfs.forceBlockingFlush();
-            markBuilt();
+            baseCfs.indexManager.markIndexBuilt(metadata.name);
         }
         logger.info("Index build of {} complete", metadata.name);
     }