Java Code Examples for org.apache.hadoop.hbase.client.TableDescriptorBuilder

The following examples show how to use org.apache.hadoop.hbase.client.TableDescriptorBuilder. These examples are extracted from open source projects. 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 Project: ambari-metrics   Source File: PhoenixHBaseAccessor.java    License: Apache License 2.0 6 votes vote down vote up
private boolean setDurabilityForTable(String tableName, TableDescriptorBuilder tableDescriptorBuilder, TableDescriptor tableDescriptor) {
  String tableDurability = metricsConf.get("timeline.metrics." + tableName + ".durability", "");

  if (StringUtils.isEmpty(tableDurability) || tableDescriptor.getDurability().toString().equals(tableDurability)) {
    return false;
  }

  if (StringUtils.isNotEmpty(tableDurability)) {
    LOG.info("Setting WAL option " + tableDurability + " for table : " + tableName);
    boolean validDurability = true;
    if ("SKIP_WAL".equals(tableDurability)) {
      tableDescriptorBuilder.setDurability(Durability.SKIP_WAL);
    } else if ("SYNC_WAL".equals(tableDurability)) {
      tableDescriptorBuilder.setDurability(Durability.SYNC_WAL);
    } else if ("ASYNC_WAL".equals(tableDurability)) {
      tableDescriptorBuilder.setDurability(Durability.ASYNC_WAL);
    } else if ("FSYNC_WAL".equals(tableDurability)) {
      tableDescriptorBuilder.setDurability(Durability.FSYNC_WAL);
    } else {
      LOG.info("Unknown value for durability : " + tableDurability);
      validDurability = false;
    }
    return validDurability;
  }
  return false;
}
 
Example 2
Source Project: hbase   Source File: RowResourceBase.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void beforeMethod() throws Exception {
  Admin admin = TEST_UTIL.getAdmin();
  if (admin.tableExists(TABLE_NAME)) {
    TEST_UTIL.deleteTable(TABLE_NAME);
  }
  TableDescriptorBuilder tableDescriptorBuilder =
    TableDescriptorBuilder.newBuilder(TableName.valueOf(TABLE));
  ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder
    .newBuilder(Bytes.toBytes(CFA)).build();
  tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
  columnFamilyDescriptor = ColumnFamilyDescriptorBuilder
    .newBuilder(Bytes.toBytes(CFB)).build();
  tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
  admin.createTable(tableDescriptorBuilder.build());
}
 
Example 3
Source Project: phoenix-tephra   Source File: TransactionProcessorTest.java    License: Apache License 2.0 6 votes vote down vote up
private HRegion updateTtl(HRegion region, byte[] family, long ttl) throws Exception {
  region.close();
  TableDescriptorBuilder tableBuilder =
      TableDescriptorBuilder.newBuilder(region.getTableDescriptor());
  ColumnFamilyDescriptorBuilder cfd =
      ColumnFamilyDescriptorBuilder.newBuilder(tableBuilder.build().getColumnFamily(family));
  if (ttl > 0) {
    cfd.setValue(Bytes.toBytes(TxConstants.PROPERTY_TTL), Bytes.toBytes(String.valueOf(ttl)));
  }
  cfd.setMaxVersions(10);
  tableBuilder.removeColumnFamily(family);
  tableBuilder.addColumnFamily(cfd.build());
  return HRegion
      .openHRegion(region.getRegionInfo(), tableBuilder.build(), region.getWAL(), conf,
        new LocalRegionServerServices(conf, ServerName
            .valueOf(InetAddress.getLocalHost().getHostName(), 0, System.currentTimeMillis())),
        null);
}
 
Example 4
Source Project: hbase   Source File: HBaseTestingUtility.java    License: Apache License 2.0 6 votes vote down vote up
public HTableDescriptor createTableDescriptor(final TableName tableName,
    byte[][] families, int maxVersions) {
  TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(tableName);

  for (byte[] family : families) {
    ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor familyDescriptor =
      new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(family)
        .setMaxVersions(maxVersions);
    if (isNewVersionBehaviorEnabled()) {
      familyDescriptor.setNewVersionBehavior(true);
    }
    tableDescriptor.setColumnFamily(familyDescriptor);
  }
  return new HTableDescriptor(tableDescriptor);
}
 
