org.apache.hadoop.hbase.client.Admin#modifyTable ( )源码实例Demo

下面列出了org.apache.hadoop.hbase.client.Admin#modifyTable ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

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();
        }
    }
}
 
源代码2 项目: kylin-on-parquet-v2   文件: CleanHtableCLI.java
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, "[email protected]");
            hbaseAdmin.modifyTable(TableName.valueOf(descriptor.getNameAsString()), descriptor);
        }
    }
    hbaseAdmin.close();
}
 
源代码3 项目: kylin   文件: HtableAlterMetadataCLI.java
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();
        }
    }
}
 
源代码4 项目: phoenix   文件: IndexUpgradeTool.java
private void modifyIndexTable(Admin admin, HashSet<String> indexes)
        throws IOException {
    for (String indexName : indexes) {
        TableDescriptorBuilder indexTableDescBuilder = TableDescriptorBuilder
                .newBuilder(admin.getDescriptor(TableName.valueOf(indexName)));
        if (upgrade) {
            //GlobalIndexChecker needs to be a "lower" priority than all the others so that it
            //goes first. It also doesn't get the codec props the IndexRegionObserver needs
            addCoprocessor(admin, indexName, indexTableDescBuilder, GlobalIndexChecker.class.getName(),
                QueryServicesOptions.DEFAULT_COPROCESSOR_PRIORITY -1, emptyProp);
        } else {
            removeCoprocessor(admin, indexName, indexTableDescBuilder, GlobalIndexChecker.class.getName());
        }
        if (!dryRun) {
            admin.modifyTable(indexTableDescBuilder.build());
        }
    }
}
 
源代码5 项目: hbase   文件: Action.java
/**
 * Apply a transform to all columns in a given table. If there are no columns in a table
 * or if the context is stopping does nothing.
 * @param tableName the table to modify
 * @param transform the modification to perform. Callers will have the
 *                  column name as a string and a column family builder available to them
 */
protected void modifyAllTableColumns(TableName tableName,
  BiConsumer<String, ColumnFamilyDescriptorBuilder> transform) throws IOException {
  HBaseTestingUtility util = this.context.getHBaseIntegrationTestingUtility();
  Admin admin = util.getAdmin();

  TableDescriptor tableDescriptor = admin.getDescriptor(tableName);
  ColumnFamilyDescriptor[] columnDescriptors = tableDescriptor.getColumnFamilies();

  if (columnDescriptors == null || columnDescriptors.length == 0) {
    return;
  }

  TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableDescriptor);
  for (ColumnFamilyDescriptor descriptor : columnDescriptors) {
    ColumnFamilyDescriptorBuilder cfd = ColumnFamilyDescriptorBuilder.newBuilder(descriptor);
    transform.accept(descriptor.getNameAsString(), cfd);
    builder.modifyColumnFamily(cfd.build());
  }

  // Don't try the modify if we're stopping
  if (this.context.isStopping()) {
    return;
  }
  admin.modifyTable(builder.build());
}
 
private static void addCoprocessor(TableName tableName) throws IOException {
  // https://hbase.apache.org/1.1/book.html#cp_loading
  Admin hbaseAdmin = testUtil.getConnection().getAdmin();
  hbaseAdmin.disableTable(tableName);
  HTableDescriptor htd = new HTableDescriptor(tableName);
  htd.addFamily(new HColumnDescriptor(COLUMN_FAMILY));
  htd.addCoprocessor(EnrichmentCoprocessor.class.getCanonicalName());
  hbaseAdmin.modifyTable(tableName, htd);
  hbaseAdmin.enableTable(tableName);
}
 
源代码7 项目: hbase   文件: TestCoprocessorTableEndpoint.java
private static void updateTable(
    final TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor) throws Exception {
  Admin admin = TEST_UTIL.getAdmin();
  admin.disableTable(tableDescriptor.getTableName());
  admin.modifyTable(tableDescriptor);
  admin.enableTable(tableDescriptor.getTableName());
}
 
