This is an automated email from the ASF dual-hosted git repository. roryqi pushed a commit to branch branch-0.6 in repository https://gitbox.apache.org/repos/asf/incubator-uniffle.git
commit 52c727f38be9cf9fc7f1e530b5ead9e0206f12e6 Author: xianjingfeng <[email protected]> AuthorDate: Tue Nov 22 23:28:29 2022 +0800 [ISSUE-364] Fix `indexWriter` don't close if exception thrown when close dataWriter (#349) ### What changes were proposed in this pull request? Fix `indexWriter` don't close if exception thrown when close dataWriter ### Why are the changes needed? It's a bug ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? I think it's not necessary, because it's too simple. --- .../handler/impl/HdfsShuffleWriteHandler.java | 24 +++++++--------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/storage/src/main/java/org/apache/uniffle/storage/handler/impl/HdfsShuffleWriteHandler.java b/storage/src/main/java/org/apache/uniffle/storage/handler/impl/HdfsShuffleWriteHandler.java index af59ecbd..36240cae 100644 --- a/storage/src/main/java/org/apache/uniffle/storage/handler/impl/HdfsShuffleWriteHandler.java +++ b/storage/src/main/java/org/apache/uniffle/storage/handler/impl/HdfsShuffleWriteHandler.java @@ -104,18 +104,15 @@ public class HdfsShuffleWriteHandler implements ShuffleWriteHandler { public void write( List<ShufflePartitionedBlock> shuffleBlocks) throws IOException, IllegalStateException { final long start = System.currentTimeMillis(); - HdfsFileWriter dataWriter = null; - HdfsFileWriter indexWriter = null; writeLock.lock(); try { - try { - final long ss = System.currentTimeMillis(); - // Write to HDFS will be failed with lease problem, and can't write the same file again - // change the prefix of file name if write failed before - String dataFileName = ShuffleStorageUtils.generateDataFileName(fileNamePrefix + "_" + failTimes); - String indexFileName = ShuffleStorageUtils.generateIndexFileName(fileNamePrefix + "_" + failTimes); - dataWriter = createWriter(dataFileName); - indexWriter = createWriter(indexFileName); + final long ss = System.currentTimeMillis(); + // Write to HDFS will be failed with lease problem, and can't write the same file again + // change the prefix of file name if write failed before + String dataFileName = ShuffleStorageUtils.generateDataFileName(fileNamePrefix + "_" + failTimes); + String indexFileName = ShuffleStorageUtils.generateIndexFileName(fileNamePrefix + "_" + failTimes); + try (HdfsFileWriter dataWriter = createWriter(dataFileName); + HdfsFileWriter indexWriter = createWriter(indexFileName)) { for (ShufflePartitionedBlock block : shuffleBlocks) { long blockId = block.getBlockId(); long crc = block.getCrc(); @@ -134,13 +131,6 @@ public class HdfsShuffleWriteHandler implements ShuffleWriteHandler { LOG.warn("Write failed with " + shuffleBlocks.size() + " blocks for " + fileNamePrefix + "_" + failTimes, e); failTimes++; throw new RuntimeException(e); - } finally { - if (dataWriter != null) { - dataWriter.close(); - } - if (indexWriter != null) { - indexWriter.close(); - } } } finally { writeLock.unlock();
