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

[HWORKS-1416] Close sparks sessions #1370

Merged
merged 6 commits into from
Jul 10, 2024

Conversation

gibchikafa
Copy link
Contributor

This PR adds/fixes/changes...

  • please summarize your changes to the code
  • and make sure to include all changes to user-facing APIs

JIRA Issue: -

Priority for Review: -

Related PRs: -

How Has This Been Tested?

  • Unit Tests
  • Integration Tests
  • Manual Tests on VM

Checklist For The Assigned Reviewer:

- [ ] Checked if merge conflicts with master exist
- [ ] Checked if stylechecks for Java and Python pass
- [ ] Checked if all docstrings were added and/or updated appropriately
- [ ] Ran spellcheck on docstring
- [ ] Checked if guides & concepts need to be updated
- [ ] Checked if naming conventions for parameters and variables were followed
- [ ] Checked if private methods are properly declared and used
- [ ] Checked if hard-to-understand areas of code are commented
- [ ] Checked if tests are effective
- [ ] Built and deployed changes on dev VM and tested manually
- [x] (Checked if all type annotations were added and/or updated appropriately)

suceeded = true;
} finally {
LOGGER.info("Closing spark session...");
engine.closeSparkSession();
Copy link
Contributor

Choose a reason for hiding this comment

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

I would move this code outside the if statement considering that if an exception happens, the job shuts down correctly.
On the other hand, if by any chance the op is not one of those 2s, the if and the finally will be skipped entirely not closing the session.

public void closeSparkSession() {
if (getSparkSession() != null) {
try {
getSparkSession().sparkContext().stop();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are you calling stop() on the spark context and not close() on the Spark session?
The spark context is a "component" of the spark session. You want to close the entire session, not a single component.

Copy link
Contributor

Choose a reason for hiding this comment

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

On the Python side you are correctly closing the session and not just the context.

Comment on lines 1105 to 1107
} catch (Exception e) {
// No-OP
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why catching the exception in the first place? If something happens in the .stop() it would be useful if it shows up in the logs, so I would say we should avoid swallowing the exception.

if spark is not None:
try:
spark.stop()
except Exception as e:
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here.

@SirOibaf SirOibaf enabled auto-merge (squash) July 10, 2024 07:09
@SirOibaf SirOibaf merged commit 8c0d994 into logicalclocks:master Jul 10, 2024
13 checks passed
Sign up for free to 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.

2 participants