/**
 * Test a table modification adding a coprocessor path
 * which is whitelisted. The coprocessor should be added to
 * the table descriptor successfully.
 * @param whitelistedPaths A String array of paths to add in
 *         for the whitelisting configuration
 * @param coprocessorPath A String to use as the
 *         path for a mock coprocessor
 */
private static void negativeTestCase(String[] whitelistedPaths,
    String coprocessorPath) throws Exception {
  Configuration conf = UTIL.getConfiguration();
  conf.setInt("hbase.client.retries.number", 5);
  // load coprocessor under test
  conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY,
      CoprocessorWhitelistMasterObserver.class.getName());
  // set retries low to raise exception quickly
  // set a coprocessor whitelist path for test
  conf.setStrings(
      CoprocessorWhitelistMasterObserver.CP_COPROCESSOR_WHITELIST_PATHS_KEY,
      whitelistedPaths);
  UTIL.startMiniCluster();
  UTIL.createTable(TEST_TABLE, new byte[][] { TEST_FAMILY });
  UTIL.waitUntilAllRegionsAssigned(TEST_TABLE);
  Connection connection = ConnectionFactory.createConnection(conf);
  Admin admin = connection.getAdmin();
  // disable table so we do not actually try loading non-existant
  // coprocessor file
  admin.disableTable(TEST_TABLE);
  Table t = connection.getTable(TEST_TABLE);
  HTableDescriptor htd = new HTableDescriptor(t.getDescriptor());
  htd.addCoprocessor("net.clayb.hbase.coprocessor.Whitelisted",
    new Path(coprocessorPath),
    Coprocessor.PRIORITY_USER, null);
  LOG.info("Modifying Table");
  admin.modifyTable(htd);
  assertEquals(1, t.getDescriptor().getCoprocessorDescriptors().size());
  LOG.info("Done Modifying Table");
}
 
源代码9 项目: phoenix   文件: IndexCoprocIT.java
@Test
public void testCreateCoprocs() throws Exception {
    String schemaName = "S" + generateUniqueName();
    String tableName = "T_" + generateUniqueName();
    String indexName = "I_" + generateUniqueName();
    String physicalTableName = SchemaUtil.getPhysicalHBaseTableName(schemaName, tableName,
        isNamespaceMapped).getString();
    String physicalIndexName = SchemaUtil.getPhysicalHBaseTableName(schemaName,
        indexName, isNamespaceMapped).getString();
    Admin admin = ((PhoenixConnection) getConnection()).getQueryServices().getAdmin();

    createBaseTable(schemaName, tableName, isMultiTenant, 0, null);
    createIndexTable(schemaName, tableName, indexName);

    TableDescriptor baseDescriptor = admin.getDescriptor(TableName.valueOf(physicalTableName));
    TableDescriptorBuilder baseDescBuilder = TableDescriptorBuilder.newBuilder(baseDescriptor);
    TableDescriptor indexDescriptor = admin.getDescriptor(TableName.valueOf(physicalIndexName));
    TableDescriptorBuilder indexDescBuilder = TableDescriptorBuilder.newBuilder(indexDescriptor);

    assertCoprocsContains(IndexRegionObserver.class, baseDescriptor);
    assertCoprocsContains(GlobalIndexChecker.class, indexDescriptor);

    removeCoproc(IndexRegionObserver.class, baseDescBuilder, admin);
    removeCoproc(IndexRegionObserver.class, indexDescBuilder, admin);
    removeCoproc(GlobalIndexChecker.class, indexDescBuilder, admin);

    Map<String, String> props = new HashMap<String, String>();
    props.put(NonTxIndexBuilder.CODEC_CLASS_NAME_KEY, PhoenixIndexCodec.class.getName());
    Indexer.enableIndexing(baseDescBuilder, PhoenixIndexBuilder.class,
        props, QueryServicesOptions.DEFAULT_COPROCESSOR_PRIORITY);
    admin.modifyTable(baseDescBuilder.build());
    baseDescriptor = admin.getDescriptor(TableName.valueOf(physicalTableName));
    indexDescriptor = admin.getDescriptor(TableName.valueOf(physicalIndexName));
    assertUsingOldCoprocs(baseDescriptor, indexDescriptor);

    createBaseTable(schemaName, tableName, true, 0, null);
    baseDescriptor = admin.getDescriptor(TableName.valueOf(physicalTableName));
    indexDescriptor = admin.getDescriptor(TableName.valueOf(physicalIndexName));
    assertUsingOldCoprocs(baseDescriptor, indexDescriptor);
}
 
源代码10 项目: phoenix   文件: UpgradeUtil.java
/**
 * Make sure that all tables have necessary column family properties in sync
 * with each other and also in sync with all the table's indexes
 * See PHOENIX-3955
 * @param conn Phoenix connection
 * @param admin HBase admin used for getting existing tables and their descriptors
 * @throws SQLException
 * @throws IOException
 */
public static void syncTableAndIndexProperties(PhoenixConnection conn, Admin admin)
throws SQLException, IOException {
    Set<TableDescriptor> tableDescriptorsToSynchronize = new HashSet<>();
    for (TableDescriptor origTableDesc : admin.listTableDescriptors()) {
        if (MetaDataUtil.isViewIndex(origTableDesc.getTableName().getNameWithNamespaceInclAsString())) {
            // Ignore physical view index tables since we handle them for each base table already
            continue;
        }
        PTable table;
        String fullTableName = SchemaUtil.getPhysicalTableName(
                origTableDesc.getTableName().getName(),
                SchemaUtil.isNamespaceMappingEnabled(
                        null, conn.getQueryServices().getProps())).getNameAsString();
        try {
            // Use this getTable API to get the latest PTable
            table = PhoenixRuntime.getTable(conn, null, fullTableName);
        } catch (TableNotFoundException e) {
            // Ignore tables not mapped to a Phoenix Table
            LOGGER.warn("Error getting PTable for HBase table: " + fullTableName);
            continue;
        }
        if (table.getType() == PTableType.INDEX) {
            // Ignore global index tables since we handle them for each base table already
            continue;
        }
        syncUpdateCacheFreqAllIndexes(conn, table);
        ColumnFamilyDescriptor defaultColFam = origTableDesc.getColumnFamily(SchemaUtil.getEmptyColumnFamily(table));
        Map<String, Object> syncedProps = MetaDataUtil.getSyncedProps(defaultColFam);

        addTableDescIfPropsChanged(origTableDesc, defaultColFam, syncedProps, tableDescriptorsToSynchronize);
        syncGlobalIndexesForTable(conn.getQueryServices(), table, defaultColFam, syncedProps, tableDescriptorsToSynchronize);
        syncViewIndexTable(conn.getQueryServices(), table, defaultColFam, syncedProps, tableDescriptorsToSynchronize);
    }
    for (TableDescriptor t: tableDescriptorsToSynchronize) {
        admin.modifyTable(t);
    }
}
 
源代码11 项目: phoenix   文件: FlappingLocalIndexIT.java
private void testBuildingLocalIndexShouldHandleNoSuchColumnFamilyException(boolean coveredIndex) throws Exception {
    String tableName = schemaName + "." + generateUniqueName();
    String indexName = "IDX_" + generateUniqueName();
    String indexTableName = schemaName + "." + indexName;
    TableName physicalTableName = SchemaUtil.getPhysicalTableName(tableName.getBytes(), isNamespaceMapped);

    createBaseTable(tableName, null, null, coveredIndex ? "cf" : null);
    Connection conn1 = DriverManager.getConnection(getUrl());
    conn1.createStatement().execute("UPSERT INTO "+tableName+" values('b',1,2,4,'z')");
    conn1.createStatement().execute("UPSERT INTO "+tableName+" values('f',1,2,3,'z')");
    conn1.createStatement().execute("UPSERT INTO "+tableName+" values('j',2,4,2,'a')");
    conn1.createStatement().execute("UPSERT INTO "+tableName+" values('q',3,1,1,'c')");
    conn1.commit();
    Admin admin = driver.getConnectionQueryServices(getUrl(), TestUtil.TEST_PROPERTIES).getAdmin();
    TableDescriptor tableDescriptor = admin.getDescriptor(physicalTableName);
    tableDescriptor=TableDescriptorBuilder.newBuilder(tableDescriptor).addCoprocessor(DeleyOpenRegionObserver.class.getName(), null,
        QueryServicesOptions.DEFAULT_COPROCESSOR_PRIORITY - 1, null).build();
    admin.disableTable(physicalTableName);
    admin.modifyTable(tableDescriptor);
    admin.enableTable(physicalTableName);
    DeleyOpenRegionObserver.DELAY_OPEN = true;
    conn1.createStatement().execute(
        "CREATE LOCAL INDEX " + indexName + " ON " + tableName + "(k3)"
                + (coveredIndex ? " include(cf.v1)" : ""));
    DeleyOpenRegionObserver.DELAY_OPEN = false;
    ResultSet rs = conn1.createStatement().executeQuery("SELECT COUNT(*) FROM " + indexTableName);
    assertTrue(rs.next());
    assertEquals(4, rs.getInt(1));
}
 
源代码12 项目: hbase   文件: TestMasterObserver.java
private void modifyTableSync(Admin admin, TableName tableName, TableDescriptor tableDescriptor)
    throws IOException {
  admin.modifyTable(tableDescriptor);
  //wait until modify table finishes
  for (int t = 0; t < 100; t++) { //10 sec timeout
    HTableDescriptor td = new HTableDescriptor(
      admin.getDescriptor(tableDescriptor.getTableName()));
    if (td.equals(tableDescriptor)) {
      break;
    }
    Threads.sleep(100);
  }
}
 
源代码13 项目: phoenix   文件: IndexUpgradeTool.java
private void modifyDataTable(Admin admin, String tableName)
        throws IOException {
    TableDescriptorBuilder tableDescBuilder = TableDescriptorBuilder
            .newBuilder(admin.getDescriptor(TableName.valueOf(tableName)));
    if (upgrade) {
        removeCoprocessor(admin, tableName, tableDescBuilder, Indexer.class.getName());
        addCoprocessor(admin, tableName,  tableDescBuilder, IndexRegionObserver.class.getName());
    } else {
        removeCoprocessor(admin, tableName,  tableDescBuilder, IndexRegionObserver.class.getName());
        addCoprocessor(admin, tableName,  tableDescBuilder, Indexer.class.getName());
    }
    if (!dryRun) {
        admin.modifyTable(tableDescBuilder.build());
    }
}
 
源代码14 项目: kylin-on-parquet-v2   文件: DeployCoprocessorCLI.java
public static boolean resetCoprocessor(String tableName, Admin hbaseAdmin, Path hdfsCoprocessorJar)
        throws IOException {
    KylinConfig kylinConfig = KylinConfig.getInstanceFromEnv();
    HTableDescriptor desc = hbaseAdmin.getTableDescriptor(TableName.valueOf(tableName));

    //when the table has migrated from dev env to test(prod) env, the dev server
    //should not reset the coprocessor of the table.
    String host = desc.getValue(IRealizationConstants.HTableTag);
    if (!host.equalsIgnoreCase(kylinConfig.getMetadataUrlPrefix())) {
        logger.warn("This server doesn't own this table: " + tableName);
        return false;
    }

    logger.info("reset coprocessor on " + tableName);

    logger.info("Disable " + tableName);
    if (hbaseAdmin.isTableEnabled(TableName.valueOf(tableName))) {
        hbaseAdmin.disableTable(TableName.valueOf(tableName));
    }

    while (desc.hasCoprocessor(CubeObserverClassOld2)) {
        desc.removeCoprocessor(CubeObserverClassOld2);
    }
    while (desc.hasCoprocessor(CubeEndpointClass)) {
        desc.removeCoprocessor(CubeEndpointClass);
    }
    while (desc.hasCoprocessor(IIEndpointClass)) {
        desc.removeCoprocessor(IIEndpointClass);
    }
    // remove legacy coprocessor from v1.x
    while (desc.hasCoprocessor(CubeObserverClassOld)) {
        desc.removeCoprocessor(CubeObserverClassOld);
    }
    while (desc.hasCoprocessor(IIEndpointClassOld)) {
        desc.removeCoprocessor(IIEndpointClassOld);
    }
    addCoprocessorOnHTable(desc, hdfsCoprocessorJar);

    // update commit tags
    String commitInfo = KylinVersion.getGitCommitInfo();
    if (!StringUtils.isEmpty(commitInfo)) {
        desc.setValue(IRealizationConstants.HTableGitTag, commitInfo);
    }

    hbaseAdmin.modifyTable(TableName.valueOf(tableName), desc);

    logger.info("Enable " + tableName);
    hbaseAdmin.enableTable(TableName.valueOf(tableName));

    return true;
}
 
