You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by S Ahmed <sa...@gmail.com> on 2016/11/07 19:51:56 UTC

store individual inventory items in a table, how to assign them correctly

Say I have 100 products in inventory, instead of having a counter I want to
create 100 rows per inventory item.

When someone purchases a product, how can I correctly assign that customer
a product from inventory without having any race conditions etc?

Thanks.

Re: store individual inventory items in a table, how to assign them correctly

Posted by Carlos Alonso <in...@mrcalonso.com>.
Bear in mind that LWT will, under certain circumstances fail too. See
amazing Chris Batey's talk about it on Cassandra Summit:
https://www.youtube.com/watch?v=wcxQM3ZN20c

Carlos Alonso | Software Engineer | @calonso <https://twitter.com/calonso>

On 7 November 2016 at 22:22, Justin Cameron <ju...@instaclustr.com> wrote:

> You can use lightweight transactions to achieve this.
>
> Example:
> UPDATE item SET customer = 'Joe' WHERE item_id = 2 IF customer = null;
>
> Keep in mind that lightweight transactions have performance tradeoffs (
> http://www.datastax.com/dev/blog/lightweight-transactions-in-cassandra-2-0
> )
>
>
> On Mon, 7 Nov 2016 at 11:52 S Ahmed <sa...@gmail.com> wrote:
>
>> Say I have 100 products in inventory, instead of having a counter I want
>> to create 100 rows per inventory item.
>>
>> When someone purchases a product, how can I correctly assign that
>> customer a product from inventory without having any race conditions etc?
>>
>> Thanks.
>>
> --
>
> Justin Cameron
>
> Senior Software Engineer | Instaclustr
>
>
>
>
> This email has been sent on behalf of Instaclustr Pty Ltd (Australia) and
> Instaclustr Inc (USA).
>
> This email and any attachments may contain confidential and legally
> privileged information.  If you are not the intended recipient, do not copy
> or disclose its content, but please reply to this email immediately and
> highlight the error to the sender and then immediately delete the message.
>
>

Re: store individual inventory items in a table, how to assign them correctly

Posted by Justin Cameron <ju...@instaclustr.com>.
You can use lightweight transactions to achieve this.

Example:
UPDATE item SET customer = 'Joe' WHERE item_id = 2 IF customer = null;

Keep in mind that lightweight transactions have performance tradeoffs (
http://www.datastax.com/dev/blog/lightweight-transactions-in-cassandra-2-0)


On Mon, 7 Nov 2016 at 11:52 S Ahmed <sa...@gmail.com> wrote:

> Say I have 100 products in inventory, instead of having a counter I want
> to create 100 rows per inventory item.
>
> When someone purchases a product, how can I correctly assign that customer
> a product from inventory without having any race conditions etc?
>
> Thanks.
>
-- 

Justin Cameron

Senior Software Engineer | Instaclustr




This email has been sent on behalf of Instaclustr Pty Ltd (Australia) and
Instaclustr Inc (USA).

This email and any attachments may contain confidential and legally
privileged information.  If you are not the intended recipient, do not copy
or disclose its content, but please reply to this email immediately and
highlight the error to the sender and then immediately delete the message.

Re: store individual inventory items in a table, how to assign them correctly

Posted by Vladimir Yudovin <vl...@winguzone.com>.
Hi,



can you elaborate a little your data model?

Would you like to create 100 rows for each product and then remove one row and add this row to customer?



Best regards, Vladimir Yudovin, 

Winguzone - Hosted Cloud Cassandra
Launch your cluster in minutes.





---- On Mon, 07 Nov 2016 14:51:56 -0500S Ahmed &lt;sahmed1020@gmail.com&gt; wrote ----




Say I have 100 products in inventory, instead of having a counter I want to create 100 rows per inventory item.



When someone purchases a product, how can I correctly assign that customer a product from inventory without having any race conditions etc?



Thanks.