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

The following examples show how to use org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder. 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: 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
 * @param splitKeys
 * @return A Table instance for the created table.
 * @throws IOException
 */
public Table createTable(TableName tableName, byte[][] families, int numVersions,
    byte[][] splitKeys) throws IOException {
  TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(tableName);
  for (byte[] family : families) {
    ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor familyDescriptor =
      new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(family)
        .setMaxVersions(numVersions);
    if (isNewVersionBehaviorEnabled()) {
      familyDescriptor.setNewVersionBehavior(true);
    }
    tableDescriptor.setColumnFamily(familyDescriptor);
  }
  if (splitKeys != null) {
    getAdmin().createTable(tableDescriptor, splitKeys);
  } else {
    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 2
@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 3
Source Project: hbase   Source File: TestMaster.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testMoveThrowsUnknownRegionException() throws IOException {
  final TableName tableName = TableName.valueOf(name.getMethodName());
  TableDescriptorBuilder tableDescriptorBuilder =
    TableDescriptorBuilder.newBuilder(tableName);
  ColumnFamilyDescriptor columnFamilyDescriptor =
    ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("value")).build();
  tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);

  admin.createTable(tableDescriptorBuilder.build());
  try {
    RegionInfo hri = RegionInfoBuilder.newBuilder(tableName)
        .setStartKey(Bytes.toBytes("A"))
        .setEndKey(Bytes.toBytes("Z"))
        .build();
    admin.move(hri.getEncodedNameAsBytes());
    fail("Region should not be moved since it is fake");
  } catch (IOException ioe) {
    assertTrue(ioe instanceof UnknownRegionException);
  } finally {
    TEST_UTIL.deleteTable(tableName);
  }
}
 
