-
Notifications
You must be signed in to change notification settings - Fork 1k
Fix SQLite 'table already exists' errors during PROXYSQL STOP (issue #5221) #5223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…5221) Add comprehensive Doxygen documentation and 'IF NOT EXISTS' clauses to prevent SQLite errors: Root Cause: - During PROXYSQL STOP, modules are restarted multiple times without proper table cleanup - MySQL_HostGroups_Manager and Base_HostGroups_Manager constructors both create tables - In-memory SQLite databases persist across restarts, causing 'table already exists' errors Solution: - Add 'IF NOT EXISTS' clauses to all 9 CREATE TABLE macros - Comprehensive Doxygen documentation explaining the issue and fix - Individual table documentation with @brief and @details Tables Fixed: - MYHGM_MYSQL_SERVERS & MYHGM_MYSQL_SERVERS_INCOMING (DEBUG/non-DEBUG variants) - MYHGM_MYSQL_REPLICATION_HOSTGROUPS - MYHGM_MYSQL_GROUP_REPLICATION_HOSTGROUPS - MYHGM_MYSQL_GALERA_HOSTGROUPS - MYHGM_MYSQL_AWS_AURORA_HOSTGROUPS - MYHGM_MYSQL_HOSTGROUP_ATTRIBUTES - MYHGM_MYSQL_SERVERS_SSL_PARAMS Benefits: - Eliminates SQLite error logging during normal PROXYSQL STOP operations - Improves shutdown performance by removing error handling overhead - Cleaner logs without confusing 'table already exists' messages - Maintains data integrity and functionality Files Modified: - include/Base_HostGroups_Manager.h: Updated all table schemas with 'IF NOT EXISTS' and Doxygen docs - include/MySQL_HostGroups_Manager.h: Removed duplicate table definitions
Summary of ChangesHello @renecannao, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly improves the stability and flexibility of ProxySQL by resolving SQLite 'table already exists' errors during shutdown sequences and enhancing the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces two major improvements. First, it resolves SQLite 'table already exists' errors during PROXYSQL STOP by adding IF NOT EXISTS to all CREATE TABLE statements, which is a direct and effective fix. Second, and more substantially, it adds a state machine and graceful shutdown logic for the PROXYSQL STOP/START cycle to prevent crashes and instability, which is a critical enhancement for the reliability of ProxySQL. The changes are well-documented with extensive Doxygen comments, and the addition of new tests for module startup and PROXYSQL STOP behavior is commendable. My review found one critical typo in a CREATE TABLE statement and some dead code that can be removed for better maintainability. Overall, this is a high-quality contribution that significantly improves the robustness of ProxySQL.
| /// @brief MySQL AWS Aurora hostgroups configuration table | ||
| /// @details Aurora-specific hostgroup management with dynamic topology detection and lag monitoring | ||
| #define MYHGM_MYSQL_AWS_AURORA_HOSTGROUPS "CREATE TABLE IF NOT EXISTS mysql_aws_aurora_hostgroups (writer_hostgroup INT CHECK (writer_hostgroup>=0) NOT NULL PRIMARY KEY , reader_hostgroup INT NOT NULL CHECK (reader_hostgroup<>writer_hostgroup AND reader_hostgroup>0) , " \ | ||
| "active INT CHECK (active IN (0,1)) NOT NULL DEFAULT 1 , aurora_port INT NOT NUlL DEFAULT 3306 , domain_name VARCHAR NOT NULL DEFAULT '' , " \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| #if 0 | ||
| { | ||
| // this block seems unnecessary, as we have enough fencing | ||
| ProxySQL_Admin *SPA=(ProxySQL_Admin *)pa; | ||
| // Check if this is a dangerous query that should be blocked during STOP states (issue 5186) | ||
| if (glovars.stop_state != STOP_STATE_RUNNING && sess->session_type == PROXYSQL_SESSION_ADMIN) { | ||
| // Block dangerous runtime_* queries that access destroyed modules | ||
| if (!strncasecmp(query_no_space, "SELECT COUNT(*) FROM runtime_mysql_query_rules", strlen("SELECT COUNT(*) FROM runtime_mysql_query_rules")) || | ||
| !strncasecmp(query_no_space, "SELECT COUNT(*) FROM runtime_mysql_query_rules_fast_routing", strlen("SELECT COUNT(*) FROM runtime_mysql_query_rules_fast_routing")) || | ||
| !strncasecmp(query_no_space, "SELECT COUNT(*) FROM runtime_mysql_users", strlen("SELECT COUNT(*) FROM runtime_mysql_users")) || | ||
| !strncasecmp(query_no_space, "SELECT COUNT(*) FROM stats_mysql_query_digest", strlen("SELECT COUNT(*) FROM stats_mysql_query_digest")) || | ||
| !strncasecmp(query_no_space, "SELECT * FROM runtime_mysql_query_rules", strlen("SELECT * FROM runtime_mysql_query_rules")) || | ||
| !strncasecmp(query_no_space, "SELECT * FROM runtime_mysql_query_rules_fast_routing", strlen("SELECT * FROM runtime_mysql_query_rules_fast_routing")) || | ||
| !strncasecmp(query_no_space, "SELECT * FROM runtime_mysql_users", strlen("SELECT * FROM runtime_mysql_users")) || | ||
| !strncasecmp(query_no_space, "SELECT * FROM stats_mysql_query_digest", strlen("SELECT * FROM stats_mysql_query_digest"))) { | ||
|
|
||
| //l_free(query_length, query); // ASAN correctly reports a double free | ||
|
|
||
| // Return empty resultset instead of crashing | ||
| SQLite3_result *resultset = new SQLite3_result(1); | ||
| resultset->add_column_definition(SQLITE_TEXT, "COUNT(*)"); | ||
|
|
||
| // Add a single row with 0 for COUNT(*) queries | ||
| SQLite3_row *row = new SQLite3_row(1); | ||
| char *field_val = strdup("0"); | ||
| row->fields[0] = field_val; | ||
| resultset->add_row(row); | ||
|
|
||
| sess->SQLite3_to_MySQL(resultset, error, affected_rows, &sess->client_myds->myprot); | ||
| delete resultset; | ||
| delete row; | ||
| free(field_val); | ||
|
|
||
| run_query = false; | ||
| goto __run_query; | ||
| } | ||
| } | ||
| needs_vacuum = SPA->GenericRefreshStatistics(query_no_space,query_no_space_length, ( sess->session_type == PROXYSQL_SESSION_ADMIN ? true : false ) ); | ||
| } | ||
|
|
||
| #endif // 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
retest this please |
…5221) Root Cause: - During PROXYSQL STOP, modules are restarted multiple times without proper table cleanup - MySQL_HostGroups_Manager and PgSQL_HostGroups_Manager constructors both create tables - In-memory SQLite databases persist across restarts, causing 'table already exists' errors Solution: - Add 'IF NOT EXISTS' clauses to all CREATE TABLE macros in both managers - Applied fix to the actual table definitions used by the code, not commented-out code Files Modified: - include/MySQL_HostGroups_Manager.h: Updated 9 CREATE TABLE macros - include/PgSQL_HostGroups_Manager.h: Updated 4 CREATE TABLE macros Benefits: - Eliminates SQLite error logging during normal PROXYSQL STOP operations - Improves shutdown performance by removing error handling overhead - Cleaner logs without confusing 'table already exists' messages - Maintains data integrity and functionality
- Removed 'pgsql_thread___enable_load_data_local_infile' assignment - This appears to be a MySQL-specific variable that shouldn't be in PgSQL code - Cleans up dead code and improves code clarity
… code - Removed large block of commented-out code (89 lines) - Code contained MySQL-specific logic that doesn't belong in PgSQL module - Removes dead code for SELECT VERSION_COMMENT, SELECT USER(), and LOAD DATA LOCAL INFILE - Improves code readability and reduces maintenance burden
|
|
retest this please |



Summary
This PR fixes SQLite 'table already exists' errors that occur during PROXYSQL STOP operations by adding 'IF NOT EXISTS' clauses to all CREATE TABLE statements. This is part of the broader work for issue #5218 (Verify dependencies between PR #5217 and PR #4960).
Problem (Issue #5221)
During PROXYSQL STOP execution, multiple SQLite errors were logged indicating that tables already exist when there's an attempt to create them:
Context
This fix addresses the table creation errors that were discovered while implementing the dependency verification for issue #5218. The errors were affecting our ability to properly test PROXYSQL STOP/START functionality with selective module configurations.
Root Cause
The issue is caused by:
Solution
Added 'IF NOT EXISTS' clauses to all CREATE TABLE macros to prevent errors when tables already exist.
Files Changed
Tables Fixed
Benefits
Documentation
Added comprehensive Doxygen documentation explaining:
Testing
Impact
This is a safe, low-risk fix that: