use of org.apache.hadoop.ozone.om.KeyDeletingService in project ozone by apache.
the class TestDirectoryDeletingServiceWithFSO method testDeleteFilesAndSubFiles.
@Test
public void testDeleteFilesAndSubFiles() throws Exception {
Table<String, OmKeyInfo> deletedDirTable = cluster.getOzoneManager().getMetadataManager().getDeletedDirTable();
Table<String, OmKeyInfo> keyTable = cluster.getOzoneManager().getMetadataManager().getKeyTable(getFSOBucketLayout());
Table<String, OmDirectoryInfo> dirTable = cluster.getOzoneManager().getMetadataManager().getDirectoryTable();
Table<String, RepeatedOmKeyInfo> deletedKeyTable = cluster.getOzoneManager().getMetadataManager().getDeletedTable();
Path root = new Path("/rootDir2");
// Create parent dir from root.
fs.mkdirs(root);
// Added 10 sub files inside root dir
for (int i = 0; i < 5; i++) {
Path path = new Path(root, "testKey" + i);
try (FSDataOutputStream stream = fs.create(path)) {
stream.write(1);
}
}
KeyDeletingService keyDeletingService = (KeyDeletingService) cluster.getOzoneManager().getKeyManager().getDeletingService();
// Before delete
assertTableRowCount(deletedDirTable, 0);
assertTableRowCount(keyTable, 5);
assertTableRowCount(dirTable, 1);
long prevDeletedKeyCount = keyDeletingService.getDeletedKeyCount().get();
// Case-1) Delete 3 Files directly.
for (int i = 0; i < 3; i++) {
Path path = new Path(root, "testKey" + i);
fs.delete(path, true);
}
DirectoryDeletingService dirDeletingService = (DirectoryDeletingService) cluster.getOzoneManager().getKeyManager().getDirDeletingService();
// After delete. 2 more files left out under the root dir
assertTableRowCount(keyTable, 2);
assertTableRowCount(dirTable, 1);
// Eventually keys would get cleaned up from deletedTables too
assertTableRowCount(deletedDirTable, 0);
assertTableRowCount(deletedKeyTable, 0);
assertSubPathsCount(dirDeletingService.getMovedFilesCount(), 0);
assertSubPathsCount(dirDeletingService.getDeletedDirsCount(), 0);
// verify whether KeyDeletingService has purged the keys
long currentDeletedKeyCount = keyDeletingService.getDeletedKeyCount().get();
Assert.assertEquals(prevDeletedKeyCount + 3, currentDeletedKeyCount);
// Case-2) Delete dir, this will cleanup sub-files under the deleted dir.
fs.delete(root, true);
// After delete. 2 sub files to be deleted.
assertTableRowCount(keyTable, 0);
assertTableRowCount(dirTable, 0);
// Eventually keys would get cleaned up from deletedTables too
assertTableRowCount(deletedDirTable, 0);
assertTableRowCount(deletedKeyTable, 0);
assertSubPathsCount(dirDeletingService.getMovedFilesCount(), 2);
assertSubPathsCount(dirDeletingService.getDeletedDirsCount(), 1);
// verify whether KeyDeletingService has purged the keys
currentDeletedKeyCount = keyDeletingService.getDeletedKeyCount().get();
Assert.assertEquals(prevDeletedKeyCount + 5, currentDeletedKeyCount);
}
Aggregations