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

S3: Download files in 1GiB chunks to reduce memory pressure. #110

Merged
merged 1 commit into from
May 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/s3/S3Endpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,24 @@ absl::Status Endpoint::putObject(const std::string &bucket, const std::string &k
absl::StatusOr<size_t> Endpoint::readBytes(const std::string &bucket, const std::string &key,
uint8_t *bytes, size_t position, size_t length) const {

auto stream = utility::ByteIOStream(bytes, length);
return read(bucket, key, stream, position, length);
size_t count = 0;
while (count < length) {
// Only request 1GiB chunks at a time.
// ToDo: Make this value configurable.
auto request = std::min((size_t)1024 * 1024 * 1024, length - count);
auto stream = utility::ByteIOStream(&bytes[count], request);
auto status = read(bucket, key, stream, position + count, request);
if (!status.ok()) {
return status;
}
if (*status == 0) {
LOG_WARNING("Unexpected length for ", bucket, "/", key, ": Requested ", length, " (at pos ",
position, ") but got ", count, "!");
break;
}
count += *status;
}
return count;
}

absl::StatusOr<size_t> Endpoint::read(const std::string &bucket, const std::string &key,
Expand Down