Skip to content

Commit 5a2bcb8

Browse files
BDC-fengyuanshenwinfys
authored andcommitted
[KYUUBI #2208] Fixed session close operator log session dir not deleted
### _Why are the changes needed?_ Operator log Session dir not deleted when the session is closed, ![image](https://user-images.githubusercontent.com/13195083/159858277-ee1b4391-3f87-41e9-906e-bc02f8ef4655.png) As time goes on, more and more directories are created, which is a big risk ### _How was this patch tested?_ 1、open session ![image](https://user-images.githubusercontent.com/13195083/159859323-221ffd93-4500-4236-8646-9253e3019983.png) session operator dir ![image](https://user-images.githubusercontent.com/13195083/159859633-4bb3db5a-8d46-4e79-af3f-ad88cb1eb3d9.png) 2、Closing the session directory is deleted ![image](https://user-images.githubusercontent.com/13195083/159860262-adcd7f60-2838-456b-beef-6413c50433b7.png) ![image](https://user-images.githubusercontent.com/13195083/159860191-9defcd23-875b-4f03-8e98-9469dcba52f9.png) Closes #2208 from winfys/master. Closes #2208 500e8cf [winfys] Fixed session close operator log session dir not deleted 315d835 [winfys] Fixed session close operator log session dir not deleted 7f261a3 [winfys] Fixed session close operator log session dir not deleted 2dad761 [Fengyuanshen] Merge branch 'apache:master' into master 46725f0 [winfys] Fixed session close operator log session dir not deleted cbcee43 [winfys] Fixed session close operator log session dir not deleted 43e1ec1 [winfys] Fixed session close operator log session dir not deleted Lead-authored-by: winfys <yuanshen.feng@yingxiong.com> Co-authored-by: Fengyuanshen <18211673094@163.com> Signed-off-by: ulysses-you <ulyssesyou@apache.org> (cherry picked from commit a13a89e) Signed-off-by: ulysses-you <ulyssesyou@apache.org>
1 parent 9fce626 commit 5a2bcb8

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

kyuubi-common/src/main/scala/org/apache/kyuubi/session/SessionManager.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,23 @@ abstract class SessionManager(name: String) extends CompositeService(name) {
8989
if (session == null) {
9090
throw KyuubiSQLException(s"Invalid $sessionHandle")
9191
}
92+
deleteOperationLogSessionDir(sessionHandle)
9293
info(s"$sessionHandle is closed, current opening sessions $getOpenSessionCount")
9394
session.close()
9495
}
9596

97+
private def deleteOperationLogSessionDir(sessionHandle: SessionHandle): Unit = {
98+
_operationLogRoot.foreach(logRoot => {
99+
val rootPath = Paths.get(logRoot, sessionHandle.identifier.toString)
100+
try {
101+
Files.deleteIfExists(rootPath)
102+
} catch {
103+
case e: IOException =>
104+
error(s"Failed to delete session operation log directory ${rootPath.toString}", e)
105+
}
106+
})
107+
}
108+
96109
def getSession(sessionHandle: SessionHandle): Session = {
97110
val session = handleToSession.get(sessionHandle)
98111
if (session == null) {

kyuubi-common/src/test/scala/org/apache/kyuubi/operation/log/OperationLogSuite.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ class OperationLogSuite extends KyuubiFunSuite {
8282

8383
operationLog.close()
8484
assert(!Files.exists(logFile))
85+
assert(Files.exists(Paths.get(operationLogRoot, sHandle.identifier.toString)))
86+
sessionManager.closeSession(sHandle)
87+
assert(!Files.exists(Paths.get(operationLogRoot, sHandle.identifier.toString)))
8588
}
8689

8790
test("log divert appender") {

0 commit comments

Comments
 (0)