Skip to content

force query results to become strongly consistent#1806

Merged
neozwu merged 4 commits intogoogleapis:masterfrom
neozwu:force-strong-consistency
Apr 17, 2017
Merged

force query results to become strongly consistent#1806
neozwu merged 4 commits intogoogleapis:masterfrom
neozwu:force-strong-consistency

Conversation

@neozwu
Copy link
Copy Markdown
Contributor

@neozwu neozwu commented Mar 23, 2017

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.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Mar 23, 2017
@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 80.823% when pulling 6eef80c on neozwu:force-strong-consistency into afdb204 on GoogleCloudPlatform:master.

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 80.823% when pulling ca1cd42 on neozwu:force-strong-consistency into afdb204 on GoogleCloudPlatform:master.

@garrettjonesgoogle garrettjonesgoogle requested review from vam-google and removed request for shinfan March 25, 2017 00:25
@garrettjonesgoogle
Copy link
Copy Markdown
Contributor

@vam-google could you do a first pass on this PR?

@neozwu
Copy link
Copy Markdown
Contributor Author

neozwu commented Mar 28, 2017

kindly ping @vam-google

continue infiniteloop;
}
}
return resultsCopy.iterator();

This comment was marked as spam.

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.

return results;
}

private <T, S> boolean haveSameSize(Iterator<T> it1, Iterator<S> it2) {

This comment was marked as spam.

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.

Set<T> scResultsSet = new HashSet<>(scResultsCopy);

infiniteloop:
while(true) {

This comment was marked as spam.

This comment was marked as spam.

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.

@neozwu
Copy link
Copy Markdown
Contributor Author

neozwu commented Mar 31, 2017

@vam-google PTAL

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.003%) to 80.82% when pulling b8e8b6d on neozwu:force-strong-consistency into afdb204 on GoogleCloudPlatform:master.

Copy link
Copy Markdown
Contributor

@vam-google vam-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM


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.

@neozwu neozwu merged commit f023d07 into googleapis:master Apr 17, 2017
chingor13 pushed a commit that referenced this pull request Feb 24, 2026
suztomo pushed a commit to suztomo/google-cloud-java that referenced this pull request Mar 11, 2026
chingor13 pushed a commit that referenced this pull request Mar 12, 2026
suztomo pushed a commit to suztomo/google-cloud-java that referenced this pull request Mar 23, 2026
meltsufin pushed a commit that referenced this pull request Apr 29, 2026
meltsufin pushed a commit that referenced this pull request May 1, 2026
meltsufin pushed a commit that referenced this pull request May 2, 2026
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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants