我尝试使用示例https://github.com/apache/cassandra/tree/trunk/examples/triggers
我接受了帮助并编写了自己的触发器。但是我在 UnsortedColumns.getColumn(UnsortedColumns.java:105) 上得到了 UnsupportedOperationException。这是网络上唯一活跃的例子。此示例不推荐使用其他其他方法。我该如何解决 ?
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.apache.cassandra.db.ColumnFamily;
import org.apache.cassandra.db.RowMutation;
import org.apache.cassandra.triggers.ITrigger;
public class FirstTrigger implements ITrigger {
@Override
public Collection<RowMutation> augment(ByteBuffer key, ColumnFamily update) {
List<RowMutation> mutations = new ArrayList<RowMutation>();
for (ByteBuffer name : update.getColumnNames()) {
RowMutation mutation = new RowMutation("mykeyspace", update.getColumn(name).value());
mutation.add("trigger_log", name, key, System.currentTimeMillis());
mutations.add(mutation);
}
return mutations;
}
}
存储日志事件的架构是:
use mykeyspace;
create table if not exists TRIGGER_LOG (
transaction_id int,
log varchar,
PRIMARY KEY (transaction_id));
我的错误是
ERROR [Thrift:1] 2013-10-28 03:53:53,120 ProcessFunction.java (line 41) Internal error processing execute_prepared_cql3_query
java.lang.RuntimeException: Exception while creating trigger on CF with ID: 08f73f2f-c4c4-3a23-b2ae-3fdc92559012
at org.apache.cassandra.triggers.TriggerExecutor.execute(TriggerExecutor.java:131)
at org.apache.cassandra.triggers.TriggerExecutor.execute(TriggerExecutor.java:73)
at org.apache.cassandra.service.StorageProxy.mutateWithTriggers(StorageProxy.java:535)
at org.apache.cassandra.cql3.statements.ModificationStatement.executeWithoutCondition(ModificationStatement.java:360)
at org.apache.cassandra.cql3.statements.ModificationStatement.execute(ModificationStatement.java:344)
at org.apache.cassandra.cql3.QueryProcessor.processStatement(QueryProcessor.java:101)
at org.apache.cassandra.cql3.QueryProcessor.processPrepared(QueryProcessor.java:235)
at org.apache.cassandra.thrift.CassandraServer.execute_prepared_cql3_query(CassandraServer.java:2045)
at org.apache.cassandra.thrift.Cassandra$Processor$execute_prepared_cql3_query.getResult(Cassandra.java:4480)
at org.apache.cassandra.thrift.Cassandra$Processor$execute_prepared_cql3_query.getResult(Cassandra.java:4464)
at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:39)
at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:39)
at org.apache.cassandra.thrift.CustomTThreadPoolServer$WorkerProcess.run(CustomTThreadPoolServer.java:194)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.UnsupportedOperationException
at org.apache.cassandra.db.UnsortedColumns.getColumn(UnsortedColumns.java:105)
at com.symantec.paranoid.trigger.FirstTrigger.augment(FirstTrigger.java:18)
at org.apache.cassandra.triggers.TriggerExecutor.execute(TriggerExecutor.java:123)
... 15 more