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); } }
void modifyTableSync(Connection conn, TableDescriptor desc) throws IOException { try (Admin admin = conn.getAdmin()) { admin.modifyTable(desc); int attempt = 0; int maxAttempts = 600; while (!admin.isTableAvailable(desc.getTableName())) { Thread.sleep(100); attempt++; if (attempt++ > maxAttempts) { throw new IOException("Timeout expired " + (maxAttempts * 100) + "ms"); } } } catch (Exception e) { throw new IOException(e); } }
@Override public void modifyTable(TTableDescriptor desc) throws TIOError, TException { try { TableDescriptor descriptor = tableDescriptorFromThrift(desc); connectionCache.getAdmin().modifyTable(descriptor); } catch (IOException e) { throw getTIOError(e); } }
private void clean() throws IOException { Connection conn = HBaseConnection.get(KylinConfig.getInstanceFromEnv().getStorageUrl()); Admin hbaseAdmin = conn.getAdmin(); for (HTableDescriptor descriptor : hbaseAdmin.listTables()) { String name = descriptor.getNameAsString().toLowerCase(Locale.ROOT); if (name.startsWith("kylin") || name.startsWith("_kylin")) { String x = descriptor.getValue(IRealizationConstants.HTableTag); System.out.println("table name " + descriptor.getNameAsString() + " host: " + x); System.out.println(descriptor); System.out.println(); descriptor.setValue(IRealizationConstants.HTableOwner, "whoami@kylin.apache.org"); hbaseAdmin.modifyTable(TableName.valueOf(descriptor.getNameAsString()), descriptor); } } hbaseAdmin.close(); }
private void alterForPolicyTest(final MobCompactPartitionPolicy type) throws Exception { hcd1.setMobCompactPartitionPolicy(type); desc.modifyFamily(hcd1); admin.modifyTable(tableName, desc); Pair<Integer, Integer> st; while (null != (st = admin.getAlterStatus(tableName)) && st.getFirst() > 0) { LOG.debug(st.getFirst() + " regions left to update"); Thread.sleep(40); } LOG.info("alter status finished"); }
@Test public void testPartialSuccess() throws IOException, InterruptedException, ExecutionException { Admin admin = TEST_UTIL.getAdmin(); TableDescriptor htd = TableDescriptorBuilder.newBuilder(admin.getDescriptor(TABLE_NAME)) .setCoprocessor(ErrorInjectObserver.class.getName()).build(); admin.modifyTable(htd); AsyncTable<?> table = tableGetter.apply(TABLE_NAME); table.putAll(Arrays.asList(SPLIT_KEYS).stream().map(k -> new Put(k).addColumn(FAMILY, CQ, k)) .collect(Collectors.toList())).get(); List<CompletableFuture<Result>> futures = table .get(Arrays.asList(SPLIT_KEYS).stream().map(k -> new Get(k)).collect(Collectors.toList())); for (int i = 0; i < SPLIT_KEYS.length - 1; i++) { assertArrayEquals(SPLIT_KEYS[i], futures.get(i).get().getValue(FAMILY, CQ)); } try { futures.get(SPLIT_KEYS.length - 1).get(); } catch (ExecutionException e) { assertThat(e.getCause(), instanceOf(RetriesExhaustedException.class)); } } }
@Test public void testModifyTable() throws IOException { Admin admin = TEST_UTIL.getAdmin(); // Create a table with one family HTableDescriptor baseHtd = new HTableDescriptor(TABLE_NAME); baseHtd.addFamily(new HColumnDescriptor(FAMILY_0)); admin.createTable(baseHtd); admin.disableTable(TABLE_NAME); try { // Verify the table descriptor verifyTableDescriptor(TABLE_NAME, FAMILY_0); // Modify the table adding another family and verify the descriptor HTableDescriptor modifiedHtd = new HTableDescriptor(TABLE_NAME); modifiedHtd.addFamily(new HColumnDescriptor(FAMILY_0)); modifiedHtd.addFamily(new HColumnDescriptor(FAMILY_1)); admin.modifyTable(TABLE_NAME, modifiedHtd); verifyTableDescriptor(TABLE_NAME, FAMILY_0, FAMILY_1); } finally { admin.deleteTable(TABLE_NAME); } }
@Override public void perform() throws Exception { HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility(); Admin admin = util.getAdmin(); LOG.info("Performing action: Change split policy of table " + tableName); TableDescriptor tableDescriptor = admin.getDescriptor(tableName); TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableDescriptor); String chosenPolicy = possiblePolicies[random.nextInt(possiblePolicies.length)]; builder.setRegionSplitPolicyClassName(chosenPolicy); LOG.info("Changing " + tableName + " split policy to " + chosenPolicy); admin.modifyTable(builder.build()); } }
/** * 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 modifyTableSync(Admin admin, TableName tableName, HTableDescriptor htd) throws IOException { admin.modifyTable(tableName, htd); //wait until modify table finishes for (int t = 0; t < 100; t++) { //10 sec timeout HTableDescriptor td = admin.getTableDescriptor(htd.getTableName()); if (td.equals(htd)) { break; } Threads.sleep(100); } }
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(); } } }
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()); }
@Test(expected = DoNotRetryIOException.class) public void testModifyTableWithZeroRegionReplicas() throws Exception { TableName tableName = TableName.valueOf(name.getMethodName()); TableDescriptor desc = TableDescriptorBuilder.newBuilder(tableName) .setColumnFamily(ColumnFamilyDescriptorBuilder.of(Bytes.toBytes("cf"))) .build(); TEST_UTIL.getAdmin().createTable(desc); TableDescriptor newDesc = TableDescriptorBuilder.newBuilder(desc) .setRegionReplication(0) .build(); TEST_UTIL.getAdmin().modifyTable(newDesc); } }
@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()); } }
@Override public void perform() throws Exception { TableDescriptor tableDescriptor = admin.getDescriptor(tableName); ColumnFamilyDescriptor columnDescriptor = null; while (columnDescriptor == null || tableDescriptor.getColumnFamily(columnDescriptor.getName()) != null) { columnDescriptor = ColumnFamilyDescriptorBuilder.of(RandomStringUtils.randomAlphabetic(5)); } // Don't try the modify if we're stopping if (context.isStopping()) { return; } LOG.debug("Performing action: Adding " + columnDescriptor + " to " + tableName); TableDescriptor modifiedTable = TableDescriptorBuilder.newBuilder(tableDescriptor) .setColumnFamily(columnDescriptor).build(); admin.modifyTable(modifiedTable); } }
/** * Verify schema change for read only table */ @Test public void testReadOnlyTableModify() throws IOException, InterruptedException { final TableName tableName = TableName.valueOf(name.getMethodName()); TEST_UTIL.createTable(tableName, HConstants.CATALOG_FAMILY).close(); // Make table read only TableDescriptor htd = TableDescriptorBuilder.newBuilder(this.admin.getDescriptor(tableName)) .setReadOnly(true).build(); admin.modifyTable(htd); // try to modify the read only table now htd = TableDescriptorBuilder.newBuilder(this.admin.getDescriptor(tableName)) .setCompactionEnabled(false).build(); admin.modifyTable(htd); // Delete the table this.admin.disableTable(tableName); this.admin.deleteTable(tableName); assertFalse(this.admin.tableExists(tableName)); }
@Test public void testModifyTableOnTableWithRegionReplicas() throws Exception { TableName tableName = TableName.valueOf(name.getMethodName()); TableDescriptor desc = TableDescriptorBuilder.newBuilder(tableName) .setColumnFamily(ColumnFamilyDescriptorBuilder.of(Bytes.toBytes("cf"))) .setRegionReplication(5) .build(); admin.createTable(desc); int maxFileSize = 10000000; TableDescriptor newDesc = TableDescriptorBuilder.newBuilder(desc) .setMaxFileSize(maxFileSize) .build(); admin.modifyTable(newDesc); TableDescriptor newTableDesc = admin.getDescriptor(tableName); assertEquals(maxFileSize, newTableDesc.getMaxFileSize()); } }
@Test public void testMasterObserverToModifyTableSchema() throws IOException { TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(TABLENAME); for (int i = 1; i <= 3; i++) { builder.setColumnFamily( ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("cf" + i)).setMaxVersions(i) .build()); } try (Admin admin = UTIL.getAdmin()) { admin.createTable(builder.build()); assertOneVersion(admin.getDescriptor(TABLENAME)); builder.modifyColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("cf1")) .setMaxVersions(Integer.MAX_VALUE).build()); admin.modifyTable(builder.build()); assertOneVersion(admin.getDescriptor(TABLENAME)); } }
@Test(expected = TableNotDisabledException.class) public void testModifyRegionReplicasEnabledTable() throws Exception { final TableName tableName = TableName.valueOf(name.getMethodName()); TEST_UTIL.createTable(tableName, HConstants.CATALOG_FAMILY).close(); // Modify region replication count TableDescriptor htd = TableDescriptorBuilder.newBuilder(admin.getDescriptor(tableName)) .setRegionReplication(3).build(); try { // try to modify the region replication count without disabling the table admin.modifyTable(htd); fail("Expected an exception"); } finally { // Delete the table admin.disableTable(tableName); admin.deleteTable(tableName); assertFalse(admin.tableExists(tableName)); } }