Skip to content

Fix latency-compensated query missing patch mutations. #621

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
4 commits merged into from
Jul 16, 2019

Conversation

ghost
Copy link

@ghost ghost commented Jul 15, 2019

No description provided.

@googlebot googlebot added the cla: yes Override cla label Jul 15, 2019
@ghost ghost added the api: firestore label Jul 15, 2019
@ghost ghost requested a review from var-const July 15, 2019 20:36
@ghost ghost assigned var-const Jul 15, 2019
@@ -182,6 +184,14 @@ private MaybeDocument getDocument(DocumentKey key, List<MutationBatch> inBatches
remoteDocumentCache.getAllDocumentsMatchingQuery(query);

List<MutationBatch> matchingBatches = mutationQueue.getAllMutationBatchesAffectingQuery(query);
// It is possible that a PatchMutation can make a document match a query, even if
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a useful comment but it interrupts the flow of this otherwise large method. Consider moving this to be a doc comment on your new method (which doesn't otherwise have comments).

Copy link
Author

Choose a reason for hiding this comment

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

Done.

@@ -210,4 +215,33 @@ private MaybeDocument getDocument(DocumentKey key, List<MutationBatch> inBatches

return results;
}

/**
* It is possible that a PatchMutation can make a document match a query, even if the version in
Copy link
Contributor

Choose a reason for hiding this comment

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

Ultranit: some class/function names are backtick-escaped, and some aren't. Consider doing backticks for consistency (PatchMutation).

Copy link
Contributor

Choose a reason for hiding this comment

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

Please don't backtick in javadoc. There's no markdown support. Use <code>/</code>.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks. Looking at other comments in the file, they use {@code foo}.

Copy link
Author

Choose a reason for hiding this comment

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

Done.


/**
* It is possible that a PatchMutation can make a document match a query, even if the version in
* the RemoteDocumentCache is not a match yet (waiting for server to ack). To handle this, we find
Copy link
Contributor

Choose a reason for hiding this comment

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

Ultranit: backtick RemoteDocumentCache.

Copy link
Author

Choose a reason for hiding this comment

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

Done.

/**
* It is possible that a PatchMutation can make a document match a query, even if the version in
* the RemoteDocumentCache is not a match yet (waiting for server to ack). To handle this, we find
* all document keys affected by the PatchMutations that are not in `result` yet, and back fill
Copy link
Contributor

Choose a reason for hiding this comment

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

Ultranit: backtick PatchMutation.

Copy link
Author

Choose a reason for hiding this comment

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

Done.

* the RemoteDocumentCache is not a match yet (waiting for server to ack). To handle this, we find
* all document keys affected by the PatchMutations that are not in `result` yet, and back fill
* them via `remoteDocumentCache.getAll`, otherwise those `PatchMutations` will be ignored because
* no base document can be found, and lead to missing result for the query.
Copy link
Contributor

Choose a reason for hiding this comment

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

Ultranit: s/result/results

Copy link
Author

Choose a reason for hiding this comment

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

Done.

*/
private ImmutableSortedMap<DocumentKey, Document> addMissingBaseDocuments(
List<MutationBatch> matchingBatches, ImmutableSortedMap<DocumentKey, Document> existingDocs) {
HashSet<DocumentKey> missedDocKeys = new HashSet<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional: s/missedDocKeys/missingDocKeys.

Copy link
Author

Choose a reason for hiding this comment

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

Done.

}

ImmutableSortedMap<DocumentKey, Document> mergedDocs = existingDocs;
Map<DocumentKey, MaybeDocument> missedDoc = remoteDocumentCache.getAll(missedDocKeys);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: s/missedDoc/missingDocs

Copy link
Author

Choose a reason for hiding this comment

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

Done.

@var-const var-const assigned ghost and unassigned var-const Jul 15, 2019
}

ImmutableSortedMap<DocumentKey, Document> mergedDocs = existingDocs;
Map<DocumentKey, MaybeDocument> missingDoc = remoteDocumentCache.getAll(missingDocKeys);
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry to nitpick, but it should be missingDocs.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed. Thank you!

@ghost ghost merged commit d50472a into master Jul 16, 2019
@rlazo rlazo deleted the wuandy/FixLatencyCompPatchQuery branch September 27, 2019 14:54
@firebase firebase locked and limited conversation to collaborators Oct 9, 2019
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants