Reputation: 149
For a test, we start a local instance of the cloud-datastore-emulator with the LocalDatastoreHelper class, provided by Google.
The interesting obersvation, we made was, that we can insert data with our code and then find it again, by performing a GQL query
SELECT [..] WHERE myfield = true
if we do it against a "live" store, hosted at Google Cloud.
But:
When we run the same code against the emulator running locally, the insert works, but the query does not. A findAll() works fine, so it looks like inserting and reading works generally, but somehow the indexes are missing?
After reading the documentation for hours now, I did not find any hint, why this might happen.
Can anybody help?
Upvotes: 0
Views: 1082
Reputation: 149
Just to not confuse people with my original question, I answer myself, as we found the source of our problem.
Unfortunately the difference between live and local was not due to some difference in behavior on the side of the datastore, but was rooted in our code. :-(
As far as I see all our former assumptions about indexes not being generated are false. With that respect, local behaves exactly as live does.
Thank you for contributing!
Upvotes: 1
Reputation: 2207
Most likely what you are running into is - eventual consistency. By default, the Datastore Emulator simulates a consistency of 0.9. Note that most queries are eventually consistent, unless the WHERE clause is a Key or the query is an Ancestor Query. I believe you are just lucky that "live" store is returning the result. If you run the test enough times at different times of the day, it is possible that it may not return the results (it all depends on the timing and the time it takes to update the indexes).
That said, the Datastore Emulator has an option to specify the consistency level it should simulate. This can be done with the following command:
gcloud beta emulators datastore start --data-dir=/my/data/dir --host-port localhost:9999 --consistency 1.0
A consistency level of 1.0 would guarantee consistent reads. I'm not sure if there is an option to set the consistency level with LocalDatastoreHelper.
Again, the "live" Datastore is always eventually consistent for all cases other than the few exceptions I have mentioned above.
Upvotes: 3