Skip to content

Transition to primary only if IndexedDB ops succeed #3049

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 1 commit into from
May 13, 2020

Conversation

schmidt-sebastian
Copy link
Contributor

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

Goal: Don't change local state before all IndexedDB transactions succeed.

Addresses #2755

@google-oss-bot
Copy link
Contributor

Binary Size Report

Affected SDKs

  • @firebase/firestore

    Type Base (a57dac5) Head (8e331c5) Diff
    browser 249 kB 249 kB +8 B (+0.0%)
    esm2017 194 kB 194 kB +8 B (+0.0%)
    main 490 kB 490 kB +29 B (+0.0%)
    module 247 kB 247 kB +8 B (+0.0%)
  • firebase

    Type Base (a57dac5) Head (8e331c5) Diff
    firebase-firestore.js 288 kB 288 kB +8 B (+0.0%)
    firebase.js 821 kB 821 kB +8 B (+0.0%)

Test Logs

@@ -1032,9 +1032,6 @@ export class MultiTabSyncEngine extends SyncEngine

async applyPrimaryState(isPrimary: boolean): Promise<void> {
if (isPrimary === true && this.isPrimary !== true) {
this.isPrimary = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

I notice that sync_engine.ts uses a mixture of reading from this.isPrimary and this.isPrimaryClient. Shouldn't all reads be consolidated to the latter? If so, we should fix this in a separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this.isPrimaryClient is the getter in the API. this.isPrimary is the underlying member variable. A more common pattern is to use this.isPrimary and this._isPrimary. I will update this is in a follow-up.

Comment on lines +1046 to +1047
this.isPrimary = true;
await this.remoteStore.applyPrimaryState(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

I want to verify something. These lines of code were moved down b/c the bit should only be set if a prior IndexDB operation succeeded correct?

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, exactly.

@schmidt-sebastian schmidt-sebastian merged commit 3960fda into master May 13, 2020
@firebase firebase locked and limited conversation to collaborators Jun 13, 2020
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/applyprimarystate branch November 9, 2020 22:39
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