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: lower batch size on BulkWriter retry #688

Merged
merged 4 commits into from Jul 3, 2021

Conversation

thebrianchen
Copy link

No description provided.

@thebrianchen thebrianchen self-assigned this Jul 2, 2021
@thebrianchen thebrianchen requested a review from a team as a code owner July 2, 2021 20:24
@thebrianchen thebrianchen requested a review from a team July 2, 2021 20:24
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Jul 2, 2021
@product-auto-label product-auto-label bot added the api: firestore Issues related to the googleapis/java-firestore API. label Jul 2, 2021
@@ -82,6 +83,9 @@
/** The maximum number of writes that can be in a single batch. */
public static final int MAX_BATCH_SIZE = 20;

/** The maximum number of writes can be can in a single batch that is being retried. */
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 Sebastian-level grammar. Please upgrade to Brian-level grammar.

Copy link
Author

Choose a reason for hiding this comment

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

Attempted.

// A backoff duration greater than 0 implies that this batch is a retry.
// Retried writes are sent with a batch size of 10 in order to guarantee
// that the batch is under the 10MiB limit.
boolean retryInSmallerBatch =
Copy link
Contributor

Choose a reason for hiding this comment

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

This boolean does more than just check whether a smaller batch should be used. It also checks the size of the current batch. I think we need to move some logic or change the name.

Copy link
Author

Choose a reason for hiding this comment

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

Removed.

@@ -1062,7 +1075,11 @@ private void sendOperationLocked(
bulkCommitBatch.enqueueOperation(op);
enqueueOperationOnBatchCallback.apply(bulkCommitBatch);

if (bulkCommitBatch.getMutationsSize() == maxBatchSize) {
if (op.getBackoffDuration() > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am a bit confused. Why do we need this and retryInSmallerBatch? Is it possible to remove one of these checks?

Copy link
Author

Choose a reason for hiding this comment

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

The first check involving retryInSmallerBatch ensures that we are adding the retry to an appropriate batch. For example, if the batch already had 15 writes enqueued, and sendOperationLocked() is called with a retry, BulkWriter needs to first send the existing batch to create a new batch of size 10.

Consolidated the checks into a single if statement at the start of the function.

bulkCommitBatch.setMaxBatchSize(RETRY_MAX_BATCH_SIZE);
}

if (bulkCommitBatch.getMutationsSize() == bulkCommitBatch.getMaxBatchSize()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

... especially since we are reading the value right back here.

@thebrianchen thebrianchen merged commit 146b21d into master Jul 3, 2021
@thebrianchen thebrianchen deleted the bc/bulk-smaller-batch branch July 3, 2021 00:23
gcf-merge-on-green bot pushed a commit that referenced this pull request Jul 29, 2021
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/java-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.

None yet

2 participants