Skip to content

Add test for getHighestListenSequenceNumber() recovery #3083

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
merged 5 commits into from
May 21, 2020

Conversation

schmidt-sebastian
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian commented May 18, 2020

This adds a test that verify that we can bubble up the exception from getHighestListenSequenceNumber to enablePersistence(). The client can then proceed with MemoryPersistence:

Addresses #2755

@google-oss-bot
Copy link
Contributor

google-oss-bot commented May 18, 2020

Binary Size Report

Affected SDKs

  • @firebase/firestore

    Type Base (9d87d70) Head (5644dad) Diff
    browser 251 kB 251 kB +24 B (+0.0%)
    esm2017 195 kB 195 kB +27 B (+0.0%)
    main 493 kB 493 kB -66 B (-0.0%)
    module 249 kB 249 kB +24 B (+0.0%)
  • firebase

    Type Base (9d87d70) Head (5644dad) Diff
    firebase-firestore.js 290 kB 290 kB +35 B (+0.0%)
    firebase.js 823 kB 823 kB +35 B (+0.0%)

Test Logs

@schmidt-sebastian schmidt-sebastian force-pushed the mrschmidt/failenablepersistence branch from 3efc875 to 12ff025 Compare May 19, 2020 01:04
@schmidt-sebastian schmidt-sebastian changed the title Fail enablePersistence() if getHighestListenSequenceNumber fails Add test for getHighestListenSequenceNumber() recovery May 19, 2020
[DbTargetGlobal.store],
txn => getHighestListenSequenceNumber(txn)
txn =>
getHighestListenSequenceNumber(
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a getHighestSequenceNumber that does this translation for you, though I'm really dubious that we should really have names that differ in this way for the difference in transaction types.

It seems like there's a change warranted where we minimize the use of SimpleDbTransaction?

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 original version of this PR changed getHighestListenSequenceNumber to take an IndedexDbTransaction. I had to duplicate a couple lines of code in the SimpleDb schema conversion to make this work, since the schema conversion needs the highest sequence number but doesn't use IndedexDbTransactions.

The other callsite that does this conversion is part the TargetCache, which hasn't been started at this point.

I have no preference either way. The cleanest solution was probably the one that changed all sites to use IndedexDbTransaction and added three lines of duplicate code to the schema conversion.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's a shame that we're ending up with two different transaction mechanisms and that migrations need to be written differently than the rest of the code. Is that the end state?

Is your intent to make everything mostly use IndedexDbTransaction except for the few places that can't? If so I'm not as concerned about the individual steps along the way.

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 cleaned this up a little, and hope it is an improvement.

  • I inlined two of the helper methods and changed them to only use IndedexDbTransactions/PersitenceTransactions.
  • I changed the called in IndexedDbPersistence to use the method from the TargetCache. The TargetCache doesn't have a start(), so there is actually no issue here.
  • The SimpleDbSchema class now has a couple lines of code duplication.

const writeSentinelKey = (
path: ResourcePath
): PersistencePromise<void> => {
return documentTargetStore.put(
new DbTargetDocument(
0,
encodeResourcePath(path),
currentSequenceNumber
metadata!.highestListenSequenceNumber!
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We set the metadata earlier in the migration. It should exist at this point.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wary of this style of commenting (review-only). The reviewer of this PR isn't the only one who's ever going to read this code.

Don't get me wrong--there's definitely a place for this kind of thing, but this comment in particular seems reasonable to just make in the code itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a debug assert that contains this message.

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

const writeSentinelKey = (
path: ResourcePath
): PersistencePromise<void> => {
return documentTargetStore.put(
new DbTargetDocument(
0,
encodeResourcePath(path),
currentSequenceNumber
metadata!.highestListenSequenceNumber!
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wary of this style of commenting (review-only). The reviewer of this PR isn't the only one who's ever going to read this code.

Don't get me wrong--there's definitely a place for this kind of thing, but this comment in particular seems reasonable to just make in the code itself.

@wilhuff wilhuff assigned schmidt-sebastian and unassigned wilhuff May 21, 2020
@schmidt-sebastian schmidt-sebastian merged commit babdcfd into master May 21, 2020
@firebase firebase locked and limited conversation to collaborators Jun 21, 2020
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/failenablepersistence branch July 9, 2020 17:44
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