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 compressed reads to cas.go. #237

Merged
merged 2 commits into from
Nov 25, 2020
Merged

Add compressed reads to cas.go. #237

merged 2 commits into from
Nov 25, 2020

Conversation

rubensf
Copy link
Contributor

@rubensf rubensf commented Nov 12, 2020

It follows the specs specified in bazelbuild/remote-apis#168, and
it is similar to #232. Note that while the API still has room to
change, it is mostly finalized and worth implementing.

A caveat of this implementation is that while the offset in reads
refers to the uncompressed bytes, the limit refers to the compressed
bytes.

@google-cla google-cla bot added the cla: yes The author signed a CLA label Nov 12, 2020
@rubensf rubensf force-pushed the read-compression branch 2 times, most recently from d9533be to 45fe3a3 Compare November 24, 2020 16:52
func (c *Client) maybeCompressReadBlob(hash string, sizeBytes int64, w io.WriteCloser) (string, io.WriteCloser, chan error, error) {
if c.CompressedBytestreamThreshold < 0 || int64(c.CompressedBytestreamThreshold) > sizeBytes {
// If we aren't compressing the data, theere's nothing to wait on.
dummyDone := make(chan error)
Copy link
Contributor

Choose a reason for hiding this comment

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

you can make the channel with a capacity of 1 so that writes don't block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -683,20 +726,45 @@ func (c *Client) ReadBlobStreamed(ctx context.Context, d digest.Digest, w io.Wri
return c.readBlobStreamed(ctx, d.Hash, d.Size, 0, 0, w)
}

type writerTracker struct {
io.Writer
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not WriteCloser? Then you can pass Close as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The arg passed in to readBlobStreamed is a io.Writer - if I make this a WriteCloser, I'll have to first wrap the given Writer.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, right, sorry.

}
return n, nil

done := make(chan error)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto, make chan of 1 so that writes don't block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could - but I still have to launch a thread anyway to do de-compression on the side, so I gain no code simplicity but now have to allocate more data.

Copy link
Contributor

Choose a reason for hiding this comment

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

The only thing gained is that the goroutine can exit sooner than it otherwise would, which I think is better. Up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair point - added it!

offset int64
limit int64
want []byte // If nil, fake.blob is expected by default.
disableCompressionTest bool
Copy link
Contributor

Choose a reason for hiding this comment

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

you're not using this disableCompressionTest, right?
Although I'd rather add a bool compressed here, and set it explicitly in some cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was going to use it for the limit test cases below, then I realized I could do it differently -- removed now.

I also technically prefer using a "compressed" here, but I think we do can have a pragmatic check (that is, check whether limit is set) instead.

It follows the specs specified in bazelbuild/remote-apis#168, and
it is similar to #232. Note that while the API still has room to
change, it is mostly finalized and worth implementing.

A caveat of this implementation is that while the `offset` in reads
refers to the uncompressed bytes, the `limit` refers to the compressed
bytes.
}
return n, nil

done := make(chan error)
Copy link
Contributor

Choose a reason for hiding this comment

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

The only thing gained is that the goroutine can exit sooner than it otherwise would, which I think is better. Up to you.

@@ -683,20 +726,45 @@ func (c *Client) ReadBlobStreamed(ctx context.Context, d digest.Digest, w io.Wri
return c.readBlobStreamed(ctx, d.Hash, d.Size, 0, 0, w)
}

type writerTracker struct {
io.Writer
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, right, sorry.

@rubensf rubensf merged commit 5c8d4d2 into master Nov 25, 2020
@rubensf rubensf deleted the read-compression branch November 25, 2020 02:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes The author signed a CLA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants