You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kyuubi.apache.org by ul...@apache.org on 2022/06/09 03:58:14 UTC

[incubator-kyuubi] branch branch-1.5 updated: [KYUUBI #2208] Fixed session close operator log session dir not deleted

This is an automated email from the ASF dual-hosted git repository.

ulyssesyou pushed a commit to branch branch-1.5
in repository https://gitbox.apache.org/repos/asf/incubator-kyuubi.git


The following commit(s) were added to refs/heads/branch-1.5 by this push:
     new 5a2bcb802 [KYUUBI #2208] Fixed session close operator log session dir not deleted
5a2bcb802 is described below

commit 5a2bcb80289ef0fbe67fc778a754adb191ebee93
Author: winfys <yu...@yingxiong.com>
AuthorDate: Fri Mar 25 16:50:08 2022 +0800

    [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
    
    500e8cf4 [winfys] Fixed session close operator log session dir not deleted
    315d8354 [winfys] Fixed session close operator log session dir not deleted
    7f261a32 [winfys] Fixed session close operator log session dir not deleted
    2dad761b [Fengyuanshen] Merge branch 'apache:master' into master
    46725f0c [winfys] Fixed session close operator log session dir not deleted
    cbcee438 [winfys] Fixed session close operator log session dir not deleted
    43e1ec19 [winfys] Fixed session close operator log session dir not deleted
    
    Lead-authored-by: winfys <yu...@yingxiong.com>
    Co-authored-by: Fengyuanshen <18...@163.com>
    Signed-off-by: ulysses-you <ul...@apache.org>
    (cherry picked from commit a13a89e8a6eef10f4c30834591de39f1128dd19c)
    Signed-off-by: ulysses-you <ul...@apache.org>
---
 .../scala/org/apache/kyuubi/session/SessionManager.scala    | 13 +++++++++++++
 .../org/apache/kyuubi/operation/log/OperationLogSuite.scala |  3 +++
 2 files changed, 16 insertions(+)

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 7c5c192cc..2817bbe84 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 a2a5d167f..b3b4b5fe6 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") {