Example 4
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 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 getSystemTableForBulkLoadedDataDescriptor(Configuration conf) {
  TableDescriptorBuilder builder =
      TableDescriptorBuilder.newBuilder(getTableNameForBulkLoadedData(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: TestTruncateTableProcedure.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTruncatePreserveWithReplicaRegionAfterSplit() throws Exception {
  String[] families = new String[] { "f1", "f2" };
  byte[][] splitKeys =
    new byte[][] { Bytes.toBytes("a"), Bytes.toBytes("b"), Bytes.toBytes("c") };
  TableName tableName = TableName.valueOf(name.getMethodName());

  // create a table with region replications
  TableDescriptor htd = TableDescriptorBuilder.newBuilder(tableName).setRegionReplication(3)
    .setColumnFamilies(Arrays.stream(families)
      .map(fam -> ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(fam)).build())
      .collect(Collectors.toList()))
    .build();
  RegionInfo[] regions = ModifyRegionUtils.createRegionInfos(htd, splitKeys);
  ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
  long procId = ProcedureTestingUtility.submitAndWait(procExec,
    new CreateTableProcedure(procExec.getEnvironment(), htd, regions));
  ProcedureTestingUtility.assertProcNotFailed(procExec.getResult(procId));

  splitAndTruncate(tableName, regions, 3);
}
 
Example 7
Source Project: hbase   Source File: TestHTableDescriptor.java    License: Apache License 2.0 6 votes vote down vote up
@Test(expected=IllegalArgumentException.class)
public void testAddDuplicateFamilies() {
  TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(
      TableName.valueOf(name.getMethodName()));
  byte[] familyName = Bytes.toBytes("cf");
  ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor familyDescriptor =
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(familyName)
      .setBlocksize(1000);
  tableDescriptor.setColumnFamily(familyDescriptor);
  assertEquals(1000, tableDescriptor.getColumnFamily(familyName).getBlocksize());
  familyDescriptor =
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(familyName)
      .setBlocksize(2000);
  tableDescriptor.setColumnFamily(familyDescriptor);
}
 
Example 8
Source Project: hbase   Source File: VisibilityController.java    License: Apache License 2.0 6 votes vote down vote up
/********************************* Master related hooks **********************************/

  @Override
  public void postStartMaster(ObserverContext<MasterCoprocessorEnvironment> ctx) throws IOException {
    // Need to create the new system table for labels here
    if (!MetaTableAccessor.tableExists(ctx.getEnvironment().getConnection(), LABELS_TABLE_NAME)) {
      TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
        new TableDescriptorBuilder.ModifyableTableDescriptor(LABELS_TABLE_NAME);
      ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor familyDescriptor =
        new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(LABELS_TABLE_FAMILY);
      familyDescriptor.setBloomFilterType(BloomType.NONE);
      // We will cache all the labels. No need of normal
      // table block cache.
      familyDescriptor.setBlockCacheEnabled(false);
      tableDescriptor.setColumnFamily(familyDescriptor);
      // Let the "labels" table having only one region always. We are not expecting too many labels in
      // the system.
      tableDescriptor.setValue(HTableDescriptor.SPLIT_POLICY,
          DisabledRegionSplitPolicy.class.getName());
      try (Admin admin = ctx.getEnvironment().getConnection().getAdmin()) {
        admin.createTable(tableDescriptor);
      }
    }
  }
 
Example 9
Source Project: hbase   Source File: AccessController.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Create the ACL table
 * @throws IOException
 */
private static void createACLTable(Admin admin) throws IOException {
  /** Table descriptor for ACL table */
  ColumnFamilyDescriptor cfd =
      ColumnFamilyDescriptorBuilder.newBuilder(PermissionStorage.ACL_LIST_FAMILY).
      setMaxVersions(1).
      setInMemory(true).
      setBlockCacheEnabled(true).
      setBlocksize(8 * 1024).
      setBloomFilterType(BloomType.NONE).
      setScope(HConstants.REPLICATION_SCOPE_LOCAL).build();
  TableDescriptor td =
      TableDescriptorBuilder.newBuilder(PermissionStorage.ACL_TABLE_NAME).
        setColumnFamily(cfd).build();
  admin.createTable(td);
}
 
Example 10
Source Project: hbase   Source File: TestScannerWithCorruptHFile.java    License: Apache License 2.0 6 votes vote down vote up
@Test(expected = DoNotRetryIOException.class)
public void testScanOnCorruptHFile() throws IOException {
  TableName tableName = TableName.valueOf(name.getMethodName());
  TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(tableName);
  tableDescriptor.setCoprocessor(CorruptHFileCoprocessor.class.getName());
  tableDescriptor.setColumnFamily(
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(FAMILY_NAME));
  Table table = TEST_UTIL.createTable(tableDescriptor, null);
  try {
    loadTable(table, 1);
    scan(table);
  } finally {
    table.close();
  }
}
 
Example 11
Source Project: hbase   Source File: TestMobStoreCompaction.java    License: Apache License 2.0 6 votes vote down vote up
private void init(Configuration conf, long mobThreshold) throws Exception {
  this.conf = conf;
  this.mobCellThreshold = mobThreshold;
  HBaseTestingUtility UTIL = new HBaseTestingUtility(conf);

  compactionThreshold = conf.getInt("hbase.hstore.compactionThreshold", 3);
  tableDescriptor = UTIL.createModifyableTableDescriptor(name.getMethodName());
  familyDescriptor =
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(COLUMN_FAMILY);
  familyDescriptor.setMobEnabled(true);
  familyDescriptor.setMobThreshold(mobThreshold);
  familyDescriptor.setMaxVersions(1);
  tableDescriptor.modifyColumnFamily(familyDescriptor);

  RegionInfo regionInfo = RegionInfoBuilder.newBuilder(tableDescriptor.getTableName()).build();
  region = HBaseTestingUtility.createRegionAndWAL(regionInfo,
    UTIL.getDataTestDir(), conf, tableDescriptor, new MobFileCache(conf));
  fs = FileSystem.get(conf);
}
 
Example 12
Source Project: hbase   Source File: FSUtils.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected boolean accept(Path p, @CheckForNull Boolean isDir) {
  try {
    // throws IAE if invalid
    ColumnFamilyDescriptorBuilder.isLegalColumnFamilyName(Bytes.toBytes(p.getName()));
  } catch (IllegalArgumentException iae) {
    // path name is an invalid family name and thus is excluded.
    return false;
  }

  try {
    return isDirectory(fs, isDir, p);
  } catch (IOException ioe) {
    // Maybe the file was moved or the fs was disconnected.
    LOG.warn("Skipping file {} due to IOException", p, ioe);
    return false;
  }
}
 
Example 13
Source Project: hbase   Source File: TestBlocksScanned.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testBlocksScannedWithEncoding() throws Exception {
  byte [] tableName = Bytes.toBytes("TestBlocksScannedWithEncoding");
  TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(TableName.valueOf(tableName));

  tableDescriptor.setColumnFamily(
      new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(FAMILY)
      .setMaxVersions(10)
      .setBlockCacheEnabled(true)
      .setDataBlockEncoding(DataBlockEncoding.FAST_DIFF)
      .setBlocksize(BLOCK_SIZE)
      .setCompressionType(Compression.Algorithm.NONE)
      );
  _testBlocksScanned(tableDescriptor);
}
 
Example 14
Source Project: hbase   Source File: IntegrationTestIngestWithMOB.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void initTable() throws IOException {
  super.initTable();

  TableName tableName = getTablename();
  try (Connection connection = ConnectionFactory.createConnection();
       Admin admin = connection.getAdmin()) {
    HTableDescriptor tableDesc = new HTableDescriptor(admin.getDescriptor(tableName));
    LOG.info("Disabling table " + getTablename());
    admin.disableTable(tableName);
    ColumnFamilyDescriptor mobColumn = tableDesc.getColumnFamily(mobColumnFamily);
    ColumnFamilyDescriptor cfd = ColumnFamilyDescriptorBuilder.newBuilder(mobColumn)
      .setMobEnabled(true)
      .setMobThreshold((long) threshold)
      .build();
    admin.modifyColumnFamily(tableName, cfd);
    LOG.info("Enabling table " + getTablename());
    admin.enableTable(tableName);
  }
}
 
Example 15
Source Project: hbase   Source File: TestFIFOCompactionPolicy.java    License: Apache License 2.0 6 votes vote down vote up
private HStore prepareData() throws IOException {
  Admin admin = TEST_UTIL.getAdmin();
  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).build())
      .build();
  admin.createTable(desc);
  Table table = TEST_UTIL.getConnection().getTable(tableName);
  TimeOffsetEnvironmentEdge edge =
      (TimeOffsetEnvironmentEdge) EnvironmentEdgeManager.getDelegate();
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      byte[] value = new byte[128 * 1024];
      ThreadLocalRandom.current().nextBytes(value);
      table.put(new Put(Bytes.toBytes(i * 10 + j)).addColumn(family, qualifier, value));
    }
    admin.flush(tableName);
    edge.increment(1001);
  }
  return getStoreWithName(tableName);
}
 
