Skip to content
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

Dequeue limbo resolutions when their respective queries are stopped #2404

Merged
merged 7 commits into from
Feb 5, 2021

Conversation

dconeybe
Copy link
Contributor

@dconeybe dconeybe commented Feb 3, 2021

Fix a bug where enqueued limbo resolutions are left in the queue even after all targets that care about their resolutions are stopped. This erroneous behavior was reported in #2311 against the Android SDK, but the bug is also present in the Web and iOS SDKs. This PR is a port of the equivalent fix in the Web SDK: firebase/firebase-js-sdk#4395. This bug was introduced when limbo resolution throttling was implemented almost a year ago (firebase/firebase-js-sdk#2790).

@google-cla google-cla bot added the cla: yes Override cla label Feb 3, 2021
@google-oss-bot
Copy link
Contributor

google-oss-bot commented Feb 3, 2021

Coverage Report

Affected SDKs

  • firebase-firestore

    SDK overall coverage changed from 48.63% (be59902) to 48.63% (1bb4d403) by +0.00%.

    Filename Base (be59902) Head (1bb4d403) Diff
    AsyncQueue.java 77.89% 76.88% -1.01%
    RemoteSerializer.java 83.96% 84.20% +0.24%
    SyncEngine.java 93.49% 93.55% +0.06%

Test Logs

Notes

HTML coverage reports can be produced locally with ./gradlew <product>:checkCoverage.
Report files are located at <product-build-dir>/reports/jacoco/.

Head commit (1bb4d403) is created by Prow via merging commits: be59902 b428adc.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Feb 3, 2021

Binary Size Report

Affected SDKs

  • firebase-firestore

    Type Base (be59902) Head (1bb4d403) Diff
    aar 1.10 MB 1.10 MB +47 B (+0.0%)
    apk (release) 3.19 MB 3.19 MB +152 B (+0.0%)

Test Logs

Notes

Head commit (1bb4d403) is created by Prow via merging commits: be59902 b428adc.

@@ -4,6 +4,9 @@
Bundles contain pre-packaged data produced with the NodeJS Server SDK and
can be used to populate Firestore's cache without reading documents from
the backend.
- [fixed] Fix a Firestore bug where local cache inconsistencies were
unnecessarily being resolved, resulting in the incompletion of `Task` objects
Copy link
Contributor

Choose a reason for hiding this comment

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

s/incompletion/something that is easier to parse

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment on lines 24 to 25
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
Copy link
Contributor

Choose a reason for hiding this comment

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

One of our goals is to eventually kick out Guava from our dependencies. Can you find another solution?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

public Queue<DocumentKey> getEnqueuedLimboDocumentResolutions() {
// Make a defensive copy as the Queue continues to be modified.
return new ArrayDeque<>(enqueuedLimboResolutions);
public LinkedHashSet<DocumentKey> getEnqueuedLimboDocumentResolutions() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Super nit (here and above): We usually try to use more generic types in our return types, as this allows us to change the implementation without changing the callsites. If the callsites don't require the HashMap or LinkedHashSet functionality, I would just use Map<> and Set<>.

Please note that this might not apply if getEnqueuedLimboDocumentResolutions() only uses the Set API but its consumers rely on the iteration order of a LinkedHashSet. Then I would still return LinkedHashSet as we will not be able to replace it later. You should still generify the signature in line 713 though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -694,7 +694,9 @@ private void trackLimboChange(LimboDocumentChange change) {
private void pumpEnqueuedLimboResolutions() {
while (!enqueuedLimboResolutions.isEmpty()
&& activeLimboTargetsByKey.size() < maxConcurrentLimboResolutions) {
DocumentKey key = enqueuedLimboResolutions.remove();
Iterator<DocumentKey> it = enqueuedLimboResolutions.iterator();
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like you need to import Iterator.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

…some return types to more general types (e.g. LinkedHashSet -> List).
@dconeybe dconeybe merged commit c9fefbe into master Feb 5, 2021
@dconeybe dconeybe deleted the dconeybe/LimboRemoveFromQueueFix branch February 5, 2021 16:59
@firebase firebase locked and limited conversation to collaborators Mar 8, 2021
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.

3 participants