This is an automated email from the ASF dual-hosted git repository.
roryqi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-uniffle.git
The following commit(s) were added to refs/heads/master by this push:
new dea310b5 [ISSUE-364] Fix `indexWriter` don't close if exception thrown
when close dataWriter (#349)
dea310b5 is described below
commit dea310b5bc247d6b9d949defbe2ac258bbbacfa0
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();