From 705d29ea41a9b1ba11d1c98ff82b4407cf7e64cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Wed, 21 Jun 2017 11:14:11 +0300 Subject: [PATCH] MXS-852: Fix prepared statement collection If a prepared statement response was collected into one buffer, it doesn't need to be processed again. By jumping directly to the routing of the collected result, we prevent the unnecessary splitting of buffers that appears to happend with continuous preparations of prepared statements. --- server/core/modutil.cc | 2 +- .../MySQL/MySQLBackend/mysql_backend.c | 29 ++++++++++++------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/server/core/modutil.cc b/server/core/modutil.cc index 2ca4108cc..8b5f7558a 100644 --- a/server/core/modutil.cc +++ b/server/core/modutil.cc @@ -1310,7 +1310,7 @@ bool modutil_ignorable_ping(DCB *dcb) return rval; } -const char format_str[] = "COM_UNKNOWN(%02x)"; +const char format_str[] = "COM_UNKNOWN(%02hhx)"; // The message always fits inside the buffer thread_local char unknow_type[sizeof(format_str)] = ""; diff --git a/server/modules/protocol/MySQL/MySQLBackend/mysql_backend.c b/server/modules/protocol/MySQL/MySQLBackend/mysql_backend.c index 2e8fc4a59..622c4e0f5 100644 --- a/server/modules/protocol/MySQL/MySQLBackend/mysql_backend.c +++ b/server/modules/protocol/MySQL/MySQLBackend/mysql_backend.c @@ -808,18 +808,27 @@ gw_read_and_write(DCB *dcb) */ if (protocol_get_srv_command((MySQLProtocol *)dcb->protocol, true) != MYSQL_COM_UNDEFINED) { - stmt = process_response_data(dcb, &read_buffer, gwbuf_length(read_buffer)); - /** - * Received incomplete response to session command. - * Store it to readqueue and return. - */ - if (!sescmd_response_complete(dcb)) + if (result_collected) { - stmt = gwbuf_append(stmt, read_buffer); - dcb->dcb_readqueue = gwbuf_append(stmt, dcb->dcb_readqueue); - return 0; + /** The result set or PS response was collected, we know it's complete */ + stmt = read_buffer; + read_buffer = NULL; + gwbuf_set_type(stmt, GWBUF_TYPE_RESPONSE_END | GWBUF_TYPE_SESCMD_RESPONSE); + } + else + { + stmt = process_response_data(dcb, &read_buffer, gwbuf_length(read_buffer)); + /** + * Received incomplete response to session command. + * Store it to readqueue and return. + */ + if (!sescmd_response_complete(dcb)) + { + stmt = gwbuf_append(stmt, read_buffer); + dcb->dcb_readqueue = gwbuf_append(stmt, dcb->dcb_readqueue); + return 0; + } } - if (!stmt) { MXS_ERROR("Read buffer unexpectedly null, even though response "