-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-31354] SparkContext only register one SparkSession ApplicationEnd listener #28128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
bcdd070
add counter to monitor number of active SparkSessions
f333a30
clear session always in stop()
8fc95e9
added tests
ff60b84
Merge branch 'master' of github.com:apache/spark into vinooganesh/SPA…
f69cabb
responding to PR comments
3fafd2a
cleanup
0c9c426
adding ticket number to test
843491f
style
92c7b22
addressing sean's PR and updating test
d4e4e27
Merge branch 'master' into vinooganesh/SPARK-27958
61c6fed
first iteration of new proposal
b586bf9
Merge remote-tracking branch 'origin/master' into vinooganesh/SPARK-2…
387acb1
testing and style
99c5f64
style fix
7613046
Merge remote-tracking branch 'origin' into vinooganesh/SPARK-27958
vinooganesh 7a70369
Merge branch 'master' into vinooganesh/SPARK-27958
vinooganesh 5a1e0ab
remove unnecessary s
vinooganesh 38dea00
Merge branch 'master' into vinooganesh/SPARK-27958
vinooganesh 0c7e9df
remove lifecycle methods - context tracks listener
vinooganesh 0284c79
remove unnecessary import
vinooganesh 19f45da
Merge branch 'master' into vinooganesh/SPARK-27958
vinooganesh 9573805
add ticket number to test
vinooganesh e877ee1
Merge branch 'master' into vinooganesh/SPARK-27958
vinooganesh e5563a7
move logic to listener
vinooganesh e5ef33a
adding test and cleanup
vinooganesh cfa1462
same class, don't need SparkSession
vinooganesh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,7 @@ package org.apache.spark.sql | |
|
|
||
| import java.io.Closeable | ||
| import java.util.concurrent.TimeUnit._ | ||
| import java.util.concurrent.atomic.AtomicReference | ||
| import java.util.concurrent.atomic.{AtomicBoolean, AtomicReference} | ||
|
|
||
| import scala.collection.JavaConverters._ | ||
| import scala.reflect.runtime.universe.TypeTag | ||
|
|
@@ -49,7 +49,6 @@ import org.apache.spark.sql.types.{DataType, StructType} | |
| import org.apache.spark.sql.util.ExecutionListenerManager | ||
| import org.apache.spark.util.{CallSite, Utils} | ||
|
|
||
|
|
||
| /** | ||
| * The entry point to programming Spark with the Dataset and DataFrame API. | ||
| * | ||
|
|
@@ -940,15 +939,7 @@ object SparkSession extends Logging { | |
| options.foreach { case (k, v) => session.initialSessionOptions.put(k, v) } | ||
| setDefaultSession(session) | ||
| setActiveSession(session) | ||
|
|
||
| // Register a successfully instantiated context to the singleton. This should be at the | ||
| // end of the class definition so that the singleton is updated only if there is no | ||
| // exception in the construction of the instance. | ||
| sparkContext.addSparkListener(new SparkListener { | ||
| override def onApplicationEnd(applicationEnd: SparkListenerApplicationEnd): Unit = { | ||
| defaultSession.set(null) | ||
| } | ||
| }) | ||
| registerContextListener(sparkContext) | ||
| } | ||
|
|
||
| return session | ||
|
|
@@ -1064,6 +1055,20 @@ object SparkSession extends Logging { | |
| // Private methods from now on | ||
| //////////////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| private val listenerRegistered: AtomicBoolean = new AtomicBoolean(false) | ||
|
|
||
| /** Register the AppEnd listener onto the Context */ | ||
| private def registerContextListener(sparkContext: SparkContext): Unit = { | ||
| if (!SparkSession.listenerRegistered.get()) { | ||
| sparkContext.addSparkListener(new SparkListener { | ||
| override def onApplicationEnd(applicationEnd: SparkListenerApplicationEnd): Unit = { | ||
| defaultSession.set(null) | ||
| } | ||
| }) | ||
| SparkSession.listenerRegistered.set(true) | ||
|
||
| } | ||
| } | ||
|
|
||
| /** The active SparkSession for the current thread. */ | ||
| private val activeThreadSession = new InheritableThreadLocal[SparkSession] | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we are in the same class so we can remove
SparkSession.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed!