You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@kyuubi.apache.org by GitBox <gi...@apache.org> on 2022/04/22 02:36:14 UTC

[GitHub] [incubator-kyuubi] yaooqinn commented on a diff in pull request #2435: [KYUUBI #1987] Support preserve user context in group/server share level

yaooqinn commented on code in PR #2435:
URL: https://github.com/apache/incubator-kyuubi/pull/2435#discussion_r855722489


##########
externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/session/SparkSQLSessionManager.scala:
##########
@@ -50,6 +53,39 @@ class SparkSQLSessionManager private (name: String, spark: SparkSession)
   val operationManager = new SparkSQLOperationManager()
 
   private lazy val singleSparkSession = conf.get(ENGINE_SINGLE_SPARK_SESSION)
+  private lazy val shareLevel = ShareLevel.withName(conf.get(ENGINE_SHARE_LEVEL))
+
+  private lazy val userIsolatedSparkSession = conf.get(ENGINE_USER_ISOLATED_SPARK_SESSION)
+  private lazy val userIsolatedSparkSessionCache = new ConcurrentHashMap[String, SparkSession]()
+
+  private def getOrNewSparkSession(user: String): SparkSession = {
+    if (singleSparkSession) {
+      spark
+    } else {
+      shareLevel match {
+        // it's unnecessary to create a new spark session in connection share level
+        // since the session is only one
+        case CONNECTION => spark
+        case USER => newSparkSession(spark)
+        case GROUP | SERVER if userIsolatedSparkSession =>
+          if (userIsolatedSparkSessionCache.containsKey(user)) {
+            userIsolatedSparkSessionCache.get(user)
+          } else {
+            val newSession = newSparkSession(spark)
+            userIsolatedSparkSessionCache.put(user, newSession)
+            newSession
+          }
+        case GROUP | SERVER => newSparkSession(spark)
+        case _ => throw new IllegalStateException(s"Unrecognized share level: $shareLevel")

Review Comment:
   this is unnecessary



-- 
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: notifications-unsubscribe@kyuubi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org