-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Reorg and refactor code around Blob abuse #1678
Conversation
Finally, fixed the MacOS failure. Ready for review. |
jib-core/src/main/java/com/google/cloud/tools/jib/hash/DigestUtil.java
Outdated
Show resolved
Hide resolved
can you rebase or resolve conflicts on this or whatever? I remember you saying it included changes from the parent PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like WritableContents
is only used in Digests
which is itself internal, does that mean writable contents is unnecessary? Am I missing something?
Unrelated but I'm still confused: are we also calculating digests for raw strings (not from streams)? It seems our primary mechanism for digest generation is through an inputstream mechanism, but it could be easier for non-streams to use MessageDigest
directly?
* @throws IOException if reading from or writing fails | ||
*/ | ||
public static BlobDescriptor computeDigest( | ||
WritableContents contents, OutputStream optionalOutStream) throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple questions about optionalOutStream
- is it truly optional? Even calls not using it still pass in a nulloutputstream.
- should we use
OutputStream
instead ofOutStream
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name "optional" is there only because of the name "computeDigest" doesn't convey the message that it can additionally copy WritableContents
into the out stream while computing the digest. Like, from the point of a user just trying to compute a digest, they won't get why they have to pass an output stream for what.
Maybe I should just rename the method to "computeDigestAndCopy", as I said in the meeting? WDYT?
For outStream
, I don't think anyone can confuse that with something else than a stream for output, but if you are averse to that, I can go with outputStream
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not so much confusion as much as consistency for outStream
vs outputStream
, so not a big deal.
I think we can actually deal with the optionalOutStream
in a follow up PR.
So calculating the digest effectively consumes the stream? Is the purpose of copying the stream to reuse it somewhere else? |
Ah, TIL we can use
Yeah, if data is coming from an input stream, in general we have to consume it, as we have no other choices (unless the input stream is resettable like a |
Merging. We can follow up in later PRs. |
Continuation of #1647. In #1647, I said the prevalent abuse of
Blob
(which is not much different from an all-consumingObject
in many contexts) is to wrap anything in aBlob
only for the sake of writing it to an output stream or compute a digest, which is an unnecessary and convoluted round-trip and making the target invisible underneathBlob
.Another complexity that hurt readability (to me at least) was the similarities between
WriterBlob
,BlobWriter
, andBlob
.Blob
andWriterBlob
look very similar,but yet, you create a
Blob
(which is actuallyWriterBlob
) out ofBlobWriter
and
WriterBlob.writeTo()
makes use ofblobWriter.writeTo()
. Before someone becomes familiarized with the code, all this will sound pretty confusing to them. With theBlob
abuse I said at the top, this is aggravating.Some highlighted changes:
DigestUtil
to do it directly without the abuse.Blob
fromJsonTemplateMapper
. Now JSON-related classes sit belowBlob
in the dependency graph.JsonBlob
. This makes sense becauseBlob
sits aboveJsonTemplate
.BlobWriter
toWritableContents
, and moved it to thehash
package that sits belowBlob
.Blob.writeTo()
methods simply and consistently delegate toDigestUtil.computeDigest()
. This resulted in removingBlobDescriptor.fromPipe()
, which I think was not named or placed nicely, hose code is also duplicated someBlob.writeTo()
method.BlobDescriptor
is merely a holder of (size, digest).Another thing to note is that, there's no
toBlob()
ortoBlobDescriptor()
functions anymore after #1647 and this. All blobs are constructed throughBlobs.from()
.