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 createTable(Admin admin, TableName tn) throws Exception { // Create a table HTableDescriptor tableDesc = new HTableDescriptor(tn); tableDesc.addFamily(new HColumnDescriptor("F1")); admin.createTable(tableDesc); }
private void createTableWithDefaultConf(TableName TABLENAME) throws IOException { HTableDescriptor htd = new HTableDescriptor(TABLENAME); HColumnDescriptor hcd = new HColumnDescriptor("value"); htd.addFamily(hcd); admin.createTable(htd, null); }
private void createWriteTable(int numberOfServers) throws IOException { int numberOfRegions = (int)(numberOfServers * regionsLowerLimit); LOG.info("Number of live regionservers {}, pre-splitting the canary table into {} regions " + "(current lower limit of regions per server is {} and you can change it with config {}).", numberOfServers, numberOfRegions, regionsLowerLimit, HConstants.HBASE_CANARY_WRITE_PERSERVER_REGIONS_LOWERLIMIT_KEY); HTableDescriptor desc = new HTableDescriptor(writeTableName); HColumnDescriptor family = new HColumnDescriptor(CANARY_TABLE_FAMILY_NAME); family.setMaxVersions(1); family.setTimeToLive(writeDataTTL); desc.addFamily(family); byte[][] splits = new RegionSplitter.HexStringSplit().split(numberOfRegions); admin.createTable(desc, splits); } }
private static void createHTableIfNeeded(Connection conn, String tableName) throws IOException { Admin hbase = conn.getAdmin(); try { boolean tableExist = false; try { hbase.getTableDescriptor(TableName.valueOf(tableName)); tableExist = true; } catch (TableNotFoundException e) { //do nothing? } if (tableExist) { logger.info("HTable '{}' already exists", tableName); return; } logger.info("Creating HTable '{}'", tableName); HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(tableName)); HColumnDescriptor fd = new HColumnDescriptor(CF); fd.setBlocksize(CELL_SIZE); desc.addFamily(fd); hbase.createTable(desc); logger.info("HTable '{}' created", tableName); } finally { hbase.close(); } }
@Override public Void call() throws Exception { HTableDescriptor htd = new HTableDescriptor(TableName.valueOf("non_existing_namespace", name.getMethodName())); htd.addFamily(new HColumnDescriptor("family1")); admin.createTable(htd); return null; } }, NamespaceNotFoundException.class);
private static void createTable(Admin admin, TableName tableName) throws IOException { HTableDescriptor desc = new HTableDescriptor(tableName); HColumnDescriptor hcd = new HColumnDescriptor("col"); hcd.setMaxVersions(3); desc.addFamily(hcd); admin.createTable(desc); }
@Test public void testCreateTableWithOnlyEmptyStartRow() throws IOException { final byte[] tableName = Bytes.toBytes(name.getMethodName()); byte[][] splitKeys = new byte[1][]; splitKeys[0] = HConstants.EMPTY_BYTE_ARRAY; HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(tableName)); desc.addFamily(new HColumnDescriptor("col")); try { admin.createTable(desc, splitKeys); fail("Test case should fail as empty split key is passed."); } catch (IllegalArgumentException e) { } }
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 testCreateTableWithEmptyRowInTheSplitKeys() throws IOException{ final byte[] tableName = Bytes.toBytes(name.getMethodName()); byte[][] splitKeys = new byte[3][]; splitKeys[0] = "region1".getBytes(); splitKeys[1] = HConstants.EMPTY_BYTE_ARRAY; splitKeys[2] = "region2".getBytes(); HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(tableName)); desc.addFamily(new HColumnDescriptor("col")); try { admin.createTable(desc, splitKeys); fail("Test case should fail as empty split key is passed."); } catch (IllegalArgumentException e) { LOG.info("Expected ", e); } }
private void createTable(String coprocessor) throws IOException { HTableDescriptor htd = new HTableDescriptor(tableName) .addFamily(new HColumnDescriptor(dummy)) .addFamily(new HColumnDescriptor(test)) .addCoprocessor(coprocessor); util.getAdmin().createTable(htd); }
@Test public void testCreateTableWithRegions() throws Exception { HTableDescriptor desc = new HTableDescriptor(TABLE_NAME); desc.addFamily(new HColumnDescriptor("cf")); SplitAlgorithm algo = new RegionSplitter.HexStringSplit(); byte[][] splits = algo.split(REGION_COUNT); LOG.info(String.format("Creating table %s with %d splits.", TABLE_NAME, REGION_COUNT)); long startTime = System.currentTimeMillis(); try { admin.createTable(desc, splits); LOG.info(String.format("Pre-split table created successfully in %dms.", (System.currentTimeMillis() - startTime))); } catch (IOException e) { LOG.error("Failed to create table", e); } } }
@Test public void testTableAvailableWithRandomSplitKeys() throws Exception { final TableName tableName = TableName.valueOf(name.getMethodName()); HTableDescriptor desc = new HTableDescriptor(tableName); desc.addFamily(new HColumnDescriptor("col")); byte[][] splitKeys = new byte[1][]; splitKeys = new byte [][] { new byte [] { 1, 1, 1 }, new byte [] { 2, 2, 2 } }; admin.createTable(desc); boolean tableAvailable = admin.isTableAvailable(tableName, splitKeys); assertFalse("Table should be created with 1 row in META", tableAvailable); }
/** * 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(); }
/** * 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); }
@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); }
@Override public void run() { // create a table : master coprocessor will throw an exception and not // catch it. HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(TEST_TABLE)); htd.addFamily(new HColumnDescriptor(TEST_FAMILY)); try { Admin admin = UTIL.getAdmin(); admin.createTable(htd); fail("BuggyMasterObserver failed to throw an exception."); } catch (IOException e) { assertEquals("HBaseAdmin threw an interrupted IOException as expected.", "java.io.InterruptedIOException", e.getClass().getName()); } } }
/** * For HBASE-2556 * @throws IOException */ @Test public void testGetTableRegions() throws IOException { final TableName tableName = TableName.valueOf(name.getMethodName()); int expectedRegions = 10; // Use 80 bit numbers to make sure we aren't limited byte [] startKey = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; byte [] endKey = { 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 }; HTableDescriptor desc = new HTableDescriptor(tableName); desc.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY)); admin.createTable(desc, startKey, endKey, expectedRegions); List<RegionInfo> RegionInfos = admin.getRegions(tableName); assertEquals("Tried to create " + expectedRegions + " regions " + "but only found " + RegionInfos.size(), expectedRegions, RegionInfos.size()); }
private static void create(Admin admin, TableName tableName, byte[]... families) throws IOException { HTableDescriptor desc = new HTableDescriptor(tableName); for (byte[] family : families) { HColumnDescriptor colDesc = new HColumnDescriptor(family); colDesc.setMaxVersions(1); colDesc.setCompressionType(Algorithm.GZ); desc.addFamily(colDesc); } try { admin.createTable(desc); } catch (TableExistsException tee) { /* Ignore */ } }
protected static void createTable(TableName tableName, String columnFamilyName) { assertNotNull("HBaseAdmin is not initialized successfully.", admin); HTableDescriptor desc = new HTableDescriptor(tableName); HColumnDescriptor colDef = new HColumnDescriptor(Bytes.toBytes(columnFamilyName)); desc.addFamily(colDef); try { admin.createTable(desc); createdTables.add(tableName); assertTrue("Fail to create the table", admin.tableExists(tableName)); } catch (IOException e) { assertNull("Exception found while creating table", e); } }