Bug #38419 Can write, but cannot perform selects with rw-splitting
Submitted: 29 Jul 2008 0:06 Modified: 17 Aug 2009 17:09
Reporter: Josh Boyd
Status: Closed
Category:Proxy Severity:S1 (Critical)
Version:0.7.0 - r511 OS:Linux
Assigned to: MC Brown Target Version:
Tags: mysql-proxy
Triage: D1 (Critical)

[29 Jul 2008 0:06] Josh Boyd
Description:
I've compiled and installed mysql-proxy from SVN, I'm on revision 511. I'm able to
connect to my database, perform use/desc/insert, however selects fail with "Lost
connection to MySQL server during query."

Here are the relevant log entries:

2008-07-28 18:00:30: (critical) (read_query) [string
"/usr/local/share/mysql-proxy/rw-splitting.l..."]:218: bad argument #1 to 'ipairs' (table
expected, got userdata)
2008-07-28 18:00:30: (critical) proxy-plugin.c.2495: I have no server backend, closing
connection
2008-07-28 18:00:30: (critical) network-mysqld.c.1092: plugin_call(CON_STATE_READ_QUERY)
failed

Here is my configuration file:
[mysql-proxy]
proxy-backend-addresses=10.254.69.204:3306
proxy-read-only-backend-addresses=10.254.70.48:3306
proxy-address=127.0.0.1:3306
proxy-lua-script=/usr/local/share/mysql-proxy/rw-splitting.lua
pid-file=/var/run/mysql-proxy.pid
log-file=/var/log/mysql-proxy.log
log-level=debug

And here is the command I use to start mysql-proxy:

/usr/local/sbin/mysql-proxy --plugin-dir=/usr/local/lib/mysql-proxy --plugins=debug
--plugins=admin --plugins=proxy --defaults-file=/etc/mysql-proxy.conf --daemon

Any help would be greatly appreciated. I may try going back to 0.6.0 since I had that
working previously, but I'd much rather be operating with all of the latest bug fixes. 

Please let me know if anyone has any workarounds or needs additional data.

Josh

How to repeat:
/etc# mysql -ujosh -p --host 127.0.0.1
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 22
Server version: 5.0.45-Debian_1ubuntu3.3-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> use mysql;
No connection. Trying to reconnect...
Connection id:    23
Current database: *** NONE ***

Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> desc user; 
+-----------------------+-----------------------------------+------+-----+---------+-------+
| Field                 | Type                              | Null | Key | Default |
Extra |
+-----------------------+-----------------------------------+------+-----+---------+-------+
| Host                  | char(60)                          | NO   | PRI |         |     
 | 
| User                  | char(16)                          | NO   | PRI |         |     
 | 
| Password              | char(41)                          | NO   |     |         |     
 | 
| Select_priv           | enum('N','Y')                     | NO   |     | N       |     
 | 
| Insert_priv           | enum('N','Y')                     | NO   |     | N       |     
 | 
| Update_priv           | enum('N','Y')                     | NO   |     | N       |     
 | 
| Delete_priv           | enum('N','Y')                     | NO   |     | N       |     
 | 
| Create_priv           | enum('N','Y')                     | NO   |     | N       |     
 | 
| Drop_priv             | enum('N','Y')                     | NO   |     | N       |     
 | 
| Reload_priv           | enum('N','Y')                     | NO   |     | N       |     
 | 
| Shutdown_priv         | enum('N','Y')                     | NO   |     | N       |     
 | 
| Process_priv          | enum('N','Y')                     | NO   |     | N       |     
 | 
| File_priv             | enum('N','Y')                     | NO   |     | N       |     
 | 
| Grant_priv            | enum('N','Y')                     | NO   |     | N       |     
 | 
| References_priv       | enum('N','Y')                     | NO   |     | N       |     
 | 
| Index_priv            | enum('N','Y')                     | NO   |     | N       |     
 | 
| Alter_priv            | enum('N','Y')                     | NO   |     | N       |     
 | 
| Show_db_priv          | enum('N','Y')                     | NO   |     | N       |     
 | 
| Super_priv            | enum('N','Y')                     | NO   |     | N       |     
 | 
| Create_tmp_table_priv | enum('N','Y')                     | NO   |     | N       |     
 | 
| Lock_tables_priv      | enum('N','Y')                     | NO   |     | N       |     
 | 
| Execute_priv          | enum('N','Y')                     | NO   |     | N       |     
 | 
| Repl_slave_priv       | enum('N','Y')                     | NO   |     | N       |     
 | 
| Repl_client_priv      | enum('N','Y')                     | NO   |     | N       |     
 | 
| Create_view_priv      | enum('N','Y')                     | NO   |     | N       |     
 | 
| Show_view_priv        | enum('N','Y')                     | NO   |     | N       |     
 | 
| Create_routine_priv   | enum('N','Y')                     | NO   |     | N       |     
 | 
| Alter_routine_priv    | enum('N','Y')                     | NO   |     | N       |     
 | 
| Create_user_priv      | enum('N','Y')                     | NO   |     | N       |     
 | 
| ssl_type              | enum('','ANY','X509','SPECIFIED') | NO   |     |         |     
 | 
| ssl_cipher            | blob                              | NO   |     |         |     
 | 
| x509_issuer           | blob                              | NO   |     |         |     
 | 
| x509_subject          | blob                              | NO   |     |         |     
 | 
| max_questions         | int(11) unsigned                  | NO   |     | 0       |     
 | 
| max_updates           | int(11) unsigned                  | NO   |     | 0       |     
 | 
| max_connections       | int(11) unsigned                  | NO   |     | 0       |     
 | 
| max_user_connections  | int(11) unsigned                  | NO   |     | 0       |     
 | 
+-----------------------+-----------------------------------+------+-----+---------+-------+
37 rows in set (0.00 sec)

mysql> select * from user;
ERROR 2013 (HY000): Lost connection to MySQL server during query
[29 Jul 2008 0:17] Josh Boyd
So, I've found the problem. If I don't specify the path to the LUA script, everything
works great. However, if I do specifiy the path, as I did in the report above, the LUA
script actually loads and executes, and throws an error on the line shown above.

Very odd.
[29 Jul 2008 10:21] Jan Kneschke
Please try this patch

=== modified file 'lib/rw-splitting.lua'
--- lib/rw-splitting.lua        2008-03-25 17:57:00 +0000
+++ lib/rw-splitting.lua        2008-07-29 08:17:09 +0000
@@ -201,7 +201,8 @@
                        is_in_select_calc_found_rows = false
                        local is_insert_id = false

-                       for i, token in ipairs(tokens) do
+                       for i = 1, #tokens do
+                               local token = tokens[i]
                                -- SQL_CALC_FOUND_ROWS + FOUND_ROWS() have to be
executed
                                -- on the same connection
                                -- print("token: " .. token.token_name)
[30 Aug 2008 1:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[31 Aug 2008 3:06] Josh Boyd
So, the reason my original "fix" appeared to work, is because it couldn't open the LUA
file, and just acted as a proxy to the master! I've applied this patch, however, I still
get the same results.  

Please advise.
[31 Aug 2008 3:08] Josh Boyd
I've made a new bug report, #39142. As this is a similar problem, but not the same.
[18 Sep 2008 20:53] Sveta Smirnova
Thank you for the report.

Verified as described. Bug #38419 was marked as duplicate of this one.
[9 Jun 2009 15:34] Diego Medina
Verified fixed on 0.7.1
[17 Aug 2009 17:09] MC Brown
A note has been added to the 0.7.1 changelog: 

When using the rw-splitting.lua script you could get an error when talking to the backend
server:

2008-07-28 18:00:30: (critical) (read_query) [string
"/usr/local/share/mysql-proxy/rw-splitting.l..."]:218: bad argument #1 to 'ipairs'
(table
expected, got userdata)
This would lead to the proxy closing the connection to the configured MySQL backend.