Neverland
Neverland

Reputation: 775

Is it possible to force strong consistency of the GAE datastore?

Is it possible to force strong consistency of the GAE datastore?

I have this code:

#!/usr/bin/env python
Import OS, says
import wsgiref.handlers
import webapp2
from google.appengine.ext import db
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp import template

class guestbook(db.Model):
  message = db.StringProperty(required=True)
  when = db.DateTimeProperty(auto_now_add=True)
  who = db.StringProperty()

class ShowGuestbookPage(webapp2.RequestHandler):
  def get(self):
    # Read from the Datastore
    shouts = db.GqlQuery('SELECT * FROM guestbook ORDER BY when DESC')
    values = {'shouts': shouts}
    self.response.out.write(template.render('main.html', values))

class MakeGuestbookEntry(webapp2.RequestHandler):
  def post(self):
    shout = guestbook(message=self.request.get('message'), who=self.request.get('who'))
    # Write into the datastore
    shout.put()
    self.redirect('/')

app = webapp2.WSGIApplication([('/', ShowGuestbookPage),
                               ('/make_entry', MakeGuestbookEntry),
                               debug=True)

def main():
  run_wsgi_app(app)

if __name__ == "__main__":
  main()

What is the most easy way to strong consistency?

I do not understand how to translate the explanations [1] from Google into the source code.

[1] https://developers.google.com/appengine/docs/java/datastore/structuring_for_strong_consistency

Thanks for any help.

Upvotes: 2

Views: 1084

Answers (3)

Zig Mandel
Zig Mandel

Reputation: 19835

Yes you can by using entity groups. Read about its advantages and dissadvantages in the docs.

you can also define your own entity ids and get them "by id" which is always guaranteed consistent.

Upvotes: 2

user1911091
user1911091

Reputation: 1373

To enforce strong consistency two conditions have to apply:

  1. The db.Model Entity has to have a ancestor relationship
  2. AND your query has to filter by ancestor

Then all children will be queried using strong consistency.

A good explanation can be foud here

Upvotes: 1

Peter Knego
Peter Knego

Reputation: 80330

Get, put and delete operations are always strongly consistent. Ancestor queries are also strongly consistent.

The rest of the queries are NOT strongly consistent and there is not special config parameter to make them strongly consistent.

Upvotes: 1

Related Questions