org.apache.hadoop.hbase.HTableDescriptor - java examples

Here are the examples of the java api org.apache.hadoop.hbase.HTableDescriptor taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

155 Examples 7

19 View Complete Implementation : Constraints.java
Copyright Apache License 2.0
Author : fengchen8086
/**
 * Add configuration-less constraints to the table.
 * <p>
 * This will overwrite any configuration replacedociated with the previous
 * constraint of the same clreplaced.
 * <p>
 * Each constraint, when added to the table, will have a specific priority,
 * dictating the order in which the {@link Constraint} will be run. A
 * {@link Constraint} earlier in the list will be run before those later in
 * the list. The same logic applies between two Constraints over time (earlier
 * added is run first on the regionserver).
 *
 * @param desc
 *          {@link HTableDescriptor} to add {@link Constraint Constraints}
 * @param constraints
 *          {@link Constraint Constraints} to add. All constraints are
 *          considered automatically enabled on add
 * @throws IOException
 *           If constraint could not be serialized/added to table
 */
public static void add(HTableDescriptor desc, Clreplaced<? extends Constraint>... constraints) throws IOException {
    // make sure constraints are enabled
    enable(desc);
    long priority = getNextPriority(desc);
    // store each constraint
    for (Clreplaced<? extends Constraint> clazz : constraints) {
        addConstraint(desc, clazz, null, priority++);
    }
    updateLatestPriority(desc, priority);
}

19 View Complete Implementation : CreateTableHandler.java
Copyright Apache License 2.0
Author : fengchen8086
/**
 * Create any replicas for the regions (the default replicas that was
 * already created is preplaceded to the method)
 * @param hTableDescriptor
 * @param regions default replicas
 * @return the combined list of default and non-default replicas
 */
protected List<HRegionInfo> addReplicas(HTableDescriptor hTableDescriptor, List<HRegionInfo> regions) {
    int numRegionReplicas = hTableDescriptor.getRegionReplication() - 1;
    if (numRegionReplicas <= 0) {
        return regions;
    }
    List<HRegionInfo> hRegionInfos = new ArrayList<HRegionInfo>((numRegionReplicas + 1) * regions.size());
    for (int i = 0; i < regions.size(); i++) {
        for (int j = 1; j <= numRegionReplicas; j++) {
            hRegionInfos.add(RegionReplicaUtil.getRegionInfoForReplica(regions.get(i), j));
        }
    }
    hRegionInfos.addAll(regions);
    return hRegionInfos;
}

19 View Complete Implementation : ConstraintProcessor.java
Copyright Apache License 2.0
Author : fengchen8086
@Override
public void start(CoprocessorEnvironment environment) {
    // make sure we are on a region server
    if (!(environment instanceof RegionCoprocessorEnvironment)) {
        throw new IllegalArgumentException("Constraints only act on regions - started in an environment that was not a region");
    }
    RegionCoprocessorEnvironment env = (RegionCoprocessorEnvironment) environment;
    HTableDescriptor desc = env.getRegion().getTableDesc();
    // load all the constraints from the HTD
    try {
        this.constraints = Constraints.getConstraints(desc, clreplacedloader);
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    }
    if (LOG.isInfoEnabled()) {
        LOG.info("Finished loading " + constraints.size() + " user Constraints on table: " + desc.getTableName());
    }
}

19 View Complete Implementation : FSTableDescriptors.java
Copyright Apache License 2.0
Author : fengchen8086
/**
 * Create new HTableDescriptor in HDFS. Happens when we are creating table. If
 * forceCreation is true then even if previous table descriptor is present it
 * will be overwritten
 *
 * @return True if we successfully created file.
 */
public boolean createTableDescriptor(HTableDescriptor htd, boolean forceCreation) throws IOException {
    Path tableDir = getTableDir(htd.getTableName());
    return createTableDescriptorForTableDirectory(tableDir, htd, forceCreation);
}

19 View Complete Implementation : TestEnableTableHandler.java
Copyright Apache License 2.0
Author : fengchen8086
public static void createTable(HBaseTestingUtility testUtil, HBaseAdmin admin, HTableDescriptor htd, byte[][] splitKeys) throws Exception {
    // NOTE: We need a latch because admin is not sync,
    // so the postOp coprocessor method may be called after the admin operation returned.
    MasterSyncObserver observer = (MasterSyncObserver) testUtil.getHBaseCluster().getMaster().getMasterCoprocessorHost().findCoprocessor(MasterSyncObserver.clreplaced.getName());
    observer.tableCreationLatch = new CountDownLatch(1);
    if (splitKeys != null) {
        admin.createTable(htd, splitKeys);
    } else {
        admin.createTable(htd);
    }
    observer.tableCreationLatch.await();
    observer.tableCreationLatch = null;
    testUtil.waitUntilAllRegionsreplacedigned(htd.getTableName());
}

19 View Complete Implementation : IntegrationTestBulkLoad.java
Copyright Apache License 2.0
Author : fengchen8086
/**
 * Modify table {@code getTableName()} to carry {@link SlowMeCoproScanOperations}.
 */
