-
Notifications
You must be signed in to change notification settings - Fork 985
[KYUUBI #3885][FOLLOWUP] Fix memory leak when using incremental collect mode in JDBC engine #5161
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
Conversation
| if (incrementalCollect) { | ||
| info("Execute in incremental collect mode") | ||
| new IterableFetchIterator(resultSetWrapper.toIterable) | ||
| new IterableFetchIterator[Row](new Iterable[Row] { |
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.
This will cause the resultSet to be fetched lazily, so we can not close the statement in the finally block.
Lines 91 to 94 in 938384c
| } finally { | |
| if (jdbcStatement != null) { | |
| jdbcStatement.closeOnCompletion() | |
| } |
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.
Thanks for the hint. It might be the cause for the failure of closing statement too early. (https://github.com/apache/kyuubi/actions/runs/5857069896/job/15886592243#step:7:292)
Let me reopen this PR to have another try.
…losing statemnt too early
Codecov Report
@@ Coverage Diff @@
## master #5161 +/- ##
======================================
Coverage 0.00% 0.00%
======================================
Files 566 566
Lines 31624 31699 +75
Branches 4122 4134 +12
======================================
- Misses 31624 31699 +75 see 19 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
|
I may need a hand in this, for early closed result set and unset operationHandle. cc @zhaomin1423 @wForget ci log: https://github.com/apache/kyuubi/actions/runs/5863404047/job/15896805347?pr=5161#step:7:272 |
|
sql syntax error: |
| private val fetched = new AtomicBoolean(false) | ||
| override def iterator: Iterator[Row] = { | ||
| if (fetched.getAndSet(true)) { | ||
| jdbcStatement.synchronized { |
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.
we need to re-execute the statement when resetPosition is called
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.
Would re-execution be a possible problem? For example, insert is executed twice.
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.
For update statement hasResult should be false.
| private lazy val metadata = currentResult.getMetaData | ||
|
|
||
| override def hasNext: Boolean = { | ||
| if (currentResult.isClosed) return false |
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.
FetchResult may be called again when the previous resultSet has ended, so we need to determine whether the resultSet has been closed.
kyuubi/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiQueryResultSet.java
Line 328 in f05aefb
| if (fetchedRows == null || !fetchedRowsItr.hasNext()) { |
| private val fetched = new AtomicBoolean(false) | ||
| override def iterator: Iterator[Row] = { | ||
| if (fetched.getAndSet(true)) { | ||
| jdbcStatement.synchronized { |
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.
Would re-execution be a possible problem? For example, insert is executed twice.
… JDBC engine ### _Why are the changes needed?_ Similar to #3885, there is also memory leak in the jdbc engine when using incremental collect mode. Duplicate of #5161 ### _How was this patch tested?_ - [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible - [ ] Add screenshots for manual tests if appropriate - [ ] [Run test](https://kyuubi.readthedocs.io/en/master/contributing/code/testing.html#running-tests) locally before make a pull request ### _Was this patch authored or co-authored using generative AI tooling?_ No Closes #5570 from wForget/hotfix. Closes #5570 dbeddc9 [wforget] comment 0c4e499 [wforget] fix b7c421a [wforget] fix 0ef21ce [wforget] fix f5f2e80 [wforget] Fix memory leak when using incremental collect mode in JDBC engine Authored-by: wforget <643348094@qq.com> Signed-off-by: Cheng Pan <chengpan@apache.org>
… JDBC engine ### _Why are the changes needed?_ Similar to #3885, there is also memory leak in the jdbc engine when using incremental collect mode. Duplicate of #5161 ### _How was this patch tested?_ - [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible - [ ] Add screenshots for manual tests if appropriate - [ ] [Run test](https://kyuubi.readthedocs.io/en/master/contributing/code/testing.html#running-tests) locally before make a pull request ### _Was this patch authored or co-authored using generative AI tooling?_ No Closes #5570 from wForget/hotfix. Closes #5570 dbeddc9 [wforget] comment 0c4e499 [wforget] fix b7c421a [wforget] fix 0ef21ce [wforget] fix f5f2e80 [wforget] Fix memory leak when using incremental collect mode in JDBC engine Authored-by: wforget <643348094@qq.com> Signed-off-by: Cheng Pan <chengpan@apache.org> (cherry picked from commit 0a0088b) Signed-off-by: Cheng Pan <chengpan@apache.org>
|
Closing this PR, as #5570 is merged for fixing the same issue. |
…ode in JDBC engine ### _Why are the changes needed?_ Similar to apache#3885, there is also memory leak in the jdbc engine when using incremental collect mode. Duplicate of apache#5161 ### _How was this patch tested?_ - [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible - [ ] Add screenshots for manual tests if appropriate - [ ] [Run test](https://kyuubi.readthedocs.io/en/master/contributing/code/testing.html#running-tests) locally before make a pull request ### _Was this patch authored or co-authored using generative AI tooling?_ No Closes apache#5570 from wForget/hotfix. Closes apache#5570 dbeddc9 [wforget] comment 0c4e499 [wforget] fix b7c421a [wforget] fix 0ef21ce [wforget] fix f5f2e80 [wforget] Fix memory leak when using incremental collect mode in JDBC engine Authored-by: wforget <643348094@qq.com> Signed-off-by: Cheng Pan <chengpan@apache.org>
Why are the changes needed?
toIterablecreates a stream byStream.cons(self.next(), self.toStream)which holds iterated rows of resultset in JDBC engineHow was this patch tested?
Add some test cases that check the changes thoroughly including negative and positive cases if possible
Add screenshots for manual tests if appropriate
Run test locally before make a pull request