Skip to content

Conversation

@bowenliang123
Copy link
Contributor

Why are the changes needed?

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 locally before make a pull request

@bowenliang123 bowenliang123 marked this pull request as draft August 14, 2023 14:34
@bowenliang123 bowenliang123 deleted the jdbc-incr branch August 15, 2023 00:49
if (incrementalCollect) {
info("Execute in incremental collect mode")
new IterableFetchIterator(resultSetWrapper.toIterable)
new IterableFetchIterator[Row](new Iterable[Row] {
Copy link
Member

@wForget wForget Aug 15, 2023

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.

} finally {
if (jdbcStatement != null) {
jdbcStatement.closeOnCompletion()
}

Copy link
Contributor Author

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.

@bowenliang123 bowenliang123 restored the jdbc-incr branch August 15, 2023 03:02
@bowenliang123 bowenliang123 reopened this Aug 15, 2023
@bowenliang123 bowenliang123 changed the title [KYUUBI #3885] [Followup]Fix memory leak when using incremental collect mode in JDBC engine [WIP][KYUUBI #3885][Followup]Fix memory leak when using incremental collect mode in JDBC engine Aug 15, 2023
@codecov-commenter
Copy link

codecov-commenter commented Aug 15, 2023

Codecov Report

Merging #5161 (df604c5) into master (9dcb61e) will not change coverage.
Report is 9 commits behind head on master.
The diff coverage is n/a.

❗ Current head df604c5 differs from pull request most recent head 74416e9. Consider uploading reports for the commit 74416e9 to get more accurate results

@@          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

@bowenliang123
Copy link
Contributor Author

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

- test fetch orientation with incremental collect mode *** FAILED ***
  org.apache.thrift.protocol.TProtocolException: Required field 'operationHandle' is unset! Struct:TGetOperationStatusReq(operationHandle:null)
  at org.apache.hive.service.rpc.thrift.TGetOperationStatusReq.validate(TGetOperationStatusReq.java:373)
  at org.apache.hive.service.rpc.thrift.TCLIService$GetOperationStatus_args.validate(TCLIService.java:12851)
  at org.apache.hive.service.rpc.thrift.TCLIService$GetOperationStatus_args$GetOperationStatus_argsStandardScheme.write(TCLIService.java:12908)
  at org.apache.hive.service.rpc.thrift.TCLIService$GetOperationStatus_args$GetOperationStatus_argsStandardScheme.write(TCLIService.java:12877)
  at org.apache.hive.service.rpc.thrift.TCLIService$GetOperationStatus_args.write(TCLIService.java:12828)
  at org.apache.thrift.TServiceClient.sendBase(TServiceClient.java:71)
  at org.apache.thrift.TServiceClient.sendBase(TServiceClient.java:62)
  at org.apache.hive.service.rpc.thrift.TCLIService$Client.send_GetOperationStatus(TCLIService.java:469)
  at org.apache.hive.service.rpc.thrift.TCLIService$Client.GetOperationStatus(TCLIService.java:461)
  at org.apache.kyuubi.operation.HiveJDBCTestHelper.waitForOperationToComplete(HiveJDBCTestHelper.scala:128)
  ...
OperationWithPhoenixEngineSuite:
- phoenix - get tables *** FAILED ***
  org.apache.kyuubi.jdbc.hive.KyuubiSQLException: ResultSet closed
  at org.apache.kyuubi.jdbc.hive.Utils.verifySuccess(Utils.java:90)
  at org.apache.kyuubi.jdbc.hive.Utils.verifySuccessWithInfo(Utils.java:76)
  at org.apache.kyuubi.jdbc.hive.KyuubiQueryResultSet.next(KyuubiQueryResultSet.java:330)
  at org.apache.kyuubi.engine.jdbc.phoenix.PhoenixOperationSuite.$anonfun$new$2(PhoenixOperationSuite.scala:35)
  at org.apache.kyuubi.engine.jdbc.phoenix.PhoenixOperationSuite.$anonfun$new$2$adapted(PhoenixOperationSuite.scala:30)
  at org.apache.kyuubi.operation.JDBCTestHelper.$anonfun$withMultipleConnectionJdbcStatement$4(JDBCTestHelper.scala:61)
  at org.apache.kyuubi.operation.JDBCTestHelper.$anonfun$withMultipleConnectionJdbcStatement$4$adapted(JDBCTestHelper.scala:61)
  at scala.collection.mutable.ResizableArray.foreach(ResizableArray.scala:62)
  at scala.collection.mutable.ResizableArray.foreach$(ResizableArray.scala:55)
  at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:49)
  ...

@wForget
Copy link
Member

wForget commented Aug 16, 2023

sql syntax error:

09:49:40.433 JdbcTBinaryFrontendHandler-Pool: Thread-87 INFO ExecuteStatement: Processing runner's query[4bda9ddb-e5f3-4a75-ae3f-6726949eedfe]: PENDING_STATE -> RUNNING_STATE, statement:
select e1 from (select 1 k1) as t lateral view explode([0,1]) tmp1 as e1
09:49:40.458 JdbcTBinaryFrontendHandler-Pool: Thread-87 ERROR ExecuteStatement: Error operating ExecuteStatement: java.sql.SQLException: errCode = 2, detailMessage = Syntax error in line 1:
...as t lateral view explode([0,1]) tmp1 as e1
                             ^
Encountered: [
Expected: IDENTIFIER

	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
	at com.mysql.cj.jdbc.StatementImpl.executeInternal(StatementImpl.java:763)
	at com.mysql.cj.jdbc.StatementImpl.execute(StatementImpl.java:648)
	at org.apache.kyuubi.engine.jdbc.operation.ExecuteStatement.org$apache$kyuubi$engine$jdbc$operation$ExecuteStatement$$executeStatement(ExecuteStatement.scala:64)
	at org.apache.kyuubi.engine.jdbc.operation.ExecuteStatement.runInternal(ExecuteStatement.scala:55)
	at org.apache.kyuubi.operation.AbstractOperation.run(AbstractOperation.scala:171)
	at org.apache.kyuubi.session.AbstractSession.runOperation(AbstractSession.scala:101)
	at org.apache.kyuubi.session.AbstractSession.$anonfun$executeStatement$1(AbstractSession.scala:131)
	at org.apache.kyuubi.session.AbstractSession.withAcquireRelease(AbstractSession.scala:82)
	at org.apache.kyuubi.session.AbstractSession.executeStatement(AbstractSession.scala:128)
	at org.apache.kyuubi.service.AbstractBackendService.executeStatement(AbstractBackendService.scala:67)
	at org.apache.kyuubi.service.TFrontendService.ExecuteStatement(TFrontendService.scala:252)
	at org.apache.hive.service.rpc.thrift.TCLIService$Processor$ExecuteStatement.getResult(TCLIService.java:1557)
	at org.apache.hive.service.rpc.thrift.TCLIService$Processor$ExecuteStatement.getResult(TCLIService.java:1542)
	at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:39)
	at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:39)
	at org.apache.kyuubi.service.authentication.TSetIpAddressProcessor.process(TSetIpAddressProcessor.scala:36)
	at org.apache.thrift.server.TThreadPoolServer$WorkerProcess.run(TThreadPoolServer.java:286)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:750)

java.sql.SQLException: errCode = 2, detailMessage = Syntax error in line 1:
...as t lateral view explode([0,1]) tmp1 as e1

private val fetched = new AtomicBoolean(false)
override def iterator: Iterator[Row] = {
if (fetched.getAndSet(true)) {
jdbcStatement.synchronized {
Copy link
Member

@wForget wForget Aug 17, 2023

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

Copy link
Contributor

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.

Copy link
Member

Choose a reason for hiding this comment

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

private lazy val metadata = currentResult.getMetaData

override def hasNext: Boolean = {
if (currentResult.isClosed) return false
Copy link
Member

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.

if (fetchedRows == null || !fetchedRowsItr.hasNext()) {

@wForget wForget marked this pull request as ready for review August 17, 2023 09:59
@wForget wForget changed the title [WIP][KYUUBI #3885][Followup]Fix memory leak when using incremental collect mode in JDBC engine [KYUUBI #3885][Followup]Fix memory leak when using incremental collect mode in JDBC engine Aug 17, 2023
@cxzl25 cxzl25 changed the title [KYUUBI #3885][Followup]Fix memory leak when using incremental collect mode in JDBC engine [KYUUBI #3885][FOLLOWUP] Fix memory leak when using incremental collect mode in JDBC engine Aug 22, 2023
cxzl25
cxzl25 previously approved these changes Aug 22, 2023
private val fetched = new AtomicBoolean(false)
override def iterator: Iterator[Row] = {
if (fetched.getAndSet(true)) {
jdbcStatement.synchronized {
Copy link
Contributor

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.

pan3793 pushed a commit that referenced this pull request Nov 1, 2023
… 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>
pan3793 pushed a commit that referenced this pull request Nov 1, 2023
… 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>
@bowenliang123
Copy link
Contributor Author

Closing this PR, as #5570 is merged for fixing the same issue.

@bowenliang123 bowenliang123 deleted the jdbc-incr branch November 1, 2023 13:52
YesOrNo828 pushed a commit to YesOrNo828/kyuubi that referenced this pull request Nov 6, 2023
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants