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

Add sample for making a batch request #7725

Closed
wants to merge 2 commits into from
Closed

Conversation

JesseLovelace
Copy link
Contributor

Adds a sample for making a batch request, internal bug 121151093

@JesseLovelace JesseLovelace requested a review from a team as a code owner November 19, 2021 23:46
@snippet-bot
Copy link

snippet-bot bot commented Nov 19, 2021

Here is the summary of changes.

You are about to add 1 region tag.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Nov 19, 2021
@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label Nov 19, 2021

// The directory prefix. All objects in the bucket with this prefix will have their metadata
// updated
// String objectName = "your-object-name";
Copy link

Choose a reason for hiding this comment

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

Is this supposed to be directoryPrefix?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, thanks!

Copy link

@cojenco cojenco left a comment

Choose a reason for hiding this comment

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

Other than the comment, LGTM!


// Add all blobs with the given prefix to the batch request
for (Blob blob : blobs.iterateAll()) {
batchRequest.update(blob.toBuilder().setMetadata(newMetadata).build());
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a max number of updates you can put into a batch? If someones has lots of objects I could imagine this possibly resulting in an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to the docs, "You should not include more than 100 calls in a single batch request. If you need to make more calls than that, use multiple batch requests. The total batch request payload must be less than 10MB."

Should i put a note about that in the comments?

Copy link
Member

Choose a reason for hiding this comment

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

I would recommend limiting the batch operation to 100 calls per batch operation / submit combination.

Might be overkill though?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@frankyn Like, in this sample? Or do you mean update the actual batch code?

Copy link
Member

Choose a reason for hiding this comment

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

This is more of a question; do you know if the Batch client will handle batch requests correctly if there are more than 100 requests?

Otherwise LGTM.

@danielduhh
Copy link

@frankyn this good to merge?


// Add all blobs with the given prefix to the batch request
for (Blob blob : blobs.iterateAll()) {
batchRequest.update(blob.toBuilder().setMetadata(newMetadata).build());
Copy link
Member

Choose a reason for hiding this comment

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

This is more of a question; do you know if the Batch client will handle batch requests correctly if there are more than 100 requests?

Otherwise LGTM.

@cbonnie
Copy link

cbonnie commented Aug 23, 2022

Thanks for your work, Jesse!

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. samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants