Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e93cedd
tags api
xupefei Aug 20, 2024
694db1b
Merge branch 'master' of github.com:apache/spark into reverse-api-tag
xupefei Aug 20, 2024
40610a7
rename
xupefei Aug 20, 2024
a70d7d2
address comments
xupefei Aug 21, 2024
0656e25
.
xupefei Aug 21, 2024
6b6ca7f
.
xupefei Aug 21, 2024
d3cd5f5
new approach
xupefei Aug 23, 2024
0922dd2
address comments
xupefei Aug 26, 2024
2a6fcc6
return job IDs earlier
xupefei Aug 26, 2024
ef0fddf
doc
xupefei Aug 26, 2024
f2ad163
no mention of spark session in core
xupefei Aug 27, 2024
ab00685
re
xupefei Aug 27, 2024
dd10f46
fix test
xupefei Aug 27, 2024
bc9b76d
revert some changes
xupefei Aug 28, 2024
8656810
undo
xupefei Aug 28, 2024
1dfafad
wip
xupefei Aug 28, 2024
1d4d5cc
.
xupefei Aug 29, 2024
a35c4e5
Merge branch 'master' of github.com:apache/spark into reverse-api-tag
xupefei Aug 29, 2024
d1208c4
revert unnessesary changes and fix tests
xupefei Aug 29, 2024
13342cf
comment
xupefei Aug 29, 2024
3879989
oh no
xupefei Aug 29, 2024
cf6437f
remove internal tags
xupefei Aug 30, 2024
4d7da3b
Merge branch 'master' of github.com:apache/spark into reverse-api-tag
xupefei Aug 30, 2024
b3b7cbc
test
xupefei Aug 30, 2024
7c9294e
Merge branch 'master' of github.com:apache/spark into reverse-api-tag
xupefei Aug 30, 2024
7338b1d
move doc to api
xupefei Aug 30, 2024
905bf91
fix test
xupefei Sep 3, 2024
514b5e4
address mridulm's comments
xupefei Sep 10, 2024
c6fb41f
address herman's comments
xupefei Sep 10, 2024
2a0292c
address hyukjin's comment
xupefei Sep 10, 2024
2d059b3
Merge branch 'master' of github.com:apache/spark into reverse-api-tag
xupefei Sep 10, 2024
a55c47c
scalastyle
xupefei Sep 16, 2024
e66ba0a
fmt
xupefei Sep 17, 2024
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
Prev Previous commit
Next Next commit
address comments
  • Loading branch information
xupefei committed Aug 26, 2024
commit 0922dd287c4f5de18b21cc3393887f7dd8282a85
8 changes: 3 additions & 5 deletions core/src/main/scala/org/apache/spark/SparkContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2698,10 +2698,8 @@ class SparkContext(config: SparkConf) extends Logging {
* @param shouldCancelJob Callback function to be called with the job ID of each job that matches
* the given tag. If the function returns true, the job will be cancelled.
* @return A future that will be completed with the set of job IDs that were cancelled.
*
* @since 4.0.0
*/
def cancelJobsWithTag(
private[spark] def cancelJobsWithTag(
tag: String,
reason: String,
shouldCancelJob: ActiveJob => Boolean): Future[Set[Int]] = {
Expand Down Expand Up @@ -2755,7 +2753,7 @@ class SparkContext(config: SparkConf) extends Logging {
* the given tag. If the function returns true, the job will be cancelled.
* @return A future that will be completed with the set of job IDs that were cancelled.
*/
def cancelAllJobs(shouldCancelJob: ActiveJob => Boolean): Future[Set[Int]] = {
private[spark] def cancelAllJobs(shouldCancelJob: ActiveJob => Boolean): Future[Set[Int]] = {
assertNotStopped()

val cancelledJobs = Promise[Set[Int]]()
Expand All @@ -2779,7 +2777,7 @@ class SparkContext(config: SparkConf) extends Logging {
* @return A future that will be completed with the set of job IDs that were cancelled.
* @note Throws `InterruptedException` if the cancel message cannot be sent
*/
def cancelJob(
private[spark] def cancelJob(
jobId: Int,
reason: String,
shouldCancelJob: ActiveJob => Boolean): Future[Set[Int]] = {
Expand Down
30 changes: 23 additions & 7 deletions sql/core/src/main/scala/org/apache/spark/sql/SparkSession.scala
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ class SparkSession private(
@transient private val existingSharedState: Option[SharedState],
@transient private val parentSessionState: Option[SessionState],
@transient private[sql] val extensions: SparkSessionExtensions,
@transient private[sql] val initialSessionOptions: Map[String, String])
@transient private[sql] val initialSessionOptions: Map[String, String],
@transient private val parentUserDefinedToRealTagsMap: Map[String, String])
extends Serializable with Closeable with Logging { self =>

// The call site where this SparkSession was constructed.
Expand All @@ -108,8 +109,13 @@ class SparkSession private(
private[sql] def this(
sc: SparkContext,
initialSessionOptions: java.util.HashMap[String, String]) = {
this(sc, None, None, SparkSession.applyExtensions(sc, new SparkSessionExtensions),
initialSessionOptions.asScala.toMap)
this(
sc,
existingSharedState = None,
parentSessionState = None,
SparkSession.applyExtensions(sc, new SparkSessionExtensions),
initialSessionOptions.asScala.toMap,
parentUserDefinedToRealTagsMap = Map.empty)
}

private[sql] def this(sc: SparkContext) = this(sc, new java.util.HashMap[String, String]())
Expand All @@ -128,7 +134,9 @@ class SparkSession private(
* A map to hold the mapping from user-defined tags to the real tags attached to Jobs.
* Real tag have the current session ID attached: `"tag1" -> s"spark-$sessionUUID-tag1"`.
*/
private val userDefinedToRealTagsMap: ConcurrentHashMap[String, String] = new ConcurrentHashMap()
@transient
private lazy val userDefinedToRealTagsMap: ConcurrentHashMap[String, String] =
new ConcurrentHashMap(parentUserDefinedToRealTagsMap.asJava)

/**
* The version of Spark on which this application is running.
Expand Down Expand Up @@ -285,7 +293,8 @@ class SparkSession private(
Some(sharedState),
parentSessionState = None,
extensions,
initialSessionOptions)
initialSessionOptions,
parentUserDefinedToRealTagsMap = Map.empty)
}

/**
Expand All @@ -306,8 +315,10 @@ class SparkSession private(
Some(sharedState),
Some(sessionState),
extensions,
Map.empty)
Map.empty,
userDefinedToRealTagsMap.asScala.toMap)
result.sessionState // force copy of SessionState
result.userDefinedToRealTagsMap // force copy of userDefinedToRealTagsMap
result
}

Expand Down Expand Up @@ -1261,7 +1272,12 @@ object SparkSession extends Logging {
loadExtensions(extensions)
applyExtensions(sparkContext, extensions)

session = new SparkSession(sparkContext, None, None, extensions, options.toMap)
session = new SparkSession(sparkContext,
existingSharedState = None,
parentSessionState = None,
extensions,
initialSessionOptions = options.toMap,
parentUserDefinedToRealTagsMap = Map.empty)
setDefaultSession(session)
setActiveSession(session)
registerContextListener(sparkContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ import org.apache.spark.tags.ExtendedSQLTest
import org.apache.spark.util.ThreadUtils

/**
* Test cases for the cancellation APIs provided by [[SparkSession]].
* Test cases for the tagging and cancellation APIs provided by [[SparkSession]].
*/
@ExtendedSQLTest
class SparkSessionJobCancellationSuite
class SparkSessionJobTaggingAndCancellationSuite
extends SparkFunSuite
with Eventually
with LocalSparkContext {
Expand All @@ -60,6 +60,33 @@ class SparkSessionJobCancellationSuite
}
}

test("Tags are not inherited by new sessions") {
val session = SparkSession.builder().master("local").getOrCreate()

assert(session.getTags() == Set())
session.addTag("one")
assert(session.getTags() == Set("one"))

val newSession = session.newSession()
assert(newSession.getTags() == Set())
}

test("Tags are inherited by cloned sessions") {
val session = SparkSession.builder().master("local").getOrCreate()

assert(session.getTags() == Set())
session.addTag("one")
assert(session.getTags() == Set("one"))

val clonedSession = session.cloneSession()
assert(clonedSession.getTags() == Set("one"))
clonedSession.addTag("two")
assert(clonedSession.getTags() == Set("one", "two"))

// Tags are not propagated back to the original session
assert(session.getTags() == Set("one"))
}

test("Cancellation APIs in SparkSession are isolated") {
sc = new SparkContext("local[2]", "test")
val globalSession = SparkSession.builder().sparkContext(sc).getOrCreate()
Expand Down