From 5ff22d4c3a417292c496a4bb02e8b19fad66ec63 Mon Sep 17 00:00:00 2001 From: Xiao Chen Date: Wed, 14 Mar 2018 21:59:26 -0700 Subject: [PATCH] HDFS-13246. FileInputStream redundant closes in readReplicasFromCache. Contributed by liaoyuxiangqin. --- .../hdfs/server/datanode/fsdataset/impl/BlockPoolSlice.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/BlockPoolSlice.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/BlockPoolSlice.java index 2d0c6ea137..3f9de78d1c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/BlockPoolSlice.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/BlockPoolSlice.java @@ -812,7 +812,6 @@ private boolean readReplicasFromCache(ReplicaMap volumeMap, break; } } - inputStream.close(); // Now it is safe to add the replica into volumeMap // In case of any exception during parsing this cache file, fall back // to scan all the files on disk. @@ -835,12 +834,13 @@ private boolean readReplicasFromCache(ReplicaMap volumeMap, return false; } finally { + // close the inputStream + IOUtils.closeStream(inputStream); + if (!fileIoProvider.delete(volume, replicaFile)) { LOG.info("Failed to delete replica cache file: " + replicaFile.getPath()); } - // close the inputStream - IOUtils.closeStream(inputStream); } }