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

refactor: use loop for transactions #875

Merged
merged 5 commits into from Jan 14, 2020
Merged

Conversation

schmidt-sebastian
Copy link
Contributor

Our transaction retry is going to get more complicated (since we have to manually RETRY on aborted), so I thought it would be a good exercise to simplify the transaction runner.

This PR:

I was hoping there would be no behavior changes, but since we are now using an async function, the try block around updateFunction() now catches the "No read after write" error, which means that we will now rollback these transactions (which are empty).

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jan 13, 2020
Copy link
Contributor

@mikelehen mikelehen left a comment

Choose a reason for hiding this comment

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

Not super familiar with the server transaction code, but I think this LGTM except I'm not sure requestTag is plumbed through right?

@@ -61,28 +62,17 @@ const READ_AFTER_WRITE_ERROR_MSG =
export class Transaction {
private _firestore: Firestore;
private _writeBatch: WriteBatch;
private _requestTag: string;
private _requestTag?: string;
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 not immediately obvious to me why this can't be passed into the constructor?

And, er, on that note, I can't figure out where this is ever assigned now? Seems like it'll always be undefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should have been assigned in runTransaction(). This does lead to a bunch of ? and ! in the code though, so I happily moved it back to the constructor.

@codecov
Copy link

codecov bot commented Jan 14, 2020

Codecov Report

Merging #875 into master will increase coverage by 1.71%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #875      +/-   ##
=========================================
+ Coverage   94.89%   96.6%   +1.71%     
=========================================
  Files          25      25              
  Lines       15194   15544     +350     
  Branches     1136    1151      +15     
=========================================
+ Hits        14418   15016     +598     
+ Misses        767     519     -248     
  Partials        9       9
Impacted Files Coverage Δ
dev/src/types.ts 100% <100%> (+100%) ⬆️
dev/src/logger.ts 100% <100%> (ø) ⬆️
dev/src/document.ts 98.67% <100%> (-0.01%) ⬇️
dev/src/write-batch.ts 99.57% <100%> (ø) ⬆️
dev/src/serializer.ts 95.32% <100%> (+0.33%) ⬆️
dev/src/index.ts 98.44% <100%> (+0.01%) ⬆️
dev/src/document-change.ts 100% <100%> (ø) ⬆️
dev/src/watch.ts 98.26% <100%> (+0.04%) ⬆️
dev/src/reference.ts 98.91% <100%> (-0.16%) ⬇️
dev/src/transaction.ts 96.75% <100%> (-0.03%) ⬇️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4e9cba8...1e553c1. Read the comment docs.

@schmidt-sebastian
Copy link
Contributor Author

@thebrianchen Since this is pretty fragile code, do you mind looking at this as well?

@@ -356,6 +356,25 @@ describe('batch support', () => {
return promise;
});

it('cannot reset a committed batch', async () => {

Choose a reason for hiding this comment

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

s/cannot/can

Copy link

@thebrianchen thebrianchen left a comment

Choose a reason for hiding this comment

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

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants