本文整理了Java中org.apache.hadoop.hbase.client.Admin.disableTable()
方法的一些代码示例,展示了Admin.disableTable()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Admin.disableTable()
方法的具体详情如下:
包路径:org.apache.hadoop.hbase.client.Admin
类名称:Admin
方法名:disableTable
[英]Disable table and wait on completion. May timeout eventually. Use #disableTableAsync(org.apache.hadoop.hbase.TableName) and #isTableDisabled(org.apache.hadoop.hbase.TableName) instead. The table has to be in enabled state for it to be disabled.
[中]禁用表并等待完成。最终可能会超时。改用#disableTableAsync(org.apache.hadoop.hbase.TableName)和#isTableDisabled(org.apache.hadoop.hbase.TableName)。表必须处于启用状态才能被禁用。
代码示例来源:origin: thinkaurelius/titan
@Override
public void disableTable(String tableString) throws IOException
{
adm.disableTable(TableName.valueOf(tableString));
}
代码示例来源:origin: apache/kylin
public Object call() throws Exception {
logger.info("Deleting HBase table " + htableName);
if (hbaseAdmin.tableExists(TableName.valueOf(htableName))) {
if (hbaseAdmin.isTableEnabled(TableName.valueOf(htableName))) {
hbaseAdmin.disableTable(TableName.valueOf(htableName));
}
hbaseAdmin.deleteTable(TableName.valueOf(htableName));
logger.info("Deleted HBase table " + htableName);
} else {
logger.info("HBase table" + htableName + " does not exist");
}
return null;
}
}
代码示例来源:origin: apache/hbase
private void dropTable(Admin admin, TableName tn) throws Exception {
admin.disableTable(tn);
admin.deleteTable(tn);
}
}
代码示例来源:origin: apache/hbase
@Test
public void testDisableCatalogTable() throws Exception {
try {
this.admin.disableTable(TableName.META_TABLE_NAME);
fail("Expected to throw ConstraintException");
} catch (ConstraintException e) {
}
// Before the fix for HBASE-6146, the below table creation was failing as the hbase:meta table
// actually getting disabled by the disableTable() call.
HTableDescriptor htd =
new HTableDescriptor(TableName.valueOf(Bytes.toBytes(name.getMethodName())));
HColumnDescriptor hcd = new HColumnDescriptor(Bytes.toBytes("cf1"));
htd.addFamily(hcd);
TEST_UTIL.getHBaseAdmin().createTable(htd);
}
代码示例来源:origin: apache/hbase
@Test
public void testDisableTable() throws IOException, InterruptedException {
createSingleRegionTable();
TEST_UTIL.getAdmin().disableTable(TABLE_NAME);
for (RegionLocateType locateType : RegionLocateType.values()) {
try {
getDefaultRegionLocation(TABLE_NAME, EMPTY_START_ROW, locateType, false).get();
} catch (ExecutionException e) {
assertThat(e.getCause(), instanceOf(TableNotFoundException.class));
}
}
}
代码示例来源:origin: apache/hbase
/**
* Can't disable a table if the table isn't in enabled state
* @throws IOException
*/
@Test (expected=TableNotEnabledException.class)
public void testTableNotEnabledExceptionWithATable() throws IOException {
final TableName name = TableName.valueOf(this.name.getMethodName());
TEST_UTIL.createTable(name, HConstants.CATALOG_FAMILY).close();
this.admin.disableTable(name);
this.admin.disableTable(name);
}
代码示例来源:origin: apache/hbase
@Test
public void testCreateNamespaceAndTable() throws Exception {
Admin admin = TEST_UTIL.getAdmin();
HelloHBase.createNamespaceAndTable(admin);
boolean namespaceExists
= HelloHBase.namespaceExists(admin, HelloHBase.MY_NAMESPACE_NAME);
assertEquals("#createNamespaceAndTable failed to create namespace.",
true, namespaceExists);
boolean tableExists = admin.tableExists(HelloHBase.MY_TABLE_NAME);
assertEquals("#createNamespaceAndTable failed to create table.",
true, tableExists);
admin.disableTable(HelloHBase.MY_TABLE_NAME);
admin.deleteTable(HelloHBase.MY_TABLE_NAME);
admin.deleteNamespace(HelloHBase.MY_NAMESPACE_NAME);
}
代码示例来源:origin: apache/hbase
@Test
public void testEnableReplicationWhenSlaveClusterDoesntHaveTable() throws Exception {
admin1.disableTableReplication(tableName);
admin2.disableTable(tableName);
admin2.deleteTable(tableName);
assertFalse(admin2.tableExists(tableName));
admin1.enableTableReplication(tableName);
assertTrue(admin2.tableExists(tableName));
}
代码示例来源:origin: apache/hbase
@Test
public void testEnableReplicationWhenReplicationNotEnabled() throws Exception {
HTableDescriptor table = new HTableDescriptor(admin1.getTableDescriptor(tableName));
for (HColumnDescriptor fam : table.getColumnFamilies()) {
fam.setScope(HConstants.REPLICATION_SCOPE_LOCAL);
}
admin1.disableTable(tableName);
admin1.modifyTable(tableName, table);
admin1.enableTable(tableName);
admin2.disableTable(tableName);
admin2.modifyTable(tableName, table);
admin2.enableTable(tableName);
admin1.enableTableReplication(tableName);
table = admin1.getTableDescriptor(tableName);
for (HColumnDescriptor fam : table.getColumnFamilies()) {
assertEquals(HConstants.REPLICATION_SCOPE_GLOBAL, fam.getScope());
}
}
代码示例来源:origin: apache/kylin
/** create a HTable that has the same performance settings as normal cube table, for benchmark purpose */
public static void createBenchmarkHTable(TableName tableName, String cfName) throws IOException {
Admin admin = HBaseConnection.get(KylinConfig.getInstanceFromEnv().getStorageUrl()).getAdmin();
try {
if (admin.tableExists(tableName)) {
logger.info("disabling hbase table " + tableName);
admin.disableTable(tableName);
logger.info("deleting hbase table " + tableName);
admin.deleteTable(tableName);
}
HTableDescriptor tableDesc = new HTableDescriptor(tableName);
tableDesc.setValue(HTableDescriptor.SPLIT_POLICY, DisabledRegionSplitPolicy.class.getName());
KylinConfig kylinConfig = KylinConfig.getInstanceFromEnv();
tableDesc.addFamily(createColumnFamily(kylinConfig, cfName, false));
logger.info("creating hbase table " + tableName);
admin.createTable(tableDesc, null);
Preconditions.checkArgument(admin.isTableAvailable(tableName), "table " + tableName + " created, but is not available due to some reasons");
logger.info("create hbase table " + tableName + " done.");
} finally {
IOUtils.closeQuietly(admin);
}
}
代码示例来源:origin: apache/hbase
/**
* Set the number of Region replicas.
*/
public static void setReplicas(Admin admin, TableName table, int replicaCount)
throws IOException, InterruptedException {
admin.disableTable(table);
HTableDescriptor desc = new HTableDescriptor(admin.getTableDescriptor(table));
desc.setRegionReplication(replicaCount);
admin.modifyTable(desc.getTableName(), desc);
admin.enableTable(table);
}
代码示例来源:origin: apache/hbase
/**
* Add metadata, and verify that this only affects one table
*/
private void runTestSnapshotMetadataChangesIndependent() throws Exception {
// Add a new column family to the original table
byte[] TEST_FAM_2 = Bytes.toBytes("fam2");
HColumnDescriptor hcd = new HColumnDescriptor(TEST_FAM_2);
admin.disableTable(originalTableName);
admin.addColumnFamily(originalTableName, hcd);
// Verify that it is not in the snapshot
admin.enableTable(originalTableName);
UTIL.waitTableAvailable(originalTableName);
// get a description of the cloned table
// get a list of its families
// assert that the family is there
HTableDescriptor originalTableDescriptor = originalTable.getTableDescriptor();
HTableDescriptor clonedTableDescriptor = admin.getTableDescriptor(cloneTableName);
Assert.assertTrue("The original family was not found. There is something wrong. ",
originalTableDescriptor.hasFamily(TEST_FAM));
Assert.assertTrue("The original family was not found in the clone. There is something wrong. ",
clonedTableDescriptor.hasFamily(TEST_FAM));
Assert.assertTrue("The new family was not found. ",
originalTableDescriptor.hasFamily(TEST_FAM_2));
Assert.assertTrue("The new family was not found. ",
!clonedTableDescriptor.hasFamily(TEST_FAM_2));
}
代码示例来源:origin: apache/hbase
@Test
public void testCreateTableWithDefault() throws IOException {
Admin admin = TEST_UTIL.getAdmin();
// Create a table with one family
HTableDescriptor baseHtd = new HTableDescriptor(TABLE_NAME);
HColumnDescriptor hcd = new HColumnDescriptor(FAMILY);
baseHtd.addFamily(hcd);
admin.createTable(baseHtd);
admin.disableTable(TABLE_NAME);
try {
// Verify the column descriptor
verifyHColumnDescriptor(1, TABLE_NAME, FAMILY);
} finally {
admin.deleteTable(TABLE_NAME);
}
}
代码示例来源:origin: apache/hbase
@Test
public void testDeleteTable() throws Exception {
createTableWithDefaultConf(tableName);
assertTrue(admin.tableExists(tableName).get());
TEST_UTIL.getAdmin().disableTable(tableName);
admin.deleteTable(tableName).join();
assertFalse(admin.tableExists(tableName).get());
}
代码示例来源:origin: apache/hbase
@Test
public void testRollbackAndDoubleExecution() throws Exception {
final TableName tableName = TableName.valueOf(name.getMethodName());
final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
final byte[][] splitKeys =
new byte[][] { Bytes.toBytes("a"), Bytes.toBytes("b"), Bytes.toBytes("c") };
MasterProcedureTestingUtility.createTable(procExec, tableName, splitKeys, "f1", "f2");
UTIL.getAdmin().disableTable(tableName);
ProcedureTestingUtility.waitNoProcedureRunning(procExec);
ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, true);
// Start the Enable procedure && kill the executor
long procId =
procExec.submitProcedure(new EnableTableProcedure(procExec.getEnvironment(), tableName));
int lastStep = 3; // fail before ENABLE_TABLE_SET_ENABLING_TABLE_STATE
MasterProcedureTestingUtility.testRollbackAndDoubleExecution(procExec, procId, lastStep);
MasterProcedureTestingUtility.validateTableIsDisabled(getMaster(), tableName);
}
}
代码示例来源:origin: apache/hbase
@Test
public void testCreateNamespaceAndTable() throws Exception {
Admin admin = TEST_UTIL.getAdmin();
HelloHBase.createNamespaceAndTable(admin);
boolean namespaceExists
= HelloHBase.namespaceExists(admin, HelloHBase.MY_NAMESPACE_NAME);
assertEquals("#createNamespaceAndTable failed to create namespace.",
true, namespaceExists);
boolean tableExists = admin.tableExists(HelloHBase.MY_TABLE_NAME);
assertEquals("#createNamespaceAndTable failed to create table.",
true, tableExists);
admin.disableTable(HelloHBase.MY_TABLE_NAME);
admin.deleteTable(HelloHBase.MY_TABLE_NAME);
admin.deleteNamespace(HelloHBase.MY_NAMESPACE_NAME);
}
代码示例来源:origin: apache/hbase
private static void deleteTable(Configuration conf, String[] args) {
TableName tableName = TableName.valueOf(args[0]);
try (Connection connection = ConnectionFactory.createConnection(conf);
Admin admin = connection.getAdmin()) {
try {
admin.disableTable(tableName);
} catch (TableNotEnabledException e) {
LOG.debug("Dry mode: Table: " + tableName + " already disabled, so just deleting it.");
}
admin.deleteTable(tableName);
} catch (IOException e) {
LOG.error(format("***Dry run: Failed to delete table '%s'.***%n%s", tableName,
e.toString()));
return;
}
LOG.info(format("Dry run: Deleted table '%s'.", tableName));
}
代码示例来源:origin: apache/kylin
private void updateHtable(String tableName) throws IOException {
HTableDescriptor desc = hbaseAdmin.getTableDescriptor(TableName.valueOf(tableName));
if (oldHostValue.equals(desc.getValue(IRealizationConstants.HTableTag))) {
desc.setValue(IRealizationConstants.HTableTag, kylinConfig.getMetadataUrlPrefix());
hbaseAdmin.disableTable(TableName.valueOf(tableName));
hbaseAdmin.modifyTable(TableName.valueOf(tableName), desc);
hbaseAdmin.enableTable(TableName.valueOf(tableName));
updatedResources.add(tableName);
}
}
代码示例来源:origin: apache/hbase
private static void destroy(Admin admin, TableName tableName) throws IOException {
try {
admin.disableTable(tableName);
admin.deleteTable(tableName);
} catch (TableNotFoundException tnfe) {
/* Ignore */
}
}
}
代码示例来源:origin: apache/hbase
@Test
public void createTableInDefaultNamespace() throws Exception {
HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(name.getMethodName()));
HColumnDescriptor colDesc = new HColumnDescriptor("cf1");
desc.addFamily(colDesc);
admin.createTable(desc);
assertTrue(admin.listTables().length == 1);
admin.disableTable(desc.getTableName());
admin.deleteTable(desc.getTableName());
}
内容来源于网络,如有侵权,请联系作者删除!