Fix JDBC reusing stale statement id after reconnect#18078
Merged
Conversation
After reConnect() refreshes this.sessionId/this.stmtId, the retry lambda in executeSQL/executeQuerySQL/executeUpdateSQL still sends the original TSExecuteStatementReq carrying the OLD ids. The server resolves the session by the current RPC connection (NEW session) but takes the statementId from the request body (OLD), so ClientSession.addQueryId throws "StatementId ... doesn't exist in this session", surfaced as INTERNAL_SERVER_ERROR(305) -- the root cause of recurring query-restart-datanode JDBC test failures. Refresh sessionId and statementId inside each retry lambda, mirroring SessionConnection in the Session SDK, which already does this correctly. executeBatchSQL is refreshed for sessionId for consistency (no statement id).
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #18078 +/- ##
==========================================
Coverage 41.59% 41.60%
Complexity 318 318
==========================================
Files 5294 5294
Lines 371228 371414 +186
Branches 48036 48059 +23
==========================================
+ Hits 154413 154521 +108
- Misses 216815 216893 +78 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Problem
When
IoTDBStatement.reConnect()runs (e.g. a DataNode is restarted mid-query),this.sessionIdandthis.stmtIdare refreshed — but the retry lambda still sends the originally-builtTSExecuteStatementReqcarrying the old session/statement ids.On the server side,
ClientRPCServiceImpl.executeStatementInternalresolves the session from the current RPC connection (getCurrSessionAndUpdateIdleTime()) while taking thestatementIdfrom the request body. After reconnect that yields new-session + old-statement-id, soClientSession.addQueryIdthrows:which is mapped to
INTERNAL_SERVER_ERROR (305). This is the root cause of the recurringquery_restart_dn_show_devJDBC test failures: the test'scheck_log_INTERNAL_SERVER_ERRORgreps the 305s and fails, even though the query results themselves are correct.Fix
Refresh
sessionId(andstatementId) on the request object inside every retry lambda, mirroringSessionConnectionin the Java Session SDK, which already handles this correctly.Affected methods in
IoTDBStatement:executeSQL(executeStatementV2) — sessionId + statementIdexecuteQuerySQL(executeQueryStatementV2) — sessionId + statementIdexecuteUpdateSQL(executeUpdateStatement) — sessionId + statementIdexecuteBatchSQL(executeBatchStatement) — sessionId (batch has no statement id)Verification
mvn spotless:apply -pl iotdb-client/jdbc— cleanmvn compile -pl iotdb-client/jdbc— BUILD SUCCESS