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

Fix docs unnecessarily undergo limbo resolution while resuming query bug #7740

Merged
merged 10 commits into from
Nov 22, 2023

Conversation

milaGGL
Copy link
Contributor

@milaGGL milaGGL commented Oct 31, 2023

While resuming a query and there is an existence filter mismatch detected, SDK updated the limbo docs without waiting for a full re-query result.

  • Add a new flag to check if we should send docs to limbo
  • Add missing .watchCurrent for some spec tests
  • add a new spec test dedicated for this bug
  • renamed updateLimboDocuments in applyChanges to limboResolutionEnabled for better semantic meaning

Ported to android in firebase/firebase-android-sdk#5506 and ios in firebase/firebase-ios-sdk#12044.

@milaGGL milaGGL requested review from a team as code owners October 31, 2023 19:49
Copy link

changeset-bot bot commented Oct 31, 2023

🦋 Changeset detected

Latest commit: 2df6a61

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@firebase/firestore Patch
firebase Patch
@firebase/firestore-compat Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@milaGGL milaGGL self-assigned this Oct 31, 2023
@milaGGL milaGGL requested a review from dconeybe October 31, 2023 20:04
@google-oss-bot
Copy link
Contributor

google-oss-bot commented Oct 31, 2023

Size Report 1

Affected Products

  • @firebase/firestore

    TypeBase (00235ba)Merge (a927106)Diff
    browser374 kB374 kB+71 B (+0.0%)
    esm5359 kB360 kB+73 B (+0.0%)
    main576 kB576 kB+298 B (+0.1%)
    module374 kB374 kB+71 B (+0.0%)
    react-native374 kB374 kB+71 B (+0.0%)
  • bundle

    TypeBase (00235ba)Merge (a927106)Diff
    firestore (Persistence)302 kB302 kB+71 B (+0.0%)
    firestore (Query Cursors)238 kB238 kB+71 B (+0.0%)
    firestore (Query)236 kB236 kB+71 B (+0.0%)
    firestore (Read data once)224 kB224 kB+71 B (+0.0%)
    firestore (Realtime updates)226 kB226 kB+71 B (+0.0%)
  • firebase

    TypeBase (00235ba)Merge (a927106)Diff
    firebase-compat.js778 kB778 kB+71 B (+0.0%)
    firebase-firestore-compat.js340 kB340 kB+71 B (+0.0%)
    firebase-firestore.js434 kB434 kB+71 B (+0.0%)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/mlXAogmDtv.html

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Oct 31, 2023

Size Analysis Report 1

Affected Products

  • @firebase/firestore

    • enableMultiTabIndexedDbPersistence

      Size

      TypeBase (00235ba)Merge (a927106)Diff
      size221 kB221 kB+71 B (+0.0%)
      size-with-ext-deps293 kB293 kB+71 B (+0.0%)
    • getDoc

      Size

      TypeBase (00235ba)Merge (a927106)Diff
      size143 kB143 kB+71 B (+0.0%)
      size-with-ext-deps213 kB213 kB+71 B (+0.0%)
    • getDocFromServer

      Size

      TypeBase (00235ba)Merge (a927106)Diff
      size143 kB143 kB+71 B (+0.0%)
      size-with-ext-deps213 kB213 kB+71 B (+0.0%)
    • getDocs

      Size

      TypeBase (00235ba)Merge (a927106)Diff
      size145 kB145 kB+71 B (+0.0%)
      size-with-ext-deps215 kB215 kB+71 B (+0.0%)
    • getDocsFromCache

      Size

      TypeBase (00235ba)Merge (a927106)Diff
      size102 kB102 kB+23 B (+0.0%)
      size-with-ext-deps172 kB172 kB+23 B (+0.0%)
    • getDocsFromServer

      Size

      TypeBase (00235ba)Merge (a927106)Diff
      size144 kB145 kB+71 B (+0.0%)
      size-with-ext-deps215 kB215 kB+71 B (+0.0%)
    • onSnapshot

      Size

      TypeBase (00235ba)Merge (a927106)Diff
      size145 kB145 kB+71 B (+0.0%)
      size-with-ext-deps216 kB216 kB+71 B (+0.0%)
    • onSnapshotsInSync

      Size

      TypeBase (00235ba)Merge (a927106)Diff
      size135 kB135 kB+71 B (+0.1%)
      size-with-ext-deps205 kB205 kB+71 B (+0.0%)
    • persistentMultipleTabManager

      Size

      TypeBase (00235ba)Merge (a927106)Diff
      size218 kB218 kB+71 B (+0.0%)
      size-with-ext-deps290 kB290 kB+71 B (+0.0%)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/VLld896AKJ.html

