cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alek...@apache.org
Subject [1/3] git commit: Pass the updated cf to the PRSI index() method
Date Tue, 10 Sep 2013 21:58:33 GMT
Updated Branches:
  refs/heads/trunk 7246502e7 -> 0132b71a0


Pass the updated cf to the PRSI index() method

patch by Ben Coverston; reviewed by Aleksey Yeschenko for
CASSANDRA-5999


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

Branch: refs/heads/trunk
Commit: fd129664ca482181d2c794a68bbd5a5bcc2b01be
Parents: 70297f9
Author: Aleksey Yeschenko <aleksey@apache.org>
Authored: Wed Sep 11 00:43:28 2013 +0300
Committer: Aleksey Yeschenko <aleksey@apache.org>
Committed: Wed Sep 11 00:43:28 2013 +0300

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 src/java/org/apache/cassandra/db/Table.java     |  2 +-
 .../db/index/PerRowSecondaryIndex.java          | 13 +++------
 .../db/index/SecondaryIndexManager.java         | 28 ++++++++++++++------
 .../db/SecondaryIndexColumnSizeTest.java        |  4 +--
 .../db/index/PerRowSecondaryIndexTest.java      | 21 ++++++---------
 6 files changed, 36 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/fd129664/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 4d5b446..12e2017 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -10,6 +10,7 @@
  * Fix loading index summary containing empty key (CASSANDRA-5965)
  * Correctly handle limits in CompositesSearcher (CASSANDRA-5975)
  * Pig: handle CQL collections (CASSANDRA-5867)
+ * Pass the updated cf to the PRSI index() method (CASSANDRA-5999)
 
 
 1.2.9

http://git-wip-us.apache.org/repos/asf/cassandra/blob/fd129664/src/java/org/apache/cassandra/db/Table.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/Table.java b/src/java/org/apache/cassandra/db/Table.java
index 99a3446..a851eee 100644
--- a/src/java/org/apache/cassandra/db/Table.java
+++ b/src/java/org/apache/cassandra/db/Table.java
@@ -385,7 +385,7 @@ public class Table
                 }
 
                 Tracing.trace("Adding to {} memtable", cf.metadata().cfName);
-                cfs.apply(key, cf, updateIndexes ? cfs.indexManager.updaterFor(key) : SecondaryIndexManager.nullUpdater);
+                cfs.apply(key, cf, updateIndexes ? cfs.indexManager.updaterFor(key, cf) :
SecondaryIndexManager.nullUpdater);
             }
         }
         finally

http://git-wip-us.apache.org/repos/asf/cassandra/blob/fd129664/src/java/org/apache/cassandra/db/index/PerRowSecondaryIndex.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/index/PerRowSecondaryIndex.java b/src/java/org/apache/cassandra/db/index/PerRowSecondaryIndex.java
index 0200667..1818473 100644
--- a/src/java/org/apache/cassandra/db/index/PerRowSecondaryIndex.java
+++ b/src/java/org/apache/cassandra/db/index/PerRowSecondaryIndex.java
@@ -19,9 +19,11 @@ package org.apache.cassandra.db.index;
 
 import java.nio.ByteBuffer;
 import java.nio.charset.CharacterCodingException;
+import java.util.SortedSet;
 
 import org.apache.cassandra.db.ColumnFamily;
 import org.apache.cassandra.db.DecoratedKey;
+import org.apache.cassandra.db.marshal.AbstractType;
 import org.apache.cassandra.thrift.Column;
 import org.apache.cassandra.utils.ByteBufferUtil;
 
