Java Code Examples for org.apache.hadoop.hbase.client.Admin#addColumnFamily()

The following examples show how to use org.apache.hadoop.hbase.client.Admin#addColumnFamily() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestTableDescriptorModificationFromClient.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddColumn() throws IOException {
  Admin admin = TEST_UTIL.getAdmin();
  // Create a table with two families
  TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(TABLE_NAME);

  tableDescriptor.setColumnFamily(
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(FAMILY_0));
  admin.createTable(tableDescriptor);
  admin.disableTable(TABLE_NAME);
  try {
    // Verify the table descriptor
    verifyTableDescriptor(TABLE_NAME, FAMILY_0);

    // Modify the table removing one family and verify the descriptor
    admin.addColumnFamily(TABLE_NAME,
      new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(FAMILY_1));
    verifyTableDescriptor(TABLE_NAME, FAMILY_0, FAMILY_1);
  } finally {
    admin.deleteTable(TABLE_NAME);
  }
}
 
Example 2
Source File: TestTableDescriptorModificationFromClient.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddSameColumnFamilyTwice() throws IOException {
  Admin admin = TEST_UTIL.getAdmin();
  // Create a table with one families
  TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(TABLE_NAME);

  tableDescriptor.setColumnFamily(
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(FAMILY_0));
  admin.createTable(tableDescriptor);
  admin.disableTable(TABLE_NAME);
  try {
    // Verify the table descriptor
    verifyTableDescriptor(TABLE_NAME, FAMILY_0);

    // Modify the table removing one family and verify the descriptor
    admin.addColumnFamily(TABLE_NAME,
      new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(FAMILY_1));
    verifyTableDescriptor(TABLE_NAME, FAMILY_0, FAMILY_1);

    try {
      // Add same column family again - expect failure
      admin.addColumnFamily(TABLE_NAME,
        new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(FAMILY_1));
      Assert.fail("Delete a non-exist column family should fail");
    } catch (InvalidFamilyOperationException e) {
      // Expected.
    }

  } finally {
    admin.deleteTable(TABLE_NAME);
  }
}
 
Example 3
Source File: IntegrationTestDDLMasterFailover.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
void perform() throws IOException {
  TableDescriptor selected = selectTable(disabledTables);
  if (selected == null) {
    return;
  }

  Admin admin = connection.getAdmin();
  try {
    ColumnFamilyDescriptor cfd = createFamilyDesc();
    if (selected.hasColumnFamily(cfd.getName())){
      LOG.info(new String(cfd.getName()) + " already exists in table "
          + selected.getTableName());
      return;
    }
    TableName tableName = selected.getTableName();
    LOG.info("Adding column family: " + cfd + " to table: " + tableName);
    admin.addColumnFamily(tableName, cfd);
    // assertion
    TableDescriptor freshTableDesc = admin.getDescriptor(tableName);
    Assert.assertTrue("Column family: " + cfd + " was not added",
        freshTableDesc.hasColumnFamily(cfd.getName()));
    Assert.assertTrue(
      "After add column family, Table: " + tableName + " is not disabled",
      admin.isTableDisabled(tableName));
    disabledTables.put(tableName, freshTableDesc);
    LOG.info("Added column family: " + cfd + " to table: " + tableName);
  } catch (Exception e) {
    LOG.warn("Caught exception in action: " + this.getClass());
    throw e;
  } finally {
    admin.close();
  }
}
 
Example 4
Source File: TestHBaseMetaEdit.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * Set versions, set HBASE-16213 indexed block encoding, and add a column family.
 * Delete the column family. Then try to delete a core hbase:meta family (should fail).
 * Verify they are all in place by looking at TableDescriptor AND by checking
 * what the RegionServer sees after opening Region.
 */
@Test
public void testEditMeta() throws IOException {
  Admin admin = UTIL.getAdmin();
  admin.tableExists(TableName.META_TABLE_NAME);
  TableDescriptor originalDescriptor = getMetaDescriptor();
  ColumnFamilyDescriptor cfd = originalDescriptor.getColumnFamily(HConstants.CATALOG_FAMILY);
  int oldVersions = cfd.getMaxVersions();
  // Add '1' to current versions count. Set encoding too.
  cfd = ColumnFamilyDescriptorBuilder.newBuilder(cfd).setMaxVersions(oldVersions + 1).
      setConfiguration(ColumnFamilyDescriptorBuilder.DATA_BLOCK_ENCODING,
          DataBlockEncoding.ROW_INDEX_V1.toString()).build();
  admin.modifyColumnFamily(TableName.META_TABLE_NAME, cfd);
  byte [] extraColumnFamilyName = Bytes.toBytes("xtra");
  ColumnFamilyDescriptor newCfd =
    ColumnFamilyDescriptorBuilder.newBuilder(extraColumnFamilyName).build();
  admin.addColumnFamily(TableName.META_TABLE_NAME, newCfd);
  TableDescriptor descriptor = getMetaDescriptor();
  // Assert new max versions is == old versions plus 1.
  assertEquals(oldVersions + 1,
      descriptor.getColumnFamily(HConstants.CATALOG_FAMILY).getMaxVersions());
  descriptor = getMetaDescriptor();
  // Assert new max versions is == old versions plus 1.
  assertEquals(oldVersions + 1,
      descriptor.getColumnFamily(HConstants.CATALOG_FAMILY).getMaxVersions());
  assertTrue(descriptor.getColumnFamily(newCfd.getName()) != null);
  String encoding = descriptor.getColumnFamily(HConstants.CATALOG_FAMILY).getConfiguration().
      get(ColumnFamilyDescriptorBuilder.DATA_BLOCK_ENCODING);
  assertEquals(encoding, DataBlockEncoding.ROW_INDEX_V1.toString());
  Region r = UTIL.getHBaseCluster().getRegionServer(0).
      getRegion(RegionInfoBuilder.FIRST_META_REGIONINFO.getEncodedName());
  assertEquals(oldVersions + 1,
      r.getStore(HConstants.CATALOG_FAMILY).getColumnFamilyDescriptor().getMaxVersions());
  encoding = r.getStore(HConstants.CATALOG_FAMILY).getColumnFamilyDescriptor().
      getConfigurationValue(ColumnFamilyDescriptorBuilder.DATA_BLOCK_ENCODING);
  assertEquals(encoding, DataBlockEncoding.ROW_INDEX_V1.toString());
  assertTrue(r.getStore(extraColumnFamilyName) != null);
  // Assert we can't drop critical hbase:meta column family but we can drop any other.
  admin.deleteColumnFamily(TableName.META_TABLE_NAME, newCfd.getName());
  descriptor = getMetaDescriptor();
  assertTrue(descriptor.getColumnFamily(newCfd.getName()) == null);
  try {
    admin.deleteColumnFamily(TableName.META_TABLE_NAME, HConstants.CATALOG_FAMILY);
    fail("Should not reach here");
  } catch (HBaseIOException hioe) {
    assertTrue(hioe.getMessage().contains("Delete of hbase:meta"));
  }
}
 
Example 5
Source File: TestRestoreSnapshotProcedure.java    From hbase with Apache License 2.0 4 votes vote down vote up
private void setupSnapshotAndUpdateTable() throws Exception {
  long tid = System.currentTimeMillis();
  final String snapshotName = "snapshot-" + tid;
  Admin admin = UTIL.getAdmin();
  // create Table
  SnapshotTestingUtils.createTable(UTIL, snapshotTableName, getNumReplicas(), CF1, CF2);
  // Load data
  SnapshotTestingUtils.loadData(UTIL, snapshotTableName, rowCountCF1, CF1);
  SnapshotTestingUtils.loadData(UTIL, snapshotTableName, rowCountCF2, CF2);
  SnapshotTestingUtils.verifyRowCount(UTIL, snapshotTableName, rowCountCF1 + rowCountCF2);

  snapshotHTD = admin.getDescriptor(snapshotTableName);

  admin.disableTable(snapshotTableName);
  // take a snapshot
  admin.snapshot(snapshotName, snapshotTableName);

  List<SnapshotDescription> snapshotList = admin.listSnapshots();
  snapshot = ProtobufUtil.createHBaseProtosSnapshotDesc(snapshotList.get(0));

  // modify the table
  ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor columnFamilyDescriptor3 =
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(CF3);
  ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor columnFamilyDescriptor4 =
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(CF4);
  admin.addColumnFamily(snapshotTableName, columnFamilyDescriptor3);
  admin.addColumnFamily(snapshotTableName, columnFamilyDescriptor4);
  admin.deleteColumnFamily(snapshotTableName, CF2);
  // enable table and insert data
  admin.enableTable(snapshotTableName);
  SnapshotTestingUtils.loadData(UTIL, snapshotTableName, rowCountCF3, CF3);
  SnapshotTestingUtils.loadData(UTIL, snapshotTableName, rowCountCF4, CF4);
  SnapshotTestingUtils.loadData(UTIL, snapshotTableName, rowCountCF1addition, CF1);
  HTableDescriptor currentHTD = new HTableDescriptor(admin.getDescriptor(snapshotTableName));
  assertTrue(currentHTD.hasFamily(CF1));
  assertFalse(currentHTD.hasFamily(CF2));
  assertTrue(currentHTD.hasFamily(CF3));
  assertTrue(currentHTD.hasFamily(CF4));
  assertNotEquals(currentHTD.getFamiliesKeys().size(), snapshotHTD.getColumnFamilies().length);
  SnapshotTestingUtils.verifyRowCount(
    UTIL, snapshotTableName, rowCountCF1 + rowCountCF3 + rowCountCF4 + rowCountCF1addition);
  admin.disableTable(snapshotTableName);
}