use of org.apache.hadoop.hbase.ipc.RpcClient in project hbase by apache.
the class TestHCM method testConnectionClose.
private void testConnectionClose(boolean allowsInterrupt) throws Exception {
TableName tableName = TableName.valueOf("HCM-testConnectionClose" + allowsInterrupt);
TEST_UTIL.createTable(tableName, FAM_NAM).close();
boolean previousBalance = TEST_UTIL.getAdmin().setBalancerRunning(false, true);
Configuration c2 = new Configuration(TEST_UTIL.getConfiguration());
// We want to work on a separate connection.
c2.set(HConstants.HBASE_CLIENT_INSTANCE_ID, String.valueOf(-1));
// retry a lot
c2.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 100);
// don't wait between retries.
c2.setInt(HConstants.HBASE_CLIENT_PAUSE, 1);
// Server do not really expire
c2.setInt(RpcClient.FAILED_SERVER_EXPIRY_KEY, 0);
c2.setBoolean(RpcClient.SPECIFIC_WRITE_THREAD, allowsInterrupt);
// to avoid the client to be stuck when do the Get
c2.setInt(HConstants.HBASE_CLIENT_META_OPERATION_TIMEOUT, 10000);
c2.setInt(HConstants.HBASE_CLIENT_OPERATION_TIMEOUT, 10000);
c2.setInt(HConstants.HBASE_RPC_TIMEOUT_KEY, 5000);
Connection connection = ConnectionFactory.createConnection(c2);
final Table table = connection.getTable(tableName);
Put put = new Put(ROW);
put.addColumn(FAM_NAM, ROW, ROW);
table.put(put);
// 4 steps: ready=0; doGets=1; mustStop=2; stopped=3
final AtomicInteger step = new AtomicInteger(0);
final AtomicReference<Throwable> failed = new AtomicReference<>(null);
Thread t = new Thread("testConnectionCloseThread") {
@Override
public void run() {
int done = 0;
try {
step.set(1);
while (step.get() == 1) {
Get get = new Get(ROW);
table.get(get);
done++;
if (done % 100 == 0)
LOG.info("done=" + done);
// without the sleep, will cause the exception for too many files in
// org.apache.hadoop.hdfs.server.datanode.DataXceiver
Thread.sleep(100);
}
} catch (Throwable t) {
failed.set(t);
LOG.error(t);
}
step.set(3);
}
};
t.start();
TEST_UTIL.waitFor(20000, new Waiter.Predicate<Exception>() {
@Override
public boolean evaluate() throws Exception {
return step.get() == 1;
}
});
ServerName sn;
try (RegionLocator rl = connection.getRegionLocator(tableName)) {
sn = rl.getRegionLocation(ROW).getServerName();
}
ConnectionImplementation conn = (ConnectionImplementation) connection;
RpcClient rpcClient = conn.getRpcClient();
LOG.info("Going to cancel connections. connection=" + conn.toString() + ", sn=" + sn);
for (int i = 0; i < 5000; i++) {
rpcClient.cancelConnections(sn);
Thread.sleep(5);
}
step.compareAndSet(1, 2);
// The test may fail here if the thread doing the gets is stuck. The way to find
// out what's happening is to look for the thread named 'testConnectionCloseThread'
TEST_UTIL.waitFor(40000, new Waiter.Predicate<Exception>() {
@Override
public boolean evaluate() throws Exception {
return step.get() == 3;
}
});
table.close();
connection.close();
Assert.assertTrue("Unexpected exception is " + failed.get(), failed.get() == null);
TEST_UTIL.getAdmin().setBalancerRunning(previousBalance, true);
}
use of org.apache.hadoop.hbase.ipc.RpcClient in project hbase by apache.
the class TestConnection method testCancelConnectionMemoryLeak.
// There is no assertion, but you need to confirm that there is no resource leak output from netty
@Test
public void testCancelConnectionMemoryLeak() throws IOException, InterruptedException {
TableName tableName = TableName.valueOf(name.getMethodName());
TEST_UTIL.createTable(tableName, FAM_NAM).close();
TEST_UTIL.getAdmin().balancerSwitch(false, true);
try (Connection connection = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration());
Table table = connection.getTable(tableName)) {
table.get(new Get(Bytes.toBytes("1")));
ServerName sn = TEST_UTIL.getRSForFirstRegionInTable(tableName).getServerName();
RpcClient rpcClient = ((AsyncConnectionImpl) connection.toAsyncConnection()).rpcClient;
rpcClient.cancelConnections(sn);
Thread.sleep(1000);
System.gc();
Thread.sleep(1000);
}
}
use of org.apache.hadoop.hbase.ipc.RpcClient in project hbase by apache.
the class TestSecureIPC method callRpcService.
/**
* Sets up a RPC Server and a Client. Does a RPC checks the result. If an exception is thrown from
* the stub, this function will throw root cause of that exception.
*/
private void callRpcService(User clientUser) throws Exception {
SecurityInfo securityInfoMock = Mockito.mock(SecurityInfo.class);
Mockito.when(securityInfoMock.getServerPrincipal()).thenReturn(HBaseKerberosUtils.KRB_PRINCIPAL);
SecurityInfo.addInfo("TestProtobufRpcProto", securityInfoMock);
InetSocketAddress isa = new InetSocketAddress(HOST, 0);
RpcServerInterface rpcServer = RpcServerFactory.createRpcServer(null, "AbstractTestSecureIPC", Lists.newArrayList(new RpcServer.BlockingServiceAndInterface((BlockingService) SERVICE, null)), isa, serverConf, new FifoRpcScheduler(serverConf, 1));
rpcServer.start();
try (RpcClient rpcClient = RpcClientFactory.createClient(clientConf, HConstants.DEFAULT_CLUSTER_ID.toString())) {
BlockingInterface stub = newBlockingStub(rpcClient, rpcServer.getListenerAddress(), clientUser);
TestThread th1 = new TestThread(stub);
final Throwable[] exception = new Throwable[1];
Collections.synchronizedList(new ArrayList<Throwable>());
Thread.UncaughtExceptionHandler exceptionHandler = new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread th, Throwable ex) {
exception[0] = ex;
}
};
th1.setUncaughtExceptionHandler(exceptionHandler);
th1.start();
th1.join();
if (exception[0] != null) {
// throw root cause.
while (exception[0].getCause() != null) {
exception[0] = exception[0].getCause();
}
throw (Exception) exception[0];
}
} finally {
rpcServer.stop();
}
}
use of org.apache.hadoop.hbase.ipc.RpcClient in project hbase by apache.
the class TestConnection method testConnectionClose.
private void testConnectionClose(boolean allowsInterrupt) throws Exception {
TableName tableName = TableName.valueOf("HCM-testConnectionClose" + allowsInterrupt);
TEST_UTIL.createTable(tableName, FAM_NAM).close();
TEST_UTIL.getAdmin().balancerSwitch(false, true);
Configuration c2 = new Configuration(TEST_UTIL.getConfiguration());
// We want to work on a separate connection.
c2.set(HConstants.HBASE_CLIENT_INSTANCE_ID, String.valueOf(-1));
// retry a lot
c2.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 100);
// don't wait between retries.
c2.setInt(HConstants.HBASE_CLIENT_PAUSE, 1);
// Server do not really expire
c2.setInt(RpcClient.FAILED_SERVER_EXPIRY_KEY, 0);
c2.setBoolean(RpcClient.SPECIFIC_WRITE_THREAD, allowsInterrupt);
// to avoid the client to be stuck when do the Get
c2.setInt(HConstants.HBASE_CLIENT_META_OPERATION_TIMEOUT, 10000);
c2.setInt(HConstants.HBASE_CLIENT_OPERATION_TIMEOUT, 10000);
c2.setInt(HConstants.HBASE_RPC_TIMEOUT_KEY, 5000);
Connection connection = ConnectionFactory.createConnection(c2);
final Table table = connection.getTable(tableName);
Put put = new Put(ROW);
put.addColumn(FAM_NAM, ROW, ROW);
table.put(put);
// 4 steps: ready=0; doGets=1; mustStop=2; stopped=3
final AtomicInteger step = new AtomicInteger(0);
final AtomicReference<Throwable> failed = new AtomicReference<>(null);
Thread t = new Thread("testConnectionCloseThread") {
@Override
public void run() {
int done = 0;
try {
step.set(1);
while (step.get() == 1) {
Get get = new Get(ROW);
table.get(get);
done++;
if (done % 100 == 0) {
LOG.info("done=" + done);
}
// without the sleep, will cause the exception for too many files in
// org.apache.hadoop.hdfs.server.datanode.DataXceiver
Thread.sleep(100);
}
} catch (Throwable t) {
failed.set(t);
LOG.error(t.toString(), t);
}
step.set(3);
}
};
t.start();
TEST_UTIL.waitFor(20000, new Waiter.Predicate<Exception>() {
@Override
public boolean evaluate() throws Exception {
return step.get() == 1;
}
});
ServerName sn;
try (RegionLocator rl = connection.getRegionLocator(tableName)) {
sn = rl.getRegionLocation(ROW).getServerName();
}
RpcClient rpcClient = ((AsyncConnectionImpl) connection.toAsyncConnection()).rpcClient;
LOG.info("Going to cancel connections. connection=" + connection.toString() + ", sn=" + sn);
for (int i = 0; i < 500; i++) {
rpcClient.cancelConnections(sn);
Thread.sleep(50);
}
step.compareAndSet(1, 2);
// The test may fail here if the thread doing the gets is stuck. The way to find
// out what's happening is to look for the thread named 'testConnectionCloseThread'
TEST_UTIL.waitFor(40000, new Waiter.Predicate<Exception>() {
@Override
public boolean evaluate() throws Exception {
return step.get() == 3;
}
});
table.close();
connection.close();
Assert.assertTrue("Unexpected exception is " + failed.get(), failed.get() == null);
}
Aggregations