Skip to content

Add onCommitted listeners for transactions #2265

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
Oct 11, 2019

Conversation

schmidt-sebastian
Copy link
Contributor

This should simply some of the idempotent development by allowing any PersistenceTransaction consumer to register onCommitted listeners.

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.

It would be nice to see a tests that showed:

  • When a transaction fails, the action isn't taken
  • When a transaction retries, the action is taken only once, afterward

I think that's how this is going to work based on just reading this but writing tests has a funny habit of showing me that code I thought was obviously correct is actually subtly broken.

abstract readonly currentSequenceNumber: ListenSequenceNumber;

addOnCommittedListener(listener: () => {}): void {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we require that the committed listeners return void? That way you can't accidentally have a return statement in your callback that you intend for the outer method.

Or would that interfere with using short arrow functions in the callback?

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 just realized this when I started to modify my "applyRemoteEvent" PR. It is much better if we return void.

@@ -180,6 +180,7 @@ export class MemoryPersistence implements Persistence {
this.referenceDelegate.onTransactionStarted();
return transactionOperation(txn)
.next(result => {
txn.raiseOnCommittedEvent();
Copy link
Contributor

Choose a reason for hiding this comment

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

This ordering seems off. Couldn't the reference delegate conceivably modify the transaction?

IndexedDbPersistence has the better implementation. Chaining this off the promise makes it clearer that it's altogether outside the transaction.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed this to invoke the committed handler as the last step.

@wilhuff wilhuff assigned schmidt-sebastian and unassigned wilhuff Oct 11, 2019
@schmidt-sebastian
Copy link
Contributor Author

Tests added. Whee.

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

@wilhuff wilhuff assigned schmidt-sebastian and unassigned wilhuff Oct 11, 2019
++commitCount;
});

++runCount;
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional: you might also consider expecting that commitCount is zero during the transaction run.

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

@schmidt-sebastian schmidt-sebastian merged commit 0465d2f into mrschmidt/idempotent Oct 11, 2019
@hsubox76 hsubox76 modified the milestone: next Oct 14, 2019
hsubox76 pushed a commit that referenced this pull request Oct 15, 2019
* Add transaction retries (#2250)

* Marking SimpleDb calls as idempotent (#2251)

* Mark mostly readonly calls as idempotent (#2252)

* Fix test failure (#2256)

* Make handleUserChange idempotent (#2257)

* Temporarily disable CountingQueryEngine tests (#2258)

*  Improve test hack (#2259)

* Improve test hack

* Comment in test hack

* Make getNewDocumentChanges() idempotent (#2255)

* Add onCommitted listeners for transactions (#2265)

* Fix build

* Fix Lint

* Make applyRemoteEvent idempotent (#2263)

* Make notifyLocalViewChanges idempotent (#2268)

* Make releaseQuery idempotent (#2266)

* Mark acknowledgeBatch and rejectBatch idempotent (#2269)

* idempotent `allocateQuery` and `notifyLocalViewChanges` (#2264)

* Mark collectGarbage idempotent (#2267)

* Idempotency: Address TODOs, add Changelog (#2270)
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/listener branch October 15, 2019 22:24
@firebase firebase locked and limited conversation to collaborators Nov 11, 2019
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