@Override public void clearTable(String tableString, long timestamp) throws IOException { TableName tableName = TableName.valueOf(tableString); if (!adm.tableExists(tableName)) { log.debug("Attempted to clear table {} before it exists (noop)", tableString); return; } if (!adm.isTableDisabled(tableName)) adm.disableTable(tableName); if (!adm.isTableDisabled(tableName)) throw new RuntimeException("Unable to disable table " + tableName); // This API call appears to both truncate and reenable the table. log.info("Truncating table {}", tableName); adm.truncateTable(tableName, true /* preserve splits */); try { adm.enableTable(tableName); } catch (TableNotDisabledException e) { // This triggers seemingly every time in testing with 1.0.2. log.debug("Table automatically reenabled by truncation: {}", tableName, e); } }
@Override public void truncateTable(TTableName tableName, boolean preserveSplits) throws TIOError, TException { try { TableName table = tableNameFromThrift(tableName); connectionCache.getAdmin().truncateTable(table, preserveSplits); } catch (IOException e) { throw getTIOError(e); } }
+ "', preserving region splits"); admin.disableTable(targetTableName); admin.truncateTable(targetTableName, true); } else { LOG.info("Using exising target table '" + targetTableName + "'");
@Override public void perform() throws Exception { HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility(); Admin admin = util.getAdmin(); // Don't try the truncate if we're stopping if (context.isStopping()) { return; } boolean preserveSplits = random.nextBoolean(); LOG.info("Performing action: Truncate table " + tableName.getNameAsString() + "preserve splits " + preserveSplits); admin.truncateTable(tableName, preserveSplits); } }
private void verify(Table t, IOThrowingRunnable test) throws IOException { admin.disableTable(t.getName()); admin.truncateTable(t.getName(), false); test.run(); }
/** * Truncate a table using the admin command. * Effectively disables, deletes, and recreates the table. * @param tableName table which must exist. * @param preserveRegions keep the existing split points * @return HTable for the new table */ public Table truncateTable(final TableName tableName, final boolean preserveRegions) throws IOException { Admin admin = getAdmin(); if (!admin.isTableDisabled(tableName)) { admin.disableTable(tableName); } admin.truncateTable(tableName, preserveRegions); return getConnection().getTable(tableName); }
@After public void clearQuotaTable() throws Exception { if (TEST_UTIL.getAdmin().tableExists(QuotaUtil.QUOTA_TABLE_NAME)) { TEST_UTIL.getAdmin().disableTable(QuotaUtil.QUOTA_TABLE_NAME); TEST_UTIL.getAdmin().truncateTable(QuotaUtil.QUOTA_TABLE_NAME, false); } }
private void cleanBackupTable() throws IOException { Admin admin = UTIL.getHBaseAdmin(); admin.disableTable(BackupSystemTable.getTableName(conf)); admin.truncateTable(BackupSystemTable.getTableName(conf), true); if (admin.isTableDisabled(BackupSystemTable.getTableName(conf))) { admin.enableTable(BackupSystemTable.getTableName(conf)); } }
private void testTruncateTable(final TableName tableName, boolean preserveSplits) throws IOException { byte[][] splitKeys = new byte[2][]; splitKeys[0] = Bytes.toBytes(4); splitKeys[1] = Bytes.toBytes(8); // Create & Fill the table Table table = TEST_UTIL.createTable(tableName, HConstants.CATALOG_FAMILY, splitKeys); try { TEST_UTIL.loadNumericRows(table, HConstants.CATALOG_FAMILY, 0, 10); assertEquals(10, TEST_UTIL.countRows(table)); } finally { table.close(); } assertEquals(3, TEST_UTIL.getHBaseCluster().getRegions(tableName).size()); // Truncate & Verify this.admin.disableTable(tableName); this.admin.truncateTable(tableName, preserveSplits); table = TEST_UTIL.getConnection().getTable(tableName); try { assertEquals(0, TEST_UTIL.countRows(table)); } finally { table.close(); } if (preserveSplits) { assertEquals(3, TEST_UTIL.getHBaseCluster().getRegions(tableName).size()); } else { assertEquals(1, TEST_UTIL.getHBaseCluster().getRegions(tableName).size()); } }
@Test public void testRestoreSnapshotAfterTruncate() throws Exception { TableName tableName = TableName.valueOf(getValidMethodName()); SnapshotTestingUtils.createTable(TEST_UTIL, tableName, getNumReplicas(), FAMILY); SnapshotTestingUtils.loadData(TEST_UTIL, tableName, 500, FAMILY); int numOfRows = 0; try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { numOfRows = countRows(table); } // take snapshot admin.snapshot("snap", tableName); admin.disableTable(tableName); admin.truncateTable(tableName, false); admin.disableTable(tableName); admin.restoreSnapshot("snap"); admin.enableTable(tableName); verifyRowCount(TEST_UTIL, tableName, numOfRows); SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas()); } }
admin.truncateTable(tableName, true); Assert.assertEquals(1, rsGroupAdmin.getRSGroupInfo(newGroup.getName()).getTables().size()); Assert.assertEquals(tableName,
admin.truncateTable(tableName, false);
if(admin.tableExists(tableName)) { admin.disableTable(tableName); admin.truncateTable(tableName, false);
admin.truncateTable(tableDescriptor.getTableName(), true); assertTrue(admin.isTableAvailable(tableDescriptor.getTableName()));
Admin admin = Connection.getAdmin(); admin.truncateTable(TableName.valueOf("name_of_the_table",true);
private static void dropTable(HBaseGraphConfiguration config, Admin admin, String name) throws IOException { TableName tableName = getTableName(config, name); if (!admin.tableExists(tableName)) return; if (admin.isTableEnabled(tableName)) { admin.disableTable(tableName); } admin.truncateTable(tableName, true); admin.enableTable(tableName); }
@Override public void perform() throws Exception { HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility(); Admin admin = util.getAdmin(); // Don't try the truncate if we're stopping if (context.isStopping()) { return; } boolean preserveSplits = random.nextBoolean(); LOG.info("Performing action: Truncate table " + tableName.getNameAsString() + "preserve splits " + preserveSplits); admin.truncateTable(tableName, preserveSplits); } }
private void verify(Table t, IOThrowingRunnable test) throws IOException { admin.disableTable(t.getName()); admin.truncateTable(t.getName(), false); test.run(); }
@After public void clearQuotaTable() throws Exception { if (TEST_UTIL.getAdmin().tableExists(QuotaUtil.QUOTA_TABLE_NAME)) { TEST_UTIL.getAdmin().disableTable(QuotaUtil.QUOTA_TABLE_NAME); TEST_UTIL.getAdmin().truncateTable(QuotaUtil.QUOTA_TABLE_NAME, false); } }
/** * Truncate a table using the admin command. * Effectively disables, deletes, and recreates the table. * @param tableName table which must exist. * @param preserveRegions keep the existing split points * @return HTable for the new table */ public Table truncateTable(final TableName tableName, final boolean preserveRegions) throws IOException { Admin admin = getAdmin(); if (!admin.isTableDisabled(tableName)) { admin.disableTable(tableName); } admin.truncateTable(tableName, preserveRegions); return getConnection().getTable(tableName); }