Example 16
Source Project: hbase   Source File: TestNamespaceAuditor.java    License: Apache License 2.0 6 votes vote down vote up
@Test(expected = QuotaExceededException.class)
public void testCloneSnapshotQuotaExceed() throws Exception {
  String nsp = prefix + "_testTableQuotaExceedWithCloneSnapshot";
  NamespaceDescriptor nspDesc =
      NamespaceDescriptor.create(nsp).addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "1")
          .build();
  ADMIN.createNamespace(nspDesc);
  assertNotNull("Namespace descriptor found null.", ADMIN.getNamespaceDescriptor(nsp));
  TableName tableName = TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table1");
  TableName cloneTableName = TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table2");
  ColumnFamilyDescriptor columnFamilyDescriptor =
    ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("fam1")).build();
  TableDescriptorBuilder tableDescOne = TableDescriptorBuilder
    .newBuilder(tableName);
  tableDescOne.setColumnFamily(columnFamilyDescriptor);
  ADMIN.createTable(tableDescOne.build());
  String snapshot = "snapshot_testTableQuotaExceedWithCloneSnapshot";
  ADMIN.snapshot(snapshot, tableName);
  ADMIN.cloneSnapshot(snapshot, cloneTableName);
  ADMIN.deleteSnapshot(snapshot);
}
 
Example 17
Source Project: hbase   Source File: TestGzipFilter.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  TEST_UTIL.startMiniCluster();
  REST_TEST_UTIL.startServletContainer(TEST_UTIL.getConfiguration());
  client = new Client(new Cluster().add("localhost",
    REST_TEST_UTIL.getServletPort()));
  Admin admin = TEST_UTIL.getAdmin();
  if (admin.tableExists(TABLE)) {
    return;
  }
  TableDescriptorBuilder tableDescriptorBuilder =
    TableDescriptorBuilder.newBuilder(TABLE);
  ColumnFamilyDescriptor columnFamilyDescriptor =
    ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(CFA)).build();
  tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
  admin.createTable(tableDescriptorBuilder.build());
}
 
Example 18
Source Project: hbase   Source File: HBaseTestingUtility.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Create a table.
 * @param tableName
 * @param family
 * @param splitRows
 * @return A Table instance for the created table.
 * @throws IOException
 */
