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

fix: bulkWriter: ensure buffered batches are sent after flush #1535

Merged
merged 3 commits into from
Jun 16, 2021

Conversation

thebrianchen
Copy link

Fixes #1531.

flush() currently does not schedule batches that are buffered, which caused the issue above. If the last batch did not meet the maximum batch size, it would not be sent, causing flush() to never resolve.

This PR allows BulkWriter to track when flush() is called while there are buffered operations and ensures that the batch is flushed even if it is not at the maximum batch size. I'm not a huge fan of adding the BufferedOperation, class but I can't seem to find a clean way to do it. Added a unit test that fails without this logic.

@thebrianchen thebrianchen self-assigned this Jun 15, 2021
@thebrianchen thebrianchen requested review from a team as code owners June 15, 2021 22:05
@product-auto-label product-auto-label bot added the api: firestore Issues related to the googleapis/nodejs-firestore API. label Jun 15, 2021
@thebrianchen thebrianchen changed the title Bc/bw buffer fix: bulkWriter: ensure buffered batches are sent after flush Jun 15, 2021
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Jun 15, 2021
*
* @private
*/
class BufferedOperation {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you just enqueue BulkWriterOperation and make send() public?

Copy link
Author

Choose a reason for hiding this comment

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

I tried that approach, but that requires storing enqueueOnBatchCallback onto BulkWriterOperation, which doesn't make sense conceptually.

Copy link
Contributor

@schmidt-sebastian schmidt-sebastian left a comment

Choose a reason for hiding this comment

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

Tried to come up with a better way but failed. See if you can address my comment. If not, this is fine as is. Please remember to cut a release.

@thebrianchen thebrianchen merged commit 115a134 into master Jun 16, 2021
@thebrianchen thebrianchen deleted the bc/bw-buffer branch June 16, 2021 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: firestore Issues related to the googleapis/nodejs-firestore API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BulkWriter.close doesn't resolve when writing more than 500 documents
2 participants