You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Jakub Narloch <jm...@gmail.com> on 2016/07/25 12:47:32 UTC

Cassandra 3.4 Triggers API

Hi guys,

I had been exploring recently the Cassandra Triggers and I think that there
are going to be very useful for my use case, though I think that I would
need a bit of help with setting it up.

I fallow this example and it was been very helpful, my use case is
basically similar I want to have the audit table that is going to populated
by the trigger, as I assume I might thanks to that be able to insert the
rows in a kind of of lightweight transaction.
https://github.com/apache/cassandra/blob/trunk/examples/triggers/src/org/apache/cassandra/triggers/AuditTrigger.java

Though I have two questions:

   - My audit table schema defines a compound partition key, how can I
   create one at hand within the trigger?
   - What is the actual way to iterate over the insert/update column values
   and decode their values into Java objects?

I would appreciate your help.

Regards,
Jakub Narloch

Re: Cassandra 3.4 Triggers API

Posted by Siddharth Verma <ve...@snapdeal.com>.
Hi Jakub,
You can read the mail thread on how to extract clustering columns in
trigger.

https://mail-archives.apache.org/mod_mbox/cassandra-user/201605.mbox/%3CCAAam9ssYf0LvBgJ86M1Phb0ak7=JNH_acoANR8OfoV4KvbrJvw@mail.gmail.com%3E

Extracting partition key for the operation is mentioned in the trigger
example.

Regards,
Siddharth Verma

Re: Cassandra 3.4 Triggers API

Posted by Jakub Narloch <jm...@gmail.com>.
Hi Siddharth,

Thank you for answer.

Yes this is exactly the same goal that I wish to accomplish, though I was
wondering whether it would be possible to access the data of the row that
is being inserted so that I would be able to take a snapshot of the entire
row. Does anybody knows if that is really impossible?

So to sum up I have a single table that I wish to audit for any of the
changes. The table partition key consists of three columns that uniquely
identify the row.

table data (
 composite_key1 TEXT,
 composite_key2 TEXT,
 composite_key3 TEXT,

 PRIMARY KEY(composite_key1, composite_key2, composite_key3)
);

What I wish to do is extract the those three columns through trigger and
insert those into a audit table which is going to have a aggregating
partition key as well as clustering timeuuid. Something similar to

table audit_table (
   timestamp_aggregate long,
   timestamp timeuuid,

   composite_key1 TEXT,
   composite_key2 TEXT,
   composite_key3 TEXT

   PRIMARY KEY(timestamp_aggregate, timestamp)
) WITH CLUSTERING ORDER BY (timestamp ASC);

Could you share any code snippet on how exactly you manage to extract the
partition keys columns?

Regards,
Jakub Narloch



2016-07-25 17:48 GMT+02:00 Siddharth Verma <ve...@snapdeal.com>:

> Hi Jakub,
> I worked with trigger, I was auditing it by time
> .
> I considered the following partition keys for the audit table.
> 1. (timeuuid,uuid) OR,
> 2. formatted date in groups of 5 minutes
> 21 March 2015, 13:44:15 -> 201503211340
>
> *Used it to batch operations by a group of minutes.*
>
>
> *Caution : If you have extremely heavy write/update work load, it may
> cause to create wide rows.*
> Your second point isn't clear.
> If you want the values of non primary key columns to be audited, as is
> done with triggers in MySQL, unfortunately, as far as I know, this can't be
> done.
> However for the values of partition key, clustering column, on which the
> update,insert,delete is called,
> this can be extracted by using the UnfilteredRowIterator of the Partition
> object you receive in the trigger function.
>
> Thanks and Regards,
> Siddharth Verma
>

Re: Cassandra 3.4 Triggers API

Posted by Siddharth Verma <ve...@snapdeal.com>.
Hi Jakub,
I worked with trigger, I was auditing it by time
.
I considered the following partition keys for the audit table.
1. (timeuuid,uuid) OR,
2. formatted date in groups of 5 minutes
21 March 2015, 13:44:15 -> 201503211340

*Used it to batch operations by a group of minutes.*


*Caution : If you have extremely heavy write/update work load, it may cause
to create wide rows.*
Your second point isn't clear.
If you want the values of non primary key columns to be audited, as is done
with triggers in MySQL, unfortunately, as far as I know, this can't be done.
However for the values of partition key, clustering column, on which the
update,insert,delete is called,
this can be extracted by using the UnfilteredRowIterator of the Partition
object you receive in the trigger function.

Thanks and Regards,
Siddharth Verma