shieldstroy
shieldstroy

Reputation: 1327

Force strong consistency with objectify on GAE using ancestors

As I understand it, objects queried with objectify that have an ancestor should be queried with strong consistency, meaning I should always get the most up-to-date object right?

This does not seem to be the case.

Here is an example of pulling data from the datastore:

  Key<Rule> k = Key.create(Key.create(NinjaAccount.class, accountId), Rule.class, ruleId);
  return ofy().consistency(Consistency.STRONG).load().key(k).now();

Or a query for multiple entities:

return ofy().consistency(Consistency.STRONG).load().type(Rule.class).ancestor(Key.create(NinjaAccount.class, accountId))
    .list();

However, when I update one of the fields on a Rule object I can run this code several times in a row and have it flip back and forth between the new value and the old value. What am I doing wrong?? I'm almost ready to just switch to mysql, but I am hoping there is something small that I am misunderstanding.

Upvotes: 4

Views: 598

Answers (1)

stickfigure
stickfigure

Reputation: 13556

There is nothing wrong with the code you have posted. Also, the consistency(Consistency.STRONG) calls are unnecessary; by default get-by-key and ancestor queries are strongly consistent.

The problem is not eventual consistency.

Are you using an old version of Objectify and have you neglected to install the ObjectifyFilter? Historically, this is the most likely issue (it's in the FAQ). However, very recent versions of Objectify will throw an exception if you have not installed the filter, so if you're current, it's something else.

Upvotes: 2

Related Questions