From 15124c86d803ebae8fa5e7405edead8ddaa80fe5 Mon Sep 17 00:00:00 2001 From: Plamen Jeliazkov Date: Tue, 15 Dec 2015 00:10:33 -0800 Subject: [PATCH] HDFS-9516. Truncate file fails with data dirs on multiple disks. Contributed by Plamen Jeliazkov. --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 +++ .../datanode/fsdataset/impl/FsDatasetImpl.java | 14 +++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 2c76a97a523..7716f9be098 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -30,6 +30,9 @@ Release 2.9.0 - UNRELEASED BUG FIXES + HDFS-9516. Truncate file fails with data dirs on multiple disks. + (Plamen Jeliazkov via shv) + Release 2.8.0 - UNRELEASED INCOMPATIBLE CHANGES 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 8fb06bfbbee..0fabf92b02f 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 @@ -2505,8 +2505,14 @@ class FsDatasetImpl implements FsDatasetSpi { } else { // Copying block to a new block with new blockId. // Not truncating original block. + FsVolumeSpi volume = rur.getVolume(); + String blockPath = blockFile.getAbsolutePath(); + String volumePath = volume.getBasePath(); + assert blockPath.startsWith(volumePath) : + "New block file: " + blockPath + " must be on " + + "same volume as recovery replica: " + volumePath; ReplicaBeingWritten newReplicaInfo = new ReplicaBeingWritten( - newBlockId, recoveryId, rur.getVolume(), blockFile.getParentFile(), + newBlockId, recoveryId, volume, blockFile.getParentFile(), newlength); newReplicaInfo.setNumBytes(newlength); volumeMap.add(bpid, newReplicaInfo); @@ -2522,10 +2528,8 @@ class FsDatasetImpl implements FsDatasetSpi { ReplicaUnderRecovery replicaInfo, String bpid, long newBlkId, long newGS) throws IOException { String blockFileName = Block.BLOCK_FILE_PREFIX + newBlkId; - FsVolumeReference v = volumes.getNextVolume( - replicaInfo.getVolume().getStorageType(), replicaInfo.getNumBytes()); - final File tmpDir = ((FsVolumeImpl) v.getVolume()) - .getBlockPoolSlice(bpid).getTmpDir(); + FsVolumeImpl v = (FsVolumeImpl) replicaInfo.getVolume(); + final File tmpDir = v.getBlockPoolSlice(bpid).getTmpDir(); final File destDir = DatanodeUtil.idToBlockDir(tmpDir, newBlkId); final File dstBlockFile = new File(destDir, blockFileName); final File dstMetaFile = FsDatasetUtil.getMetaFile(dstBlockFile, newGS);