use of org.apache.hive.service.cli.SessionHandle in project hive by apache.
the class TestOperationLogManager method testOperationLogManager.
@Test
public void testOperationLogManager() throws Exception {
MyThriftBinaryCLIService service = new MyThriftBinaryCLIService();
service.init(hiveConf);
ThriftCLIServiceClient client = new ThriftCLIServiceClient(service);
SessionManager sessionManager = ((CLIService) service.getService()).getSessionManager();
SessionHandle session1 = client.openSession("user1", "foobar", Collections.<String, String>emptyMap());
OperationHandle opHandle1 = client.executeStatement(session1, "select 1 + 1", null);
Operation operation1 = sessionManager.getOperationManager().getOperation(opHandle1);
String logLocation = operation1.getOperationLog().toString();
// as the historic log is enabled, the log dir of the operation1 should be under the historic dir
assertTrue(logLocation.startsWith(OperationLogManager.getHistoricLogDir()));
File operationLogFile = new File(operation1.getOperationLog().toString());
assertTrue(operationLogFile.exists());
client.closeOperation(opHandle1);
// now close the session1
client.closeSession(session1);
// check that the log of operation1 is exist even if the session1 has been closed
assertTrue(operationLogFile.exists());
SessionHandle session2 = client.openSession("user1", "foobar", Collections.<String, String>emptyMap());
OperationHandle opHandle2 = client.executeStatement(session2, "select 1 + 1", null);
Operation operation2 = sessionManager.getOperationManager().getOperation(opHandle2);
// as the historic log is enabled, the log dir of the operation2 should be under the historic dir
logLocation = operation2.getOperationLog().toString();
assertTrue(logLocation.startsWith(OperationLogManager.getHistoricLogDir()));
// remove the query info of operation1 from the cache
client.closeOperation(opHandle2);
// the operation1 becomes unreachable
OperationManager operationManager = sessionManager.getOperationManager();
assertTrue(operationManager.getAllCachedQueryIds().size() == 1 && operationManager.getLiveQueryInfos().isEmpty());
assertNull(operationManager.getQueryInfo(opHandle1.getHandleIdentifier().toString()));
// now the session1 is closed and has no cached query info, the historic session log dir should be returned.
OperationLogManager logManager = sessionManager.getLogManager().get();
List<File> expiredLogDirs = logManager.getExpiredSessionLogDirs();
List<File> expiredOperationLogs = logManager.getExpiredOperationLogFiles();
assertEquals(operation1.getQueryId(), expiredOperationLogs.get(0).getName());
assertEquals(session1.getHandleIdentifier().toString(), expiredLogDirs.get(0).getName());
logManager.removeExpiredOperationLogAndDir();
// the historic session log dir has been cleanup
assertFalse(operationLogFile.exists());
assertFalse(expiredLogDirs.get(0).exists());
// though session2 is closed, but there exists his operation(operation2) in cache and
// log file under the historic session log dir, so the historic log dir of session2 would not be cleaned
client.closeSession(session2);
assertNotNull(operationManager.getQueryInfo(opHandle2.getHandleIdentifier().toString()));
assertTrue(operationManager.getAllCachedQueryIds().size() == 1 && operationManager.getLiveQueryInfos().isEmpty());
expiredOperationLogs = logManager.getExpiredOperationLogFiles();
expiredLogDirs = logManager.getExpiredSessionLogDirs();
assertTrue(expiredLogDirs.isEmpty());
assertTrue(expiredOperationLogs.isEmpty());
logManager.removeExpiredOperationLogAndDir();
assertTrue(new File(logLocation).getParentFile().exists());
FileUtils.deleteQuietly(new File(OperationLogManager.getHistoricLogDir()));
}
use of org.apache.hive.service.cli.SessionHandle in project hive by apache.
the class TestPluggableHiveSessionImpl method testSessionImpl.
@Test
public void testSessionImpl() throws Exception {
HiveConf hiveConf = new HiveConf();
hiveConf.setVar(HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER, HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER.getDefaultValue());
hiveConf.setVar(HiveConf.ConfVars.HIVE_SESSION_IMPL_CLASSNAME, SampleHiveSessionImpl.class.getName());
hiveConf.setBoolVar(HiveConf.ConfVars.HIVE_SERVER2_ENABLE_DOAS, false);
CLIService cliService = new CLIService(null, true);
cliService.init(hiveConf);
ThriftBinaryCLIService service = new ThriftBinaryCLIService(cliService);
service.init(hiveConf);
ThriftCLIServiceClient client = new ThriftCLIServiceClient(service);
SessionHandle sessionHandle = null;
sessionHandle = client.openSession("tom", "password");
assertEquals(SampleHiveSessionImpl.class.getName(), service.getHiveConf().getVar(HiveConf.ConfVars.HIVE_SESSION_IMPL_CLASSNAME));
HiveSession session = cliService.getSessionManager().getSession(sessionHandle);
assertEquals(SampleHiveSessionImpl.MAGIC_RETURN_VALUE, session.getNoOperationTime());
client.closeSession(sessionHandle);
}
use of org.apache.hive.service.cli.SessionHandle in project hive by apache.
the class TestSessionManagerMetrics method testOpenSessionTimeMetrics.
@Test
public void testOpenSessionTimeMetrics() throws Exception {
String json = metrics.dumpJson();
MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.GAUGE, MetricsConstant.HS2_AVG_OPEN_SESSION_TIME, "NaN");
long firstSessionOpen = System.currentTimeMillis();
SessionHandle handle = sm.openSession(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V9, "user", "passw", "127.0.0.1", new HashMap<String, String>());
json = metrics.dumpJson();
MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.GAUGE, MetricsConstant.HS2_AVG_OPEN_SESSION_TIME, (double) (System.currentTimeMillis() - firstSessionOpen), 100d);
long secondSessionOpen = System.currentTimeMillis();
sm.openSession(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V9, "user", "passw", "127.0.0.1", new HashMap<String, String>());
json = metrics.dumpJson();
MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.GAUGE, MetricsConstant.HS2_AVG_OPEN_SESSION_TIME, (double) (System.currentTimeMillis() - firstSessionOpen + System.currentTimeMillis() - secondSessionOpen) / 2d, 100d);
sm.closeSession(handle);
json = metrics.dumpJson();
MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.GAUGE, MetricsConstant.HS2_AVG_OPEN_SESSION_TIME, (double) (System.currentTimeMillis() - secondSessionOpen), 100d);
}
use of org.apache.hive.service.cli.SessionHandle in project hive by apache.
the class TestSessionManagerMetrics method testActiveSessionTimeMetrics.
@Test
public void testActiveSessionTimeMetrics() throws Exception {
final CyclicBarrier ready = new CyclicBarrier(2);
CyclicBarrier completed = new CyclicBarrier(2);
String json = metrics.dumpJson();
MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.GAUGE, MetricsConstant.HS2_AVG_ACTIVE_SESSION_TIME, "NaN");
SessionHandle handle = sm.openSession(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V9, "user", "passw", "127.0.0.1", new HashMap<String, String>());
final HiveSession session = sm.getSession(handle);
OperationManager operationManager = mock(OperationManager.class);
when(operationManager.newGetTablesOperation(session, "catalog", "schema", "table", null)).thenReturn(new BlockingOperation(session, OperationType.GET_TABLES, ready, completed));
session.setOperationManager(operationManager);
long sessionActivateTime = System.currentTimeMillis();
new Thread(new Runnable() {
@Override
public void run() {
try {
Hive.set(session.getSessionHive());
OperationHandle handle = session.getTables("catalog", "schema", "table", null);
session.closeOperation(handle);
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
try {
ready.await();
} catch (InterruptedException | BrokenBarrierException e) {
// ignore
}
}
}
}).start();
ready.await(2, TimeUnit.SECONDS);
ready.reset();
json = metrics.dumpJson();
MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.GAUGE, MetricsConstant.HS2_AVG_ACTIVE_SESSION_TIME, (double) System.currentTimeMillis() - sessionActivateTime, 100d);
completed.await(2, TimeUnit.SECONDS);
ready.await(2, TimeUnit.SECONDS);
json = metrics.dumpJson();
MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.GAUGE, MetricsConstant.HS2_AVG_ACTIVE_SESSION_TIME, "NaN");
}
use of org.apache.hive.service.cli.SessionHandle in project hive by apache.
the class TestSessionManagerMetrics method testOpenSessionMetrics.
@Test
public void testOpenSessionMetrics() throws Exception {
String json = metrics.dumpJson();
MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.GAUGE, MetricsConstant.HS2_OPEN_SESSIONS, 0);
SessionHandle handle = sm.openSession(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V9, "user", "passw", "127.0.0.1", new HashMap<String, String>());
json = metrics.dumpJson();
MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.GAUGE, MetricsConstant.HS2_OPEN_SESSIONS, 1);
sm.openSession(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V9, "user", "passw", "127.0.0.1", new HashMap<String, String>());
json = metrics.dumpJson();
MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.GAUGE, MetricsConstant.HS2_OPEN_SESSIONS, 2);
sm.closeSession(handle);
json = metrics.dumpJson();
MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.GAUGE, MetricsConstant.HS2_OPEN_SESSIONS, 1);
}
Aggregations