diff --git a/bootstrap.sh b/bootstrap.sh index b4d39e5..e25f0aa 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -1,4 +1,5 @@ #!/bin/sh base=$(cd "$(dirname "$0")"; pwd) cd $base -PKG_CONFIG_PATH=/usr/local/lib/pkgconfig ./configure --with-mysql=/usr --prefix=/usr/local/mysql-proxy CFLAGS="-DHAVE_LUA_H -g -O2" LDFLAGS="-lm -ldl -lcrypto -ljemalloc" LUA_CFLAGS="-I/usr/local/include/" LUA_LIBS="-L/usr/local/lib -llua" +export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH +PKG_CONFIG_PATH=/usr/local/lib/pkgconfig ./configure --with-mysql=/usr --prefix=/usr/local/mysql-proxy CFLAGS="-DHAVE_LUA_H -O2" LDFLAGS="-lm -ldl -lcrypto -ljemalloc" LUA_CFLAGS="-I/usr/local/include/" LUA_LIBS="-L/usr/local/lib -llua" diff --git a/plugins/proxy/proxy-plugin.c b/plugins/proxy/proxy-plugin.c index 53c5bd7..c9b20ca 100644 --- a/plugins/proxy/proxy-plugin.c +++ b/plugins/proxy/proxy-plugin.c @@ -1243,15 +1243,15 @@ void check_flags(GPtrArray* tokens, network_mysqld_con* con) { if (!g_hash_table_lookup(con->locks, key)) g_hash_table_add(con->locks, g_strdup(key)); } - if (len > 4) { //SET AUTOCOMMIT = {0 | 1} - if (ts[1]->token_id == TK_SQL_SET && ts[3]->token_id == TK_EQ) { - if (strcasecmp(ts[2]->text->str, "AUTOCOMMIT") == 0) { - char* str = ts[4]->text->str; - if (strcmp(str, "0") == 0) con->is_not_autocommit = TRUE; - else if (strcmp(str, "1") == 0) con->is_not_autocommit = FALSE; - } - } - } + /* if (len > 4) { //SET AUTOCOMMIT = {0 | 1} */ + /* if (ts[1]->token_id == TK_SQL_SET && ts[3]->token_id == TK_EQ) { */ + /* if (strcasecmp(ts[2]->text->str, "AUTOCOMMIT") == 0) { */ + /* /1* char* str = ts[4]->text->str; *1/ */ + /* /1* if (strcmp(str, "0") == 0) con->is_not_autocommit = TRUE; *1/ */ + /* /1* else if (strcmp(str, "1") == 0) con->is_not_autocommit = FALSE; *1/ */ + /* } */ + /* } */ + /* } */ } guint i; @@ -1302,7 +1302,8 @@ gboolean sql_is_write(GPtrArray *tokens) { token_id = ts[i]->token_id; } - return (token_id != TK_SQL_SELECT && token_id != TK_SQL_SET && token_id != TK_SQL_USE && token_id != TK_SQL_SHOW && token_id != TK_SQL_DESC && token_id != TK_SQL_EXPLAIN); + // "set autocommit = 0; or show variables" need send to master + return (token_id != TK_SQL_SELECT /*&& token_id != TK_SQL_SET */ && token_id != TK_SQL_USE /*&& token_id != TK_SQL_SHOW*/ && token_id != TK_SQL_DESC && token_id != TK_SQL_EXPLAIN); } return TRUE; @@ -1438,7 +1439,14 @@ NETWORK_MYSQLD_PLUGIN_PROTO(proxy_read_query) { g_ptr_array_free(sqls, TRUE); } - + /* the sql after SQL_CALC_FOUND_ROWS must be "select FOUND_ROWS();" + * if not, must redo the read write split operation. because the write sql + * may send to slave. + */ + if (con->is_in_select_calc_found_rows && is_write) { + network_connection_pool_lua_add_connection(con); + } + check_flags(tokens, con); if (con->server == NULL) { @@ -1446,7 +1454,7 @@ NETWORK_MYSQLD_PLUGIN_PROTO(proxy_read_query) { if (!con->is_in_transaction && !con->is_not_autocommit && g_hash_table_size(con->locks) == 0) { if (type == COM_QUERY) { - if (is_write) { + if (is_write ) { backend_ndx = idle_rw(con); } else { backend_ndx = rw_split(tokens, con); @@ -1812,6 +1820,9 @@ NETWORK_MYSQLD_PLUGIN_PROTO(proxy_read_query_result) { inj->qstat.server_status = com_query->server_status; inj->qstat.warning_count = com_query->warning_count; inj->qstat.query_status = com_query->query_status; + + con->is_in_transaction = com_query->server_status & SERVER_STATUS_IN_TRANS; + con->is_not_autocommit = !(com_query->server_status & SERVER_STATUS_AUTOCOMMIT); } inj->ts_read_query_result_last = chassis_get_rel_microseconds(); /* g_get_current_time(&(inj->ts_read_query_result_last)); */ @@ -1899,11 +1910,11 @@ NETWORK_MYSQLD_PLUGIN_PROTO(proxy_read_query_result) { switch (ret) { case PROXY_SEND_RESULT: - if (!con->is_in_transaction || (inj->qstat.server_status & SERVER_STATUS_IN_TRANS)) { - con->is_in_transaction = (inj->qstat.server_status & SERVER_STATUS_IN_TRANS); - } else { - if (strcasestr(str, "COMMIT") == str || strcasestr(str, "ROLLBACK") == str) con->is_in_transaction = FALSE; - } + /* if (!con->is_in_transaction || (inj->qstat.server_status & SERVER_STATUS_IN_TRANS)) { */ + /* con->is_in_transaction = (inj->qstat.server_status & SERVER_STATUS_IN_TRANS); */ + /* } else { */ + /* if (strcasestr(str, "COMMIT") == str || strcasestr(str, "ROLLBACK") == str) con->is_in_transaction = FALSE; */ + /* } */ if (g_hash_table_size(con->locks) > 0 && strcasestr(str, "SELECT RELEASE_LOCK") == str) { gchar* b = strchr(str+strlen("SELECT RELEASE_LOCK"), '(') + 1; diff --git a/src/network-mysqld.h b/src/network-mysqld.h index eee88ad..552fc80 100644 --- a/src/network-mysqld.h +++ b/src/network-mysqld.h @@ -60,12 +60,12 @@ typedef struct network_mysqld_con network_mysqld_con; /* forward declaration */ -#undef NETWORK_MYSQLD_WANT_CON_TRACK_TIME -#ifdef NETWORK_MYSQLD_WANT_CON_TRACK_TIME -#define NETWORK_MYSQLD_CON_TRACK_TIME(con, name) chassis_timestamps_add(con->timestamps, name, __FILE__, __LINE__) -#else +/* #undef NETWORK_MYSQLD_WANT_CON_TRACK_TIME */ +/* #ifdef NETWORK_MYSQLD_WANT_CON_TRACK_TIME */ +/* #define NETWORK_MYSQLD_CON_TRACK_TIME(con, name) chassis_timestamps_add(con->timestamps, name, __FILE__, __LINE__) */ +/* #else */ #define NETWORK_MYSQLD_CON_TRACK_TIME(con, name) -#endif +/* #endif */ /** * A macro that produces a plugin callback function pointer declaration.