You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@parquet.apache.org by ge...@apache.org on 2022/06/10 07:21:57 UTC

[parquet-mr] branch master updated: PARQUET-2154: `ParquetFileReader` should close its input stream when `filterRowGroups` throw Exception in constructor (#972)

This is an automated email from the ASF dual-hosted git repository.

gershinsky pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/parquet-mr.git


The following commit(s) were added to refs/heads/master by this push:
     new c797a85b3 PARQUET-2154: `ParquetFileReader` should close its input stream when `filterRowGroups` throw Exception in constructor (#972)
c797a85b3 is described below

commit c797a85b37ced716efe36597344eb2f3fa06a1cf
Author: YangJie <ya...@baidu.com>
AuthorDate: Fri Jun 10 15:21:51 2022 +0800

    PARQUET-2154: `ParquetFileReader` should close its input stream when `filterRowGroups` throw Exception in constructor (#972)
    
    * fix fd leak if filterRowGroups thrown IOE
    
    Signed-off-by: yangjie01 <ya...@baidu.com>
    
    * change to Exception
---
 .../apache/parquet/hadoop/ParquetFileReader.java   | 27 +++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/parquet-hadoop/src/main/java/org/apache/parquet/hadoop/ParquetFileReader.java b/parquet-hadoop/src/main/java/org/apache/parquet/hadoop/ParquetFileReader.java
index 97fe86d19..5a798a524 100644
--- a/parquet-hadoop/src/main/java/org/apache/parquet/hadoop/ParquetFileReader.java
+++ b/parquet-hadoop/src/main/java/org/apache/parquet/hadoop/ParquetFileReader.java
@@ -715,7 +715,14 @@ public class ParquetFileReader implements Closeable {
                                       .withDecryption(fileDecryptor.getDecryptionProperties())
                                       .build();
     }
-    this.blocks = filterRowGroups(blocks);
+    try {
+      this.blocks = filterRowGroups(blocks);
+    } catch (Exception e) {
+      // In case that filterRowGroups throws an exception in the constructor, the new stream
+      // should be closed. Otherwise, there's no way to close this outside.
+      f.close();
+      throw e;
+    }
     this.blockIndexStores = listWithNulls(this.blocks.size());
     this.blockRowRanges = listWithNulls(this.blocks.size());
     for (ColumnDescriptor col : columns) {
@@ -759,7 +766,14 @@ public class ParquetFileReader implements Closeable {
                                       .build();
     }
     this.footer = footer;
-    this.blocks = filterRowGroups(footer.getBlocks());
+    try {
+      this.blocks = filterRowGroups(footer.getBlocks());
+    } catch (Exception e) {
+      // In case that filterRowGroups throws an exception in the constructor, the new stream
+      // should be closed. Otherwise, there's no way to close this outside.
+      f.close();
+      throw e;
+    }
     this.blockIndexStores = listWithNulls(this.blocks.size());
     this.blockRowRanges = listWithNulls(this.blocks.size());
     for (ColumnDescriptor col : footer.getFileMetaData().getSchema().getColumns()) {
@@ -787,7 +801,14 @@ public class ParquetFileReader implements Closeable {
       this.fileDecryptor = null; // Plaintext file. No need in decryptor
     }
 
-    this.blocks = filterRowGroups(footer.getBlocks());
+    try {
+      this.blocks = filterRowGroups(footer.getBlocks());
+    } catch (Exception e) {
+      // In case that filterRowGroups throws an exception in the constructor, the new stream
+      // should be closed. Otherwise, there's no way to close this outside.
+      f.close();
+      throw e;
+    }
     this.blockIndexStores = listWithNulls(this.blocks.size());
     this.blockRowRanges = listWithNulls(this.blocks.size());
     for (ColumnDescriptor col : footer.getFileMetaData().getSchema().getColumns()) {