Example 5
Source Project: hbase   Source File: BackupSystemTable.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Get backup system table descriptor
 * @return table's descriptor
 */
public static TableDescriptor getSystemTableDescriptor(Configuration conf) {
  TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(getTableName(conf));

  ColumnFamilyDescriptorBuilder colBuilder =
      ColumnFamilyDescriptorBuilder.newBuilder(SESSIONS_FAMILY);

  colBuilder.setMaxVersions(1);
  Configuration config = HBaseConfiguration.create();
  int ttl = config.getInt(BackupRestoreConstants.BACKUP_SYSTEM_TTL_KEY,
    BackupRestoreConstants.BACKUP_SYSTEM_TTL_DEFAULT);
  colBuilder.setTimeToLive(ttl);

  ColumnFamilyDescriptor colSessionsDesc = colBuilder.build();
  builder.setColumnFamily(colSessionsDesc);

  colBuilder = ColumnFamilyDescriptorBuilder.newBuilder(META_FAMILY);
  colBuilder.setTimeToLive(ttl);
  builder.setColumnFamily(colBuilder.build());
  return builder.build();
}
 
Example 6
Source Project: hbase   Source File: HBaseTestingUtility.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Create a table.
 * @param tableName
 * @param families
 * @param numVersions
 * @return A Table instance for the created table.
 * @throws IOException
 */
public Table createTable(TableName tableName, byte[][] families,
    int[] numVersions) throws IOException {
  TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(tableName);
  int i = 0;
  for (byte[] family : families) {
    ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor familyDescriptor =
      new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(family)
        .setMaxVersions(numVersions[i]);
    if (isNewVersionBehaviorEnabled()) {
      familyDescriptor.setNewVersionBehavior(true);
    }
    tableDescriptor.setColumnFamily(familyDescriptor);
    i++;
  }
  getAdmin().createTable(tableDescriptor);
  // HBaseAdmin only waits for regions to appear in hbase:meta we should wait until they are
  // assigned
  waitUntilAllRegionsAssigned(tableName);
  return getConnection().getTable(tableName);
}
 
Example 7
Source Project: hbase   Source File: RSGroupableBalancerTestBase.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Construct table descriptors evenly distributed between the groups.
 * @param hasBogusTable there is a table that does not determine the group
 * @return the list of table descriptors
 */
protected static Map<TableName, TableDescriptor> constructTableDesc(boolean hasBogusTable) {
  Map<TableName, TableDescriptor> tds = new HashMap<>();
  int index = rand.nextInt(groups.length);
  for (int i = 0; i < tables.length; i++) {
    int grpIndex = (i + index) % groups.length;
    String groupName = groups[grpIndex];
    TableDescriptor htd =
        TableDescriptorBuilder.newBuilder(tables[i]).setRegionServerGroup(groupName).build();
    tds.put(htd.getTableName(), htd);
  }
  if (hasBogusTable) {
    tds.put(table0, TableDescriptorBuilder.newBuilder(table0).setRegionServerGroup("").build());
  }
  return tds;
}
 
Example 8
Source Project: hbase   Source File: SpaceQuotaHelperForTests.java    License: Apache License 2.0 6 votes vote down vote up
TableName createTableInNamespace(NamespaceDescriptor nd) throws Exception {
  final Admin admin = testUtil.getAdmin();
  final TableName tn = TableName.valueOf(nd.getName(),
      testName.getMethodName() + counter.getAndIncrement());

  // Delete the old table
  if (admin.tableExists(tn)) {
    admin.disableTable(tn);
    admin.deleteTable(tn);
  }

  // Create the table
  TableDescriptor tableDesc = TableDescriptorBuilder.newBuilder(tn)
      .setColumnFamily(ColumnFamilyDescriptorBuilder.of(F1)).build();

  admin.createTable(tableDesc);
  return tn;
}
 
Example 9
@Test
public void testDeleteColumn() 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));
  tableDescriptor.setColumnFamily(
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(FAMILY_1));
  admin.createTable(tableDescriptor);
  admin.disableTable(TABLE_NAME);
  try {
    // Verify the table descriptor
    verifyTableDescriptor(TABLE_NAME, FAMILY_0, FAMILY_1);

    // Modify the table removing one family and verify the descriptor
    admin.deleteColumnFamily(TABLE_NAME, FAMILY_1);
    verifyTableDescriptor(TABLE_NAME, FAMILY_0);
  } finally {
    admin.deleteTable(TABLE_NAME);
  }
}
 
Example 10
Source Project: hbase   Source File: HBaseTestingUtility.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates a pre-split table for load testing. If the table already exists,
 * logs a warning and continues.
 * @return the number of regions the table was split into
 */
public static int createPreSplitLoadTestTable(Configuration conf,
    TableName tableName, byte[] columnFamily, Algorithm compression,
    DataBlockEncoding dataBlockEncoding, int numRegionsPerServer, int regionReplication,
    Durability durability)
        throws IOException {
  TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(tableName);
  tableDescriptor.setDurability(durability);
  tableDescriptor.setRegionReplication(regionReplication);
  ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor familyDescriptor =
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(columnFamily);
  familyDescriptor.setDataBlockEncoding(dataBlockEncoding);
  familyDescriptor.setCompressionType(compression);
  return createPreSplitLoadTestTable(conf, tableDescriptor, familyDescriptor,
    numRegionsPerServer);
}
 
Example 11
Source Project: hbase   Source File: TestProcedurePriority.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
  UTIL.getConfiguration().setLong(ProcedureExecutor.WORKER_KEEP_ALIVE_TIME_CONF_KEY, 5000);
  UTIL.getConfiguration().setInt(MasterProcedureConstants.MASTER_PROCEDURE_THREADS, 4);
  UTIL.getConfiguration().set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, MyCP.class.getName());
  UTIL.startMiniCluster(3);
  CORE_POOL_SIZE =
    UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor().getCorePoolSize();
  TABLE_COUNT = 50 * CORE_POOL_SIZE;
  List<Future<?>> futures = new ArrayList<>();
  AsyncAdmin admin = UTIL.getAsyncConnection().getAdmin();
  Semaphore concurrency = new Semaphore(10);
  for (int i = 0; i < TABLE_COUNT; i++) {
    concurrency.acquire();
    futures.add(admin
      .createTable(TableDescriptorBuilder.newBuilder(TableName.valueOf(TABLE_NAME_PREFIX + i))
        .setColumnFamily(ColumnFamilyDescriptorBuilder.of(CF)).build())
      .whenComplete((r, e) -> concurrency.release()));
  }
  for (Future<?> future : futures) {
    future.get(3, TimeUnit.MINUTES);
  }
  UTIL.getAdmin().balance(true);
  UTIL.waitUntilNoRegionsInTransition();
}
 
Example 12
Source Project: hbase   Source File: HMaster.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public long modifyColumn(final TableName tableName, final ColumnFamilyDescriptor descriptor,
    final long nonceGroup, final long nonce) throws IOException {
  checkInitialized();
  checkTableExists(tableName);
  return modifyTable(tableName, new TableDescriptorGetter() {

    @Override
    public TableDescriptor get() throws IOException {
      TableDescriptor old = getTableDescriptors().get(tableName);
      if (!old.hasColumnFamily(descriptor.getName())) {
        throw new InvalidFamilyOperationException("Family '" + descriptor.getNameAsString()
            + "' does not exist, so it cannot be modified");
      }

      return TableDescriptorBuilder.newBuilder(old).modifyColumnFamily(descriptor).build();
    }
  }, nonceGroup, nonce, true);
}
 
Example 13
Source Project: hbase   Source File: TestAccessController.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTableCreate() throws Exception {
  AccessTestAction createTable = new AccessTestAction() {
    @Override
    public Object run() throws Exception {
      TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
        new TableDescriptorBuilder.ModifyableTableDescriptor(
          TableName.valueOf(name.getMethodName()));
      tableDescriptor.setColumnFamily(
        new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(TEST_FAMILY));
      ACCESS_CONTROLLER.preCreateTable(ObserverContextImpl.createAndPrepare(CP_ENV),
        tableDescriptor, null);
      return null;
    }
  };

  // verify that superuser can create tables
  verifyAllowed(createTable, SUPERUSER, USER_ADMIN, USER_GROUP_CREATE, USER_GROUP_ADMIN);

  // all others should be denied
  verifyDenied(createTable, USER_CREATE, USER_RW, USER_RO, USER_NONE, USER_GROUP_READ,
    USER_GROUP_WRITE);
}
 
Example 14
Source Project: hbase   Source File: TestMiniClusterLoadSequential.java    License: Apache License 2.0 6 votes vote down vote up
protected void prepareForLoadTest() throws IOException {
  LOG.info("Starting load test: dataBlockEncoding=" + dataBlockEncoding +
      ", isMultiPut=" + isMultiPut);
  numKeys = numKeys();
  Admin admin = TEST_UTIL.getAdmin();
  while (admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS))
              .getLiveServerMetrics().size() < NUM_RS) {
    LOG.info("Sleeping until " + NUM_RS + " RSs are online");
    Threads.sleepWithoutInterrupt(1000);
  }
  admin.close();

  TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(TABLE);
  ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor familyDescriptor =
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(CF)
    .setCompressionType(compression)
    .setDataBlockEncoding(dataBlockEncoding);
  createPreSplitLoadTestTable(tableDescriptor, familyDescriptor);

  LoadTestDataGenerator dataGen = new MultiThreadedAction.DefaultDataGenerator(CF);
  writerThreads = prepareWriterThreads(dataGen, conf, TABLE);
  readerThreads = prepareReaderThreads(dataGen, conf, TABLE, 100);
}
 
Example 15
@Test
public void testCreateTableWithSingleReplica() throws Exception {
  final int numRegions = 3;
  final int numReplica = 1;
  final TableName tableName = TableName.valueOf(name.getMethodName());
  try {
    TableDescriptor desc =
      TableDescriptorBuilder.newBuilder(tableName).setRegionReplication(numReplica)
        .setColumnFamily(ColumnFamilyDescriptorBuilder.of("family")).build();
    ADMIN.createTable(desc, Bytes.toBytes("A"), Bytes.toBytes("Z"), numRegions);
    TEST_UTIL.waitUntilAllRegionsAssigned(tableName);
    TEST_UTIL.waitUntilNoRegionsInTransition();

    validateNumberOfRowsInMeta(tableName, numRegions, ADMIN.getConnection());
    List<RegionInfo> hris = MetaTableAccessor.getTableRegions(ADMIN.getConnection(), tableName);
    assertEquals(numRegions * numReplica, hris.size());
  } finally {
    ADMIN.disableTable(tableName);
    ADMIN.deleteTable(tableName);
  }
}
 
Example 16
Source Project: hbase   Source File: TestMobDataBlockEncoding.java    License: Apache License 2.0 6 votes vote down vote up
public void setUp(long threshold, String TN, DataBlockEncoding encoding)
    throws Exception {
  tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(TableName.valueOf(TN));
  columnFamilyDescriptor =
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(family);
  columnFamilyDescriptor.setMobEnabled(true);
  columnFamilyDescriptor.setMobThreshold(threshold);
  columnFamilyDescriptor.setMaxVersions(4);
  columnFamilyDescriptor.setDataBlockEncoding(encoding);
  tableDescriptor.setColumnFamily(columnFamilyDescriptor);
  admin = TEST_UTIL.getAdmin();
  admin.createTable(tableDescriptor);
  table = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration())
    .getTable(TableName.valueOf(TN));
}
 
Example 17
Source Project: hbase   Source File: AddColumnAction.java    License: Apache License 2.0 6 votes vote down vote up
@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;
  }

  getLogger().debug("Performing action: Adding " + columnDescriptor + " to " + tableName);

  TableDescriptor modifiedTable = TableDescriptorBuilder.newBuilder(tableDescriptor)
      .setColumnFamily(columnDescriptor).build();
  admin.modifyTable(modifiedTable);
}
 
