Java Code Examples for org.apache.hadoop.hbase.HTableDescriptor#getTableName()

The following examples show how to use org.apache.hadoop.hbase.HTableDescriptor#getTableName() . 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: TransactionProcessorTest.java    From phoenix-tephra with Apache License 2.0 6 votes vote down vote up
private HRegion createRegion(String tableName, byte[] family, long ttl) throws IOException {
  HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(tableName));
  HColumnDescriptor cfd = new HColumnDescriptor(family);
  if (ttl > 0) {
    cfd.setValue(TxConstants.PROPERTY_TTL, String.valueOf(ttl));
  }
  cfd.setMaxVersions(10);
  htd.addFamily(cfd);
  htd.addCoprocessor(TransactionProcessor.class.getName());
  Path tablePath = FSUtils.getTableDir(FSUtils.getRootDir(conf), htd.getTableName());
  FileSystem fs = FileSystem.get(conf);
  assertTrue(fs.mkdirs(tablePath));
  WALFactory walFactory = new WALFactory(conf, tableName + ".hlog");
  HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false);
  WAL hLog = walFactory.getWAL(info);
  HRegionInfo regionInfo = new HRegionInfo(TableName.valueOf(tableName));
  HRegionFileSystem regionFS = HRegionFileSystem.createRegionOnFileSystem(conf, fs, tablePath, regionInfo);
  return new HRegion(regionFS, hLog, conf, htd,
      new LocalRegionServerServices(conf, ServerName.valueOf(
          InetAddress.getLocalHost().getHostName(), 0, System.currentTimeMillis())));
}
 
Example 2
Source File: CreateTableCommand.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
@Override
public boolean execute(HbaseAdminOperation hbaseAdminOperation) {
    HTableDescriptor htd = getHtd();
    TableName tableName = htd.getTableName();
    if (hbaseAdminOperation.tableExists(tableName)) {
        return false;
    }
    logger.info("Creating {} table...", tableName);
    if (ArrayUtils.isEmpty(splitKeys)) {
        hbaseAdminOperation.createTable(htd);
        logger.info("{} table created.", tableName);
    } else {
        hbaseAdminOperation.createTable(htd, splitKeys);
        logger.info("{} table created with {} splitKeys.", tableName, splitKeys.length + 1);
    }
    return true;
}
 
Example 3
Source File: ModifyTableCommand.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
@Override
public boolean execute(HbaseAdminOperation hbaseAdminOperation) {
    HTableDescriptor htd = getHtd();
    HColumnDescriptor[] hcds = htd.getColumnFamilies();
    if (ArrayUtils.isEmpty(hcds)) {
        return false;
    }

    TableName tableName = htd.getTableName();
    HTableDescriptor currentHtd = hbaseAdminOperation.getTableDescriptor(tableName);

    // Filter existing column families as column family modification is not supported.
    // We could use modifyTable(HTableDescriptor) to add column families, but this deletes existing column families
    // if they are not specified in HTableDescriptor and this may be dangerous.
    // Instead, use addColumn.
    boolean changesMade = false;
    for (HColumnDescriptor hcd : hcds) {
        if (!currentHtd.hasFamily(hcd.getName())) {
            logger.info("Adding {} to {} table.", hcd, tableName);
            hbaseAdminOperation.addColumn(tableName, hcd);
            changesMade = true;
        }
    }
    return changesMade;
}
 
Example 4
Source File: TestReplicasClient.java    From hbase with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void beforeClass() throws Exception {
  // enable store file refreshing
  HTU.getConfiguration().setInt(
      StorefileRefresherChore.REGIONSERVER_STOREFILE_REFRESH_PERIOD, REFRESH_PERIOD);
  HTU.getConfiguration().setBoolean("hbase.client.log.scanner.activity", true);
  HTU.getConfiguration().setBoolean(MetricsConnection.CLIENT_SIDE_METRICS_ENABLED_KEY, true);
  StartMiniClusterOption option = StartMiniClusterOption.builder().numRegionServers(1).
      numAlwaysStandByMasters(1).numMasters(1).build();
  HTU.startMiniCluster(option);

  // Create table then get the single region for our new table.
  HTableDescriptor hdt = HTU.createTableDescriptor(
    TableName.valueOf(TestReplicasClient.class.getSimpleName()),
    HColumnDescriptor.DEFAULT_MIN_VERSIONS, 3, HConstants.FOREVER,
    HColumnDescriptor.DEFAULT_KEEP_DELETED);
  hdt.addCoprocessor(SlowMeCopro.class.getName());
  HTU.createTable(hdt, new byte[][]{f}, null);
  TABLE_NAME = hdt.getTableName();
  try (RegionLocator locator = HTU.getConnection().getRegionLocator(hdt.getTableName())) {
    hriPrimary = locator.getRegionLocation(row, false).getRegion();
  }

  // mock a secondary region info to open
  hriSecondary = RegionReplicaUtil.getRegionInfoForReplica(hriPrimary, 1);

  // No master
  LOG.info("Master is going to be stopped");
  TestRegionServerNoMaster.stopMasterAndAssignMeta(HTU);
  Configuration c = new Configuration(HTU.getConfiguration());
  c.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1);
  LOG.info("Master has stopped");
}
 
Example 5
Source File: HBaseAdminTemplate.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public void modifyTable(HTableDescriptor htd) {
    final TableName tableName = htd.getTableName();
    execute(admin -> {
        admin.modifyTable(tableName, htd);
        logger.info("{} table modified, htd : {}", tableName, htd);
        return null;
    });
}
 
Example 6
Source File: HbaseSchemaCommandManager.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
private List<HTableDescriptor> filterTablesByNamespace(List<HTableDescriptor> htds) {
    if (CollectionUtils.isEmpty(htds)) {
        return Collections.emptyList();
    }
    List<HTableDescriptor> filteredHtds = new ArrayList<>();
    for (HTableDescriptor htd : htds) {
        TableName tableName = htd.getTableName();
        String namespace = tableName.getNamespaceAsString();
        if (this.namespace.equalsIgnoreCase(namespace)) {
            filteredHtds.add(htd);
        }
    }
    return filteredHtds;
}
 
Example 7
Source File: ReadOnlyAdminTemplate.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public boolean createTableIfNotExists(HTableDescriptor htd) {
    TableName tableName = htd.getTableName();
    boolean tableExists = delegate.tableExists(tableName);
    if (tableExists) {
        return false;
    }
    this.createTable(htd);
    return true;
}