org.apache.hadoop.hbase.client.Admin.truncateTable()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(537)

本文整理了Java中org.apache.hadoop.hbase.client.Admin.truncateTable()方法的一些代码示例,展示了Admin.truncateTable()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Admin.truncateTable()方法的具体详情如下:
包路径:org.apache.hadoop.hbase.client.Admin
类名称:Admin
方法名:truncateTable

Admin.truncateTable介绍

[英]Truncate a table. Synchronous operation.
[中]截断表格。同步操作。

代码示例

代码示例来源:origin: thinkaurelius/titan

@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);
  }
}

代码示例来源:origin: apache/hbase

@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);
 }
}

代码示例来源:origin: apache/hbase

+ "', preserving region splits");
 admin.disableTable(targetTableName);
 admin.truncateTable(targetTableName, true);
} else {
 LOG.info("Using exising target table '" + targetTableName + "'");

代码示例来源:origin: apache/hbase

@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);
 }
}

代码示例来源:origin: apache/hbase

private void verify(Table t, IOThrowingRunnable test) throws IOException {
 admin.disableTable(t.getName());
 admin.truncateTable(t.getName(), false);
 test.run();
}

代码示例来源:origin: apache/hbase

/**
 * 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);
}

代码示例来源:origin: apache/hbase

@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);
 }
}

代码示例来源:origin: apache/hbase

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));
 }
}

代码示例来源:origin: apache/hbase

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());
 }
}

代码示例来源:origin: apache/hbase

@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());
 }
}

代码示例来源:origin: apache/hbase

admin.truncateTable(tableName, true);
Assert.assertEquals(1, rsGroupAdmin.getRSGroupInfo(newGroup.getName()).getTables().size());
Assert.assertEquals(tableName,

代码示例来源:origin: apache/hbase

admin.truncateTable(tableName, false);

代码示例来源:origin: apache/phoenix

if(admin.tableExists(tableName)) {
  admin.disableTable(tableName);
  admin.truncateTable(tableName, false);

代码示例来源:origin: apache/hbase

admin.truncateTable(tableDescriptor.getTableName(), true);
assertTrue(admin.isTableAvailable(tableDescriptor.getTableName()));

代码示例来源:origin: stackoverflow.com

Admin admin = Connection.getAdmin();
admin.truncateTable(TableName.valueOf("name_of_the_table",true);

代码示例来源:origin: rayokota/hgraphdb

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);
}

代码示例来源:origin: org.apache.hbase/hbase-it

@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);
 }
}

代码示例来源:origin: org.apache.hbase/hbase-server

private void verify(Table t, IOThrowingRunnable test) throws IOException {
 admin.disableTable(t.getName());
 admin.truncateTable(t.getName(), false);
 test.run();
}

代码示例来源:origin: org.apache.hbase/hbase-server

@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);
 }
}

代码示例来源:origin: org.apache.hbase/hbase-server

/**
 * 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);
}

相关文章

Admin类方法