public void deleteTable(String tableName) { try (HBaseAdmin admin = (HBaseAdmin) getConnection().getAdmin()) { if (admin.isTableEnabled(tableName)) { disableTable(tableName); } admin.deleteTable(tableName); } catch (IOException e) { logger.error(e.getMessage(), e); throw new RuntimeException(e); } }
public Object call() throws Exception { logger.info("Deleting HBase table " + htableName); if (hbaseAdmin.tableExists(htableName)) { if (hbaseAdmin.isTableEnabled(htableName)) { hbaseAdmin.disableTable(htableName); } hbaseAdmin.deleteTable(htableName); logger.info("Deleted HBase table " + htableName); } else { logger.info("HBase table" + htableName + " does not exist"); } return null; } }
/** * Delete tables matching the passed in pattern and wait on completion. * * Warning: Use this method carefully, there is no prompting and the effect is * immediate. Consider using {@link #listTables(java.util.regex.Pattern) } and * {@link #deleteTable(TableName)} * * @param pattern The pattern to match table names against * @return Table descriptors for tables that couldn't be deleted * @throws IOException */ @Override public HTableDescriptor[] deleteTables(Pattern pattern) throws IOException { List<HTableDescriptor> failed = new LinkedList<>(); for (HTableDescriptor table : listTables(pattern)) { try { deleteTable(table.getTableName()); } catch (IOException ex) { LOG.info("Failed to delete table " + table.getTableName(), ex); failed.add(table); } } return failed.toArray(new HTableDescriptor[failed.size()]); }
@Test public void test() throws IOException { HBaseAdmin hBaseAdmin = mock(HBaseAdmin.class); HTableDescriptor[] hds = new HTableDescriptor[2]; HTableDescriptor d1 = mock(HTableDescriptor.class); HTableDescriptor d2 = mock(HTableDescriptor.class); hds[0] = d1; hds[1] = d2; when(d1.getValue("KYLIN_HOST")).thenReturn("../examples/test_metadata/"); when(d2.getValue("KYLIN_HOST")).thenReturn("../examples/test_metadata/"); when(d1.getTableName()).thenReturn(TableName.valueOf("KYLIN_J9TE08D9IA")); String toBeDel = "to-be-del"; when(d2.getTableName()).thenReturn(TableName.valueOf(toBeDel)); when(hBaseAdmin.listTables("KYLIN_.*")).thenReturn(hds); when(hBaseAdmin.tableExists(toBeDel)).thenReturn(true); when(hBaseAdmin.isTableEnabled(toBeDel)).thenReturn(false); StorageCleanJobHbaseUtil.cleanUnusedHBaseTables(hBaseAdmin, true, 100000); ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class); verify(hBaseAdmin).deleteTable(captor.capture()); assertEquals(Lists.newArrayList(toBeDel), captor.getAllValues()); } }
@Test public void testWithEmptyFirstAndLastRegion() throws Exception { HBaseAdmin admin = (HBaseAdmin) HBaseTestsSuite.getAdmin(); TableName tableName = TableName.valueOf("drill_ut_empty_regions"); try (Table table = HBaseTestsSuite.getConnection().getTable(tableName);) { HTableDescriptor desc = new HTableDescriptor(tableName); desc.addFamily(new HColumnDescriptor("f")); admin.createTable(desc, Arrays.copyOfRange(TestTableGenerator.SPLIT_KEYS, 0, 2)); Put p = new Put("b".getBytes()); p.addColumn("f".getBytes(), "c".getBytes(), "1".getBytes()); table.put(p); setColumnWidths(new int[] {8, 15}); runHBaseSQLVerifyCount("SELECT *\n" + "FROM\n" + " hbase.`" + tableName + "` tableName\n", 1); } finally { try { admin.disableTable(tableName); admin.deleteTable(tableName); } catch (Exception e) { } // ignore } }
public static void prepareTestData() throws Exception { try { util.getHBaseAdmin().disableTable(TABLE); util.getHBaseAdmin().deleteTable(TABLE); } catch (Exception e) { // ignore table not found } Table table = util.createTable(TABLE, FAM); HRegionInfo hRegionInfo = new HRegionInfo(table.getName()); region = util.createLocalHRegion(hRegionInfo, table.getTableDescriptor()); gtInfo = newInfo(); GridTable gridTable = newTable(gtInfo); IGTScanner scanner = gridTable.scan(new GTScanRequestBuilder().setInfo(gtInfo).setRanges(null) .setDimensions(null).setFilterPushDown(null).createGTScanRequest()); for (GTRecord record : scanner) { byte[] value = record.exportColumns(gtInfo.getPrimaryKey()).toBytes(); byte[] key = new byte[RowConstants.ROWKEY_SHARD_AND_CUBOID_LEN + value.length]; System.arraycopy(Bytes.toBytes(baseCuboid), 0, key, RowConstants.ROWKEY_SHARDID_LEN, RowConstants.ROWKEY_CUBOIDID_LEN); System.arraycopy(value, 0, key, RowConstants.ROWKEY_SHARD_AND_CUBOID_LEN, value.length); Put put = new Put(key); put.addColumn(FAM, COL_M, record.exportColumns(gtInfo.getColumnBlock(1)).toBytes()); region.put(put); } }
/** * Delete tables matching the passed in pattern and wait on completion. * * Warning: Use this method carefully, there is no prompting and the effect is * immediate. Consider using {@link #listTables(java.util.regex.Pattern) } and * {@link #deleteTable(TableName)} * * @param pattern The pattern to match table names against * @return Table descriptors for tables that couldn't be deleted * @throws IOException */ @Override public HTableDescriptor[] deleteTables(Pattern pattern) throws IOException { List<HTableDescriptor> failed = new LinkedList<>(); for (HTableDescriptor table : listTables(pattern)) { try { deleteTable(table.getTableName()); } catch (IOException ex) { LOG.info("Failed to delete table " + table.getTableName(), ex); failed.add(table); } } return failed.toArray(new HTableDescriptor[failed.size()]); }
admin.deleteTable(table2);
public void dropTable(String tableName) { try { utility.getHBaseAdmin().disableTable(tableName); utility.getHBaseAdmin().deleteTable(tableName); } catch (IOException e) { logger.error(e.getMessage()); } }
/** * Assert in validate. * * @throws IOException * Signals that an I/O exception has occurred. */ private void assertInValidate() throws IOException { admin.disableTable(TABLE_2); admin.deleteTable(TABLE_2); try { EntityManagerFactory emf = Persistence.createEntityManagerFactory(HBASE_PU, propertyMap); EntityManager em = emf.createEntityManager(); Assert.assertTrue(false); em.close(); emf.close(); } catch (SchemaGenerationException sge) { Assert.assertTrue(true); } }
private static void destroyIndexTable() throws Exception { Properties props = new Properties(TEST_PROPERTIES); ConnectionQueryServices services = DriverManager.getConnection(getUrl(), props).unwrap(PhoenixConnection.class).getQueryServices(); HBaseAdmin admin = services.getAdmin(); try { admin.disableTable(INDEX_TABLE_FULL_NAME); admin.deleteTable(INDEX_TABLE_FULL_NAME); } catch (TableNotFoundException e) { } finally { admin.close(); } }
private static void destroyTable() throws Exception { // Physically delete HBase table so that splits occur as expected for each test Properties props = new Properties(TEST_PROPERTIES); ConnectionQueryServices services = DriverManager.getConnection(getUrl(), props).unwrap(PhoenixConnection.class).getQueryServices(); HBaseAdmin admin = services.getAdmin(); try { try { admin.disableTable(PRODUCT_METRICS_NAME); admin.deleteTable(PRODUCT_METRICS_NAME); } catch (TableNotFoundException e) { } } finally { admin.close(); } }
/** * Test update. * * @throws IOException * Signals that an I/O exception has occurred. */ public void testUpdate() throws IOException { init(); admin.disableTable(TABLE_2); admin.deleteTable(TABLE_2); propertyMap.put(PersistenceProperties.KUNDERA_DDL_AUTO_PREPARE, "update"); assertSchema(); postAssert(); }
@BeforeClass public static void doBeforeTestSetup() throws Exception { HBaseAdmin admin = driver.getConnectionQueryServices(getUrl(), TEST_PROPERTIES).getAdmin(); try { try { admin.disableTable(HBASE_NATIVE_BYTES); admin.deleteTable(HBASE_NATIVE_BYTES); } catch (org.apache.hadoop.hbase.TableNotFoundException e) { } HTableDescriptor descriptor = new HTableDescriptor(HBASE_NATIVE_BYTES); HColumnDescriptor columnDescriptor = new HColumnDescriptor(FAMILY_NAME); columnDescriptor.setKeepDeletedCells(true); descriptor.addFamily(columnDescriptor); admin.createTable(descriptor, SPLITS); initTableValues(); } finally { admin.close(); } }
if ( admin.tableExists(tableName) ) { admin.disableTable(tableName); admin.deleteTable(tableName);
admin.deleteTable(TABLE); admin.deleteTable(TABLE); Assert.assertFalse(admin.isTableAvailable(TABLE));
admin.deleteTable(TABLE);
@Test public void testCreate() throws IOException { propertyMap.put(PersistenceProperties.KUNDERA_DDL_AUTO_PREPARE, "create"); EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceUnit, propertyMap); Assert.assertTrue(admin.isTableAvailable(TABLE)); HTableDescriptor descriptor = admin.getTableDescriptor(TABLE.getBytes()); Assert.assertNotNull(descriptor.getFamilies()); Assert.assertEquals(1, descriptor.getFamilies().size()); for (HColumnDescriptor columnDescriptor : descriptor.getFamilies()) { Assert.assertNotNull(columnDescriptor); Assert.assertNotNull(columnDescriptor.getNameAsString()); Assert.assertEquals(HBASE_ENTITY_SIMPLE, columnDescriptor.getNameAsString()); } admin.disableTable(TABLE); admin.deleteTable(TABLE); Assert.assertFalse(admin.isTableAvailable(TABLE)); }
admin.deleteTable(TABLE); admin.deleteTable(TABLE); Assert.assertFalse(admin.isTableAvailable(TABLE));
@BeforeClass public static void doBeforeTestSetup() throws Exception { HBaseAdmin admin = driver.getConnectionQueryServices(getUrl(), TEST_PROPERTIES).getAdmin(); try { try { admin.disableTable(HBASE_DYNAMIC_COLUMNS_BYTES); admin.deleteTable(HBASE_DYNAMIC_COLUMNS_BYTES); } catch (org.apache.hadoop.hbase.TableNotFoundException e) {} ensureTableCreated(getUrl(), HBASE_DYNAMIC_COLUMNS); initTableValues(); } finally { admin.close(); } }