From 6396f8d0c8108c0822f52636394f8ce5e6fb47eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Osipiuk?= Date: Thu, 17 Feb 2022 18:47:03 +0100 Subject: [PATCH] Make close on streaming S3 OutputStream idempotent --- .../java/io/trino/plugin/hive/s3/TrinoS3FileSystem.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/s3/TrinoS3FileSystem.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/s3/TrinoS3FileSystem.java index 6fbec96f4761..1bfd8fb5db45 100644 --- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/s3/TrinoS3FileSystem.java +++ b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/s3/TrinoS3FileSystem.java @@ -1481,6 +1481,7 @@ private static class TrinoS3StreamingOutputStream private byte[] buffer; private int bufferSize; + private boolean closed; private boolean failed; // Mutated and read by main thread; mutated just before scheduling upload to background thread (access does not need to be thread safe) private boolean multipartUploadStarted; @@ -1548,6 +1549,11 @@ public void flush() public void close() throws IOException { + if (closed) { + return; + } + closed = true; + if (failed) { try { abortUpload();