juliuszsompolski commented on code in PR #41005:
URL: https://github.com/apache/spark/pull/41005#discussion_r1182447748


##########
connector/connect/server/src/main/scala/org/apache/spark/sql/connect/service/SessionHolder.scala:
##########
@@ -0,0 +1,55 @@
+/*
+ * 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.spark.sql.connect.service
+
+import java.util.UUID
+import java.util.concurrent.{ConcurrentHashMap, ConcurrentMap}
+
+import collection.JavaConverters._
+
+import org.apache.spark.connect.proto
+import org.apache.spark.sql.SparkSession
+
+/**
+ * Object used to hold the Spark Connect session state.
+ */
+case class SessionHolder(
+  userId: String,
+  sessionId: String,
+  session: SparkSession) {
+
+  val executePlanOperations: ConcurrentMap[String, ExecutePlanHolder] =
+    new ConcurrentHashMap[String, ExecutePlanHolder]()
+
+  private[connect] def createExecutePlanHolder(
+      request: proto.ExecutePlanRequest): ExecutePlanHolder = {
+
+    val operationId = UUID.randomUUID().toString
+    val executePlanHolder = ExecutePlanHolder(operationId, this, request)
+    assert(executePlanOperations.putIfAbsent(operationId, executePlanHolder) 
== null)
+    executePlanHolder
+  }
+
+  private[connect] def removeExecutePlanHolder(operationId: String): Unit = {
+    executePlanOperations.remove(operationId)
+  }
+
+  private[connect] def interruptAll(): Unit = {
+    executePlanOperations.asScala.values.foreach(_.interrupt())

Review Comment:
   Currently all that this is doing boils down to 
`eventProcessLoop.post(JobGroupCancelled(groupId))` which I don't think can 
throw for as long as DAGScheduler is running / Spark is not shutting down, so I 
think no; the actual interrupt is done async by the DAGScheduler event loop 
that picks that up)
   It's a good point that as the implementation changes (e.g. it goes to 
interrupt the thread running the query) we may want to add some defenses here 
by eating any NonFatal exception here and moving forward.



-- 
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]

Reply via email to