Track Variable State Across Transactions and Savepoints - v3.0#4929
Track Variable State Across Transactions and Savepoints - v3.0#4929renecannao merged 16 commits intov3.0from
Conversation
…haracters at compile time
Added get_pg_parameter_status
Dump transaction state in proxysql internal session output
There was a problem hiding this comment.
Pull Request Overview
This PR introduces explicit tracking of variable states across transactions and savepoints through a new transaction state manager and related updates in variable handling and query processing.
- Updated client/server reset methods to take a flag (reorder_dynamic_variables_idx) for dynamic variable reordering
- Integrated a new PgSQL_ExplicitTxnStateMgr class for managing transaction state and savepoint operations
- Modified query parsing and connection handling functions to account for transaction state changes
Reviewed Changes
Copilot reviewed 15 out of 16 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| lib/PgSQL_Variables.cpp | Added new parameter to reset functions and conditionally reordering indices |
| lib/PgSQL_Session.cpp | Instantiated and used the new transaction state manager |
| lib/PgSQL_Query_Processor.cpp | Updated tokenization and command parsing (including ABORT command handling) |
| lib/PgSQL_Protocol.cpp | Forwarded transaction state to function calls |
| lib/PgSQL_ExplicitTxnStateMgr.cpp | Introduced explicit transaction state management and savepoint support |
| lib/PgSQL_Connection.cpp | Modified query processing logic to use savepoint count |
| lib/MySQL_Session.cpp | Minor cleanup in error handling |
| lib/Base_Session.cpp | Adjusted transaction state handling with conditional MySQL-specific checks |
| include/proxysql_utils.h | Updated set_thread_name to use a templated approach |
| include/proxysql_structs.h | Added new PGSQL_QUERY_ABORT command |
| include/PgSQL_Variables.h | Updated method signatures to reflect new parameter usage |
| include/PgSQL_Session.h | Added transaction_state_manager member |
| include/PgSQL_Protocol.h | Updated related friend function declarations |
| include/PgSQL_ExplicitTxnStateMgr.h | Added declarations for the explicit transaction state manager |
Files not reviewed (1)
- lib/Makefile: Language not supported
|
/gemini review |
There was a problem hiding this comment.
Code Review
The pull request introduces transaction state management and savepoint functionality for PostgreSQL connections in ProxySQL. This is a significant enhancement that could improve the handling of complex transactions. However, the code requires careful review to ensure correctness, security, and maintainability.
Summary of Findings
- Missing Abort Handling: The addition of
PGSQL_QUERY_ABORTinproxysql_structs.handPgSQL_Query_Processor.cppis good, but the code inPgSQL_ExplicitTxnStateMgr.cppdoesn't explicitly handle theABORTcommand. This could lead to inconsistent transaction state management. - Savepoint Logic: The logic for handling savepoints in
PgSQL_Connection.cppseems complex and potentially error-prone. The interaction betweensavepoint_countandIsKnownActiveTransactionneeds careful consideration. - Potential Memory Leaks: The
strdupcalls inPgSQL_ExplicitTxnStateMgr.cpprequire correspondingfreecalls to prevent memory leaks, especially in error handling paths. - Missing Error Handling: The
async_connectfunction inPgSQL_Connection.cpphas cases forASYNC_CONNECT_FAILEDandASYNC_CONNECT_TIMEOUTthat return error codes, but thedefaultcase does not handle errors. This could lead to unhandled connection errors.
Merge Readiness
The pull request is not yet ready for merging. The issues related to missing abort handling, savepoint logic, potential memory leaks, and missing error handling need to be addressed before merging. I am unable to directly approve this pull request, and strongly recommend that others review and approve this code before merging, especially after the identified issues are resolved.
High-Level Workflow
The PgSQL_ExplicitTxnStateMgr manages explicit PostgreSQL transactions and savepoints by tracking the state of session variables. Here's how it operates logically:
1. Transaction Start (BEGIN)
Snapshot Capture:
When a transaction begins, the manager takes a snapshot of all tracked session variables from client connection.
2. Creating Savepoints (SAVEPOINT)
State Preservation:
Each SAVEPOINT command triggers a new snapshot of the current session variables.
3. Committing (COMMIT)
Finalization:
4. Rolling Back (ROLLBACK)
Full Reset:###
5. Rolling Back to a Savepoint (ROLLBACK TO SAVEPOINT)
Targeted Reset:
Example: After SAVEPOINT A → SAVEPOINT B, rolling back to A removes B and its snapshot.
6. Releasing Savepoints (RELEASE SAVEPOINT)
Cleanup Without Rollback:
Edge Cases & Safety
No Active Transaction:
Commands like COMMIT or ROLLBACK with no active transaction log warnings but take no action.
Duplicate Savepoints:
Creating a savepoint with an existing name is blocked to avoid ambiguity.
Debug Checks:
In debug builds, the manager verifies that server-side variables match client expectations to ensure consistency.
Example Workflow
Note:
Currently,
SET LOCALis not supported and will lock session on host group if executed.Closes #4907