/** * 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(); }
@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); } } } }
.setOperationTimeout(2000).build()) { table.put( new Put(Bytes.toBytes("key")).addColumn(CF, Bytes.toBytes("cq"), Bytes.toBytes("val")));
.setOperationTimeout(2000).build()) { table.put( new Put(Bytes.toBytes("key")).addColumn(CF, Bytes.toBytes("cq"), Bytes.toBytes("val")));
@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))); } } }
@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)); } } }
/** * 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(); }
/** * 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(); }
@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); } } } }
@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))); } } }
@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)); } } }