Author: kihwal Date: Wed Feb 26 17:07:56 2014 New Revision: 1572165 URL: http://svn.apache.org/r1572165 Log: HDFS-6020. Fix the five findbugs warnings. Contributed by Kihwal Lee.
Modified: hadoop/common/branches/HDFS-5535/hadoop-hdfs-project/hadoop-hdfs/CHANGES_HDFS-5535.txt hadoop/common/branches/HDFS-5535/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockReceiver.java hadoop/common/branches/HDFS-5535/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/BlockPoolSlice.java Modified: hadoop/common/branches/HDFS-5535/hadoop-hdfs-project/hadoop-hdfs/CHANGES_HDFS-5535.txt URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-5535/hadoop-hdfs-project/hadoop-hdfs/CHANGES_HDFS-5535.txt?rev=1572165&r1=1572164&r2=1572165&view=diff ============================================================================== --- hadoop/common/branches/HDFS-5535/hadoop-hdfs-project/hadoop-hdfs/CHANGES_HDFS-5535.txt (original) +++ hadoop/common/branches/HDFS-5535/hadoop-hdfs-project/hadoop-hdfs/CHANGES_HDFS-5535.txt Wed Feb 26 17:07:56 2014 @@ -104,3 +104,4 @@ HDFS-5535 subtasks: TestRollingUpgrade and TestRollingUpgradeRollback. (Haohui Mai via Arpit Agarwal) + HDFS-6020. Fix the five findbugs warnings. (kihwal) Modified: hadoop/common/branches/HDFS-5535/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockReceiver.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-5535/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockReceiver.java?rev=1572165&r1=1572164&r2=1572165&view=diff ============================================================================== --- hadoop/common/branches/HDFS-5535/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockReceiver.java (original) +++ hadoop/common/branches/HDFS-5535/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockReceiver.java Wed Feb 26 17:07:56 2014 @@ -752,8 +752,9 @@ class BlockReceiver implements Closeable File blockFile = ((ReplicaInPipeline)replicaInfo).getBlockFile(); File restartMeta = new File(blockFile.getParent() + File.pathSeparator + "." + blockFile.getName() + ".restart"); - if (restartMeta.exists()) { - restartMeta.delete(); + if (restartMeta.exists() && !restartMeta.delete()) { + LOG.warn("Failed to delete restart meta file: " + + restartMeta.getPath()); } try { FileWriter out = new FileWriter(restartMeta); Modified: hadoop/common/branches/HDFS-5535/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/BlockPoolSlice.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-5535/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/BlockPoolSlice.java?rev=1572165&r1=1572164&r2=1572165&view=diff ============================================================================== --- hadoop/common/branches/HDFS-5535/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/BlockPoolSlice.java (original) +++ hadoop/common/branches/HDFS-5535/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/BlockPoolSlice.java Wed Feb 26 17:07:56 2014 @@ -201,23 +201,28 @@ class BlockPoolSlice { */ void saveDfsUsed() { File outFile = new File(currentDir, DU_CACHE_FILE); - if (outFile.exists()) { - outFile.delete(); + if (outFile.exists() && !outFile.delete()) { + FsDatasetImpl.LOG.warn("Failed to delete old dfsUsed file in " + + outFile.getParent()); } + FileWriter out = null; try { long used = getDfsUsed(); if (used > 0) { - FileWriter out = new FileWriter(outFile); + out = new FileWriter(outFile); // mtime is written last, so that truncated writes won't be valid. out.write(Long.toString(used) + " " + Long.toString(Time.now())); out.flush(); out.close(); + out = null; } } catch (IOException ioe) { // If write failed, the volume might be bad. Since the cache file is // not critical, log the error and continue. FsDatasetImpl.LOG.warn("Failed to write dfsUsed to " + outFile, ioe); + } finally { + IOUtils.cleanup(null, out); } } @@ -297,7 +302,10 @@ class BlockPoolSlice { loadRwr = false; } sc.close(); - restartMeta.delete(); + if (restartMeta.delete()) { + FsDatasetImpl.LOG.warn("Failed to delete restart meta file: " + + restartMeta.getPath()); + } } catch (FileNotFoundException fnfe) { // nothing to do here } finally {