Example 18
@Override
public int runTestFromCommandLine() throws Exception {
  IntegrationTestingUtility.setUseDistributedCluster(getConf());
  int numPresplits = getConf().getInt("loadmapper.numPresplits", 5);
  // create HTableDescriptor for specified table
  TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(getTablename());
  tableDescriptor.setColumnFamily(
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(TEST_FAMILY));

  try (Connection conn = ConnectionFactory.createConnection(getConf());
      Admin admin = conn.getAdmin()) {
    admin.createTable(tableDescriptor, Bytes.toBytes(0L), Bytes.toBytes(-1L), numPresplits);
  }
  doLoad(getConf(), tableDescriptor);
  doVerify(getConf(), tableDescriptor);
  getTestingUtil(getConf()).deleteTable(getTablename());
  return 0;
}
 
Example 19
Source Project: hbase   Source File: TestFileArchiverNotifierImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testSnapshotSizePersistence() throws IOException {
  final Admin admin = TEST_UTIL.getAdmin();
  final TableName tn = TableName.valueOf(testName.getMethodName());
  if (admin.tableExists(tn)) {
    admin.disableTable(tn);
    admin.deleteTable(tn);
  }
  TableDescriptor desc = TableDescriptorBuilder.newBuilder(tn).setColumnFamily(
      ColumnFamilyDescriptorBuilder.of(QuotaTableUtil.QUOTA_FAMILY_USAGE)).build();
  admin.createTable(desc);

  FileArchiverNotifierImpl notifier = new FileArchiverNotifierImpl(conn, conf, fs, tn);
  List<SnapshotWithSize> snapshotsWithSizes = new ArrayList<>();
  try (Table table = conn.getTable(tn)) {
    // Writing no values will result in no records written.
    verify(table, () -> {
      notifier.persistSnapshotSizes(table, snapshotsWithSizes);
      assertEquals(0, count(table));
    });

    verify(table, () -> {
      snapshotsWithSizes.add(new SnapshotWithSize("ss1", 1024L));
      snapshotsWithSizes.add(new SnapshotWithSize("ss2", 4096L));
      notifier.persistSnapshotSizes(table, snapshotsWithSizes);
      assertEquals(2, count(table));
      assertEquals(1024L, extractSnapshotSize(table, tn, "ss1"));
      assertEquals(4096L, extractSnapshotSize(table, tn, "ss2"));
    });
  }
}
 
Example 20
Source Project: hbase   Source File: TestVisibilityLabelsWithDeletes.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected Table createTable(byte[] fam) throws IOException {
  TableName tableName = TableName.valueOf(testName.getMethodName());
  TEST_UTIL.getAdmin().createTable(TableDescriptorBuilder.newBuilder(tableName)
      .setColumnFamily(ColumnFamilyDescriptorBuilder.of(fam)).build());
  return TEST_UTIL.getConnection().getTable(tableName);
}
 
Example 21
Source Project: hbase   Source File: TestParallelPut.java    License: Apache License 2.0 5 votes vote down vote up
private HRegion initHRegion(byte [] tableName, String callingMethod, byte[] ... families)
    throws IOException {
  TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(TableName.valueOf(tableName));
  for(byte [] family : families) {
    tableDescriptor.setColumnFamily(
      new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(family));
  }
  RegionInfo info = RegionInfoBuilder.newBuilder(tableDescriptor.getTableName()).build();
  return HBTU.createLocalHRegion(info, tableDescriptor);
}
 
Example 22
Source Project: hbase   Source File: TestModifyTableProcedure.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testRecoveryAndDoubleExecutionOffline() throws Exception {
  final TableName tableName = TableName.valueOf(name.getMethodName());
  final String cf2 = "cf2";
  final String cf3 = "cf3";
  final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();

  // create the table
  RegionInfo[] regions = MasterProcedureTestingUtility.createTable(
    procExec, tableName, null, "cf1", cf3);
  UTIL.getAdmin().disableTable(tableName);

  ProcedureTestingUtility.waitNoProcedureRunning(procExec);
  ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, true);

  // Modify multiple properties of the table.
  TableDescriptor oldDescriptor = UTIL.getAdmin().getDescriptor(tableName);
  TableDescriptor newDescriptor = TableDescriptorBuilder.newBuilder(oldDescriptor)
      .setCompactionEnabled(!oldDescriptor.isCompactionEnabled())
      .setColumnFamily(ColumnFamilyDescriptorBuilder.of(cf2))
      .removeColumnFamily(Bytes.toBytes(cf3))
      .setRegionReplication(3)
      .build();

  // Start the Modify procedure && kill the executor
  long procId = procExec.submitProcedure(
    new ModifyTableProcedure(procExec.getEnvironment(), newDescriptor));

  // Restart the executor and execute the step twice
  MasterProcedureTestingUtility.testRecoveryAndDoubleExecution(procExec, procId);

  // Validate descriptor
  TableDescriptor currentDescriptor = UTIL.getAdmin().getDescriptor(tableName);
  assertEquals(newDescriptor.isCompactionEnabled(), currentDescriptor.isCompactionEnabled());
  assertEquals(2, newDescriptor.getColumnFamilyNames().size());

  // cf2 should be added cf3 should be removed
  MasterProcedureTestingUtility.validateTableCreation(UTIL.getHBaseCluster().getMaster(),
    tableName, regions, false, "cf1", cf2);
}
 
Example 23
/**
 * Create simple HTD with three families: 'a', 'b', and 'c'
 * @param tableName name of the table descriptor
 * @return
 */
private TableDescriptor createBasic3FamilyHTD(final String tableName) {
  TableDescriptorBuilder tableBuilder = TableDescriptorBuilder.newBuilder(TableName.valueOf(tableName));
  ColumnFamilyDescriptor  a = ColumnFamilyDescriptorBuilder.of(Bytes.toBytes("a"));
  tableBuilder.addColumnFamily(a);
  ColumnFamilyDescriptor b = ColumnFamilyDescriptorBuilder.of(Bytes.toBytes("b"));
  tableBuilder.addColumnFamily(b);
  ColumnFamilyDescriptor c = ColumnFamilyDescriptorBuilder.of(Bytes.toBytes("c"));
  tableBuilder.addColumnFamily(c);
  return tableBuilder.build();
}
 
Example 24
Source Project: hbase   Source File: TestRSGroupsFallback.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testGroupFallback() throws Exception {
  // add fallback group
  addGroup(FALLBACK_GROUP, 1);
  // add test group
  String groupName = getGroupName(name.getMethodName());
  addGroup(groupName, 1);
  TableDescriptor desc = TableDescriptorBuilder.newBuilder(tableName)
      .setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("f")).build())
      .setRegionServerGroup(groupName)
      .build();
  ADMIN.createTable(desc);
  TEST_UTIL.waitUntilAllRegionsAssigned(tableName);
  // server of test group crash
  for (Address server : ADMIN.getRSGroup(groupName).getServers()) {
    AssignmentTestingUtil.crashRs(TEST_UTIL, getServerName(server), true);
  }
  Threads.sleep(1000);
  TEST_UTIL.waitUntilNoRegionsInTransition(10000);
  TEST_UTIL.waitUntilAllRegionsAssigned(tableName);

  // regions move to fallback group
  assertRegionsInGroup(FALLBACK_GROUP);

  // move a new server from default group
  Address address = ADMIN.getRSGroup(RSGroupInfo.DEFAULT_GROUP).getServers().first();
  ADMIN.moveServersToRSGroup(Collections.singleton(address), groupName);

  // correct misplaced regions
  MASTER.balance();

  TEST_UTIL.waitUntilNoRegionsInTransition(10000);
  TEST_UTIL.waitUntilAllRegionsAssigned(tableName);

  // regions move back
  assertRegionsInGroup(groupName);

  TEST_UTIL.deleteTable(tableName);
}
 
Example 25
Source Project: hbase   Source File: TestCoreRegionCoprocessor.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void before() throws IOException {
  String methodName = this.name.getMethodName();
  TableName tn = TableName.valueOf(methodName);
  ColumnFamilyDescriptor cfd = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(methodName)).build();
  TableDescriptor td = TableDescriptorBuilder.newBuilder(tn).setColumnFamily(cfd).build();
  RegionInfo ri = RegionInfoBuilder.newBuilder(tn).build();
  this.rss = new MockRegionServerServices(HTU.getConfiguration());
  this.region = HRegion.openHRegion(ri, td, null, HTU.getConfiguration(), this.rss, null);
}
 
Example 26
Source Project: hbase   Source File: TestFIFOCompactionPolicy.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testSanityCheckMinVersion() throws IOException {
  error.expect(DoNotRetryIOException.class);
  error.expectMessage("MIN_VERSION > 0 is not supported for FIFO compaction");
  TableName tableName = TableName.valueOf(getClass().getSimpleName() + "-MinVersion");
  TableDescriptor desc = TableDescriptorBuilder.newBuilder(tableName)
      .setValue(DefaultStoreEngine.DEFAULT_COMPACTION_POLICY_CLASS_KEY,
        FIFOCompactionPolicy.class.getName())
      .setValue(HConstants.HBASE_REGION_SPLIT_POLICY_KEY,
        DisabledRegionSplitPolicy.class.getName())
      .setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(family).setTimeToLive(1)
          .setMinVersions(1).build())
      .build();
  TEST_UTIL.getAdmin().createTable(desc);
}
 
Example 27
Source Project: hbase   Source File: AbstractTestWALReplay.java    License: Apache License 2.0 5 votes vote down vote up
private TableDescriptorBuilder.ModifyableTableDescriptor createBasic3FamilyHTD(
    final TableName tableName) {
  TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(tableName);
  ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor a =
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(Bytes.toBytes("a"));
  tableDescriptor.setColumnFamily(a);
  ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor b =
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(Bytes.toBytes("b"));
  tableDescriptor.setColumnFamily(b);
  ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor c =
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(Bytes.toBytes("c"));
  tableDescriptor.setColumnFamily(c);
  return tableDescriptor;
}
 
Example 28
Source Project: hbase   Source File: TestRegionInfo.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testContainsRange() {
  TableDescriptor tableDesc =
    TableDescriptorBuilder.newBuilder(TableName.valueOf(name.getMethodName())).build();
  RegionInfo hri = RegionInfoBuilder.newBuilder(tableDesc.getTableName())
    .setStartKey(Bytes.toBytes("a")).setEndKey(Bytes.toBytes("g")).build();
  // Single row range at start of region
  assertTrue(hri.containsRange(Bytes.toBytes("a"), Bytes.toBytes("a")));
  // Fully contained range
  assertTrue(hri.containsRange(Bytes.toBytes("b"), Bytes.toBytes("c")));
  // Range overlapping start of region
  assertTrue(hri.containsRange(Bytes.toBytes("a"), Bytes.toBytes("c")));
  // Fully contained single-row range
  assertTrue(hri.containsRange(Bytes.toBytes("c"), Bytes.toBytes("c")));
  // Range that overlaps end key and hence doesn't fit
  assertFalse(hri.containsRange(Bytes.toBytes("a"), Bytes.toBytes("g")));
  // Single row range on end key
  assertFalse(hri.containsRange(Bytes.toBytes("g"), Bytes.toBytes("g")));
  // Single row range entirely outside
  assertFalse(hri.containsRange(Bytes.toBytes("z"), Bytes.toBytes("z")));

  // Degenerate range
  try {
    hri.containsRange(Bytes.toBytes("z"), Bytes.toBytes("a"));
    fail("Invalid range did not throw IAE");
  } catch (IllegalArgumentException iae) {
  }
}
 
Example 29
Source Project: hbase   Source File: TestDurability.java    License: Apache License 2.0 5 votes vote down vote up
private HRegion createHRegion(WALFactory wals, Durability durability) throws IOException {
  TableName tableName = TableName.valueOf(name.getMethodName().replaceAll("[^A-Za-z0-9-_]", "_"));
  TableDescriptor htd = TableDescriptorBuilder.newBuilder(tableName)
      .setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY)).build();
  RegionInfo info = RegionInfoBuilder.newBuilder(tableName).build();
  Path path = new Path(DIR, tableName.getNameAsString());
  if (FS.exists(path)) {
    if (!FS.delete(path, true)) {
      throw new IOException("Failed delete of " + path);
    }
  }
  ChunkCreator.initialize(MemStoreLABImpl.CHUNK_SIZE_DEFAULT, false, 0, 0, 0, null);
  return HRegion.createHRegion(info, path, CONF, htd, wals.getWAL(info));
}
 
Example 30
Source Project: phoenix   Source File: FlappingLocalIndexIT.java    License: Apache License 2.0 5 votes vote down vote up
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));
}