From b443bb7525eef6d089fb14ca025faef50b9a719d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Sun, 11 Nov 2018 21:59:39 +0200 Subject: [PATCH] Store PS session commands with internal ID Commit a9e236497963251f8b4afa07484b88ad97e73a03 changed where the PS ID for a binary protocol command is replaced with the internal form. This caused prepared statements that are also session commands to be always routed with the external ID. As the external ID is almost always the master's ID, the aforementioned bug resulted in odd side-effects and the true cause of these was only revealed when the error message sent by the slave was included in the log messages. --- .../routing/readwritesplit/rwsplit_route_stmt.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc b/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc index a8802cc7e..2d09b153c 100644 --- a/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc +++ b/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc @@ -400,6 +400,17 @@ void RWSplitSession::continue_large_session_write(GWBUF* querybuf, uint32_t type */ bool RWSplitSession::route_session_write(GWBUF* querybuf, uint8_t command, uint32_t type) { + if (mxs_mysql_is_ps_command(m_qc.current_route_info().command())) + { + /** + * Replace the ID with our internal one, the backends will replace it with their own ID + * when the packet is being written. We use the internal ID when we store the command + * to remove the need for extra conversions from external to internal form when the command + * is being replayed on a server. + */ + replace_binary_ps_id(querybuf, m_qc.current_route_info().stmt_id()); + } + /** The SessionCommand takes ownership of the buffer */ uint64_t id = m_sescmd_count++; mxs::SSessionCommand sescmd(new mxs::SessionCommand(querybuf, id));