private static void createTable(Admin admin, TableName tableName, String[] columns) throws IOException { HTableDescriptor htd = new HTableDescriptor(tableName); Set<String> cfSet = getColumnFamilies(columns); for (String cf : cfSet) { HColumnDescriptor hcd = new HColumnDescriptor(Bytes.toBytes(cf)); htd.addFamily(hcd); } LOG.warn(format("Creating table '%s' with '%s' columns and default descriptors.", tableName, cfSet)); admin.createTable(htd); }
@Before public void beforeMethod() throws Exception { Admin admin = TEST_UTIL.getAdmin(); if (admin.tableExists(TABLE_NAME)) { TEST_UTIL.deleteTable(TABLE_NAME); } HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(TABLE)); htd.addFamily(new HColumnDescriptor(CFA)); htd.addFamily(new HColumnDescriptor(CFB)); admin.createTable(htd); }
@After public void tearDown() throws IOException { Admin admin = UTIL.getAdmin(); if (admin.tableExists(NAME)) { admin.disableTable(NAME); admin.deleteTable(NAME); } }
private void updateHtable(String tableName) throws IOException { HTableDescriptor desc = hbaseAdmin.getTableDescriptor(TableName.valueOf(tableName)); if (oldHostValue.equals(desc.getValue(IRealizationConstants.HTableTag))) { desc.setValue(IRealizationConstants.HTableTag, kylinConfig.getMetadataUrlPrefix()); hbaseAdmin.disableTable(TableName.valueOf(tableName)); hbaseAdmin.modifyTable(TableName.valueOf(tableName), desc); hbaseAdmin.enableTable(TableName.valueOf(tableName)); updatedResources.add(tableName); } }
/** * Set the number of Region replicas. */ public static void setReplicas(Admin admin, TableName table, int replicaCount) throws IOException, InterruptedException { admin.disableTable(table); HTableDescriptor desc = new HTableDescriptor(admin.getTableDescriptor(table)); desc.setRegionReplication(replicaCount); admin.modifyTable(desc.getTableName(), desc); admin.enableTable(table); }
@Override public boolean evaluate() throws IOException { return getAdmin().tableExists(tableName) && getAdmin().isTableEnabled(tableName); } };
@Test public void testRegionCache() throws IOException { HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name.getMethodName())); HColumnDescriptor fam = new HColumnDescriptor(FAMILY); htd.addFamily(fam); byte[][] KEYS = HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE; Admin admin = TEST_UTIL.getAdmin(); admin.createTable(htd, KEYS); HRegionLocator locator = (HRegionLocator) admin.getConnection().getRegionLocator(htd.getTableName()); List<HRegionLocation> results = locator.getAllRegionLocations(); int number = ((ConnectionImplementation)admin.getConnection()) .getNumberOfCachedRegionLocations(htd.getTableName()); assertEquals(results.size(), number); ConnectionImplementation conn = ((ConnectionImplementation)admin.getConnection()); assertNotNull("Can't get cached location for row aaa", conn.getCachedLocation(htd.getTableName(),Bytes.toBytes("aaa"))); for(byte[] startKey:HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE){ assertNotNull("Can't get cached location for row "+ Bytes.toString(startKey),(conn.getCachedLocation(htd.getTableName(),startKey))); } }
/** * Test for hadoop-1581 'HBASE: Unopenable tablename bug'. * @throws Exception */ @Test public void testTableNameClash() throws Exception { final String name = this.name.getMethodName(); HTableDescriptor htd1 = new HTableDescriptor(TableName.valueOf(name + "SOMEUPPERCASE")); HTableDescriptor htd2 = new HTableDescriptor(TableName.valueOf(name)); htd1.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY)); htd2.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY)); admin.createTable(htd1); admin.createTable(htd2); // Before fix, below would fail throwing a NoServerForRegionException. TEST_UTIL.getConnection().getTable(htd2.getTableName()).close(); }
@Test public void createTableInDefaultNamespace() throws Exception { HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(name.getMethodName())); HColumnDescriptor colDesc = new HColumnDescriptor("cf1"); desc.addFamily(colDesc); admin.createTable(desc); assertTrue(admin.listTables().length == 1); admin.disableTable(desc.getTableName()); admin.deleteTable(desc.getTableName()); }
@Test public void testRoundRobinAssignment() throws Exception { TableName tableName = TableName.valueOf("testRoundRobinAssignment"); HTableDescriptor desc = new HTableDescriptor(tableName); desc.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY)); admin.createTable(desc, Bytes.toBytes("aaa"), Bytes.toBytes("zzz"), REGION_NUM); TEST_UTIL.waitTableAvailable(tableName); TEST_UTIL.loadTable(admin.getConnection().getTable(tableName), HConstants.CATALOG_FAMILY); admin.flush(tableName); LoadBalancer balancer = master.getLoadBalancer(); List<RegionInfo> regions = admin.getRegions(tableName); regions.addAll(admin.getTableRegions(TableName.META_TABLE_NAME)); List<ServerName> servers = Lists.newArrayList( admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)).getLiveServerMetrics().keySet()); Map<ServerName, List<RegionInfo>> map = balancer.roundRobinAssignment(regions, servers); for (List<RegionInfo> regionInfos : map.values()) { regions.removeAll(regionInfos); } assertEquals("No region should be missed by balancer", 0, regions.size()); }
@Test public void testRegionObserverSingleRegion() throws IOException { final TableName tableName = TableName.valueOf(name.getMethodName()); try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration()); Admin admin = connection.getAdmin()) { admin.createTable( new HTableDescriptor(tableName) .addFamily(new HColumnDescriptor(foo)) // add the coprocessor for the region .addCoprocessor(CustomRegionObserver.class.getName())); try (Table table = connection.getTable(tableName)) { table.get(new Get(foo)); table.get(new Get(foo)); // 2 gets } } assertPreGetRequestsCounter(CustomRegionObserver.class); }
public void setUp(long threshold, String TN, DataBlockEncoding encoding) throws Exception { desc = new HTableDescriptor(TableName.valueOf(TN)); hcd = new HColumnDescriptor(family); hcd.setMobEnabled(true); hcd.setMobThreshold(threshold); hcd.setMaxVersions(4); hcd.setDataBlockEncoding(encoding); desc.addFamily(hcd); admin = TEST_UTIL.getAdmin(); admin.createTable(desc); table = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration()) .getTable(TableName.valueOf(TN)); }
@Test public void testMoveThrowsUnknownRegionException() throws IOException { final TableName tableName = TableName.valueOf(name.getMethodName()); HTableDescriptor htd = new HTableDescriptor(tableName); HColumnDescriptor hcd = new HColumnDescriptor("value"); htd.addFamily(hcd); admin.createTable(htd, null); try { RegionInfo hri = RegionInfoBuilder.newBuilder(tableName) .setStartKey(Bytes.toBytes("A")) .setEndKey(Bytes.toBytes("Z")) .build(); admin.move(hri.getEncodedNameAsBytes(), null); fail("Region should not be moved since it is fake"); } catch (IOException ioe) { assertTrue(ioe instanceof UnknownRegionException); } finally { TEST_UTIL.deleteTable(tableName); } }
@Test public void testDisableCatalogTable() throws Exception { try { this.admin.disableTable(TableName.META_TABLE_NAME); fail("Expected to throw ConstraintException"); } catch (ConstraintException e) { } // Before the fix for HBASE-6146, the below table creation was failing as the hbase:meta table // actually getting disabled by the disableTable() call. HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(Bytes.toBytes(name.getMethodName()))); HColumnDescriptor hcd = new HColumnDescriptor(Bytes.toBytes("cf1")); htd.addFamily(hcd); TEST_UTIL.getHBaseAdmin().createTable(htd); }
@BeforeClass public static void beforeClass() throws Exception { UTIL.getConfiguration().set("hbase.client.retries.number", "3"); UTIL.startMiniCluster(); Admin admin = UTIL.getAdmin(); HTableDescriptor tableDescriptor = new HTableDescriptor(TableName.valueOf(tableAname)); for (HColumnDescriptor family : families) { tableDescriptor.addFamily(family); } admin.createTable(tableDescriptor); admin.close(); }
private void setUpForPolicyTest(String tableNameAsString, MobCompactPartitionPolicy type) throws IOException { tableName = TableName.valueOf(tableNameAsString); hcd1 = new HColumnDescriptor(family1); hcd1.setMobEnabled(true); hcd1.setMobThreshold(10); hcd1.setMobCompactPartitionPolicy(type); desc = new HTableDescriptor(tableName); desc.addFamily(hcd1); admin.createTable(desc); table = conn.getTable(tableName); bufMut = conn.getBufferedMutator(tableName); }
@Before public void setUp() throws Exception { // Create the test table (owner added to the _acl_ table) Admin admin = TEST_UTIL.getAdmin(); HTableDescriptor htd = new HTableDescriptor(TEST_TABLE.getTableName()); HColumnDescriptor hcd = new HColumnDescriptor(TEST_FAMILY); hcd.setMaxVersions(4); htd.setOwner(USER_OWNER); htd.addFamily(hcd); admin.createTable(htd, new byte[][] { Bytes.toBytes("s") }); TEST_UTIL.waitTableEnabled(TEST_TABLE.getTableName()); LOG.info("Sleeping a second because of HBASE-12581"); Threads.sleep(1000); }
/** * Setup a clean table before we start mucking with it. * * @throws IOException * @throws InterruptedException * @throws KeeperException */ private Table setupTable(TableName tablename) throws Exception { HTableDescriptor desc = new HTableDescriptor(tablename); HColumnDescriptor hcd = new HColumnDescriptor(Bytes.toString(FAM)); desc.addFamily(hcd); // If a table has no CF's it doesn't get checked TEST_UTIL.getAdmin().createTable(desc, splits); return this.connection.getTable(tablename); }
private void prepareTest(String testId) throws IOException { tableName = TableName.valueOf("test_table_" + testId); HTableDescriptor htd = new HTableDescriptor(tableName); hcd = new HColumnDescriptor(CF); htd.addFamily(hcd); try (Admin admin = TEST_UTIL.getConnection().getAdmin()) { admin.createTable(htd); } numBatchesWritten = 0; }
@Test public void testPriorityRegionIsOpenedWithSeparateThreadPool() throws Exception { final TableName tableName = TableName.valueOf(TestRegionOpen.class.getSimpleName()); ThreadPoolExecutor exec = getRS().getExecutorService() .getExecutorThreadPool(ExecutorType.RS_OPEN_PRIORITY_REGION); long completed = exec.getCompletedTaskCount(); HTableDescriptor htd = new HTableDescriptor(tableName); htd.setPriority(HConstants.HIGH_QOS); htd.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY)); try (Connection connection = ConnectionFactory.createConnection(HTU.getConfiguration()); Admin admin = connection.getAdmin()) { admin.createTable(htd); } assertEquals(completed + 1, exec.getCompletedTaskCount()); }