|
26 | 26 | import static org.junit.Assert.assertNull; |
27 | 27 | import static org.junit.Assert.assertTrue; |
28 | 28 |
|
| 29 | +import java.io.ByteArrayOutputStream; |
29 | 30 | import java.io.File; |
30 | 31 | import java.io.FileOutputStream; |
31 | 32 | import java.io.IOException; |
|
72 | 73 | import org.apache.hadoop.test.GenericTestUtils; |
73 | 74 | import org.apache.hadoop.util.AutoCloseableLock; |
74 | 75 | import org.apache.hadoop.util.Time; |
| 76 | +import org.apache.log4j.Level; |
| 77 | +import org.apache.log4j.SimpleLayout; |
| 78 | +import org.apache.log4j.WriterAppender; |
75 | 79 | import org.junit.Before; |
76 | 80 | import org.junit.Test; |
77 | 81 | import org.mockito.Mockito; |
@@ -394,6 +398,70 @@ public void testRetainBlockOnPersistentStorage() throws Exception { |
394 | 398 | } |
395 | 399 | } |
396 | 400 |
|
| 401 | + /** |
| 402 | + * test scan only meta file NOT generate wrong folder structure warn log. |
| 403 | + */ |
| 404 | + @Test(timeout=600000) |
| 405 | + public void testScanDirectoryStructureWarn() throws Exception { |
| 406 | + |
| 407 | + //add a logger stream to check what has printed to log |
| 408 | + ByteArrayOutputStream loggerStream = new ByteArrayOutputStream(); |
| 409 | + org.apache.log4j.Logger rootLogger = |
| 410 | + org.apache.log4j.Logger.getRootLogger(); |
| 411 | + rootLogger.setLevel(Level.INFO); |
| 412 | + WriterAppender writerAppender = |
| 413 | + new WriterAppender(new SimpleLayout(), loggerStream); |
| 414 | + rootLogger.addAppender(writerAppender); |
| 415 | + |
| 416 | + cluster = new MiniDFSCluster |
| 417 | + .Builder(CONF) |
| 418 | + .storageTypes(new StorageType[] { |
| 419 | + StorageType.RAM_DISK, StorageType.DEFAULT }) |
| 420 | + .numDataNodes(1) |
| 421 | + .build(); |
| 422 | + try { |
| 423 | + cluster.waitActive(); |
| 424 | + bpid = cluster.getNamesystem().getBlockPoolId(); |
| 425 | + fds = DataNodeTestUtils.getFSDataset(cluster.getDataNodes().get(0)); |
| 426 | + client = cluster.getFileSystem().getClient(); |
| 427 | + scanner = new DirectoryScanner(fds, CONF); |
| 428 | + scanner.setRetainDiffs(true); |
| 429 | + FsDatasetTestUtil.stopLazyWriter(cluster.getDataNodes().get(0)); |
| 430 | + |
| 431 | + // Create a file file on RAM_DISK |
| 432 | + createFile(GenericTestUtils.getMethodName(), BLOCK_LENGTH, true); |
| 433 | + |
| 434 | + // Ensure no difference between volumeMap and disk. |
| 435 | + scan(1, 0, 0, 0, 0, 0); |
| 436 | + |
| 437 | + //delete thre block file , left the meta file alone |
| 438 | + deleteBlockFile(); |
| 439 | + |
| 440 | + //scan to ensure log warn not printed |
| 441 | + scan(1, 1, 0, 1, 0, 0, 0); |
| 442 | + |
| 443 | + //ensure the warn log not appear and missing block log do appear |
| 444 | + String logContent = new String(loggerStream.toByteArray()); |
| 445 | + String missingBlockWarn = "Deleted a metadata file" + |
| 446 | + " for the deleted block"; |
| 447 | + String dirStructureWarnLog = " found in invalid directory." + |
| 448 | + " Expected directory: "; |
| 449 | + assertFalse("directory check print meaningless warning message", |
| 450 | + logContent.contains(dirStructureWarnLog)); |
| 451 | + assertTrue("missing block warn log not appear", |
| 452 | + logContent.contains(missingBlockWarn)); |
| 453 | + LOG.info("check pass"); |
| 454 | + |
| 455 | + } finally { |
| 456 | + if (scanner != null) { |
| 457 | + scanner.shutdown(); |
| 458 | + scanner = null; |
| 459 | + } |
| 460 | + cluster.shutdown(); |
| 461 | + cluster = null; |
| 462 | + } |
| 463 | + } |
| 464 | + |
397 | 465 | @Test(timeout = 300000) |
398 | 466 | public void testDeleteBlockOnTransientStorage() throws Exception { |
399 | 467 | cluster = new MiniDFSCluster.Builder(CONF) |
|
0 commit comments