From 9ae8d1a8de2ffbc8a0082a0089f477d4cefea030 Mon Sep 17 00:00:00 2001 From: Jason Lowe Date: Fri, 15 Dec 2017 14:47:54 -0600 Subject: [PATCH] HDFS-12881. Output streams closed with IOUtils suppressing write errors. Contributed by Ajay Kumar --- .../server/datanode/fsdataset/impl/FsDatasetImpl.java | 4 +++- .../hadoop/hdfs/server/namenode/FSImageTestUtil.java | 8 ++++++-- .../tools/offlineImageViewer/TestOfflineImageViewer.java | 6 ++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsDatasetImpl.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsDatasetImpl.java index c6cff6957d6..58fdff459c8 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsDatasetImpl.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsDatasetImpl.java @@ -1116,8 +1116,10 @@ class FsDatasetImpl implements FsDatasetSpi { // calculate and write the last crc checksum.calculateChunkedSums(data, 0, offset, crcs, 0); metaOut.write(crcs, 0, 4); + metaOut.close(); + metaOut = null; } finally { - IOUtils.cleanupWithLogger(LOG, metaOut); + IOUtils.closeStream(metaOut); } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/FSImageTestUtil.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/FSImageTestUtil.java index 12b5180c5b3..9b0723a5085 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/FSImageTestUtil.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/FSImageTestUtil.java @@ -108,6 +108,8 @@ public abstract class FSImageTestUtil { try { raf.seek(IMAGE_TXID_POS); raf.writeLong(0); + raf.close(); + raf = null; } finally { IOUtils.closeStream(raf); } @@ -542,9 +544,11 @@ public abstract class FSImageTestUtil { out = new FileOutputStream(versionFile); props.store(out, null); - + out.close(); + out = null; } finally { - IOUtils.cleanup(null, fis, out); + IOUtils.closeStream(fis); + IOUtils.closeStream(out); } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java index 41bbaddc5b5..74e426e6b9e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java @@ -271,9 +271,11 @@ public class TestOfflineImageViewer { in = new FileInputStream(src); out = new FileOutputStream(dest); in.getChannel().transferTo(0, MAX_BYTES, out.getChannel()); + out.close(); + out = null; } finally { - IOUtils.cleanup(null, in); - IOUtils.cleanup(null, out); + IOUtils.closeStream(in); + IOUtils.closeStream(out); } }