/* * Take a snapshot of a table, add data, and verify that deleting the snapshot does not affect * either table. * @param online - Whether the table is online or not during the snapshot */ private void runTestSnapshotDeleteIndependent(boolean online) throws Exception { FileSystem fs = UTIL.getHBaseCluster().getMaster().getMasterFileSystem().getFileSystem(); Path rootDir = UTIL.getHBaseCluster().getMaster().getMasterFileSystem().getRootDir(); final Admin admin = UTIL.getHBaseAdmin(); final long startTime = System.currentTimeMillis(); final TableName localTableName = TableName.valueOf(STRING_TABLE_NAME + startTime); try (Table original = UTIL.createTable(localTableName, TEST_FAM)) { UTIL.loadTable(original, TEST_FAM); } // Take a snapshot final String snapshotNameAsString = "snapshot_" + localTableName; byte[] snapshotName = Bytes.toBytes(snapshotNameAsString); SnapshotTestingUtils.createSnapshotAndValidate( admin, localTableName, TEST_FAM_STR, snapshotNameAsString, rootDir, fs, online); if (!online) { admin.enableTable(localTableName); } TableName cloneTableName = TableName.valueOf("test-clone-" + localTableName); admin.cloneSnapshot(snapshotName, cloneTableName); // Ensure the original table does not reference the HFiles anymore admin.majorCompact(localTableName); // Deleting the snapshot used to break the cloned table by deleting in-use HFiles admin.deleteSnapshot(snapshotName); // Wait for cleaner run and DFS heartbeats so that anything that is deletable is fully deleted Thread.sleep(10000); try (Table original = UTIL.getConnection().getTable(localTableName)) { try (Table clonedTable = UTIL.getConnection().getTable(cloneTableName)) { // Verify that all regions of both tables are readable final int origTableRowCount = UTIL.countRows(original); final int clonedTableRowCount = UTIL.countRows(clonedTable); Assert.assertEquals(origTableRowCount, clonedTableRowCount); } } }