KEMBAR78
fix: lower batch size on BulkWriter retry by thebrianchen · Pull Request #688 · googleapis/java-firestore · GitHub
Skip to content

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
/** 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.

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 force-pushed the bc/bulk-smaller-batch branch from 1d98f52 to 3cd69f3 Compare July 2, 2021 22:41
@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.

2 participants