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

Implementation (but not plumbing) of the gRPC remote downloader #10914

Conversation

jmillikin-stripe
Copy link
Contributor

Extracted from #10622

Per discussion on that PR, there's still some unanswered questions about how exactly we plumb the new Downloader type into RemoteModule. And per #10742 (comment), it is unlikely that even heroic effort from me will get the full end-to-end functionality into v3.0.

Given this, to simplify the review, I'm taking some of the bits the reviewer is happy with and moving them to a separate PR. After merger, GrpcRemoteDownloader and its tests will exist in the source tree, but will not yet be available as CLI options.

R: @michajlo
CC: @adunham-stripe @dslomov @EricBurnett @philwo @sstriker

When Bazel downloads an external file (via `ctx.download()` or similar,
it supports the concept of a "canonical ID". This ID is used to
disambiguate download requests when the content checksum is unknown and
the URL doesn't change between fetched resources.

Links:
* Design: https://github.com/bazelbuild/proposals/blob/master/designs/2019-04-29-cache.md
* Implementation PR: bazelbuild#5144
* API doc: https://docs.bazel.build/versions/master/skylark/lib/repository_ctx.html#download

This field was properly plumbed into the `Downloader` interface when it
was added by PR bazelbuild#10547, but an
ad-hoc change during import caused it to get lost. We need to put it
back, or remote downloaders won't be able to do correct cache lookups
for these resources.
These fields are not registered as options yet, they only exist so that
code depending on them can be merged prior to all the RemoteModule
plumbing being worked out.
@jmillikin-stripe jmillikin-stripe force-pushed the remote-downloader-impl-only branch from 121d947 to 218be7d Compare March 6, 2020 08:19
@laurentlb laurentlb assigned katre and unassigned laurentlb Mar 6, 2020
@katre katre self-requested a review March 6, 2020 13:42
Copy link
Member

@katre katre left a comment

Choose a reason for hiding this comment

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

All in all this looks good, a few things I'd like clarification on.

* data will be written to the underlying stream regardless of whether it matches
* the expected checksum.
*
* <p>This class is not thread safe, but it is safe to message pass this object
Copy link
Member

Choose a reason for hiding this comment

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

Is there a meaning to "message pass", or is this just mis-pasted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's copied from HashInputStream.java. I don't know what "message pass" means in the context of Java.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I didn't realize the source. Thanks for clarifying.


private final OutputStream delegate;
private final Hasher hasher;
private final HashCode code;
Copy link
Member

Choose a reason for hiding this comment

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

It looks like "code" is the passed-in code this checks against, and "actual" is the computed checksum to compare with? Add some comments to clarify this (and to explain why this needs to be "volatile", because I'm not sure why).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are also copied from HashInputStream.java. I have no context on why these names were chosen, or what the purpose of volatile is for the Hash*Stream classes.

To clarify: I'm happy to change these to be something else, but I don't have the ability to explain why existing Bazel code is the way it is.

Copy link
Member

Choose a reason for hiding this comment

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

Fair point. Let's leave as is, then.

if (checksum.isPresent()) {
requestBuilder.addQualifiers(
Qualifier.newBuilder()
.setName("checksum.sri")
Copy link
Member

Choose a reason for hiding this comment

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

Should "checksum.sri" be a constant somewhere? Do we have remote-exec specific constants anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to a constant. I can't find any common shared constants file, so I just put it at the top of this one.

return;
}
cacheClient.close();
channel.release();
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 handling the release, but where is the corresponding retain call?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It gets retained by the caller of new GrpcRemoteDownloader. See the implementation and lifecycle of GrpcCacheClient.java for the code I copied from.

Copy link
Member

@katre katre 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 explanations. I'll get this imported today.

@katre
Copy link
Member

katre commented Mar 9, 2020

Turns out I also need to sync open source https://source.bazel.build/bazel/+/master:third_party/remoteapis/ with the internal version. This may slow things down, my apologies.

@bazel-io bazel-io closed this in 289efe5 Mar 9, 2020
@jmillikin-stripe jmillikin-stripe deleted the remote-downloader-impl-only branch March 9, 2020 23:30
katre pushed a commit that referenced this pull request Mar 10, 2020
Extracted from #10622

Per discussion on that PR, there's still some unanswered questions about how exactly we plumb the new `Downloader` type into `RemoteModule`. And per #10742 (comment), it is unlikely that even heroic effort from me will get the full end-to-end functionality into v3.0.

Given this, to simplify the review, I'm taking some of the bits the reviewer is happy with and moving them to a separate PR. After merger, `GrpcRemoteDownloader` and its tests will exist in the source tree, but will not yet be available as CLI options.

R: @michajlo
CC: @adunham-stripe @dslomov @EricBurnett  @philwo @sstriker

Closes #10914.

PiperOrigin-RevId: 299908615
@tjgq
Copy link
Contributor

tjgq commented Oct 14, 2022

@jmillikin-stripe With apologies for the thread necromancy: I am trying to understand the rationale for including the authorization headers in the qualifiers for the FetchBlobRequest in this PR [1].

My understanding of the spec [2][3] is that qualifiers serve to disambiguate resources residing at the same URI. However, it seems to me that authorization should only control access to a resource and would (should?) not affect its contents.

Do you recall why we decided to do this? Would you object to an incompatible Bazel change to drop authorization headers from the qualifier?

/cc @coeuvre @Yannic

[1] https://cs.opensource.google/bazel/bazel/+/master:src/main/java/com/google/devtools/build/lib/remote/downloader/GrpcRemoteDownloader.java;l=199;drc=1ccc0a378a65ad6d7a9b6f1117871fdeda5c26e8
[2] https://cs.opensource.google/bazel/bazel/+/master:third_party/remoteapis/build/bazel/remote/asset/v1/remote_asset.proto;l=282;drc=29ac010f3754c308de2ff13d3480b870dc7cb7f6
[3] https://cs.opensource.google/bazel/bazel/+/master:third_party/remoteapis/build/bazel/remote/asset/v1/remote_asset.proto;l=67;drc=29ac010f3754c308de2ff13d3480b870dc7cb7f6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants