ThePiachu
ThePiachu

Reputation: 9175

GAE Golang - queries not returning data right after it is saved

I am writing a Google App Engine Go application and I'm having problem in testing some functionality. Here is some sample code. The problem is as follows:

  1. I create a new item and save it to datastore
  2. I make a search query for that item immediately after (for example, getting all items in the namespace)
  3. The item is not there

If I query for the item later (say, in subsequent pages), the item is found normally. I understand this behaviour might be intentional for apps deployed on GAE, but I would expect the local datastore to be instantly good for queries.

Is there any way I can force the datastore to consolidate and be good for such queries?

Upvotes: 0

Views: 102

Answers (1)

Andrei Volgin
Andrei Volgin

Reputation: 41089

This is called eventual consistency, and it's a feature of App Engine's Datastore.

You can use a get method instead of a query to test if an entity has been saved.

In Java we can set the desired behavior of a local datastore by changing a run parameter:

By default, the local datastore is configured to simulate the consistency model of the High Replication Datastore, with the percentage of datastore writes that are not immediately visible in global queries set to 10%.

To adjust this level of consistency, set the datastore.default_high_rep_job_policy_unapplied_job_pct system property with a value corresponding to the amount of eventual consistency you want your application to see.

I could not find something similar for Go.

Upvotes: 3

Related Questions