Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import scala.concurrent.duration.Duration
import scala.util.control.NonFatal

import com.google.common.annotations.VisibleForTesting
import org.apache.hadoop.fs.Path
import org.apache.spark.{ui, SparkConf}
import org.apache.spark.kyuubi.{SparkContextHelper, SparkSQLEngineEventListener, SparkSQLEngineListener}
import org.apache.spark.kyuubi.SparkUtilsHelper.getLocalDir
Expand Down Expand Up @@ -58,8 +59,7 @@ case class SparkSQLEngine(spark: SparkSession) extends Serverable("SparkSQLEngin

@volatile private var lifetimeTerminatingChecker: Option[ScheduledExecutorService] = None
@volatile private var stopEngineExec: Option[ThreadPoolExecutor] = None
private lazy val engineSavePath =
backendService.sessionManager.asInstanceOf[SparkSQLSessionManager].getEngineResultSavePath()
@volatile private var engineSavePath: Path = _

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer Option over null

Suggested change
@volatile private var engineSavePath: Path = _
@volatile private var engineSavePath: Option[Path] = None


override def initialize(conf: KyuubiConf): Unit = {
val listener = new SparkSQLEngineListener(this)
Expand Down Expand Up @@ -90,11 +90,13 @@ case class SparkSQLEngine(spark: SparkSession) extends Serverable("SparkSQLEngin
startFastFailChecker(maxInitTimeout)
}

if (backendService.sessionManager.getConf.get(OPERATION_RESULT_SAVE_TO_FILE)) {
val fs = engineSavePath.getFileSystem(spark.sparkContext.hadoopConfiguration)
fs.mkdirs(engineSavePath)
fs.deleteOnExit(engineSavePath)
}
// Due to the fact that session-level enabling of `kyuubi.operation.result.saveToFile.enabled`
// is allowed, we always create and clean up this directory
engineSavePath =
backendService.sessionManager.asInstanceOf[SparkSQLSessionManager].getEngineResultSavePath()
val fs = engineSavePath.getFileSystem(spark.sparkContext.hadoopConfiguration)
fs.mkdirs(engineSavePath)
fs.deleteOnExit(engineSavePath)
Comment on lines +95 to +99

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
engineSavePath =
backendService.sessionManager.asInstanceOf[SparkSQLSessionManager].getEngineResultSavePath()
val fs = engineSavePath.getFileSystem(spark.sparkContext.hadoopConfiguration)
fs.mkdirs(engineSavePath)
fs.deleteOnExit(engineSavePath)
val savePath =
backendService.sessionManager.asInstanceOf[SparkSQLSessionManager].getEngineResultSavePath()
engineSavePath = Some(savePath)
val fs = savePath.getFileSystem(spark.sparkContext.hadoopConfiguration)
fs.mkdirs(savePath)
fs.deleteOnExit(savePath)

}

override def stop(): Unit = if (shutdown.compareAndSet(false, true)) {
Expand All @@ -110,13 +112,15 @@ case class SparkSQLEngine(spark: SparkSession) extends Serverable("SparkSQLEngin
exec,
Duration(60, TimeUnit.SECONDS))
})
try {
val fs = engineSavePath.getFileSystem(spark.sparkContext.hadoopConfiguration)
if (fs.exists(engineSavePath)) {
fs.delete(engineSavePath, true)
if (engineSavePath != null) {
try {
val fs = engineSavePath.getFileSystem(spark.sparkContext.hadoopConfiguration)
if (fs.exists(engineSavePath)) {
fs.delete(engineSavePath, true)
}
} catch {
case e: Throwable => error(s"Error cleaning engine result save path: $engineSavePath", e)
}
} catch {
case e: Throwable => error(s"Error cleaning engine result save path: $engineSavePath", e)
}
Comment on lines +115 to 124

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (engineSavePath != null) {
try {
val fs = engineSavePath.getFileSystem(spark.sparkContext.hadoopConfiguration)
if (fs.exists(engineSavePath)) {
fs.delete(engineSavePath, true)
}
} catch {
case e: Throwable => error(s"Error cleaning engine result save path: $engineSavePath", e)
}
} catch {
case e: Throwable => error(s"Error cleaning engine result save path: $engineSavePath", e)
}
engineSavePath.foreach { path =>
try {
val fs = path.getFileSystem(spark.sparkContext.hadoopConfiguration)
if (fs.exists(path)) {
fs.delete(path, true)
}
} catch {
case e: Throwable => error(s"Error cleaning engine result save path: $path", e)
}
}

}

Expand Down
Loading