源代码15 项目: kylin   文件: DeployCoprocessorCLI.java
public static boolean resetCoprocessor(String tableName, Admin hbaseAdmin, Path hdfsCoprocessorJar)
        throws IOException {
    KylinConfig kylinConfig = KylinConfig.getInstanceFromEnv();
    HTableDescriptor desc = hbaseAdmin.getTableDescriptor(TableName.valueOf(tableName));

    //when the table has migrated from dev env to test(prod) env, the dev server
    //should not reset the coprocessor of the table.
    String host = desc.getValue(IRealizationConstants.HTableTag);
    if (!host.equalsIgnoreCase(kylinConfig.getMetadataUrlPrefix())) {
        logger.warn("This server doesn't own this table: " + tableName);
        return false;
    }

    logger.info("reset coprocessor on " + tableName);

    logger.info("Disable " + tableName);
    if (hbaseAdmin.isTableEnabled(TableName.valueOf(tableName))) {
        hbaseAdmin.disableTable(TableName.valueOf(tableName));
    }

    while (desc.hasCoprocessor(CubeObserverClassOld2)) {
        desc.removeCoprocessor(CubeObserverClassOld2);
    }
    while (desc.hasCoprocessor(CubeEndpointClass)) {
        desc.removeCoprocessor(CubeEndpointClass);
    }
    while (desc.hasCoprocessor(IIEndpointClass)) {
        desc.removeCoprocessor(IIEndpointClass);
    }
    // remove legacy coprocessor from v1.x
    while (desc.hasCoprocessor(CubeObserverClassOld)) {
        desc.removeCoprocessor(CubeObserverClassOld);
    }
    while (desc.hasCoprocessor(IIEndpointClassOld)) {
        desc.removeCoprocessor(IIEndpointClassOld);
    }
    addCoprocessorOnHTable(desc, hdfsCoprocessorJar);

    // update commit tags
    String commitInfo = KylinVersion.getGitCommitInfo();
    if (!StringUtils.isEmpty(commitInfo)) {
        desc.setValue(IRealizationConstants.HTableGitTag, commitInfo);
    }

    hbaseAdmin.modifyTable(TableName.valueOf(tableName), desc);

    logger.info("Enable " + tableName);
    hbaseAdmin.enableTable(TableName.valueOf(tableName));

    return true;
}
 
