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

Make 'handleClientStateEvent()/handleQueryTargetEvent()' idempotent #2916

Merged
merged 3 commits into from
Apr 20, 2020

Conversation

schmidt-sebastian
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian commented Apr 16, 2020

This solves a problem where we were able to modify a in-memory state before the database transaction failed and also addresses issues where targets to allocate already existed or rejected targets were missing.

I believe there are no other issues in the WebStorage callbacks.

Addresses #2755

@schmidt-sebastian schmidt-sebastian changed the title Make 'handleClientStateEvent()' idempotent Make 'handleClientStateEvent()/handleQueryTargetEvent()' idempotent Apr 16, 2020
This solves a problem where we were able to modify a in-memory state before the database transaction failed and also addresses issues where targets to allocate already existed or rejected targets were missing. I beliuve there are no other issues in the WebStorage callbacks
@google-oss-bot
Copy link
Contributor

google-oss-bot commented Apr 16, 2020

Binary Size Report

Affected SDKs

  • @firebase/firestore

    Type Base (77cb183) Head (4ec2f3b) Diff
    browser 253 kB 248 kB -5.43 kB (-2.1%)
    esm2017 200 kB 194 kB -5.34 kB (-2.7%)
    main 487 kB 488 kB +484 B (+0.1%)
    module 251 kB 246 kB -5.40 kB (-2.2%)
  • @firebase/firestore/memory

    Type Base (77cb183) Head (4ec2f3b) Diff
    browser 200 kB 195 kB -4.40 kB (-2.2%)
    esm2017 156 kB 152 kB -4.42 kB (-2.8%)
    main 377 kB 377 kB +37 B (+0.0%)
    module 198 kB 194 kB -4.40 kB (-2.2%)
  • firebase

    Type Base (77cb183) Head (4ec2f3b) Diff
    firebase-firestore.js 295 kB 289 kB -5.40 kB (-1.8%)
    firebase-firestore.memory.js 243 kB 238 kB -4.40 kB (-1.8%)
    firebase.js 828 kB 823 kB -5.41 kB (-0.7%)

Test Logs

// the database.
.recoverDatabase()
.runTimer(TimerId.AsyncQueueRetry)
.expectActiveTargets()
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we expect that there is an active target before recoverDatabase?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The targets are checked at each step, but adding this here explicitly makes it much clearer what is going on. Done.

`Tried to release nonexistent target: ${targetId}`
);

if (targetData === null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

How would this happen in practice that isn't a bug? I mean, how could we get in a state where the sync engine thought we were listening but local store didn't?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was trying to guard against this line: https://github.com/firebase/firebase-js-sdk/blob/master/packages/firestore/src/core/sync_engine.ts#L1115

I did miss that this is only executed if the target is still active. I reverted this change.

@wilhuff wilhuff assigned schmidt-sebastian and unassigned wilhuff Apr 20, 2020
Copy link
Contributor

@wilhuff wilhuff left a comment

Choose a reason for hiding this comment

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

LGTM

// The primary client 0 receives a notification that the query can
// be released, but it can only process the change after we recover
// the database.
.expectActiveTargets({ query})
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: should there be a space between query and }?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. As you may have noticed, the prettier pre-commit hook doesn't work for me at all. I have been working with @hsubox76 to see if this can be fixed, but it seems like the behavior I am seeing is actually the indented behavior. Pre-commit hooks are only meant to push changes that existed prior to running.

@wilhuff wilhuff assigned schmidt-sebastian and unassigned wilhuff Apr 20, 2020
@schmidt-sebastian schmidt-sebastian merged commit 6cfb268 into master Apr 20, 2020
@firebase firebase locked and limited conversation to collaborators May 21, 2020
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/idempotenthandleclientstate branch July 9, 2020 17:45
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.

None yet

3 participants