feat: Add cancel support for batch/script/transaction operations#1519
feat: Add cancel support for batch/script/transaction operations#1519dbin0123 wants to merge 8 commits into
Conversation
…ry functionality -Implemented health check mechanism for PostgreSQL connection pool -Added health checks for ClickHouse, Elasticsearch, VectorDB, InfluxDB, Rqlite, Turso, and Agent connection pools -Implemented ping check timeout mechanism for MySQL connections -Added timeout detection mechanism for MongoDB connections -Implemented independent health check processing for Redis connection pool -Added the function of automatically refreshing the connection pool during application recovery -Automatically remove invalid connection pools when query fails -Refactored metadata retrieval method to support retry mechanism -Change the default interval of Keepalive from 0 seconds to 60 seconds -Implemented connection cloning support for various database types -Added resource cleaning mechanism when connection is closed
- 在数据库类型列表中添加了 milvus 和 qdrant 选项 - 扩展了支持的数据库连接类型描述信息
- 在executeBatch、executeScript和executeInTransaction等API调用中添加executionId参数 - 为SchemaDiffDialog、QueryHistory、ObjectBrowser、TableStructureEditor和DataGridEditor组件添加UUID生成器导入 - 更新API函数签名以支持executionId参数传递 - 修改默认查询超时时间为0(无限制) - 优化PostgreSQL连接客户端管理,添加execute_query_on_client和execute_query_with_schema_on_client函数 - 为MySQL连接添加连接终止机制和查询取消处理 - 完善事务处理中的取消逻辑,确保连接池在取消或错误时正确清理 - 重构查询执行逻辑以支持执行ID跟踪和更精确的超时错误报告 - 为插件驱动程序会话实现Drop trait以自动终止进程 - 优化各种数据库类型的批量执行和事务执行逻辑
- 在测试数据库配置中增加了 query_timeout_secs 参数 - 设置默认查询超时时间为 30 秒 - 防止长时间运行的查询导致测试失败
t8y2
left a comment
There was a problem hiding this comment.
PR #1519: feat: Add cancel support for batch/script/transaction operations
+376/-91, 20 files | CI: pass | Mergeable: MERGEABLE
🔴 Must Fix
-
executeInTransactioncancellation does not interrupt an active long-running statement on the main native transaction paths. Incrates/dbx-core/src/query.rs:1927,:1958, and:1996, the code only checksis_canceled()before starting each statement, then awaitstx.execute,conn.query_iter, or SQLiteexecute_batchwithout racing against the cancellation token or invoking the driver-specific interrupt/kill path. A single-statement transaction likeSELECT pg_sleep(600)orSELECT SLEEP(600)will keep running until the database returns, so the new cancel support does not work for the exact long-running transaction case this PR targets. -
The explicit transaction rollback path reuses the already-canceled token, so rollback may never be sent. At
crates/dbx-core/src/query.rs:2065, cancellation triggersdo_execute(... "ROLLBACK", cancel_token.clone(), ...); because the token is canceled,do_execute/wait_for_query_optcan returnQuery canceledimmediately instead of executingROLLBACK. The same pattern appears on statement error rollback at:2099and commit at:2118. Cleanup statements should run through an uncancelable/internal cleanup path, or the pool should be discarded when rollback cannot be confirmed. -
The frontend generates execution IDs for these operations but does not expose them to the existing cancel flow. For example,
apps/desktop/src/App.vue:503,TableStructureEditor.vue:838,SchemaDiffDialog.vue:520, anduseDataGridEditor.ts:762create local IDs, butcancelActiveExecution()only cancelstab.isExecutingortab.isExplainingvia the tab’s stored execution ID (apps/desktop/src/composables/useSqlExecution.ts:129). Users still have no practical way to cancel structure saves, schema diff deploys, data-grid saves, object-source saves, or rollbacks.
🟡 Suggestions
Add targeted tests for canceling executeInTransaction while a statement is currently running, plus a test that verifies explicit transactions actually issue ROLLBACK after cancellation.
✅ Well Done
The PR consistently extends the Tauri and web request shapes for executionId, and the non-transaction executeBatch / executeScript paths are moving in the right direction by passing cancellation tokens into do_execute.
Verdict
Request changes. The wiring is promising, but transaction cancellation and rollback cleanup currently have correctness holes that can leave long-running work alive or leave a connection in an open transaction.
Summary
Add user cancel support for all long-running database operations, not just queries. This includes executeBatch, executeScript, and executeInTransaction commands which are used for DDL operations (CREATE/ALTER TABLE etc.) and data modifications.
Changes
Backend (Rust):
Added execution_id parameter to execute_batch, execute_script, execute_in_transaction Tauri commands
Added cancel_token parameter to execute_statements() and execute_statements_in_transaction() core functions
Added is_canceled() check before each statement execution in loops
Added proper ROLLBACK on cancel for transaction operations
Updated web routes (dbx-web) to support cancel token registration
Frontend (TypeScript/Vue):
Updated tauri.ts, http.ts, api.ts to pass executionId parameter
Updated useDataGridEditor.ts - DataGrid save operations
Updated TableStructureEditor.vue - Structure save operations
Updated ObjectBrowser.vue - Object source save operations
Updated App.vue - Object source save operations
Updated QueryHistory.vue - Rollback operations
Updated SchemaDiffDialog.vue - Schema diff deploy operations