thomasmueller commented on code in PR #2688:
URL: https://github.com/apache/jackrabbit-oak/pull/2688#discussion_r2704545885
##########
oak-blob-cloud/src/main/java/org/apache/jackrabbit/oak/blob/cloud/s3/S3Backend.java:
##########
@@ -1334,42 +1334,38 @@ private static String getIdentifierName(String key) {
@NotNull
private AsyncRequestBody getRequestBody(final InputStream input, final
ExecutorService executor,
final PutObjectRequest.Builder
builder) throws IOException {
+ // for both AWS/GCP we need to know the length in advance, else it
won't work.
final AsyncRequestBody body;
- if (Objects.equals(RemoteStorageMode.S3,
properties.get(S3Constants.MODE))) {
- body = AsyncRequestBody.fromInputStream(input, null, executor);
+ final long length;
+ if (input instanceof FileInputStream) {
+ final FileInputStream fis = (FileInputStream) input;
+ // if the file is modified after opening, the size may not reflect
the latest changes
+ length = fis.getChannel().size();
+ body = AsyncRequestBody.fromInputStream(input, length, executor);
+ } else if (input instanceof ByteArrayInputStream) {
+ length = input.available();
+ body = AsyncRequestBody.fromInputStream(input, length, executor);
+ } else if (input.markSupported()) {
+ // in case the inputStream supports mark & reset
+ input.mark(Integer.MAX_VALUE);
+ length = IOUtils.consume(input);
+ input.reset();
+ body = AsyncRequestBody.fromInputStream(input, length, executor);
} else {
- // for GCP we need to know the length in advance, else it won't
work.
- final long length;
- if (input instanceof FileInputStream) {
- final FileInputStream fis = (FileInputStream) input;
- // if the file is modified after opening, the size may not
reflect the latest changes
- length = fis.getChannel().size();
- body = AsyncRequestBody.fromInputStream(input, length,
executor);
- } else if (input instanceof ByteArrayInputStream) {
- length = input.available();
- body = AsyncRequestBody.fromInputStream(input, length,
executor);
- } else if (input.markSupported()) {
- // in case the inputStream supports mark & reset
- input.mark(Integer.MAX_VALUE);
- length = IOUtils.consume(input);
- input.reset();
- body = AsyncRequestBody.fromInputStream(input, length,
executor);
- } else {
- // we have to read all the stream to get the actual length
- // last else block: store to temp file and re-read
- final File tempFile = File.createTempFile("inputstream-",
".tmp");
- tempFile.deleteOnExit(); // Clean up after JVM exits
+ // we have to read all the stream to get the actual length
+ // last else block: store to temp file and re-read
+ final File tempFile = File.createTempFile("inputstream-", ".tmp");
+ tempFile.deleteOnExit(); // Clean up after JVM exits
Review Comment:
This will delete on exit, but not delete after reading. I would delete after
reading as well, so that in the normal case (where the process is not killed)
the file is deleted. Otherwise we might have a large number of temp files, if
the process is not terminated for a long time.
(This could cause out-of-disk space, and if the number of files is huge,
also out-of-memory in kubernetes)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]