Skip to content
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

Added warnings handling #4365

Merged
merged 22 commits into from
Dec 8, 2023
Merged

Added warnings handling #4365

merged 22 commits into from
Dec 8, 2023

Conversation

rahim-kanji
Copy link
Collaborator

@rahim-kanji rahim-kanji commented Oct 21, 2023

Resolves Issue#1751

Summary:

When a query is executed, and it generates a warning, the multiplexing feature is temporarily disabled. The status is set to 'has_warnings' and the 'warning_in_hg' is assigned the current host group. If the next query happens to be either 'SHOW WARNINGS' or 'SHOW COUNT(*) FROM WARNINGS', it will be executed on the host group specified in 'warning_in_hg'. However, if any other type of query is executed, multiplexing is re-enabled, and 'warning_in_hg' is reset to -1.

Changes:

  • Implemented 'SHOW WARNINGS' and 'SHOW COUNT(*) FROM WARNINGS' query handling.
  • When a query produces warnings, the warning count is now included in the query response.

For more granular control, a new variable 'mysql-handle_warnings' and 'handling_warnings' flag in the 'mysql_hostgroup_attributes' table ('hostgroup_settings') has been introduced to control warnings handling in ProxySQL:

  • A value of '0' means warnings handling is completely disabled.
  • A value of '1' enables warnings handling as described above.

'handling_warnings' flag holds top priority and can override the value of the global variable 'mysql_handle_warnings'

Additionally, a new variable 'mysql-query_cache_handle_warnings' has been introduced for the query cache feature:

  • A value of '0' means that if a query execution produces warnings, the resultset will not be saved in the query cache.
  • A value of '1' indicates that if a query produces warnings, the resultset will be saved in the query cache, but the warning count in that result set will be set to '0'.

Note:

  • Warning handling is dependent on the query digest and 'mysql-query_digests' must be enabled for it to work.
  • Warnings saved in logfile ['mysql-log_mysql_warnings_enabled'] and the current feature can work in conjunction with each other.
  • This feature will not work correctly if 'mysql-query_digests_keep_comment' is enabled, and 'SHOW WARNINGS' or 'SHOW COUNT(*) FROM WARNINGS' is used with comments.
  • No support for handling 'SELECT @@warning_count'. If this query is executed, multiplexing will be disabled and will remain disabled for that connection.
  • With the exception of a few, all TAP tests are now geared up to log warning count and the query that triggered the warning during its execution.

* Implemented 'SHOW WARNINGS' and 'SHOW COUNT(*) FROM WARNINGS' query handling.
* When a query produces warnings, the warning count is now included in the query response.

Additionally, a new variable 'mysql-query_cache_with_warnings_support' has been introduced for the query cache feature:

* A value of '0' means that if a query execution produces warnings, the resultset will not be saved in the query cache.
* A value of '1' indicates that if a query produces warnings, the resultset will be saved in the query cache, but the warning count in that resultset will be set to '0'.

** Note:
* Warning handling is dependent on the query digest and 'mysql-query_digests' must be enabled for it to work.
* Warnings saved in logfile ['mysql-log_mysql_warnings_enabled'] and the current feature can work in conjunction with each other.
lib/MySQL_Session.cpp Show resolved Hide resolved
lib/MySQL_Session.cpp Show resolved Hide resolved
lib/MySQL_Session.cpp Outdated Show resolved Hide resolved
lib/mysql_connection.cpp Outdated Show resolved Hide resolved
test/tap/tests/test_warnings-t.cpp Outdated Show resolved Hide resolved
test/tap/tests/test_warnings-t.cpp Outdated Show resolved Hide resolved
…' to 'mysql-query_cache_handle_warnings'

* Introduced global variable 'mysql-handle_warnings' to control warning support in ProxySQL
* Included 'handling_warnings' flag in the 'mysql_hostgroup_attributes' table (hostgroup_settings). This flag holds top priority and can override the value of the global variable 'mysql_handle_warnings'.
* 'MySQL_Connection::warning_count' will be globally employed for managing multiplexing control and transmitting the warning count to the client
* Fixed prepare statement bug: When preparing, if the digest matches, the result set is retrieved from the cache and sent to the client.

Note:
Currently using 'mysql_warning_count' to retrieve the warning count for prepared statement.
@kmcphillips
Copy link

I'm not in a position to review this, but just wanted to say we tripped over this issue recently and this fix is exactly what we are looking for. So thank you. 🙏

@rahim-kanji rahim-kanji marked this pull request as draft November 15, 2023 12:34
… disabled.

* Introduced 'ps_type' enum to differentiate between preparing a statement and executing a statement
* Fixed issue where the warning count fails to reset when the SET statement generates a warning.
* Resolved the issue where the 'server_status' and 'warning count' were not accurately represented in the statement.
* Replaced 'mysql_warning_count' with 'mysql_stmt_warning_count' for retrieving the warning count in statements.
* Added 'handle_warning' field in hostgroup_attributes TAP test
* Updated warnings TAP test
@mirostauder
Copy link
Collaborator

retest this please

1 similar comment
@mirostauder
Copy link
Collaborator

retest this please

…ent does not support CLIENT_DEPRECATE_EOF, warning_count will be '0' in intermediate EOF packet.

* Suppress the display of warning counts in the "SHOW WARNINGS" statement.
@mirostauder
Copy link
Collaborator

retest this please

1 similar comment
@mirostauder
Copy link
Collaborator

retest this please

…d print it in the log. This override will apply to all TAP tests, except when the TAP test is linked with the MySQL client library (LIBMYSQL_HELPER defined).

* Avoid closing of same mysql connection twice on error.
* Disabled warning count logging on few TAP tests
* Enable CLIENT_DEPRECATE_EOF on 20% of total mysql connections
…final

# Conflicts:
#	test/tap/tests/set_testing-240-t.cpp
@mirostauder
Copy link
Collaborator

retest this please

@rahim-kanji rahim-kanji marked this pull request as ready for review November 29, 2023 05:21
@rahim-kanji
Copy link
Collaborator Author

retest this please

1 similar comment
@mirostauder
Copy link
Collaborator

retest this please

@renecannao renecannao merged commit 1e98de7 into v2.x Dec 8, 2023
216 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ProxySQL does not propagate database warnings
4 participants