Repository navigation
Conversation
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
morrySnow
added a commit
to morrySnow/incubator-doris
that referenced
this pull request
Nov 3, 2026
### What problem does this PR solve? Issue Number: None Related PR: apache#70064 Problem Summary: Move the lifecycle and caller contract into ConnectContext's English class Javadoc, where callers can find the required initialization, activation, operation admission and cleanup APIs. Explain state transitions, registration and close races, thread binding, timeout responsibilities and cleanup completion/failure behavior. Remove the standalone lifecycle design document from the PR. No runtime code changes. ### Release note None ### Check List (For Author) - Test: No need to rerun unit tests for comment-only changes. Verified that all changed Java lines are comments; FE Core Checkstyle and git diff --check passed. - Behavior changed: No. - Does this need documentation: Yes, included as ConnectContext class Javadoc.
morrySnow
added a commit
to morrySnow/incubator-doris
that referenced
this pull request
Nov 3, 2026
### What problem does this PR solve? Issue Number: None Related PR: apache#70064 Problem Summary: The isKilled flag duplicated lifecycle state and could leave a context ACTIVE after self KILL requested termination. MySQL consumed that flag after processing a command, while Flight could keep admitting requests. Self KILL QUERY also took the connection-termination path. Remove isKilled and make lifecycle state the admission authority. Rename the operation counter to inFlightOperations. Route closure through requestClose with immediate or after-response timing: both revoke registration immediately, but deferred closure lets admitted responses finish without cancellation. An immediate request can upgrade a pending deferred close; registration, transport closure and final release each run once across concurrent callers. Migrate MySQL quit/read loops, KILL and workload cancellation checks. Keep self KILL QUERY query-only, and return an empty FlightInfo for self KILL CONNECTION without issuing a DoGet ticket requiring the revoked session. Update the class Javadoc and test response ordering, mode upgrades and cleanup races. ### Release note Complete normal quit and self KILL CONNECTION responses before closing the session. Self KILL QUERY preserves the connection, and Flight self-termination does not return an unusable result ticket. ### Check List (For Author) - Test: Unit tests via run-fe-ut.sh --run: 15 classes, 181 tests passed with zero failures, errors or skipped tests; full script BUILD SUCCESS. FE Core Checkstyle and git diff --check passed. No cluster SQL regression tests run. - Behavior changed: Yes. Session admission uses lifecycle state only, close requests distinguish immediate and after-response closure, and self KILL QUERY no longer closes the connection. - Does this need documentation: Yes, updated ConnectContext class Javadoc.
morrySnow
added a commit
to morrySnow/incubator-doris
that referenced
this pull request
Nov 3, 2026
### What problem does this PR solve? Issue Number: None Related PR: apache#70064 Problem Summary: Four correlated booleans encode sequential teardown progress, making concurrent and reentrant closure harder to reason about. Replace them with a monotonic CleanupPhase while retaining separate admission, close policy and operation lifetime. Name Flight's monitor-guarded deferred-executor sealing state explicitly. Document that MySQL flushes before operation exit, while a synchronous Flight response must be independent of session resources before gRPC serializes it. Clarify independent CloseSession cancellation semantics and test resource-release reentry, deferred handoff, response serialization after cleanup, and CloseSession from a concurrent RPC. ### Release note None ### Check List (For Author) - Test: Unit Test: 15 selected FE classes, 184 tests passed; FE Checkstyle and git diff --check passed - Behavior changed: No; preserve teardown and protocol behavior while simplifying state and clarifying response boundaries - Does this need documentation: Yes; update the English lifecycle and protocol Javadoc in the changed classes
morrySnow
added a commit
to morrySnow/incubator-doris
that referenced
this pull request
Nov 3, 2026
### What problem does this PR solve? Issue Number: None Related PR: apache#70064 Problem Summary: Separate lifecycle, close-mode and cleanup-phase fields make concurrent close ownership harder to maintain. Keep one control value and a resource-user count instead. The unique protocol closer owns an internal reference and returns it in finally; the last reference holder runs final cleanup. Revoke local pool registration under the existing lifecycle-to-pool lock order and preserve immediate and after-response semantics. Derive public lifecycle observations from control and completion, and restore thread-local context before completion callbacks. Document caller responsibilities and verify both ownership handoff orders, reentry, close races and cleanup errors. ### Release note None ### Check List (For Author) - Test: Unit Test: 15 selected FE classes, 199 tests passed; FE Checkstyle and git diff --check passed - Behavior changed: Yes; completion callbacks observe the restored caller context, and executor publication is rejected once final cleanup owns all resources, including after cleanup failure. Client close policies are unchanged. - Does this need documentation: Yes; update the English ConnectContext class Javadoc and pool-unregistration contract in code
morrySnow
added a commit
to morrySnow/incubator-doris
that referenced
this pull request
Nov 5, 2026
### What problem does this PR solve? Issue Number: None Related PR: apache#70064 Problem Summary: Keep one session-owned resource reference from construction until transport closure and let the last session or operation reference perform final cleanup. Remove the unused lifecycle observation enum, completion future, cleanup failure accumulator and close-action record. Release Flight deferred executors after admitted commands exit, removing the separate sealed flag and duplicate teardown path. Tests verify pool admission, response ordering and actual release effects instead of a test-only lifecycle view. Move assertions out of callbacks whose failures cleanup deliberately catches. ### Release note None ### Check List (For Author) - Test - [ ] Regression test - [ ] Unit Test - [x] Manual test (add detailed scripts or steps below) - [ ] No need to test or manual test. Explain why: Checkstyle and git diff --check passed. The selected unit-test build was stopped during dependency compilation so the final validation can include the current upstream Flight changes; no unit-test pass is claimed for this intermediate commit. - Behavior changed: - [ ] No. - [x] Yes. Flight deferred executors are released with other session resources after admitted commands exit. - Does this need documentation? - [ ] No. - [x] Yes. Updated the English ConnectContext and FlightProtocolAdapter class comments. ### Check List (For Reviewer who merge this PR) - [ ] Confirm the release note - [ ] Confirm test cases - [ ] Confirm document - [ ] Add branch pick label
morrySnow
added a commit
to morrySnow/incubator-doris
that referenced
this pull request
Nov 5, 2026
…hemas ### Background ConnectContext coordinates client admission and resource lifetime. Flight prepared statements now validate execution response schemas against the schema advertised during Prepare. ### What problem does this PR solve? Issue Number: None Related PR: apache#70064, apache#69867 PR Type: Refactor Problem Summary: Integrate upstream/master while retaining deferred session cleanup and self-KILL responses. A self KILL CONNECTION response must carry the advertised StatusResult schema while avoiding a DoGet ticket for its revoked session. Also snapshot the volatile executor when reading its timeout to avoid racing the previous command's clear(). ### Details - **Change map:** Integrate upstream/master at 897bb25; resolve the Flight producer response conflict, add prepared self-KILL tests, adapt the new schema fixture to admission/cleanup, and use one local executor snapshot for timeout calculation. The other upstream changes are retained as-is. - **Moves vs. logic changes:** Retain current Flight schema handling and the unified reference-based cleanup; represent self-KILL with its matching status schema and no ticket. - **Behavior change:** Prepared self KILL CONNECTION succeeds without a schema mismatch; self KILL QUERY retains its session and prepared handle. - **Compatibility:** No wire definitions, stored formats or configuration changes. The response header matches Prepare. - **Performance impact:** No new shared state, lock or command-path allocation for timeout calculation. - **Rollback:** Revert the lifecycle PR as a unit; no metadata migration is required. ### Testing - ./run-fe-ut.sh --run with 17 selected lifecycle, protocol, timeout, KILL and schema test classes: 272 tests passed, zero failures/errors/skips; full script BUILD SUCCESS. - mvn -f fe/pom.xml checkstyle:check -pl fe-core: passed. - git diff --cached upstream/master --check: passed. - Verified report totals and source/compiled-class timestamps. No MySQL golden changes. - Cluster regression tests were not run. ### Release note None ### Check List (For Author) - Behavior changed: Yes (see Details). - Does this need documentation: Yes; ownership and caller responsibilities are documented in the English class comments. - Pre-submission status: Partially verified: selected unit tests and style checks passed; cluster regression was not run. ### AI Disclosure - Tool: OpenAI Codex (GPT-6). - Generated: Conflict resolution, tests and this description. - Human review: Pending.
morrySnow
added a commit
to morrySnow/incubator-doris
that referenced
this pull request
Nov 5, 2026
…ership ### Background ConnectContext cleanup used explicit activation, paired operation calls and resource reference counting. MySQL scheduling and Flight's separate command lock also participated in lifetime management. ### What problem does this PR solve? Issue Number: None Related PR: apache#70064 (continuation) PR Type: Refactor Problem Summary: Give each context one execution owner and one ready finalizer. Fixed protocol callbacks now own initialization and requests, while close interruption publishes cleanup only after its synchronous work returns. Capture forwarded cancellation identity so a delayed cancel cannot target a subsequent query or overwrite the statement response. ### Details - **Change map:** Production Java: 421 added / 350 removed lines in 12 files. Tests: 1243 added / 541 removed lines in 13 files. No standalone document or generated file. - **Moves vs. logic changes:** Remove activate, public begin/end pairs and resource reference counting. Share one execution gate across MySQL and Flight. Move MySQL read rearm after response/finally/TLS completion. Document creation, usage, closing and handoff in the English class comment. - **Behavior change:** Closed sessions reject queued work. Immediate close interrupts transport/execution, then hands off final cleanup; deferred close preserves the response and supports immediate upgrade. Reentry cannot repeat cleanup. Forwarded cancellation retains the original query identity and uses its own result for journal waiting. - **Compatibility:** No configuration, wire, journal or stored-format changes. Existing MySQL packet and Flight response expectations remain covered. - **Performance impact:** Remove Flight's duplicate command lock. No additional per-session thread or cleanup executor; admission and handoff use short critical sections. - **Rollback:** Revert this commit; no metadata migration. ### Testing The repository run-fe-ut.sh broad selection exercised 306 tests across 23 classes. A missing token in one new mocked Flight fixture was corrected; the focused lifecycle rerun passed all 33 executions and completed with BUILD SUCCESS. Latest reports for the 23 classes show 306 passing tests, zero failures/errors/skips. All changed Java sources have current compiled classes. FE Checkstyle and git diff --cached upstream/master --check passed. Cluster SQL regression was not run. ### Release note None ### Check List (For Author) - Behavior changed: Yes (see Details). - Does this need documentation: Yes; English ConnectContext class comment updated. - Pre-submission status: Not ready: Draft awaiting human review; selected local unit tests and style checks passed. ### AI Disclosure - Tool: OpenAI Codex (GPT-6). - Generated: Implementation, tests, class comment and description. - Human review: Pending.
### What problem does this PR solve? Issue Number: None Related PR: None Problem Summary: ConnectContext construction, connection registration, thread binding, statement cleanup, and session teardown follow different ownership paths across MySQL, Flight, forwarding, background jobs, and HTTP requests. Document those paths and map concrete cleanup gaps and unverified lifecycle contracts to their triggering scenarios and validation cases. Exclude the obsolete temporary-table session registration mechanism from the findings. ### Release note None ### Check List (For Author) - Test: No need to test runtime behavior (documentation only); validated source links, scenario and issue mappings, Markdown structure, and git diff --check - Behavior changed: No - Does this need documentation: No (this change is the documentation)
### What problem does this PR solve? Issue Number: None Related PR: None Problem Summary: The existing lifecycle inventory mixes protocols, execution phases, ownership, and failure events. Define a four-state ConnectContext lifecycle, separate registration and thread binding from object state, and consolidate the scenarios into client-session and operation-owned templates. Map cleanup defects to shared activation, teardown, and scope mechanisms while preserving protocol-specific and deferred-resource boundaries. ### Release note None ### Check List (For Author) - Test: No need to test runtime behavior (documentation only); validated source links, section ordering, scenario coverage, Markdown fences, and git diff --check - Behavior changed: No - Does this need documentation: No (this change is the documentation)
### What problem does this PR solve? Issue Number: None Related PR: None Problem Summary: The lifecycle refactoring proposal needs explicit ownership of connection registration, deregistration, and Flight timeout handling. Document entry-point triggers, ConnectContext orchestration, connection-pool bookkeeping, and protocol resource boundaries. Distinguish idle-session expiry, query timeout, and deferred-result expiry, including concurrency constraints and migration acceptance tests. ### Release note None ### Check List (For Author) - Test: No need to test runtime behavior (documentation only); validated 38 source anchors, section ordering, existing scenario and issue mappings, Markdown fences, and git diff --check - Behavior changed: No - Does this need documentation: No (this change is the documentation)
### What problem does this PR solve? Issue Number: None Related PR: None Problem Summary: MySQL registration could survive a failed login response because unregistration depended on a channel listener installed after the response. Flight teardown called back into the connection pool, which also owned protocol release and transaction rollback, leaving lifecycle responsibilities split across paths. Coordinate initialization, activation, registration and idempotent closure in ConnectContext. Revoke admission before cancelling commands and closing transport, then release session resources after the existing protocol operations exit. Keep pool bookkeeping separate, preserve the caller's thread context during cleanup, and distinguish idle session expiry from query and deferred-result timeouts. Migrate MySQL and Flight client entry points, cover initialization and response failures and registration/closure races, and update the lifecycle design document. Internal owned/binding scopes and reliable remote cleanup retries remain separate migration work. ### Release note Clean up failed client sessions reliably and defer Flight session buffer release until running commands exit. ### Check List (For Author) - Test: Unit tests via run-fe-ut.sh --run: 9 selected classes, 115 tests passed; full script BUILD SUCCESS. FE Core Checkstyle and git diff --check passed. - Behavior changed: Yes. Client teardown uses one lifecycle, rejects new commands after closure starts, and releases resources after running operations exit. - Does this need documentation: Yes, updated docs/connect-context-lifecycle.md.
### What problem does this PR solve? Issue Number: None Related PR: apache#70064 Problem Summary: Move the lifecycle and caller contract into ConnectContext's English class Javadoc, where callers can find the required initialization, activation, operation admission and cleanup APIs. Explain state transitions, registration and close races, thread binding, timeout responsibilities and cleanup completion/failure behavior. Remove the standalone lifecycle design document from the PR. No runtime code changes. ### Release note None ### Check List (For Author) - Test: No need to rerun unit tests for comment-only changes. Verified that all changed Java lines are comments; FE Core Checkstyle and git diff --check passed. - Behavior changed: No. - Does this need documentation: Yes, included as ConnectContext class Javadoc.
Issue Number: None Related PR: apache#70064 Problem Summary: The isKilled flag duplicated lifecycle state and could leave a context ACTIVE after self KILL requested termination. MySQL consumed that flag after processing a command, while Flight could keep admitting requests. Self KILL QUERY also took the connection-termination path. Remove isKilled and make lifecycle state the admission authority. Rename the operation counter to inFlightOperations. Route closure through requestClose with immediate or after-response timing: both revoke registration immediately, but deferred closure lets admitted responses finish without cancellation. An immediate request can upgrade a pending deferred close; registration, transport closure and final release each run once across concurrent callers. Migrate MySQL quit/read loops, KILL and workload cancellation checks. Keep self KILL QUERY query-only, and return an empty FlightInfo for self KILL CONNECTION without issuing a DoGet ticket requiring the revoked session. Update the class Javadoc and test response ordering, mode upgrades and cleanup races. Complete normal quit and self KILL CONNECTION responses before closing the session. Self KILL QUERY preserves the connection, and Flight self-termination does not return an unusable result ticket. - Test: Unit tests via run-fe-ut.sh --run: 15 classes, 181 tests passed with zero failures, errors or skipped tests; full script BUILD SUCCESS. FE Core Checkstyle and git diff --check passed. No cluster SQL regression tests run. - Behavior changed: Yes. Session admission uses lifecycle state only, close requests distinguish immediate and after-response closure, and self KILL QUERY no longer closes the connection. - Does this need documentation: Yes, updated ConnectContext class Javadoc.
Issue Number: None Related PR: apache#70064 Problem Summary: Four correlated booleans encode sequential teardown progress, making concurrent and reentrant closure harder to reason about. Replace them with a monotonic CleanupPhase while retaining separate admission, close policy and operation lifetime. Name Flight's monitor-guarded deferred-executor sealing state explicitly. Document that MySQL flushes before operation exit, while a synchronous Flight response must be independent of session resources before gRPC serializes it. Clarify independent CloseSession cancellation semantics and test resource-release reentry, deferred handoff, response serialization after cleanup, and CloseSession from a concurrent RPC. None - Test: Unit Test: 15 selected FE classes, 184 tests passed; FE Checkstyle and git diff --check passed - Behavior changed: No; preserve teardown and protocol behavior while simplifying state and clarifying response boundaries - Does this need documentation: Yes; update the English lifecycle and protocol Javadoc in the changed classes
### What problem does this PR solve? Issue Number: None Related PR: apache#70064 Problem Summary: Separate lifecycle, close-mode and cleanup-phase fields make concurrent close ownership harder to maintain. Keep one control value and a resource-user count instead. The unique protocol closer owns an internal reference and returns it in finally; the last reference holder runs final cleanup. Revoke local pool registration under the existing lifecycle-to-pool lock order and preserve immediate and after-response semantics. Derive public lifecycle observations from control and completion, and restore thread-local context before completion callbacks. Document caller responsibilities and verify both ownership handoff orders, reentry, close races and cleanup errors. ### Release note None ### Check List (For Author) - Test: Unit Test: 15 selected FE classes, 199 tests passed; FE Checkstyle and git diff --check passed - Behavior changed: Yes; completion callbacks observe the restored caller context, and executor publication is rejected once final cleanup owns all resources, including after cleanup failure. Client close policies are unchanged. - Does this need documentation: Yes; update the English ConnectContext class Javadoc and pool-unregistration contract in code
### What problem does this PR solve? Issue Number: None Related PR: apache#70064 Problem Summary: Keep one session-owned resource reference from construction until transport closure and let the last session or operation reference perform final cleanup. Remove the unused lifecycle observation enum, completion future, cleanup failure accumulator and close-action record. Release Flight deferred executors after admitted commands exit, removing the separate sealed flag and duplicate teardown path. Tests verify pool admission, response ordering and actual release effects instead of a test-only lifecycle view. Move assertions out of callbacks whose failures cleanup deliberately catches. ### Release note None ### Check List (For Author) - Test - [ ] Regression test - [ ] Unit Test - [x] Manual test (add detailed scripts or steps below) - [ ] No need to test or manual test. Explain why: Checkstyle and git diff --check passed. The selected unit-test build was stopped during dependency compilation so the final validation can include the current upstream Flight changes; no unit-test pass is claimed for this intermediate commit. - Behavior changed: - [ ] No. - [x] Yes. Flight deferred executors are released with other session resources after admitted commands exit. - Does this need documentation? - [ ] No. - [x] Yes. Updated the English ConnectContext and FlightProtocolAdapter class comments. ### Check List (For Reviewer who merge this PR) - [ ] Confirm the release note - [ ] Confirm test cases - [ ] Confirm document - [ ] Add branch pick label
…ership ConnectContext cleanup used explicit activation, paired operation calls and resource reference counting. MySQL scheduling and Flight's separate command lock also participated in lifetime management. Issue Number: None Related PR: apache#70064 (continuation) PR Type: Refactor Problem Summary: Give each context one execution owner and one ready finalizer. Fixed protocol callbacks now own initialization and requests, while close interruption publishes cleanup only after its synchronous work returns. Capture forwarded cancellation identity so a delayed cancel cannot target a subsequent query or overwrite the statement response. - **Change map:** Production Java: 421 added / 350 removed lines in 12 files. Tests: 1243 added / 541 removed lines in 13 files. No standalone document or generated file. - **Moves vs. logic changes:** Remove activate, public begin/end pairs and resource reference counting. Share one execution gate across MySQL and Flight. Move MySQL read rearm after response/finally/TLS completion. Document creation, usage, closing and handoff in the English class comment. - **Behavior change:** Closed sessions reject queued work. Immediate close interrupts transport/execution, then hands off final cleanup; deferred close preserves the response and supports immediate upgrade. Reentry cannot repeat cleanup. Forwarded cancellation retains the original query identity and uses its own result for journal waiting. - **Compatibility:** No configuration, wire, journal or stored-format changes. Existing MySQL packet and Flight response expectations remain covered. - **Performance impact:** Remove Flight's duplicate command lock. No additional per-session thread or cleanup executor; admission and handoff use short critical sections. - **Rollback:** Revert this commit; no metadata migration. The repository run-fe-ut.sh broad selection exercised 306 tests across 23 classes. A missing token in one new mocked Flight fixture was corrected; the focused lifecycle rerun passed all 33 executions and completed with BUILD SUCCESS. Latest reports for the 23 classes show 306 passing tests, zero failures/errors/skips. All changed Java sources have current compiled classes. FE Checkstyle and git diff --cached upstream/master --check passed. Cluster SQL regression was not run. None - Behavior changed: Yes (see Details). - Does this need documentation: Yes; English ConnectContext class comment updated. - Pre-submission status: Not ready: Draft awaiting human review; selected local unit tests and style checks passed. - Tool: OpenAI Codex (GPT-6). - Generated: Implementation, tests, class comment and description. - Human review: Pending.
morrySnow
force-pushed
the
codex/connect-context-lifecycle
branch
from
November 5, 2026 15:53
8a8f18a to
82bfe0f
Compare
### Background Flight SQL returns a FlightInfo ticket before DoGet consumes the local result. Backend results also retain deferred query resources on the frontend. ### What problem does this PR solve? Issue Number: None Related PR: apache#70064 (ConnectContext lifecycle refactor) PR Type: Bugfix Problem Summary: Deferred closure revoked the session token and replaced normal Flight results with an empty StatusResult response. Keep existing tickets usable until their results are consumed or expire, while rejecting new commands and retaining the unique execution owner for cleanup. ### Details - **Change map:** Production Java has 272 added / 120 removed lines across 6 files; tests have 820 added / 45 removed lines across 8 files. Changes cover response admission/readiness, expiry under execution ownership, producer failure cleanup and protocol tests. No generated files or standalone documents are added. - **Frequency:** A Flight request requests AFTER_RESPONSE, such as self KILL CONNECTION, including a following SHOW in the same request. - **Root cause:** GetFlightInfo returning was treated as completion of result delivery, although DoGet still needs the session registration and Arrow buffers. - **Why existing tests missed it:** The earlier self-kill tests asserted zero endpoints and successful serialization instead of consuming a normal result ticket. - **Fix:** Defer unregister and finalizer readiness until response resources are released. Existing result continuations and expiry maintenance share the execution owner, with fixed expiry and immediate-close upgrade support. Preserve normal schema, endpoints and rows; discard results on failed response construction and listener failures. - **Behavior change:** A gracefully closing Flight session retains its pool quota and existing result tickets until consumption or expiry; new commands are rejected. - **Other paths and branches:** Covers ordinary and prepared statements, metadata admission, MySQL handoff, immediate closure and deferred backend query expiry. No wire format, configuration or shared lifecycle flag is added. BE DoGet still has no FE completion callback, so existing query/session deadlines bound retention. ### Testing Local verification on the final source tree (JDK 17): - `bash run-fe-ut.sh --run 'ConnectContextLifecycleTest,ConnectContextFlightDrainTest,ConnectContextTest,ConnectPoolMgrTest,AcceptListenerTest,ReadListenerTest,FlightProtocolAdapterTest,DorisFlightSqlProducerTest,DorisFlightSqlSchemaTest,FlightSqlDeferredQueryIdleTimeoutTest,FlightSessionsInConnectPoolTest,FlightSessionOptionsTest,FlightSqlTableTypesTest,FlightSqlChannelTest,FEOpExecutorCancellationTest,FEOpExecutorMysqlProtocolTest,MasterOpExecutorBackendSelectionTest,MysqlPreparedStatementForwardingTest'`: **245 tests passed across 18 classes**, zero failures, errors or skips. The complete script finished with **BUILD SUCCESS**. Counts were verified against the fresh Surefire XML reports. - Covers real SQL parsing/execution of `KILL CONNECTION <self>; SHOW DATABASES`, normal and prepared self-kill tickets, actual DoGet rows, fixed result expiry, deferred BE query expiry, immediate-close/DoGet handoff, slow cleanup notification, reentry, listener failures and failed response construction. Existing MySQL and forwarded-cancellation checks also pass. - `mvn -f fe/pom.xml checkstyle:check -pl fe-core`: **passed**, zero violations. - `git diff --cached --check`: **passed**. Validated source hashes match the submitted files. - Cluster SQL regression tests were not run. ### Release note Flight SQL preserves the normal result of self KILL CONNECTION and subsequent statements in the same accepted request until the result is consumed or expires. ### Check List (For Author) - Behavior changed: Yes (see Details). - Does this need documentation: No; the existing English lifecycle and protocol class comments are updated. - Pre-submission status: Partially verified: selected local FE tests and Checkstyle pass; cluster SQL regression was not run. Draft PR awaits human review. ### AI Disclosure - Tool: OpenAI Codex (GPT-6). - Generated: Implementation, tests, class comments and this description. - Human review: Pending.
### Background ConnectContext serializes local session admission and execution ownership while MySQL and Flight callbacks can concurrently request closure. User quota and statement timeout properties can block on Auth metadata or directory lookup. ### What problem does this PR solve? Issue Number: None Related PR: apache#70064 (ConnectContext lifecycle refactor) PR Type: Refactor Problem Summary: Property lookup under the lifecycle gate could delay immediate interruption. Move these lookups outside the gate and revalidate the observed statement before timeout cancellation. Remove redundant cancellation copies and audit state, restore independent static Flight metadata handling and preserve pool-slot release after COM_CHANGE_USER. ### Details - **Change map:** Production Java: 103 added / 91 removed lines in 5 files; tests: 219 added / 22 removed lines in 4 files. No generated files or standalone documents. - **Moves vs. logic changes:** Registration accepts a pre-read quota. Timeout lookup checks the same executor and start time after returning. Cancellation shares its read-only request and derives audit IDs from the SQL result. Prepared-query cleanup uses the existing failure boundaries. - **Behavior change:** Slow property reads no longer block connection interruption. Static metadata does not wait for SQL ownership or refresh idle time. Unregistration after a changed user with no quota counter still releases the total slot. - **Compatibility:** No configuration, protocol, persisted format or journal changes. Per-user quota transfer during COM_CHANGE_USER remains unchanged. - **Performance impact:** Shorter lifecycle critical sections and no duplicate cancellation request, address or audit-set state. - **Rollback:** Revert this commit; no migration required. ### Testing - Preset run-fe-ut.sh: 326 tests passed across 24 selected FE classes; zero failures, errors or skips. Complete script BUILD SUCCESS. - Includes blocked Auth lookup interruption, stale timeout revalidation, independent static metadata, changed-user pool release and repeated cancellation tests. - FE Checkstyle: zero violations. git diff --cached --check passed. - No cluster SQL regression run. ### Notes for Reviewers Rechecked the complete PR for scope, redundant state, ownership, lock boundaries, protocol compatibility, exception paths and test coverage after applying the corrections. Remote SQL/cancel arrival ordering and historical changed-user quota transfer remain outside this local lifecycle refactor. ### Release note None ### Check List (For Author) - Behavior changed: Yes (see Details). - Does this need documentation: Yes; the English ConnectContext class contract is updated. - Pre-submission status: Not ready: Draft awaiting human review. Selected unit tests and style passed; cluster regression not run. ### AI Disclosure - Tool: OpenAI Codex (GPT-6). - Generated: Code, tests, class comment and commit description. - Human review: Pending.
### Background ConnectPoolMgr counts each admitted connection against its authenticated user. COM_CHANGE_USER authenticates a replacement identity and selects its default database while keeping the same client connection. ### What problem does this PR solve? Issue Number: None Related PR: apache#70064 (session lifecycle refactor) PR Type: Bugfix Problem Summary: Changing users updated the context identity without moving its connection quota. Disconnect then leaked the original user's count or decremented another user's count, and switching did not enforce the target user's limit. Validate the new namespace privately, then transfer the quota and identity under the existing lifecycle/admission locks. Failed changes preserve the original session. ### Details - **Change map:** production Java: 111 added / 20 removed lines in 3 files; tests: 628 added / 8 removed lines in 3 files. No generated files or standalone documents. - **Frequency:** A connection switches to a different user with COM_CHANGE_USER; a later disconnect leaves the per-user counters inconsistent. Database selection failure could also leave the new identity installed. - **Root cause:** Registration charged the original user, while unregistration looked up the independently mutable current identity. The switch path neither checked nor transferred the target quota and published identity before database validation. - **Why existing tests missed it:** The previous changed-user test only checked global slot release after direct identity mutation. It did not inspect both user counts or exercise a real COM_CHANGE_USER packet and failure response. - **Fix:** Require registered identity changes to use one command-owned entry. A private, always-cleaned context validates namespace and reads target quota outside lifecycle locks using the intended TLS/authentication/catalog context. Commit user counts, identity and namespace while holding the existing close lock order; total quota stays unchanged. Same-user refreshes do not consume another slot. No additional shared lifecycle state or quota-owner map. - **Other paths and branches:** Initial authentication, private contexts and same-user setters remain valid. Reviewed all production identity setters. MySQL and Flight still share pool accounting. Authentication policy, protocol layouts and persistence are unchanged; this commit targets the current master-based PR. ### Testing - Preset run-fe-ut.sh: 373 tests passed across 29 selected FE classes; zero failures, errors or skips. Complete script BUILD SUCCESS. - Covers successful and repeated transfers, existing target-user connections, quota rejection, same-user changes at full quota, competing new admission, both switch/close orderings, property failure, authentication/database failure, namespace/TLS isolation and actual OK/ERR packets followed by a usable old session. - FE Checkstyle: zero violations. git diff --cached --check passed. - No cluster SQL regression run. ### Notes for Reviewers The registered identity remains the quota owner: direct cross-user setter writes are rejected, so no duplicate owner field is needed. A close and quota transfer cannot interleave between count migration and identity commit. Namespace commit uses validated values without catalog IO under the lock. Candidate session variables are independent, while existing authentication and delegated catalog context are preserved for equivalent validation. ### Release note MySQL COM_CHANGE_USER now enforces the target user's connection limit and correctly transfers connection counts. A rejected user change preserves the original identity and namespace. ### Check List (For Author) - Behavior changed: Yes. Successful changes transfer user quota; failed changes leave the original session intact. - Does this need documentation: Yes; the English ConnectContext caller contract documents the registered-user invariant. - Pre-submission status: Not ready: Draft awaiting human review. Selected unit tests and style passed; cluster regression not run. ### AI Disclosure - Tool: OpenAI Codex (GPT-6). - Generated: Code, tests, class comment and commit description. - Human review: Pending.
### Background COM_CHANGE_USER authenticates a new logical session on an existing MySQL connection. ConnectContext owns session resources and the pool tracks the registered user's connection quota. ### What problem does this PR solve? Issue Number: None Related PR: apache#70064 (ConnectContext lifecycle refactor) PR Type: Bugfix Problem Summary: The previous switch path transferred identity and quota without resetting session resources, including when the username was unchanged. Reset before authentication, reload target-user defaults and close rejected changes after sending their error response. ### Details - **Change map:** Production Java has 69 added / 37 removed lines across five files; tests have 323 added / 25 removed lines across two files. No generated files or standalone documents change. - **Frequency:** Every COM_CHANGE_USER with existing session resources or overridden session defaults; same-user requests are affected too. - **Root cause:** User switching was treated as an identity/quota transfer instead of a fresh logical session. The private validation context copied old authentication and session state, and equal usernames bypassed target admission. - **Why existing tests missed it:** Tests checked quota transfer and namespace preservation but did not populate old session resources or assert reset-before-authentication. They incorrectly expected rejected changes to leave the old connection usable. - **Fix:** Reuse resetConnection before authentication. Initialize fresh target-user variables, authentication metadata, compute group and catalog; commit them with quota ownership under the existing locks. Reuse login's default-catalog setup, check same-user admission, and use AFTER_RESPONSE for rejected changes. - **Other paths and branches:** Login and change-user share default-catalog initialization. COM_RESET_CONNECTION retains its namespace behavior. No new lifecycle state, configuration or wire/storage fields are added; no release branch is changed. - **Behavior change:** Same-user requests reset the session and can be refused at the user connection limit. Failed authentication, namespace validation, quota admission or reset sends an error before closing. ### Testing - The repository run-fe-ut.sh script ran 392 tests across 33 lifecycle, pool, MySQL, Flight and forwarded-cancellation classes. One new rollback-error text assertion failed; the remaining 32 classes passed. After correcting the assertion and verifying final-close rollback retry, run-fe-ut.sh --run MysqlConnectProcessorChangeUserTest passed all 13 tests with BUILD SUCCESS. Combined final coverage is 392 distinct tests, zero remaining failures, errors or skips; fresh Surefire reports and source hashes were checked. - Maven Checkstyle passed with zero violations; git diff --cached --check passed. - Cluster SQL regression tests were not run. ### Release note MySQL COM_CHANGE_USER resets existing session state even when the username is unchanged, reloads target-user defaults and enforces its connection limit. Failed changes send an error before closing the connection. ### Check List (For Author) - Behavior changed: Yes (see Details). - Does this need documentation: No; the caller contract is updated in the ConnectContext class comment. - Pre-submission status: Not ready: Draft awaiting human review; cluster SQL regression was not run. ### AI Disclosure - Tool: OpenAI Codex (GPT-6). - Generated: Implementation, tests, class comments and this description. - Human review: Pending.
### Background ConnectContext serializes commands and resource cleanup with one execution owner. Immediate closure must wait for synchronous cancellation to return, while graceful closure must wait for response resources to be released. ### What problem does this PR solve? Issue Number: None Related PR: apache#70064 (ConnectContext lifecycle refactor) PR Type: Refactor Problem Summary: Cleanup used a pending Runnable that moved between a field and local variables through publishing, claiming and execution helpers. Finalizer exit recursively called yieldExecution and inspected already-released protocol resources. Replace the task with a direct ownership handoff and release execution directly after cleanup. ### Details - **Moves vs. logic changes:** Replace pendingFinalizer with cleanupPending, used only when interruption finishes before the current owner exits. The interruption winner either sets that flag or takes idle execution to clean up. A graceful owner atomically claims STOPPING and unregisters while retaining execution, then closes and cleans up directly. Remove claimFinalizerLocked, runFinalizer and finishAfterResponse; keep existing resource-release steps. - **Behavior change:** Public command and response contracts are unchanged. Cleanup no longer reenters yieldExecution or reads protocol state after releasing resources. - **Compatibility:** No configuration, protocol encoding, journal or persisted-format changes. The lifecycle-to-admission lock order is unchanged. - **Performance impact:** Remove Runnable finalizer allocation and post-cleanup response scanning. Interruption and resource release remain outside the locks; no new waits or workers. - **Rollback:** Revert this commit; no metadata migration is needed. ### Testing - run-fe-ut.sh ran 395 tests across 33 classes, including 39 ConnectContext lifecycle cases and 14 Flight drain cases: zero failures, errors or skips; the complete script finished with BUILD SUCCESS. Fresh Surefire XML counts and tested source hashes were verified. - New tests cover immediate closure during the response-readiness check and both close modes avoiding protocol reads after resource release. Existing handoff, reentry, exception, MySQL/Flight response, change-user and forwarding tests pass. - Maven Checkstyle passed with zero violations; git diff --cached --check passed. - Cluster SQL regression tests were not run. ### Release note None ### Check List (For Author) - Behavior changed: Yes (see Details; internal cleanup ordering only). - Does this need documentation: No; the English ConnectContext class comment describes the handoff and caller contract. - Pre-submission status: Not ready: Draft awaiting human review. Cluster SQL regression tests were not run. ### AI Disclosure - Tool: OpenAI Codex (GPT-6). - Generated: Implementation, tests, class comments and this description. - Human review: Pending.
### Background FlightProtocolAdapter resets cached results, deferred executors and endpoint state before the next SQL execution and when a request fails before returning a result ticket. ### What problem does this PR solve? Issue Number: None Related PR: apache#70064 (ConnectContext lifecycle refactor) PR Type: Refactor Problem Summary: The name beginRequest obscured that the same operation also discards failed-request resources. Rename it to resetRequestState and update every call and related comment so its cleanup responsibility is explicit. ### Details - **Moves vs. logic changes:** Rename the existing method and all production/test callers. Update Javadoc, sender comments and the session-lifecycle regression comment. The method body and failure-path cancellation/reset order are unchanged. - **Behavior change:** None. Both ordinary-request failure and prepared-schema mismatch continue to discard unpublished results. - **Compatibility:** Internal Java method rename only; no configuration, wire encoding, journal or persistent-format changes. - **Performance impact:** None; no new allocations, checks, waits or I/O. - **Rollback:** Revert this naming-only commit; no migration is required. ### Testing - run-fe-ut.sh --run 'FlightProtocolAdapterTest,DorisFlightSqlProducerTest,DorisFlightSqlSchemaTest,FlightSqlExecutionSchemaTest,FlightSqlDeferredQueryIdleTimeoutTest,ConnectContextFlightDrainTest': 118 tests across six classes passed, zero failures, errors or skips; the complete script finished with BUILD SUCCESS. Fresh Surefire XML counts and source hashes were checked. - A token comparison of all eight modified files confirms only the identifier rename and comment changes. Existing tests cover failed-request result cleanup and prepared-schema failure cleanup; no new tests were added for the rename. - Maven Checkstyle passed with zero violations; git diff --cached --check passed. - Cluster SQL regression tests were not run; the regression-file change is a comment only. ### Release note None ### Check List (For Author) - Behavior changed: No. - Does this need documentation: No; method and caller comments are updated. - Pre-submission status: Not ready: Draft awaiting human review. Cluster SQL regression was not run. ### AI Disclosure - Tool: OpenAI Codex (GPT-6). - Generated: Rename, comments and this description. - Human review: Pending.
### Background ConnectContext accepts a CloseMode request and retains a private state to coordinate admission, response draining and cleanup. ### What problem does this PR solve? Issue Number: None Related PR: apache#70064 (ConnectContext lifecycle refactor) PR Type: Refactor Problem Summary: CloseIntent included OPEN and STOPPING even though it represented the session's current state. Rename it to SessionState, its field to sessionState and its internal AFTER_RESPONSE value to DRAINING to distinguish state from the public close request. ### Details - **Moves vs. logic changes:** Rename the private enum, field and value throughout ConnectContext. Update the English class contract, transition diagram and enum comments. All other code tokens are unchanged after normalizing these names. - **Behavior change:** None. Public CloseMode remains IMMEDIATE/AFTER_RESPONSE; state transitions, ownership and cleanup are unchanged. Temporary-table handling is unchanged and deferred to a separate follow-up. - **Compatibility:** Private Java identifiers only; no configuration, wire encoding, persisted-format or FE/BE field changes. - **Performance impact:** None. - **Rollback:** Revert this naming-only commit; no migration is required. ### Testing - Local JDK 17: `bash run-fe-ut.sh --run 'ConnectContextLifecycleTest,ConnectContextFlightDrainTest,ConnectContextTest,ConnectSchedulerTest,ConnectContextChangeUserTest,MysqlConnectProcessorChangeUserTest'` passed: 108 tests across 6 classes, zero failures, errors or skips; complete script BUILD SUCCESS. Counts match fresh Surefire XML reports and tested source hashes. - `mvn -f fe/pom.xml checkstyle:check -pl fe-core` passed with zero violations. - `git diff --cached --check` passed. Independent review and normalized code-token comparison confirmed only the approved identifiers and comments changed. - Cluster SQL regression was not run. ### Release note None ### Check List (For Author) - Behavior changed: No. - Does this need documentation: No; class and enum comments are updated. - Pre-submission status: Not ready: Draft awaiting human review. Cluster SQL regression was not run. ### AI Disclosure - Tool: OpenAI Codex (GPT-6). - Generated: Rename, comments and this description. - Human review: Pending.
### Background ConnectContext owns session and statement resources and can be bound to reusable HTTP or background threads. Internal helpers also create private contexts that must restore the caller's binding when they finish. ### What problem does this PR solve? Issue Number: None Related PR: apache#70064 (lifecycle refactor) PR Type: Bugfix Problem Summary: HTTP requests and several background load/planning paths left their context bound after completion. Streaming metadata scopes captured their own context as the parent, and query-id publication could recreate a trace index after unregistration. Close private scopes deterministically, restore borrowed caller bindings, serialize trace publication with close, and finish statement-resource cleanup even when planner release fails. ### Details - **Change map:** Production Java: 362 added / 269 removed lines in 23 files; tests: 1342 added / 0 removed lines in 12 files. Production changes reuse existing scope and cleanup APIs; much of the diff indents existing task bodies inside scopes. - **Frequency:** HTTP and affected background task exits; trace publication requires concurrent immediate close, and statement cleanup requires a resource-close failure. - **Root cause:** Missing scope owners, binding before capturing the parent, publication outside the close gate, and sequential cleanup that stopped after its first error. - **Why existing tests missed it:** Existing tests checked operation results without asserting the worker's TLS, parent ownership or resources retained after failure. - **Fix:** One HTTP dispatch filter; private task scopes; database-only snapshots for async HTTP workers; trace publication under lifecycleLock; final-owner StatementContext cleanup with exception-safe resource release. - **Other paths and branches:** Audited production context creation, bindings and long-lived holders. Cover single/multi-table Stream Load, Group Commit, Broker/Routine Load, cloud Alter/Index jobs, metadata replay, MV cache and connector rewrite. Borrowed contexts and deferred Flight resources retain their owner. No new shared state, configuration or wire/storage format. - **Behavior change:** Completed private scopes release statement resources; immediate closure cannot recreate a removed trace index. No change to MySQL or Flight response encoding. ### Testing - Repository FE UT script: 642 tests passed across 63 selected classes (57 classes in the broad run, then 39 tests in six corrected fixture classes). The targeted rerun completed with BUILD SUCCESS. - Fresh Surefire XML and source hashes verified; production and the other 57 test classes were unchanged between runs. - FE Checkstyle passed with zero violations; git diff --cached --check passed. - Cluster SQL regression tests were not run. ### Release note Fix retained HTTP and background-task contexts and incomplete statement cleanup after resource-release failures. ### Check List (For Author) - Behavior changed: Yes (see Details). - Does this need documentation: No; the English ConnectContext class contract is updated. - Pre-submission status: Partially verified: local unit tests and style checks completed; cluster regression not run. PR remains a draft for human review. ### AI Disclosure - Tool: OpenAI Codex (GPT-6). - Generated: Implementation, tests, comments and this commit description. - Human review: Pending.
### Background AutoCloseConnectContext owns a private context and now requests final cleanup when its scope exits. That cleanup releases statement resources and resets session counters. ### What problem does this PR solve? Issue Number: None Related PR: apache#70064 (context lifecycle refactor) PR Type: Bugfix Problem Summary: StatisticsUtil.execUpdate wrote its audit event after closing the context, so the new deterministic cleanup reset returnRows before the audit consumed it. Write the audit event while the private context is still open and bound, then close the scope on success or failure. Clarify the owning scope contract and correct analysis-test factories that incorrectly wrapped a borrowed parent context. ### Details - **Frequency:** Internal statistics INSERTs that update returnRows and use StatisticsUtil.execUpdate. - **Root cause:** The caller treated close as only statement/TLS cleanup and read session counters afterwards; final cleanup now clears those counters. - **Why existing tests missed it:** No test observed audit counters and scope lifetime together; two analysis fixtures also returned a borrowed context from a factory that creates private contexts in production. - **Fix:** Outer try-with-resources owns the context; the inner finally audits before closing. Audit failures still close the context. No new state or ownership flags are added. - **Other paths and branches:** Audited every production AutoCloseConnectContext construction and factory consumer. Borrowing helpers return no owning scope, private workers create it within their execution, and asynchronous connector cleanup retains its own resources. Returned load plans/results and driver-owned rewrite transactions do not depend on an open scoped context. - **Behavior change:** Statistics update audits retain the actual row count. The scope still requests AFTER_RESPONSE, which is not a barrier for arbitrary asynchronous work. ### Testing - `bash run-fe-ut.sh --run 'StatisticsUpdateContextLifecycleTest,StatisticsUtilTest,AnalyzeTest,AnalysisJobTest,BaseAnalysisTaskTest,OlapAnalysisTaskTest,RewriteSimpleAggToConstantRuleTest,AutoCloseConnectContextTest,StreamLoadContextLifecycleTest,LoadTaskContextLifecycleTest,ConnectorRewriteGroupTaskTest,ConnectorStatementScopeTest,StatementContextCleanupTest'`: **107 tests passed across 13 classes**, zero failures/errors/skips; complete script **BUILD SUCCESS** on the final source tree. Fresh Surefire XML and source hashes were verified. FE Checkstyle and `git diff --cached --check` passed. - Cluster SQL regression was not run. ### Release note Preserve the affected-row count in internal statistics update audit events when the private context is cleaned up. ### Check List (For Author) - Behavior changed: Yes (see Details). - Does this need documentation: No; the English owning-scope contract is updated in code. - Pre-submission status: Partially verified: selected local unit tests and style checks passed; cluster regression was not run. Draft PR awaits human review. ### AI Disclosure - Tool: OpenAI Codex (GPT-6). - Generated: Fix, tests, comments and this description. - Human review: Pending.
### Background Frontend protocols, requests, planning helpers and background jobs all use ConnectContext. Helpers may own a private context or borrow their caller's session, and asynchronous cancellation must not release resources still in use. ### What problem does this PR solve? Issue Number: None Related PR: None PR Type: Bugfix Problem Summary: Some private contexts only lost their thread-local binding or closed their statement, leaving session cleanup without an owner. Failed initialization and unbound HTTP authentication were also outside their cleanup boundary. Assign deterministic cleanup at each owning boundary while preserving borrowed sessions and asynchronous resource ownership. ### Details - **Change map:** This follow-up changes 49 production Java files (+847/-704) and 26 test files (+1615/-224). Production changes mostly establish cleanup boundaries around existing bodies; no generated files or standalone documents are included. - **Frequency:** Internal planning, HTTP requests, forwarded statements and background task exits, including failure, retry and cancellation paths. - **Root cause:** Ownership transfer was implicit in thread-local bindings, and several callers restored or dropped references without closing the created context. Streaming cancellation could release execution resources on a different thread. - **Why existing tests missed it:** Tests mostly asserted results or restored thread bindings, without observing context/statement release or the ownership of resources after failure and cancellation. - **Fix:** Close private scopes and failed factories; make MTMV/Insert factories transfer unbound ownership; use callback-scoped temporary Cascades contexts; track HTTP dispatch-owned contexts before binding; finalize streaming attempts on their execution thread. Proxy cleanup preserves the originating transaction/session and response packets. Remove an unused context and the session-variable dummy sentinel. Cover Flight admission failure before its command body. - **Other paths and branches:** Audit every production context constructor/factory and its callers. Borrowed sessions remain owned by their protocol/task. No new lifecycle flags, locks, wire fields or persisted data. ### Testing Local verification used JDK 17 and the repository's `run-fe-ut.sh` entry point: - Broad run with 100 selected FE test classes: **1097 tests passed**, zero failures, errors or skips; the complete script finished with **BUILD SUCCESS**. Coverage includes MySQL/Flight admission, response completion and cancellation; ConnectContext ownership and change-user; HTTP/RPC boundaries; Stream/Broker/Routine Load; cloud/background/streaming tasks; planning/MTMV; statistics and connector resource cleanup. - Final targeted run: `bash run-fe-ut.sh --run 'RefreshMTMVCommandTest,MTMVContextLifecycleTest,ExternalCatalogNamespaceFailureTest'`: **36 tests passed across 3 classes**, zero failures, errors or skips; complete script **BUILD SUCCESS**. This verifies the final refresh factory implementation and updated explicit-ownership test callers. - Fresh Surefire XML counts match both run logs. Source hashes confirm that the other production/test changes are unchanged from the broad run and that the final tested tree matches the staged files. Combined latest results remain **1097 passing tests across 100 classes**. - FE Checkstyle (`mvn -f fe/pom.xml checkstyle:check -pl fe-core`) and `git diff --cached --check`: passed. - Cluster SQL regression tests were not run. ### Release note HTTP, forwarded and internal background work explicitly release private session resources on completion and failure; streaming cancellation leaves final resource release to the execution thread. ### Check List (For Author) - Behavior changed: Yes (see Details). - Does this need documentation: No; caller ownership is documented in the class and helper comments. - Pre-submission status: Not ready: Existing draft PR awaits human review; cluster regression was not run. ### AI Disclosure - Tool: OpenAI Codex (GPT-6). - Generated: Implementation, tests, comments and this description. - Human review: Pending.
### Background Synchronous helpers can use their caller's execution context, while parameter-only helpers do not need a session. Independent SQL and background execution still need explicit session ownership. ### What problem does this PR solve? Issue Number: None Related PR: None PR Type: Refactor Problem Summary: Several helpers created a ConnectContext only to obtain defaults, copy a request or wrap an already owned load task. Remove eight redundant construction sites, reduce view metadata to one context per request and keep statement-only isolation local. ### Details - **Change map:** 18 production Java files, +168/-232; 11 test files, +465/-71. No generated files or standalone documentation. - **Moves vs. logic changes:** Pass the current executor and compute group directly; pass the task context through the load coordinator chain. Remove redundant cloud/HTTP contexts and duplicate Flight/MV TLS management. Keep private contexts for independent identity, settings and SQL execution. - **Behavior change:** Group Commit block rules and audit use the current SQL, user and planner. HTTP Group Commit uses request settings; auto-start without a context or explicit cluster returns no selection. View collection closes statement resources per view without replacing the borrowed statement. - **Compatibility:** Internal Java call sites migrate together. No protocol, journal, stored format or configuration changes. - **Performance impact:** Direct construction sites fall from 46 to 38. A metadata request creates at most one context only when a view needs parsing. No new lifecycle state or executor. - **Rollback:** Revert this commit; no metadata migration. ### Testing Combined final results: 316 tests passed across 28 FE classes. The initial run passed 27 classes and found two exception-format assertion errors in LoadActionTest. After correcting those test assertions, the repository run-fe-ut.sh script passed all 26 LoadActionTest cases and completed with BUILD SUCCESS. FE Checkstyle and staged diff checks passed. Cluster regression tests were not run. ### Notes for Reviewers Private execution/identity contexts remain owned by their scope. Synchronous borrowing does not transfer cleanup responsibility. The broader audit found pre-existing MysqlLoad reader, InsertTask cancellation and queryId lookup races; these are documented in the draft PR and not modified here. ### Release note Group Commit planning uses the active statement's user and SQL for block-rule checks and its planner for audit information. ### Check List (For Author) - Behavior changed: Yes (see Details). - Does this need documentation: Yes; ConnectContext's English class comment explains when to create or borrow a context. - Pre-submission status: Not ready: Draft, awaiting human review; broader audit findings are documented and cluster regression is unrun. ### AI Disclosure - Tool: OpenAI Codex (GPT-6). - Generated: Implementation, tests, class comments and PR description. - Human review: Pending.
### Background Internal helpers sometimes create a SQL session only to supply metadata parameters. ConnectContext also carries analysis, execution, response and session data with different lifetimes. ### What problem does this PR solve? Issue Number: None Related PR: apache#70064 (ConnectContext lifecycle refactor) PR Type: Refactor Problem Summary: Remove unnecessary helper sessions and keep result payloads and observer options with their actual owners. Review all 68 instance fields, remove unused storage, and reset the Group Commit decision at the SQL statement boundary for both protocols. ### Details - **Change map:** Production Java: 22 files, +233/-270; FE tests: 16 files, +1117/-86. No generated files or standalone documentation. - **Moves vs. logic changes:** Seven direct production constructor sites disappear. Metadata RPCs accept explicit fields; workload-group resolution takes owner and group inputs. FileScan expression translation and constant Round precision avoid temporary sessions. Stream Load uses its handler-owned context instead of a redundant cloud planner subclass. Result attachments move to the existing StmtExecutor; processlist readers own their immutable full-SQL option. Four unused context fields/accessors are removed. - **Behavior change:** Result attachments no longer accumulate across commands. Processlist readers cannot overwrite each other's display option. Each text SQL statement, including Flight requests and multi-statement packets, recomputes its Group Commit decision; binary MySQL requests retain their existing reset. DoGet and HTTP stream planning preserve their execution boundaries. - **Compatibility:** No wire, configuration, journal or stored-format change. Metadata timeout, retry and replay behavior remain the same. Workload-group access context stays NONE; the existing cloud-policy path retains its caller-thread authorization context. Internal Java helpers and all callers change together. - **Performance impact:** Context creation sites drop from 38 to 31 and instance fields from 68 to 62. Explicit default-value getters avoid session-variable cloning. No new registry, lifecycle flag, lock order or context container; no throughput benchmark performed. - **Rollback:** Revert this commit; no metadata migration is needed. ### Testing Local JDK 17 verification used the repository's `run-fe-ut.sh` entry point. - **416 tests across 38 selected FE classes passed**, with zero failures, errors or skips in the combined final results. - The first 31-class run exposed seven test-fixture/expectation issues: an old authorization mock missed the new explicit entry point, exception assertions omitted existing Doris wrapping, and two new test setups initialized mocks in the wrong order. Only five test files changed to correct them. The follow-up 12-class run passed all **176 tests** and the complete script finished with **BUILD SUCCESS**; the other 26 classes passed in the first run. - New tests cover explicit workload-group identity/defaults/authorization, metadata RPC fields/timeouts/retries/pool cleanup/journal waits, zero context construction in value-only paths, shared Stream Load planning ownership, independent processlist display options, and two real consecutive SQL executions with isolated result attachments. - Flight tests exercise real parsing, SET execution and Group Commit analysis across successive requests, failure, and a single multi-statement request. Existing Flight schema/options, MySQL prepared/forward/retry/cleanup and session-lifecycle tests also pass. - FE Checkstyle and `git diff --cached --check` passed. Surefire XML totals match the run logs; staged/source hashes match the final verification snapshot. No cluster SQL regression tests were run. ### Notes for Reviewers Read ConnectContext's State ownership class comment and the complete field inventory in PR apache#70064. Session identity, namespace, variables, transactions, prepared statements, temporary tables and history remain session-owned. Existing analysis and protocol scopes retain their owners. ### Release note Long-lived sessions no longer retain result attachments from previous commands. Concurrent processlist readers preserve their individual full-SQL display choices. Flight and multi-statement SQL recompute the Group Commit decision for each statement. ### Check List (For Author) - Behavior changed: Yes (see Details). - Does this need documentation: Yes; updated English class comment and the PR's field ownership inventory. - Pre-submission status: Draft; selected FE tests and Checkstyle verified. Cluster regression not run. ### AI Disclosure - Tool: OpenAI Codex (GPT-6). - Generated: Implementation, tests, class comments and this description. - Human review: Pending.
### Background ConnectContext is used by protocol sessions, private tasks and analysis helpers. Reviewing its ownership requires both the callers' business intent and the actual state each method accesses. ### What problem does this PR solve? Issue Number: None Related PR: apache#70064 (lifecycle refactor under review) PR Type: Build/CI/Chore Problem Summary: Add the requested production usage inventory for human review. It records construction, borrowing, retained references and cleanup responsibility, with a complete per-method index at a fixed source revision. This commit changes documentation only. ### Details - **Change map:** One document with 12235 lines; zero production, test or generated-code changes. - **Affected:** docs/connect-context-usage-review.md covers 899 production files, 2559 method/member entries and 31 direct constructions. - **Developer and release impact:** Review aid only; no runtime or build behavior changes. Ownership questions are labeled separately from confirmed facts. - **License and third-party:** Apache license header; no dependency or third-party code added. - **Rollback:** Remove the inventory document. ### Testing Cross-checked Java AST references with compiled call, field and method-reference metadata. Validated all 8208 indexed operations, 31 direct constructions, 3805 fixed-source links, 2797 unique anchors and Markdown table structure. Whitespace validation passed. No kernel tests were rerun for this documentation-only commit. ### Release note None ### Check List (For Author) - Behavior changed: No - Does this need documentation: Yes; this commit is the requested review document. - Pre-submission status: Not ready: Draft, awaiting human review. ### AI Disclosure - Tool: Codex, GPT-6 - Generated: Usage inventory and this commit description. - Human review: Pending.
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.
Background
ConnectContext holds a frontend session's query, transaction and protocol resources. MySQL and Flight share ConnectPoolMgr registration, quotas and timeout scanning. Internal jobs and HTTP requests also create contexts, while helpers sometimes borrow an existing session.
What problem does this PR solve?
Issue Number: None
Related PR: #69867 (prepared Flight response schema integration)
PR Type: Refactor
Problem Summary:
Registration, execution and cleanup previously had overlapping owners. Some internal paths only removed a thread-local reference or closed a StatementContext, leaving session cleanup to object reclamation. This PR gives protocol requests one execution owner and makes private-context scopes responsible for cleanup on success, failure and cancellation. MySQL and Flight preserve their response contracts, and borrowed sessions remain with their original owner.
Details
Testing
Local JDK 17 verification used the repository's
run-fe-ut.shentry point.git diff --cached --checkpassed. Surefire XML totals match the run logs; staged/source hashes match the final verification snapshot.Documentation-only verification: all 8208 indexed call/field operations match the compiled metadata scan; all AST type references and 31 direct constructions are covered. Checked 3805 fixed-revision source links, 2797 unique anchors, table structure and whitespace. No kernel tests were rerun for the documentation-only addition.
No cluster SQL regression tests were run.
Historical baseline: 7398c4f passed 316 tests across 28 selected classes, and 60cecaa passed 1097 tests across 100 selected classes. These are separate from this change's latest verification. No cluster SQL regression tests were run.
Notes for Reviewers
Start with ConnectContext's English class comment, then acquireExecution/executeOwned/yieldExecution and interruptAndHandOffCleanup/handOffCleanup. STOPPING is terminal but is not a promise that cleanup has completed. If interruption finishes first, cleanupPending transfers finalization to the running owner; otherwise the closer takes idle execution and finalizes inline. Graceful closure claims STOPPING while retaining execution once protocol responses are empty. Cleanup's finally releases execution directly.
AutoCloseConnectContext owns a newly created private context; it is not a general binding guard. Its synchronous body must finish using the context and copy results/audit data before exit. Background work must own its scope inside the worker or retain independent resources. A request or cancellation callback that never returns still prevents safe release of resources it may be using. Java object memory remains GC-managed; session resources are released explicitly.
COM_CHANGE_USER follows the MySQL change-user contract. The server dispatch path resets before authentication; connection admission checks the authenticated user's slot before releasing the previous slot, including same-user requests.
Deferred follow-up: the existing follower temporary-table deletion hook builds an unqualified DROP using the current database and does not check forwarded SQL error status. Cleanup invocation is deterministic here, but those inherited namespace/error-handling problems require a separate fix. Cross-FE orphan reclamation and remote cleanup retries are outside this local ownership change. The old no-op session-registration hook is not treated as an actual leak.
Remaining findings from the broader caller audit, not fixed by this allocation simplification:
These inherited paths prevent claiming that every asynchronous borrowing/cancellation scenario is already correct. They need focused fixes and concurrency tests; adding ConnectContext lifecycle states would not resolve the caller ownership errors.
Complete ConnectContext field ownership audit
Field ownership audit: all 68 instance fields at 7398c4f, grouped by the same lifetime.
protocolAdapterlifecycleLock,sessionState,owner,cleanupPending,registeredPoolconnectionId,loginTime,sessionIdcurrentUserIdentity,authenticatedPrincipal,authenticatedRoles,isTempUser,sessionContextremoteIP,connectAttributessessionVariable,userVarsdefaultCatalog,currentDb,currentDbId,lastDBOfCatalogtxnEntrypreparedStmtId,preparedStatementContextMapdbToTempTableNamesMaplastQueryId,insertResultenv,connectSchedulerexecutor,command,statestmtId,forwardedStmtId,queryId,traceIdstartTime,startTimeInstant,returnRows,sqlHash,auditEventBuilderstatementContextloadId,backendId,needRegenerateInstanceId,instanceIdGeneratorcloudCluster,computeGroupeffectiveCloudCluster,queryBackendSelectionDecision,loadBackendSelectionDecision,backendSelectionProfile,workloadGroupNameloadBackendSelectionHintcurrentConnectedFEIp,isProxysyntheticWriteColTargetTableIdskipAuthisGroupCommitstatsErrorEstimatornoAuthresultAttachedInfothreadInfostreamLoadInfo,notEvalNondeterministicFunction,queryDetail,connectingFeLocalResourceGroupRelease note
HTTP and internal background work release their private session resources when their scope ends, including failure and cancellation paths. MySQL COM_CHANGE_USER resets the session even when the username is unchanged, reloads target-user defaults and enforces its connection limit. Failed changes return an error before closing. Group Commit planning applies SQL block rules to the active statement's SQL and user and exposes its planner to audit. Its statement decision is reset between Flight commands and text multi-statements. Result attachments no longer accumulate across commands in a long-lived session, and concurrent processlist readers do not overwrite each other's full-SQL display option.
Check List (For Author)
AI Disclosure