public Table createTable(TableName tableName, byte[] family, byte[][] splitRows)
    throws IOException {
  TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(tableName);
  ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor familyDescriptor =
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(family);
  if (isNewVersionBehaviorEnabled()) {
    familyDescriptor.setNewVersionBehavior(true);
  }
  tableDescriptor.setColumnFamily(familyDescriptor);
  getAdmin().createTable(tableDescriptor, splitRows);
  // HBaseAdmin only waits for regions to appear in hbase:meta we should wait until they are
  // assigned
  waitUntilAllRegionsAssigned(tableName);
  return getConnection().getTable(tableName);
}
 
Example 19
Source Project: hbase   Source File: BaseTestHBaseFsck.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Setup a clean table with a mob-enabled column.
 *
 * @param tablename The name of a table to be created.
 * @throws Exception
 */
void setupMobTable(TableName tablename) throws Exception {
  TableDescriptorBuilder tableDescriptorBuilder =
    TableDescriptorBuilder.newBuilder(tablename);
  ColumnFamilyDescriptor columnFamilyDescriptor =
    ColumnFamilyDescriptorBuilder
      .newBuilder(FAM)
      .setMobEnabled(true)
      .setMobThreshold(0).build();
  // If a table has no CF's it doesn't get checked
  tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
  createTable(TEST_UTIL, tableDescriptorBuilder.build(), SPLITS);

  tbl = connection.getTable(tablename, tableExecutorService);
  List<Put> puts = new ArrayList<>(ROWKEYS.length);
  for (byte[] row : ROWKEYS) {
    Put p = new Put(row);
    p.addColumn(FAM, Bytes.toBytes("val"), row);
    puts.add(p);
  }
  tbl.put(puts);
}
 
Example 20
Source Project: hbase   Source File: TestCoprocessorMetrics.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testRegionObserverMultiCoprocessor() throws IOException {
  final TableName tableName = TableName.valueOf(name.getMethodName());
  try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration());
       Admin admin = connection.getAdmin()) {
    admin.createTable(
      new TableDescriptorBuilder.ModifyableTableDescriptor(tableName)
        .setColumnFamily(
          new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(foo))
        // add the coprocessor for the region. We add two different coprocessors
        .setCoprocessor(CustomRegionObserver.class.getName())
        .setCoprocessor(CustomRegionObserver2.class.getName()));
    try (Table table = connection.getTable(tableName)) {
      table.get(new Get(foo));
      table.get(new Get(foo)); // 2 gets
    }
  }

  // we will have two counters coming from two coprocs, in two different MetricRegistries
  assertPreGetRequestsCounter(CustomRegionObserver.class);
  assertPreGetRequestsCounter(CustomRegionObserver2.class);
}
 
Example 21
private static void startFourthCluster() throws Exception {
  LOG.info("Setup Zk to same one from UTIL1 and UTIL2 and UTIL3");
  UTIL4.setZkCluster(UTIL1.getZkCluster());
  UTIL4.startMiniCluster(NUM_SLAVES1);

  TableDescriptor table = TableDescriptorBuilder.newBuilder(tableName)
      .setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(famName).setMaxVersions(100)
          .setScope(HConstants.REPLICATION_SCOPE_GLOBAL).build())
      .setColumnFamily(ColumnFamilyDescriptorBuilder.of(noRepfamName)).build();

  Connection connection4 = ConnectionFactory.createConnection(CONF4);
  try (Admin admin4 = connection4.getAdmin()) {
    admin4.createTable(table, HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE);
  }
  UTIL4.waitUntilAllRegionsAssigned(tableName);
}
 
Example 22
Source Project: hbase   Source File: TestFilterFromRegionSide.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(TABLE_NAME);

  for (byte[] family : FAMILIES) {
    ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor familyDescriptor =
      new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(family);
    tableDescriptor.setColumnFamily(familyDescriptor);
  }
  RegionInfo info = RegionInfoBuilder.newBuilder(tableDescriptor.getTableName()).build();
  REGION = HBaseTestingUtility.createRegionAndWAL(info, TEST_UTIL.getDataTestDir(),
    TEST_UTIL.getConfiguration(), tableDescriptor);
  for(Put put:createPuts(ROWS, FAMILIES, QUALIFIERS, VALUE)){
    REGION.put(put);
  }
}
 
Example 23
Source Project: hbase   Source File: TestMinVersions.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testMinVersionsWithKeepDeletedCellsTTL() throws Exception {
  int ttl = 4;
  ColumnFamilyDescriptor cfd =
    ColumnFamilyDescriptorBuilder.newBuilder(c0)
      .setVersionsWithTimeToLive(ttl, 2).build();
  verifyVersionedCellKeyValues(ttl, cfd);

  cfd = ColumnFamilyDescriptorBuilder.newBuilder(c0)
    .setMinVersions(2)
    .setMaxVersions(Integer.MAX_VALUE)
    .setTimeToLive(ttl)
    .setKeepDeletedCells(KeepDeletedCells.TTL)
    .build();
  verifyVersionedCellKeyValues(ttl, cfd);
}
 
Example 24
Source Project: hbase   Source File: TestAccessController2.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateTableWithGroupPermissions() throws Exception {
  grantGlobal(TEST_UTIL, TESTGROUP_1_NAME, Action.CREATE);
  try {
    AccessTestAction createAction = new AccessTestAction() {
      @Override
      public Object run() throws Exception {
        TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
          new TableDescriptorBuilder.ModifyableTableDescriptor(testTable.getTableName());
        tableDescriptor.setColumnFamily(
          new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(TEST_FAMILY));
        try (Connection connection =
            ConnectionFactory.createConnection(TEST_UTIL.getConfiguration())) {
          try (Admin admin = connection.getAdmin()) {
            admin.createTable(tableDescriptor);
          }
        }
        return null;
      }
    };
    verifyAllowed(createAction, TESTGROUP1_USER1);
    verifyDenied(createAction, TESTGROUP2_USER1);
  } finally {
    revokeGlobal(TEST_UTIL, TESTGROUP_1_NAME, Action.CREATE);
  }
}
 
Example 25
Source Project: hbase   Source File: TestSwitchToStreamRead.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws IOException {
  UTIL.getConfiguration().setLong(StoreScanner.STORESCANNER_PREAD_MAX_BYTES, 2048);
  StringBuilder sb = new StringBuilder(256);
  for (int i = 0; i < 255; i++) {
    sb.append((char) ThreadLocalRandom.current().nextInt('A', 'z' + 1));
  }
  VALUE_PREFIX = sb.append("-").toString();
  REGION = UTIL.createLocalHRegion(
    TableDescriptorBuilder.newBuilder(TABLE_NAME)
      .setColumnFamily(
        ColumnFamilyDescriptorBuilder.newBuilder(FAMILY).setBlocksize(1024).build())
      .build(),
    null, null);
  for (int i = 0; i < 900; i++) {
    REGION
      .put(new Put(Bytes.toBytes(i)).addColumn(FAMILY, QUAL, Bytes.toBytes(VALUE_PREFIX + i)));
  }
  REGION.flush(true);
  for (int i = 900; i < 1000; i++) {
    REGION
      .put(new Put(Bytes.toBytes(i)).addColumn(FAMILY, QUAL, Bytes.toBytes(VALUE_PREFIX + i)));
  }
}
 
Example 26
Source Project: hbase   Source File: TestAtomicOperation.java    License: Apache License 2.0 6 votes vote down vote up
private void initHRegion (byte [] tableName, String callingMethod, int [] maxVersions,
  byte[] ... families)
throws IOException {
  TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(TableName.valueOf(tableName));

  int i=0;
  for(byte [] family : families) {
    ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor familyDescriptor =
      new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(family);
    familyDescriptor.setMaxVersions(maxVersions != null ? maxVersions[i++] : 1);
    tableDescriptor.setColumnFamily(familyDescriptor);
  }
  RegionInfo info = RegionInfoBuilder.newBuilder(tableDescriptor.getTableName()).build();
  region = TEST_UTIL.createLocalHRegion(info, tableDescriptor);
}
 
Example 27
Source Project: atlas   Source File: HBaseStoreManager.java    License: Apache License 2.0 5 votes vote down vote up
private TableDescriptor createTable(String tableName, String cfName, int ttlInSeconds, AdminMask adm) throws IOException {
    TableDescriptor desc = compat.newTableDescriptor(tableName);

    ColumnFamilyDescriptor cdesc = ColumnFamilyDescriptorBuilder.of(cfName);
    cdesc = setCFOptions(cdesc, ttlInSeconds);

    desc = compat.addColumnFamilyToTableDescriptor(desc, cdesc);

    int count; // total regions to create
    String src;

    if (MIN_REGION_COUNT <= (count = regionCount)) {
        src = "region count configuration";
    } else if (0 < regionsPerServer &&
               MIN_REGION_COUNT <= (count = regionsPerServer * adm.getEstimatedRegionServerCount())) {
        src = "ClusterStatus server count";
    } else {
        count = -1;
        src = "default";
    }

    if (MIN_REGION_COUNT < count) {
        adm.createTable(desc, getStartKey(count), getEndKey(count), count);
        logger.debug("Created table {} with region count {} from {}", tableName, count, src);
    } else {
        adm.createTable(desc);
        logger.debug("Created table {} with default start key, end key, and region count", tableName);
    }

    return desc;
}
 
Example 28
Source Project: phoenix   Source File: TransactionIT.java    License: Apache License 2.0 5 votes vote down vote up
private static void assertTTL(Admin admin, String tableName, int ttl) throws Exception {
    TableDescriptor tableDesc = admin.getTableDescriptor(TableName.valueOf(tableName));
    for (ColumnFamilyDescriptor colDesc : tableDesc.getColumnFamilies()) {
        assertEquals(ttl,Integer.parseInt(Bytes.toString(colDesc.getValue(Bytes.toBytes(TxConstants.PROPERTY_TTL)))));
        assertEquals(ColumnFamilyDescriptorBuilder.DEFAULT_TTL,colDesc.getTimeToLive());
    }
}
 
Example 29
Source Project: hbase   Source File: TestSplitTransactionOnCluster.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testStoreFileReferenceCreationWhenSplitPolicySaysToSkipRangeCheck()
    throws Exception {
  final TableName tableName = TableName.valueOf(name.getMethodName());
  try {
    byte[] cf = Bytes.toBytes("f");
    byte[] cf1 = Bytes.toBytes("i_f");
    TableDescriptor htd = TableDescriptorBuilder.newBuilder(tableName)
      .setColumnFamily(ColumnFamilyDescriptorBuilder.of(cf))
      .setColumnFamily(ColumnFamilyDescriptorBuilder.of(cf1))
      .setRegionSplitPolicyClassName(CustomSplitPolicy.class.getName()).build();
    admin.createTable(htd);
    List<HRegion> regions = awaitTableRegions(tableName);
    HRegion region = regions.get(0);
    for(int i = 3;i<9;i++) {
      Put p = new Put(Bytes.toBytes("row"+i));
      p.addColumn(cf, Bytes.toBytes("q"), Bytes.toBytes("value" + i));
      p.addColumn(cf1, Bytes.toBytes("q"), Bytes.toBytes("value" + i));
      region.put(p);
    }
    region.flush(true);
    HStore store = region.getStore(cf);
    Collection<HStoreFile> storefiles = store.getStorefiles();
    assertEquals(1, storefiles.size());
    assertFalse(region.hasReferences());
    Path referencePath =
        region.getRegionFileSystem().splitStoreFile(region.getRegionInfo(), "f",
          storefiles.iterator().next(), Bytes.toBytes("row1"), false, region.getSplitPolicy());
    assertNull(referencePath);
    referencePath =
        region.getRegionFileSystem().splitStoreFile(region.getRegionInfo(), "i_f",
          storefiles.iterator().next(), Bytes.toBytes("row1"), false, region.getSplitPolicy());
    assertNotNull(referencePath);
  } finally {
    TESTING_UTIL.deleteTable(tableName);
  }
}
 
Example 30
Source Project: hbase   Source File: TestNamespace.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void createTableInSystemNamespace() throws Exception {
  final TableName tableName = TableName.valueOf("hbase:" + name.getMethodName());
  TableDescriptorBuilder tableDescriptorBuilder =
    TableDescriptorBuilder.newBuilder(tableName);
  ColumnFamilyDescriptor columnFamilyDescriptor =
    ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("cf1")).build();
  tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
  TableDescriptor tableDescriptor = tableDescriptorBuilder.build();
  admin.createTable(tableDescriptor);
  assertEquals(0, admin.listTableDescriptors().size());
  assertTrue(admin.tableExists(tableName));
  admin.disableTable(tableDescriptor.getTableName());
  admin.deleteTable(tableDescriptor.getTableName());
}