diff --git a/kyuubi-common/src/main/scala/org/apache/kyuubi/session/SessionManager.scala b/kyuubi-common/src/main/scala/org/apache/kyuubi/session/SessionManager.scala index 7c5c192ccb6..2817bbe8425 100644 --- a/kyuubi-common/src/main/scala/org/apache/kyuubi/session/SessionManager.scala +++ b/kyuubi-common/src/main/scala/org/apache/kyuubi/session/SessionManager.scala @@ -89,10 +89,23 @@ abstract class SessionManager(name: String) extends CompositeService(name) { if (session == null) { throw KyuubiSQLException(s"Invalid $sessionHandle") } + deleteOperationLogSessionDir(sessionHandle) info(s"$sessionHandle is closed, current opening sessions $getOpenSessionCount") session.close() } + private def deleteOperationLogSessionDir(sessionHandle: SessionHandle): Unit = { + _operationLogRoot.foreach(logRoot => { + val rootPath = Paths.get(logRoot, sessionHandle.identifier.toString) + try { + Files.deleteIfExists(rootPath) + } catch { + case e: IOException => + error(s"Failed to delete session operation log directory ${rootPath.toString}", e) + } + }) + } + def getSession(sessionHandle: SessionHandle): Session = { val session = handleToSession.get(sessionHandle) if (session == null) { diff --git a/kyuubi-common/src/test/scala/org/apache/kyuubi/operation/log/OperationLogSuite.scala b/kyuubi-common/src/test/scala/org/apache/kyuubi/operation/log/OperationLogSuite.scala index a2a5d167f76..b3b4b5fe6ee 100644 --- a/kyuubi-common/src/test/scala/org/apache/kyuubi/operation/log/OperationLogSuite.scala +++ b/kyuubi-common/src/test/scala/org/apache/kyuubi/operation/log/OperationLogSuite.scala @@ -82,6 +82,9 @@ class OperationLogSuite extends KyuubiFunSuite { operationLog.close() assert(!Files.exists(logFile)) + assert(Files.exists(Paths.get(operationLogRoot, sHandle.identifier.toString))) + sessionManager.closeSession(sHandle) + assert(!Files.exists(Paths.get(operationLogRoot, sHandle.identifier.toString))) } test("log divert appender") {