From 2a28e8cf0469a373a99011f0fa540474e60528c8 Mon Sep 17 00:00:00 2001 From: Wei-Chiu Chuang Date: Fri, 9 Dec 2016 16:02:42 -0800 Subject: [PATCH] HDFS-11229. HDFS-11056 failed to close meta file. Contributed by Wei-Chiu Chuang. --- .../hdfs/server/datanode/fsdataset/impl/FsVolumeImpl.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsVolumeImpl.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsVolumeImpl.java index 08564de689..97bb09b9be 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsVolumeImpl.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsVolumeImpl.java @@ -1132,9 +1132,10 @@ private byte[] loadLastPartialChunkChecksum( int offsetInChecksum = BlockMetadataHeader.getHeaderSize() + (int)(onDiskLen / bytesPerChecksum * checksumSize); byte[] lastChecksum = new byte[checksumSize]; - RandomAccessFile raf = new RandomAccessFile(metaFile, "r"); - raf.seek(offsetInChecksum); - raf.read(lastChecksum, 0, checksumSize); + try (RandomAccessFile raf = new RandomAccessFile(metaFile, "r")) { + raf.seek(offsetInChecksum); + raf.read(lastChecksum, 0, checksumSize); + } return lastChecksum; }