[KYUUBI #2227] Fix operation log dir not deleted issue

### _Why are the changes needed?_

Refer: https://github.com/apache/incubator-kyuubi/pull/2208#discussion_r835444874

To close #2227

### _How was this patch tested?_
- [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible

- [ ] Add screenshots for manual tests if appropriate

- [ ] [Run test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request

Closes #2229 from turboFei/delete_log.

Closes #2227

bf7efca1 [Fei Wang] delete log dir with recurisive

Authored-by: Fei Wang <fwang12@ebay.com>
Signed-off-by: Fei Wang <fwang12@ebay.com>
This commit is contained in:
Fei Wang 2022-03-27 18:19:32 +08:00
parent c1ffc3ca6b
commit 55052f963e

View File

@ -25,7 +25,7 @@ import scala.collection.JavaConverters._
import org.apache.hive.service.rpc.thrift.TProtocolVersion
import org.apache.kyuubi.KyuubiSQLException
import org.apache.kyuubi.{KyuubiSQLException, Utils}
import org.apache.kyuubi.config.KyuubiConf
import org.apache.kyuubi.config.KyuubiConf._
import org.apache.kyuubi.operation.OperationManager
@ -89,16 +89,16 @@ 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()
deleteOperationLogSessionDir(sessionHandle)
}
private def deleteOperationLogSessionDir(sessionHandle: SessionHandle): Unit = {
_operationLogRoot.foreach(logRoot => {
val rootPath = Paths.get(logRoot, sessionHandle.identifier.toString)
try {
Files.deleteIfExists(rootPath)
Utils.deleteDirectoryRecursively(rootPath.toFile)
} catch {
case e: IOException =>
error(s"Failed to delete session operation log directory ${rootPath.toString}", e)