sysown / proxysql

High-performance MySQL proxy with a GPL license.
http://www.proxysql.com
GNU General Public License v3.0
5.93k stars 967 forks source link

Client disconnect with no apparent reason during transaction, kill_query_thread(), COMMIT never issued #3880

Open rickymarini opened 2 years ago

rickymarini commented 2 years ago

Hi Team,

Description: Application is apache Druid, we are trying to remove mysql-router component (used only on RW port) and start using ProxySQL. Publishing segments on the metadata storage (mariadb) tasks is failing. This is not working at all and we didn't found any suitable reason for that, despite trying different combination for multiplexing, transactions, tcp, queries. During the transaction -no matter the configuration- a client disconnect is performed right before the COMMIT. Application is connecting through mariadb-java-client-2.7.3 , proxysql is running on a k8s container (as mysql-router currently is). No endpoint change during switch between the two components, we operated them on the same socket. I also tested some RW transaction using standard mysql client with similar patterns, and everything seems ok. For matter of simplification I've reduced the configuration to the minimum, keeping one single catching rule for queries, and keeping safe defaults. Also some information have been stripped or and changed with ___placeholders___. Please note that backend servers are correctly being discovered and are ONLINE in a stable manner. For what we can understand through a bit of reverse engineering, proxySQL is quitting before sending COMMIT.

proxysql docker image: 2.3.2-10-g8cd66cf, 2.3.1, 2.4.1, latest client: mariadb-java-client-2.7.3

Exception raised by application:

2022-05-17T11:56:15.288+0000 WARN [qtp290991542-223] org.apache.druid.indexing.overlord.http.OverlordResource - Failed to perform task action
java.lang.RuntimeException: org.skife.jdbi.v2.exceptions.CallbackFailedException: org.skife.jdbi.v2.exceptions.UnableToManipulateTransactionIsolationLevelException: Unable to set isolation level to 2
...
org.apache.druid.indexing.common.actions.SegmentTransactionalInsertAction.perform(SegmentTransactionalInsertAction.java:
Caused by: org.skife.jdbi.v2.exceptions.CallbackFailedException: org.skife.jdbi.v2.exceptions.UnableToManipulateTransactionIsolationLevelException: Unable to set isolation level to 2
...
Caused by: org.skife.jdbi.v2.exceptions.UnableToManipulateTransactionIsolationLevelException: Unable to set isolation level to 2
    at org.skife.jdbi.v2.BasicHandle.setTransactionIsolation(BasicHandle.java:450) ~[jdbi-2.63.1.jar:2.63.1]
...
Caused by: java.sql.SQLNonTransientConnectionException: (conn=584) (conn=584) Connection is closed
    at org.mariadb.jdbc.internal.util.exceptions.ExceptionFactory.createException(ExceptionFactory.java:73) ~[?:?]
...
Caused by: java.sql.SQLNonTransientConnectionException: (conn=584) Connection is closed
    at org.mariadb.jdbc.internal.util.exceptions.ExceptionFactory.createException(ExceptionFactory.java:73) ~[?:?]

ProxySQL variables

+----------------------------------------------------------------------+-----------------------------+
| variable_name                                                        | variable_value              |
+----------------------------------------------------------------------+-----------------------------+
| mysql-default_charset                                                | utf8                        |
| mysql-default_collation_connection                                   | utf8_general_ci             |
| mysql-shun_on_failures                                               | 5                           |
| mysql-shun_recovery_time_sec                                         | 10                          |
| mysql-query_retries_on_failure                                       | 1                           |
| mysql-client_multi_statements                                        | true                        |
| mysql-client_host_cache_size                                         | 0                           |
| mysql-client_host_error_counts                                       | 0                           |
| mysql-connect_retries_on_failure                                     | 10                          |
| mysql-connect_retries_delay                                          | 1                           |
| mysql-connection_delay_multiplex_ms                                  | 0                           |
| mysql-connection_max_age_ms                                          | 0                           |
| mysql-connect_timeout_client                                         | 10000                       |
| mysql-connect_timeout_server                                         | 1000                        |
| mysql-connect_timeout_server_max                                     | 10000                       |
| mysql-enable_client_deprecate_eof                                    | true                        |
| mysql-enable_server_deprecate_eof                                    | true                        |
| mysql-enable_load_data_local_infile                                  | false                       |
| mysql-eventslog_filename                                             |                             |
| mysql-eventslog_filesize                                             | 104857600                   |
| mysql-eventslog_default_log                                          | 0                           |
| mysql-eventslog_format                                               | 1                           |
| mysql-auditlog_filename                                              |                             |
| mysql-auditlog_filesize                                              | 104857600                   |
| mysql-handle_unknown_charset                                         | 1                           |
| mysql-free_connections_pct                                           | 10                          |
| mysql-connection_warming                                             | false                       |
| mysql-session_idle_ms                                                | 1                           |
| mysql-have_ssl                                                       | false                       |
| mysql-have_compress                                                  | true                        |
| mysql-client_found_rows                                              | true                        |
| mysql-log_mysql_warnings_enabled                                     | false                       |
| mysql-monitor_enabled                                                | true                        |
| mysql-monitor_history                                                | 600000                      |
| mysql-monitor_connect_interval                                       | 120000                      |
| mysql-monitor_connect_timeout                                        | 600                         |
| mysql-monitor_ping_interval                                          | 8000                        |
| mysql-monitor_ping_max_failures                                      | 3                           |
| mysql-monitor_ping_timeout                                           | 1000                        |
| mysql-monitor_read_only_interval                                     | 1000                        |
| mysql-monitor_read_only_timeout                                      | 800                         |
| mysql-monitor_read_only_max_timeout_count                            | 3                           |
| mysql-monitor_replication_lag_interval                               | 10000                       |
| mysql-monitor_replication_lag_timeout                                | 1000                        |
| mysql-monitor_replication_lag_count                                  | 1                           |
| mysql-monitor_groupreplication_healthcheck_interval                  | 5000                        |
| mysql-monitor_groupreplication_healthcheck_timeout                   | 800                         |
| mysql-monitor_groupreplication_healthcheck_max_timeout_count         | 3                           |
| mysql-monitor_groupreplication_max_transactions_behind_count         | 3                           |
| mysql-monitor_groupreplication_max_transactions_behind_for_read_only | 1                           |
| mysql-monitor_galera_healthcheck_interval                            | 5000                        |
| mysql-monitor_galera_healthcheck_timeout                             | 800                         |
| mysql-monitor_galera_healthcheck_max_timeout_count                   | 3                           |
| mysql-monitor_replication_lag_use_percona_heartbeat                  |                             |
| mysql-monitor_query_interval                                         | 60000                       |
| mysql-monitor_query_timeout                                          | 100                         |
| mysql-monitor_slave_lag_when_null                                    | 60                          |
| mysql-monitor_threads_min                                            | 8                           |
| mysql-monitor_threads_max                                            | 128                         |
| mysql-monitor_threads_queue_maxsize                                  | 128                         |
| mysql-monitor_wait_timeout                                           | true                        |
| mysql-monitor_writer_is_also_reader                                  | true                        |
| mysql-max_allowed_packet                                             | 67108864                    |
| mysql-tcp_keepalive_time                                             | 0                           |
| mysql-automatic_detect_sqli                                          | false                       |
| mysql-firewall_whitelist_enabled                                     | false                       |
| mysql-firewall_whitelist_errormsg                                    | Firewall blocked this query |
| mysql-throttle_connections_per_sec_to_hostgroup                      | 1000000                     |
| mysql-max_transaction_idle_time                                      | 14400000                    |
| mysql-max_transaction_time                                           | 14400000                    |
| mysql-multiplexing                                                   | true                        |
| mysql-log_unhealthy_connections                                      | true                        |
| mysql-enforce_autocommit_on_reads                                    | false                       |
| mysql-autocommit_false_not_reusable                                  | false                       |
| mysql-autocommit_false_is_transaction                                | false                       |
| mysql-hostgroup_manager_verbose                                      | 1                           |
| mysql-binlog_reader_connect_retry_msec                               | 3000                        |
| mysql-threshold_query_length                                         | 524288                      |
| mysql-threshold_resultset_size                                       | 4194304                     |
| mysql-query_digests_max_digest_length                                | 2048                        |
| mysql-query_digests_max_query_length                                 | 65000                       |
| mysql-query_digests_grouping_limit                                   | 3                           |
| mysql-wait_timeout                                                   | 28800000                    |
| mysql-throttle_max_bytes_per_second_to_client                        | 0                           |
| mysql-throttle_ratio_server_to_client                                | 0                           |
| mysql-max_connections                                                | 10000                       |
| mysql-max_stmts_cache                                                | 10000                       |
| mysql-mirror_max_concurrency                                         | 16                          |
| mysql-mirror_max_queue_length                                        | 32000                       |
| mysql-default_max_latency_ms                                         | 1000                        |
| mysql-default_query_delay                                            | 0                           |
| mysql-default_query_timeout                                          | 86400000                    |
| mysql-query_processor_iterations                                     | 0                           |
| mysql-query_processor_regex                                          | 1                           |
| mysql-set_query_lock_on_hostgroup                                    | 1                           |
| mysql-reset_connection_algorithm                                     | 2                           |
| mysql-auto_increment_delay_multiplex                                 | 5                           |
| mysql-long_query_time                                                | 1000                        |
| mysql-query_cache_size_MB                                            | 256                         |
| mysql-ping_interval_server_msec                                      | 10000                       |
| mysql-ping_timeout_server                                            | 200                         |
| mysql-default_schema                                                 | information_schema          |
| mysql-poll_timeout                                                   | 2000                        |
| mysql-poll_timeout_on_failure                                        | 100                         |
| mysql-keep_multiplexing_variables                                    | tx_isolation,version        |
| mysql-kill_backend_connection_when_disconnect                        | true                        |
| mysql-client_session_track_gtid                                      | true                        |
| mysql-sessions_sort                                                  | true                        |
| mysql-session_idle_show_processlist                                  | true                        |
| mysql-show_processlist_extended                                      | 0                           |
| mysql-commands_stats                                                 | true                        |
| mysql-query_digests                                                  | true                        |
| mysql-query_digests_lowercase                                        | false                       |
| mysql-query_digests_replace_null                                     | false                       |
| mysql-query_digests_no_digits                                        | false                       |
| mysql-query_digests_normalize_digest_text                            | false                       |
| mysql-query_digests_track_hostname                                   | false                       |
| mysql-servers_stats                                                  | true                        |
| mysql-default_reconnect                                              | true                        |
| mysql-ssl_p2s_ca                                                     |                             |
| mysql-ssl_p2s_capath                                                 |                             |
| mysql-ssl_p2s_cert                                                   |                             |
| mysql-ssl_p2s_key                                                    |                             |
| mysql-ssl_p2s_cipher                                                 |                             |
| mysql-ssl_p2s_crl                                                    |                             |
| mysql-ssl_p2s_crlpath                                                |                             |
| mysql-stacksize                                                      | 1048576                     |
| mysql-threads                                                        | 4                           |
| mysql-init_connect                                                   |                             |
| mysql-ldap_user_variable                                             |                             |
| mysql-add_ldap_user_comment                                          |                             |
| mysql-default_session_track_gtids                                    | OFF                         |
| mysql-connpoll_reset_queue_length                                    | 50                          |
| mysql-min_num_servers_lantency_awareness                             | 1000                        |
| mysql-aurora_max_lag_ms_only_read_from_replicas                      | 2                           |
| mysql-stats_time_backend_query                                       | false                       |
| mysql-stats_time_query_processor                                     | false                       |
| mysql-query_cache_stores_empty_result                                | true                        |
| mysql-interfaces                                                     | 0.0.0.0:6446                |
| mysql-server_version                                                 | 8.0.19                      |
| mysql-verbose_query_error                                            | true                        |
| mysql-use_tcp_keepalive                                              | true                        |
| mysql-max_stmts_per_connection                                       | 1024                        |
| mysql-default_tx_isolation                                           | REPEATABLE-READ             |
| mysql-server_capabilities                                            | 569899                      |
+----------------------------------------------------------------------+-----------------------------+

Logfile:

2022-05-17 14:21:46 [INFO] Using config file /var/lib/proxysql/proxysql.cfg
2022-05-17 14:21:46 [INFO] Current RLIMIT_NOFILE: 65535
2022-05-17 14:21:46 [INFO] Using OpenSSL version: OpenSSL 1.1.1j  16 Feb 2021
2022-05-17 14:21:46 [INFO] No SSL keys/certificates found in datadir (/var/lib/proxysql). Generating new keys/certificates.
2022-05-17 14:21:46 [INFO] ProxySQL version 2.3.2-10-g8cd66cf
2022-05-17 14:21:46 [INFO] Detected OS: Linux proxysql-c659879b6-8ntwn 3.10.0-1160.31.1.el7.x86_64 #1 SMP Wed May 26 20:18:08 UTC 2021 x86_64
2022-05-17 14:21:46 [INFO] ProxySQL SHA1 checksum: 02bd28227ad712af37c9a1afcf9b72eecf7eb2f6
2022-05-17 14:21:46 [INFO] Loaded built-in SQLite3
Standard ProxySQL MySQL Logger rev. 2.0.0714 -- MySQL_Logger.cpp -- Thu Sep 30 21:22:46 2021
Standard ProxySQL Cluster rev. 0.4.0906 -- ProxySQL_Cluster.cpp -- Thu Sep 30 21:22:46 2021
Standard ProxySQL Statistics rev. 1.4.1027 -- ProxySQL_Statistics.cpp -- Thu Sep 30 21:22:46 2021
Standard ProxySQL HTTP Server Handler rev. 1.4.1031 -- ProxySQL_HTTP_Server.cpp -- Thu Sep 30 21:22:46 2021
2022-05-17 14:21:46 ProxySQL_Admin.cpp:6161:flush_mysql_variables___database_to_runtime(): [WARNING] Impossible to set variable server_capabilities with value "569867". Resetting to current "569899".
....
2022-05-17 14:21:47 [INFO] Dumping mysql_servers: ALL
+-----+----------------------------------------------------------------------------+------+------+--------+--------+-----+-----------+---------+-----+---------+---------+-----------------+
| hid | hostname                                                                   | port | gtid | weight | status | cmp | max_conns | max_lag | ssl | max_lat | comment | mem_pointer     |
+-----+----------------------------------------------------------------------------+------+------+--------+--------+-----+-----------+---------+-----+---------+---------+-----------------+
| 10  | server-2.example.net | 3306 | 0    | 1      | 0      | 0   | 1500      | 0       | 0   | 0       |         | 139839272674560 |
| 20  | server-1.example.net | 3306 | 0    | 1      | 0      | 0   | 1500      | 0       | 0   | 0       |         | 139839110767712 |
| 20  | server-0.example.net | 3306 | 0    | 1      | 0      | 0   | 1500      | 0       | 0   | 0       |         | 139839110767552 |
+-----+----------------------------------------------------------------------------+------+------+--------+--------+-----+-----------+---------+-----+---------+---------+-----------------+
2022-05-17 14:21:48 [INFO] Regenerating read_only_set1 with 1 servers
2022-05-17 14:21:48 [INFO] read_only_action() detected RO=0 on server server-2.example.net:3306 for the first time after commit(), but no need to reconfigure
2022-05-17 14:22:45 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.0.0.2 . Session_status: 6 , client_status: -1 Disconnecting it
2022-05-17 14:22:45 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.0.0.2 . Session_status: 6 , client_status: -1 Disconnecting it
2022-05-17 14:22:45 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.0.0.2 . Session_status: 6 , client_status: 10682367 Disconnecting it
2022-05-17 14:22:45 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.0.0.2 . Session_status: 6 , client_status: 10682367 Disconnecting it
2022-05-17 14:22:54 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.0.0.2 . Session_status: 6 , client_status: 10682367 Disconnecting it
2022-05-17 14:23:03 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.0.0.2 . Session_status: 6 , client_status: 1280 Disconnecting it
2022-05-17 14:23:10 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.0.0.2 . Session_status: 6 , client_status: -1 Disconnecting it
2022-05-17 14:23:17 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.0.0.1 . Session_status: 6 , client_status: -1414812757 Disconnecting it
2022-05-17 14:23:32 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.0.0.1 . Session_status: 6 , client_status: 10682367 Disconnecting it
2022-05-17 14:23:35 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.0.0.1 . Session_status: 6 , client_status: -1 Disconnecting it
2022-05-17 14:23:37 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.0.0.1 . Session_status: 6 , client_status: 0 Disconnecting it
2022-05-17 14:23:42 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.0.0.1 . Session_status: 6 , client_status: 10682367 Disconnecting it
2022-05-17 14:23:48 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.0.0.1 . Session_status: 6 , client_status: 10682367 Disconnecting it
2022-05-17 14:23:58 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.0.0.1 . Session_status: 6 , client_status: 10682367 Disconnecting it
2022-05-17 14:23:58 MySQL_Session.cpp:149:kill_query_thread(): [WARNING] KILL CONNECTION 33655 on server-2.example.net:3306
2022-05-17 14:24:01 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.0.0.1 . Session_status: 6 , client_status: 10682367 Disconnecting it
2022-05-17 14:24:17 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.0.0.1 . Session_status: 6 , client_status: 10682367 Disconnecting it
2022-05-17 14:24:17 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.0.0.1 . Session_status: 6 , client_status: 10682367 Disconnecting it
2022-05-17 14:24:26 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.0.0.1 . Session_status: 6 , client_status: 10682367 Disconnecting it
2022-05-17 14:24:27 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.0.0.1 . Session_status: 6 , client_status: 0 Disconnecting it
2022-05-17 14:24:32 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.0.0.1 . Session_status: 6 , client_status: 0 Disconnecting it
2022-05-17 14:24:33 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.0.0.1 . Session_status: 6 , client_status: 10682367 Disconnecting it
2022-05-17 14:24:39 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.0.0.2 . Session_status: 6 , client_status: 10682367 Disconnecting it
2022-05-17 14:24:41 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.0.0.1 . Session_status: 6 , client_status: 11 Disconnecting it

Configuration:

admin_variables=
{
    admin_credentials="___ADMIN_USER___:___ADMIN_PASS___"
    mysql_ifaces="0.0.0.0:6032"
}

mysql_variables=
{

    interfaces="0.0.0.0:6446"
    server_version="8.0.19"
    monitor_username="___MONITOR_USER___"
    monitor_password="___MONITOR_PASS___"
}
mysql_users =
(
  { username = "___USER___" , password = "___PASS___" , default_hostgroup = 10 , active = 1 },
)

mysql_replication_hostgroups =
(
  { writer_hostgroup=10, reader_hostgroup=20, comment="dummy_comment" }
)

mysql_servers =
(
  { address="__SERVER0__" , port=3306 , hostgroup=10, max_connections=1500 },
  { address="__SERVER1__" , port=3306 , hostgroup=10, max_connections=1500 },
  { address="__SERVER2__" , port=3306 , hostgroup=10, max_connections=1500 },
)

mysql_query_rules =
(
  {
    rule_id=300
    active=1
    match_pattern=".*"
    destination_hostgroup=10
    apply=1
  }
)

Tcpdump session of what ProxySQL try to do

Screenshot 2022-05-17 at 14 37 48

Tcpdump session of what mysql-router does

Screenshot 2022-05-17 at 14 45 07

Statements logged on MARIADB with ProxySQL, for relevant thread

| 2022-05-17 16:20:03.36691  | Query        | SET sql_select_limit=DEFAULT                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| 2022-05-17 16:20:03.367178 | Query        | SELECT 1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| 2022-05-17 16:20:03.385452 | Query        | SET sql_select_limit=1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| 2022-05-17 16:20:03.385885 | Query        | SELECT payload FROM druid_tasks WHERE id = ..                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| 2022-05-17 16:20:04.938141 | Query        | SET sql_select_limit=DEFAULT                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| 2022-05-17 16:20:04.938435 | Query        | SELECT 1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| 2022-05-17 16:20:04.947961 | Query        | SELECT @@transaction_isolation                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| 2022-05-17 16:20:04.957949 | Query        | SELECT @@transaction_isolation                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| 2022-05-17 16:20:04.977933 | Query        | SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| 2022-05-17 16:20:04.978217 | Query        | SELECT @@transaction_isolation                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| 2022-05-17 16:20:04.987662 | Query        | SELECT @@transaction_isolation                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| 2022-05-17 16:20:05.006462 | Query        | SELECT commit_metadata_payload FROM druid_dataSource WHERE dataSource = ..                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| 2022-05-17 16:20:05.016772 | Query        | SET autocommit=0   ..                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| 2022-05-17 16:20:05.01712  | Query        | UPDATE druid_dataSource SET commit_metadata_payload ..
| 2022-05-17 16:20:05.026547 | Query        | SELECT id FROM druid_segments WHERE id in      ..                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| 2022-05-17 16:20:05.036511 | Query        | INSERT INTO druid_segments (id, dataSource, created_date, start, `end`, partitioned, version, used, payload) VALUES .. |
| 2022-05-17 16:20:05.03781  | Quit         |

Statements logged on MARIADB with mysql router, for relevant thread

| 2022-05-17 16:48:44.222221 | Query        | SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| 2022-05-17 16:48:44.230159 | Query        | SELECT 1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| 2022-05-17 16:48:44.237561 | Query        | SELECT @@transaction_isolation                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| 2022-05-17 16:48:44.245087 | Query        | SELECT @@transaction_isolation                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| 2022-05-17 16:48:44.251995 | Query        | SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| 2022-05-17 16:48:44.258784 | Query        | SELECT @@transaction_isolation                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| 2022-05-17 16:48:44.266035 | Query        | SELECT @@transaction_isolation                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| 2022-05-17 16:48:44.273698 | Query        | set autocommit=0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| 2022-05-17 16:48:44.281933 | Query        | SELECT commit_metadata_payload FROM druid_dataSource WHERE dataSource = ..                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| 2022-05-17 16:48:44.29115  | Query        | UPDATE druid_dataSource SET commit_metadata_payload = .. |
| 2022-05-17 16:48:44.301094 | Query        | SELECT id FROM druid_segments WHERE id in ..                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| 2022-05-17 16:48:44.312189 | Query        | INSERT INTO druid_segments (id, dataSource, created_date, start, `end`, partitioned, version, used, payload) VALUES .. |
| 2022-05-17 16:48:44.322931 | Query        | COMMIT                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
rickymarini commented 2 years ago

Hi @renecannao and Team would be great to have your opinion on this. Many thanks

renecannao commented 2 years ago

Hi @rickymarini . Thank you for the detailed report, I really apreciate the level of details.

You provided the tcpdump session between proxysql and the database server: thanks for that. Can you please provide also the tcpdump of the traffic between the client and proxysql, and again between proxysql and the database server? From proxysql's error log I suspect the client is sending a COMMIT without waiting the OK after sending the INSERT.

Also, since you are using a private network (10.x) , can you please not obfuscate the full IP address, so it makes easier to understand who originates the packet? Again, 10.x is a private network, so there is no security concern in making this information public.

Thanks

rickymarini commented 2 years ago

Hi @renecannao , thanks for looking at this. The tcpdump session I provided is already between client and proxysql (port 2035). Unluckily I am unable to get a trace between proxysql and backend since we don't have permission to do that on k8s network (db's and proxysql are hosted there). For that reason I enabled query logging on db's and provided queries that actually reach the final db instance. I did some further analysis and I see that the problem may be also related to JDBC DBCP datasource. As far as I understand, having client application that is doing pooling, and also having it proxysql side may create some problems. I read some bug report specific to this setup, involving Druid application. I tried to set fast_forward to true for user, but then the error I got is

Caused by: java.sql.SQLNonTransientConnectionException: Could not connect to address=(host=mysql-router.app-test.example.net)(port=2035)(type=master) : unexpected end of stream, read 0 bytes from 4 (socket was closed by server)

This is the tcpdump trace with actual IP addresses. From client to proxySQL. Capture is on port 2035, the external port we use to connect proxysql or mysql-router.

image

additional detail Everything works fine for ~20 minutes using defaults, then transaction problem starts and keeps popping every few seconds. Seems like the client become stuck in it. I observed that the client is logging a different connection id each and every time.

Caused by: org.skife.jdbi.v2.exceptions.CallbackFailedException: org.skife.jdbi.v2.exceptions.UnableToManipulateTransactionIsolationLevelException: Unable to set isolation level to 2
Caused by: org.skife.jdbi.v2.exceptions.UnableToManipulateTransactionIsolationLevelException: Unable to set isolation level to 2
Caused by: java.sql.SQLNonTransientConnectionException: (conn=700) (conn=700) Connection is closed
Caused by: java.sql.SQLNonTransientConnectionException: (conn=700) Connection is closed
Caused by: org.skife.jdbi.v2.exceptions.CallbackFailedException: org.skife.jdbi.v2.exceptions.UnableToManipulateTransactionIsolationLevelException: Unable to set isolation level to 2
Caused by: org.skife.jdbi.v2.exceptions.UnableToManipulateTransactionIsolationLevelException: Unable to set isolation level to 2
Caused by: java.sql.SQLNonTransientConnectionException: (conn=704) (conn=704) Connection is closed
Caused by: java.sql.SQLNonTransientConnectionException: (conn=704) Connection is closed
Caused by: org.skife.jdbi.v2.exceptions.CallbackFailedException: org.skife.jdbi.v2.exceptions.UnableToManipulateTransactionIsolationLevelException: Unable to set isolation level to 2
Caused by: org.skife.jdbi.v2.exceptions.UnableToManipulateTransactionIsolationLevelException: Unable to set isolation level to 2
Caused by: java.sql.SQLNonTransientConnectionException: (conn=698) (conn=698) Connection is closed
Caused by: java.sql.SQLNonTransientConnectionException: (conn=698) Connection is closed

while proxysql logs is like

2022-05-24 11:26:38 MySQL_Session.cpp:149:kill_query_thread(): [WARNING] KILL CONNECTION 76219 on server-2.example.net:3306
2022-05-24 11:26:39 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.222.10.5 . Session_status: 6 , client_status: 10682367 Disconnecting it
2022-05-24 11:26:39 MySQL_Session.cpp:149:kill_query_thread(): [WARNING] KILL CONNECTION 76222 on server-2.example.net:3306
2022-05-24 11:26:40 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.222.10.5 . Session_status: 6 , client_status: 10682367 Disconnecting it
2022-05-24 11:26:40 MySQL_Session.cpp:149:kill_query_thread(): [WARNING] KILL CONNECTION 76224 on server-2.example.net:3306
2022-05-24 11:26:44 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.222.10.5 . Session_status: 6 , client_status: 11 Disconnecting it
2022-05-24 11:26:45 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.222.10.5 . Session_status: 6 , client_status: 0 Disconnecting it
2022-05-24 11:26:48 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.222.10.5 . Session_status: 6 , client_status: 10682367 Disconnecting it
2022-05-24 11:26:53 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.222.10.5 . Session_status: 6 , client_status: 10682367 Disconnecting it
2022-05-24 11:26:54 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.222.10.5 . Session_status: 6 , client_status: 0 Disconnecting it
2022-05-24 11:26:55 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.222.10.5 . Session_status: 6 , client_status: 10682367 Disconnecting it
2022-05-24 11:26:55 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.222.10.4 . Session_status: 6 , client_status: 10682367 Disconnecting it
2022-05-24 11:27:01 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.222.10.4 . Session_status: 6 , client_status: 0 Disconnecting it
2022-05-24 11:27:01 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.222.10.4 . Session_status: 6 , client_status: 10682367 Disconnecting it
2022-05-24 11:27:04 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.222.10.4 . Session_status: 6 , client_status: 10682367 Disconnecting it
2022-05-24 11:27:05 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.222.10.4 . Session_status: 6 , client_status: 10682367 Disconnecting it
2022-05-24 11:27:07 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.222.10.5 . Session_status: 6 , client_status: 11 Disconnecting it
2022-05-24 11:27:07 MySQL_Session.cpp:149:kill_query_thread(): [WARNING] KILL CONNECTION 76231 on server-2.example.net:3306
2022-05-24 11:27:07 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.222.10.5 . Session_status: 6 , client_status: 10682367 Disconnecting it
2022-05-24 11:27:08 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.222.10.5 . Session_status: 6 , client_status: 10682367 Disconnecting it
2022-05-24 11:27:08 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.222.10.5 . Session_status: 6 , client_status: 10682367 Disconnecting it
2022-05-24 11:27:10 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.222.10.5 . Session_status: 6 , client_status: 10682367 Disconnecting it
2022-05-24 11:27:11 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.222.10.5 . Session_status: 6 , client_status: 10682367 Disconnecting it
2022-05-24 11:27:12 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.222.10.5 . Session_status: 6 , client_status: 10682367 Disconnecting it
2022-05-24 11:27:13 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.222.10.5 . Session_status: 6 , client_status: 11 Disconnecting it
2022-05-24 11:27:18 MySQL_Session.cpp:3364:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.222.10.5 . Session_status: 6 , client_status: 11 Disconnecting it
2022-05-24 11:27:18 MySQL_Session.cpp:149:kill_query_thread(): [WARNING] KILL CONNECTION 76240 on server-2.example.net:3306
2022-05-24 11:27:18 MySQL_Thread.cpp:3751:process_all_sessions(): [WARNING] Closing unhealthy client connection 10.222.15.175:60822

Problem start as soon as the first kill_query_thread message is issued. In this example after ~20 minutes

rickymarini commented 2 years ago

complete tcpdump session executed on proxysql k8s container (ip masked) seems like for some reason proxy is not sending COMMIT after asking for autocommit=0 or anyway not finishing the transaction properly right after INSERT.

What you think @renecannao it is a bug? I tried almost any setup without luck

Screenshot 2022-05-30 at 19 07 13
renecannao commented 2 years ago

From my comment 7 days ago:

From proxysql's error log I suspect the client is sending a COMMIT without waiting the OK after sending the INSERT.

tcpdump seems to confirm this. In the last screenshot, the client sent 3 INSERT statements without waiting any OK. At the end of the 1st INSERT , proxysql tries to send the OK packet to the client, but finds more data waiting in the socket, returning an error Unexpected packet from client . The MySQL Protocol allows this, while proxysql doesn't support this batching method. ProxySQL's internal state machine requires that a statement needs to complete before a new one is received.

This clearly seems a limitation in ProxySQL. Meanwhile, can you disable any sort of batching used by the application?

Thanks

rickymarini commented 2 years ago

@renecannao thanks! application is using mariadb JDBC, and for what I can see from the java source code it is making use of batching. Tried to set:

rewriteBatchedStatements=true

On the jdbc URL string but it breaks proxysql this way:

...
2022-05-31 09:42:12 MySQL_Session.cpp:7401:unable_to_parse_set_statement(): [WARNING] Unable to parse unknown SET query from client 10.222.10.4:47400. Setting lock_hostgroup. Please report a bug for future enhancements:set autocommit=1, session_track_schema=1, session_track_system_variables='auto_increment_increment' , sql_mode = concat(@@sql_mode,',STRICT_TRANS_TABLES')
2022-05-31 09:42:12 MySQL_Session.cpp:3471:handler___status_NONE_or_default(): [ERROR] Unexpected packet from client 10.222.10.4 . Session_status: 6 , client_status: -1414812757 Disconnecting it
2022-05-31 09:42:22 MySQL_Session.cpp:7401:unable_to_parse_set_statement(): [WARNING] Unable to parse unknown SET query from client 10.222.10.4:48268. Setting lock_hostgroup. Please report a bug for future enhancements:set autocommit=1, session_track_schema=1, session_track_system_variables='auto_increment_increment' , sql_mode = concat(@@sql_mode,',STRICT_TRANS_TABLES')
...

Now I am testing useBatchMultiSend=false , will inform about outcome.

renecannao commented 2 years ago

Hi @rickymarini . ProxySQL's doesn't send tracked variables to the client, so I suggest to completely remove session_track_system_variables='auto_increment_increment' because it has no real effect.

About batching, we are evaluating internally how to implement it and its limitation: stay tuned.

Thanks

rickymarini commented 2 years ago

Hi @renecannao , I confirm that setting useBatchMultiSend=false on jdbc works. Now we can effort to migrate test and pre-prod environment. We still need to understand impact for prod as this application may require batching to be efficient, and since it use up to 100 insert in a shot, we can have a potential perf. issue (but we will measure this) .

When you say

ProxySQL's doesn't send tracked variables to the client, so I suggest to completely remove

You mean to query rewrite it through a rule (cannot modify code)? I think that rewriteBatchedStatements=true is promising as an option, since it allows to rewrite multiple statements in a single one but unable to test due to SET command issue

renecannao commented 2 years ago

I confirm that setting useBatchMultiSend=false on jdbc works. Now we can effort to migrate test and pre-prod environment.

Good to hear that!

We still need to understand impact for prod as this application may require batching to be efficient, and since it use up to 100 insert in a shot, we can have a potential perf. issue (but we will measure this) .

If the application wants to boost performance should not use "batching inserts" (I am not sure this is the right term), but multi-rows INSERT. If you follow the math described in MySQL documentation on Optimizing INSERT Statements , you will agree with me that sending 100 INSERTs in a shot will only solve the network latency: if you really want to improve performance you need to use multi-rows INSERTs.

You mean to query rewrite it through a rule (cannot modify code)?

Yes. Something like this:

INSERT INTO mysql_query_rules (active,match_pattern,replace_pattern)
VALUES
(1,"session_track_system_variables='auto_increment_increment' ,","");
rickymarini commented 2 years ago

Thanks again @renecannao The rewrite rule works and application is now starting, but no luck with rewriteBatchedStatements=true as I got an exception on the batch insert section, then application is firing ROLLBACK. ProxySQL log is clean and there is nothing strange happening in the logs, I think forcing the driver to do rewrite somehow breaks the application logic, also not clear why he sends different SET parameters with the option turned on. However, I thought batch packet was too big, but statement seems to be complete and packet way below the configured size threshold.

Screenshot 2022-05-31 at 14 25 12

