Skip to content

Commit 7e68030

Browse files
committed
Forbid force slave visit in transaction context
1 parent 1720f42 commit 7e68030

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

plugins/proxy/proxy-plugin.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -1170,9 +1170,13 @@ process_query_or_stmt_prepare(network_mysqld_con *con, proxy_plugin_con_t *st,
11701170
}
11711171

11721172
/* forbid force write on slave */
1173-
if ((context->rw_flag & CF_FORCE_SLAVE) && (context->rw_flag & CF_WRITE)) {
1173+
if ((context->rw_flag & CF_FORCE_SLAVE) && ((context->rw_flag & CF_WRITE) || con->is_in_transaction)) {
11741174
g_message("%s Comment usage error. SQL: %s", G_STRLOC, con->orig_sql->str);
1175-
network_mysqld_con_send_error(con->client, C("Force write on read-only slave"));
1175+
if (con->is_in_transaction) {
1176+
network_mysqld_con_send_error(con->client, C("Force transaction on read-only slave"));
1177+
} else {
1178+
network_mysqld_con_send_error(con->client, C("Force write on read-only slave"));
1179+
}
11761180
*disp_flag = PROXY_SEND_RESULT;
11771181
return 0;
11781182
}

plugins/shard/shard-plugin.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -666,9 +666,13 @@ proxy_parse_query(network_mysqld_con *con)
666666
return PROXY_SEND_RESULT;
667667
}
668668
/* forbid force write on slave */
669-
if ((context->rw_flag & CF_FORCE_SLAVE) && (context->rw_flag & CF_WRITE)) {
669+
if ((context->rw_flag & CF_FORCE_SLAVE) && ((context->rw_flag & CF_WRITE) || con->is_in_transaction)) {
670670
g_message("%s Comment usage error. SQL: %s", G_STRLOC, con->orig_sql->str);
671-
network_mysqld_con_send_error(con->client, C("Force write on read-only slave"));
671+
if (con->is_in_transaction) {
672+
network_mysqld_con_send_error(con->client, C("Force transaction on read-only slave"));
673+
} else {
674+
network_mysqld_con_send_error(con->client, C("Force write on read-only slave"));
675+
}
672676
return PROXY_SEND_RESULT;
673677
}
674678

0 commit comments

Comments
 (0)