[google-appengine] Re: datastore transaction question

2008-10-11 Thread David


thanks for your replies, especially yejun, that thread is very
informative, not only now, but of a problem I could see coming when I
need to transact a product from one user to another and money must
also be updated on both users.



On Oct 10, 8:31 pm, yejun <[EMAIL PROTECTED]> wrote:
> I found an old thread on this 
> topic.http://groups.google.com/group/google-appengine/browse_thread/thread/...
> It seems eventual consistency is the only practical option.
>
> On Oct 9, 1:04 pm, David <[EMAIL PROTECTED]> wrote:
>
> > Hi, a question for all you datastore gurus:
>
> > If I have:
>
> > class User(db.Model):
> >     money = db.IntegerProperty(required=True)
>
> > class Thing(db.Model):
> >     cost = db.IntegerProperty(required=True)
> >     stuff = db.BlobProperty(required=True)
>
> > I need to allow a user to create a new thing and then reference the
> > things they have somehow. So a request would be called with the cost
> > and the blob data, and I would like to put a new Thing in the
> > datastore. But heres the problem, only if the user has enough money to
> > create the new Thing.
>
> > This is causing me a issue, as i cant update two separate entity
> > groups in one transaction. unless im missing something i dont want to
> > group them as the Thing may be sold at a later data to a new User.
>
> > so i need to:
>
> > 1)get the users money
> > 2)if they have enough create the Thing and put it in the datastore
> > 3)update the users money and reference the Thing to the user somehow
> > and re-store
>
> > If any of this fails i need it all to roll back.
>
> > Currently im creating the Thing regardles and performing a transaction
> > on the User, if this fails i delete the Thing after. This makes me
> > uneasy :)
>
> > any suggestions would be most welcome.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: datastore transaction question

2008-10-10 Thread yejun

I found an old thread on this topic.
http://groups.google.com/group/google-appengine/browse_thread/thread/ba1c22b37581/8722ed96f11f0c17
It seems eventual consistency is the only practical option.

On Oct 9, 1:04 pm, David <[EMAIL PROTECTED]> wrote:
> Hi, a question for all you datastore gurus:
>
> If I have:
>
> class User(db.Model):
>     money = db.IntegerProperty(required=True)
>
> class Thing(db.Model):
>     cost = db.IntegerProperty(required=True)
>     stuff = db.BlobProperty(required=True)
>
> I need to allow a user to create a new thing and then reference the
> things they have somehow. So a request would be called with the cost
> and the blob data, and I would like to put a new Thing in the
> datastore. But heres the problem, only if the user has enough money to
> create the new Thing.
>
> This is causing me a issue, as i cant update two separate entity
> groups in one transaction. unless im missing something i dont want to
> group them as the Thing may be sold at a later data to a new User.
>
> so i need to:
>
> 1)get the users money
> 2)if they have enough create the Thing and put it in the datastore
> 3)update the users money and reference the Thing to the user somehow
> and re-store
>
> If any of this fails i need it all to roll back.
>
> Currently im creating the Thing regardles and performing a transaction
> on the User, if this fails i delete the Thing after. This makes me
> uneasy :)
>
> any suggestions would be most welcome.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: datastore transaction question

2008-10-09 Thread Josh Heitzman

In this scenario "Update both the User and the Thing using a single
db.put([thing, user])" the thing and the user won't be updated in the
same transaction, so the put of the thing could succeed while the put
of the user failed.

