-
Notifications
You must be signed in to change notification settings - Fork 220
Remove SparkSession from class to prevent it being included in the serialization process #1460
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
base: master
Are you sure you want to change the base?
Conversation
… from shading configuration.
…terfaces for parameters and return types, and exclude the common connector from shading.
This reverts commit b91527c.
… List interfaces for parameters and return types, and exclude the common connector from shading." This reverts commit b5b296b.
….common` from shading configuration." This reverts commit b5ef154.
Summary of ChangesHello @yalimu-g, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a potential serialization issue within the Spark BigQuery connector's metrics tracking. By marking the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
/gcbrun |
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.
Code Review
This pull request correctly identifies and fixes a serialization issue by marking the SparkSession field as transient in SparkBigQueryReadSessionMetrics. This prevents NotSerializableException since SparkSession is not meant to be serialized. The addition of a serialization test is a great way to verify the fix. I've provided a few suggestions to improve the new test case by using try-with-resources for stream handling to prevent resource leaks and by adding more assertions to make the test more comprehensive.
| java.io.ObjectOutputStream out = new java.io.ObjectOutputStream(bos); | ||
| out.writeObject(metrics); | ||
| out.close(); |
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.
To ensure resources are properly managed and to make the code more robust, it's recommended to use a try-with-resources statement for the ObjectOutputStream. This guarantees that the stream is closed even if an exception is thrown.
| java.io.ObjectOutputStream out = new java.io.ObjectOutputStream(bos); | |
| out.writeObject(metrics); | |
| out.close(); | |
| try (java.io.ObjectOutputStream out = new java.io.ObjectOutputStream(bos)) { | |
| out.writeObject(metrics); | |
| } |
| java.io.ByteArrayInputStream bis = new java.io.ByteArrayInputStream(bos.toByteArray()); | ||
| java.io.ObjectInputStream in = new java.io.ObjectInputStream(bis); | ||
| SparkBigQueryReadSessionMetrics deserializedMetrics = | ||
| (SparkBigQueryReadSessionMetrics) in.readObject(); |
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.
The ObjectInputStream is not being closed, which can lead to resource leaks in other contexts. It's best practice to use a try-with-resources statement to manage the stream's lifecycle automatically, ensuring it's always closed.
| java.io.ByteArrayInputStream bis = new java.io.ByteArrayInputStream(bos.toByteArray()); | |
| java.io.ObjectInputStream in = new java.io.ObjectInputStream(bis); | |
| SparkBigQueryReadSessionMetrics deserializedMetrics = | |
| (SparkBigQueryReadSessionMetrics) in.readObject(); | |
| SparkBigQueryReadSessionMetrics deserializedMetrics; | |
| try (java.io.ByteArrayInputStream bis = new java.io.ByteArrayInputStream(bos.toByteArray()); | |
| java.io.ObjectInputStream in = new java.io.ObjectInputStream(bis)) { | |
| deserializedMetrics = (SparkBigQueryReadSessionMetrics) in.readObject(); | |
| } |
| (SparkBigQueryReadSessionMetrics) in.readObject(); | ||
|
|
||
| assertThat(deserializedMetrics.getNumReadStreams()).isEqualTo(10L); | ||
| assertThat(deserializedMetrics.getBytesRead()).isEqualTo(0); |
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.
To make the test more thorough, it would be good to also assert that the other metric accumulators (rowsRead, parseTime, scanTime) are correctly initialized to 0 after deserialization. This will provide stronger guarantees about the serialization behavior.
assertThat(deserializedMetrics.getBytesRead()).isEqualTo(0);
assertThat(deserializedMetrics.getRowsRead()).isEqualTo(0);
assertThat(deserializedMetrics.getParseTime()).isEqualTo(0);
assertThat(deserializedMetrics.getScanTime()).isEqualTo(0);
...n/src/main/java/com/google/cloud/spark/bigquery/metrics/SparkBigQueryReadSessionMetrics.java
Outdated
Show resolved
Hide resolved
|
/gcbrun |
|
/gcbrun |
No description provided.