源代码16 项目: phoenix   文件: MutableIndexReplicationIT.java
@Test
public void testReplicationWithMutableIndexes() throws Exception {
    Connection conn = getConnection();

    //create the primary and index tables
    conn.createStatement().execute(
            "CREATE TABLE " + DATA_TABLE_FULL_NAME
                    + " (k VARCHAR NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR)");
    conn.createStatement().execute(
            "CREATE INDEX " + INDEX_TABLE_NAME + " ON " + DATA_TABLE_FULL_NAME
                    + " (v1)");

    // make sure that the tables are empty, but reachable
    String query = "SELECT * FROM " + DATA_TABLE_FULL_NAME;
    ResultSet rs = conn.createStatement().executeQuery(query);
    assertFalse(rs.next());

    //make sure there is no data in the table
    query = "SELECT * FROM " + INDEX_TABLE_FULL_NAME;
    rs = conn.createStatement().executeQuery(query);
    assertFalse(rs.next());

    // make sure the data tables are created on the remote cluster
    Admin admin = utility1.getAdmin();
    Admin admin2 = utility2.getAdmin();

    List<String> dataTables = new ArrayList<String>();
    dataTables.add(DATA_TABLE_FULL_NAME);
    dataTables.add(INDEX_TABLE_FULL_NAME);
    for (String tableName : dataTables) {
        TableDescriptor desc = admin.getDescriptor(TableName.valueOf(tableName));

        //create it as-is on the remote cluster
        admin2.createTable(desc);

        LOGGER.info("Enabling replication on source table: "+tableName);
        ColumnFamilyDescriptor[] cols = desc.getColumnFamilies();
        assertEquals(1, cols.length);
        // add the replication scope to the column
        ColumnFamilyDescriptor col = ColumnFamilyDescriptorBuilder.newBuilder(cols[0].getName()).setScope(HConstants.REPLICATION_SCOPE_GLOBAL).build();
        desc=TableDescriptorBuilder.newBuilder(desc).removeColumnFamily(cols[0].getName()).addColumnFamily(col).build();
        //disable/modify/enable table so it has replication enabled
        admin.disableTable(desc.getTableName());
        admin.modifyTable(desc);
        admin.enableTable(desc.getTableName());
        LOGGER.info("Replication enabled on source table: "+tableName);
    }


    // load some data into the source cluster table
    PreparedStatement stmt =
            conn.prepareStatement("UPSERT INTO " + DATA_TABLE_FULL_NAME + " VALUES(?,?,?)");
    stmt.setString(1, "a"); // k
    stmt.setString(2, "x"); // v1 <- has index
    stmt.setString(3, "1"); // v2
    stmt.execute();
    conn.commit();

    // make sure the index is working as expected
    query = "SELECT * FROM " + INDEX_TABLE_FULL_NAME;
    rs = conn.createStatement().executeQuery(query);
    assertTrue(rs.next());
    assertEquals("x", rs.getString(1));
    assertFalse(rs.next());
    conn.close();

    /*
     Validate that we have replicated the rows to the remote cluster
    */

    // other table can't be reached through Phoenix right now - would need to change how we
    // lookup tables. For right now, we just go through an HTable
    LOGGER.info("Looking up tables in replication target");
    TableName[] tables = admin2.listTableNames();
    org.apache.hadoop.hbase.client.Connection hbaseConn = ConnectionFactory.createConnection(utility2.getConfiguration());
    Table remoteTable = hbaseConn.getTable(tables[0]);
    for (int i = 0; i < REPLICATION_RETRIES; i++) {
        if (i >= REPLICATION_RETRIES - 1) {
            fail("Waited too much time for put replication on table " + remoteTable
                    .getDescriptor().getTableName());
        }
        if (ensureAnyRows(remoteTable)) {
            break;
        }
        LOGGER.info("Sleeping for " + REPLICATION_WAIT_TIME_MILLIS
                + " for edits to get replicated");
        Thread.sleep(REPLICATION_WAIT_TIME_MILLIS);
    }
    remoteTable.close();
}
 
private void deleteCf(Admin admin) throws IOException {
  TableDescriptor desc = createTableDescriptor(NORMAL_CF);
  admin.modifyTable(desc);
}
 
