@Override public void enableTable(String tableString) throws IOException { adm.enableTable(TableName.valueOf(tableString)); }
@Override public void enableTable(ByteBuffer tableName) throws IOError { try{ getAdmin().enableTable(getTableName(tableName)); } catch (IOException e) { LOG.warn(e.getMessage(), e); throw getIOError(e); } }
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); } }
@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 disable() throws IOException { try { if (LOG.isTraceEnabled()) { LOG.trace("Starting enable of " + getTableName()); } getRegionServerServices().getClusterConnection().getAdmin().enableTable(getTableName()); if (LOG.isTraceEnabled()) { LOG.trace("Enable is complete for " + getTableName()); } } catch (TableNotDisabledException | TableNotFoundException e) { // The state we wanted it to be in // Or, in case table is not found, nothing to do } }
@Override public void enableTable(TTableName tableName) throws TIOError, TException { try { TableName table = tableNameFromThrift(tableName); connectionCache.getAdmin().enableTable(table); } catch (IOException e) { throw getTIOError(e); } }
/** * Can't enable a table if the table isn't in disabled state * @throws IOException */ @Test (expected=TableNotDisabledException.class) public void testTableNotDisabledExceptionWithATable() throws IOException { final TableName name = TableName.valueOf(this.name.getMethodName()); Table t = TEST_UTIL.createTable(name, HConstants.CATALOG_FAMILY); try { this.admin.enableTable(name); }finally { t.close(); } }
/** * 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); }
private void alter() throws IOException { Connection conn = HBaseConnection.get(KylinConfig.getInstanceFromEnv().getStorageUrl()); Admin hbaseAdmin = null; try { hbaseAdmin = conn.getAdmin(); HTableDescriptor table = hbaseAdmin.getTableDescriptor(TableName.valueOf(tableName)); hbaseAdmin.disableTable(table.getTableName()); table.setValue(metadataKey, metadataValue); hbaseAdmin.modifyTable(table.getTableName(), table); hbaseAdmin.enableTable(table.getTableName()); } finally { if (hbaseAdmin != null) { hbaseAdmin.close(); } } }
/** * Takes the snapshot of originalTable and clones the snapshot to another tables. * If {@code online} is false, the original table is disabled during taking snapshot, so also * enables it again. * @param online - Whether the table is online or not during the snapshot */ private void createAndCloneSnapshot(boolean online) throws Exception { SnapshotTestingUtils.createSnapshotAndValidate(admin, originalTableName, TEST_FAM_STR, snapshotNameAsString, rootDir, fs, online); // If offline, enable the table disabled by snapshot testing util. if (!online) { admin.enableTable(originalTableName); UTIL.waitTableAvailable(originalTableName); } admin.cloneSnapshot(snapshotName, cloneTableName); UTIL.waitUntilAllRegionsAssigned(cloneTableName); }
protected static void waitUntilAllReplicasHaveRow(byte[] row) throws IOException { // this is the fastest way to let all replicas have the row TEST_UTIL.getAdmin().disableTable(TABLE_NAME); TEST_UTIL.getAdmin().enableTable(TABLE_NAME); TEST_UTIL.waitFor(30000, () -> allReplicasHaveRow(row)); }
private static void updateTable(HTableDescriptor desc) throws Exception { Admin admin = TEST_UTIL.getAdmin(); admin.disableTable(desc.getTableName()); admin.modifyTable(desc.getTableName(), desc); admin.enableTable(desc.getTableName()); }
@Test public void disableNotFullReplication() throws Exception { HTableDescriptor table = new HTableDescriptor(admin2.getTableDescriptor(tableName)); HColumnDescriptor f = new HColumnDescriptor("notReplicatedFamily"); table.addFamily(f); admin1.disableTable(tableName); admin1.modifyTable(tableName, table); admin1.enableTable(tableName); admin1.disableTableReplication(tableName); table = admin1.getTableDescriptor(tableName); for (HColumnDescriptor fam : table.getColumnFamilies()) { assertEquals(HConstants.REPLICATION_SCOPE_LOCAL, fam.getScope()); } admin1.deleteColumnFamily(table.getTableName(), f.getName()); }
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)); } }
@Override protected void initTable() throws IOException { super.initTable(); TableName tableName = getTablename(); try (Connection connection = ConnectionFactory.createConnection(); Admin admin = connection.getAdmin()) { HTableDescriptor tableDesc = admin.getTableDescriptor(tableName); LOG.info("Disabling table " + getTablename()); admin.disableTable(tableName); ColumnFamilyDescriptor mobColumn = tableDesc.getColumnFamily(mobColumnFamily); ColumnFamilyDescriptor cfd = ColumnFamilyDescriptorBuilder.newBuilder(mobColumn) .setMobEnabled(true) .setMobThreshold((long) threshold) .build(); admin.modifyColumnFamily(tableName, cfd); LOG.info("Enabling table " + getTablename()); admin.enableTable(tableName); } }
@Test public void testRegionReplicasCreatedAreDistributed() throws Exception { try { checkAndAssertRegionDistribution(false); // now diesbale and enable the table again. It should be truly distributed HTU.getAdmin().disableTable(table.getName()); LOG.info("Disabled the table " + table.getName()); LOG.info("enabling the table " + table.getName()); HTU.getAdmin().enableTable(table.getName()); LOG.info("Enabled the table " + table.getName()); boolean res = checkAndAssertRegionDistribution(true); assertTrue("Region retainment not done ", res); } finally { HTU.getAdmin().disableTable(table.getName()); HTU.getAdmin().deleteTable(table.getName()); } }
private void validateSnapshotRestore() throws IOException { try { UTIL.getAdmin().enableTable(snapshotTableName); HTableDescriptor currentHTD = UTIL.getAdmin().getTableDescriptor(snapshotTableName); assertTrue(currentHTD.hasFamily(CF1)); assertTrue(currentHTD.hasFamily(CF2)); assertFalse(currentHTD.hasFamily(CF3)); assertFalse(currentHTD.hasFamily(CF4)); assertEquals(currentHTD.getFamiliesKeys().size(), snapshotHTD.getFamiliesKeys().size()); SnapshotTestingUtils.verifyRowCount(UTIL, snapshotTableName, rowCountCF1 + rowCountCF2); } finally { UTIL.getAdmin().disableTable(snapshotTableName); } } }
@Test public void testRestoreSnapshotToEnabledTable() throws Exception { final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); try { UTIL.getAdmin().enableTable(snapshotTableName); long procId = ProcedureTestingUtility.submitAndWait( procExec, new RestoreSnapshotProcedure(procExec.getEnvironment(), snapshotHTD, snapshot)); Procedure<?> result = procExec.getResult(procId); assertTrue(result.isFailed()); LOG.debug("Restore snapshot failed with exception: " + result.getException()); assertTrue( ProcedureTestingUtility.getExceptionCause(result) instanceof TableNotDisabledException); } finally { UTIL.getAdmin().disableTable(snapshotTableName); } }
@Test public void testCloneAndRestoreSnapshot() throws IOException, InterruptedException { TEST_UTIL.deleteTable(tableName); waitCleanerRun(); admin.cloneSnapshot(snapshotName0, tableName); verifyRowCount(TEST_UTIL, tableName, snapshot0Rows); SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas()); waitCleanerRun(); admin.disableTable(tableName); admin.restoreSnapshot(snapshotName0); admin.enableTable(tableName); verifyRowCount(TEST_UTIL, tableName, snapshot0Rows); SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas()); }
/** * Tests the case where if there is some data in the primary region, reopening the region replicas * (enable/disable table, etc) makes the region replicas readable. * @throws IOException */ @Test public void testSecondaryRegionWithNonEmptyRegion() throws IOException { // Create a new table with region replication and load some data // than disable and enable the table again and verify the data from secondary try (Connection connection = ConnectionFactory.createConnection(HTU.getConfiguration()); Table table = connection.getTable(htd.getTableName())) { HTU.loadNumericRows(table, fam, 0, 1000); HTU.getAdmin().disableTable(htd.getTableName()); HTU.getAdmin().enableTable(htd.getTableName()); HTU.verifyNumericRows(table, fam, 0, 1000, 1); } }