Skip to content

Commit 58714f3

Browse files
author
Lei Xu
committed
HDFS-9490. MiniDFSCluster should change block generation stamp via FsDatasetTestUtils. (Tony Wu via lei)
(cherry picked from commit 0ac8fb4)
1 parent a68faf1 commit 58714f3

File tree

5 files changed

+30
-6
lines changed

5 files changed

+30
-6
lines changed

hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,9 @@ Release 2.8.0 - UNRELEASED
841841
HDFS-9485. Make BlockManager#removeFromExcessReplicateMap accept BlockInfo
842842
instead of Block. (Mingliang Liu via jing9)
843843

844+
HDFS-9490. MiniDFSCluster should change block generation stamp via
845+
FsDatasetTestUtils. (Tony Wu via lei)
846+
844847
OPTIMIZATIONS
845848

846849
HDFS-8026. Trace FSOutputSummer#writeChecksumChunks rather than

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/MiniDFSCluster.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,12 +2026,10 @@ public void truncateMeta(int i, ExtendedBlock blk, int newSize)
20262026
getMaterializedReplica(i, blk).truncateMeta(newSize);
20272027
}
20282028

2029-
public boolean changeGenStampOfBlock(int dnIndex, ExtendedBlock blk,
2029+
public void changeGenStampOfBlock(int dnIndex, ExtendedBlock blk,
20302030
long newGenStamp) throws IOException {
2031-
File blockFile = getBlockFile(dnIndex, blk);
2032-
File metaFile = FsDatasetUtil.findMetaFile(blockFile);
2033-
return metaFile.renameTo(new File(DatanodeUtil.getMetaName(
2034-
blockFile.getAbsolutePath(), newGenStamp)));
2031+
getFsDatasetTestUtils(dnIndex)
2032+
.changeStoredGenerationStamp(blk, newGenStamp);
20352033
}
20362034

20372035
/*

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/FsDatasetTestUtils.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,4 +242,13 @@ Replica createReplicaUnderRecovery(ExtendedBlock block, long recoveryId)
242242
* Get the persistently stored generation stamp.
243243
*/
244244
long getStoredGenerationStamp(ExtendedBlock block) throws IOException;
245+
246+
/**
247+
* Change the persistently stored generation stamp.
248+
* @param block the block whose generation stamp will be changed
249+
* @param newGenStamp the new generation stamp
250+
* @throws IOException
251+
*/
252+
void changeStoredGenerationStamp(ExtendedBlock block, long newGenStamp)
253+
throws IOException;
245254
}

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsDatasetImplTestUtils.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.apache.hadoop.fs.FileUtil;
3030
import org.apache.hadoop.hdfs.protocol.ExtendedBlock;
3131
import org.apache.hadoop.hdfs.server.datanode.DataNode;
32+
import org.apache.hadoop.hdfs.server.datanode.DatanodeUtil;
3233
import org.apache.hadoop.hdfs.server.datanode.FinalizedReplica;
3334
import org.apache.hadoop.hdfs.server.datanode.FsDatasetTestUtils;
3435
import org.apache.hadoop.hdfs.server.datanode.Replica;
@@ -47,6 +48,7 @@
4748
import java.io.RandomAccessFile;
4849
import java.nio.channels.FileChannel;
4950
import java.nio.file.Files;
51+
import java.nio.file.StandardCopyOption;
5052
import java.util.Random;
5153

5254
/**
@@ -363,4 +365,16 @@ public long getStoredGenerationStamp(ExtendedBlock block) throws IOException {
363365
File[] files = FileUtil.listFiles(dir);
364366
return FsDatasetUtil.getGenerationStampFromFile(files, f);
365367
}
368+
369+
@Override
370+
public void changeStoredGenerationStamp(
371+
ExtendedBlock block, long newGenStamp) throws IOException {
372+
File blockFile =
373+
dataset.getBlockFile(block.getBlockPoolId(), block.getBlockId());
374+
File metaFile = FsDatasetUtil.findMetaFile(blockFile);
375+
File newMetaFile = new File(
376+
DatanodeUtil.getMetaName(blockFile.getAbsolutePath(), newGenStamp));
377+
Files.move(metaFile.toPath(), newMetaFile.toPath(),
378+
StandardCopyOption.ATOMIC_MOVE);
379+
}
366380
}

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestPendingCorruptDnMessages.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void testChangedStorageId() throws IOException, URISyntaxException,
6868
// Change the gen stamp of the block on datanode to go back in time (gen
6969
// stamps start at 1000)
7070
ExtendedBlock block = DFSTestUtil.getFirstBlock(fs, filePath);
71-
assertTrue(cluster.changeGenStampOfBlock(0, block, 900));
71+
cluster.changeGenStampOfBlock(0, block, 900);
7272

7373
// Run directory dsscanner to update Datanode's volumeMap
7474
DataNodeTestUtils.runDirectoryScanner(cluster.getDataNodes().get(0));

0 commit comments

Comments
 (0)