cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bened...@apache.org
Subject [2/6] cassandra git commit: Overload SecondaryIndex#indexes to accept the column definition
Date Thu, 07 May 2015 10:58:26 GMT
Overload SecondaryIndex#indexes to accept the column definition

patch by sam; reviewed by sergio for CASSANDRA-9314


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

Branch: refs/heads/cassandra-2.1
Commit: 6ab0c301edaf16544de7f839ffcd345dadef1cf6
Parents: afe541a
Author: Benedict Elliott Smith <benedict@apache.org>
Authored: Thu May 7 11:53:30 2015 +0100
Committer: Benedict Elliott Smith <benedict@apache.org>
Committed: Thu May 7 11:53:30 2015 +0100

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../cassandra/db/index/SecondaryIndex.java      | 12 ++++++++-
 .../db/index/SecondaryIndexManager.java         |  4 +--
 .../cassandra/db/ColumnFamilyStoreTest.java     | 27 +++++++++-----------
 .../db/index/PerRowSecondaryIndexTest.java      | 14 ++++++++++
 5 files changed, 40 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/6ab0c301/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 45c0238..d76606c 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 2.0.15:
+ * Overload SecondaryIndex#indexes to accept the column definition (CASSANDRA-9314)
  * (cqlsh) Add SERIAL and LOCAL_SERIAL consistency levels (CASSANDRA-8051)
  * Fix index selection during rebuild with certain table layouts (CASSANDRA-9281)
  * Fix partition-level-delete-only workload accounting (CASSANDRA-9194)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/6ab0c301/src/java/org/apache/cassandra/db/index/SecondaryIndex.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/index/SecondaryIndex.java b/src/java/org/apache/cassandra/db/index/SecondaryIndex.java
index a83f5dd..789cc29 100644
--- a/src/java/org/apache/cassandra/db/index/SecondaryIndex.java
+++ b/src/java/org/apache/cassandra/db/index/SecondaryIndex.java
@@ -292,7 +292,7 @@ public abstract class SecondaryIndex
     /**
      * Returns true if the provided column name is indexed by this secondary index.
      *
-     * The default implement checks whether the name is one the columnDef name,
+     * The default implementation checks whether the name is one the columnDef name,
      * but this should be overriden but subclass if needed.
      */
     public boolean indexes(ByteBuffer name)
@@ -304,6 +304,16 @@ public abstract class SecondaryIndex
         }
         return false;
     }
+    
+    /**
+     * Returns true if the provided column definition is indexed by this secondary index.
+     *
+     * The default implementation checks whether it is contained in this index column definitions
set.
+     */
+    public boolean indexes(ColumnDefinition cdef)
+    {
+        return columnDefs.contains(cdef);
+    }
 
     /**
      * This is the primary way to create a secondary index instance for a CF column.

http://git-wip-us.apache.org/repos/asf/cassandra/blob/6ab0c301/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 d5e88d0..b2f5196 100644
--- a/src/java/org/apache/cassandra/db/index/SecondaryIndexManager.java
+++ b/src/java/org/apache/cassandra/db/index/SecondaryIndexManager.java
@@ -133,7 +133,7 @@ public class SecondaryIndexManager
     {
         idxNames = filterByColumn(idxNames);
         if (idxNames.isEmpty())
-            return;
+            return;        
 
         logger.info(String.format("Submitting index build of %s for data in %s",
                                   idxNames, StringUtils.join(sstables, ", ")));
@@ -589,7 +589,7 @@ public class SecondaryIndexManager
         {
             for (ColumnDefinition column : baseCfs.metadata.allColumns())
             {
-                if (candidate.getColumnDefs().contains(column))
+                if (candidate.indexes(column))
                 {
                     filtered.add(candidate.getIndexName());
                     break;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/6ab0c301/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 001f838..2bcead8 100644
--- a/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java
+++ b/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java
@@ -62,6 +62,7 @@ import org.apache.cassandra.utils.WrappedRunnable;
 
 import static org.junit.Assert.*;
 import static org.apache.cassandra.Util.*;
+import org.apache.cassandra.db.index.PerRowSecondaryIndexTest;
 import static org.apache.cassandra.utils.ByteBufferUtil.bytes;
 import static org.apache.commons.lang3.ArrayUtils.EMPTY_BYTE_ARRAY;
 
@@ -2173,34 +2174,30 @@ public class ColumnFamilyStoreTest extends SchemaLoader
         });
         System.err.println("Row key: " + rowKey + " Cols: " + transformed);
     }
-
+    
     @Test
     public void testRebuildSecondaryIndex() throws IOException
     {
-        ByteBuffer indexedColumnName = ByteBufferUtil.bytes("indexed");
         RowMutation rm;
-
+        
         rm = new RowMutation("PerRowSecondaryIndex", ByteBufferUtil.bytes("k1"));
-        rm.add("Indexed1", indexedColumnName, ByteBufferUtil.bytes("foo"), 1);
+        rm.add("Indexed1", ByteBufferUtil.bytes("indexed"), ByteBufferUtil.bytes("foo"),
1);
         rm.apply();
         assertTrue(Arrays.equals("k1".getBytes(), PerRowSecondaryIndexTest.TestIndex.LAST_INDEXED_KEY.array()));
-
-        ColumnFamilyStore cfs = Keyspace.open("PerRowSecondaryIndex").getColumnFamilyStore("Indexed1");
-        cfs.forceBlockingFlush();
-
+        
+        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();
-
-        ColumnDefinition indexedColumnDef = cfs.metadata.getColumnDefinition(indexedColumnName);
-        cfs.indexManager.getIndexForColumn(indexedColumnName).getColumnDefs().remove(indexedColumnDef);
-
+        
+        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/6ab0c301/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 81173b2..1a4b7d4 100644
--- a/test/unit/org/apache/cassandra/db/index/PerRowSecondaryIndexTest.java
+++ b/test/unit/org/apache/cassandra/db/index/PerRowSecondaryIndexTest.java
@@ -116,16 +116,30 @@ 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 boolean indexes(ColumnDefinition cdef)
+        {
+            return ACTIVE;
+        }
+        
+        @Override
         public void index(ByteBuffer rowKey, ColumnFamily cf)
         {
             QueryFilter filter = QueryFilter.getIdentityFilter(DatabaseDescriptor.getPartitioner().decorateKey(rowKey),


Mime
View raw message