force query results to become strongly consistent#1806
force query results to become strongly consistent#1806neozwu merged 4 commits intogoogleapis:masterfrom
Conversation
|
@vam-google could you do a first pass on this PR? |
|
kindly ping @vam-google |
| continue infiniteloop; | ||
| } | ||
| } | ||
| return resultsCopy.iterator(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| while(true) { | ||
| QueryResults<T> results = DATASTORE.run(query); | ||
| List<T> resultsCopy = makeResultsCopy(results); | ||
| if (!haveSameSize(scResultsCopy.iterator(), resultsCopy.iterator())) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| return results; | ||
| } | ||
|
|
||
| private <T, S> boolean haveSameSize(Iterator<T> it1, Iterator<S> it2) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| results1 = DATASTORE.run(query1); | ||
| } | ||
| results1 = DATASTORE.run(query1); | ||
| Query<Entity> scQuery1 = Query.newEntityQueryBuilder() |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| Set<T> scResultsSet = new HashSet<>(scResultsCopy); | ||
|
|
||
| infiniteloop: | ||
| while(true) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| private static final Entity ENTITY3 = Entity.newBuilder(ENTITY1).setKey(KEY3).remove("str") | ||
| .set("null", NULL_VALUE).set("partial1", PARTIAL_ENTITY2).set("partial2", ENTITY2).build(); | ||
|
|
||
| private <T> Iterator<T> getStronglyConsistentResults (Query scQuery, Query query) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
@vam-google PTAL |
|
|
||
| private <T> Iterator<T> getStronglyConsistentResults (Query scQuery, Query query) throws InterruptedException { | ||
| //scQuery is equivalent to query, but with an ancestor filter in it | ||
| //This makes scQuery strongly consistent |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This removes the unused image tag in this file. Part of the cleanup after enabling Hermetic Library generation in this repo. Newline at EOF automatically added - see [this SO](https://stackoverflow.com/questions/729692/why-should-text-files-end-with-a-newline).
Outside transactions, global queries of google cloud datastore utilize eventually consistent model - this means query results are not guaranteed to be updated. To facilitate deterministic testing, a helper method is implemented to force strong consistency for global queries. It leverages the fact that any queries with ancestor filter will become strongly consistent queries.