|
52 | 52 | import org.apache.hadoop.hdfs.DFSTestUtil; |
53 | 53 | import org.apache.hadoop.hdfs.HdfsConfiguration; |
54 | 54 | import org.apache.hadoop.hdfs.MiniDFSCluster; |
| 55 | +import org.apache.hadoop.hdfs.MiniDFSNNTopology; |
55 | 56 | import org.apache.hadoop.hdfs.server.datanode.checker.VolumeCheckResult; |
56 | 57 | import org.apache.hadoop.hdfs.server.datanode.fsdataset.DataNodeVolumeMetrics; |
57 | 58 | import org.apache.hadoop.hdfs.protocol.Block; |
@@ -309,15 +310,22 @@ private void scan(long totalBlocks, int diffsize, long missingMetaFile, long mis |
309 | 310 | missingMemoryBlocks, mismatchBlocks, 0); |
310 | 311 | } |
311 | 312 |
|
312 | | - private void scan(long totalBlocks, int diffsize, long missingMetaFile, long missingBlockFile, |
313 | | - long missingMemoryBlocks, long mismatchBlocks, long duplicateBlocks) throws IOException { |
| 313 | + private void scan(long totalBlocks, int diffsize, long missingMetaFile, |
| 314 | + long missingBlockFile, long missingMemoryBlocks, long mismatchBlocks, |
| 315 | + long duplicateBlocks) throws IOException { |
314 | 316 | scanner.reconcile(); |
315 | | - |
| 317 | + verifyStats(totalBlocks, diffsize, missingMetaFile, missingBlockFile, |
| 318 | + missingMemoryBlocks, mismatchBlocks, duplicateBlocks); |
| 319 | + } |
| 320 | + |
| 321 | + private void verifyStats(long totalBlocks, int diffsize, long missingMetaFile, |
| 322 | + long missingBlockFile, long missingMemoryBlocks, long mismatchBlocks, |
| 323 | + long duplicateBlocks) { |
316 | 324 | assertTrue(scanner.diffs.containsKey(bpid)); |
317 | 325 | LinkedList<DirectoryScanner.ScanInfo> diff = scanner.diffs.get(bpid); |
318 | 326 | assertTrue(scanner.stats.containsKey(bpid)); |
319 | 327 | DirectoryScanner.Stats stats = scanner.stats.get(bpid); |
320 | | - |
| 328 | + |
321 | 329 | assertEquals(diffsize, diff.size()); |
322 | 330 | assertEquals(totalBlocks, stats.totalBlocks); |
323 | 331 | assertEquals(missingMetaFile, stats.missingMetaFile); |
@@ -1009,4 +1017,48 @@ public void testExceptionHandlingWhileDirectoryScan() throws Exception { |
1009 | 1017 | cluster.shutdown(); |
1010 | 1018 | } |
1011 | 1019 | } |
| 1020 | + |
| 1021 | + @Test |
| 1022 | + public void testDirectoryScannerInFederatedCluster() throws Exception { |
| 1023 | + //Create Federated cluster with two nameservices and one DN |
| 1024 | + try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(CONF) |
| 1025 | + .nnTopology(MiniDFSNNTopology.simpleHAFederatedTopology(2)) |
| 1026 | + .numDataNodes(1).build()) { |
| 1027 | + cluster.waitActive(); |
| 1028 | + cluster.transitionToActive(1); |
| 1029 | + cluster.transitionToActive(3); |
| 1030 | + DataNode dataNode = cluster.getDataNodes().get(0); |
| 1031 | + fds = DataNodeTestUtils.getFSDataset(cluster.getDataNodes().get(0)); |
| 1032 | + //Create one block in first nameservice |
| 1033 | + FileSystem fs = cluster.getFileSystem(1); |
| 1034 | + int bp1Files = 1; |
| 1035 | + writeFile(fs, bp1Files); |
| 1036 | + //Create two blocks in second nameservice |
| 1037 | + FileSystem fs2 = cluster.getFileSystem(3); |
| 1038 | + int bp2Files = 2; |
| 1039 | + writeFile(fs2, bp2Files); |
| 1040 | + //Call the Directory scanner |
| 1041 | + scanner = new DirectoryScanner(dataNode, fds, CONF); |
| 1042 | + scanner.setRetainDiffs(true); |
| 1043 | + scanner.reconcile(); |
| 1044 | + //Check blocks in corresponding BP |
| 1045 | + bpid = cluster.getNamesystem(1).getBlockPoolId(); |
| 1046 | + verifyStats(bp1Files, 0, 0, 0, 0, 0, 0); |
| 1047 | + bpid = cluster.getNamesystem(3).getBlockPoolId(); |
| 1048 | + verifyStats(bp2Files, 0, 0, 0, 0, 0, 0); |
| 1049 | + } finally { |
| 1050 | + if (scanner != null) { |
| 1051 | + scanner.shutdown(); |
| 1052 | + scanner = null; |
| 1053 | + } |
| 1054 | + } |
| 1055 | + } |
| 1056 | + |
| 1057 | + private void writeFile(FileSystem fs, int numFiles) throws IOException { |
| 1058 | + final String fileName = "/" + GenericTestUtils.getMethodName(); |
| 1059 | + final Path filePath = new Path(fileName); |
| 1060 | + for (int i = 0; i < numFiles; i++) { |
| 1061 | + DFSTestUtil.createFile(fs, filePath, 1, (short) 1, 0); |
| 1062 | + } |
| 1063 | + } |
1012 | 1064 | } |
0 commit comments