Skip to content

Commit

Permalink
Fix coredump for prepare stmt and process silence while in transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
wangbin579 committed Sep 24, 2020
1 parent ca6f449 commit 1c231d9
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion plugins/proxy/proxy-plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,46 @@ process_trans_query(network_mysqld_con *con)
return PROXY_NO_DECISION;
}

static int
process_filter_for_trans_query(network_mysqld_con *con, sql_context_t *context, mysqld_query_attr_t *query_attr)
{
gboolean is_orig_ro_server = FALSE;
gboolean need_to_visit_master = FALSE;
proxy_plugin_con_t *st = con->plugin_con_state;

switch (context->stmt_type) {
case STMT_SET_NAMES:{
char *charset_name = (char *)context->sql_statement;
process_set_names(con, charset_name, query_attr);
break;
}
case STMT_SET:{
sql_expr_list_t *set_list = context->sql_statement;
if (set_list && set_list->len > 0) {
sql_expr_t *expr = g_ptr_array_index(set_list, 0);
if (expr && expr->op == TK_EQ) {
sql_expr_t *left = expr->left;
sql_expr_t *right = expr->right;
if (!left || !right)
break;

if (sql_filter_vars_is_silent(left->token_text, right->token_text)) {
network_mysqld_con_send_ok(con->client);
g_message("silent variable: %s", left->token_text);
return PROXY_SEND_RESULT;
}
}
}
break;
}
default:
break;
}

return PROXY_NO_DECISION;
}


static int
process_non_trans_query(network_mysqld_con *con, sql_context_t *context, mysqld_query_attr_t *query_attr)
{
Expand Down Expand Up @@ -1218,6 +1258,13 @@ process_rw_split(network_mysqld_con *con, proxy_plugin_con_t *st,
break;
}
} else {
if (command == COM_QUERY) {
int ret = process_filter_for_trans_query(con, context, query_attr);
if (ret == PROXY_SEND_RESULT) {
*disp_flag = PROXY_SEND_RESULT;
return 0;
}
}
con->srv->query_stats.client_query.rw++;
if (con->is_in_transaction) {
query_attr->conn_reserved = 1;
Expand Down Expand Up @@ -1553,7 +1600,11 @@ network_read_query(network_mysqld_con *con, proxy_plugin_con_t *st)
packet.offset = NET_HEADER_SIZE;

if (network_mysqld_proto_get_stmt_id(&packet, &stmt_id) == 0) {
change_stmt_id(con, stmt_id);
if (change_stmt_id(con, stmt_id) == -1) {
network_mysqld_con_send_error_full(con->client,
C("change stmt id failed"), ER_ABORTING_CONNECTION, "29001");
return PROXY_SEND_RESULT;
}
}
} else if (command == COM_QUERY) {
change_server_by_rw(con, st->backend_ndx);
Expand Down

0 comments on commit 1c231d9

Please sign in to comment.