xuanyuanking commented on a change in pull request #28280:
URL: https://github.com/apache/spark/pull/28280#discussion_r413573253



##########
File path: 
core/src/main/scala/org/apache/spark/scheduler/JobCleanedHookListener.scala
##########
@@ -0,0 +1,47 @@
+/*
+ * 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.scheduler
+
+import scala.collection.mutable.HashMap
+
+import org.apache.spark.internal.Logging
+
+/**
+ * JobCleanedHookListener is a basic job cleaned listener. It holds 
jobCleanedHooks for
+ * jobs and run cleaned hook after a job is cleaned.
+ */
+class JobCleanedHookListener extends SparkListener with Logging {
+  // use private val and synchronized to keep thread safe
+  private val jobCleanedHooks = new HashMap[Int, Int => Unit]()
+
+  def addCleanedHook(jobId: Int, fun: Int => Unit): Unit = synchronized{
+    jobCleanedHooks.put(jobId, fun)
+  }
+
+  def deleteCleanedHook(jobId: Int): Unit = synchronized {
+    jobCleanedHooks.remove(jobId)
+  }
+
+  override def onJobCleaned(jobCleaned: SparkListenerJobCleaned): Unit = {
+    jobCleanedHooks.get(jobCleaned.jobId)
+      .foreach{function =>

Review comment:
       `foreach { function`

##########
File path: 
core/src/main/scala/org/apache/spark/scheduler/JobCleanedHookListener.scala
##########
@@ -0,0 +1,47 @@
+/*
+ * 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.scheduler
+
+import scala.collection.mutable.HashMap
+
+import org.apache.spark.internal.Logging
+
+/**
+ * JobCleanedHookListener is a basic job cleaned listener. It holds 
jobCleanedHooks for
+ * jobs and run cleaned hook after a job is cleaned.
+ */
+class JobCleanedHookListener extends SparkListener with Logging {

Review comment:
       Maybe we need to add UT for the new class in SparkListenerSuite or 
somewhere else.

##########
File path: 
core/src/main/scala/org/apache/spark/scheduler/JobCleanedHookListener.scala
##########
@@ -0,0 +1,47 @@
+/*
+ * 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.scheduler
+
+import scala.collection.mutable.HashMap
+
+import org.apache.spark.internal.Logging
+
+/**
+ * JobCleanedHookListener is a basic job cleaned listener. It holds 
jobCleanedHooks for
+ * jobs and run cleaned hook after a job is cleaned.
+ */
+class JobCleanedHookListener extends SparkListener with Logging {
+  // use private val and synchronized to keep thread safe
+  private val jobCleanedHooks = new HashMap[Int, Int => Unit]()
+
+  def addCleanedHook(jobId: Int, fun: Int => Unit): Unit = synchronized{

Review comment:
       `synchronized {`

##########
File path: 
sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/InsertIntoHiveTable.scala
##########
@@ -99,6 +99,12 @@ case class InsertIntoHiveTable(
 
     try {
       processInsert(sparkSession, externalCatalog, hadoopConf, tableDesc, 
tmpLocation, child)
+    } catch {
+      case e: Throwable =>
+        // Make sure tmp path deleted while getting Exception before sc.runJob
+        deleteExternalTmpPath(hadoopConf)
+        throw new SparkException(
+          s"Failed inserting ubti table ${table.identifier.quotedString}", e)

Review comment:
       ubti table?




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

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