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/05/19 13:10:55 UTC

[1/9] cassandra git commit: Improve javadoc around trigger execution

Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.0 0b92967d3 -> 37d81b9dc
  refs/heads/cassandra-2.1 59b8e171e -> 116de2bee
  refs/heads/cassandra-2.2 816c2b3f7 -> 86c9c00e9
  refs/heads/trunk c844bfeea -> 3a6e9c91b


Improve javadoc around trigger execution

Patch by Sam Tunnicliffe; reviewed by brandonwilliams for CASSANDRA-9334


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

Branch: refs/heads/cassandra-2.0
Commit: 37d81b9dcb08dd8c16a560591f46481b5d316841
Parents: 0b92967
Author: Sam Tunnicliffe <sa...@beobal.com>
Authored: Tue May 12 11:49:03 2015 +0100
Committer: Sam Tunnicliffe <sa...@beobal.com>
Committed: Tue May 19 09:39:56 2015 +0100

----------------------------------------------------------------------
 .../org/apache/cassandra/triggers/ITrigger.java |  4 +--
 .../cassandra/triggers/TriggerExecutor.java     | 32 ++++++++++++++++++++
 2 files changed, 34 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/37d81b9d/src/java/org/apache/cassandra/triggers/ITrigger.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/triggers/ITrigger.java b/src/java/org/apache/cassandra/triggers/ITrigger.java
index 15ed7ba..fe2a9e6 100644
--- a/src/java/org/apache/cassandra/triggers/ITrigger.java
+++ b/src/java/org/apache/cassandra/triggers/ITrigger.java
@@ -36,7 +36,7 @@ import org.apache.cassandra.db.RowMutation;
  * 2) ITrigger implementation can be instantiated multiple times during the server life time.
  *      (Depends on the number of times trigger folder is updated.)<br>
  * 3) ITrigger implementation should be state-less (avoid dependency on instance variables).<br>
- * 
+ *
  * <br><b>The API is still beta and can change.</b>
  */
 public interface ITrigger
@@ -46,7 +46,7 @@ public interface ITrigger
      *
      * @param key - Row Key for the update.
      * @param update - Update received for the CF
-     * @return modifications to be applied, null if no action to be performed.
+     * @return additional modifications to be applied along with the supplied update
      */
     public Collection<RowMutation> augment(ByteBuffer key, ColumnFamily update);
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/37d81b9d/src/java/org/apache/cassandra/triggers/TriggerExecutor.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/triggers/TriggerExecutor.java b/src/java/org/apache/cassandra/triggers/TriggerExecutor.java
index 988c6a7..bae0da6 100644
--- a/src/java/org/apache/cassandra/triggers/TriggerExecutor.java
+++ b/src/java/org/apache/cassandra/triggers/TriggerExecutor.java
@@ -64,6 +64,23 @@ public class TriggerExecutor
         cachedTriggers.clear();
     }
 
+    /**
+     * Augment a partition update by executing triggers to generate an intermediate
+     * set of mutations, then merging the ColumnFamily from each mutation with those
+     * supplied. This is called from @{link org.apache.cassandra.service.StorageProxy#cas}
+     * which is scoped for a single partition. For that reason, any mutations generated
+     * by triggers are checked to ensure that they are for the same table and partition
+     * key as the primary update; if not, InvalidRequestException is thrown. If no
+     * additional mutations are generated, the original updates are returned unmodified.
+     *
+     * @param key partition key for the update
+     * @param updates partition update to be applied, contains the merge of the original
+     *                update and any generated mutations
+     * @return the final update to be applied, the original update merged with any
+     * additional  mutations generated by configured triggers
+     * @throws InvalidRequestException if any mutation generated by a trigger does not
+     * apply to the exact same partition as the initial update
+     */
     public ColumnFamily execute(ByteBuffer key, ColumnFamily updates) throws InvalidRequestException
     {
         List<RowMutation> intermediate = executeInternal(key, updates);
@@ -79,6 +96,21 @@ public class TriggerExecutor
         return updates;
     }
 
+    /**
+     * Takes a collection of mutations and possibly augments it by adding extra mutations
+     * generated by configured triggers. If no additional mutations are created
+     * this returns null, signalling to the caller that only the initial set of
+     * mutations should be applied. If additional mutations <i>are</i> generated,
+     * the total set (i.e. the original plus the additional mutations) are applied
+     * together in a logged batch. Should this not be possible because the initial
+     * mutations contain counter updates, InvalidRequestException is thrown.
+     *
+     * @param mutations initial collection of mutations
+     * @return augmented mutations. Either the union of the initial and additional
+     * mutations or null if no additional mutations were generated
+     * @throws InvalidRequestException if additional mutations were generated, but
+     * the initial mutations contains counter updates
+     */
     public Collection<RowMutation> execute(Collection<? extends IMutation> mutations) throws InvalidRequestException
     {
         boolean hasCounters = false;


[2/9] cassandra git commit: Improve javadoc around trigger execution

Posted by sa...@apache.org.
Improve javadoc around trigger execution

Patch by Sam Tunnicliffe; reviewed by brandonwilliams for CASSANDRA-9334


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

Branch: refs/heads/cassandra-2.1
Commit: 116de2bee5920bc6842300a3f686d88f443b281d
Parents: 59b8e17
Author: Sam Tunnicliffe <sa...@beobal.com>
Authored: Tue May 12 11:49:03 2015 +0100
Committer: Sam Tunnicliffe <sa...@beobal.com>
Committed: Tue May 19 11:59:44 2015 +0100

----------------------------------------------------------------------
 .../org/apache/cassandra/triggers/ITrigger.java |  4 +--
 .../cassandra/triggers/TriggerExecutor.java     | 32 ++++++++++++++++++++
 2 files changed, 34 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/116de2be/src/java/org/apache/cassandra/triggers/ITrigger.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/triggers/ITrigger.java b/src/java/org/apache/cassandra/triggers/ITrigger.java
index 4701b61..21aba05 100644
--- a/src/java/org/apache/cassandra/triggers/ITrigger.java
+++ b/src/java/org/apache/cassandra/triggers/ITrigger.java
@@ -36,7 +36,7 @@ import org.apache.cassandra.db.Mutation;
  * 2) ITrigger implementation can be instantiated multiple times during the server life time.
  *      (Depends on the number of times trigger folder is updated.)<br>
  * 3) ITrigger implementation should be state-less (avoid dependency on instance variables).<br>
- * 
+ *
  * <br><b>The API is still beta and can change.</b>
  */
 public interface ITrigger
@@ -46,7 +46,7 @@ public interface ITrigger
      *
      * @param partitionKey - partition Key for the update.
      * @param update - update received for the CF
-     * @return modifications to be applied, null if no action to be performed.
+     * @return additional modifications to be applied along with the supplied update
      */
     public Collection<Mutation> augment(ByteBuffer partitionKey, ColumnFamily update);
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/116de2be/src/java/org/apache/cassandra/triggers/TriggerExecutor.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/triggers/TriggerExecutor.java b/src/java/org/apache/cassandra/triggers/TriggerExecutor.java
index 677daad..bc6f46c 100644
--- a/src/java/org/apache/cassandra/triggers/TriggerExecutor.java
+++ b/src/java/org/apache/cassandra/triggers/TriggerExecutor.java
@@ -60,6 +60,23 @@ public class TriggerExecutor
         cachedTriggers.clear();
     }
 
+    /**
+     * Augment a partition update by executing triggers to generate an intermediate
+     * set of mutations, then merging the ColumnFamily from each mutation with those
+     * supplied. This is called from @{link org.apache.cassandra.service.StorageProxy#cas}
+     * which is scoped for a single partition. For that reason, any mutations generated
+     * by triggers are checked to ensure that they are for the same table and partition
+     * key as the primary update; if not, InvalidRequestException is thrown. If no
+     * additional mutations are generated, the original updates are returned unmodified.
+     *
+     * @param key partition key for the update
+     * @param updates partition update to be applied, contains the merge of the original
+     *                update and any generated mutations
+     * @return the final update to be applied, the original update merged with any
+     * additional  mutations generated by configured triggers
+     * @throws InvalidRequestException if any mutation generated by a trigger does not
+     * apply to the exact same partition as the initial update
+     */
     public ColumnFamily execute(ByteBuffer key, ColumnFamily updates) throws InvalidRequestException
     {
         List<Mutation> intermediate = executeInternal(key, updates);
@@ -78,6 +95,21 @@ public class TriggerExecutor
         return updates;
     }
 
+    /**
+     * Takes a collection of mutations and possibly augments it by adding extra mutations
+     * generated by configured triggers. If no additional mutations are created
+     * this returns null, signalling to the caller that only the initial set of
+     * mutations should be applied. If additional mutations <i>are</i> generated,
+     * the total set (i.e. the original plus the additional mutations) are applied
+     * together in a logged batch. Should this not be possible because the initial
+     * mutations contain counter updates, InvalidRequestException is thrown.
+     *
+     * @param mutations initial collection of mutations
+     * @return augmented mutations. Either the union of the initial and additional
+     * mutations or null if no additional mutations were generated
+     * @throws InvalidRequestException if additional mutations were generated, but
+     * the initial mutations contains counter updates
+     */
     public Collection<Mutation> execute(Collection<? extends IMutation> mutations) throws InvalidRequestException
     {
         boolean hasCounters = false;


[7/9] cassandra git commit: Add test for triggers which throw IRE

Posted by sa...@apache.org.
Add test for triggers which throw IRE

Patch by Sam Tunnicliffe; reviewed by brandonwilliams for CASSANDRA-9334


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

Branch: refs/heads/cassandra-2.2
Commit: 86c9c00e98a1867deff3b8acc883d224b532197b
Parents: e2723a4
Author: Sam Tunnicliffe <sa...@beobal.com>
Authored: Tue May 12 16:26:24 2015 +0100
Committer: Sam Tunnicliffe <sa...@beobal.com>
Committed: Tue May 19 12:02:40 2015 +0100

----------------------------------------------------------------------
 .../apache/cassandra/triggers/TriggersTest.java | 49 +++++++++++++++-----
 1 file changed, 38 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/86c9c00e/test/unit/org/apache/cassandra/triggers/TriggersTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/triggers/TriggersTest.java b/test/unit/org/apache/cassandra/triggers/TriggersTest.java
index 41d4bb8..b0a5aca 100644
--- a/test/unit/org/apache/cassandra/triggers/TriggersTest.java
+++ b/test/unit/org/apache/cassandra/triggers/TriggersTest.java
@@ -22,18 +22,13 @@ import java.nio.ByteBuffer;
 import java.util.Collection;
 import java.util.Collections;
 
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.*;
 
 import org.apache.cassandra.SchemaLoader;
 import org.apache.cassandra.config.Schema;
 import org.apache.cassandra.cql3.QueryProcessor;
 import org.apache.cassandra.cql3.UntypedResultSet;
-import org.apache.cassandra.db.ArrayBackedSortedColumns;
-import org.apache.cassandra.db.BufferCell;
-import org.apache.cassandra.db.ColumnFamily;
+import org.apache.cassandra.db.*;
 import org.apache.cassandra.db.ConsistencyLevel;
 import org.apache.cassandra.db.Mutation;
 import org.apache.cassandra.exceptions.ConfigurationException;
@@ -42,11 +37,10 @@ import org.apache.cassandra.service.StorageService;
 import org.apache.cassandra.thrift.*;
 import org.apache.thrift.protocol.TBinaryProtocol;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
 import static org.apache.cassandra.utils.ByteBufferUtil.bytes;
 import static org.apache.cassandra.utils.ByteBufferUtil.toInt;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 public class TriggersTest
 {
@@ -61,12 +55,12 @@ public class TriggersTest
     public static void beforeTest() throws ConfigurationException
     {
         SchemaLoader.loadSchema();
+        StorageService.instance.initServer(0);
     }
 
     @Before
     public void setup() throws Exception
     {
-        StorageService.instance.initServer(0);
         if (thriftServer == null || ! thriftServer.isRunning())
         {
             thriftServer = new ThriftServer(InetAddress.getLocalHost(), 9170, 50);
@@ -283,6 +277,29 @@ public class TriggersTest
         }
     }
 
+    @Test(expected=RuntimeException.class)
+    public void ifTriggerThrowsErrorNoMutationsAreApplied() throws Exception
+    {
+        String cf = "cf" + System.nanoTime();
+        try
+        {
+            setupTableWithTrigger(cf, ErrorTrigger.class);
+            String cql = String.format("INSERT INTO %s.%s (k, v1) VALUES (11, 11)", ksName, cf);
+            QueryProcessor.process(cql, ConsistencyLevel.ONE);
+        }
+        catch (Exception e)
+        {
+            Throwable cause = e.getCause();
+            assertTrue((cause instanceof org.apache.cassandra.exceptions.InvalidRequestException));
+            assertTrue(cause.getMessage().equals(ErrorTrigger.MESSAGE));
+            throw e;
+        }
+        finally
+        {
+            assertUpdateNotExecuted(cf, 11);
+        }
+    }
+
     private void setupTableWithTrigger(String cf, Class<? extends ITrigger> triggerImpl)
     throws RequestExecutionException
     {
@@ -350,4 +367,14 @@ public class TriggersTest
             return Collections.singletonList(new Mutation(ksName, key, extraUpdate));
         }
     }
+
+    public static class ErrorTrigger implements ITrigger
+    {
+        public static final String MESSAGE = "Thrown by ErrorTrigger";
+        public Collection<Mutation> augment(ByteBuffer partitionKey, ColumnFamily update)
+        {
+            throw new org.apache.cassandra.exceptions.InvalidRequestException(MESSAGE);
+        }
+    }
+
 }


[8/9] cassandra git commit: Add test for triggers which throw IRE

Posted by sa...@apache.org.
Add test for triggers which throw IRE

Patch by Sam Tunnicliffe; reviewed by brandonwilliams for CASSANDRA-9334


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

Branch: refs/heads/trunk
Commit: 86c9c00e98a1867deff3b8acc883d224b532197b
Parents: e2723a4
Author: Sam Tunnicliffe <sa...@beobal.com>
Authored: Tue May 12 16:26:24 2015 +0100
Committer: Sam Tunnicliffe <sa...@beobal.com>
Committed: Tue May 19 12:02:40 2015 +0100

----------------------------------------------------------------------
 .../apache/cassandra/triggers/TriggersTest.java | 49 +++++++++++++++-----
 1 file changed, 38 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/86c9c00e/test/unit/org/apache/cassandra/triggers/TriggersTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/triggers/TriggersTest.java b/test/unit/org/apache/cassandra/triggers/TriggersTest.java
index 41d4bb8..b0a5aca 100644
--- a/test/unit/org/apache/cassandra/triggers/TriggersTest.java
+++ b/test/unit/org/apache/cassandra/triggers/TriggersTest.java
@@ -22,18 +22,13 @@ import java.nio.ByteBuffer;
 import java.util.Collection;
 import java.util.Collections;
 
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.*;
 
 import org.apache.cassandra.SchemaLoader;
 import org.apache.cassandra.config.Schema;
 import org.apache.cassandra.cql3.QueryProcessor;
 import org.apache.cassandra.cql3.UntypedResultSet;
-import org.apache.cassandra.db.ArrayBackedSortedColumns;
-import org.apache.cassandra.db.BufferCell;
-import org.apache.cassandra.db.ColumnFamily;
+import org.apache.cassandra.db.*;
 import org.apache.cassandra.db.ConsistencyLevel;
 import org.apache.cassandra.db.Mutation;
 import org.apache.cassandra.exceptions.ConfigurationException;
@@ -42,11 +37,10 @@ import org.apache.cassandra.service.StorageService;
 import org.apache.cassandra.thrift.*;
 import org.apache.thrift.protocol.TBinaryProtocol;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
 import static org.apache.cassandra.utils.ByteBufferUtil.bytes;
 import static org.apache.cassandra.utils.ByteBufferUtil.toInt;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 public class TriggersTest
 {
@@ -61,12 +55,12 @@ public class TriggersTest
     public static void beforeTest() throws ConfigurationException
     {
         SchemaLoader.loadSchema();
+        StorageService.instance.initServer(0);
     }
 
     @Before
     public void setup() throws Exception
     {
-        StorageService.instance.initServer(0);
         if (thriftServer == null || ! thriftServer.isRunning())
         {
             thriftServer = new ThriftServer(InetAddress.getLocalHost(), 9170, 50);
@@ -283,6 +277,29 @@ public class TriggersTest
         }
     }
 
+    @Test(expected=RuntimeException.class)
+    public void ifTriggerThrowsErrorNoMutationsAreApplied() throws Exception
+    {
+        String cf = "cf" + System.nanoTime();
+        try
+        {
+            setupTableWithTrigger(cf, ErrorTrigger.class);
+            String cql = String.format("INSERT INTO %s.%s (k, v1) VALUES (11, 11)", ksName, cf);
+            QueryProcessor.process(cql, ConsistencyLevel.ONE);
+        }
+        catch (Exception e)
+        {
+            Throwable cause = e.getCause();
+            assertTrue((cause instanceof org.apache.cassandra.exceptions.InvalidRequestException));
+            assertTrue(cause.getMessage().equals(ErrorTrigger.MESSAGE));
+            throw e;
+        }
+        finally
+        {
+            assertUpdateNotExecuted(cf, 11);
+        }
+    }
+
     private void setupTableWithTrigger(String cf, Class<? extends ITrigger> triggerImpl)
     throws RequestExecutionException
     {
@@ -350,4 +367,14 @@ public class TriggersTest
             return Collections.singletonList(new Mutation(ksName, key, extraUpdate));
         }
     }
+
+    public static class ErrorTrigger implements ITrigger
+    {
+        public static final String MESSAGE = "Thrown by ErrorTrigger";
+        public Collection<Mutation> augment(ByteBuffer partitionKey, ColumnFamily update)
+        {
+            throw new org.apache.cassandra.exceptions.InvalidRequestException(MESSAGE);
+        }
+    }
+
 }


[5/9] cassandra git commit: Merge branch 'cassandra-2.1' into cassandra-2.2

Posted by sa...@apache.org.
Merge branch 'cassandra-2.1' into cassandra-2.2


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

Branch: refs/heads/cassandra-2.2
Commit: e2723a400d1fec823d853374d3a64c6d061c55a5
Parents: 816c2b3 116de2b
Author: Sam Tunnicliffe <sa...@beobal.com>
Authored: Tue May 19 12:02:33 2015 +0100
Committer: Sam Tunnicliffe <sa...@beobal.com>
Committed: Tue May 19 12:02:33 2015 +0100

----------------------------------------------------------------------
 .../org/apache/cassandra/triggers/ITrigger.java |  4 +--
 .../cassandra/triggers/TriggerExecutor.java     | 32 ++++++++++++++++++++
 2 files changed, 34 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/e2723a40/src/java/org/apache/cassandra/triggers/TriggerExecutor.java
----------------------------------------------------------------------


[4/9] cassandra git commit: Improve javadoc around trigger execution

Posted by sa...@apache.org.
Improve javadoc around trigger execution

Patch by Sam Tunnicliffe; reviewed by brandonwilliams for CASSANDRA-9334


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

Branch: refs/heads/trunk
Commit: 116de2bee5920bc6842300a3f686d88f443b281d
Parents: 59b8e17
Author: Sam Tunnicliffe <sa...@beobal.com>
Authored: Tue May 12 11:49:03 2015 +0100
Committer: Sam Tunnicliffe <sa...@beobal.com>
Committed: Tue May 19 11:59:44 2015 +0100

----------------------------------------------------------------------
 .../org/apache/cassandra/triggers/ITrigger.java |  4 +--
 .../cassandra/triggers/TriggerExecutor.java     | 32 ++++++++++++++++++++
 2 files changed, 34 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/116de2be/src/java/org/apache/cassandra/triggers/ITrigger.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/triggers/ITrigger.java b/src/java/org/apache/cassandra/triggers/ITrigger.java
index 4701b61..21aba05 100644
--- a/src/java/org/apache/cassandra/triggers/ITrigger.java
+++ b/src/java/org/apache/cassandra/triggers/ITrigger.java
@@ -36,7 +36,7 @@ import org.apache.cassandra.db.Mutation;
  * 2) ITrigger implementation can be instantiated multiple times during the server life time.
  *      (Depends on the number of times trigger folder is updated.)<br>
  * 3) ITrigger implementation should be state-less (avoid dependency on instance variables).<br>
- * 
+ *
  * <br><b>The API is still beta and can change.</b>
  */
 public interface ITrigger
@@ -46,7 +46,7 @@ public interface ITrigger
      *
      * @param partitionKey - partition Key for the update.
      * @param update - update received for the CF
-     * @return modifications to be applied, null if no action to be performed.
+     * @return additional modifications to be applied along with the supplied update
      */
     public Collection<Mutation> augment(ByteBuffer partitionKey, ColumnFamily update);
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/116de2be/src/java/org/apache/cassandra/triggers/TriggerExecutor.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/triggers/TriggerExecutor.java b/src/java/org/apache/cassandra/triggers/TriggerExecutor.java
index 677daad..bc6f46c 100644
--- a/src/java/org/apache/cassandra/triggers/TriggerExecutor.java
+++ b/src/java/org/apache/cassandra/triggers/TriggerExecutor.java
@@ -60,6 +60,23 @@ public class TriggerExecutor
         cachedTriggers.clear();
     }
 
