Search in sources :

Example 1 with KeyDeletingService

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);
}
Also used : Path(org.apache.hadoop.fs.Path) DirectoryDeletingService(org.apache.hadoop.ozone.om.DirectoryDeletingService) RepeatedOmKeyInfo(org.apache.hadoop.ozone.om.helpers.RepeatedOmKeyInfo) OmKeyInfo(org.apache.hadoop.ozone.om.helpers.OmKeyInfo) RepeatedOmKeyInfo(org.apache.hadoop.ozone.om.helpers.RepeatedOmKeyInfo) KeyDeletingService(org.apache.hadoop.ozone.om.KeyDeletingService) OmDirectoryInfo(org.apache.hadoop.ozone.om.helpers.OmDirectoryInfo) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) Test(org.junit.Test)

Aggregations

FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)1 Path (org.apache.hadoop.fs.Path)1 DirectoryDeletingService (org.apache.hadoop.ozone.om.DirectoryDeletingService)1 KeyDeletingService (org.apache.hadoop.ozone.om.KeyDeletingService)1 OmDirectoryInfo (org.apache.hadoop.ozone.om.helpers.OmDirectoryInfo)1 OmKeyInfo (org.apache.hadoop.ozone.om.helpers.OmKeyInfo)1 RepeatedOmKeyInfo (org.apache.hadoop.ozone.om.helpers.RepeatedOmKeyInfo)1 Test (org.junit.Test)1