diff --git service/src/java/org/apache/hive/service/cli/session/SessionManager.java service/src/java/org/apache/hive/service/cli/session/SessionManager.java index c2313c0..7bcf3a3 100644 --- service/src/java/org/apache/hive/service/cli/session/SessionManager.java +++ service/src/java/org/apache/hive/service/cli/session/SessionManager.java @@ -351,14 +351,16 @@ public HiveSession createSession(SessionHandle sessionHandle, TProtocolVersion p throw new HiveSQLException("Failed to execute session hooks: " + e.getMessage(), e); } handleToSession.put(session.getSessionHandle(), session); + LOG.info("Session opened, " + session.getSessionHandle() + ", current sessions:" + getOpenSessionCount()); return session; } - public void closeSession(SessionHandle sessionHandle) throws HiveSQLException { + public synchronized void closeSession(SessionHandle sessionHandle) throws HiveSQLException { HiveSession session = handleToSession.remove(sessionHandle); if (session == null) { throw new HiveSQLException("Session does not exist!"); } + LOG.info("Session closed, " + sessionHandle + ", current sessions:" + getOpenSessionCount()); try { session.close(); } finally { diff --git service/src/java/org/apache/hive/service/cli/thrift/ThriftCLIService.java service/src/java/org/apache/hive/service/cli/thrift/ThriftCLIService.java index 24f1a61..e097b79 100644 --- service/src/java/org/apache/hive/service/cli/thrift/ThriftCLIService.java +++ service/src/java/org/apache/hive/service/cli/thrift/ThriftCLIService.java @@ -117,7 +117,6 @@ protected CLIService cliService; private static final TStatus OK_STATUS = new TStatus(TStatusCode.SUCCESS_STATUS); protected static HiveAuthFactory hiveAuthFactory; - private static final AtomicInteger sessionCount = new AtomicInteger(); protected int portNum; protected InetAddress serverIPAddress; @@ -320,7 +319,6 @@ public TOpenSessionResp OpenSession(TOpenSessionReq req) throws TException { if (context != null) { context.setSessionHandle(sessionHandle); } - LOG.info("Opened a session, current sessions: " + sessionCount.incrementAndGet()); } catch (Exception e) { LOG.warn("Error opening session: ", e); resp.setStatus(HiveSQLException.toTStatus(e)); @@ -466,7 +464,6 @@ public TCloseSessionResp CloseSession(TCloseSessionReq req) throws TException { try { SessionHandle sessionHandle = new SessionHandle(req.getSessionHandle()); cliService.closeSession(sessionHandle); - LOG.info("Closed a session, current sessions: " + sessionCount.decrementAndGet()); resp.setStatus(OK_STATUS); ThriftCLIServerContext context = (ThriftCLIServerContext)currentServerContext.get();