Copy link
Contributor

@ehsannas ehsannas left a comment

Choose a reason for hiding this comment

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

looks good. I think it'd be better to add spec tests rather than modify the existing one. because the old test and the new exercise different series of events

@milaGGL
Copy link
Contributor Author

milaGGL commented Nov 6, 2023

looks good. I think it'd be better to add spec tests rather than modify the existing one. because the old test and the new exercise different series of events

Correct me if I am wrong @dconeybe. The existing one is missing a ".watchCurrent" when resuming a query, adding it on corrects the behaviour, which by the way checks the bug fix.

I will add a new spec test dedicated for this bug fix.

@dconeybe
Copy link
Contributor

dconeybe commented Nov 8, 2023

Correct me if I am wrong @dconeybe. The existing one is missing a ".watchCurrent" when resuming a query, adding it on corrects the behaviour, which by the way checks the bug fix.

I agree with @milaGGL. The fact that the spec tests were missing the watchCurrents() call actually made them invalid. This went unnoticed until this bug fix, which caused the test to fail, uncovering their invalidity. So the tests needed to be "fixed" to properly emulate Watch's behavior. I mean, the tests were, technically, still "valid", but the expected result was incorrect. So this PR needs to change to either (a) more accurately emulate Watch's behavior or (b) update the expected result to correctly represent what the client should do if such a sequence of messages from Watch were to ever be received. I think option A has the most value in this case.

Copy link
Contributor

@dconeybe dconeybe left a comment

Choose a reason for hiding this comment

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

Thanks for the fix! Nice job finding the root cause and an elegant solution. Technically, it all LGTM. My comments are merely nitpicks about style and some minor tweaks to improve readability.

packages/firestore/src/core/sync_engine_impl.ts Outdated Show resolved Hide resolved
packages/firestore/src/core/view.ts Outdated Show resolved Hide resolved
packages/firestore/src/core/view.ts Outdated Show resolved Hide resolved
packages/firestore/src/core/view.ts Outdated Show resolved Hide resolved
packages/firestore/src/core/view.ts Outdated Show resolved Hide resolved
packages/firestore/src/core/view.ts Outdated Show resolved Hide resolved
packages/firestore/test/unit/specs/limbo_spec.test.ts Outdated Show resolved Hide resolved
packages/firestore/test/unit/specs/limbo_spec.test.ts Outdated Show resolved Hide resolved
packages/firestore/test/unit/specs/limbo_spec.test.ts Outdated Show resolved Hide resolved
@dconeybe dconeybe assigned milaGGL and unassigned dconeybe Nov 8, 2023
@milaGGL milaGGL assigned dconeybe and unassigned milaGGL Nov 13, 2023
Copy link
Contributor

@dconeybe dconeybe left a comment

Choose a reason for hiding this comment

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

Looks great! Please add a changeset so there will be a release notes entry for this fix. Make sure to word it in such a way that a customer who is unfamiliar with implementation details like "limbo resolution" will have some idea of what was fixed.

@dconeybe dconeybe removed their assignment Nov 16, 2023
@milaGGL milaGGL requested a review from a team as a code owner November 20, 2023 16:12
milaGGL added a commit to firebase/firebase-android-sdk that referenced this pull request Nov 21, 2023
@milaGGL milaGGL merged commit 0d29adc into master Nov 22, 2023
40 of 41 checks passed
@milaGGL milaGGL deleted the mila/fix-limbo-resolution-bug branch November 22, 2023 00:24
@google-oss-bot google-oss-bot mentioned this pull request Nov 22, 2023
@firebase firebase locked and limited conversation to collaborators Dec 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants