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); }
private void clean() throws IOException { Connection conn = HBaseConnection.get(KylinConfig.getInstanceFromEnv().getStorageUrl()); Admin hbaseAdmin = conn.getAdmin(); for (HTableDescriptor descriptor : hbaseAdmin.listTables()) { String name = descriptor.getNameAsString().toLowerCase(Locale.ROOT); if (name.startsWith("kylin") || name.startsWith("_kylin")) { String x = descriptor.getValue(IRealizationConstants.HTableTag); System.out.println("table name " + descriptor.getNameAsString() + " host: " + x); System.out.println(descriptor); System.out.println(); descriptor.setValue(IRealizationConstants.HTableOwner, "whoami@kylin.apache.org"); hbaseAdmin.modifyTable(TableName.valueOf(descriptor.getNameAsString()), descriptor); } } hbaseAdmin.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()); }
public static void addCoprocessorOnHTable(HTableDescriptor desc, Path hdfsCoprocessorJar) throws IOException { logger.info("Add coprocessor on " + desc.getNameAsString()); desc.addCoprocessor(CubeEndpointClass, hdfsCoprocessorJar, 1001, null); }
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); } }
@Test public void testBlocksScanned() throws Exception { byte [] tableName = Bytes.toBytes("TestBlocksScanned"); HTableDescriptor table = new HTableDescriptor(TableName.valueOf(tableName)); table.addFamily( new HColumnDescriptor(FAMILY) .setMaxVersions(10) .setBlockCacheEnabled(true) .setBlocksize(BLOCK_SIZE) .setCompressionType(Compression.Algorithm.NONE) ); _testBlocksScanned(table); }
@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 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()); }
@Before public void setUp() throws Exception { HTableDescriptor htd = new HTableDescriptor( TableName.valueOf(TABLE_NAME_BYTES)); htd.addFamily(new HColumnDescriptor(FAMILY_NAME_BYTES)); HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false); this.region = HBaseTestingUtility.createRegionAndWAL(info, TEST_UTIL.getDataTestDir(), TEST_UTIL.getConfiguration(), htd); Put put = new Put(ROW_BYTES); for (int i = 0; i < 10; i += 2) { // puts 0, 2, 4, 6 and 8 put.addColumn(FAMILY_NAME_BYTES, Bytes.toBytes(QUALIFIER_PREFIX + i), (long) i, Bytes.toBytes(VALUE_PREFIX + i)); } this.region.put(put); this.region.flush(true); }
@Test(expected=IllegalArgumentException.class) public void testAddDuplicateFamilies() { HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name.getMethodName())); byte[] familyName = Bytes.toBytes("cf"); HColumnDescriptor hcd = new HColumnDescriptor(familyName); hcd.setBlocksize(1000); htd.addFamily(hcd); assertEquals(1000, htd.getFamily(familyName).getBlocksize()); hcd = new HColumnDescriptor(familyName); hcd.setBlocksize(2000); htd.addFamily(hcd); }
private void init() throws Exception { HTableDescriptor desc = new HTableDescriptor(tableName); HColumnDescriptor hcd = new HColumnDescriptor(family); hcd.setMobEnabled(true); hcd.setMobThreshold(3L); hcd.setMaxVersions(4); desc.addFamily(hcd); admin = TEST_UTIL.getAdmin(); admin.createTable(desc); table = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration()) .getBufferedMutator(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); }
Table newA = TEST_UTIL.getConnection().getTable(tableAname); Admin admin = TEST_UTIL.getAdmin(); HTableDescriptor desc = new HTableDescriptor(a.getTableDescriptor()); admin.disableTable(tableAname); desc.setValue(attrName, attrValue); for (HColumnDescriptor c : desc.getFamilies()) c.setValue(attrName, attrValue); admin.modifyTable(tableAname, desc); admin.enableTable(tableAname); assertEquals("wrong table descriptor returned", desc.getTableName(), tableAname); value = desc.getValue(attrName); assertFalse("missing HTD attribute value", value == null); assertFalse("HTD attribute value is incorrect", Bytes.compareTo(value, attrValue) != 0); for (HColumnDescriptor c : desc.getFamilies()) { value = c.getValue(attrName); assertFalse("missing HCD attribute value", value == null); assertFalse("HCD attribute value is incorrect",
@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); } }
@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); }
@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); }
util.startMiniCluster(option); for (String tableStrSingle : tableStr) { byte[][] splitKeys = generateRandomSplitKeys(regionNum - 1); TableName tableName = TableName.valueOf(tableStrSingle); Table chosenTable = allTables.values().iterator().next(); LOG.info("Changing regions in table " + chosenTable.getName().getNameAsString()); admin.disableTable(chosenTable.getName()); !admin.isTableAvailable(table.getName())) { Thread.sleep(200); LOG.info("Waiting for new region assignment to happen"); String tableNameStr = singleTableInfo.getHTableDescriptor().getNameAsString(); LOG.info("Running LoadIncrementalHFiles on table" + tableNameStr); if (writeMultipleTables) { for (Cell kv : res.rawCells()) { assertTrue(CellUtil.matchingRows(first, kv)); assertTrue(Bytes.equals(CellUtil.cloneValue(first), CellUtil.cloneValue(kv))); admin.disableTable(currentTableName);
private void createTestTable(TableName tname, byte[] cf) throws Exception { HTableDescriptor htd = new HTableDescriptor(tname); HColumnDescriptor hcd = new HColumnDescriptor(cf); hcd.setMaxVersions(100); htd.addFamily(hcd); htd.setOwner(USER_OWNER); createTable(TEST_UTIL, htd, new byte[][] { Bytes.toBytes("s") }); }
@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(); }
@Before public void setUp() throws Exception { TableName tableName = TableName.valueOf(getClass().getSimpleName()); HTableDescriptor htd = new HTableDescriptor(tableName); htd.addFamily(new HColumnDescriptor(cfName).setDataBlockEncoding(DataBlockEncoding.FAST_DIFF)); HRegionInfo info = new HRegionInfo(tableName, null, null, false); Path path = testUtil.getDataTestDir(getClass().getSimpleName()); region = HBaseTestingUtility.createRegionAndWAL(info, path, testUtil.getConfiguration(), htd); }