Skip to content

[SPARK-20129][Core] JavaSparkContext should use SparkContext.getOrCreate - #20347

Closed
rekhajoshm wants to merge 11 commits into
apache:masterfrom
rekhajoshm:SPARK-20129
Closed

[SPARK-20129][Core] JavaSparkContext should use SparkContext.getOrCreate#20347
rekhajoshm wants to merge 11 commits into
apache:masterfrom
rekhajoshm:SPARK-20129

Conversation

@rekhajoshm

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Using SparkContext getOrCreate() instead of recreating new sc in JavaSparkContext.

How was this patch tested?

Existing tests

@SparkQA

Copy link
Copy Markdown

Test build #86456 has finished for PR 20347 at commit b1ae512.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@jerryshao

Copy link
Copy Markdown
Contributor

Can you please explain why do we need to change to getOrCreate?

@srowen

Copy link
Copy Markdown
Member

@mengxr suggested this in the JIRA originally -- what was the reasoning? It makes some sense, but so does leaving the current behavior, where a constructor calls a constructor. It's a behavior change, albeit a slight one.

@jerryshao

Copy link
Copy Markdown
Contributor

Using getOrCreate in constructor seems change the semantics. Maybe we can add a new static method for such usage in JavaSparkContext.

@srowen

Copy link
Copy Markdown
Member

Yes, you can already get the new semantics here with new JavaSparkContext(SparkContext.getOrCreate()).

Yes, probably better to add a new method, or else, decide that it's not worth a new API method just as a shortcut for the above. Maybe that's the right conclusion, unless @mengxr comes back with a particular reason to change the behavior slightly.

@jiangxb1987

Copy link
Copy Markdown
Contributor

My major concern is that, if there is a existing SparkContext, some confs you set may not take effect, as described in SparkContext.getOrCreate(). It's hard to enumerate the use cases but I'm sure there are some that pass in specific confs to create a new JavaSparkContext, so I tend to keep the current behavior here.

On the other hand, the following comment copyed from the comment of the class JavaSparkContext:

 * Only one SparkContext may be active per JVM. You must `stop()` the active SparkContext before
* creating a new one. This limitation may eventually be removed; see SPARK-2243 for more details.

If that is the case, there should be no active SparkContext before we initiate the JavaSparkContext, so the change doesn't bring any advantage in that means.

@srowen

Copy link
Copy Markdown
Member

@rekhajoshm I think maybe the right resolution here is to do nothing. I haven't heard @mengxr on his old JIRA to make this change. Thank you for chasing down open JIRAs like this of course.

@rekhajoshm

Copy link
Copy Markdown
ContributorAuthor

Thank you @srowen I admire you for doing what you do over all the jira/PR's I have studied, and followed up.
If its ok, will keep this PR open for few days, and close if jira is getting to 'Not an issue'/'Won't fix' state.thanks.

@srowensrowen mentioned this pull request May 11, 2018
zifeif2 pushed a commit to zifeif2/spark that referenced this pull request Nov 22, 2025
Closesapache#20458Closesapache#20530Closesapache#20557Closesapache#20966Closesapache#20857Closesapache#19694Closesapache#18227Closesapache#20683Closesapache#20881Closesapache#20347Closesapache#20825Closesapache#20078Closesapache#21281Closesapache#19951Closesapache#20905Closesapache#20635
Author: Sean Owen <srowen@gmail.com>
Closesapache#21303 from srowen/ClosePRs.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@rekhajoshm@SparkQA@jerryshao@srowen@jiangxb1987