[
https://issues.apache.org/jira/browse/ORC-419?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16654198#comment-16654198
]
ASF GitHub Bot commented on ORC-419:
------------------------------------
prasanthj closed pull request #322: ORC-419: Ensure to call `close` at
RecordReaderImpl constructor exception
URL: https://github.com/apache/orc/pull/322
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/java/core/src/java/org/apache/orc/impl/RecordReaderImpl.java
b/java/core/src/java/org/apache/orc/impl/RecordReaderImpl.java
index 731b46e26e..2b8a6bf46a 100644
--- a/java/core/src/java/org/apache/orc/impl/RecordReaderImpl.java
+++ b/java/core/src/java/org/apache/orc/impl/RecordReaderImpl.java
@@ -269,7 +269,14 @@ protected RecordReaderImpl(ReaderImpl fileReader,
indexes = new OrcProto.RowIndex[types.size()];
bloomFilterIndices = new OrcProto.BloomFilterIndex[types.size()];
bloomFilterKind = new OrcProto.Stream.Kind[types.size()];
- advanceToNextRow(reader, 0L, true);
+
+ try {
+ advanceToNextRow(reader, 0L, true);
+ } catch (IOException e) {
+ // Try to close since this happens in constructor.
+ close();
+ throw e;
+ }
}
public static final class PositionProviderImpl implements PositionProvider {
diff --git a/java/core/src/test/org/apache/orc/impl/TestRecordReaderImpl.java
b/java/core/src/test/org/apache/orc/impl/TestRecordReaderImpl.java
index 66951ff680..529a08b12c 100644
--- a/java/core/src/test/org/apache/orc/impl/TestRecordReaderImpl.java
+++ b/java/core/src/test/org/apache/orc/impl/TestRecordReaderImpl.java
@@ -24,10 +24,12 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.any;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -54,6 +56,8 @@
import org.apache.hadoop.fs.Seekable;
import org.apache.hadoop.hive.common.io.DiskRangeList;
import org.apache.hadoop.hive.common.type.HiveDecimal;
+import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch;
import org.apache.hadoop.hive.ql.io.sarg.SearchArgument;
import org.apache.hadoop.hive.ql.io.sarg.SearchArgumentFactory;
import org.apache.hadoop.hive.ql.io.sarg.SearchArgumentImpl;
@@ -2119,4 +2123,35 @@ public void testSkipDataReaderOpen() throws Exception {
RecordReader recordReader = reader.rows(readerOptions);
recordReader.close();
}
+
+ @Test
+ public void testCloseAtConstructorException() throws Exception {
+ Configuration conf = new Configuration();
+ Path path = new Path(workDir, "oneRow.orc");
+ FileSystem.get(conf).delete(path, true);
+
+ TypeDescription schema = TypeDescription.createLong();
+ OrcFile.WriterOptions options =
OrcFile.writerOptions(conf).setSchema(schema);
+ Writer writer = OrcFile.createWriter(path, options);
+ VectorizedRowBatch writeBatch = schema.createRowBatch();
+ int row = writeBatch.size++;
+ ((LongColumnVector) writeBatch.cols[0]).vector[row] = 0;
+ writer.addRowBatch(writeBatch);
+ writer.close();
+
+ DataReader mockedDataReader = mock(DataReader.class);
+ when(mockedDataReader.clone()).thenReturn(mockedDataReader);
+ doThrow(new IOException()).when(mockedDataReader).readStripeFooter(any());
+
+ Reader reader = OrcFile.createReader(path, OrcFile.readerOptions(conf));
+ Reader.Options readerOptions =
reader.options().dataReader(mockedDataReader);
+ boolean isCalled = false;
+ try {
+ reader.rows(readerOptions);
+ } catch (IOException ie) {
+ isCalled = true;
+ }
+ assertTrue(isCalled);
+ verify(mockedDataReader, times(1)).close();
+ }
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Ensure to call `close` at RecordReaderImpl constructor exception
> ----------------------------------------------------------------
>
> Key: ORC-419
> URL: https://issues.apache.org/jira/browse/ORC-419
> Project: ORC
> Issue Type: Bug
> Components: Java
> Affects Versions: 1.5.0, 1.5.1, 1.5.2, 1.5.3
> Reporter: Dongjoon Hyun
> Priority: Critical
>
> Currently, there is no way to call `RecordReaderImpl.close` if
> `RecordReader.rows` fails at creating `RecordReaderImpl`. This issue aims to
> try to invoke `close` in the constructor in case of Exceptions.
> {code}
> @Override
> public RecordReader rows(Options options) throws IOException {
> LOG.info("Reading ORC rows from " + path + " with " + options);
> return new RecordReaderImpl(this, options);
> }
> {code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)