cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kant Kodali <k...@peernova.com>
Subject Re: How to write a trigger in Cassandra to only detect updates of an existing row?
Date Tue, 04 Oct 2016 19:53:05 GMT
Hi Siddharth,
I don't quite follow the assumption "If you are sure that your application will
NOT do an insert of the form when ONLY primary key values are specified, you can
check the length of next, to indicate whether it is an insert/update(where
atleast one non primary key column value is inserted) or a delete if length is
zero.". Could you please provide an example ?
Thanks,kant
 





On Tue, Oct 4, 2016 12:34 PM, siddharth verma sidd.verma29.list@gmail.com
wrote:
Hi,I am not sure whether it will help you or not.Code snippet :public
Collection<Mutation> augment(Partition update){...    StringBuilder next=new
StringBuilder();    SearchIterator<Clustering, Row> searchIterator =
update.searchIterator(ColumnFilter.all(update.metadata()),false);       
while(searchIterator.hasNext()){           
next.append(searchIterator.next(Clustering.EMPTY).toString()+"\001");        }
...//next carries non primary key column values}
If you are sure that your application will NOT do an insert of the form when
ONLY primary key values are specified, you can check the length of next, to
indicate whether it is an insert/update(where atleast one non primary key column
value is inserted) or a delete if length is zero.
The code snippet is to the best of my knowledge, however, kindly try it once at
your end, as this was part of some legacy code, and I am not completely sure
about it.
Here, if the assumption stated above holds true, you could avoid a cassandra
select for that key.
ThanksSiddharth Verma

On Wed, Oct 5, 2016 at 12:20 AM, Kant Kodali <kant@peernova.com>  wrote:
Thanks a lot, This helps me to make a decision on not to write one for the
performance reasons you pointed out!

 





On Tue, Oct 4, 2016 11:42 AM, Eric Stevens mightye@gmail.com
wrote:
You would have to perform a SELECT on the row in the trigger code in order to
determine if there was underlying data.  Cassandra is in essence an append-only
data store, when an INSERT or UPDATE is executed, it has no idea if there is
already a row underlying it, and for write performance reasons it also doesn't
care.
Note that if you do this, you're going to introduce a giant bottleneck in your
write path and increase the IO cost of writes.  You'll also probably have some
race conditions such that if two writes to the same row happen in quick
succession your trigger might not notice that one of them is writing to the same
row as the other. You might need to resort to CAS operations to overcome that,
along with its associated overhead.  But all that said, it should be possible,
though you'll have to write it for yourself in your trigger code.


On Tue, Oct 4, 2016 at 12:29 PM Kant Kodali <kant@peernova.com> wrote:
Hi all,
How to write a trigger in Cassandra to detect updates? My requirement is that I
want a trigger to alert me only when there is an update to an existing row and
looks like given the way INSERT and Update works this might be hard to do
because INSERT will just overwrite if there is an existing row and Update
becomes new insert where there is no row that belongs to certain partition key.
is there a way to solve this problem?
Thanks,

kant
Mime
View raw message