Re: [appengine-java] Possibility for race condition on datastore?

2011-03-05 Thread Justin
Thanks for the input. Transactions is exactly what I was looking for.
I coding a small game where people can attack each other and decrease
their hp. If players ended up quering for the players hp and different
datastores contain different values, well that's not a good thing
haha.  I'm planning on using the memcache to store the players hp, but
when the value is removed from the cache I got to get the newest value
back into the memcache.

On Thu, Mar 3, 2011 at 11:28 AM, Ikai Lan (Google) ika...@google.com wrote:
 Yes. The only way to correctly do this is with transactions and sharded
 counters.
 The better question, however, is this: what are you doing? Perhaps there is
 an alternative solution.

 Ikai Lan
 Developer Programs Engineer, Google App Engine
 Blog: http://googleappengine.blogspot.com
 Twitter: http://twitter.com/app_engine
 Reddit: http://www.reddit.com/r/appengine


 On Thu, Mar 3, 2011 at 10:57 AM, justin thekeyboard...@gmail.com wrote:

 I need to write code so that a user has a counter. This counter can be
 read, increase, and decrease. This counter is mission critical so I
 will use the high replication datastore.

 So lets say I create a counter entity which has a user entity as the
 ancestor. I increase the counter value and store the value. Almost
 simultaneously I get another request to read the counter. I get the
 entity from the datastore , using the correct ancestor chain, and I
 read the value. Is it possible that these two values will be
 different? If so, is there anyway way to prevent this from happening?

 --
 You received this message because you are subscribed to the Google Groups
 Google App Engine for Java group.
 To post to this group, send email to
 google-appengine-java@googlegroups.com.
 To unsubscribe from this group, send email to
 google-appengine-java+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/google-appengine-java?hl=en.


 --
 You received this message because you are subscribed to the Google Groups
 Google App Engine for Java group.
 To post to this group, send email to google-appengine-java@googlegroups.com.
 To unsubscribe from this group, send email to
 google-appengine-java+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/google-appengine-java?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine for Java group.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Possibility for race condition on datastore?

2011-03-03 Thread justin
I need to write code so that a user has a counter. This counter can be
read, increase, and decrease. This counter is mission critical so I
will use the high replication datastore.

So lets say I create a counter entity which has a user entity as the
ancestor. I increase the counter value and store the value. Almost
simultaneously I get another request to read the counter. I get the
entity from the datastore , using the correct ancestor chain, and I
read the value. Is it possible that these two values will be
different? If so, is there anyway way to prevent this from happening?

-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine for Java group.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



Re: [appengine-java] Possibility for race condition on datastore?

2011-03-03 Thread Ikai Lan (Google)
Yes. The only way to correctly do this is with transactions and sharded
counters.

The better question, however, is this: what are you doing? Perhaps there is
an alternative solution.

Ikai Lan
Developer Programs Engineer, Google App Engine
Blog: http://googleappengine.blogspot.com
Twitter: http://twitter.com/app_engine
Reddit: http://www.reddit.com/r/appengine



On Thu, Mar 3, 2011 at 10:57 AM, justin thekeyboard...@gmail.com wrote:

 I need to write code so that a user has a counter. This counter can be
 read, increase, and decrease. This counter is mission critical so I
 will use the high replication datastore.

 So lets say I create a counter entity which has a user entity as the
 ancestor. I increase the counter value and store the value. Almost
 simultaneously I get another request to read the counter. I get the
 entity from the datastore , using the correct ancestor chain, and I
 read the value. Is it possible that these two values will be
 different? If so, is there anyway way to prevent this from happening?

 --
 You received this message because you are subscribed to the Google Groups
 Google App Engine for Java group.
 To post to this group, send email to
 google-appengine-java@googlegroups.com.
 To unsubscribe from this group, send email to
 google-appengine-java+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/google-appengine-java?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine for Java group.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.