[fix](connect) Align COM_RESET_CONNECTION behavior with MySQL#63884
Conversation
COM_RESET_CONNECTION should clear session-scoped state without losing user-level default session settings such as query and insert timeout. Key changes: - Reset session variables, user variables, prepared statements, catalog/database state, running query, and return rows on COM_RESET_CONNECTION. - Reapply user default query_timeout and insert_timeout after rebuilding SessionVariable. - Add a regression helper to send COM_RESET_CONNECTION directly through the MySQL protocol. Unit Test: - ConnectContextTest - test_reset_connection_session_variable
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
|
run buildall |
TPC-H: Total hot run time: 31506 ms |
TPC-DS: Total hot run time: 173055 ms |
FE Regression Coverage ReportIncrement line coverage |
|
run nonConcurrent |
FE Regression Coverage ReportIncrement line coverage |
COM_RESET_CONNECTION should reset per-connection state without clearing the current database, and cleanup failures should be returned to clients instead of silently succeeding. Key changes: - Preserve current catalog and database across reset connection. - Reset user variables, prepared statements, running query state, insert result, temporary tables, and transaction state. - Return autocommit server status on reset OK and MySQL-compatible prepared statement errors. Unit Test: - ConnectContextTest - test_reset_connection_session_variable - FE checkstyle validate
|
Updated the PR to align Changes added in the latest commit:
Validation:
|
|
run buildall |
FE UT Coverage ReportIncrement line coverage |
FE Regression Coverage ReportIncrement line coverage |
|
/review |
There was a problem hiding this comment.
Review opinion: approve/comment only. I did not find blocking correctness issues in the PR scope.
Critical checkpoint conclusions:
- Goal and tests: The change aligns COM_RESET_CONNECTION with the intended behavior by resetting per-connection state, preserving current catalog/database, cleaning prepared/user/session state, and returning reset failures. FE unit tests and a regression test cover the main session-variable and database-preservation path.
- Scope and clarity: The implementation is focused on ConnectContext reset handling, MySQL command handling, and targeted tests.
- Concurrency and locking: No new shared cross-thread state or lock ordering issue was identified. Reset runs in the connection processing path for its own ConnectContext.
- Lifecycle/static initialization: No new static/global initialization dependency was introduced.
- Configuration: No new configuration item was added.
- Compatibility/protocol: The COM_RESET_CONNECTION response and unknown prepared statement error are more MySQL-compatible. No FE-BE protocol or persisted metadata compatibility concern was identified.
- Parallel paths: The MySQL command path and direct ConnectContext reset path were both updated where applicable.
- Conditional checks/error handling: Transaction rollback and temporary table cleanup failures are converted to UserException/DdlException and returned to the client instead of silently succeeding.
- Test coverage: Coverage exists for session variable reset, user defaults, prepared/user state cleanup, insert result cleanup, current DB preservation, OK autocommit status, and reset error propagation. I did not run tests in this review environment.
- Observability: Existing logging around temporary table cleanup remains sufficient for this change.
- Transaction/persistence/data correctness: No persisted metadata format or visible-version path is changed. Reset aborts the active transaction and reports failure if abort fails.
- Performance: No hot-path performance concern was found; work is limited to explicit connection reset.
- User focus: No additional user-provided review focus was present.
morrySnow
left a comment
There was a problem hiding this comment.
Reviewed reset-connection state handling.
| if (ctx.getSessionVariable().autoCommit) { | ||
| ctx.getState().serverStatus |= MysqlServerStatusFlag.SERVER_STATUS_AUTOCOMMIT; | ||
| } |
There was a problem hiding this comment.
这个可能可以不改,因为第一次连接的时候,也没这个 auto commit
There was a problem hiding this comment.
Removed the autocommit server status update from COM_RESET_CONNECTION. Doris currently does not set this flag on the initial OK packet either, so reset now keeps the OK packet status behavior consistent with the existing connection path.
| ctx.clearLastDBOfCatalog(); | ||
| ctx.getState().setOk(); | ||
| try { | ||
| ctx.resetConnection(); |
There was a problem hiding this comment.
resetConnection() clears preparedStatementContextMap, but COM_STMT_RESET still never reads the statement id and handleStmtReset() always returns OK. After a client sends COM_RESET_CONNECTION, mysql_stmt_reset() on one of the old handles should receive an ERR packet because the statement id is no longer valid; with this path it succeeds and the client only sees the failure later on execute. Please parse the stmt id in COM_STMT_RESET and return ERR_UNKNOWN_STMT_HANDLER when ctx.getPreparedStementContext(...) is null, with the message target mysqld_stmt_reset.
There was a problem hiding this comment.
Fixed. COM_STMT_RESET now parses the statement id in the MySQL packet path and returns ERR_UNKNOWN_STMT_HANDLER when the prepared statement context is missing, using mysqld_stmt_reset in the error message.
| preparedQuerys.clear(); | ||
| preparedStatementContextMap.clear(); | ||
| preparedStmtId = Integer.MIN_VALUE; | ||
| runningQuery = null; |
There was a problem hiding this comment.
This clears the textual runningQuery, but leaves queryId from the previous statement. An idle connection that has just been reset can still show the old query id in SHOW PROCESSLIST / connection profile APIs, which is not a fresh-session state. Please clear the current query id as part of reset before returning OK.
There was a problem hiding this comment.
Fixed. resetConnection() now clears the current query id by calling resetQueryId(), so a reset idle connection no longer exposes the previous statement query id in processlist or connection profile APIs.
TPC-H: Total hot run time: 29231 ms |
TPC-DS: Total hot run time: 170124 ms |
Align reset connection handling with Doris' existing MySQL OK packet behavior and make prepared statement reset report cleared statement ids immediately. Key changes: - Do not set autocommit server status in COM_RESET_CONNECTION OK packets - Clear query id during connection reset - Parse COM_STMT_RESET statement id and return unknown statement errors for cleared statements Unit Test: - ConnectContextTest
|
run buildall |
### What problem does this PR solve? Issue Number: close apache#63884 Related PR: apache#63884 Problem Summary: Extend the COM_RESET_CONNECTION regression coverage to verify that reset keeps the current database while restoring session state, clears user variables, and invalidates server-side prepared statements from the previous session state. ### Release note None ### Check List (For Author) - Test: Regression test - Attempted ./run-regression-test.sh --run -d query_p0/session_variable -s test_reset_connection_session_variable, but the local FE mysql port 127.0.0.1:59130 timed out before the case could complete. - Behavior changed: No - Does this need documentation: No
Extend the reset connection regression to cover user variables, processlist state, and server-side prepared statements after COM_RESET_CONNECTION. Key changes: - Send COM_RESET_CONNECTION directly in the regression case. - Verify reset clears user variables, processlist QueryId/Info, and server prepared statement handlers. Unit Test: - ./run-regression-test.sh --run -d query_p0/session_variable -s test_reset_connection_session_variable
|
run buildall |
Use a named constant for the initial prepared statement id and keep temporary table map cleanup scoped to connections that have temporary tables. Key changes: - Add INITIAL_PREPARED_STMT_ID for prepared statement id initialization and reset - Move temporary table map clear into the non-empty cleanup branch Unit Test: - ConnectContextTest
|
run buildall |
1 similar comment
|
run buildall |
FE UT Coverage ReportIncrement line coverage |
FE UT Coverage ReportIncrement line coverage |
|
run buildall |
FE UT Coverage ReportIncrement line coverage |
FE Regression Coverage ReportIncrement line coverage |
TPC-H: Total hot run time: 29284 ms |
TPC-DS: Total hot run time: 168846 ms |
TPC-H: Total hot run time: 29100 ms |
TPC-DS: Total hot run time: 169550 ms |
|
/review |
|
OpenCode automated review failed and did not complete. Error: Review step was skipped (possibly timeout or cancelled) Please inspect the workflow logs and rerun the review after the underlying issue is resolved. |
There was a problem hiding this comment.
Review conclusion: no additional blocking issues found in the current PR diff after accounting for the existing inline review threads.
Critical checkpoint conclusions:
- Goal/test: The PR implements COM_RESET_CONNECTION cleanup for session variables, user variables, prepared statements, temporary tables, transaction state, query identity, trace id, insert result, command, and return rows. Added FE unit tests and a regression test cover the main reset behavior and stale prepared statement handles.
- Scope: The current GitHub PR diff is focused on FE connection reset handling and test support.
- Concurrency/lifecycle: No new shared concurrent state or non-obvious lifecycle issue was found in the reviewed paths. Temporary-table cleanup now snapshots session bookkeeping before dropping tables.
- Configuration/compatibility: No new config items or storage/protocol format changes were introduced. The COM_STMT_RESET/EXECUTE error code change aligns stale server-prepared-statement behavior with unknown statement handler errors.
- Parallel paths: COM_RESET_CONNECTION and COM_STMT_RESET packet paths were reviewed; existing review threads already covered query id, last query id, trace id, statement id monotonicity, and temporary-table cleanup.
- Error handling: Reset failures are converted to query-state errors; no unchecked Status-style omission applies in this Java path.
- Test coverage: Unit and regression coverage exists for session variable reset, user variable clearing, processlist query id cleanup, stale prepared statement execution, reset failure handling, trace id cleanup, and multiple temporary tables. I did not run tests in this review runner.
- Observability/performance: No additional observability or performance concern was identified for this narrow reset path.
User focus: no additional user-provided review focus was specified.
### What problem does this PR solve? `COM_RESET_CONNECTION` was accepted by Doris, but its behavior was not compatible with MySQL. The previous implementation cleared the current catalog/database state and returned OK after only a partial reset. This could make pooled clients, such as C# MySqlConnector with `ConnectionReset=True`, fail later unqualified SQL with `Current database is not set`. Other session-scoped state, including user variables and prepared statements, also needed to be reset consistently. ### What is changed? - Preserve the current catalog/database state across `COM_RESET_CONNECTION` so pooled connections can continue using the selected database. - Reset session variables, user variables, prepared statements, running query state, insert result, command state, and returned row count. - Roll back transaction state during reset and return an error if rollback fails. - Drop temporary tables during reset and return an error if cleanup fails. - Return OK with the autocommit server status when reset succeeds. - Return the MySQL-compatible unknown prepared statement error when executing a statement cleared by reset. - Extend regression and FE unit coverage for reset behavior, error handling, and current database preservation.
### What problem does this PR solve? `COM_RESET_CONNECTION` was accepted by Doris, but its behavior was not compatible with MySQL. The previous implementation cleared the current catalog/database state and returned OK after only a partial reset. This could make pooled clients, such as C# MySqlConnector with `ConnectionReset=True`, fail later unqualified SQL with `Current database is not set`. Other session-scoped state, including user variables and prepared statements, also needed to be reset consistently. ### What is changed? - Preserve the current catalog/database state across `COM_RESET_CONNECTION` so pooled connections can continue using the selected database. - Reset session variables, user variables, prepared statements, running query state, insert result, command state, and returned row count. - Roll back transaction state during reset and return an error if rollback fails. - Drop temporary tables during reset and return an error if cleanup fails. - Return OK with the autocommit server status when reset succeeds. - Return the MySQL-compatible unknown prepared statement error when executing a statement cleared by reset. - Extend regression and FE unit coverage for reset behavior, error handling, and current database preservation.
### What problem does this PR solve? `COM_RESET_CONNECTION` was accepted by Doris, but its behavior was not compatible with MySQL. The previous implementation cleared the current catalog/database state and returned OK after only a partial reset. This could make pooled clients, such as C# MySqlConnector with `ConnectionReset=True`, fail later unqualified SQL with `Current database is not set`. Other session-scoped state, including user variables and prepared statements, also needed to be reset consistently. ### What is changed? - Preserve the current catalog/database state across `COM_RESET_CONNECTION` so pooled connections can continue using the selected database. - Reset session variables, user variables, prepared statements, running query state, insert result, command state, and returned row count. - Roll back transaction state during reset and return an error if rollback fails. - Drop temporary tables during reset and return an error if cleanup fails. - Return OK with the autocommit server status when reset succeeds. - Return the MySQL-compatible unknown prepared statement error when executing a statement cleared by reset. - Extend regression and FE unit coverage for reset behavior, error handling, and current database preservation.
### What problem does this PR solve? Issue Number: close apache#63884 Related PR: apache#63884 Problem Summary: Extend the COM_RESET_CONNECTION regression coverage to verify that reset keeps the current database while restoring session state, clears user variables, and invalidates server-side prepared statements from the previous session state. ### Release note None ### Check List (For Author) - Test: Regression test - Attempted ./run-regression-test.sh --run -d query_p0/session_variable -s test_reset_connection_session_variable, but the local FE mysql port 127.0.0.1:59130 timed out before the case could complete. - Behavior changed: No - Does this need documentation: No
Backporting PR apache#63884 to branch-4.1 leaves ConnectContextTest incompatible with the branch's existing test setup. The new reset-connection cases need local Mockito mocks for catalog-related dependencies, and the env stubs must be set before ConnectContext.setEnv() initializes the default catalog. Key changes: - add missing Mockito and catalog imports used by the new reset-connection tests - use local Mockito mocks in reset-connection test cases instead of class-level JMockit mocks - stub internal catalog access before calling ConnectContext.setEnv() in the new tests Unit Test: - run-fe-ut.sh --run ConnectContextTest
What problem does this PR solve?
COM_RESET_CONNECTIONwas accepted by Doris, but its behavior was not compatible with MySQL. The previous implementation cleared the current catalog/database state and returned OK after only a partial reset. This could make pooled clients, such as C# MySqlConnector withConnectionReset=True, fail later unqualified SQL withCurrent database is not set. Other session-scoped state, including user variables and prepared statements, also needed to be reset consistently.What is changed?
COM_RESET_CONNECTIONso pooled connections can continue using the selected database.Check List
tools/fast-compile-fe.shtools/fast-compile-fe.sh --test ConnectContextTest.javarun-fe-ut.sh --run ConnectContextTestmvn -f fe/pom.xml -pl fe-core -am validate -DskipTests -Dmaven.build.cache.enabled=falsetest_reset_connection_session_variable