RaigorJiang opened a new pull request, #38680:
URL: https://github.com/apache/shardingsphere/pull/38680
Related to #38665
## Background
Commit `7a75e3931f6d404af7ee299c0112d997a0e22230`(#38665) improved the
Proxy backend executor lifecycle, but it still left several follow-up issues
around repeated Proxy startup and shutdown flows.
The remaining concern was that `BackendExecutorContext` could still be
reinitialized from request-side execution paths after shutdown. In practice,
this made the lifecycle boundary ambiguous:
- `shutdown()` closed the executor, but later `getExecutorEngine()` could
still lazily initialize a new executor.
- Request execution paths could revive the backend executor after Proxy
shutdown instead of requiring an explicit lifecycle startup.
- Repeated Proxy lifecycle scenarios were not covered by near-production
frontend execution tests.
- Some tests depended on singleton state left by other tests, which made
the lifecycle behavior easier to regress.
## Changes
This PR tightens the `BackendExecutorContext` lifecycle semantics.
### Backend executor lifecycle
- Makes `shutdown()` close the current executor and move the context into
the `CLOSED` state.
- Prevents `getExecutorEngine()` from lazily creating a new executor when
the lifecycle state is `CLOSED`.
- Keeps explicit `init()` as the only supported way to move from a closed
lifecycle into a running lifecycle again.
- Replaces the old close-style helper flow with an internal executor close
helper so lifecycle state changes stay explicit.
The intended lifecycle behavior is now:
- `UNINITIALIZED -> RUNNING`: explicit `init()` creates the executor.
- `RUNNING -> RUNNING`: repeated `init()` replaces the old executor with a
fresh one.
- `RUNNING -> CLOSED`: `shutdown()` closes the executor and marks the
context closed.
- `CLOSED -> getExecutorEngine()`: rejected with `IllegalStateException`.
- `CLOSED -> RUNNING`: only allowed through explicit `init()`.
### Tests
This PR adds and updates tests for the lifecycle and affected execution
paths:
- Covers repeated `BackendExecutorContext.init()` replacing the executor.
- Covers `shutdown()` rejecting later request-side executor access.
- Covers explicit `init()` after `shutdown()` creating a fresh executor.
- Initializes and shuts down `BackendExecutorContext` explicitly in
`ProxySQLExecutorTest` to avoid singleton state leakage between tests.
- Adds a PostgreSQL batched statements repeated Proxy lifecycle test.
- Adds a MySQL multi-statements adjacent repeated Proxy lifecycle test.
- Updates bootstrap lifecycle test naming to reflect repeated bootstrap
behavior.
## Impact
This change makes the Proxy backend executor lifecycle stricter and more
predictable.
After Proxy shutdown, request execution paths can no longer accidentally
recreate the backend executor. A new executor can still be created for a
repeated Proxy startup, but only through the explicit lifecycle initialization
path.
This reduces the risk of accepting work after shutdown and makes repeated
Proxy lifecycle behavior easier to reason about and test.
No SQL behavior, configuration format, protocol packet format, SPI
contract, or dependency is changed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]