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.
S Ahmed 's gravatar image asked Nov 7 2016 at 11:51 in Cassandra-User by S Ahmed

3 Answers

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)
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.
Justin Cameron 's gravatar image answered Nov 7 2016 at 13:22 by Justin Cameron
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>
Carlos Alonso 's gravatar image answered Nov 8 2016 at 04:05 by Carlos Alonso
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.
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.
Vladimir Yudovin 's gravatar image answered Nov 8 2016 at 05:53 by Vladimir Yudovin

Related Discussions

  • Using Node-mysql-queue Transactions Correctly in Nodejs

  • Hi folks! I'm working on a webshop prototype which makes use of mongodb for product catalouge, users and orders, redis for sessions and mysql for the inventory. I want to use mysql transactions to make sure that, if a order is placed, the inventory stock is changed accordingly. So started writing the code, messed around with it but was left behind with one problem: for (lineitem in lineitems) { ...

  • How To Correctly Handle Offsets? in Incubator-kafka-users

  • Hi all: I am using Kafka 0.8.2 and SimpleConsumer in maven: org.apache.kafka kafka_2.11 0.8.2.1 I follow the SimpleConsumer example in the wiki, and there are some questions: 1. There seems lacking of how to commit the offset to Kafka. As far as I google it, it seems that I should use the OffsetCommitRequest. However, like a thread that posted in this email group several...

  • How To Terminate A TkinterApp Correctly? in Python

  • I'm working on a windows machine I've written a Tkinter-app (sort of game) which consists mainly of an animation which is driven by a while True: ... loop. If I close the App's window by clicking the right upper standard-X-Button, the program doesn't terminate cleanly. Instead a somewhat cryptic error message is displayed, e.g.: .... TclError: invalid command name ".12880040.12880944" which - ...

  • How To Export A Project To A JAR In Scala IDE For Eclipse Correctly? in Spark-user

  • Hi there: I export a project into jar like this "right click my project->choose export ->java-> jar file-> next->choose "src/main/resouces" and ''src/main/scala"'-> clikc browse and choose a jar file export location-> choose overwrite it", and this jar is unable to run with "java -jar myjar.jar". It says "no main manifest attribute, in /opt/MyJar.jar". It seems the file MANIFEST.MF lost the ...

  • Error Setting Property In Case Of A Null Value - How To Map Correctly ? in Ibatis-user-java

  • Hi, I am new on iBatis and I try to map an Oracle 9i based result and get the following error: Caused by: java.lang.RuntimeException: Error setting property 'setRepurchaseFeeId' of XYZ ( [email protected] repurchaseFeeId = 0 targetGroupId = 0 offerFeeId = 0 offerId = null transferToDo = FALSE salesInfoId = 0 minimumQuota = 0 validFrom = null quotaIsPublic = FALSE ...

  • How To Verify If A Property Is Indexed Correctly? in Neo4j

  • Hi, I am doing a batch import and creating indexes at the same time. 3 node indexes were created. The first two node indexes are fine, but the third one, seems to be created, is not working when I use it in cypher. How do I check if the index was created correctly? Is there a way to see the values in the index? Thanks, Fudong...

  • [2.1 Java] How To: Compose A Future Correctly in Play-framework

  • Hello, We are using Amazon AWS API inside a typed actor to send back a list of Instance (http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/ec2/AmazonEC2Client.html#describeInstances()). Currently, the class, which is being used as a Typed Actor is returning List. Based on the docs for Akka (http://doc.akka.io/docs/akka/2.1.2/java/typed-actors.html), I would like to change...

  • How Include Library Correctly In A Visual C++ 6 Project in Mysql-general

  • how to include your library in visual c++ 6 project because y have many problem y must redefine all path for include ex #include ->> #include "..\directory\mysql++" thank you for your answer Thomas Wolff Akosystem Am Tiefen Weg 17b 76547 Sinzheim Email: mailto:[email protected] Telefon: +49 (0) 7221 / 98 78 40 Fax: +49 (0) 72 21/98 78 42 Handy France : +33...

  • How To Use TypeMap Correctly? in Ibatis-user-java

  • Hi, We are trying to handle custom types (such as Oracle Object), the only way we find out now is to get the connection instance from SqlMapper.getDataSource().getConnection(), and set the typeMap in that connection, and set it back using SqlMapper.setUserConnection. The API document says: "Using a user supplied connection basically sidesteps the...

  • $location.url How To Use Correctly? in Angularjs

  • My current page is website.com/app/#/login I need to then send the user to website.com/app/server/login.php $location.url(server/login.php); Doesn't work?...

  • How To Install Paramiko Correctly? in Python

  • My system:win7+python3.4 . I have installed Crypto and Paramiko . C:\Windows\system32>pip3.4 install Crypto Requirement already satisfied (use --upgrade to upgrade): Crypto in d:\python34\ lib\site-packages Cleaning up... C:\Windows\system32>pip3.4 install Paramiko Requirement already satisfied (use --upgrade to upgrade): Paramiko in d:\python3 4\lib\site-packages ...

  • How Do You Correctly Minify / Allow For Dependency Injection For Variables Passed To A Controller In A Resolve Block in Angularjs

  • Below is my code, but when passing crew to the controller it is failing. I get error, "Service name expected". I need to figure out how to do this so I can minify my code. Any help is appreciated! var app = angular.module('app', ['starTrekServices']); app.config(function ($locationProvider, $routeProvider) { $routeProvider.when("/", {templateUrl:"partials/home.html"}); $routeProvider...

  • GIMP: How To Correctly And Effectively Install It In Kubuntu in Ubuntu-users

  • 11.04? SOLVED. *Dear everybody* *Thanks for the different replies in this thread: GIMP: how to correctly and effectively install it in Kubuntu 11.04? Below you can find a"workaround" which works perfectly well. Respectfully yours, Bas Roufs. * ===================*Bas G. Roufs* Van 't Hoffstraat 1 NL-3514 VT Utrecht M./SMS +31 6 446 835 10 T. +31 30 785 2040 E. BasRoufs at gmail.com An HTML...

  • GIMP: How To Correctly And Effectively Install It In Kubuntu in Kubuntu-users

  • 11.04? SOLVED. *Dear everybody* *Thanks for the different replies in this thread: GIMP: how to correctly and effectively install it in Kubuntu 11.04? Below you can find a"workaround" which works perfectly well. Respectfully yours, Bas Roufs. * ===================*Bas G. Roufs* Van 't Hoffstraat 1 NL-3514 VT Utrecht M./SMS +31 6 446 835 10 T. +31 30 785 2040 E. BasRoufs at gmail.com An HTML...

  • How To Upgrade Correctly To 2.2.1??? in Python

  • hello I have 2.2 installed and now I want to install 2.2.1 make uninstall in the 2.2 dicrectory does not work so I typed sudo rm -rf /usr/local/bin/pydoc sudo rm -rf /usr/local/binpython* sudo rm -rf /usr/local/lib/python2.2/ does this remove all the python 2.2 stuff?? markus...

  • How To Correctly Infer A Type Variable Of A Generic Trai in Scala-user

  • In the example below i am trying to get the type "K" of the trait "BaseEntity" without specifying it as an extra type parameter in the "Dao" class. Means i would like to have the compiler complaining about the call with the string parameter in the Test Application and to accept the call with the Int parameter. The compiler infers Any as the type of the first parameter in the method requireAndGet...

  • How To Verify Master<->slave Working Correctly in Mysql-replication

  • I have inherited two load-balanced replicated servers from an admin who has since left the company. The two (Linux redhat) servers were set up with mastermaster replication. Replication broke and although I managed to fix it, it continues to break. I want to move the configuration back to being masterslave. My question is, how can I ensure that both Server A and Server B write to DB1 and ...

  • How To Use `replace` Of Directive Correctly? in Angularjs

  • Hi, all: I thought `replace:true` means the template of directive will replace original tag content, and `replace:false` will append. But it seems not, see this live demo:http://plnkr.co/edit/rGIgmjO81X2UxJohL4HM?p=preview Also see this stackoverflow question I just asked:http://stackoverflow.com/questions/15285635/how-to-use-replace-of-directive-definition...

  • How To Calculate Correctly The Cluster Size in Python

  • Josiah> The Windows 2k "Disk Administrator" software for Josiah> 2K always uses 4k cluster sizes by default. Josiah> I believe your varied cluster sizes are the Josiah> result of using Partition Magic to create them. FWIW, the FORMAT command does offer the possibility of selecting different cluster sizes. I've never used it personally (and I'm not about to try it on this machine, either!) ...

  • How To Calculate Correctly The Cluster Size in Python

  • Hi! I need Your help... I am trying to find a way to calculate the cluster size for a drive. I looked at the GetDiskFreeSpaceEx function in Win32 and it turned out that it didn't provide the information I was looking for. Using the old GetDiskFreeSpace function I could just multiply the Bytes per Sector by the Sector per Cluster and get the cluster size. I heard that the old GetDiskFreeSpace function...