|
69 | 69 |
|
70 | 70 | import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_LEASE_RECHECK_INTERVAL_MS_DEFAULT; |
71 | 71 | import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_LEASE_RECHECK_INTERVAL_MS_KEY; |
| 72 | +import static org.junit.Assert.assertEquals; |
| 73 | +import static org.mockito.ArgumentMatchers.any; |
72 | 74 | import static org.junit.Assert.assertNotEquals; |
73 | 75 |
|
74 | 76 | /** |
@@ -513,4 +515,48 @@ public void testOpenRenameRace() throws Exception { |
513 | 515 | } |
514 | 516 | } |
515 | 517 | } |
| 518 | + |
| 519 | + /** |
| 520 | + * Test get snapshot diff on a directory which delete got failed. |
| 521 | + */ |
| 522 | + @Test |
| 523 | + public void testDeleteOnSnapshottableDir() throws Exception { |
| 524 | + conf.setBoolean( |
| 525 | + DFSConfigKeys.DFS_NAMENODE_SNAPSHOT_DIFF_ALLOW_SNAP_ROOT_DESCENDANT, |
| 526 | + true); |
| 527 | + try { |
| 528 | + cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1).build(); |
| 529 | + cluster.waitActive(); |
| 530 | + DistributedFileSystem hdfs = cluster.getFileSystem(); |
| 531 | + FSNamesystem fsn = cluster.getNamesystem(); |
| 532 | + FSDirectory fsdir = fsn.getFSDirectory(); |
| 533 | + Path dir = new Path("/dir"); |
| 534 | + hdfs.mkdirs(dir); |
| 535 | + hdfs.allowSnapshot(dir); |
| 536 | + Path file1 = new Path(dir, "file1"); |
| 537 | + Path file2 = new Path(dir, "file2"); |
| 538 | + |
| 539 | + // directory should not get deleted |
| 540 | + FSDirectory fsdir2 = Mockito.spy(fsdir); |
| 541 | + cluster.getNamesystem().setFSDirectory(fsdir2); |
| 542 | + Mockito.doReturn(-1L).when(fsdir2).removeLastINode(any()); |
| 543 | + hdfs.delete(dir, true); |
| 544 | + |
| 545 | + // create files and create snapshots |
| 546 | + DFSTestUtil.createFile(hdfs, file1, BLOCK_SIZE, (short) 1, 0); |
| 547 | + hdfs.createSnapshot(dir, "s1"); |
| 548 | + DFSTestUtil.createFile(hdfs, file2, BLOCK_SIZE, (short) 1, 0); |
| 549 | + hdfs.createSnapshot(dir, "s2"); |
| 550 | + |
| 551 | + // should able to get snapshot diff on ancestor dir |
| 552 | + Path dirDir1 = new Path(dir, "dir1"); |
| 553 | + hdfs.mkdirs(dirDir1); |
| 554 | + hdfs.getSnapshotDiffReport(dirDir1, "s2", "s1"); |
| 555 | + assertEquals(1, fsn.getSnapshotManager().getNumSnapshottableDirs()); |
| 556 | + } finally { |
| 557 | + if (cluster != null) { |
| 558 | + cluster.shutdown(); |
| 559 | + } |
| 560 | + } |
| 561 | + } |
516 | 562 | } |
0 commit comments