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:58 UTC

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

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;