cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alek...@apache.org
Subject [1/3] cassandra git commit: Do not attempt to rebuild indexes if no index accepts any column
Date Tue, 21 Apr 2015 11:43:19 GMT
Repository: cassandra
Updated Branches:
  refs/heads/trunk 1fab7b785 -> 1e8c5e0a1


Do not attempt to rebuild indexes if no index accepts any column

patch by Sergio Bossa; reviewed by Sam Tunnicliffe for CASSANDRA-9196


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

Branch: refs/heads/trunk
Commit: b325316f58a4df07d8037b179fe53c03f97dfd2e
Parents: 738229b
Author: Sergio Bossa <sergio.bossa@gmail.com>
Authored: Wed Apr 15 19:22:21 2015 +0100
Committer: Aleksey Yeschenko <aleksey@apache.org>
Committed: Tue Apr 21 14:16:41 2015 +0300

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../db/index/SecondaryIndexManager.java         | 19 ++++++++++++++
 .../cassandra/db/ColumnFamilyStoreTest.java     | 27 ++++++++++++++++++++
 .../db/index/PerRowSecondaryIndexTest.java      | 10 +++++++-
 4 files changed, 56 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/b325316f/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 6c546c4..5e1e62c 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 2.0.15:
+ * Do not attempt to rebuild indexes if no index accepts any column (CASSANDRA-9196)
  * Don't initiate snitch reconnection for dead states (CASSANDRA-7292)
  * Fix ArrayIndexOutOfBoundsException in CQLSSTableWriter (CASSANDRA-8978)
  * Add shutdown gossip state to prevent timeouts during rolling restarts (CASSANDRA-8336)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b325316f/src/java/org/apache/cassandra/db/index/SecondaryIndexManager.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/index/SecondaryIndexManager.java b/src/java/org/apache/cassandra/db/index/SecondaryIndexManager.java
index fda79f8..1db7de6 100644
--- a/src/java/org/apache/cassandra/db/index/SecondaryIndexManager.java
+++ b/src/java/org/apache/cassandra/db/index/SecondaryIndexManager.java
@@ -131,6 +131,7 @@ public class SecondaryIndexManager
      */
     public void maybeBuildSecondaryIndexes(Collection<SSTableReader> sstables, Set<String>
idxNames)
     {
+        idxNames = filterByColumn(idxNames);
         if (idxNames.isEmpty())
             return;
 
@@ -580,6 +581,24 @@ public class SecondaryIndexManager
         return true;
     }
 
+    private Set<String> filterByColumn(Set<String> idxNames)
+    {
+        Set<SecondaryIndex> indexes = getIndexesByNames(idxNames);
+        Set<String> filtered = new HashSet<>(idxNames.size());
+        for (SecondaryIndex candidate : indexes)
+        {
+            for (ColumnDefinition column : baseCfs.metadata.allColumns())
+            {
+                if (candidate.indexes(column.name))
+                {
+                    filtered.add(candidate.getIndexName());
+                    break;
+                }
+            }
+        }
+        return filtered;
+    }
+
     public static interface Updater
     {
         /** called when constructing the index against pre-existing data */

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b325316f/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java b/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java
index 292b7f2..8f4a18f 100644
--- a/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java
+++ b/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java
@@ -45,6 +45,7 @@ import org.apache.cassandra.config.ColumnDefinition;
 import org.apache.cassandra.config.Schema;
 import org.apache.cassandra.db.columniterator.IdentityQueryFilter;
 import org.apache.cassandra.db.filter.*;
+import org.apache.cassandra.db.index.PerRowSecondaryIndexTest;
 import org.apache.cassandra.db.index.SecondaryIndex;
 import org.apache.cassandra.db.marshal.CompositeType;
 import org.apache.cassandra.db.marshal.LexicalUUIDType;
@@ -2172,4 +2173,30 @@ public class ColumnFamilyStoreTest extends SchemaLoader
         });
         System.err.println("Row key: " + rowKey + " Cols: " + transformed);
     }
+
+    @Test
+    public void testRebuildSecondaryIndex() throws IOException
+    {
+        RowMutation rm;
+
+        rm = new RowMutation("PerRowSecondaryIndex", ByteBufferUtil.bytes("k1"));
+        rm.add("Indexed1", ByteBufferUtil.bytes("indexed"), ByteBufferUtil.bytes("foo"),
1);
+        rm.apply();
+        assertTrue(Arrays.equals("k1".getBytes(), PerRowSecondaryIndexTest.TestIndex.LAST_INDEXED_KEY.array()));
+
+        Keyspace.open("PerRowSecondaryIndex").getColumnFamilyStore("Indexed1").forceBlockingFlush();
+
+        PerRowSecondaryIndexTest.TestIndex.reset();
+
+        ColumnFamilyStore.rebuildSecondaryIndex("PerRowSecondaryIndex", "Indexed1", PerRowSecondaryIndexTest.TestIndex.class.getSimpleName());
+        assertTrue(Arrays.equals("k1".getBytes(), PerRowSecondaryIndexTest.TestIndex.LAST_INDEXED_KEY.array()));
+
+        PerRowSecondaryIndexTest.TestIndex.reset();
+
+        PerRowSecondaryIndexTest.TestIndex.ACTIVE = false;
+        ColumnFamilyStore.rebuildSecondaryIndex("PerRowSecondaryIndex", "Indexed1", PerRowSecondaryIndexTest.TestIndex.class.getSimpleName());
+        assertNull(PerRowSecondaryIndexTest.TestIndex.LAST_INDEXED_KEY);
+
+        PerRowSecondaryIndexTest.TestIndex.reset();
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b325316f/test/unit/org/apache/cassandra/db/index/PerRowSecondaryIndexTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/index/PerRowSecondaryIndexTest.java b/test/unit/org/apache/cassandra/db/index/PerRowSecondaryIndexTest.java
index b983e6e..6a6956c 100644
--- a/test/unit/org/apache/cassandra/db/index/PerRowSecondaryIndexTest.java
+++ b/test/unit/org/apache/cassandra/db/index/PerRowSecondaryIndexTest.java
@@ -115,16 +115,24 @@ public class PerRowSecondaryIndexTest extends SchemaLoader
 
     public static class TestIndex extends PerRowSecondaryIndex
     {
+        public static volatile boolean ACTIVE = true;
         public static ColumnFamily LAST_INDEXED_ROW;
         public static ByteBuffer LAST_INDEXED_KEY;
 
         public static void reset()
         {
+            ACTIVE = true;
             LAST_INDEXED_KEY = null;
             LAST_INDEXED_ROW = null;
         }
 
         @Override
+        public boolean indexes(ByteBuffer name)
+        {
+            return ACTIVE;
+        }
+
+        @Override
         public void index(ByteBuffer rowKey, ColumnFamily cf)
         {
             QueryFilter filter = QueryFilter.getIdentityFilter(DatabaseDescriptor.getPartitioner().decorateKey(rowKey),
@@ -157,7 +165,7 @@ public class PerRowSecondaryIndexTest extends SchemaLoader
         @Override
         public String getIndexName()
         {
-            return null;
+            return this.getClass().getSimpleName();
         }
 
         @Override


Mime
View raw message