Skip to content

Commit

Permalink
Forbid force slave visit in transaction context
Browse files Browse the repository at this point in the history
  • Loading branch information
lazio579 committed Apr 13, 2019
1 parent 1720f42 commit 7e68030
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions plugins/proxy/proxy-plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -1170,9 +1170,13 @@ process_query_or_stmt_prepare(network_mysqld_con *con, proxy_plugin_con_t *st,
}

/* forbid force write on slave */
if ((context->rw_flag & CF_FORCE_SLAVE) && (context->rw_flag & CF_WRITE)) {
if ((context->rw_flag & CF_FORCE_SLAVE) && ((context->rw_flag & CF_WRITE) || con->is_in_transaction)) {
g_message("%s Comment usage error. SQL: %s", G_STRLOC, con->orig_sql->str);
network_mysqld_con_send_error(con->client, C("Force write on read-only slave"));
if (con->is_in_transaction) {
network_mysqld_con_send_error(con->client, C("Force transaction on read-only slave"));
} else {
network_mysqld_con_send_error(con->client, C("Force write on read-only slave"));
}
*disp_flag = PROXY_SEND_RESULT;
return 0;
}
Expand Down
8 changes: 6 additions & 2 deletions plugins/shard/shard-plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -666,9 +666,13 @@ proxy_parse_query(network_mysqld_con *con)
return PROXY_SEND_RESULT;
}
/* forbid force write on slave */
if ((context->rw_flag & CF_FORCE_SLAVE) && (context->rw_flag & CF_WRITE)) {
if ((context->rw_flag & CF_FORCE_SLAVE) && ((context->rw_flag & CF_WRITE) || con->is_in_transaction)) {
g_message("%s Comment usage error. SQL: %s", G_STRLOC, con->orig_sql->str);
network_mysqld_con_send_error(con->client, C("Force write on read-only slave"));
if (con->is_in_transaction) {
network_mysqld_con_send_error(con->client, C("Force transaction on read-only slave"));
} else {
network_mysqld_con_send_error(con->client, C("Force write on read-only slave"));
}
return PROXY_SEND_RESULT;
}

Expand Down

0 comments on commit 7e68030

Please sign in to comment.