源代码18 项目: hbase   文件: IntegrationTestDDLMasterFailover.java
@Override
void perform() throws IOException {
  TableDescriptor selected = selectTable(disabledTables);
  if (selected == null) {
    return;
  }
  ColumnFamilyDescriptor columnDesc = selectFamily(selected);
  if (columnDesc == null){
    return;
  }

  Admin admin = connection.getAdmin();
  int versions = RandomUtils.nextInt(0, 10) + 3;
  try {
    TableName tableName = selected.getTableName();
    LOG.info("Altering versions of column family: " + columnDesc + " to: " + versions +
        " in table: " + tableName);

    ColumnFamilyDescriptor cfd = ColumnFamilyDescriptorBuilder.newBuilder(columnDesc)
        .setMinVersions(versions)
        .setMaxVersions(versions)
        .build();
    TableDescriptor td = TableDescriptorBuilder.newBuilder(selected)
        .modifyColumnFamily(cfd)
        .build();
    admin.modifyTable(td);

    // assertion
    TableDescriptor freshTableDesc = admin.getDescriptor(tableName);
    ColumnFamilyDescriptor freshColumnDesc = freshTableDesc.getColumnFamily(columnDesc.getName());
    Assert.assertEquals("Column family: " + columnDesc + " was not altered",
        freshColumnDesc.getMaxVersions(), versions);
    Assert.assertEquals("Column family: " + freshColumnDesc + " was not altered",
        freshColumnDesc.getMinVersions(), versions);
    Assert.assertTrue(
      "After alter versions of column family, Table: " + tableName + " is not disabled",
      admin.isTableDisabled(tableName));
    disabledTables.put(tableName, freshTableDesc);
    LOG.info("Altered versions of column family: " + columnDesc + " to: " + versions +
      " in table: " + tableName);
  } catch (Exception e) {
    LOG.warn("Caught exception in action: " + this.getClass());
    throw e;
  } finally {
    admin.close();
  }
}
 
源代码19 项目: hbase   文件: IntegrationTestDDLMasterFailover.java
@Override
void perform() throws IOException {
  TableDescriptor selected = selectTable(disabledTables);
  if (selected == null) {
    return;
  }
  ColumnFamilyDescriptor columnDesc = selectFamily(selected);
  if (columnDesc == null){
    return;
  }

  Admin admin = connection.getAdmin();
  try {
    TableName tableName = selected.getTableName();
    // possible DataBlockEncoding ids
    DataBlockEncoding[] possibleIds = {DataBlockEncoding.NONE, DataBlockEncoding.PREFIX,
            DataBlockEncoding.DIFF, DataBlockEncoding.FAST_DIFF, DataBlockEncoding.ROW_INDEX_V1};
    short id = possibleIds[RandomUtils.nextInt(0, possibleIds.length)].getId();
    LOG.info("Altering encoding of column family: " + columnDesc + " to: " + id +
        " in table: " + tableName);

    ColumnFamilyDescriptor cfd = ColumnFamilyDescriptorBuilder.newBuilder(columnDesc)
        .setDataBlockEncoding(DataBlockEncoding.getEncodingById(id))
        .build();
    TableDescriptor td = TableDescriptorBuilder.newBuilder(selected)
        .modifyColumnFamily(cfd)
        .build();
    admin.modifyTable(td);

    // assertion
    TableDescriptor freshTableDesc = admin.getDescriptor(tableName);
    ColumnFamilyDescriptor freshColumnDesc = freshTableDesc.getColumnFamily(columnDesc.getName());
    Assert.assertEquals("Encoding of column family: " + columnDesc + " was not altered",
        freshColumnDesc.getDataBlockEncoding().getId(), id);
    Assert.assertTrue(
      "After alter encoding of column family, Table: " + tableName + " is not disabled",
      admin.isTableDisabled(tableName));
    disabledTables.put(tableName, freshTableDesc);
    LOG.info("Altered encoding of column family: " + freshColumnDesc + " to: " + id +
      " in table: " + tableName);
  } catch (Exception e) {
    LOG.warn("Caught exception in action: " + this.getClass());
    throw e;
  } finally {
    admin.close();
  }
}
 
源代码20 项目: hbase   文件: HBaseTestingUtility.java
/**
 * Modify a table, synchronous.
 * @deprecated since 3.0.0 and will be removed in 4.0.0. Just use
 *   {@link Admin#modifyTable(TableDescriptor)} directly as it is synchronous now.
 * @see Admin#modifyTable(TableDescriptor)
 * @see <a href="https://issues.apache.org/jira/browse/HBASE-22002">HBASE-22002</a>
 */
@Deprecated
public static void modifyTableSync(Admin admin, TableDescriptor desc)
    throws IOException, InterruptedException {
  admin.modifyTable(desc);
}