1
votes

If I save an entity to the datastore and then right after load the entity by it's key, will the program wait and ensure strong consistency?

thing.setValue(newValue);
ofy().save().entity(thing).now();
Thing updatedThing = ofy().load().key(thingKey).now(); 

Does updatedThing contain the new value?

Is this a good method to ensure strong consistency for a case when I want to update an entity?

1
lookups by key (and ancestor queries) are strongly consistent. [Link: cloud.google.com/datastore/docs/articles/… - DazWilkin

1 Answers

5
votes

Yes, key lookups are always consistent in the datastore. From the table at the beginning of the Eventual Consistency in Cloud Datastore:

[Lookup by key][2] (get())    Strong consistency

But there's a catch - if you do both the write and the read inside the same transaction the read won't see the written info. From Isolation and consistency:

This consistent snapshot view also extends to reads after writes inside transactions. Unlike with most databases, queries and gets inside a Cloud Datastore transaction do not see the results of previous writes inside that transaction. Specifically, if an entity is modified or deleted within a transaction, a query or get returns the original version of the entity as of the beginning of the transaction, or nothing if the entity did not exist then.