0

I'm trying to wrap my head around eventuality consistency and 1 write per sec principles in GAE datastore. I have a scenario and two questions:

#python like pseudo-code
class User:
   user_id = StringProperty
   last_update_time = DateTimeProperty

class Comment:    
   user_id = StringProperty
   comment = StringProperty

...
def AddCommentAndReturnAllComments(user_id):
    user = db.GqlQuery("SELECT * FROM User where user_id = :1", user_id)

    user.last_update_time = datetime.now()
    user.put()

    comment = Comment(parent=User(user_id))
    comment.put()

    comments = db.GqlQuery("SELECT * FROM Comment where user_id = :1", user_id)   
    return comments

Questions:

  1. Will I get an exception here because I make two writes into the same EntityGroup within one second (user.put and comment.put)? Is there a simple way around it?
  2. If I remove the parent=user(user_id), the two entities will no longer belong to the same EntityGroup. Does it mean that the list of comments returned from the function might not contain the last added comment?
  3. Am I doing something inherently wrong?

I know that I got the entity referencing part wrong. It doesn't matter for the question (or does it?)

Alon Catz
  • 2,417
  • 1
  • 19
  • 23
  • The comments query should have the ancestor key on it: https://developers.google.com/appengine/docs/python/datastore/gqlreference – Brian Michelich May 04 '13 at 15:47

1 Answers1

1
  1. This seems to be a soft limit. In practice I see up to 5 writes/s allowed.

  2. Yes and it also happens now, because you are not using ancestor query.

  3. Nothing, except as mentioned in point 2.

Peter Knego
  • 79,991
  • 11
  • 123
  • 154
  • Thanks. Will I get an exception if I just make user.put(); user.put()? Two puts one after the over of the same entity? – Alon Catz May 04 '13 at 16:30