Skip to content

fix: bulkWriter: writing to the same document does not create a new batch#1298

Merged
thebrianchen merged 8 commits intomasterfrom
bc/bulk-no-order
Sep 22, 2020
Merged

fix: bulkWriter: writing to the same document does not create a new batch#1298
thebrianchen merged 8 commits intomasterfrom
bc/bulk-no-order

Conversation

@thebrianchen
Copy link

No description provided.

@thebrianchen thebrianchen requested review from a team as code owners September 16, 2020 15:27
@thebrianchen thebrianchen self-assigned this Sep 16, 2020
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Sep 16, 2020
@codecov
Copy link

codecov bot commented Sep 16, 2020

Codecov Report

Merging #1298 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1298   +/-   ##
=======================================
  Coverage   98.45%   98.46%           
=======================================
  Files          30       30           
  Lines       18675    18648   -27     
  Branches     1442     1435    -7     
=======================================
- Hits        18387    18362   -25     
+ Misses        285      283    -2     
  Partials        3        3           
Impacted Files Coverage Δ
dev/src/bulk-writer.ts 98.90% <100.00%> (+0.22%) ⬆️
dev/src/write-batch.ts 100.00% <100.00%> (ø)

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 b678857...232a349. Read the comment docs.

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.

This is mostly good, though I wonder if we need to fix the "docsToRetry" logic in the WriteBatch constructor?

this.pendingOps.get(result.key)!.reject(result.status);
this.pendingOps.delete(result.key);
for (let i = resolvedOps.length - 1; i >= 0; i--) {
this.pendingOps.splice(resolvedOps[i], 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Aren't these indices off after the first splice? I wonder if we can simply build up the reverse array in the loop above and replace this.pendingOps with it.

Copy link
Author

Choose a reason for hiding this comment

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

Since we're going in reverse order and deleting the last element in the array each time, the remaining indices won't be affected.

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 add a comment?

Copy link
Author

Choose a reason for hiding this comment

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

done.

});

it('sends writes to the same document in separate batches', async () => {
it('sends writes to the same documents in the same batch', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this test still have value over the other tests?

Copy link
Author

Choose a reason for hiding this comment

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

This test would fail if pendingOps got changed back to its original map type since the second write to the same document path would override the existing entry, so it serves to make sure that writes to the same document are added properly.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense. Maybe prefix the test name with "can send"?

Copy link
Author

Choose a reason for hiding this comment

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

done.

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.

Thanks for the updates. Can you find a way to address the comment in the summary response?

@product-auto-label product-auto-label bot added the api: firestore Issues related to the googleapis/nodejs-firestore API. label Sep 17, 2020
@thebrianchen
Copy link
Author

Thanks for the updates. Can you find a way to address the comment in the summary response?

Updated to use an index-based tracking system instead. Also modified the retry test to include retries to the same document path, which would have failed with the previous iteration.

this.pendingOps.delete(result.key);
private processResults(
results: BatchWriteResult[],
failRemainingOperations = false
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian Sep 22, 2020

Choose a reason for hiding this comment

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

I think this should be "allowRetry" or something like that, which also means that you can just merge the corresponding branch with if (!this.shouldRetry(result.status.code)). In the context of this method, failRemainingOperations is not quite self-explanatory.

Copy link
Author

Choose a reason for hiding this comment

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

Done.

// indexes to retry.
this._ops = retryBatch._ops.filter(
v => docsToRetry!.indexOf(v.docPath) !== -1
(op, index) => indexesToRetry!.indexOf(index) !== -1
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a bit confusing to read. Could we make indexesToRetry a Set? Optional.

Copy link
Author

Choose a reason for hiding this comment

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

Good call. Done.

@schmidt-sebastian schmidt-sebastian removed their assignment Sep 22, 2020
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.

2 participants