Skip to content

Commit 2cae387

Browse files
committed
HDFS-12319. DirectoryScanner will throw IllegalStateException when Multiple BP's are present. Contributed by Brahma Reddy Battula.
1 parent 82957ce commit 2cae387

2 files changed

Lines changed: 58 additions & 7 deletions

File tree

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DirectoryScanner.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -813,13 +813,12 @@ public ReportCompiler(DataNode datanode, FsVolumeSpi volume) {
813813
public ScanInfoPerBlockPool call() throws IOException {
814814
String[] bpList = volume.getBlockPoolList();
815815
ScanInfoPerBlockPool result = new ScanInfoPerBlockPool(bpList.length);
816+
perfTimer.start();
817+
throttleTimer.start();
816818
for (String bpid : bpList) {
817819
LinkedList<ScanInfo> report = new LinkedList<>();
818820
File bpFinalizedDir = volume.getFinalizedDir(bpid);
819821

820-
perfTimer.start();
821-
throttleTimer.start();
822-
823822
try {
824823
result.put(bpid,
825824
compileReport(volume, bpFinalizedDir, bpFinalizedDir, report));

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

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.apache.hadoop.hdfs.DFSTestUtil;
5353
import org.apache.hadoop.hdfs.HdfsConfiguration;
5454
import org.apache.hadoop.hdfs.MiniDFSCluster;
55+
import org.apache.hadoop.hdfs.MiniDFSNNTopology;
5556
import org.apache.hadoop.hdfs.server.datanode.checker.VolumeCheckResult;
5657
import org.apache.hadoop.hdfs.server.datanode.fsdataset.DataNodeVolumeMetrics;
5758
import org.apache.hadoop.hdfs.protocol.Block;
@@ -309,15 +310,22 @@ private void scan(long totalBlocks, int diffsize, long missingMetaFile, long mis
309310
missingMemoryBlocks, mismatchBlocks, 0);
310311
}
311312

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 {
314316
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) {
316324
assertTrue(scanner.diffs.containsKey(bpid));
317325
LinkedList<DirectoryScanner.ScanInfo> diff = scanner.diffs.get(bpid);
318326
assertTrue(scanner.stats.containsKey(bpid));
319327
DirectoryScanner.Stats stats = scanner.stats.get(bpid);
320-
328+
321329
assertEquals(diffsize, diff.size());
322330
assertEquals(totalBlocks, stats.totalBlocks);
323331
assertEquals(missingMetaFile, stats.missingMetaFile);
@@ -1009,4 +1017,48 @@ public void testExceptionHandlingWhileDirectoryScan() throws Exception {
10091017
cluster.shutdown();
10101018
}
10111019
}
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+
}
10121064
}

0 commit comments

Comments
 (0)