I think it's related to how application expects to validate the INSERT, the packet with OK answer from proxySQL is now reporting 2 affectedRows, while application wants to validate in a different way and expects 1 for each and every statement?

        final int[] affectedRows = preparedBatch.execute();
        final boolean succeeded = Arrays.stream(affectedRows).allMatch(eachAffectedRows -> eachAffectedRows == 1);
        if (succeeded) {
          log.infoSegments(partition, "Published segments to DB");
        } else {
          final List<DataSegment> failedToPublish = IntStream.range(0, partition.size())
              .filter(i -> affectedRows[i] != 1)
              .mapToObj(partition::get)
              .collect(Collectors.toList());
          throw new ISE(
              "Failed to publish segments to DB: %s",
              SegmentUtils.commaSeparatedIdentifiers(failedToPublish)
          );
renecannao commented 2 years ago

From your description it seems that the application doesn't like to use multi-rows INSERTs, because it validates that each INSERT inserts only 1 row. This doesn't seem a smart check :thinking:

rickymarini commented 2 years ago

Yes I also think is trying to do like that, I' ll post a bug on their Github, as they are unintentionally breaking an allowed jdbc behaviour. For now I think useBatchMultiSend=false could be our solution, until you do something proxysql side to better support batching.

Thanks a lot for the support and feel free to comment again if you need some feature testing @renecannao

arun4a commented 2 years ago

Hi @rickymarini and @renecannao , as of now, to execute any batch statements from JDBC through proxysql server. Apart from the changing url parameters, is there any configuration we can do from proxysql ?

rickymarini commented 2 years ago

Hi @rickymarini and @renecannao , as of now, to execute any batch statements from JDBC through proxysql server. Apart from the changing url parameters, is there any configuration we can do from proxysql ?

As far as I understood, no, not today. They are evaluating if worthwhile to implement batching support in proxysql. As today, you need to change jdbc properties to alter how batched statements are sent to the proxy

arun4a commented 2 years ago

Hi @rickymarini and @renecannao , as of now, to execute any batch statements from JDBC through proxysql server. Apart from the changing url parameters, is there any configuration we can do from proxysql ?

As far as I understood, no, not today. They are evaluating if worthwhile to implement batching support in proxysql. As today, you need to change jdbc properties to alter how batched statements are sent to the proxy

Thanks for the response. Ok continue as you suggested

arun4a commented 2 years ago

HI @renecannao and @rickymarini,

Is proxysql support High availability ? For example, if master server(write) goes down, can proxysql route request to other slave node(write) .

ThomasVerhoeven1998 commented 9 months ago

I confirm that setting useBatchMultiSend=false on jdbc works. Now we can effort to migrate test and pre-prod environment.

Good to hear that!

We still need to understand impact for prod as this application may require batching to be efficient, and since it use up to 100 insert in a shot, we can have a potential perf. issue (but we will measure this) .

If the application wants to boost performance should not use "batching inserts" (I am not sure this is the right term), but multi-rows INSERT. If you follow the math described in MySQL documentation on Optimizing INSERT Statements , you will agree with me that sending 100 INSERTs in a shot will only solve the network latency: if you really want to improve performance you need to use multi-rows INSERTs.

You mean to query rewrite it through a rule (cannot modify code)?

Yes. Something like this:

INSERT INTO mysql_query_rules (active,match_pattern,replace_pattern)
VALUES
(1,"session_track_system_variables='auto_increment_increment' ,","");

@renecannao Is there a fix in a new version for this work around?

renecannao commented 9 months ago

@ThomasVerhoeven1998 , there is a POC to support this JDBC capabilities , yet we believe that:

cocorossello commented 7 months ago

RewriteBatchedStatements was removed in mariadb connector-j 3.0.3, and useBulkStmtsForInserts was introduced.

useBulkStmtsForInserts does not work neither.

It would be very useful if it could work, rewriting the application is not an easy task if there is an ORM in the middle. I can see a performance degradation when turning useBulkStmtsForInserts=false. A batch job that was around 32 seconds now is around 44 seconds.

mwilberg commented 4 months ago

Have read through this thread with great interest with hopes of actually finding a solution to my current predicament - which seems to be similar or nearly identical to that of the original poster.

We have a setup with a 3 node Galera Cluster (MariaDB 10.11.6) on Debian Bookworm - and are trying to set up Service(not exactly)NOW using ProxySQL.

I can connect to the backend servers just fine through ProxySQL, but the application seems to be running some batching of commands that is tossing out the exact same error messages as @rickymarini has documented in his post.

Sadly none of the jdbc-hacks I've seen in here have solved anything for me, and I still can't seem to get the application installed as long as I point the jdbc-url to proxysql

glide.db.properties

# glide.db.properties

glide.db.name = sntest_16000
glide.db.rdbms = mysql 
glide.db.url = jdbc:mariadb://localhost:6033/sntest_16000?usePipeLineAuth=false&disablePipeLine=true&useBatchMultiSend=false
glide.db.user = sntestuser
glide.db.password = SomeLongRandomPassword

If I bypass ProxySQL and enter either one of the Galera nodes in the jdbc-url it works fine, but one of the main reasons I wanted to use ProxySQL in the first place was to be able to use read/write splitting and being able to set up a true HA solution

Another problem is of course that our systems are air gapped and getting any kind of logs and stuff out of there is a total pain in the backside... Would love some more pointers though, if anyone has gotten ServiceNOW to work through ProxySQL

renecannao commented 4 months ago

Hi @mwilberg . Thank you for using ProxySQL . I hope you understand that although we would like to help everyone, the lack of error log and a reproducible test case make investigation almost a no started.

I am not going to imply that it will make any difference, but have you tried to use a different JDBC driver? Also, please try to use the latest version of ProxySQL .

Thanks

mwilberg commented 4 months ago

Hey again @renecannao and of course I appreciate the problem with helping someone who can't be helped ;)

I will try setting up a new test-environment in one of our more accessible zones, and get you some logs to look at. We are running ProxySQL 2.6.1-31-g9d788c0 so I don't think we are too far behind.

Will check out the possibility of trying a different JDBC driver - might be that simple :+1:

cheers

ron-azuelos commented 3 weeks ago

Hi @renecannao , just to be on the safe side. We had the same issue working with mariadb driver (we were unable to write batch inserts without changing the "useBatchMultiSend" value to "false") than we moved to work with MYSQL 8.0.33 driver and it resolved the issue ( the batch worked ) (our proxy works with MariaDB databases) Is there any issue with working that way (mariadb + mysql driver + proxy 2.5.5 + using the batch ) in production environment ?