Skip to content
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

[SPARK-32029][SQL] Check spark context is stoped when get active session #28868

Closed
wants to merge 6 commits into from

Conversation

ulysses-you
Copy link
Contributor

@ulysses-you ulysses-you commented Jun 19, 2020

What changes were proposed in this pull request?

Check spark context is stoped when get active session.

Why are the changes needed?

Now default session is set null when application end but active session still exists, we should forbid this.

Before this pr:
We can still use spark.sql("show tables") after sc.stop.

Does this PR introduce any user-facing change?

BUG fix.

How was this patch tested?

Add UT.

@ulysses-you ulysses-you changed the title [SPARK-32029][SQL] Make activeSession null when application end [SPARK-32029][SQL] Make active session null when application end Jun 19, 2020
@SparkQA
Copy link

SparkQA commented Jun 19, 2020

Test build #124259 has finished for PR 28868 at commit cbd33cb.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jun 19, 2020

Test build #124263 has finished for PR 28868 at commit 4d7ff58.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds no public classes.

@dongjoon-hyun
Copy link
Member

Retest this please.

@SparkQA
Copy link

SparkQA commented Jun 20, 2020

Test build #124302 has finished for PR 28868 at commit 4d7ff58.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jun 20, 2020

Test build #124312 has finished for PR 28868 at commit a59119f.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@ulysses-you
Copy link
Contributor Author

close and check this offline.

@ulysses-you ulysses-you reopened this Jul 1, 2020
@ulysses-you ulysses-you changed the title [SPARK-32029][SQL] Make active session null when application end [SPARK-32029][SQL] Check active session if spark context is stop Jul 1, 2020
@SparkQA
Copy link

SparkQA commented Jul 1, 2020

Test build #124779 has finished for PR 28868 at commit a59119f.

  • This patch fails build dependency tests.
  • This patch does not merge cleanly.
  • This patch adds no public classes.

@@ -758,7 +758,7 @@ class SparkSession private(
// Use the active session thread local directly to make sure we get the session that is actually
// set and not the default session. This to prevent that we promote the default session to the
// active session once we are done.
val old = SparkSession.activeThreadSession.get()
val old = SparkSession.getActiveSession.get
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unify the entrance of active session.

@ulysses-you ulysses-you changed the title [SPARK-32029][SQL] Check active session if spark context is stop [SPARK-32029][SQL] Check spark context is stoped when get active session Jul 1, 2020
@srowen
Copy link
Member

srowen commented Jul 1, 2020

I don't think anything is meant to work after you shut down the SparkContext?

@ulysses-you
Copy link
Contributor Author

ulysses-you commented Jul 1, 2020

Yes, it won't. But it would be best to do that if we not support it we should check and assert explicitly.

@SparkQA
Copy link

SparkQA commented Jul 1, 2020

Test build #124780 has finished for PR 28868 at commit a3b7d1e.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@ulysses-you
Copy link
Contributor Author

@srowen Does this pr make sense to you ? I'm ok if not necessary.
also cc @xuanyuanking @cloud-fan

}.getMessage
assert(msg.contains("Cannot call methods on a stopped SparkContext."))
val msg2 = intercept[IllegalStateException] {
SparkSession.getActiveSession
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the behavior before this PR? is the session still use-able?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, now we only clear default session, active session is still alive.

@@ -1020,7 +1020,9 @@ object SparkSession extends Logging {
// Return None when running on executors.
None
} else {
Option(activeThreadSession.get)
val session = Option(activeThreadSession.get)
session.foreach(_.sparkContext.assertNotStopped())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's necessary. A user may get the active session instance, and after that someone else stops the spark context. This check can't help this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true. This place only checks if user get an active session, existing used session can not be covered. But in some case which used session.withActive() this can do the help.

@ulysses-you ulysses-you closed this Nov 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants