Skip to content

Commit 67a7c6b

Browse files
authored
fix: ParallelCompositeUpload in Transfer Manager hangs when encountering OOM (#2526)
* fix: ParallelCompositeUpload in Transfer Manager hangs when encountering OOM * lint * include missing import
1 parent 7d7f526 commit 67a7c6b

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

google-cloud-storage/src/main/java/com/google/cloud/storage/transfermanager/TransferManagerImpl.java

+13-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.google.cloud.storage.BlobInfo;
2727
import com.google.cloud.storage.BlobWriteSessionConfigs;
2828
import com.google.cloud.storage.ParallelCompositeUploadBlobWriteSessionConfig;
29+
import com.google.cloud.storage.ParallelCompositeUploadBlobWriteSessionConfig.BufferAllocationStrategy;
2930
import com.google.cloud.storage.ParallelCompositeUploadBlobWriteSessionConfig.ExecutorSupplier;
3031
import com.google.cloud.storage.Storage;
3132
import com.google.cloud.storage.Storage.BlobWriteOption;
@@ -83,7 +84,11 @@ final class TransferManagerImpl implements TransferManager {
8384
if (transferManagerConfig.isAllowParallelCompositeUpload()) {
8485
ParallelCompositeUploadBlobWriteSessionConfig pcuConfig =
8586
BlobWriteSessionConfigs.parallelCompositeUpload()
86-
.withExecutorSupplier(ExecutorSupplier.useExecutor(executor));
87+
.withExecutorSupplier(ExecutorSupplier.useExecutor(executor))
88+
.withBufferAllocationStrategy(
89+
BufferAllocationStrategy.fixedPool(
90+
transferManagerConfig.getMaxWorkers(),
91+
transferManagerConfig.getPerWorkerBufferSize()));
8792
storageOptions = storageOptions.toBuilder().setBlobWriteSessionConfig(pcuConfig).build();
8893
}
8994
this.pcuQueue = new ConcurrentLinkedDeque<>();
@@ -264,8 +269,13 @@ public void run() {
264269
return;
265270
}
266271

267-
UploadResult result = poll.callable.call();
268-
poll.resultFuture.set(result);
272+
try {
273+
UploadResult result = poll.callable.call();
274+
poll.resultFuture.set(result);
275+
} catch (Throwable e) {
276+
poll.resultFuture.setException(e);
277+
throw e;
278+
}
269279

270280
} while (true);
271281
}

0 commit comments

Comments
 (0)