java – 在cassandra中使用触发器

我尝试使用示例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

解决方法:

而不是遍历单元名称,迭代单元格本身.

for (Column cell : update)
{
    // stuff
}

该示例已得到纠正.

上一篇:javascript – jQuery只有在使用jQuery附加时才触发keyup事件


下一篇:如何在mysql或JDBC中的表中自动插入外键引用?