[CARBONDATA-1207] Resource leak problem in CarbonDictionaryWriter
Project: http://git-wip-us.apache.org/repos/asf/carbondata/repo Commit: http://git-wip-us.apache.org/repos/asf/carbondata/commit/e54456fa Tree: http://git-wip-us.apache.org/repos/asf/carbondata/tree/e54456fa Diff: http://git-wip-us.apache.org/repos/asf/carbondata/diff/e54456fa Branch: refs/heads/streaming_ingest Commit: e54456fa66350e045223dee96d3a584c1b9a61d8 Parents: 65907d4 Author: mohammadshahidkhan <[email protected]> Authored: Wed Jun 21 16:53:49 2017 +0530 Committer: Venkata Ramana G <[email protected]> Committed: Wed Jun 28 18:19:42 2017 +0530 ---------------------------------------------------------------------- .../core/writer/CarbonDictionaryWriterImpl.java | 26 ++++++++++++-------- 1 file changed, 16 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/carbondata/blob/e54456fa/core/src/main/java/org/apache/carbondata/core/writer/CarbonDictionaryWriterImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/carbondata/core/writer/CarbonDictionaryWriterImpl.java b/core/src/main/java/org/apache/carbondata/core/writer/CarbonDictionaryWriterImpl.java index eae99f2..9de41e1 100644 --- a/core/src/main/java/org/apache/carbondata/core/writer/CarbonDictionaryWriterImpl.java +++ b/core/src/main/java/org/apache/carbondata/core/writer/CarbonDictionaryWriterImpl.java @@ -197,10 +197,13 @@ public class CarbonDictionaryWriterImpl implements CarbonDictionaryWriter { */ @Override public void close() throws IOException { if (null != dictionaryThriftWriter && dictionaryThriftWriter.isOpen()) { - // if stream is open then only need to write dictionary file. - writeDictionaryFile(); - // close the thrift writer for dictionary file - closeThriftWriter(); + try { + // if stream is open then only need to write dictionary file. + writeDictionaryFile(); + } finally { + // close the thrift writer for dictionary file + closeThriftWriter(); + } } } @@ -335,12 +338,15 @@ public class CarbonDictionaryWriterImpl implements CarbonDictionaryWriter { ColumnDictionaryChunkMeta dictionaryChunkMeta = new ColumnDictionaryChunkMeta(min_surrogate_key, max_surrogate_key, chunk_start_offset, chunk_end_offset, chunk_count); - openThriftWriter(this.dictionaryMetaFilePath); - // write dictionary metadata file - writeThriftObject(dictionaryChunkMeta); - closeThriftWriter(); - LOGGER.info("Dictionary metadata file written successfully for column " + this.columnIdentifier - + " at path " + this.dictionaryMetaFilePath); + try { + openThriftWriter(this.dictionaryMetaFilePath); + // write dictionary metadata file + writeThriftObject(dictionaryChunkMeta); + LOGGER.info("Dictionary metadata file written successfully for column " + + this.columnIdentifier + " at path " + this.dictionaryMetaFilePath); + } finally { + closeThriftWriter(); + } } /**
