pan3793 commented on code in PR #6587:
URL: https://github.com/apache/kyuubi/pull/6587#discussion_r1724816399
##########
kyuubi-server/src/main/scala/org/apache/kyuubi/session/KyuubiSessionManager.scala:
##########
@@ -97,7 +98,8 @@ class KyuubiSessionManager private (name: String) extends
SessionManager(name) {
this,
userConf,
userConf.get(ENGINE_DO_AS_ENABLED),
- parser)
+ parser,
+ tempFileService = kyuubiServer.tempFileService)
Review Comment:
do we need each session to hold one TempFileService instance? if not, just
access the global TempFileService through SessionManager
##########
kyuubi-common/src/main/scala/org/apache/kyuubi/service/TempFileService.scala:
##########
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kyuubi.service
+
+import java.nio.file.{Path, Paths}
+import java.util.concurrent.TimeUnit
+import java.util.concurrent.atomic.AtomicLong
+
+import com.google.common.cache.{Cache, CacheBuilder, RemovalNotification}
+
+import org.apache.kyuubi.Utils
+import org.apache.kyuubi.config.KyuubiConf
+import org.apache.kyuubi.service.TempFileService.tempFileCounter
+import org.apache.kyuubi.util.{TempFileCleanupUtils, ThreadUtils}
+
+class TempFileService(name: String) extends AbstractService(name) {
+ def this() = this(classOf[TempFileService].getSimpleName)
+
+ final private var expiringFiles: Cache[String, String] = _
+ private lazy val cleanupScheduler =
+
ThreadUtils.newDaemonSingleThreadScheduledExecutor(s"temp-file-cleanup-scheduler")
+
+ override def initialize(conf: KyuubiConf): Unit = {
+ super.initialize(conf)
+ val interval = conf.get(KyuubiConf.SERVER_STALE_FILE_EXPIRATION_INTERVAL)
+ expiringFiles = CacheBuilder.newBuilder()
+ .expireAfterWrite(interval, TimeUnit.MILLISECONDS)
+ .removalListener((notification: RemovalNotification[String, String]) => {
+ val pathStr = notification.getValue
+ cleanupFilePath(pathStr)
Review Comment:
add a info log
##########
kyuubi-server/src/main/scala/org/apache/kyuubi/session/KyuubiSessionImpl.scala:
##########
@@ -118,6 +120,8 @@ class KyuubiSessionImpl(
// we should call super.open before running launch engine operation
super.open()
+
Option(tempFileService).foreach(_.addPathToExpiration(operationalLogRootDir.orNull))
Review Comment:
`addPathToExpiration` requires arg not null
##########
kyuubi-common/src/main/scala/org/apache/kyuubi/util/TempFileCleanupUtils.scala:
##########
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kyuubi.util
+
+import java.io.File
+import java.nio.file.{Path, Paths}
+import java.util
+import java.util.Collections
+import java.util.concurrent.atomic.AtomicBoolean
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.kyuubi.Utils
+
+object TempFileCleanupUtils {
+ private lazy val deleteTargets: mutable.Set[String] =
+ Collections.synchronizedSet(new util.HashSet[String]).asScala
+
+ private lazy val isCleanupShutdownHookInstalled = {
+ installFilesCleanupOnExitShutdownHook()
+ new AtomicBoolean(true)
+ }
+
+ private def installFilesCleanupOnExitShutdownHook(): Unit = {
+ Utils.addShutdownHook(
+ hook = () => {
+ deleteTargets.foreach(pathStr =>
+ Utils.deleteDirectoryRecursively(Paths.get(pathStr).toFile))
+ deleteTargets.clear()
+ },
+ priority = Integer.MIN_VALUE)
Review Comment:
is it same as the JDK's one?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]