Repository navigation
fix: make MySQL task storage close terminal - #27074
Conversation
|
No unresolved unrelated CI blockers remain. The earlier #27071 fixed-budget producer timeout did not recur in run 31691982155: the Compose Pessimistic BVT producer and downstream Coverage job both passed. #27075 had already resolved on the preceding rerun when Java setup succeeded. |
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review complete. The ownership change is sound: database/sql marks the DB closed and removes pending requests before collecting driver-close errors, and the pinned MySQL driver always performs idempotent connection cleanup and clears result state even when COM_QUIT fails. Therefore the returned write error is terminal and cannot represent retryable cleanup. Generic task-storage/service errors still propagate, so cluster admission safety is not weakened. The transplanted regression fails on the base and passes on this head; focused race x100, full pkg/taskservice tests, embedded lifecycle tests, and go list/build/vet for pkg/taskservice and pkg/embed all pass. Required CI is green.
Merge Queue Status
This pull request spent 53 seconds in the queue, with no time running CI. ReasonThe pull request can't be updated
HintYou should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again. Tick the box to put this pull request back in the merge queue (same as
|
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#27072 ## What this PR does / why we need it: ### Root cause Embedded CN services use `mysqlTaskStorage` through `database/sql`. During cluster shutdown, a pooled task connection can outlive the server endpoint it uses. `sql.DB.Close` first makes the DB terminal, then closes idle driver connections. The MySQL driver sends a courtesy `COM_QUIT`; if that write fails because the endpoint has already stopped, it returns errors such as `bad connection`, but still closes the socket, marks the connection closed, and clears its result state. `mysqlTaskStorage.Close` propagated that already-terminal driver error through the task holder and service close chain. The embedded cluster correctly treats a service close error as incomplete ownership cleanup and retains the process-wide complete-cluster admission token, so this false cleanup failure caused every later embedded-cluster test to fail admission. ### Changes - Make the concrete MySQL task storage treat `sql.DB.Close` as terminal after invoking it. This is the ownership boundary that knows the driver has no cleanup left to retry. - Keep generic task-storage, service-close, and embedded-cluster error handling unchanged, so real service cleanup errors still propagate and retain admission. - Add a deterministic regression for the reported `bad connection` and a second driver write error. It proves the DB is closed after the error and repeated close remains safe. ### Issue-to-test proof - `TestMySQLTaskStorageCloseIsTerminalAfterDriverError` injects the exact reported error and a different write error, then proves close succeeds, the DB rejects later use as closed, and close is idempotent. Before the production change, the exact test failed with `bad connection`. - `TestBasicCluster` exercises the issue's original embedded-cluster functional and shutdown path; it passes under coverage. - `TestClusterAdmissionCoversFullLifecycle` proves admission is released after successful full shutdown. - `TestClusterCloseContinuesAfterServiceError` proves unrelated service close errors still propagate and keep admission held; the fix does not weaken the cluster's cleanup safety rule. BVT is not applicable because SQL cannot inject a driver `Conn.Close` failure or observe the process-wide test-cluster admission token. The focused unit test provides deterministic fault injection, and the embedded package tests cover the end-to-end owner chain. ### Tests run On the issue base (`6a29b7d47eae06b414cce51ede4a129b6da9b68a`), before the final main merges: - `mo-cgo-test -count=1 -timeout=300s ./pkg/taskservice` - `mo-cgo-test -count=1 -timeout=900s ./pkg/embed` - `mo-cgo-test -race -count=1 -timeout=600s ./pkg/taskservice` - `mo-cgo-test -race -count=1 -timeout=1800s ./pkg/embed` - Focused `-race` stress with a 30-second budget: the storage regression and both admission tests measured below timer resolution and passed with `N=100`; `TestBasicCluster` measured 19.25 seconds and passed with `N=1`. After rebasing onto main at `1d7b6311ce91df0968da435bb405f3d68137c595`: - `mo-cgo-test -count=1 -timeout=180s -run '^TestMySQLTaskStorageCloseIsTerminalAfterDriverError$' ./pkg/taskservice` - `mo-cgo-test -race -count=100 -timeout=180s -run '^TestMySQLTaskStorageCloseIsTerminalAfterDriverError$' ./pkg/taskservice` - `mo-cgo-test -count=1 -timeout=300s ./pkg/taskservice` - `mo-cgo-test -race -count=1 -timeout=600s ./pkg/taskservice` - `mo-cgo-test -cover -count=1 -timeout=420s -run '^TestBasicCluster$' ./pkg/embed` (64.3% package coverage) - `go build -mod=readonly ./pkg/taskservice ./pkg/embed` with the repository CGo flags - `go vet -mod=readonly ./pkg/taskservice ./pkg/embed` with the repository CGo flags Final readiness validation on head `4c802c3f1ca6ec3ed36a8d22f3ae6714978e31af`, after merging main through `bdbd613fdece966769eb68481a3e58bfbc36b30c`: - Enumerated `TestMySQLTaskStorageCloseIsTerminalAfterDriverError` before execution. - `mo-cgo-test -race -count=100 -timeout=180s -run '^TestMySQLTaskStorageCloseIsTerminalAfterDriverError$' ./pkg/taskservice` (`T` below timer resolution, 30-second stress budget, `N=100`). - `mo-cgo-test -race -count=1 -timeout=600s ./pkg/taskservice` - `GOWORK=off go list -mod=readonly ./pkg/taskservice ./pkg/embed` - `GOWORK=off go build -mod=readonly ./pkg/taskservice ./pkg/embed` with the repository CGo flags - `GOWORK=off go vet -mod=readonly ./pkg/taskservice ./pkg/embed` with the repository CGo flags - `git diff --check` - [MatrixOne ALL CI run 31691982155](https://github.com/matrixorigin/matrixone/actions/runs/31691982155): PR validation, Ubuntu UT, arm64 SCA, UT coverage, Compose Proxy BVT, Compose Pessimistic BVT, and final Coverage all passed. ### Self-review The complete PR diff remains limited to the concrete MySQL task storage and its regression test. `database/sql` owns concurrent close serialization and marks the DB closed before invoking driver cleanup; the MySQL driver makes connection cleanup idempotent even when `COM_QUIT` fails. The change adds no waits, goroutines, retained state, allocation growth, wire/storage format, or hot-path work. Generic task storage, CN service, and embedded-cluster cleanup errors retain their existing propagation and admission semantics. ### Residual risks This intentionally stops reporting MySQL driver's courtesy shutdown write errors from task storage. Those errors cannot be retried because `database/sql` has already closed the DB and the MySQL driver has already released the connection. Errors from task schedulers, runners, stores other than this concrete MySQL storage, and all other embedded services remain unchanged and continue to block admission release. Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#27072 ## What this PR does / why we need it: ### Root cause Embedded CN services use `mysqlTaskStorage` through `database/sql`. During cluster shutdown, a pooled task connection can outlive the server endpoint it uses. `sql.DB.Close` first makes the DB terminal, then closes idle driver connections. The MySQL driver sends a courtesy `COM_QUIT`; if that write fails because the endpoint has already stopped, it returns errors such as `bad connection`, but still closes the socket, marks the connection closed, and clears its result state. `mysqlTaskStorage.Close` propagated that already-terminal driver error through the task holder and service close chain. The embedded cluster correctly treats a service close error as incomplete ownership cleanup and retains the process-wide complete-cluster admission token, so this false cleanup failure caused every later embedded-cluster test to fail admission. ### Changes - Make the concrete MySQL task storage treat `sql.DB.Close` as terminal after invoking it. This is the ownership boundary that knows the driver has no cleanup left to retry. - Keep generic task-storage, service-close, and embedded-cluster error handling unchanged, so real service cleanup errors still propagate and retain admission. - Add a deterministic regression for the reported `bad connection` and a second driver write error. It proves the DB is closed after the error and repeated close remains safe. ### Issue-to-test proof - `TestMySQLTaskStorageCloseIsTerminalAfterDriverError` injects the exact reported error and a different write error, then proves close succeeds, the DB rejects later use as closed, and close is idempotent. Before the production change, the exact test failed with `bad connection`. - `TestBasicCluster` exercises the issue's original embedded-cluster functional and shutdown path; it passes under coverage. - `TestClusterAdmissionCoversFullLifecycle` proves admission is released after successful full shutdown. - `TestClusterCloseContinuesAfterServiceError` proves unrelated service close errors still propagate and keep admission held; the fix does not weaken the cluster's cleanup safety rule. BVT is not applicable because SQL cannot inject a driver `Conn.Close` failure or observe the process-wide test-cluster admission token. The focused unit test provides deterministic fault injection, and the embedded package tests cover the end-to-end owner chain. ### Tests run On the issue base (`6a29b7d47eae06b414cce51ede4a129b6da9b68a`), before the final main merges: - `mo-cgo-test -count=1 -timeout=300s ./pkg/taskservice` - `mo-cgo-test -count=1 -timeout=900s ./pkg/embed` - `mo-cgo-test -race -count=1 -timeout=600s ./pkg/taskservice` - `mo-cgo-test -race -count=1 -timeout=1800s ./pkg/embed` - Focused `-race` stress with a 30-second budget: the storage regression and both admission tests measured below timer resolution and passed with `N=100`; `TestBasicCluster` measured 19.25 seconds and passed with `N=1`. After rebasing onto main at `1d7b6311ce91df0968da435bb405f3d68137c595`: - `mo-cgo-test -count=1 -timeout=180s -run '^TestMySQLTaskStorageCloseIsTerminalAfterDriverError$' ./pkg/taskservice` - `mo-cgo-test -race -count=100 -timeout=180s -run '^TestMySQLTaskStorageCloseIsTerminalAfterDriverError$' ./pkg/taskservice` - `mo-cgo-test -count=1 -timeout=300s ./pkg/taskservice` - `mo-cgo-test -race -count=1 -timeout=600s ./pkg/taskservice` - `mo-cgo-test -cover -count=1 -timeout=420s -run '^TestBasicCluster$' ./pkg/embed` (64.3% package coverage) - `go build -mod=readonly ./pkg/taskservice ./pkg/embed` with the repository CGo flags - `go vet -mod=readonly ./pkg/taskservice ./pkg/embed` with the repository CGo flags Final readiness validation on head `4c802c3f1ca6ec3ed36a8d22f3ae6714978e31af`, after merging main through `bdbd613fdece966769eb68481a3e58bfbc36b30c`: - Enumerated `TestMySQLTaskStorageCloseIsTerminalAfterDriverError` before execution. - `mo-cgo-test -race -count=100 -timeout=180s -run '^TestMySQLTaskStorageCloseIsTerminalAfterDriverError$' ./pkg/taskservice` (`T` below timer resolution, 30-second stress budget, `N=100`). - `mo-cgo-test -race -count=1 -timeout=600s ./pkg/taskservice` - `GOWORK=off go list -mod=readonly ./pkg/taskservice ./pkg/embed` - `GOWORK=off go build -mod=readonly ./pkg/taskservice ./pkg/embed` with the repository CGo flags - `GOWORK=off go vet -mod=readonly ./pkg/taskservice ./pkg/embed` with the repository CGo flags - `git diff --check` - [MatrixOne ALL CI run 31691982155](https://github.com/matrixorigin/matrixone/actions/runs/31691982155): PR validation, Ubuntu UT, arm64 SCA, UT coverage, Compose Proxy BVT, Compose Pessimistic BVT, and final Coverage all passed. ### Self-review The complete PR diff remains limited to the concrete MySQL task storage and its regression test. `database/sql` owns concurrent close serialization and marks the DB closed before invoking driver cleanup; the MySQL driver makes connection cleanup idempotent even when `COM_QUIT` fails. The change adds no waits, goroutines, retained state, allocation growth, wire/storage format, or hot-path work. Generic task storage, CN service, and embedded-cluster cleanup errors retain their existing propagation and admission semantics. ### Residual risks This intentionally stops reporting MySQL driver's courtesy shutdown write errors from task storage. Those errors cannot be retried because `database/sql` has already closed the DB and the MySQL driver has already released the connection. Errors from task schedulers, runners, stores other than this concrete MySQL storage, and all other embedded services remain unchanged and continue to block admission release. Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#27072 ## What this PR does / why we need it: ### Root cause Embedded CN services use `mysqlTaskStorage` through `database/sql`. During cluster shutdown, a pooled task connection can outlive the server endpoint it uses. `sql.DB.Close` first makes the DB terminal, then closes idle driver connections. The MySQL driver sends a courtesy `COM_QUIT`; if that write fails because the endpoint has already stopped, it returns errors such as `bad connection`, but still closes the socket, marks the connection closed, and clears its result state. `mysqlTaskStorage.Close` propagated that already-terminal driver error through the task holder and service close chain. The embedded cluster correctly treats a service close error as incomplete ownership cleanup and retains the process-wide complete-cluster admission token, so this false cleanup failure caused every later embedded-cluster test to fail admission. ### Changes - Make the concrete MySQL task storage treat `sql.DB.Close` as terminal after invoking it. This is the ownership boundary that knows the driver has no cleanup left to retry. - Keep generic task-storage, service-close, and embedded-cluster error handling unchanged, so real service cleanup errors still propagate and retain admission. - Add a deterministic regression for the reported `bad connection` and a second driver write error. It proves the DB is closed after the error and repeated close remains safe. ### Issue-to-test proof - `TestMySQLTaskStorageCloseIsTerminalAfterDriverError` injects the exact reported error and a different write error, then proves close succeeds, the DB rejects later use as closed, and close is idempotent. Before the production change, the exact test failed with `bad connection`. - `TestBasicCluster` exercises the issue's original embedded-cluster functional and shutdown path; it passes under coverage. - `TestClusterAdmissionCoversFullLifecycle` proves admission is released after successful full shutdown. - `TestClusterCloseContinuesAfterServiceError` proves unrelated service close errors still propagate and keep admission held; the fix does not weaken the cluster's cleanup safety rule. BVT is not applicable because SQL cannot inject a driver `Conn.Close` failure or observe the process-wide test-cluster admission token. The focused unit test provides deterministic fault injection, and the embedded package tests cover the end-to-end owner chain. ### Tests run On the issue base (`6a29b7d47eae06b414cce51ede4a129b6da9b68a`), before the final main merges: - `mo-cgo-test -count=1 -timeout=300s ./pkg/taskservice` - `mo-cgo-test -count=1 -timeout=900s ./pkg/embed` - `mo-cgo-test -race -count=1 -timeout=600s ./pkg/taskservice` - `mo-cgo-test -race -count=1 -timeout=1800s ./pkg/embed` - Focused `-race` stress with a 30-second budget: the storage regression and both admission tests measured below timer resolution and passed with `N=100`; `TestBasicCluster` measured 19.25 seconds and passed with `N=1`. After rebasing onto main at `1d7b6311ce91df0968da435bb405f3d68137c595`: - `mo-cgo-test -count=1 -timeout=180s -run '^TestMySQLTaskStorageCloseIsTerminalAfterDriverError$' ./pkg/taskservice` - `mo-cgo-test -race -count=100 -timeout=180s -run '^TestMySQLTaskStorageCloseIsTerminalAfterDriverError$' ./pkg/taskservice` - `mo-cgo-test -count=1 -timeout=300s ./pkg/taskservice` - `mo-cgo-test -race -count=1 -timeout=600s ./pkg/taskservice` - `mo-cgo-test -cover -count=1 -timeout=420s -run '^TestBasicCluster$' ./pkg/embed` (64.3% package coverage) - `go build -mod=readonly ./pkg/taskservice ./pkg/embed` with the repository CGo flags - `go vet -mod=readonly ./pkg/taskservice ./pkg/embed` with the repository CGo flags Final readiness validation on head `4c802c3f1ca6ec3ed36a8d22f3ae6714978e31af`, after merging main through `bdbd613fdece966769eb68481a3e58bfbc36b30c`: - Enumerated `TestMySQLTaskStorageCloseIsTerminalAfterDriverError` before execution. - `mo-cgo-test -race -count=100 -timeout=180s -run '^TestMySQLTaskStorageCloseIsTerminalAfterDriverError$' ./pkg/taskservice` (`T` below timer resolution, 30-second stress budget, `N=100`). - `mo-cgo-test -race -count=1 -timeout=600s ./pkg/taskservice` - `GOWORK=off go list -mod=readonly ./pkg/taskservice ./pkg/embed` - `GOWORK=off go build -mod=readonly ./pkg/taskservice ./pkg/embed` with the repository CGo flags - `GOWORK=off go vet -mod=readonly ./pkg/taskservice ./pkg/embed` with the repository CGo flags - `git diff --check` - [MatrixOne ALL CI run 31691982155](https://github.com/matrixorigin/matrixone/actions/runs/31691982155): PR validation, Ubuntu UT, arm64 SCA, UT coverage, Compose Proxy BVT, Compose Pessimistic BVT, and final Coverage all passed. ### Self-review The complete PR diff remains limited to the concrete MySQL task storage and its regression test. `database/sql` owns concurrent close serialization and marks the DB closed before invoking driver cleanup; the MySQL driver makes connection cleanup idempotent even when `COM_QUIT` fails. The change adds no waits, goroutines, retained state, allocation growth, wire/storage format, or hot-path work. Generic task storage, CN service, and embedded-cluster cleanup errors retain their existing propagation and admission semantics. ### Residual risks This intentionally stops reporting MySQL driver's courtesy shutdown write errors from task storage. Those errors cannot be retried because `database/sql` has already closed the DB and the MySQL driver has already released the connection. Errors from task schedulers, runners, stores other than this concrete MySQL storage, and all other embedded services remain unchanged and continue to block admission release. Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #27072
What this PR does / why we need it:
Root cause
Embedded CN services use
mysqlTaskStoragethroughdatabase/sql. During cluster shutdown, a pooled task connection can outlive the server endpoint it uses.sql.DB.Closefirst makes the DB terminal, then closes idle driver connections. The MySQL driver sends a courtesyCOM_QUIT; if that write fails because the endpoint has already stopped, it returns errors such asbad connection, but still closes the socket, marks the connection closed, and clears its result state.mysqlTaskStorage.Closepropagated that already-terminal driver error through the task holder and service close chain. The embedded cluster correctly treats a service close error as incomplete ownership cleanup and retains the process-wide complete-cluster admission token, so this false cleanup failure caused every later embedded-cluster test to fail admission.Changes
sql.DB.Closeas terminal after invoking it. This is the ownership boundary that knows the driver has no cleanup left to retry.bad connectionand a second driver write error. It proves the DB is closed after the error and repeated close remains safe.Issue-to-test proof
TestMySQLTaskStorageCloseIsTerminalAfterDriverErrorinjects the exact reported error and a different write error, then proves close succeeds, the DB rejects later use as closed, and close is idempotent. Before the production change, the exact test failed withbad connection.TestBasicClusterexercises the issue's original embedded-cluster functional and shutdown path; it passes under coverage.TestClusterAdmissionCoversFullLifecycleproves admission is released after successful full shutdown.TestClusterCloseContinuesAfterServiceErrorproves unrelated service close errors still propagate and keep admission held; the fix does not weaken the cluster's cleanup safety rule.BVT is not applicable because SQL cannot inject a driver
Conn.Closefailure or observe the process-wide test-cluster admission token. The focused unit test provides deterministic fault injection, and the embedded package tests cover the end-to-end owner chain.Tests run
On the issue base (
6a29b7d47eae06b414cce51ede4a129b6da9b68a), before the final main merges:mo-cgo-test -count=1 -timeout=300s ./pkg/taskservicemo-cgo-test -count=1 -timeout=900s ./pkg/embedmo-cgo-test -race -count=1 -timeout=600s ./pkg/taskservicemo-cgo-test -race -count=1 -timeout=1800s ./pkg/embed-racestress with a 30-second budget: the storage regression and both admission tests measured below timer resolution and passed withN=100;TestBasicClustermeasured 19.25 seconds and passed withN=1.After rebasing onto main at
1d7b6311ce91df0968da435bb405f3d68137c595:mo-cgo-test -count=1 -timeout=180s -run '^TestMySQLTaskStorageCloseIsTerminalAfterDriverError$' ./pkg/taskservicemo-cgo-test -race -count=100 -timeout=180s -run '^TestMySQLTaskStorageCloseIsTerminalAfterDriverError$' ./pkg/taskservicemo-cgo-test -count=1 -timeout=300s ./pkg/taskservicemo-cgo-test -race -count=1 -timeout=600s ./pkg/taskservicemo-cgo-test -cover -count=1 -timeout=420s -run '^TestBasicCluster$' ./pkg/embed(64.3% package coverage)go build -mod=readonly ./pkg/taskservice ./pkg/embedwith the repository CGo flagsgo vet -mod=readonly ./pkg/taskservice ./pkg/embedwith the repository CGo flagsFinal readiness validation on head
4c802c3f1ca6ec3ed36a8d22f3ae6714978e31af, after merging main throughbdbd613fdece966769eb68481a3e58bfbc36b30c:TestMySQLTaskStorageCloseIsTerminalAfterDriverErrorbefore execution.mo-cgo-test -race -count=100 -timeout=180s -run '^TestMySQLTaskStorageCloseIsTerminalAfterDriverError$' ./pkg/taskservice(Tbelow timer resolution, 30-second stress budget,N=100).mo-cgo-test -race -count=1 -timeout=600s ./pkg/taskserviceGOWORK=off go list -mod=readonly ./pkg/taskservice ./pkg/embedGOWORK=off go build -mod=readonly ./pkg/taskservice ./pkg/embedwith the repository CGo flagsGOWORK=off go vet -mod=readonly ./pkg/taskservice ./pkg/embedwith the repository CGo flagsgit diff --checkSelf-review
The complete PR diff remains limited to the concrete MySQL task storage and its regression test.
database/sqlowns concurrent close serialization and marks the DB closed before invoking driver cleanup; the MySQL driver makes connection cleanup idempotent even whenCOM_QUITfails. The change adds no waits, goroutines, retained state, allocation growth, wire/storage format, or hot-path work. Generic task storage, CN service, and embedded-cluster cleanup errors retain their existing propagation and admission semantics.Residual risks
This intentionally stops reporting MySQL driver's courtesy shutdown write errors from task storage. Those errors cannot be retried because
database/sqlhas already closed the DB and the MySQL driver has already released the connection. Errors from task schedulers, runners, stores other than this concrete MySQL storage, and all other embedded services remain unchanged and continue to block admission release.