You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Todd Nine <to...@spidertracks.co.nz> on 2010/05/26 11:45:54 UTC

Questions regarding batch mutates and transactions

Hey guys,
  I originally asked this on the Hector group, but no one was sure of the
answer.  Can I get some feedback on this.  I'd prefer to avoid having to use
something like Cages if I can for most of our use cases.  Long term I can
see we'll need to use something like Cages, especially when it comes to
complex operations such as billing.  However for a majority of our uses, I
think it's a bit overkill.  I've used transactions heavily in the workplace
on SQL based app developments.  To be honest, a majority of application's
I've built utilize optimistic locking, and only the atomic, consistent, and
durable functionality of transactional ACID properties.

To encapsulate all 3, I essentially need all writes to cassandra for a given
business invocation to occur in a single write.  With Spring, I would
implement my own transaction manager which simply adds all mutates and
delete ops to a batch mutate.  When my transaction commits, I would execute
the mutation on the given keyspace.  Now this would only work if the
following semantics apply.  I've tried searching for details in Cassandra's
batch mutate, but I'm not finding what I need.  Here are 2 use cases as an
example.

Case 1: Successful update : User adds new contact

Transaction Start.
Biz op 1. Row is created in  "contacts" and all data is added via batch
mutation
Biz op 2. Row is created for an SMS message is created for queueing  through
the SMS gateway
return op 2
return op 1
Transaction Commit (batch mutate executed)

Case 2. Failed update: User adds new contact

Biz op 1. Row is created in "contacts"
Biz op 2. Row is created for SMS message queuing.  Fails due to invalid
international phone number format
return op 2
return op 1
Transaction is rolled back (batch mutate never executed)


Now, here is where I can't find what I need in the doc.  In case 1, if my
mutation from biz op 2 were to fail during a batch mutate operation
encapsulating all mutations, does the batch mutation as a whole not get
executed, or would I still have the mutation from op 1 written to cassandra
while the op 2 write fails?

Thanks,

Re: Questions regarding batch mutates and transactions

Posted by Gary Dusbabek <gd...@gmail.com>.
On Wed, May 26, 2010 at 04:45, Todd Nine <to...@spidertracks.co.nz> wrote:
>
> Now, here is where I can't find what I need in the doc.  In case 1, if my
> mutation from biz op 2 were to fail during a batch mutate operation
> encapsulating all mutations, does the batch mutation as a whole not get
> executed, or would I still have the mutation from op 1 written to cassandra
> while the op 2 write fails?
> Thanks,

batch_mutate makes no atomicity guarantees.  It s intended to help
avoiding many round-trips.

It can fail half-way through leaving you with a partially completed batch.

Gary.

Re: Questions regarding batch mutates and transactions

Posted by Todd Nine <to...@spidertracks.co.nz>.
Correct Ran.  It seems like the only way I'm going to get true mutations
in a single op is to use Cages.  Thankfully a majority of our
application won't require it, just a few specialized components.


On Wed, 2010-05-26 at 12:57 +0300, Ran Tavory wrote:
> The summary of your question is: is batch_mutate atomic in the general
> sense, meaning when used with multiple keys, multiple column families
> etc, correct?


Re: Questions regarding batch mutates and transactions

Posted by Ran Tavory <ra...@gmail.com>.
The summary of your question is: is batch_mutate atomic in the general
sense, meaning when used with multiple keys, multiple column families etc,
correct?

On Wed, May 26, 2010 at 12:45 PM, Todd Nine <to...@spidertracks.co.nz> wrote:

> Hey guys,
>   I originally asked this on the Hector group, but no one was sure of the
> answer.  Can I get some feedback on this.  I'd prefer to avoid having to use
> something like Cages if I can for most of our use cases.  Long term I can
> see we'll need to use something like Cages, especially when it comes to
> complex operations such as billing.  However for a majority of our uses, I
> think it's a bit overkill.  I've used transactions heavily in the workplace
> on SQL based app developments.  To be honest, a majority of application's
> I've built utilize optimistic locking, and only the atomic, consistent, and
> durable functionality of transactional ACID properties.
>
> To encapsulate all 3, I essentially need all writes to cassandra for a
> given business invocation to occur in a single write.  With Spring, I would
> implement my own transaction manager which simply adds all mutates and
> delete ops to a batch mutate.  When my transaction commits, I would execute
> the mutation on the given keyspace.  Now this would only work if the
> following semantics apply.  I've tried searching for details in Cassandra's
> batch mutate, but I'm not finding what I need.  Here are 2 use cases as an
> example.
>
> Case 1: Successful update : User adds new contact
>
> Transaction Start.
> Biz op 1. Row is created in  "contacts" and all data is added via batch
> mutation
>  Biz op 2. Row is created for an SMS message is created for queueing
>  through the SMS gateway
> return op 2
> return op 1
> Transaction Commit (batch mutate executed)
>
> Case 2. Failed update: User adds new contact
>
> Biz op 1. Row is created in "contacts"
> Biz op 2. Row is created for SMS message queuing.  Fails due to invalid
> international phone number format
> return op 2
> return op 1
> Transaction is rolled back (batch mutate never executed)
>
>
> Now, here is where I can't find what I need in the doc.  In case 1, if my
> mutation from biz op 2 were to fail during a batch mutate operation
> encapsulating all mutations, does the batch mutation as a whole not get
> executed, or would I still have the mutation from op 1 written to cassandra
> while the op 2 write fails?
>
> Thanks,
>