private void installSlowingCoproc() throws IOException, InterruptedException {
    int replicaCount = conf.getInt(NUM_REPLICA_COUNT_KEY, NUM_REPLICA_COUNT_DEFAULT);
    if (replicaCount == NUM_REPLICA_COUNT_DEFAULT)
        return;
    TableName t = getTablename();
    Admin admin = util.getHBaseAdmin();
    HTableDescriptor desc = admin.getTableDescriptor(t);
    desc.addCoprocessor(SlowMeCoproScanOperations.clreplaced.getName());
    HBaseTestingUtility.modifyTableSync(admin, desc);
    // sleep for sometime. Hope is that the regions are closed/opened before
    // the sleep returns. TODO: do this better
    Thread.sleep(30000);
}

19 View Complete Implementation : TestFromClientSide3.java
Copyright Apache License 2.0
Author : fengchen8086
/**
 * @throws java.lang.Exception
 */
@After
public void tearDown() throws Exception {
    for (HTableDescriptor htd : TEST_UTIL.getHBaseAdmin().listTables()) {
        LOG.info("Tear down, remove table=" + htd.getTableName());
        TEST_UTIL.deleteTable(htd.getTableName());
    }
}

19 View Complete Implementation : Constraints.java
Copyright Apache License 2.0
Author : fengchen8086
/**
 * Write the raw constraint and configuration to the descriptor.
 * <p>
 * This method takes care of creating a new configuration based on the preplaceded
 * in configuration and then updating that with enabled and priority of the
 * constraint.
 * <p>
 * When a constraint is added, it is automatically enabled.
 */
private static void addConstraint(HTableDescriptor desc, Clreplaced<? extends Constraint> clazz, Configuration conf, long priority) throws IOException {
    writeConstraint(desc, serializeConstraintClreplaced(clazz), configure(conf, true, priority));
}

19 View Complete Implementation : CCIndexAdmin.java
Copyright Apache License 2.0
Author : fengchen8086
/**
 * Check if table is existed.
 *
 * @param tableName name of table to check
 * @return true if table is existed
 * @throws IOException-if a remote or network exception occurs
 */
public boolean tableExists(TableName tableName) throws IOException {
    try {
        HTableDescriptor desc = admin.getTableDescriptor(tableName);
        if (isIndexTable(desc)) {
            return false;
        }
    } catch (IOException e) {
        return false;
    }
    return true;
}

19 View Complete Implementation : CreateTableProcedure.java
Copyright Apache License 2.0
Author : fengchen8086
/**
 * Create any replicas for the regions (the default replicas that was
 * already created is preplaceded to the method)
 * @param hTableDescriptor descriptor to use
 * @param regions default replicas
 * @return the combined list of default and non-default replicas
 */
private static List<HRegionInfo> addReplicas(final MasterProcedureEnv env, final HTableDescriptor hTableDescriptor, final List<HRegionInfo> regions) {
    int numRegionReplicas = hTableDescriptor.getRegionReplication() - 1;
    if (numRegionReplicas <= 0) {
        return regions;
    }
    List<HRegionInfo> hRegionInfos = new ArrayList<HRegionInfo>((numRegionReplicas + 1) * regions.size());
    for (int i = 0; i < regions.size(); i++) {
        for (int j = 1; j <= numRegionReplicas; j++) {
            hRegionInfos.add(RegionReplicaUtil.getRegionInfoForReplica(regions.get(i), j));
        }
    }
    hRegionInfos.addAll(regions);
    return hRegionInfos;
}

19 View Complete Implementation : CreateTableProcedure.java
Copyright Apache License 2.0
Author : fengchen8086
protected static List<HRegionInfo> createFsLayout(final MasterProcedureEnv env, final HTableDescriptor hTableDescriptor, final List<HRegionInfo> newRegions) throws IOException {
    return createFsLayout(env, hTableDescriptor, newRegions, new CreateHdfsRegions() {

        @Override
        public List<HRegionInfo> createHdfsRegions(final MasterProcedureEnv env, final Path tableRootDir, final TableName tableName, final List<HRegionInfo> newRegions) throws IOException {
            HRegionInfo[] regions = newRegions != null ? newRegions.toArray(new HRegionInfo[newRegions.size()]) : null;
            return ModifyRegionUtils.createRegions(env.getMasterConfiguration(), tableRootDir, hTableDescriptor, regions, null);
        }
    });
}

19 View Complete Implementation : CCIndexAdmin.java
Copyright Apache License 2.0
Author : fengchen8086
/**
 * List all index columns of table.
 *
 * @param tableName
 * @return
 * @throws IOException
 */
public byte[][] listIndex(TableName tableName) throws IOException {
    HTableDescriptor desc = admin.getTableDescriptor(tableName);
    if (isIndexTable(desc)) {
        throw new TableNotFoundException(tableName);
    }
    IndexTableDescriptor indexDesc = new IndexTableDescriptor(desc);
    return indexDesc.getIndexedColumns();
}

19 View Complete Implementation : TableEventHandler.java
Copyright Apache License 2.0
Author : fengchen8086
/**
 * Gets a TableDescriptor from the masterServices.  Can Throw exceptions.
 *
 * @return Table descriptor for this table
 * @throws FileNotFoundException
 * @throws IOException
 */
public HTableDescriptor getTableDescriptor() throws FileNotFoundException, IOException {
    HTableDescriptor htd = this.masterServices.getTableDescriptors().get(tableName);
    if (htd == null) {
        throw new IOException("HTableDescriptor missing for " + tableName);
    }
    return htd;
}

19 View Complete Implementation : TestConstraints.java
Copyright Apache License 2.0
Author : fengchen8086
/**
 * Test that if a constraint hasn't been set that there are no problems with
 * attempting to remove it.
 *
 * @throws Throwable
 *           on failure.
 */
@Test
public void testRemoveUnsetConstraint() throws Throwable {
    HTableDescriptor desc = new HTableDescriptor(TableName.valueOf("table"));
    Constraints.remove(desc);
    Constraints.remove(desc, AlsoWorks.clreplaced);
}

19 View Complete Implementation : Constraints.java
Copyright Apache License 2.0
Author : fengchen8086
/**
 * Check to see if the given constraint is enabled.
 *
 * @param desc
 *          {@link HTableDescriptor} to check.
 * @param clazz
 *          {@link Constraint} to check for
 * @return <tt>true</tt> if the {@link Constraint} is present and enabled.
 *         <tt>false</tt> otherwise.
 * @throws IOException
 *           If the constraint has improperly stored in the table
 */
public static boolean enabled(HTableDescriptor desc, Clreplaced<? extends Constraint> clazz) throws IOException {
    // get the kv
    Pair<String, String> entry = getKeyValueForClreplaced(desc, clazz);
    // its not enabled so just return false. In fact, its not even present!
    if (entry == null) {
        return false;
    }
    // get the info about the constraint
    Configuration conf = readConfiguration(entry.getSecond());
    return conf.getBoolean(ENABLED_KEY, false);
}

19 View Complete Implementation : HFileOutputFormat2.java
Copyright Apache License 2.0
Author : fengchen8086
/**
 * Configure a MapReduce Job to perform an incremental load into the given
 * table. This
 * <ul>
 *   <li>Inspects the table to configure a total order parreplacedioner</li>
 *   <li>Uploads the parreplacedions file to the cluster and adds it to the DistributedCache</li>
 *   <li>Sets the number of reduce tasks to match the current number of regions</li>
 *   <li>Sets the output key/value clreplaced to match HFileOutputFormat2's requirements</li>
 *   <li>Sets the reducer up to perform the appropriate sorting (either KeyValueSortReducer or
 *     PutSortReducer)</li>
 * </ul>
 * The user should be sure to set the map output value clreplaced to either KeyValue or Put before
 * running this function.
 */
public static void configureIncrementalLoad(Job job, HTableDescriptor tableDescriptor, RegionLocator regionLocator) throws IOException {
    configureIncrementalLoad(job, tableDescriptor, regionLocator, HFileOutputFormat2.clreplaced);
}

19 View Complete Implementation : CCIndexAdmin.java
Copyright Apache License 2.0
Author : fengchen8086
/**
 * Check if a table has indexes.
 *
 * @param tableName
 * @return true if table has any index
 * @throws IOException
 */
public boolean hasIndex(TableName tableName) throws IOException {
    HTableDescriptor desc = admin.getTableDescriptor(tableName);
    if (isIndexTable(desc)) {
        throw new TableNotFoundException(tableName);
    }
    IndexTableDescriptor indexDesc = new IndexTableDescriptor(desc);
    return indexDesc.hasIndex();
}

19 View Complete Implementation : CCIndexAdmin.java
Copyright Apache License 2.0
Author : fengchen8086
/**
 * Get IndexDescriptor of a table.
 *
 * @param tableName
 * @return IndexDescriptor of the table
 * @throws IOException
 */
public IndexTableDescriptor getIndexTableDescriptor(TableName tableName) throws IOException {
    HTableDescriptor desc = admin.getTableDescriptor(tableName);
    if (isIndexTable(desc)) {
        throw new TableNotFoundException(tableName);
    }
    return new IndexTableDescriptor(desc);
}

19 View Complete Implementation : TestRestoreSnapshotHelper.java
Copyright Apache License 2.0
Author : fengchen8086
/**
 * Execute the restore operation
 * @param snapshotDir The snapshot directory to use as "restore source"
 * @param sd The snapshot descriptor
 * @param htdClone The HTableDescriptor of the table to restore/clone.
 */
public void testRestore(final Path snapshotDir, final SnapshotDescription sd, final HTableDescriptor htdClone) throws IOException {
    LOG.debug("pre-restore table=" + htdClone.getTableName() + " snapshot=" + snapshotDir);
    FSUtils.logFileSystemState(fs, rootDir, LOG);
    new FSTableDescriptors(conf).createTableDescriptor(htdClone);
    RestoreSnapshotHelper helper = getRestoreHelper(rootDir, snapshotDir, sd, htdClone);
    helper.restoreHdfsRegions();
    LOG.debug("post-restore table=" + htdClone.getTableName() + " snapshot=" + snapshotDir);
    FSUtils.logFileSystemState(fs, rootDir, LOG);
}

19 View Complete Implementation : UnmodifyableHTableDescriptor.java
Copyright Apache License 2.0
Author : fengchen8086
/*
   * @param desc
   * @return Families as unmodifiable array.
   */
private static HColumnDescriptor[] getUnmodifyableFamilies(final HTableDescriptor desc) {
    HColumnDescriptor[] f = new HColumnDescriptor[desc.getFamilies().size()];
    int i = 0;
    for (HColumnDescriptor c : desc.getFamilies()) {
        f[i++] = c;
    }
    return f;
}

19 View Complete Implementation : ModifyTableProcedure.java
Copyright Apache License 2.0
Author : fengchen8086
/**
 * Removes from hdfs the families that are not longer present in the new table descriptor.
 * @param env MasterProcedureEnv
 * @throws IOException
 */
private void deleteFromFs(final MasterProcedureEnv env, final HTableDescriptor oldHTableDescriptor, final HTableDescriptor newHTableDescriptor) throws IOException {
    final Set<byte[]> oldFamilies = oldHTableDescriptor.getFamiliesKeys();
    final Set<byte[]> newFamilies = newHTableDescriptor.getFamiliesKeys();
    for (byte[] familyName : oldFamilies) {
        if (!newFamilies.contains(familyName)) {
            MasterDDLOperationHelper.deleteColumnFamilyFromFileSystem(env, getTableName(), getRegionInfoList(env), familyName);
        }
    }
}

19 View Complete Implementation : IncreasingToUpperBoundRegionSplitPolicy.java
Copyright Apache License 2.0
Author : fengchen8086
@Override
protected void configureForRegion(HRegion region) {
    super.configureForRegion(region);
    Configuration conf = getConf();
    initialSize = conf.getLong("hbase.increasing.policy.initial.size", -1);
    if (initialSize > 0) {
        return;
    }
    HTableDescriptor desc = region.getTableDesc();
    if (desc != null) {
        initialSize = 2 * desc.getMemStoreFlushSize();
    }
    if (initialSize <= 0) {
        initialSize = 2 * conf.getLong(HConstants.HREGION_MEMSTORE_FLUSH_SIZE, HTableDescriptor.DEFAULT_MEMSTORE_FLUSH_SIZE);
    }
}

19 View Complete Implementation : CCIndexAdmin.java
Copyright Apache License 2.0
Author : fengchen8086
/**
 * Get the KeyGen clreplaced for table's index key.
 *
 * @param tableName
 * @return clreplaced
 * @throws IOException
 */
public Clreplaced<? extends IndexKeyGenerator> getKeygenClreplaced(TableName tableName) throws IOException {
    HTableDescriptor desc = admin.getTableDescriptor(tableName);
    IndexTableDescriptor indexDesc = new IndexTableDescriptor(desc);
    return indexDesc.getKeygenClreplaced();
}

19 View Complete Implementation : Constraints.java
Copyright Apache License 2.0
Author : fengchen8086
/**
 * Disable the given {@link Constraint}. Retains all the information (e.g.
 * Configuration) for the {@link Constraint}, but it just doesn't load the
 * {@link Constraint} on the table.
 *
 * @param desc
 *          {@link HTableDescriptor} to modify
 * @param clazz
 *          {@link Constraint} to disable.
 * @throws IOException
 *           if the constraint cannot be found
 */
public static void disableConstraint(HTableDescriptor desc, Clreplaced<? extends Constraint> clazz) throws IOException {
    changeConstraintEnabled(desc, clazz, false);
}

19 View Complete Implementation : CCIndexAdmin.java
Copyright Apache License 2.0
Author : fengchen8086
/**
 * Set the KeyGen clreplaced for table's index key.
 *
 * @param tableName
 * @param clreplacedName
 * @throws IOException
 * @throws ClreplacedNotFoundException
 */
public void setKeygenClreplaced(TableName tableName, String clreplacedName) throws IOException, ClreplacedNotFoundException {
    HTableDescriptor desc = admin.getTableDescriptor(tableName);
    IndexTableDescriptor indexDesc = new IndexTableDescriptor(desc);
    indexDesc.setKeygenClreplaced(clreplacedName);
    if (isTableEnabled(tableName)) {
        throw new IOException("Table " + tableName + " is enabled! Disable it first!");
    }
    // modify base table
    admin.modifyTable(tableName, indexDesc.getTableDescriptor());
// TODO
// maybe need to enable and disable, check add indexes
}

19 View Complete Implementation : ConstantSizeRegionSplitPolicy.java
Copyright Apache License 2.0
Author : fengchen8086
@Override
protected void configureForRegion(HRegion region) {
    super.configureForRegion(region);
    Configuration conf = getConf();
    HTableDescriptor desc = region.getTableDesc();
    if (desc != null) {
        this.desiredMaxFileSize = desc.getMaxFileSize();
    }
    if (this.desiredMaxFileSize <= 0) {
        this.desiredMaxFileSize = conf.getLong(HConstants.HREGION_MAX_FILESIZE, HConstants.DEFAULT_MAX_FILE_SIZE);
    }
    double jitter = conf.getDouble("hbase.hregion.max.filesize.jitter", 0.25D);
    this.desiredMaxFileSize += (long) (desiredMaxFileSize * (RANDOM.nextFloat() - 0.5D) * jitter);
}

19 View Complete Implementation : TestFSHLog.java
Copyright Apache License 2.0
Author : fengchen8086
@Test
public void testSyncRunnerIndexOverflow() throws IOException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    final String name = "testSyncRunnerIndexOverflow";
    FSHLog log = new FSHLog(fs, FSUtils.getRootDir(conf), name, HConstants.HREGION_OLDLOGDIR_NAME, conf, null, true, null, null);
    try {
        Field ringBufferEventHandlerField = FSHLog.clreplaced.getDeclaredField("ringBufferEventHandler");
        ringBufferEventHandlerField.setAccessible(true);
        FSHLog.RingBufferEventHandler ringBufferEventHandler = (FSHLog.RingBufferEventHandler) ringBufferEventHandlerField.get(log);
        Field syncRunnerIndexField = FSHLog.RingBufferEventHandler.clreplaced.getDeclaredField("syncRunnerIndex");
        syncRunnerIndexField.setAccessible(true);
        syncRunnerIndexField.set(ringBufferEventHandler, Integer.MAX_VALUE - 1);
        HTableDescriptor htd = new HTableDescriptor(TableName.valueOf("t1")).addFamily(new HColumnDescriptor("row"));
        HRegionInfo hri = new HRegionInfo(htd.getTableName(), HConstants.EMPTY_START_ROW, HConstants.EMPTY_END_ROW);
        MultiVersionConcurrencyControl mvcc = new MultiVersionConcurrencyControl();
        for (int i = 0; i < 10; i++) {
            addEdits(log, hri, htd, 1, mvcc);
        }
    } finally {
        log.close();
    }
}

19 View Complete Implementation : HFileOutputFormat2.java
Copyright Apache License 2.0
Author : fengchen8086
public static void configureIncrementalLoadMap(Job job, Table table) throws IOException {
    Configuration conf = job.getConfiguration();
    job.setOutputKeyClreplaced(ImmutableBytesWritable.clreplaced);
    job.setOutputValueClreplaced(KeyValue.clreplaced);
    job.setOutputFormatClreplaced(HFileOutputFormat2.clreplaced);
    // Set compression algorithms based on column families
    configureCompression(conf, table.getTableDescriptor());
    configureBloomType(table.getTableDescriptor(), conf);
    configureBlockSize(table.getTableDescriptor(), conf);
    HTableDescriptor tableDescriptor = table.getTableDescriptor();
    configureDataBlockEncoding(tableDescriptor, conf);
    TableMapReduceUtil.addDependencyJars(job);
    TableMapReduceUtil.initCredentials(job);
    LOG.info("Incremental table " + table.getName() + " output configured.");
}

19 View Complete Implementation : ModifyRegionUtils.java
Copyright Apache License 2.0
Author : fengchen8086
/**
 * Create new set of regions on the specified file-system.
 * NOTE: that you should add the regions to hbase:meta after this operation.
 *
 * @param conf {@link Configuration}
 * @param rootDir Root directory for HBase instance
 * @param hTableDescriptor description of the table
 * @param newRegions {@link HRegionInfo} that describes the regions to create
 * @throws IOException
 */
public static List<HRegionInfo> createRegions(final Configuration conf, final Path rootDir, final HTableDescriptor hTableDescriptor, final HRegionInfo[] newRegions) throws IOException {
    return createRegions(conf, rootDir, hTableDescriptor, newRegions, null);
}

19 View Complete Implementation : Constraints.java
Copyright Apache License 2.0
Author : fengchen8086
/**
 * Check to see if the Constraint is currently set.
 *
 * @param desc
 *          {@link HTableDescriptor} to check
 * @param clazz
 *          {@link Constraint} clreplaced to check for.
 * @return <tt>true</tt> if the {@link Constraint} is present, even if it is
 *         disabled. <tt>false</tt> otherwise.
 */
public static boolean has(HTableDescriptor desc, Clreplaced<? extends Constraint> clazz) {
    return getKeyValueForClreplaced(desc, clazz) != null;
}

19 View Complete Implementation : RegionLocationFinder.java
Copyright Apache License 2.0
Author : fengchen8086
/**
 * return HTableDescriptor for a given tableName
 *
 * @param tableName the table name
 * @return HTableDescriptor
 * @throws IOException
 */
protected HTableDescriptor getTableDescriptor(TableName tableName) throws IOException {
    HTableDescriptor tableDescriptor = null;
    try {
        if (this.services != null && this.services.getTableDescriptors() != null) {
            tableDescriptor = this.services.getTableDescriptors().get(tableName);
        }
    } catch (FileNotFoundException fnfe) {
        LOG.debug("FileNotFoundException during getTableDescriptors." + " Current table name = " + tableName, fnfe);
    }
    return tableDescriptor;
}

19 View Complete Implementation : FSTableDescriptors.java
Copyright Apache License 2.0
Author : fengchen8086
/**
 * Update table descriptor on the file system
 * @throws IOException Thrown if failed update.
 * @throws NotImplementedException if in read only mode
 */
@VisibleForTesting
Path updateTableDescriptor(HTableDescriptor htd) throws IOException {
    if (fsreadonly) {
        throw new NotImplementedException("Cannot update a table descriptor - in read only mode");
    }
    Path tableDir = getTableDir(htd.getTableName());
    Path p = writeTableDescriptor(fs, htd, tableDir, getTableInfoPath(tableDir));
    if (p == null)
        throw new IOException("Failed update");
    LOG.info("Updated tableinfo=" + p);
    if (usecache) {
        this.cache.put(htd.getTableName(), htd);
    }
    return p;
}

19 View Complete Implementation : Constraints.java
Copyright Apache License 2.0
Author : fengchen8086
/**
 * Add a {@link Constraint} to the table with the given configuration
 * <p>
 * Each constraint, when added to the table, will have a specific priority,
 * dictating the order in which the {@link Constraint} will be run. A
 * {@link Constraint} added will run on the regionserver before those added to
 * the {@link HTableDescriptor} later.
 *
 * @param desc
 *          table descriptor to the constraint to
 * @param constraint
 *          to be added
 * @param conf
 *          configuration replacedociated with the constraint
 * @throws IOException
 *           if any constraint could not be deserialized. replacedumes if 1
 *           constraint is not loaded properly, something has gone terribly
 *           wrong and that all constraints need to be enforced.
 */
public static void add(HTableDescriptor desc, Clreplaced<? extends Constraint> constraint, Configuration conf) throws IOException {
    enable(desc);
    long priority = getNextPriority(desc);
    addConstraint(desc, constraint, conf, priority++);
    updateLatestPriority(desc, priority);
}

19 View Complete Implementation : Constraints.java
Copyright Apache License 2.0
Author : fengchen8086
/**
 * Get the kv {@link Entry} in the descriptor for the specified clreplaced
 *
 * @param desc
 *          {@link HTableDescriptor} to read
 * @param clazz
 *          to search for
 * @return the {@link Pair} of <key, value> in the table, if that clreplaced is
 *         present. <tt>null</tt> otherwise.
 */
private static Pair<String, String> getKeyValueForClreplaced(HTableDescriptor desc, Clreplaced<? extends Constraint> clazz) {
    // get the serialized version of the constraint
    String key = serializeConstraintClreplaced(clazz);
    String value = desc.getValue(key);
    return value == null ? null : new Pair<String, String>(key, value);
}

19 View Complete Implementation : CCIndexAdmin.java
Copyright Apache License 2.0
Author : fengchen8086
/**
 * Set each column's data type of this table.
 *
 * @param columnTypes
 * @throws IOException
 */
public void setColumnInfoMap(TableName tableName, Map<byte[], DataType> columnTypes) throws IOException {
    HTableDescriptor desc = admin.getTableDescriptor(tableName);
    if (isTableEnabled(tableName)) {
        throw new IOException("Table " + tableName + " is enabled! Disable it first!");
    }
    StringBuilder sb = new StringBuilder();
    if (columnTypes != null && !columnTypes.isEmpty()) {
        int i = 0;
        for (Map.Entry<byte[], DataType> entry : columnTypes.entrySet()) {
            sb.append(Bytes.toString(entry.getKey()));
            sb.append(":");
            sb.append(entry.getValue().toString());
            if (i != columnTypes.size() - 1) {
                sb.append(",");
            }
            i++;
        }
    }
    desc.setValue("DATA_FORMAT", sb.toString());
    admin.modifyTable(tableName, desc);
// TODO maybe need to enable and disable, check add indexes
}

19 View Complete Implementation : TestRemoteTable.java
Copyright Apache License 2.0
Author : fengchen8086
@Test
public void testGetTableDescriptor() throws IOException {
    Table table = null;
    try {
        table = new HTable(TEST_UTIL.getConfiguration(), TABLE);
        HTableDescriptor local = table.getTableDescriptor();
        replacedertEquals(remoteTable.getTableDescriptor(), local);
    } finally {
        if (null != table)
            table.close();
    }
}

19 View Complete Implementation : FSTableDescriptors.java
Copyright Apache License 2.0
Author : fengchen8086
/* (non-Javadoc)
   * @see org.apache.hadoop.hbase.TableDescriptors#getTableDescriptors(org.apache.hadoop.fs.FileSystem, org.apache.hadoop.fs.Path)
   */
@Override
public Map<String, HTableDescriptor> getByNamespace(String name) throws IOException {
    Map<String, HTableDescriptor> htds = new TreeMap<String, HTableDescriptor>();
    List<Path> tableDirs = FSUtils.getLocalTableDirs(fs, FSUtils.getNamespaceDir(rootdir, name));
    for (Path d : tableDirs) {
        HTableDescriptor htd = null;
        try {
            htd = get(FSUtils.getTableName(d));
        } catch (FileNotFoundException fnfe) {
            // inability of retrieving one HTD shouldn't stop getting the remaining
            LOG.warn("Trouble retrieving htd", fnfe);
        }
        if (htd == null)
            continue;
        htds.put(FSUtils.getTableName(d).getNamereplacedtring(), htd);
    }
    return htds;
}

19 View Complete Implementation : TestRegionReplicaReplicationEndpoint.java
Copyright Apache License 2.0
Author : fengchen8086
@Test(timeout = 240000)
public void testRegionReplicaReplicationPeerIsCreatedForModifyTable() throws Exception {
    // modify a table by adding region replicas. Check whether the replication peer is created
    // and replication started.
    ReplicationAdmin admin = new ReplicationAdmin(HTU.getConfiguration());
    String peerId = "region_replica_replication";
    if (admin.getPeerConfig(peerId) != null) {
        admin.removePeer(peerId);
    }
    HTableDescriptor htd = HTU.createTableDescriptor("testRegionReplicaReplicationPeerIsCreatedForModifyTable");
    HTU.getHBaseAdmin().createTable(htd);
    // replacedert that replication peer is not created yet
    ReplicationPeerConfig peerConfig = admin.getPeerConfig(peerId);
    replacedertNull(peerConfig);
    HTU.getHBaseAdmin().disableTable(htd.getTableName());
    htd.setRegionReplication(2);
    HTU.getHBaseAdmin().modifyTable(htd.getTableName(), htd);
    HTU.getHBaseAdmin().enableTable(htd.getTableName());
    // replacedert peer configuration is correct
    peerConfig = admin.getPeerConfig(peerId);
    replacedertNotNull(peerConfig);
    replacedertEquals(peerConfig.getClusterKey(), ZKConfig.getZooKeeperClusterKey(HTU.getConfiguration()));
    replacedertEquals(peerConfig.getReplicationEndpointImpl(), RegionReplicaReplicationEndpoint.clreplaced.getName());
    admin.close();
}

