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

chore(dataobj): deduplicate decoder code across bucket and io.ReadSeeker #15945

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rfratto
Copy link
Member

@rfratto rfratto commented Jan 24, 2025

A previous comment identified that the code for BucketDecoder and ReadSeekerDecoder were extremely similar, and that they could be deduplicated by introducing some kind of "range reader" interface.

This commit introduces such an interface, which maps perfectly to bucket decoding. Implementations of the interface must be able to tolerate concurrent instance of readers, which io.ReadSeeker does not. To tolerate this while still allowing to decode data objects that are either in-memory or backed by a file, ReadSeekerDecoder has been updated to ReaderAtDecoder and accepts a size argument to note how large the object is.

@rfratto rfratto requested a review from a team as a code owner January 24, 2025 15:06
github.com/dustin/go-humanize v1.0.1
github.com/grafana/loki/v3 v3.3.2
)
require github.com/grafana/loki/v3 v3.3.2
Copy link
Member Author

Choose a reason for hiding this comment

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

@benclive Go told me I needed to run go mod tidy, let me know if anything here seems off

ReadRange(ctx context.Context, offset int64, length int64) (io.ReadCloser, error)
}

type rangeDecoder struct {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is more or less a copy/paste from the old bucket decoder but it uses rangeReader instead.

A previous comment identified that the code for BucketDecoder and
ReadSeekerDecoder were extremely similar, and that they could be
deduplicated by introducing some kind of "range reader" interface.

This commit inroduces such an interface, which maps perfectly to bucket
decoding. Implementations of the interface must be able to tolerate
concurrent instance of readers, which io.ReadSeeker does not. To
tolerate this while still allowing to decode data objects that are
either in-memory or backed by a file, ReadSeekerDecoder has been updated
to ReaderAtDecoder.
@rfratto rfratto force-pushed the dataobj-dedupe-decoders branch from edc9d87 to cf745b6 Compare January 24, 2025 15:08
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.

1 participant