@@ -31,21 +33,14 @@ import org.apache.cassandra.utils.ByteBufferUtil;
 public abstract class PerRowSecondaryIndex extends SecondaryIndex
 {
     /**
-     * Index the given row for new index creation.  @param cf will represent the entire row.
+     * Index the given row.
      *
      * @param rowKey the row key
-     * @param cf the current rows data
+     * @param cf the cf data to be indexed
      */
     public abstract void index(ByteBuffer rowKey, ColumnFamily cf);
 
     /**
-     * Index the given row
-     *
-     * @param rowKey the row key
-     */
-    public abstract void index(ByteBuffer rowKey);
-
-    /**
      * cleans up deleted columns from cassandra cleanup compaction
      *
      * @param key

http://git-wip-us.apache.org/repos/asf/cassandra/blob/fd129664/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 2f03515..52d2152 100644
--- a/src/java/org/apache/cassandra/db/index/SecondaryIndexManager.java
+++ b/src/java/org/apache/cassandra/db/index/SecondaryIndexManager.java
@@ -29,6 +29,7 @@ import org.apache.cassandra.config.ColumnDefinition;
 import org.apache.cassandra.db.*;
 import org.apache.cassandra.db.compaction.CompactionManager;
 import org.apache.cassandra.db.filter.IDiskAtomFilter;
+import org.apache.cassandra.db.marshal.AbstractType;
 import org.apache.cassandra.dht.AbstractBounds;
 import org.apache.cassandra.exceptions.ConfigurationException;
 import org.apache.cassandra.io.sstable.ReducingKeyIterator;
@@ -476,15 +477,24 @@ public class SecondaryIndexManager
 
     /**
      * This helper acts as a closure around the indexManager
-     * and row key to ensure that down in Memtable's ColumnFamily implementation, the index
-     * can get updated. Note: only a CF backed by AtomicSortedColumns implements this behaviour
-     * fully, other types simply ignore the index updater.
+     * and updated cf data to ensure that down in
+     * Memtable's ColumnFamily implementation, the index
+     * can get updated. Note: only a CF backed by AtomicSortedColumns implements
+     * this behaviour fully, other types simply ignore the index updater.
      */
-    public Updater updaterFor(final DecoratedKey key)
+    public Updater updaterFor(DecoratedKey key, ColumnFamily cf)
     {
         return (indexesByColumn.isEmpty() && rowLevelIndexMap.isEmpty())
                 ? nullUpdater
-                : new StandardUpdater(key);
+                : new StandardUpdater(key, cf);
+    }
+
+    /**
+     * Updated closure with only the modified row key.
+     */
+    public Updater updaterFor(DecoratedKey key)
+    {
+        return updaterFor(key, null);
     }
 
     /**
@@ -574,7 +584,7 @@ public class SecondaryIndexManager
     public boolean validate(Column column)
     {
         SecondaryIndex index = getIndexForColumn(column.name);
-        return index != null ? index.validate(column) : true;
+        return index == null || index.validate(column);
     }
 
     public static interface Updater
@@ -595,10 +605,12 @@ public class SecondaryIndexManager
     private class StandardUpdater implements Updater
     {
         private final DecoratedKey key;
+        private final ColumnFamily cf;
 
-        public StandardUpdater(DecoratedKey key)
+        public StandardUpdater(DecoratedKey key, ColumnFamily cf)
         {
             this.key = key;
+            this.cf = cf;
         }
 
         public void insert(IColumn column)
@@ -649,7 +661,7 @@ public class SecondaryIndexManager
         public void updateRowLevelIndexes()
         {
             for (SecondaryIndex index : rowLevelIndexMap.values())
-                ((PerRowSecondaryIndex) index).index(key.key);
+                ((PerRowSecondaryIndex) index).index(key.key, cf);
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/fd129664/test/unit/org/apache/cassandra/db/SecondaryIndexColumnSizeTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/SecondaryIndexColumnSizeTest.java b/test/unit/org/apache/cassandra/db/SecondaryIndexColumnSizeTest.java
index 6cca2ab..3281a5a 100644
--- a/test/unit/org/apache/cassandra/db/SecondaryIndexColumnSizeTest.java
+++ b/test/unit/org/apache/cassandra/db/SecondaryIndexColumnSizeTest.java
@@ -53,8 +53,8 @@ public class SecondaryIndexColumnSizeTest
         buffer.flip();
         column.value = buffer;
 
-        MockRowIndex mockRowIndex = new MockRowIndex();
-        MockColumnIndex mockColumnIndex = new MockColumnIndex();
+        SecondaryIndexColumnSizeTest.MockRowIndex mockRowIndex = new SecondaryIndexColumnSizeTest.MockRowIndex();
+        SecondaryIndexColumnSizeTest.MockColumnIndex mockColumnIndex = new SecondaryIndexColumnSizeTest.MockColumnIndex();
 
         assertTrue(mockRowIndex.validate(column));
         assertFalse(mockColumnIndex.validate(column));

http://git-wip-us.apache.org/repos/asf/cassandra/blob/fd129664/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 3080912..c720d21 100644
--- a/test/unit/org/apache/cassandra/db/index/PerRowSecondaryIndexTest.java
+++ b/test/unit/org/apache/cassandra/db/index/PerRowSecondaryIndexTest.java
@@ -50,7 +50,7 @@ public class PerRowSecondaryIndexTest extends SchemaLoader
     @Before
     public void clearTestStub()
     {
-        TestIndex.reset();
+        PerRowSecondaryIndexTest.TestIndex.reset();
     }
 
     @Test
@@ -62,7 +62,7 @@ public class PerRowSecondaryIndexTest extends SchemaLoader
         rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("indexed")), ByteBufferUtil.bytes("foo"),
1);
         rm.apply();
 
-        ColumnFamily indexedRow = TestIndex.LAST_INDEXED_ROW;
+        ColumnFamily indexedRow = PerRowSecondaryIndexTest.TestIndex.LAST_INDEXED_ROW;
         assertNotNull(indexedRow);
         assertEquals(ByteBufferUtil.bytes("foo"), indexedRow.getColumn(ByteBufferUtil.bytes("indexed")).value());
 
@@ -71,10 +71,10 @@ public class PerRowSecondaryIndexTest extends SchemaLoader
         rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("indexed")), ByteBufferUtil.bytes("bar"),
2);
         rm.apply();
 
-        indexedRow = TestIndex.LAST_INDEXED_ROW;
+        indexedRow = PerRowSecondaryIndexTest.TestIndex.LAST_INDEXED_ROW;
         assertNotNull(indexedRow);
         assertEquals(ByteBufferUtil.bytes("bar"), indexedRow.getColumn(ByteBufferUtil.bytes("indexed")).value());
-        assertTrue(Arrays.equals("k1".getBytes(), TestIndex.LAST_INDEXED_KEY.array()));
+        assertTrue(Arrays.equals("k1".getBytes(), PerRowSecondaryIndexTest.TestIndex.LAST_INDEXED_KEY.array()));
     }
 
     @Test
@@ -86,14 +86,14 @@ public class PerRowSecondaryIndexTest extends SchemaLoader
         rm.delete(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("indexed")), 1);
         rm.apply();
 
-        ColumnFamily indexedRow = TestIndex.LAST_INDEXED_ROW;
+        ColumnFamily indexedRow = PerRowSecondaryIndexTest.TestIndex.LAST_INDEXED_ROW;
         assertNotNull(indexedRow);
 
         for (IColumn column : indexedRow.getSortedColumns())
         {
             assertTrue(column.isMarkedForDelete());
         }
-        assertTrue(Arrays.equals("k2".getBytes(), TestIndex.LAST_INDEXED_KEY.array()));
+        assertTrue(Arrays.equals("k2".getBytes(), PerRowSecondaryIndexTest.TestIndex.LAST_INDEXED_KEY.array()));
     }
 
     @Test
@@ -105,13 +105,13 @@ public class PerRowSecondaryIndexTest extends SchemaLoader
         rm.delete(new QueryPath("Indexed1"), 1);
         rm.apply();
 
-        ColumnFamily indexedRow = TestIndex.LAST_INDEXED_ROW;
+        ColumnFamily indexedRow = PerRowSecondaryIndexTest.TestIndex.LAST_INDEXED_ROW;
         assertNotNull(indexedRow);
         for (IColumn column : indexedRow.getSortedColumns())
         {
             assertTrue(column.isMarkedForDelete());
         }
-        assertTrue(Arrays.equals("k3".getBytes(), TestIndex.LAST_INDEXED_KEY.array()));
+        assertTrue(Arrays.equals("k3".getBytes(), PerRowSecondaryIndexTest.TestIndex.LAST_INDEXED_KEY.array()));
     }
 
     public static class TestIndex extends PerRowSecondaryIndex
@@ -128,11 +128,6 @@ public class PerRowSecondaryIndexTest extends SchemaLoader
         @Override
         public void index(ByteBuffer rowKey, ColumnFamily cf)
         {
-        }
-
-        @Override
-        public void index(ByteBuffer rowKey)
-        {
             QueryFilter filter = QueryFilter.getIdentityFilter(DatabaseDescriptor.getPartitioner().decorateKey(rowKey),
                                                                new QueryPath(baseCfs.getColumnFamilyName()));
             LAST_INDEXED_ROW = baseCfs.getColumnFamily(filter);


Mime
View raw message