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

fix: update TransferManager downloads to reduce in memory buffering #2630

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ final class ChunkedDownloadCallable implements Callable<DownloadSegment> {
@Override
public DownloadSegment call() {
long bytesCopied = -1L;
try (ReadChannel rc = storage.reader(originalBlob.getBlobId(), opts)) {
FileChannel wc =
FileChannel.open(destPath, StandardOpenOption.WRITE, StandardOpenOption.CREATE);
try (ReadChannel rc = storage.reader(originalBlob.getBlobId(), opts);
FileChannel wc =
FileChannel.open(destPath, StandardOpenOption.WRITE, StandardOpenOption.CREATE)) {
rc.setChunkSize(0);
rc.seek(startPosition);
rc.limit(endPosition);
wc.position(startPosition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@ public DownloadResult call() {
Path path = TransferManagerUtils.createDestPath(parallelDownloadConfig, originalBlob);
long bytesCopied = -1L;
try (ReadChannel rc =
storage.reader(
BlobId.of(parallelDownloadConfig.getBucketName(), originalBlob.getName()), opts)) {
FileChannel wc =
FileChannel.open(
path,
StandardOpenOption.WRITE,
StandardOpenOption.CREATE,
StandardOpenOption.TRUNCATE_EXISTING);
storage.reader(
BlobId.of(parallelDownloadConfig.getBucketName(), originalBlob.getName()), opts);
FileChannel wc =
FileChannel.open(
path,
StandardOpenOption.WRITE,
StandardOpenOption.CREATE,
StandardOpenOption.TRUNCATE_EXISTING)) {
rc.setChunkSize(0);
bytesCopied = ByteStreams.copy(rc, wc);
if (originalBlob.getSize() != null) {
if (bytesCopied != originalBlob.getSize()) {
Expand Down
Loading