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

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

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

Admin.modifyTable介绍

[英]Modify an existing table, more IRB friendly version. Asynchronous operation. This means that it may be a while before your schema change is updated across all of the table.
[中]修改现有表,更为IRB友好的版本。异步操作。这意味着在整个表中更新模式更改之前可能需要一段时间。

代码示例

代码示例来源: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

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

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

@Override
public void modifyTable(TTableDescriptor desc) throws TIOError, TException {
 try {
  TableDescriptor descriptor = tableDescriptorFromThrift(desc);
  connectionCache.getAdmin().modifyTable(descriptor);
 } catch (IOException e) {
  throw getTIOError(e);
 }
}

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

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

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

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

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

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

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

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

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

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

代码示例来源: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

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

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

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

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

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

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

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

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

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

代码示例来源: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/hbase

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

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

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

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

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

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

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

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

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

相关文章

Admin类方法