+    /**
+     * Augment a partition update by executing triggers to generate an intermediate
+     * set of mutations, then merging the ColumnFamily from each mutation with those
+     * supplied. This is called from @{link org.apache.cassandra.service.StorageProxy#cas}
+     * which is scoped for a single partition. For that reason, any mutations generated
+     * by triggers are checked to ensure that they are for the same table and partition
+     * key as the primary update; if not, InvalidRequestException is thrown. If no
+     * additional mutations are generated, the original updates are returned unmodified.
+     *
+     * @param key partition key for the update
+     * @param updates partition update to be applied, contains the merge of the original
+     *                update and any generated mutations
+     * @return the final update to be applied, the original update merged with any
+     * additional  mutations generated by configured triggers
+     * @throws InvalidRequestException if any mutation generated by a trigger does not
+     * apply to the exact same partition as the initial update
+     */
     public ColumnFamily execute(ByteBuffer key, ColumnFamily updates) throws InvalidRequestException
     {
         List<Mutation> intermediate = executeInternal(key, updates);
@@ -78,6 +95,21 @@ public class TriggerExecutor
         return updates;
     }
 
+    /**
+     * Takes a collection of mutations and possibly augments it by adding extra mutations
+     * generated by configured triggers. If no additional mutations are created
+     * this returns null, signalling to the caller that only the initial set of
+     * mutations should be applied. If additional mutations <i>are</i> generated,
+     * the total set (i.e. the original plus the additional mutations) are applied
+     * together in a logged batch. Should this not be possible because the initial
+     * mutations contain counter updates, InvalidRequestException is thrown.
+     *
+     * @param mutations initial collection of mutations
+     * @return augmented mutations. Either the union of the initial and additional
+     * mutations or null if no additional mutations were generated
+     * @throws InvalidRequestException if additional mutations were generated, but
+     * the initial mutations contains counter updates
+     */
     public Collection<Mutation> execute(Collection<? extends IMutation> mutations) throws InvalidRequestException
     {
         boolean hasCounters = false;


[6/9] cassandra git commit: Merge branch 'cassandra-2.1' into cassandra-2.2

Posted by sa...@apache.org.
Merge branch 'cassandra-2.1' into cassandra-2.2


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

Branch: refs/heads/trunk
Commit: e2723a400d1fec823d853374d3a64c6d061c55a5
Parents: 816c2b3 116de2b
Author: Sam Tunnicliffe <sa...@beobal.com>
Authored: Tue May 19 12:02:33 2015 +0100
Committer: Sam Tunnicliffe <sa...@beobal.com>
Committed: Tue May 19 12:02:33 2015 +0100

----------------------------------------------------------------------
 .../org/apache/cassandra/triggers/ITrigger.java |  4 +--
 .../cassandra/triggers/TriggerExecutor.java     | 32 ++++++++++++++++++++
 2 files changed, 34 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/e2723a40/src/java/org/apache/cassandra/triggers/TriggerExecutor.java
----------------------------------------------------------------------


[3/9] cassandra git commit: Improve javadoc around trigger execution

Posted by sa...@apache.org.
Improve javadoc around trigger execution

Patch by Sam Tunnicliffe; reviewed by brandonwilliams for CASSANDRA-9334


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

Branch: refs/heads/cassandra-2.2
Commit: 116de2bee5920bc6842300a3f686d88f443b281d
Parents: 59b8e17
Author: Sam Tunnicliffe <sa...@beobal.com>
Authored: Tue May 12 11:49:03 2015 +0100
Committer: Sam Tunnicliffe <sa...@beobal.com>
Committed: Tue May 19 11:59:44 2015 +0100

----------------------------------------------------------------------
 .../org/apache/cassandra/triggers/ITrigger.java |  4 +--
 .../cassandra/triggers/TriggerExecutor.java     | 32 ++++++++++++++++++++
 2 files changed, 34 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/116de2be/src/java/org/apache/cassandra/triggers/ITrigger.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/triggers/ITrigger.java b/src/java/org/apache/cassandra/triggers/ITrigger.java
index 4701b61..21aba05 100644
--- a/src/java/org/apache/cassandra/triggers/ITrigger.java
+++ b/src/java/org/apache/cassandra/triggers/ITrigger.java
@@ -36,7 +36,7 @@ import org.apache.cassandra.db.Mutation;
  * 2) ITrigger implementation can be instantiated multiple times during the server life time.
  *      (Depends on the number of times trigger folder is updated.)<br>
  * 3) ITrigger implementation should be state-less (avoid dependency on instance variables).<br>
