本文整理了Java中org.apache.hadoop.hbase.client.Connection.getTableBuilder()
方法的一些代码示例,展示了Connection.getTableBuilder()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Connection.getTableBuilder()
方法的具体详情如下:
包路径:org.apache.hadoop.hbase.client.Connection
类名称:Connection
方法名:getTableBuilder
[英]Returns an TableBuilder for creating Table.
[中]返回用于创建表的TableBuilder。
代码示例来源:origin: apache/hbase
@Override
public TableBuilder getTableBuilder(TableName tableName, ExecutorService pool) {
return this.conn.getTableBuilder(tableName, pool);
}
代码示例来源:origin: apache/hbase
/**
* Retrieve a Table implementation for accessing a table.
* The returned Table is not thread safe, a new instance should be created for each using thread.
* This is a lightweight operation, pooling or caching of the returned Table
* is neither required nor desired.
* <p>
* The caller is responsible for calling {@link Table#close()} on the returned
* table instance.
* <p>
* Since 0.98.1 this method no longer checks table existence. An exception
* will be thrown if the table does not exist only when the first operation is
* attempted.
*
* @param tableName the name of the table
* @param pool The thread pool to use for batch operations, null to use a default pool.
* @return a Table to use for interactions with this table
*/
default Table getTable(TableName tableName, ExecutorService pool) throws IOException {
return getTableBuilder(tableName, pool).build();
}
代码示例来源:origin: apache/hbase
try (Table table = conn.getTableBuilder(tableName, null).setOperationTimeout(8000).build()) {
try (Table table = conn.getTableBuilder(tableName, null).setOperationTimeout(6000).build()) {
代码示例来源:origin: apache/hbase
@Test
public void testRpcTimeout() throws IOException {
Configuration c = new Configuration(TEST_UTIL.getConfiguration());
try (Table table = TEST_UTIL.getConnection().getTableBuilder(tableName, null)
.setRpcTimeout(SleepCoprocessor.SLEEP_TIME / 2)
.setReadRpcTimeout(SleepCoprocessor.SLEEP_TIME / 2)
.setWriteRpcTimeout(SleepCoprocessor.SLEEP_TIME / 2)
.setOperationTimeout(SleepCoprocessor.SLEEP_TIME * 100).build()) {
execute(table);
fail("Get should not have succeeded");
} catch (RetriesExhaustedException e) {
LOG.info("We received an exception, as expected ", e);
}
// Again, with configuration based override
c.setInt(HConstants.HBASE_RPC_TIMEOUT_KEY, SleepCoprocessor.SLEEP_TIME / 2);
c.setInt(HConstants.HBASE_RPC_READ_TIMEOUT_KEY, SleepCoprocessor.SLEEP_TIME / 2);
c.setInt(HConstants.HBASE_RPC_WRITE_TIMEOUT_KEY, SleepCoprocessor.SLEEP_TIME / 2);
c.setInt(HConstants.HBASE_CLIENT_OPERATION_TIMEOUT, SleepCoprocessor.SLEEP_TIME * 100);
try (Connection conn = ConnectionFactory.createConnection(c)) {
try (Table table = conn.getTable(tableName)) {
execute(table);
fail("Get should not have succeeded");
} catch (RetriesExhaustedException e) {
LOG.info("We received an exception, as expected ", e);
}
}
}
}
代码示例来源:origin: apache/hbase
try (Table table = UTIL.getConnection().getTableBuilder(NAME, null).setWriteRpcTimeout(1000)
.setOperationTimeout(2000).build()) {
table.put(
代码示例来源:origin: apache/hbase
try (Table table = UTIL.getConnection().getTableBuilder(NAME, null).setWriteRpcTimeout(1000)
.setOperationTimeout(2000).build()) {
table.put(
代码示例来源:origin: apache/hbase
public void testOperationTimeout() throws IOException {
TableBuilder builder =
TEST_UTIL.getConnection().getTableBuilder(tableName, null).setRpcTimeout(Integer.MAX_VALUE)
.setReadRpcTimeout(Integer.MAX_VALUE).setWriteRpcTimeout(Integer.MAX_VALUE);
代码示例来源:origin: apache/hbase
@Test
public void test() throws InterruptedException, IOException {
HMaster master = UTIL.getMiniHBaseCluster().stopMaster(0).getMaster();
// Shutdown master before shutting down rs
UTIL.waitFor(30000, () -> !master.isAlive());
RegionServerThread thread = null;
for (RegionServerThread t : UTIL.getMiniHBaseCluster().getRegionServerThreads()) {
if (!t.getRegionServer().getRegions(TABLE_NAME).isEmpty()) {
thread = t;
break;
}
}
// shutdown rs
thread.getRegionServer().abort("For testing");
thread.join();
// restart master
UTIL.getMiniHBaseCluster().startMaster();
// make sure that we can schedule a SCP for the crashed server which WAL is disabled and bring
// the region online.
try (Table table =
UTIL.getConnection().getTableBuilder(TABLE_NAME, null).setOperationTimeout(30000).build()) {
table.put(new Put(Bytes.toBytes(1)).addColumn(CF, CQ, Bytes.toBytes(1)));
assertEquals(1, Bytes.toInt(table.get(new Get(Bytes.toBytes(1))).getValue(CF, CQ)));
}
}
}
代码示例来源:origin: apache/hbase
@Test
public void testDropTimeoutRequest() throws Exception {
// Simulate the situation that the server is slow and client retries for several times because
// of timeout. When a request can be handled after waiting in the queue, we will drop it if
// it has been considered as timeout at client. If we don't drop it, the server will waste time
// on handling timeout requests and finally all requests timeout and client throws exception.
TableDescriptorBuilder builder =
TableDescriptorBuilder.newBuilder(TableName.valueOf(name.getMethodName()));
builder.setCoprocessor(SleepLongerAtFirstCoprocessor.class.getName());
ColumnFamilyDescriptor cfd = ColumnFamilyDescriptorBuilder.newBuilder(FAM_NAM).build();
builder.setColumnFamily(cfd);
TableDescriptor td = builder.build();
try (Admin admin = TEST_UTIL.getConnection().getAdmin()) {
admin.createTable(td);
}
TableBuilder tb = TEST_UTIL.getConnection().getTableBuilder(td.getTableName(), null);
tb.setReadRpcTimeout(SleepLongerAtFirstCoprocessor.SLEEP_TIME * 2);
tb.setWriteRpcTimeout(SleepLongerAtFirstCoprocessor.SLEEP_TIME * 2);
try (Table table = tb.build()) {
table.get(new Get(FAM_NAM));
}
}
}
代码示例来源:origin: org.apache.hbase/hbase-client
/**
* Retrieve a Table implementation for accessing a table.
* The returned Table is not thread safe, a new instance should be created for each using thread.
* This is a lightweight operation, pooling or caching of the returned Table
* is neither required nor desired.
* <p>
* The caller is responsible for calling {@link Table#close()} on the returned
* table instance.
* <p>
* Since 0.98.1 this method no longer checks table existence. An exception
* will be thrown if the table does not exist only when the first operation is
* attempted.
*
* @param tableName the name of the table
* @param pool The thread pool to use for batch operations, null to use a default pool.
* @return a Table to use for interactions with this table
*/
default Table getTable(TableName tableName, ExecutorService pool) throws IOException {
return getTableBuilder(tableName, pool).build();
}
代码示例来源:origin: com.aliyun.hbase/alihbase-client
/**
* Retrieve a Table implementation for accessing a table.
* The returned Table is not thread safe, a new instance should be created for each using thread.
* This is a lightweight operation, pooling or caching of the returned Table
* is neither required nor desired.
* <p>
* The caller is responsible for calling {@link Table#close()} on the returned
* table instance.
* <p>
* Since 0.98.1 this method no longer checks table existence. An exception
* will be thrown if the table does not exist only when the first operation is
* attempted.
*
* @param tableName the name of the table
* @param pool The thread pool to use for batch operations, null to use a default pool.
* @return a Table to use for interactions with this table
*/
default Table getTable(TableName tableName, ExecutorService pool) throws IOException {
return getTableBuilder(tableName, pool).build();
}
代码示例来源:origin: org.apache.hbase/hbase-server
try (Table table = conn.getTableBuilder(tableName, null).setOperationTimeout(8000).build()) {
try (Table table = conn.getTableBuilder(tableName, null).setOperationTimeout(6000).build()) {
代码示例来源:origin: org.apache.hbase/hbase-server
@Test
public void testRpcTimeout() throws IOException {
Configuration c = new Configuration(TEST_UTIL.getConfiguration());
try (Table table = TEST_UTIL.getConnection().getTableBuilder(tableName, null)
.setRpcTimeout(SleepCoprocessor.SLEEP_TIME / 2)
.setReadRpcTimeout(SleepCoprocessor.SLEEP_TIME / 2)
.setWriteRpcTimeout(SleepCoprocessor.SLEEP_TIME / 2)
.setOperationTimeout(SleepCoprocessor.SLEEP_TIME * 100).build()) {
execute(table);
fail("Get should not have succeeded");
} catch (RetriesExhaustedException e) {
LOG.info("We received an exception, as expected ", e);
}
// Again, with configuration based override
c.setInt(HConstants.HBASE_RPC_TIMEOUT_KEY, SleepCoprocessor.SLEEP_TIME / 2);
c.setInt(HConstants.HBASE_RPC_READ_TIMEOUT_KEY, SleepCoprocessor.SLEEP_TIME / 2);
c.setInt(HConstants.HBASE_RPC_WRITE_TIMEOUT_KEY, SleepCoprocessor.SLEEP_TIME / 2);
c.setInt(HConstants.HBASE_CLIENT_OPERATION_TIMEOUT, SleepCoprocessor.SLEEP_TIME * 100);
try (Connection conn = ConnectionFactory.createConnection(c)) {
try (Table table = conn.getTable(tableName)) {
execute(table);
fail("Get should not have succeeded");
} catch (RetriesExhaustedException e) {
LOG.info("We received an exception, as expected ", e);
}
}
}
}
代码示例来源:origin: org.apache.hbase/hbase-server
public void testOperationTimeout() throws IOException {
TableBuilder builder =
TEST_UTIL.getConnection().getTableBuilder(tableName, null).setRpcTimeout(Integer.MAX_VALUE)
.setReadRpcTimeout(Integer.MAX_VALUE).setWriteRpcTimeout(Integer.MAX_VALUE);
代码示例来源:origin: org.apache.hbase/hbase-server
@Test
public void test() throws InterruptedException, IOException {
HMaster master = UTIL.getMiniHBaseCluster().stopMaster(0).getMaster();
// Shutdown master before shutting down rs
UTIL.waitFor(30000, () -> !master.isAlive());
RegionServerThread thread = null;
for (RegionServerThread t : UTIL.getMiniHBaseCluster().getRegionServerThreads()) {
if (!t.getRegionServer().getRegions(TABLE_NAME).isEmpty()) {
thread = t;
break;
}
}
// shutdown rs
thread.getRegionServer().abort("For testing");
thread.join();
// restart master
UTIL.getMiniHBaseCluster().startMaster();
// make sure that we can schedule a SCP for the crashed server which WAL is disabled and bring
// the region online.
try (Table table =
UTIL.getConnection().getTableBuilder(TABLE_NAME, null).setOperationTimeout(30000).build()) {
table.put(new Put(Bytes.toBytes(1)).addColumn(CF, CQ, Bytes.toBytes(1)));
assertEquals(1, Bytes.toInt(table.get(new Get(Bytes.toBytes(1))).getValue(CF, CQ)));
}
}
}
代码示例来源:origin: org.apache.hbase/hbase-server
@Test
public void testDropTimeoutRequest() throws Exception {
// Simulate the situation that the server is slow and client retries for several times because
// of timeout. When a request can be handled after waiting in the queue, we will drop it if
// it has been considered as timeout at client. If we don't drop it, the server will waste time
// on handling timeout requests and finally all requests timeout and client throws exception.
TableDescriptorBuilder builder =
TableDescriptorBuilder.newBuilder(TableName.valueOf(name.getMethodName()));
builder.setCoprocessor(SleepLongerAtFirstCoprocessor.class.getName());
ColumnFamilyDescriptor cfd = ColumnFamilyDescriptorBuilder.newBuilder(FAM_NAM).build();
builder.setColumnFamily(cfd);
TableDescriptor td = builder.build();
try (Admin admin = TEST_UTIL.getConnection().getAdmin()) {
admin.createTable(td);
}
TableBuilder tb = TEST_UTIL.getConnection().getTableBuilder(td.getTableName(), null);
tb.setReadRpcTimeout(SleepLongerAtFirstCoprocessor.SLEEP_TIME * 2);
tb.setWriteRpcTimeout(SleepLongerAtFirstCoprocessor.SLEEP_TIME * 2);
try (Table table = tb.build()) {
table.get(new Get(FAM_NAM));
}
}
}
内容来源于网络,如有侵权,请联系作者删除!