Java Code Examples for org.apache.hadoop.hbase.client.TableDescriptor#getColumnFamilyCount()

The following examples show how to use org.apache.hadoop.hbase.client.TableDescriptor#getColumnFamilyCount() . 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: WALPerformanceEvaluation.java    From hbase with Apache License 2.0 5 votes vote down vote up
WALPutBenchmark(final HRegion region, final TableDescriptor htd,
    final long numIterations, final boolean noSync, final int syncInterval,
    final double traceFreq) {
  this.numIterations = numIterations;
  this.noSync = noSync;
  this.syncInterval = syncInterval;
  this.numFamilies = htd.getColumnFamilyCount();
  this.region = region;
  scopes = new TreeMap<>(Bytes.BYTES_COMPARATOR);
  for(byte[] fam : htd.getColumnFamilyNames()) {
    scopes.put(fam, 0);
  }
  String spanReceivers = getConf().get("hbase.trace.spanreceiver.classes");
  if (spanReceivers == null || spanReceivers.isEmpty()) {
    loopSampler = Sampler.NEVER;
  } else {
    if (traceFreq <= 0.0) {
      LOG.warn("Tracing enabled but traceFreq=0.");
      loopSampler = Sampler.NEVER;
    } else if (traceFreq >= 1.0) {
      loopSampler = Sampler.ALWAYS;
      if (numIterations > 1000) {
        LOG.warn("Full tracing of all iterations will produce a lot of data. Be sure your"
          + " SpanReceiver can keep up.");
      }
    } else {
      getConf().setDouble("hbase.sampler.fraction", traceFreq);
      loopSampler = new ProbabilitySampler(new HBaseHTraceConfiguration(getConf()));
    }
  }
}
 
Example 2
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);
  ColumnFamilyDescriptor cfd = selectFamily(selected);
  if (selected == null || cfd == null) {
    return;
  }

  Admin admin = connection.getAdmin();
  try {
    if (selected.getColumnFamilyCount() < 2) {
      LOG.info("No enough column families to delete in table " + selected.getTableName());
      return;
    }
    TableName tableName = selected.getTableName();
    LOG.info("Deleting column family: " + cfd + " from table: " + tableName);
    admin.deleteColumnFamily(tableName, cfd.getName());
    // assertion
    TableDescriptor freshTableDesc = admin.getDescriptor(tableName);
    Assert.assertFalse("Column family: " + cfd + " was not added",
        freshTableDesc.hasColumnFamily(cfd.getName()));
    Assert.assertTrue(
      "After delete column family, Table: " + tableName + " is not disabled",
      admin.isTableDisabled(tableName));
    disabledTables.put(tableName, freshTableDesc);
    LOG.info("Deleted column family: " + cfd + " from table: " + tableName);
  } catch (Exception e) {
    LOG.warn("Caught exception in action: " + this.getClass());
    throw e;
  } finally {
    admin.close();
  }
}
 
Example 3
Source File: PerformanceEvaluation.java    From hbase with Apache License 2.0 4 votes vote down vote up
static boolean checkTable(Admin admin, TestOptions opts) throws IOException {
  TableName tableName = TableName.valueOf(opts.tableName);
  boolean needsDelete = false, exists = admin.tableExists(tableName);
  boolean isReadCmd = opts.cmdName.toLowerCase(Locale.ROOT).contains("read")
    || opts.cmdName.toLowerCase(Locale.ROOT).contains("scan");
  if (!exists && isReadCmd) {
    throw new IllegalStateException(
      "Must specify an existing table for read commands. Run a write command first.");
  }
  TableDescriptor desc =
    exists ? admin.getDescriptor(TableName.valueOf(opts.tableName)) : null;
  byte[][] splits = getSplits(opts);

  // recreate the table when user has requested presplit or when existing
  // {RegionSplitPolicy,replica count} does not match requested, or when the
  // number of column families does not match requested.
  if ((exists && opts.presplitRegions != DEFAULT_OPTS.presplitRegions)
    || (!isReadCmd && desc != null &&
        !StringUtils.equals(desc.getRegionSplitPolicyClassName(), opts.splitPolicy))
    || (!isReadCmd && desc != null && desc.getRegionReplication() != opts.replicas)
    || (desc != null && desc.getColumnFamilyCount() != opts.families)) {
    needsDelete = true;
    // wait, why did it delete my table?!?
    LOG.debug(MoreObjects.toStringHelper("needsDelete")
      .add("needsDelete", needsDelete)
      .add("isReadCmd", isReadCmd)
      .add("exists", exists)
      .add("desc", desc)
      .add("presplit", opts.presplitRegions)
      .add("splitPolicy", opts.splitPolicy)
      .add("replicas", opts.replicas)
      .add("families", opts.families)
      .toString());
  }

  // remove an existing table
  if (needsDelete) {
    if (admin.isTableEnabled(tableName)) {
      admin.disableTable(tableName);
    }
    admin.deleteTable(tableName);
  }

  // table creation is necessary
  if (!exists || needsDelete) {
    desc = getTableDescriptor(opts);
    if (splits != null) {
      if (LOG.isDebugEnabled()) {
        for (int i = 0; i < splits.length; i++) {
          LOG.debug(" split " + i + ": " + Bytes.toStringBinary(splits[i]));
        }
      }
    }
    if (splits != null) {
      admin.createTable(desc, splits);
    } else {
      admin.createTable(desc);
    }
    LOG.info("Table " + desc + " created");
  }
  return admin.tableExists(tableName);
}