diff --git a/server/core/modutil.cc b/server/core/modutil.cc index 7618edf40..568fa99cf 100644 --- a/server/core/modutil.cc +++ b/server/core/modutil.cc @@ -637,9 +637,11 @@ int modutil_count_signal_packets(GWBUF *reply, int n_found, bool* more_out, modu bool skip_next = state ? state->state : false; bool more = false; bool only_ok = true; + uint64_t num_packets = 0; while (offset < len) { + num_packets++; uint8_t header[MYSQL_HEADER_LEN + 5]; // Maximum size of an EOF packet gwbuf_copy_data(reply, offset, MYSQL_HEADER_LEN + 1, header); @@ -720,7 +722,9 @@ int modutil_count_signal_packets(GWBUF *reply, int n_found, bool* more_out, modu *more_out = more; - if (only_ok && !more) + // Treat complete multi-statement result sets that consist of only OK packets as a single result set + // TODO: Review this, it doesn't look very convincing. + if (only_ok && !more && num_packets > 1) { total = 2; } diff --git a/server/modules/routing/readwritesplit/rwsplit_session_cmd.cc b/server/modules/routing/readwritesplit/rwsplit_session_cmd.cc index 238b60650..48463ba15 100644 --- a/server/modules/routing/readwritesplit/rwsplit_session_cmd.cc +++ b/server/modules/routing/readwritesplit/rwsplit_session_cmd.cc @@ -26,6 +26,26 @@ * Functions for session command handling */ + +static std::string extract_error(GWBUF* buffer) +{ + std::string rval; + + if (MYSQL_IS_ERROR_PACKET(((uint8_t *)GWBUF_DATA(buffer)))) + { + size_t replylen = MYSQL_GET_PAYLOAD_LEN(GWBUF_DATA(buffer)); + char replybuf[replylen]; + gwbuf_copy_data(buffer, 0, gwbuf_length(buffer), (uint8_t*)replybuf); + std::string err; + std::string msg; + err.append(replybuf + 8, 5); + msg.append(replybuf + 13, replylen - 4 - 5); + rval = err + ": " + msg; + } + + return rval; +} + /** * Discards the slave connection if its response differs from the master's response * @@ -88,7 +108,12 @@ void process_sescmd_response(RWSplitSession* rses, SRWBackend& backend, * be compared to it */ rses->sescmd_responses[id] = cmd; - if (command == MXS_COM_STMT_PREPARE) + if (cmd == MYSQL_REPLY_ERR) + { + MXS_INFO("Session command no. %lu failed: %s", + id, extract_error(*ppPacket).c_str()); + } + else if (command == MXS_COM_STMT_PREPARE) { /** Map the returned response to the internal ID */ MXS_INFO("PS ID %u maps to internal ID %lu", resp.id, id);