cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vi...@apache.org
Subject [1/3] patch by Vijay; reviewed by Aleksey Yeschenko for CASSANDRA-5576
Date Sun, 16 Jun 2013 22:58:35 GMT
Updated Branches:
  refs/heads/trunk ed4d45565 -> 8bf6e1559


http://git-wip-us.apache.org/repos/asf/cassandra/blob/8bf6e155/src/java/org/apache/cassandra/cql3/statements/CreateTriggerStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/CreateTriggerStatement.java b/src/java/org/apache/cassandra/cql3/statements/CreateTriggerStatement.java
new file mode 100644
index 0000000..4c6e78a
--- /dev/null
+++ b/src/java/org/apache/cassandra/cql3/statements/CreateTriggerStatement.java
@@ -0,0 +1,66 @@
+package org.apache.cassandra.cql3.statements;
+
+import org.apache.cassandra.auth.Permission;
+import org.apache.cassandra.config.CFMetaData;
+import org.apache.cassandra.config.Schema;
+import org.apache.cassandra.config.TriggerOptions;
+import org.apache.cassandra.cql3.CFName;
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.exceptions.ExceptionCode;
+import org.apache.cassandra.exceptions.InvalidRequestException;
+import org.apache.cassandra.exceptions.RequestValidationException;
+import org.apache.cassandra.exceptions.UnauthorizedException;
+import org.apache.cassandra.service.ClientState;
+import org.apache.cassandra.service.MigrationManager;
+import org.apache.cassandra.thrift.ThriftValidation;
+import org.apache.cassandra.transport.messages.ResultMessage;
+import org.apache.cassandra.triggers.TriggerExecutor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class CreateTriggerStatement extends SchemaAlteringStatement
+{
+    private static final Logger logger = LoggerFactory.getLogger(CreateTriggerStatement.class);
+
+    private final String triggerName;
+    private final String clazz;
+
+    public CreateTriggerStatement(CFName name, String triggerName, String clazz)
+    {
+        super(name);
+        this.triggerName = triggerName;
+        this.clazz = clazz;
+    }
+
+    public void checkAccess(ClientState state) throws UnauthorizedException, InvalidRequestException
+    {
+        state.hasColumnFamilyAccess(keyspace(), columnFamily(), Permission.ALTER);
+    }
+
+    @Override
+    public void validate(ClientState state) throws RequestValidationException
+    {
+        ThriftValidation.validateColumnFamily(keyspace(), columnFamily());
+        try
+        {
+            TriggerExecutor.instance.loadTriggerInstance(clazz);
+        }
+        catch (Exception ex)
+        {
+            throw new RequestValidationException(ExceptionCode.INVALID, "Trigger class: "
+ clazz + ", doesnt exist.", ex) {};
+        }
+    }
+
+    public void announceMigration() throws InvalidRequestException, ConfigurationException
+    {
+        CFMetaData cfm = Schema.instance.getCFMetaData(keyspace(), columnFamily()).clone();
+        TriggerOptions.update(cfm, triggerName, clazz);
+        logger.info("Adding triggers with name {} and classes {}", triggerName, clazz);
+        MigrationManager.announceColumnFamilyUpdate(cfm, false);
+    }
+
+    public ResultMessage.SchemaChange.Change changeType()
+    {
+        return ResultMessage.SchemaChange.Change.UPDATED;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cassandra/blob/8bf6e155/src/java/org/apache/cassandra/cql3/statements/DropTriggerStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/DropTriggerStatement.java b/src/java/org/apache/cassandra/cql3/statements/DropTriggerStatement.java
new file mode 100644
index 0000000..36da2f0
--- /dev/null
+++ b/src/java/org/apache/cassandra/cql3/statements/DropTriggerStatement.java
@@ -0,0 +1,59 @@
+package org.apache.cassandra.cql3.statements;
+
+import org.apache.cassandra.auth.Permission;
+import org.apache.cassandra.config.CFMetaData;
+import org.apache.cassandra.config.Schema;
+import org.apache.cassandra.config.TriggerOptions;
+import org.apache.cassandra.cql3.CFName;
+import org.apache.cassandra.exceptions.ConfigurationException;
+import org.apache.cassandra.exceptions.ExceptionCode;
+import org.apache.cassandra.exceptions.InvalidRequestException;
+import org.apache.cassandra.exceptions.RequestValidationException;
+import org.apache.cassandra.exceptions.UnauthorizedException;
+import org.apache.cassandra.service.ClientState;
+import org.apache.cassandra.service.MigrationManager;
+import org.apache.cassandra.thrift.ThriftValidation;
+import org.apache.cassandra.transport.messages.ResultMessage;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DropTriggerStatement extends SchemaAlteringStatement
+{
+    private static final Logger logger = LoggerFactory.getLogger(DropTriggerStatement.class);
+    private final String triggerName;
+
+    public DropTriggerStatement(CFName name, String triggerName)
+    {
+        super(name);
+        this.triggerName = triggerName;
+    }
+
+    public void checkAccess(ClientState state) throws UnauthorizedException, InvalidRequestException
+    {
+        state.hasColumnFamilyAccess(keyspace(), columnFamily(), Permission.ALTER);
+    }
+
+    @Override
+    public void validate(ClientState state) throws RequestValidationException
+    {
+        ThriftValidation.validateColumnFamily(keyspace(), columnFamily());
+        CFMetaData cfm = Schema.instance.getCFMetaData(keyspace(), columnFamily());
+        if (cfm.getTriggerClasses() == null)
+            throw new RequestValidationException(ExceptionCode.CONFIG_ERROR, "No triggers
found") {};
+        if (!TriggerOptions.hasTrigger(cfm, triggerName))
+            throw new RequestValidationException(ExceptionCode.CONFIG_ERROR, "trigger: "
+ triggerName + ", not found") {};
+    }
+
+    public void announceMigration() throws InvalidRequestException, ConfigurationException
+    {
+        CFMetaData cfm = Schema.instance.getCFMetaData(keyspace(), columnFamily()).clone();
+        TriggerOptions.remove(cfm, triggerName);
+        logger.info("Dropping trigger with name {}", triggerName);
+        MigrationManager.announceColumnFamilyUpdate(cfm, false);
+    }
+
+    public ResultMessage.SchemaChange.Change changeType()
+    {
+        return ResultMessage.SchemaChange.Change.UPDATED;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cassandra/blob/8bf6e155/src/java/org/apache/cassandra/db/SystemTable.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/SystemTable.java b/src/java/org/apache/cassandra/db/SystemTable.java
index 12c976d..e62b258 100644
--- a/src/java/org/apache/cassandra/db/SystemTable.java
+++ b/src/java/org/apache/cassandra/db/SystemTable.java
@@ -73,6 +73,7 @@ public class SystemTable
     public static final String SCHEMA_KEYSPACES_CF = "schema_keyspaces";
     public static final String SCHEMA_COLUMNFAMILIES_CF = "schema_columnfamilies";
     public static final String SCHEMA_COLUMNS_CF = "schema_columns";
+    public static final String SCHEMA_TRIGGERS_CF = "schema_triggers";
     public static final String COMPACTION_LOG = "compactions_in_progress";
     public static final String PAXOS_CF = "paxos";
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/8bf6e155/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 a49792f..6a77295 100644
--- a/src/java/org/apache/cassandra/triggers/TriggerExecutor.java
+++ b/src/java/org/apache/cassandra/triggers/TriggerExecutor.java
@@ -27,7 +27,6 @@ import java.nio.ByteBuffer;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 
 import org.apache.cassandra.cql.QueryProcessor;
 import org.apache.cassandra.db.ColumnFamily;
@@ -107,7 +106,7 @@ public class TriggerExecutor
      */
     private List<RowMutation> execute(ByteBuffer key, ColumnFamily columnFamily)
     {
-        Set<String> triggerNames = columnFamily.metadata().getTriggerClass();
+        Collection<String> triggerNames = columnFamily.metadata().getTriggerClasses();
         if (triggerNames == null)
             return null;
         List<RowMutation> tmutations = Lists.newLinkedList();
@@ -138,7 +137,7 @@ public class TriggerExecutor
         }
     }
 
-    private synchronized ITrigger loadTriggerInstance(String triggerName) throws Exception
+    public synchronized ITrigger loadTriggerInstance(String triggerName) throws Exception
     {
         // double check.
         if (cachedTriggers.get(triggerName) != null)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/8bf6e155/src/resources/org/apache/cassandra/cli/CliHelp.yaml
----------------------------------------------------------------------
diff --git a/src/resources/org/apache/cassandra/cli/CliHelp.yaml b/src/resources/org/apache/cassandra/cli/CliHelp.yaml
index d5ee151..3d4bd99 100644
--- a/src/resources/org/apache/cassandra/cli/CliHelp.yaml
+++ b/src/resources/org/apache/cassandra/cli/CliHelp.yaml
@@ -650,9 +650,6 @@ commands:
         - bloom_filter_fp_chance: Desired false positive probability for
           sstable row bloom filters.  Default is 0.000744.
 
-        - trigger_class: Trigger class / set of Trigger classes implementing ITrigger
-          Tigger class is invoked for every insert/update statement.
-
         - column_type: Type of columns this column family holds, valid values are
           Standard and Super. Default is Standard.
 


Mime
View raw message