本文整理了Java中org.apache.hadoop.hbase.client.Table.close()
方法的一些代码示例,展示了Table.close()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Table.close()
方法的具体详情如下:
包路径:org.apache.hadoop.hbase.client.Table
类名称:Table
方法名:close
[英]Releases any resources held or pending changes in internal buffers.
[中]释放内部缓冲区中保留或挂起的任何资源。
代码示例来源:origin: apache/hbase
/**
* Remove specified namespace from the acl table.
*/
static void removeNamespacePermissions(Configuration conf, String namespace, Table t)
throws IOException{
Delete d = new Delete(Bytes.toBytes(toNamespaceEntry(namespace)));
if (LOG.isDebugEnabled()) {
LOG.debug("Removing permissions of removed namespace "+ namespace);
}
try {
t.delete(d);
} finally {
t.close();
}
}
代码示例来源:origin: apache/hbase
/**
* Test read only tables
* @throws Exception
*/
@Test
public void testReadOnlyTable() throws Exception {
final TableName name = TableName.valueOf(this.name.getMethodName());
Table table = TEST_UTIL.createTable(name, HConstants.CATALOG_FAMILY);
byte[] value = Bytes.toBytes("somedata");
// This used to use an empty row... That must have been a bug
Put put = new Put(value);
put.addColumn(HConstants.CATALOG_FAMILY, HConstants.CATALOG_FAMILY, value);
table.put(put);
table.close();
}
代码示例来源:origin: apache/hbase
/**
* Return the number of rows in the given table.
*/
public int countRows(final TableName tableName) throws IOException {
Table table = getConnection().getTable(tableName);
try {
return countRows(table);
} finally {
table.close();
}
}
代码示例来源:origin: apache/hbase
/**
* For HADOOP-2579
* @throws IOException
*/
@Test (expected=TableExistsException.class)
public void testTableExistsExceptionWithATable() throws IOException {
final TableName name = TableName.valueOf(this.name.getMethodName());
TEST_UTIL.createTable(name, HConstants.CATALOG_FAMILY).close();
TEST_UTIL.createTable(name, HConstants.CATALOG_FAMILY);
}
代码示例来源:origin: apache/hbase
@Test
public void testGetTableDescriptor() throws IOException {
Table table = null;
try {
table = TEST_UTIL.getConnection().getTable(TABLE);
HTableDescriptor local = table.getTableDescriptor();
assertEquals(remoteTable.getTableDescriptor(), local);
} finally {
if (null != table) table.close();
}
}
代码示例来源:origin: apache/hbase
@Test
public void testQualifierAccess() throws Exception {
final Table table = createTable(TEST_UTIL, TABLE, new byte[][] { FAMILY });
try {
doQualifierAccess(table);
} finally {
table.close();
}
}
代码示例来源:origin: apache/hbase
/**
* @throws java.lang.Exception
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
TEST_UTIL.startMiniCluster();
Table table = TEST_UTIL.createTable(TableName.valueOf(TABLE_NAME), Bytes.toBytes(COL_FAM));
writeRows(table, TOTAL_ROWS, ROWS_WITH_ONE_COL);
table.close();
}
代码示例来源:origin: apache/hbase
private void createTableWithNonDefaultProperties() throws Exception {
final long startTime = System.currentTimeMillis();
final String sourceTableNameAsString = STRING_TABLE_NAME + startTime;
originalTableName = TableName.valueOf(sourceTableNameAsString);
// enable replication on a column family
HColumnDescriptor maxVersionsColumn = new HColumnDescriptor(MAX_VERSIONS_FAM);
HColumnDescriptor bloomFilterColumn = new HColumnDescriptor(BLOOMFILTER_FAM);
HColumnDescriptor dataBlockColumn = new HColumnDescriptor(COMPRESSED_FAM);
HColumnDescriptor blockSizeColumn = new HColumnDescriptor(BLOCKSIZE_FAM);
maxVersionsColumn.setMaxVersions(MAX_VERSIONS);
bloomFilterColumn.setBloomFilterType(BLOOM_TYPE);
dataBlockColumn.setDataBlockEncoding(DATA_BLOCK_ENCODING_TYPE);
blockSizeColumn.setBlocksize(BLOCK_SIZE);
HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(sourceTableNameAsString));
htd.addFamily(maxVersionsColumn);
htd.addFamily(bloomFilterColumn);
htd.addFamily(dataBlockColumn);
htd.addFamily(blockSizeColumn);
htd.setValue(TEST_CUSTOM_VALUE, TEST_CUSTOM_VALUE);
htd.setConfiguration(TEST_CONF_CUSTOM_VALUE, TEST_CONF_CUSTOM_VALUE);
assertTrue(htd.getConfiguration().size() > 0);
admin.createTable(htd);
Table original = UTIL.getConnection().getTable(originalTableName);
originalTableName = TableName.valueOf(sourceTableNameAsString);
originalTableDescriptor = admin.getTableDescriptor(originalTableName);
originalTableDescription = originalTableDescriptor.toStringCustomizedValues();
original.close();
}
代码示例来源:origin: apache/hbase
@Test
public void testNegativeMemstoreSize() throws IOException, InterruptedException {
boolean IOEthrown = false;
Table table = null;
try {
table = TEST_UTIL.getConnection().getTable(TableName.valueOf(tableName));
// Adding data
Put put1 = new Put(Bytes.toBytes("row1"));
put1.addColumn(family, qualifier, Bytes.toBytes("Value1"));
table.put(put1);
Put put2 = new Put(Bytes.toBytes("row2"));
put2.addColumn(family, qualifier, Bytes.toBytes("Value2"));
table.put(put2);
table.put(put2);
} catch (IOException e) {
IOEthrown = true;
} finally {
Assert.assertFalse("Shouldn't have thrown an exception", IOEthrown);
if (table != null) {
table.close();
}
}
}
代码示例来源:origin: apache/hbase
/**
* Not really restarting the master. Simulate it by clear of new region
* state since it is not persisted, will be lost after master restarts.
*/
@Test
public void testMergeAndRestartingMaster() throws Exception {
final TableName tableName = TableName.valueOf(name.getMethodName());
// Create table and load data.
Table table = createTableAndLoadData(MASTER, tableName);
try {
MyMasterRpcServices.enabled.set(true);
// Merge 1st and 2nd region
mergeRegionsAndVerifyRegionNum(MASTER, tableName, 0, 1, INITIAL_REGION_NUM - 1);
} finally {
MyMasterRpcServices.enabled.set(false);
}
table.close();
}
代码示例来源:origin: apache/hbase
@Test
public void testCoprocessorError() throws Exception {
Configuration configuration = new Configuration(util.getConfiguration());
// Make it not retry forever
configuration.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1);
Table table = util.getConnection().getTable(TEST_TABLE);
try {
CoprocessorRpcChannel protocol = table.coprocessorService(ROWS[0]);
TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface service =
TestRpcServiceProtos.TestProtobufRpcProto.newBlockingStub(protocol);
service.error(null, TestProtos.EmptyRequestProto.getDefaultInstance());
fail("Should have thrown an exception");
} catch (ServiceException e) {
} finally {
table.close();
}
}
代码示例来源:origin: apache/hbase
@Test
public void testFaultyScanner() throws Exception {
TableName tableName = TEST_TABLE.getTableName();
Table table = UTIL.createTable(tableName, FAMILY_NAME);
try {
final int NUM_ROWS = 100;
loadTable(table, NUM_ROWS);
checkTableRows(table, NUM_ROWS);
} finally {
table.close();
}
}
代码示例来源:origin: apache/hbase
/**
* Returns all rows from the hbase:meta table.
*
* @throws IOException When reading the rows fails.
*/
public List<byte[]> getMetaTableRows() throws IOException {
// TODO: Redo using MetaTableAccessor class
Table t = getConnection().getTable(TableName.META_TABLE_NAME);
List<byte[]> rows = new ArrayList<>();
ResultScanner s = t.getScanner(new Scan());
for (Result result : s) {
LOG.info("getMetaTableRows: row -> " +
Bytes.toStringBinary(result.getRow()));
rows.add(result.getRow());
}
s.close();
t.close();
return rows;
}
代码示例来源:origin: apache/hbase
public void testRegionReplicaReplication(int regionReplication) throws Exception {
// test region replica replication. Create a table with single region, write some data
// ensure that data is replicated to the secondary region
TableName tableName = TableName.valueOf("testRegionReplicaReplicationWithReplicas_"
+ regionReplication);
HTableDescriptor htd = HTU.createTableDescriptor(tableName.toString());
htd.setRegionReplication(regionReplication);
HTU.getAdmin().createTable(htd);
TableName tableNameNoReplicas =
TableName.valueOf("testRegionReplicaReplicationWithReplicas_NO_REPLICAS");
HTU.deleteTableIfAny(tableNameNoReplicas);
HTU.createTable(tableNameNoReplicas, HBaseTestingUtility.fam1);
Connection connection = ConnectionFactory.createConnection(HTU.getConfiguration());
Table table = connection.getTable(tableName);
Table tableNoReplicas = connection.getTable(tableNameNoReplicas);
try {
// load some data to the non-replicated table
HTU.loadNumericRows(tableNoReplicas, HBaseTestingUtility.fam1, 6000, 7000);
// load the data to the table
HTU.loadNumericRows(table, HBaseTestingUtility.fam1, 0, 1000);
verifyReplication(tableName, regionReplication, 0, 1000);
} finally {
table.close();
tableNoReplicas.close();
HTU.deleteTableIfAny(tableNameNoReplicas);
connection.close();
}
}
代码示例来源:origin: apache/hbase
/**
* do a single put that is bypassed by a RegionObserver
* @throws Exception
*/
@Test
public void testSimple() throws Exception {
Table t = util.getConnection().getTable(tableName);
Put p = new Put(row1);
p.addColumn(test, dummy, dummy);
// before HBASE-4331, this would throw an exception
t.put(p);
checkRowAndDelete(t,row1,0);
t.close();
}
代码示例来源:origin: apache/hbase
/**
* Can't enable a table if the table isn't in disabled state
* @throws IOException
*/
@Test (expected=TableNotDisabledException.class)
public void testTableNotDisabledExceptionWithATable() throws IOException {
final TableName name = TableName.valueOf(this.name.getMethodName());
Table t = TEST_UTIL.createTable(name, HConstants.CATALOG_FAMILY);
try {
this.admin.enableTable(name);
}finally {
t.close();
}
}
代码示例来源:origin: apache/hbase
/**
* Ensure when we go to top level index pages that we get redirected to an info-server specific status
* page.
*/
@Test
public void testInfoServersRedirect() throws Exception {
// give the cluster time to start up
UTIL.getConnection().getTable(TableName.META_TABLE_NAME).close();
int port = UTIL.getHBaseCluster().getMaster().getInfoServer().getPort();
assertContainsContent(new URL("http://localhost:" + port + "/index.html"), "master-status");
port = UTIL.getHBaseCluster().getRegionServerThreads().get(0).getRegionServer()
.getInfoServer().getPort();
assertContainsContent(new URL("http://localhost:" + port + "/index.html"), "rs-status");
}
代码示例来源:origin: apache/hbase
public static void verifyRowCount(final HBaseTestingUtility util, final TableName tableName,
long expectedRows) throws IOException {
Table table = util.getConnection().getTable(tableName);
try {
assertEquals(expectedRows, util.countRows(table));
} finally {
table.close();
}
}
代码示例来源:origin: apache/hbase
/**
* 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();
}
代码示例来源:origin: apache/hbase
@Test(expected = DoNotRetryIOException.class)
public void testScanOnCorruptHFile() throws IOException {
TableName tableName = TableName.valueOf(name.getMethodName());
HTableDescriptor htd = new HTableDescriptor(tableName);
htd.addCoprocessor(CorruptHFileCoprocessor.class.getName());
htd.addFamily(new HColumnDescriptor(FAMILY_NAME));
Table table = TEST_UTIL.createTable(htd, null);
try {
loadTable(table, 1);
scan(table);
} finally {
table.close();
}
}
内容来源于网络,如有侵权,请联系作者删除!