Hi Usul,

First of all and to be clear: the only way to 100% ensure strong
consistency is to make strong consistency queries.

If your user entity has a parent relationship with userList, the way to
achieve what you want is:

 * first transaction starts
 * first transaction looks for already existing user with name for user
list X -> no such user
 * second transaction starts -> As we have a transaction started in the
same entity group, this transaction is queued
 * first transaction creates new user
 * second transaction looks for already existing user with name  for user
list X -> already exists

* Transactions on a given entity group are executed serially, one after
another.*

As you are making strong consistency queries, using the parent user list,
you can be confident that a user is never created twice.

Cheers!!







Alejandro González Rodrigo
*www.nextinit.com* <https://www.nextinit.com/>
*[email protected] <[email protected]>*
*+34  666 57 79 13*


2014-04-28 9:01 GMT+02:00 Pertti Kellomäki <[email protected]>:

> Hi Usul,
>
> On Sun, Apr 27, 2014 at 8:24 PM, Usul <[email protected]> wrote:
>
>> Hi,
>>
>> I am new to nosql and eventual consistency. What is the recommended way
>> of ensuring, that an entity is not created, if it already exists?
>>
>> For example: A new user should only be created, if the name (=primary id)
>> does not exist yet. So if two people create a new user with the same name
>> at the same time, one of them should get an error message. Since there is
>> no single database, how is it done with google app engine?
>>
>> I do not need code, I only need to know how it is supposed to be done
>> with eventual consistancy. I already read about "Structuring Data for
>> Strong Consistency".
>>
>
> I can give you code ;-) There is an example in the Python documentation
> doing what you describe:
>
>
> https://developers.google.com/appengine/docs/python/datastore/transactions#Python_Uses_for_transactions
>
> The documentation also mentions a convenience method Model.get_or_insert()
> which I had missed the first time around, so thanks for asking this
> question.
>
> I don't know about Java on appengine, but I would expect something similar
> to exist there.
> --
> Pertti Kellomäki, Kesanto Enterprises
> Your training in the cloud: <http://www.trainingcommons.com>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/google-appengine.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-appengine.
For more options, visit https://groups.google.com/d/optout.

Reply via email to