[ 
https://issues.apache.org/jira/browse/MAPREDUCE-5865?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14133576#comment-14133576
 ] 

Rahul Palamuttam commented on MAPREDUCE-5865:
---------------------------------------------

Hi,
I agree that the reader should be closed but, from what I see, closing it in a 
finally block adds a level of complexity that may not be necessary. 

1) If we are going to close it in a finally block then the scope of reader 
needs to be beyond just the try block. We would need to declare the object 
outside of the try block and instantiate it inside the try block.
2) calling the close() function requires catching an IOException. If we close 
it in a finally block then we must catch the exception in the finally block as 
well - which is just unnecessary and seems strange to nest a try block in a 
finally block.

I propose that we close the reader in the try block. The IOException is already 
caught and thrown. In other words close the file but no need for a finally 
block.
Let me know if this is best practice or if there is another possible 
implementation. Will post the patch shortly.

> RecordReader is not closed in TeraInputFormat#writePartitionFile()
> ------------------------------------------------------------------
>
>                 Key: MAPREDUCE-5865
>                 URL: https://issues.apache.org/jira/browse/MAPREDUCE-5865
>             Project: Hadoop Map/Reduce
>          Issue Type: Bug
>          Components: mrv1
>            Reporter: Ted Yu
>
> Here is related code:
> {code}
>             RecordReader<Text, Text> reader = 
>               inFormat.createRecordReader(splits.get(sampleStep * idx),
>               context);
>             reader.initialize(splits.get(sampleStep * idx), context);
>             while (reader.nextKeyValue()) {
>               sampler.addKey(new Text(reader.getCurrentKey()));
>               records += 1;
>               if (recordsPerSample <= records) {
>                 break;
>               }
>             }
> {code}
> reader should be closed using finally block.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to