- * 
+ *
  * <br><b>The API is still beta and can change.</b>
  */
 public interface ITrigger
@@ -46,7 +46,7 @@ public interface ITrigger
      *
      * @param partitionKey - partition Key for the update.
      * @param update - update received for the CF
-     * @return modifications to be applied, null if no action to be performed.
+     * @return additional modifications to be applied along with the supplied update
      */
     public Collection<Mutation> augment(ByteBuffer partitionKey, ColumnFamily update);
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/116de2be/src/java/org/apache/cassandra/triggers/TriggerExecutor.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/triggers/TriggerExecutor.java b/src/java/org/apache/cassandra/triggers/TriggerExecutor.java
index 677daad..bc6f46c 100644
--- a/src/java/org/apache/cassandra/triggers/TriggerExecutor.java
+++ b/src/java/org/apache/cassandra/triggers/TriggerExecutor.java
@@ -60,6 +60,23 @@ public class TriggerExecutor
         cachedTriggers.clear();
     }
 
+    /**
+     * Augment a partition update by executing triggers to generate an intermediate
+     * set of mutations, then merging the ColumnFamily from each mutation with those
+     * supplied. This is called from @{link org.apache.cassandra.service.StorageProxy#cas}
+     * which is scoped for a single partition. For that reason, any mutations generated
+     * by triggers are checked to ensure that they are for the same table and partition
+     * key as the primary update; if not, InvalidRequestException is thrown. If no
+     * additional mutations are generated, the original updates are returned unmodified.
+     *
+     * @param key partition key for the update
+     * @param updates partition update to be applied, contains the merge of the original
+     *                update and any generated mutations
+     * @return the final update to be applied, the original update merged with any
+     * additional  mutations generated by configured triggers
+     * @throws InvalidRequestException if any mutation generated by a trigger does not
+     * apply to the exact same partition as the initial update
+     */
     public ColumnFamily execute(ByteBuffer key, ColumnFamily updates) throws InvalidRequestException
     {
         List<Mutation> intermediate = executeInternal(key, updates);
@@ -78,6 +95,21 @@ public class TriggerExecutor
         return updates;
     }
 
+    /**
+     * Takes a collection of mutations and possibly augments it by adding extra mutations
+     * generated by configured triggers. If no additional mutations are created
+     * this returns null, signalling to the caller that only the initial set of
+     * mutations should be applied. If additional mutations <i>are</i> generated,
+     * the total set (i.e. the original plus the additional mutations) are applied
+     * together in a logged batch. Should this not be possible because the initial
+     * mutations contain counter updates, InvalidRequestException is thrown.
+     *
+     * @param mutations initial collection of mutations
+     * @return augmented mutations. Either the union of the initial and additional
+     * mutations or null if no additional mutations were generated
+     * @throws InvalidRequestException if additional mutations were generated, but
+     * the initial mutations contains counter updates
+     */
     public Collection<Mutation> execute(Collection<? extends IMutation> mutations) throws InvalidRequestException
     {
         boolean hasCounters = false;


[9/9] cassandra git commit: Merge branch 'cassandra-2.2' into trunk

Posted by sa...@apache.org.
Merge branch 'cassandra-2.2' into trunk


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

Branch: refs/heads/trunk
Commit: 3a6e9c91b83ad0dc9b2423b51975277c790af66d
Parents: c844bfe 86c9c00
Author: Sam Tunnicliffe <sa...@beobal.com>
Authored: Tue May 19 12:05:24 2015 +0100
Committer: Sam Tunnicliffe <sa...@beobal.com>
Committed: Tue May 19 12:05:24 2015 +0100

----------------------------------------------------------------------
 .../org/apache/cassandra/triggers/ITrigger.java |  4 +-
 .../cassandra/triggers/TriggerExecutor.java     | 32 +++++++++++++
 .../apache/cassandra/triggers/TriggersTest.java | 49 +++++++++++++++-----
 3 files changed, 72 insertions(+), 13 deletions(-)
----------------------------------------------------------------------