On Oct 9, 9:29 pm, johnP <[EMAIL PROTECTED]> wrote:
> Why not simply have the reference in the Thing, pointing to the
> User?   Then use the idiom: x = user.thing_set.fetch(1000) to get the
> User's Things?  Update both the User and the Thing using a single
> db.put([thing, user])
>
> johnP
>
> On Oct 9, 2:19 pm, Josh Heitzman <[EMAIL PROTECTED]> wrote:
>
> > I ran into a similar problem with the strategy game I'm working on.
> > The game world is divided up into areas and each area can have a more
> > then one player's troops in it at a time.  I've modeled these with
> > three entities, player, area, and areaplayer.  When a player has his
> > troops do something in an area it can potentially affect the area
> > state, the associated areaplayer states, and the associated player
> > states.  If all of those things were in the same entity group that
> > would mean the entire game state would be in the same entity group
> > resulting in massive contention.  Instead each player and their home
> > area is an entity group and each non-home area is an entity group.
> > The areaplayer is in the entity group with the area, which is the same
> > as the player for the case of the home area.
>
> > So when a player orders troops to do something in their home area when
> > no other player has troops there, its no problem as the player, the
> > area, and the sole areaplayer are all in the same entity group so a
> > GAE DS transaction can be used.  However, orders given to troops away
> > from home or at home other players have troops there have to make
> > updates to multiple entity groups.
>
> > I'm dealing with this by via a reliable multi-entity group update
> > mechanism (no rollback, but will continue processing the update across
> > requests and server process instances) that I hope can be enhance into
> > true multi-entity group transactions if that can actually be done will
> > still staying under quotas.  I'm getting close to deploying my
> > prototype with the reliable multi-entity group update mechanism, so I
> > can find out how I'm doing on quotas as it is.  Then I'll know if
> > there is possibly create a cross-entity group transaction mechanism.
>
> > I really think Google needs to provide cross-entity group transactions
> > though, as they'll be able to do it in native code, and thus faster
> > then we'll be able to do it in Python on at the app level.
>
> > On Oct 9, 1:20 pm, David <[EMAIL PROTECTED]> wrote:
>
> > > thanks for the replies.
>
> > > as i mentioned in the question, the Thing will become a product and
> > > could be sold to another user at a later date. A list of keys is also
> > > what ive been using, as a referenece property in the Thing causes the
> > > blobs to pulled from the data store (they can be quite large, well
> > > less then a mb aye ;) ) when i want to list the users current things
> > > (by title).
>
> > > i guess another way of looking at it is really the user is creating a
> > > new product. and then is trying to buy it. if the product is no longer
> > > wanted by anyone it can be deleted.
>
> > > i was trying to work out a was to safly trasact on the money so the
> > > Thing never touches the datastore if there isnt enough cash. But this
> > > is a unuaul case, things will be sold between users more then created.
>
> > > any thoughts? its all a learning process for me.
>
> > > On Oct 9, 8:49 pm, Bill <[EMAIL PROTECTED]> wrote:
>
> > > > > Have you seen: "Entity Groups, Ancestors and Paths" 
> > > > > ?http://code.google.com/appengine/docs/datastore/keysandentitygroups.html
>
> > > > Good point. If a Thing will never be used for another User (e.g., it's
> > > > not a product), you could make the Thing part of a User's entity group.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: datastore transaction question

2008-10-09 Thread johnP

Why not simply have the reference in the Thing, pointing to the
User?   Then use the idiom: x = user.thing_set.fetch(1000) to get the
User's Things?  Update both the User and the Thing using a single
db.put([thing, user])

johnP


On Oct 9, 2:19 pm, Josh Heitzman <[EMAIL PROTECTED]> wrote:
> I ran into a similar problem with the strategy game I'm working on.
> The game world is divided up into areas and each area can have a more
> then one player's troops in it at a time.  I've modeled these with
> three entities, player, area, and areaplayer.  When a player has his
> troops do something in an area it can potentially affect the area
> state, the associated areaplayer states, and the associated player
> states.  If all of those things were in the same entity group that
> would mean the entire game state would be in the same entity group
> resulting in massive contention.  Instead each player and their home
> area is an entity group and each non-home area is an entity group.
> The areaplayer is in the entity group with the area, which is the same
> as the player for the case of the home area.
>
> So when a player orders troops to do something in their home area when
> no other player has troops there, its no problem as the player, the
> area, and the sole areaplayer are all in the same entity group so a
> GAE DS transaction can be used.  However, orders given to troops away
> from home or at home other players have troops there have to make
> updates to multiple entity groups.
>
> I'm dealing with this by via a reliable multi-entity group update
> mechanism (no rollback, but will continue processing the update across
> requests and server process instances) that I hope can be enhance into
> true multi-entity group transactions if that can actually be done will
> still staying under quotas.  I'm getting close to deploying my
> prototype with the reliable multi-entity group update mechanism, so I
> can find out how I'm doing on quotas as it is.  Then I'll know if
> there is possibly create a cross-entity group transaction mechanism.
>
> I really think Google needs to provide cross-entity group transactions
> though, as they'll be able to do it in native code, and thus faster
> then we'll be able to do it in Python on at the app level.
>
> On Oct 9, 1:20 pm, David <[EMAIL PROTECTED]> wrote:
>
> > thanks for the replies.
>
> > as i mentioned in the question, the Thing will become a product and
> > could be sold to another user at a later date. A list of keys is also
> > what ive been using, as a referenece property in the Thing causes the
> > blobs to pulled from the data store (they can be quite large, well
> > less then a mb aye ;) ) when i want to list the users current things
> > (by title).
>
> > i guess another way of looking at it is really the user is creating a
> > new product. and then is trying to buy it. if the product is no longer
> > wanted by anyone it can be deleted.
>
> > i was trying to work out a was to safly trasact on the money so the
> > Thing never touches the datastore if there isnt enough cash. But this
> > is a unuaul case, things will be sold between users more then created.
>
> > any thoughts? its all a learning process for me.
>
> > On Oct 9, 8:49 pm, Bill <[EMAIL PROTECTED]> wrote:
>
> > > > Have you seen: "Entity Groups, Ancestors and Paths" 
> > > > ?http://code.google.com/appengine/docs/datastore/keysandentitygroups.html
>
> > > Good point. If a Thing will never be used for another User (e.g., it's
> > > not a product), you could make the Thing part of a User's entity group.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: datastore transaction question

2008-10-09 Thread Josh Heitzman

I ran into a similar problem with the strategy game I'm working on.
The game world is divided up into areas and each area can have a more
then one player's troops in it at a time.  I've modeled these with
three entities, player, area, and areaplayer.  When a player has his
troops do something in an area it can potentially affect the area
state, the associated areaplayer states, and the associated player
states.  If all of those things were in the same entity group that
would mean the entire game state would be in the same entity group
resulting in massive contention.  Instead each player and their home
area is an entity group and each non-home area is an entity group.
The areaplayer is in the entity group with the area, which is the same
as the player for the case of the home area.

So when a player orders troops to do something in their home area when
no other player has troops there, its no problem as the player, the
area, and the sole areaplayer are all in the same entity group so a
GAE DS transaction can be used.  However, orders given to troops away
from home or at home other players have troops there have to make
updates to multiple entity groups.

I'm dealing with this by via a reliable multi-entity group update
mechanism (no rollback, but will continue processing the update across
requests and server process instances) that I hope can be enhance into
true multi-entity group transactions if that can actually be done will
still staying under quotas.  I'm getting close to deploying my
prototype with the reliable multi-entity group update mechanism, so I
can find out how I'm doing on quotas as it is.  Then I'll know if
there is possibly create a cross-entity group transaction mechanism.

I really think Google needs to provide cross-entity group transactions
though, as they'll be able to do it in native code, and thus faster
then we'll be able to do it in Python on at the app level.

On Oct 9, 1:20 pm, David <[EMAIL PROTECTED]> wrote:
> thanks for the replies.
>
> as i mentioned in the question, the Thing will become a product and
> could be sold to another user at a later date. A list of keys is also
> what ive been using, as a referenece property in the Thing causes the
> blobs to pulled from the data store (they can be quite large, well
> less then a mb aye ;) ) when i want to list the users current things
> (by title).
>
> i guess another way of looking at it is really the user is creating a
> new product. and then is trying to buy it. if the product is no longer
> wanted by anyone it can be deleted.
>
> i was trying to work out a was to safly trasact on the money so the
> Thing never touches the datastore if there isnt enough cash. But this
> is a unuaul case, things will be sold between users more then created.
>
> any thoughts? its all a learning process for me.
>
> On Oct 9, 8:49 pm, Bill <[EMAIL PROTECTED]> wrote:
>
> > > Have you seen: "Entity Groups, Ancestors and Paths" 
> > > ?http://code.google.com/appengine/docs/datastore/keysandentitygroups.html
>
> > Good point. If a Thing will never be used for another User (e.g., it's
> > not a product), you could make the Thing part of a User's entity group.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: datastore transaction question

2008-10-09 Thread yejun

Maybe you can store money and ownership relation in a single entity
group.
ListProperty only works with key value not reference, so they won't be
dereferenced automatically. If you want to access partial information
about thing without pulling the blob value, you need to make a
separated kind in datastore.

On Oct 9, 4:20 pm, David <[EMAIL PROTECTED]> wrote:
> thanks for the replies.
>
> as i mentioned in the question, the Thing will become a product and
> could be sold to another user at a later date. A list of keys is also
> what ive been using, as a referenece property in the Thing causes the
> blobs to pulled from the data store (they can be quite large, well
> less then a mb aye ;) ) when i want to list the users current things
> (by title).
>
> i guess another way of looking at it is really the user is creating a
> new product. and then is trying to buy it. if the product is no longer
> wanted by anyone it can be deleted.
>
> i was trying to work out a was to safly trasact on the money so the
> Thing never touches the datastore if there isnt enough cash. But this
> is a unuaul case, things will be sold between users more then created.
>
> any thoughts? its all a learning process for me.
>
> On Oct 9, 8:49 pm, Bill <[EMAIL PROTECTED]> wrote:
>
> > > Have you seen: "Entity Groups, Ancestors and Paths" 
> > > ?http://code.google.com/appengine/docs/datastore/keysandentitygroups.html
>
> > Good point. If a Thing will never be used for another User (e.g., it's
> > not a product), you could make the Thing part of a User's entity group.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: datastore transaction question

2008-10-09 Thread David

thanks for the replies.

as i mentioned in the question, the Thing will become a product and
could be sold to another user at a later date. A list of keys is also
what ive been using, as a referenece property in the Thing causes the
blobs to pulled from the data store (they can be quite large, well
less then a mb aye ;) ) when i want to list the users current things
(by title).

i guess another way of looking at it is really the user is creating a
new product. and then is trying to buy it. if the product is no longer
wanted by anyone it can be deleted.

i was trying to work out a was to safly trasact on the money so the
Thing never touches the datastore if there isnt enough cash. But this
is a unuaul case, things will be sold between users more then created.

any thoughts? its all a learning process for me.


On Oct 9, 8:49 pm, Bill <[EMAIL PROTECTED]> wrote:
> > Have you seen: "Entity Groups, Ancestors and Paths" 
> > ?http://code.google.com/appengine/docs/datastore/keysandentitygroups.html
>
> Good point. If a Thing will never be used for another User (e.g., it's
> not a product), you could make the Thing part of a User's entity group.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: datastore transaction question

2008-10-09 Thread Bill


> Have you seen: "Entity Groups, Ancestors and Paths" 
> ?http://code.google.com/appengine/docs/datastore/keysandentitygroups.html

Good point. If a Thing will never be used for another User (e.g., it's
not a product), you could make the Thing part of a User's entity group.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: datastore transaction question

2008-10-09 Thread Davide Rognoni

Have you seen: "Entity Groups, Ancestors and Paths" ?
http://code.google.com/appengine/docs/datastore/keysandentitygroups.html


On Oct 9, 7:04 pm, David <[EMAIL PROTECTED]> wrote:
> Hi, a question for all you datastore gurus:
>
> If I have:
>
> class User(db.Model):
>     money = db.IntegerProperty(required=True)
>
> class Thing(db.Model):
>     cost = db.IntegerProperty(required=True)
>     stuff = db.BlobProperty(required=True)
>
> I need to allow a user to create a new thing and then reference the
> things they have somehow. So a request would be called with the cost
> and the blob data, and I would like to put a new Thing in the
> datastore. But heres the problem, only if the user has enough money to
> create the new Thing.
>
> This is causing me a issue, as i cant update two separate entity
> groups in one transaction. unless im missing something i dont want to
> group them as the Thing may be sold at a later data to a new User.
>
> so i need to:
>
> 1)get the users money
> 2)if they have enough create the Thing and put it in the datastore
> 3)update the users money and reference the Thing to the user somehow
> and re-store
>
> If any of this fails i need it all to roll back.
>
> Currently im creating the Thing regardles and performing a transaction
> on the User, if this fails i delete the Thing after. This makes me
> uneasy :)
>
> any suggestions would be most welcome.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: datastore transaction question

2008-10-09 Thread Bill

If there aren't a huge number of Things for each User, then your
approach sounds workable.  A User would have a ListProperty of keys to
Things.  Your transaction on the User would add the key to a
previously created (before the txn) Thing and adjust the money
property.  You could garbage collect unreferenced Things at a later
time.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---