Skip to content

branch-4.0: [fix](connect) Align COM_RESET_CONNECTION behavior with MySQL #63884#64074

Open
yujun777 wants to merge 9 commits into
apache:branch-4.0from
yujun777:pick-pr-64073-4.0
Open

branch-4.0: [fix](connect) Align COM_RESET_CONNECTION behavior with MySQL #63884#64074
yujun777 wants to merge 9 commits into
apache:branch-4.0from
yujun777:pick-pr-64073-4.0

Conversation

@yujun777
Copy link
Copy Markdown
Contributor

@yujun777 yujun777 commented Jun 3, 2026

cherry-pick: #63884

yujun777 added 9 commits June 3, 2026 18:09
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
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
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
### 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
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
COM_RESET_CONNECTION can drop temporary tables through a path that unregisters
them from the current ConnectContext while cleanup is iterating the session
temporary-table map.

Key changes:
- Iterate over a snapshot of temporary table names during reset cleanup.
- Apply the same snapshot iteration to local master cleanup and forwarded cleanup.
- Add FE coverage for resetting a connection with multiple temporary tables.

Unit Test:
- ConnectContextTest
- FE Core validate
COM_RESET_CONNECTION should clear query identity state without reusing server-side prepared statement ids from stale client handles.

Key changes:
- Keep the server prepared statement id counter monotonic across connection reset.
- Clear current and last query ids during connection reset.
- Clear derived trace id state during connection reset.

Unit Test:
- ConnectContextTest covers prepared statement id preservation, query id cleanup, last query id cleanup, and trace id cleanup on reset.
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
@yujun777 yujun777 requested a review from morningman as a code owner June 3, 2026 10:12
@hello-stephen
Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@yujun777
Copy link
Copy Markdown
Contributor Author

yujun777 commented Jun 3, 2026

run buildall

@yujun777 yujun777 changed the title branch-4.0: [fix](connect) Align COM_RESET_CONNECTION behavior with MySQL #64073 branch-4.0: [fix](connect) Align COM_RESET_CONNECTION behavior with MySQL #63884 Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants