本文整理匯總了Java中org.apache.hadoop.hbase.client.HBaseAdmin.modifyTable方法的典型用法代碼示例。如果您正苦於以下問題:Java HBaseAdmin.modifyTable方法的具體用法?Java HBaseAdmin.modifyTable怎麽用?Java HBaseAdmin.modifyTable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.hadoop.hbase.client.HBaseAdmin
的用法示例。
在下文中一共展示了HBaseAdmin.modifyTable方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testModifyTable
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入方法依賴的package包/類
@Test
public void testModifyTable() throws IOException {
HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
// Create a table with one family
HTableDescriptor baseHtd = new HTableDescriptor(TABLE_NAME);
baseHtd.addFamily(new HColumnDescriptor(FAMILY_0));
admin.createTable(baseHtd);
admin.disableTable(TABLE_NAME);
try {
// Verify the table descriptor
verifyTableDescriptor(TABLE_NAME, FAMILY_0);
// Modify the table adding another family and verify the descriptor
HTableDescriptor modifiedHtd = new HTableDescriptor(TABLE_NAME);
modifiedHtd.addFamily(new HColumnDescriptor(FAMILY_0));
modifiedHtd.addFamily(new HColumnDescriptor(FAMILY_1));
admin.modifyTable(TABLE_NAME, modifiedHtd);
verifyTableDescriptor(TABLE_NAME, FAMILY_0, FAMILY_1);
} finally {
admin.deleteTable(TABLE_NAME);
}
}
示例2: updateTableAttribute
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入方法依賴的package包/類
/**
@param rawAttributeName is the attribute name viewed by applications, it allows multiple values. For example, secondaryIndex in secondaryIndex$1 and coprocessor in corpcessor$2
@param indexOfAttribute is of the same raw attribute name, for example 2 in secondary$2
*/
static void updateTableAttribute(Configuration conf, byte[] tableName, String rawAttributeName, int indexOfAttribute, boolean ifUpdateorRemove, String value) throws IOException{
HBaseAdmin admin = new HBaseAdmin(conf);
HTableDescriptor desc = admin.getTableDescriptor(tableName);
admin.disableTable(tableName);
// System.out.println("TTDEBUG: disable table " + Bytes.toString(tableName));
String coprocessorKey = rawAttributeName + indexOfAttribute;
if(!ifUpdateorRemove) {
desc.remove(Bytes.toBytes(coprocessorKey));
} else {
desc.setValue(coprocessorKey, value);
}
admin.modifyTable(tableName, desc);
// System.out.println("TTDEBUG: modify table " + Bytes.toString(tableName));
admin.enableTable(tableName);
// System.out.println("TTDEBUG: enable table " + Bytes.toString(tableName));
HTableDescriptor descNew = admin.getTableDescriptor(tableName);
//modify table is asynchronous, has to loop over to check
while (!desc.equals(descNew)){
System.err.println("TTDEBUG: waiting for descriptor to change: from " + descNew + " to " + desc);
try {Thread.sleep(500);} catch(InterruptedException ex) {}
descNew = admin.getTableDescriptor(tableName);
}
}
示例3: createIndexTable
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入方法依賴的package包/類
public static void createIndexTable(String userTable, Configuration conf,
Map<String, List<String>> indexColumnFamily) throws IOException, InterruptedException,
ClassNotFoundException {
HBaseAdmin hbaseAdmin = new IndexAdmin(conf);
try {
HTableDescriptor tableDescriptor = hbaseAdmin.getTableDescriptor(Bytes.toBytes(userTable));
String input = conf.get(TABLE_INPUT_COLS);
HTableDescriptor ihtd = parse(userTable, tableDescriptor, input, indexColumnFamily);
// disable the table
hbaseAdmin.disableTable(userTable);
// This will create the index table. Also modifies the existing table htable descriptor.
hbaseAdmin.modifyTable(Bytes.toBytes(userTable), ihtd);
hbaseAdmin.enableTable(Bytes.toBytes(userTable));
} finally {
if (hbaseAdmin != null) {
hbaseAdmin.close();
}
}
}
示例4: modifyTableSync
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入方法依賴的package包/類
private void modifyTableSync(HBaseAdmin admin, byte[] tableName, HTableDescriptor htd)
throws IOException {
admin.modifyTable(tableName, htd);
//wait until modify table finishes
for (int t = 0; t < 100; t++) { //10 sec timeout
HTableDescriptor td = admin.getTableDescriptor(htd.getName());
if (td.equals(htd)) {
break;
}
Threads.sleep(100);
}
}
示例5: updateCoprocessor
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入方法依賴的package包/類
private static void updateCoprocessor(Configuration conf, byte[] dataTableName) throws IOException{
HBaseAdmin admin = new HBaseAdmin(conf);
HTableDescriptor desc = admin.getTableDescriptor(dataTableName);
admin.disableTable(dataTableName);
System.out.println("TTDEBUG: disable data table");
if(INDEX_CP_CLASS.contains("null")) {
desc.remove(Bytes.toBytes(INDEX_CP_NAME));
} else {
desc.setValue(INDEX_CP_NAME, INDEX_CP_PATH + "|" + INDEX_CP_CLASS + "|1001|arg1=1,arg2=2");
}
HColumnDescriptor descIndexCF = desc.getFamily(Bytes.toBytes("cf"));//TOREMOVE don't use cf,
//KEEP_DELETED_CELLS => 'true'
descIndexCF.setKeepDeletedCells(true);
descIndexCF.setTimeToLive(HConstants.FOREVER);
descIndexCF.setMaxVersions(Integer.MAX_VALUE);
admin.modifyTable(dataTableName, desc);
System.out.println("TTDEBUG: modify data table");
admin.enableTable(dataTableName);
System.out.println("TTDEBUG: enable data table");
HTableDescriptor descNew = admin.getTableDescriptor(dataTableName);
//modify table is asynchronous, has to loop over to check
while (!desc.equals(descNew)){
System.out.println("TTDEBUG: waiting for descriptor to change: from " + descNew + " to " + desc);
try {Thread.sleep(500);} catch(InterruptedException ex) {}
descNew = admin.getTableDescriptor(dataTableName);
}
}
示例6: modifyTableSync
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入方法依賴的package包/類
private void modifyTableSync(HBaseAdmin admin, TableName tableName, HTableDescriptor htd)
throws IOException {
admin.modifyTable(tableName, htd);
//wait until modify table finishes
for (int t = 0; t < 100; t++) { //10 sec timeout
HTableDescriptor td = admin.getTableDescriptor(htd.getTableName());
if (td.equals(htd)) {
break;
}
Threads.sleep(100);
}
}
示例7: perform
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入方法依賴的package包/類
@Override
public void perform() throws Exception {
Random random = new Random();
HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
HBaseAdmin admin = util.getHBaseAdmin();
LOG.info("Performing action: Change bloom filter on all columns of table "
+ tableName);
HTableDescriptor tableDescriptor = admin.getTableDescriptor(Bytes
.toBytes(tableName));
HColumnDescriptor[] columnDescriptors = tableDescriptor.getColumnFamilies();
if (columnDescriptors == null || columnDescriptors.length == 0) {
return;
}
final BloomType[] bloomArray = BloomType.values();
final int bloomArraySize = bloomArray.length;
for (HColumnDescriptor descriptor : columnDescriptors) {
int bloomFilterIndex = random.nextInt(bloomArraySize);
LOG.debug("Performing action: About to set bloom filter type to "
+ bloomArray[bloomFilterIndex] + " on column "
+ descriptor.getNameAsString() + " of table " + tableName);
descriptor.setBloomFilterType(bloomArray[bloomFilterIndex]);
LOG.debug("Performing action: Just set bloom filter type to "
+ bloomArray[bloomFilterIndex] + " on column "
+ descriptor.getNameAsString() + " of table " + tableName);
}
admin.modifyTable(tableName, tableDescriptor);
}
示例8: modifyTable
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入方法依賴的package包/類
@Test
public void modifyTable() throws Exception {
String TABLE_NAME = "TEST_BENCHMARK";
//
Configuration configuration = createConfiguration();
HBaseAdmin hbaseAdmin = createHBaseAdmin(configuration);
HTableDescriptor htd = hbaseAdmin.getTableDescriptor(Bytes
.toBytes(TABLE_NAME));
//
HTableDescriptor newHtd = new HTableDescriptor(htd);
newHtd.setValue(HTableDescriptor.SPLIT_POLICY,
ConstantSizeRegionSplitPolicy.class.getName());
//
boolean disabled = false;
if (hbaseAdmin.isTableEnabled(TABLE_NAME)) {
hbaseAdmin.disableTable(TABLE_NAME);
disabled = true;
}
//
hbaseAdmin.modifyTable(Bytes.toBytes(TABLE_NAME), newHtd);
//
if (disabled) {
hbaseAdmin.enableTable(TABLE_NAME);
}
//
System.out.println(newHtd);
}
示例9: main
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
String quorum = "192.168.0.30,192.168.0.31,192.168.0.32";
//quorum = "192.168.8.191,192.168.1.192,192.168.1.193";
int port = 2181;
String znode = "/hyperbase1";
HBaseConnPool connPool = new HBaseClientManager(quorum, port, znode);
HBaseDDLHandler ddlHandler = new HBaseDDLHandler(connPool);
String tableName = "demo_test";
System.out.println("=============================== : delete");
ddlHandler.deleteTable(tableName);
String columnFamily = "cf";
System.out.println("=============================== : create");
ddlHandler.createTable(tableName, columnFamily, "cf2");
System.out.println("=============================== : desc");
HBaseUtils.printTableInfo(ddlHandler.getTable(tableName));
System.out.println("=============================== : alter");
HBaseAdmin admin = new HBaseAdmin(connPool.getConn());
admin.disableTable(tableName);
HTableInterface htable = ddlHandler.getTable(tableName);
HTableDescriptor tableDesc = admin.getTableDescriptor(htable.getTableName());
tableDesc.removeFamily(Bytes.toBytes("cf2"));
HColumnDescriptor newhcd = new HColumnDescriptor("cf3");
newhcd.setMaxVersions(2);
newhcd.setKeepDeletedCells(KeepDeletedCells.TRUE);
tableDesc.addFamily(newhcd);
admin.modifyTable(tableName, tableDesc);
admin.enableTable(tableName);
admin.close();
System.out.println("=============================== : desc");
HBaseUtils.printTableInfo(ddlHandler.getTable(tableName));
System.out.println("=============================== : delete");
ddlHandler.deleteTable(tableName);
connPool.closeConn();
}
示例10: testHbckFixOrphanTable
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入方法依賴的package包/類
@Test
public void testHbckFixOrphanTable() throws Exception {
String table = "tableInfo";
FileSystem fs = null;
Path tableinfo = null;
try {
setupTable(table);
HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
Path hbaseTableDir = new Path(conf.get(HConstants.HBASE_DIR) + "/" + table );
fs = hbaseTableDir.getFileSystem(conf);
FileStatus status = FSTableDescriptors.getTableInfoPath(fs, hbaseTableDir);
tableinfo = status.getPath();
fs.rename(tableinfo, new Path("/.tableinfo"));
//to report error if .tableinfo is missing.
HBaseFsck hbck = doFsck(conf, false);
assertErrors(hbck, new ERROR_CODE[] { ERROR_CODE.NO_TABLEINFO_FILE });
// fix OrphanTable with default .tableinfo (htd not yet cached on master)
hbck = doFsck(conf, true);
assertNoErrors(hbck);
status = null;
status = FSTableDescriptors.getTableInfoPath(fs, hbaseTableDir);
assertNotNull(status);
HTableDescriptor htd = admin.getTableDescriptor(table.getBytes());
htd.setValue("NOT_DEFAULT", "true");
admin.disableTable(table);
admin.modifyTable(table.getBytes(), htd);
admin.enableTable(table);
fs.delete(status.getPath(), true);
// fix OrphanTable with cache
htd = admin.getTableDescriptor(table.getBytes()); // warms up cached htd on master
hbck = doFsck(conf, true);
assertNoErrors(hbck);
status = null;
status = FSTableDescriptors.getTableInfoPath(fs, hbaseTableDir);
assertNotNull(status);
htd = admin.getTableDescriptor(table.getBytes());
assertEquals(htd.getValue("NOT_DEFAULT"), "true");
} finally {
fs.rename(new Path("/.tableinfo"), tableinfo);
deleteTable(table);
}
}
示例11: testHbckFixOrphanTable
import org.apache.hadoop.hbase.client.HBaseAdmin; //導入方法依賴的package包/類
@Test
public void testHbckFixOrphanTable() throws Exception {
TableName table = TableName.valueOf("tableInfo");
FileSystem fs = null;
Path tableinfo = null;
try {
setupTable(table);
HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
Path hbaseTableDir = FSUtils.getTableDir(
FSUtils.getRootDir(conf), table);
fs = hbaseTableDir.getFileSystem(conf);
FileStatus status = FSTableDescriptors.getTableInfoPath(fs, hbaseTableDir);
tableinfo = status.getPath();
fs.rename(tableinfo, new Path("/.tableinfo"));
//to report error if .tableinfo is missing.
HBaseFsck hbck = doFsck(conf, false);
assertErrors(hbck, new ERROR_CODE[] { ERROR_CODE.NO_TABLEINFO_FILE });
// fix OrphanTable with default .tableinfo (htd not yet cached on master)
hbck = doFsck(conf, true);
assertNoErrors(hbck);
status = null;
status = FSTableDescriptors.getTableInfoPath(fs, hbaseTableDir);
assertNotNull(status);
HTableDescriptor htd = admin.getTableDescriptor(table);
htd.setValue("NOT_DEFAULT", "true");
admin.disableTable(table);
admin.modifyTable(table, htd);
admin.enableTable(table);
fs.delete(status.getPath(), true);
// fix OrphanTable with cache
htd = admin.getTableDescriptor(table); // warms up cached htd on master
hbck = doFsck(conf, true);
assertNoErrors(hbck);
status = null;
status = FSTableDescriptors.getTableInfoPath(fs, hbaseTableDir);
assertNotNull(status);
htd = admin.getTableDescriptor(table);
assertEquals(htd.getValue("NOT_DEFAULT"), "true");
} finally {
fs.rename(new Path("/.tableinfo"), tableinfo);
deleteTable(table);
}
}