Skip to content

Commit

Permalink
Merge pull request #1 from Qihoo360/master
Browse files Browse the repository at this point in the history
update
  • Loading branch information
assad2008 committed Mar 17, 2016
2 parents 6bd6943 + 128b054 commit 311a511
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 23 deletions.
3 changes: 2 additions & 1 deletion bootstrap.sh
Original file line number Diff line number Diff line change
@@ -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"
45 changes: 28 additions & 17 deletions plugins/proxy/proxy-plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1438,15 +1439,22 @@ 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) {
int backend_ndx = -1;

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);
Expand Down Expand Up @@ -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)); */
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/network-mysqld.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 311a511

Please sign in to comment.