19 View Complete Implementation : ModifyRegionUtils.java
Copyright Apache License 2.0
Author : fengchen8086
public static HRegionInfo[] createHRegionInfos(HTableDescriptor hTableDescriptor, byte[][] splitKeys) {
    long regionId = System.currentTimeMillis();
    HRegionInfo[] hRegionInfos = null;
    if (splitKeys == null || splitKeys.length == 0) {
        hRegionInfos = new HRegionInfo[] { new HRegionInfo(hTableDescriptor.getTableName(), null, null, false, regionId) };
    } else {
        int numRegions = splitKeys.length + 1;
        hRegionInfos = new HRegionInfo[numRegions];
        byte[] startKey = null;
        byte[] endKey = null;
        for (int i = 0; i < numRegions; i++) {
            endKey = (i == splitKeys.length) ? null : splitKeys[i];
            hRegionInfos[i] = new HRegionInfo(hTableDescriptor.getTableName(), startKey, endKey, false, regionId);
            startKey = endKey;
        }
    }
    return hRegionInfos;
}

19 View Complete Implementation : HFileOutputFormat.java
Copyright Apache License 2.0
Author : fengchen8086
/**
 * Serialize column family to data block encoding map to configuration.
 * Invoked while configuring the MR job for incremental load.
 *
 * @param table to read the properties from
 * @param conf to persist serialized values into
 * @throws IOException
 *           on failure to read column family descriptors
 */
@VisibleForTesting
static void configureDataBlockEncoding(Table table, Configuration conf) throws IOException {
    HTableDescriptor tableDescriptor = table.getTableDescriptor();
    HFileOutputFormat2.configureDataBlockEncoding(tableDescriptor, conf);
}

19 View Complete Implementation : Constraints.java
Copyright Apache License 2.0
Author : fengchen8086
private static long getNextPriority(HTableDescriptor desc) {
    String value = desc.getValue(COUNTER_KEY);
    long priority;
    // get the current priority
    if (value == null) {
        priority = MIN_PRIORITY;
    } else {
        priority = Long.parseLong(value) + 1;
    }
    return priority;
}

19 View Complete Implementation : TestLoadIncrementalHFilesSplitRecovery.java
Copyright Apache License 2.0
Author : fengchen8086
/**
 * Creates a table with given table name,specified number of column families<br>
 * and splitkeys if the table does not already exist.
 * @param table
 * @param cfs
 * @param SPLIT_KEYS
 */
private void setupTableWithSplitkeys(TableName table, int cfs, byte[][] SPLIT_KEYS) throws IOException {
    try {
        LOG.info("Creating table " + table);
        HTableDescriptor htd = new HTableDescriptor(table);
        for (int i = 0; i < cfs; i++) {
            htd.addFamily(new HColumnDescriptor(family(i)));
        }
        util.createTable(htd, SPLIT_KEYS);
    } catch (TableExistsException tee) {
        LOG.info("Table " + table + " already exists");
    }
}

19 View Complete Implementation : TestAdmin2.java
Copyright Apache License 2.0
Author : fengchen8086
private HRegionServer startAndWriteData(TableName tableName, byte[] value) throws IOException, InterruptedException {
    // When the hbase:meta table can be opened, the region servers are running
    new HTable(TEST_UTIL.getConfiguration(), TableName.META_TABLE_NAME).close();
    // Create the test table and open it
    HTableDescriptor desc = new HTableDescriptor(tableName);
    desc.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY));
    admin.createTable(desc);
    Table table = new HTable(TEST_UTIL.getConfiguration(), tableName);
    HRegionServer regionServer = TEST_UTIL.getRSForFirstRegionInTable(tableName);
    for (int i = 1; i <= 256; i++) {
        // 256 writes should cause 8 log rolls
        Put put = new Put(Bytes.toBytes("row" + String.format("%1$04d", i)));
        put.add(HConstants.CATALOG_FAMILY, null, value);
        table.put(put);
        if (i % 32 == 0) {
            // After every 32 writes sleep to let the log roller run
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
            // continue
            }
        }
    }
    table.close();
    return regionServer;
}

19 View Complete Implementation : Canary.java
Copyright Apache License 2.0
Author : fengchen8086
/*
   * Loops over regions that owns this table, and output some information abouts the state.
   */
private static List<Future<Void>> sniff(final Admin admin, final Sink sink, HTableDescriptor tableDesc, ExecutorService executor, TaskType taskType) throws Exception {
    Table table = null;
    try {
        table = admin.getConnection().getTable(tableDesc.getTableName());
    } catch (TableNotFoundException e) {
        return new ArrayList<Future<Void>>();
    }
    List<RegionTask> tasks = new ArrayList<RegionTask>();
    try {
        for (HRegionInfo region : admin.getTableRegions(tableDesc.getTableName())) {
            tasks.add(new RegionTask(admin.getConnection(), region, sink, taskType));
        }
    } finally {
        table.close();
    }
    return executor.invokeAll(tasks);
}

19 View Complete Implementation : FlushPolicyFactory.java
Copyright Apache License 2.0
Author : fengchen8086
/**
 * Get FlushPolicy clreplaced for the given table.
 */
public static Clreplaced<? extends FlushPolicy> getFlushPolicyClreplaced(HTableDescriptor htd, Configuration conf) throws IOException {
    String clreplacedName = htd.getFlushPolicyClreplacedName();
    if (clreplacedName == null) {
        clreplacedName = conf.get(HBASE_FLUSH_POLICY_KEY, DEFAULT_FLUSH_POLICY_CLreplaced.getName());
    }
    try {
        Clreplaced<? extends FlushPolicy> clazz = Clreplaced.forName(clreplacedName).replacedubclreplaced(FlushPolicy.clreplaced);
        return clazz;
    } catch (Exception e) {
        LOG.warn("Unable to load configured flush policy '" + clreplacedName + "' for table '" + htd.getTableName() + "', load default flush policy " + DEFAULT_FLUSH_POLICY_CLreplaced.getName() + " instead", e);
        return DEFAULT_FLUSH_POLICY_CLreplaced;
    }
}

19 View Complete Implementation : Constraints.java
Copyright Apache License 2.0
Author : fengchen8086
/**
 * Enable constraints on a table.
 * <p>
 * Currently, if you attempt to add a constraint to the table, then
 * Constraints will automatically be turned on.
 *
 * @param desc
 *          table description to add the processor
 * @throws IOException
 *           If the {@link ConstraintProcessor} CP couldn't be added to the
 *           table.
 */
public static void enable(HTableDescriptor desc) throws IOException {
    // if the CP has already been loaded, do nothing
    String clazz = ConstraintProcessor.clreplaced.getName();
    if (desc.hasCoprocessor(clazz)) {
        return;
    }
    // add the constrain processor CP to the table
    desc.addCoprocessor(clazz);
}

19 View Complete Implementation : Constraints.java
Copyright Apache License 2.0
Author : fengchen8086
/**
 * Enable the given {@link Constraint}. Retains all the information (e.g.
 * Configuration) for the {@link Constraint}, but makes sure that it gets
 * loaded on the table.
 *
 * @param desc
 *          {@link HTableDescriptor} to modify
 * @param clazz
 *          {@link Constraint} to enable
 * @throws IOException
 *           If the constraint cannot be properly deserialized
 */
public static void enableConstraint(HTableDescriptor desc, Clreplaced<? extends Constraint> clazz) throws IOException {
    changeConstraintEnabled(desc, clazz, true);
}

19 View Complete Implementation : MasterFileSystem.java
Copyright Apache License 2.0
Author : fengchen8086
private static void bootstrap(final Path rd, final Configuration c) throws IOException {
    LOG.info("BOOTSTRAP: creating hbase:meta region");
    try {
        // Bootstrapping, make sure blockcache is off.  Else, one will be
        // created here in bootstrap and it'll need to be cleaned up.  Better to
        // not make it in first place.  Turn off block caching for bootstrap.
        // Enable after.
        HRegionInfo metaHRI = new HRegionInfo(HRegionInfo.FIRST_META_REGIONINFO);
        HTableDescriptor metaDescriptor = new FSTableDescriptors(c).get(TableName.META_TABLE_NAME);
        setInfoFamilyCachingForMeta(metaDescriptor, false);
        HRegion meta = HRegion.createHRegion(metaHRI, rd, c, metaDescriptor, null, true, true);
        setInfoFamilyCachingForMeta(metaDescriptor, true);
        HRegion.closeHRegion(meta);
    } catch (IOException e) {
        e = RemoteExceptionHandler.checkIOException(e);
        LOG.error("bootstrap", e);
        throw e;
    }
}

19 View Complete Implementation : FSTableDescriptors.java
Copyright Apache License 2.0
Author : fengchen8086
/**
 * Returns a map from table name to table descriptor for all tables.
 */
@Override
public Map<String, HTableDescriptor> getAll() throws IOException {
    Map<String, HTableDescriptor> htds = new TreeMap<String, HTableDescriptor>();
    if (fsvisited && usecache) {
        for (Map.Entry<TableName, HTableDescriptor> entry : this.cache.entrySet()) {
            htds.put(entry.getKey().toString(), entry.getValue());
        }
        // add hbase:meta to the response
        htds.put(HTableDescriptor.META_TABLEDESC.getTableName().getNamereplacedtring(), HTableDescriptor.META_TABLEDESC);
    } else {
        LOG.debug("Fetching table descriptors from the filesystem.");
        boolean allvisited = true;
        for (Path d : FSUtils.getTableDirs(fs, rootdir)) {
            HTableDescriptor htd = null;
            try {
                htd = get(FSUtils.getTableName(d));
            } catch (FileNotFoundException fnfe) {
                // inability of retrieving one HTD shouldn't stop getting the remaining
                LOG.warn("Trouble retrieving htd", fnfe);
            }
            if (htd == null) {
                allvisited = false;
                continue;
            } else {
                htds.put(htd.getTableName().getNamereplacedtring(), htd);
            }
            fsvisited = allvisited;
        }
    }
    return htds;
}

19 View Complete Implementation : TestRegionObserverScannerOpenHook.java
Copyright Apache License 2.0
Author : fengchen8086
Region initHRegion(byte[] tableName, String callingMethod, Configuration conf, byte[]... families) throws IOException {
    HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(tableName));
    for (byte[] family : families) {
        htd.addFamily(new HColumnDescriptor(family));
    }
    HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false);
    Path path = new Path(DIR + callingMethod);
    HRegion r = HRegion.createHRegion(info, path, conf, htd);
    // this following piece is a hack. currently a coprocessorHost
    // is secretly loaded at OpenRegionHandler. we don't really
    // start a region server here, so just manually create cphost
    // and set it to region.
    RegionCoprocessorHost host = new RegionCoprocessorHost(r, null, conf);
    r.setCoprocessorHost(host);
    return r;
}