Repository navigation
fix(plugin-dameng): reconnect after a stopped query instead of failing forever - #2267
Merged
Merged
Conversation
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Workflows to automatically generate PRs for you. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
plz release |
Member
Author
|
@miracleloveWT dm8 plugin is releasing, please wait https://github.com/TableProApp/TablePro/actions/runs/32329126061 |
This branch was successfully deployed
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.
Fixes #2262.
What was wrong
The Dameng driver's own documentation and its own code comment both promise this:
The reconnect was never written. Measured against a live DM8 8.1 server through the exact C ABI
the plugin calls, using the committed
libdameng_bridge.a:is_recoverablein the bridge is false forCancelled,Timeout,Protocol,Io,ConnectionFailed,AuthFailedandNotConnected, sotp_dm_executedisposes the client andTpDmConnection.clientstaysNonefor the life of the handle. Swift never learned:DamengConnection.executerethrew without releasingrawConnection, soconnectedPointer()kept handing out the stale pointer and every later call reported a closed connection.
Cancellation is routine flow control in TablePro, not an exceptional path.
MainContentCoordinator.supersedeExecutionruns on every tab retarget, which is every time theuser clicks a second table, and it cancels the in-flight query, the table-load task and the
row-count task. So opening one table while another was still loading killed the connection, and
everything after it failed until
ConnectionHealthMonitor's 30 second ping noticed. That windowis the reporter's "opening a table takes a very long time, sometimes it cannot be opened at all",
and a schema switch inside it surfaces through
MainContentCoordinator+Navigation.swift:540asthe reported "Schema Switch Failed" alert.
The fix
The driver reconnects and runs the statement once more, which is the shape MySQL
(
MySQLPluginDriver.executeWithReconnect), PostgreSQL (LibPQDriverCore.executeWithReconnect)and Redis (
RedisPluginConnection.executeCommandSyncRetrying) already ship. Dameng was the onlydriver missing it.
Native/DamengBridge:TpDmErrorcarries aconnection_lostflag, taken from theis_recoverablethe bridge already computes at the failure site, exposed astp_dm_error_is_connection_lostnext to the existingtp_dm_error_is_cancellation. Themessage text cannot separate "the server rejected this SQL", which leaves the connection
usable, from "the transport died".
transaction_operationnow reports throughset_driver_erroras well, so a stopped commit or ping is classified the same way a stoppedquery already was.
DamengConnection: retires its handle when the bridge says the connection closed, so theSwift state is honest and the driver can tell a dead connection from a rejected statement.
Cancellation is now scoped to the statement actually on the wire:
tp_dm_cancelisconnection-wide, so a cancellation aimed at a statement still queued behind another used to
interrupt the wrong one, and a queued statement that was cancelled ran anyway because the next
tp_dm_executecleared the flag on its way in. A connect is fenced by an epoch so one thatlands after a disconnect cannot revive a connection the caller already closed.
DamengPluginDriver:executeWithReconnectrestores the active schema and the textescaping mode. Only a read is sent again, using the same rule MySQL applies, because a write
may already have been applied before its reply was abandoned.
switchSchemarecovers too,since
SET SCHEMAis idempotent. However many statements find the connection dead, they shareone rebuild rather than each starting its own, the shape
SQLSchemaProvideruses. A connectionlost inside a transaction is never rebuilt under it: the loss is reported, because the rebuilt
connection never saw the
BEGINand the later commit would report success having writtennothing.
Verified
verify.sh generateverify.sh build(app)DamengDriver+DamengDriverTestsbuildcargo testinNative/DamengBridgeverify.sh lint Plugins/DamengDriverPlugin Plugins/DamengDriverPluginTestsverify.sh plugins(AllPlugins)@TaskLocalmacro, which this branch does not touchSkill(code-review)at high effort found six real defects in the first draft of this change,all fixed here and covered by tests: retiring a dead handle used to invalidate the rebuild that
was recovering it, concurrent rebuilds fought each other,
tp_dm_cancelcould read a handleanother thread was freeing, a transaction could be silently replaced, and a failed escaping probe
permanently downgraded the mode.
Skill(security-review)found nothing.The regression test is
testLiveDM8RecoversFromAStoppedStatement. It was checked both waysagainst a live server: with the retry removed it fails with the exact error the issue reports,
DamengError(message: "The Dameng connection is closed."), and it passes with the fix in place.The one failing test in the Dameng suite is
testLiveDM8Workflow, which fails at "create parent"with
-2004: 不支持的语句类型. That is pre-existing: it fails identically onmain, and it is areal defect described below, not a regression from this change. It had never been seen because
the live tests need
TABLEPRO_DM8_INTEGRATION=1and the environment does not reach the testprocess through
xcodebuild; they run underxcrun xctest.There are no screenshots because nothing on screen changed. The user-visible difference is the
absence of an error, and staging it by hand means racing a cancel against a query, which is the
non-deterministic thing the regression test replaced.
Found while investigating, not fixed here
generateCreateTableSQLemitsCREATE TABLEandCREATE INDEXas one statement string, andDM8 rejects a multi-statement batch with
-2004. Creating a table with an index fails.Measured directly against the server.
ALL_COL_COMMENTS.OWNERis the owning user, while every otherALL_*view TablePro readsuses the schema, so the join in
fetchColumnsandfetchAllColumnsdrops every columncomment whenever a schema is not named after its owner. Measured: the same query returns rows
for
OWNER = 'SYSDBA'and none forOWNER = 'APP'.table, and 1,159 of 2,000 tables in the sidebar, with
is_truncatedstill false.CLOBcolumn comes back with the wrong number of columns and rows.the pinned Rust fork that measures 9.80s to 0.00s at the crate level, but it made no difference
through the shipped static library and I could not explain why, so it is not in this PR.