voonhous commented on code in PR #18776:
URL: https://github.com/apache/hudi/pull/18776#discussion_r4060384508


##########
hudi-hadoop-common/src/main/java/org/apache/hudi/parquet/io/HoodieParquetBinaryCopyBase.java:
##########
@@ -159,24 +160,44 @@ protected void initFileWriter(Path outPutFile, 
CompressionCodecName newCodecName
       writer.start();
       log.info("init writer ");
     } catch (Exception e) {
+      closeParquetFileWriterQuietly(e);
       log.error("failed to init parquet writer", e);
       throw new HoodieException(e);
     }
   }
 
   @Override
   public void close() throws IOException {
-    Map<String, String> extraMetaData = finalizeMetadata();
-    extraMetaData = extraMetaData == null ? new HashMap<>() : extraMetaData;
-    extraMetaData.remove("parquet.avro.schema");
-    extraMetaData.remove("org.apache.spark.sql.parquet.row.metadata");
-    writer.end(extraMetaData);
-    // Release the buffer
-    reusableBlockBuffer = null;
+    if (writer == null) {
+      return;
+    }
+    try {
+      Map<String, String> extraMetaData = finalizeMetadata();
+      extraMetaData = extraMetaData == null ? new HashMap<>() : extraMetaData;
+      extraMetaData.remove("parquet.avro.schema");
+      extraMetaData.remove("org.apache.spark.sql.parquet.row.metadata");
+      writer.end(extraMetaData);
+    } catch (IOException | RuntimeException e) {
+      closeParquetFileWriterQuietly(e);
+      throw e;
+    } finally {
+      writer = null;
+      // Release the buffer
+      reusableBlockBuffer = null;
+    }
   }
 
   protected abstract Map<String, String> finalizeMetadata();
 
+  private void closeParquetFileWriterQuietly(Throwable failure) {
+    // Parquet 1.12.x/1.13.x have no close(); newer versions implement 
AutoCloseable.
+    ParquetFileWriter parquetFileWriter = writer;
+    writer = null;
+    if (parquetFileWriter instanceof AutoCloseable) {

Review Comment:
   Fair enough, the updated comment makes the 1.12/1.13 gap explicit. Resolving.



##########
hudi-common/src/main/java/org/apache/hudi/common/bootstrap/index/hfile/HFileBootstrapIndexWriter.java:
##########
@@ -174,28 +176,60 @@ private void commit() {
    * Close Writer Handles.
    */
   public void close() {
-    try {
-      if (!closed) {
-        indexByPartitionWriter.close();
-        indexByFileIdWriter.close();
-        closed = true;
-      }
-    } catch (IOException ioe) {
-      throw new HoodieIOException(ioe.getMessage(), ioe);
+    if (closed) {
+      return;
+    }
+    Exception failure = closeHFileWriter(indexByPartitionWriter, null);
+    failure = closeHFileWriter(indexByFileIdWriter, failure);
+    indexByPartitionWriter = null;
+    indexByFileIdWriter = null;
+    closed = true;
+    if (failure != null) {
+      throw new HoodieException(failure.getMessage(), failure);

Review Comment:
   OK, no caller depends on the subtype and the cause is kept. Resolving.



-- 
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]

Reply via email to