MXS-2521: Detect COM_STMT_EXECUTE without metadata

If a COM_STMT_EXECUTE has no metadata in it and it has more than one
parameter, it must be routed to the same backend where the previous
COM_STMT_EXECUTE with the same ID was routed to. This prevents MDEV-19811
that is triggered by MaxScale routing the queries to different backends.
This commit is contained in:
Markus Mäkelä
2019-06-26 12:33:46 +03:00
parent a6617f52fc
commit 5eba688c1b
4 changed files with 105 additions and 12 deletions

View File

@ -234,6 +234,17 @@ public:
return qc_query_is_type(m_route_info.type_mask(), QUERY_TYPE_BEGIN_TRX);
}
/**
* Whether the current binary protocol statement is a continuation of a previously executed statement.
*
* All COM_STMT_FETCH are continuations of a previously executed COM_STMT_EXECUTE. A COM_STMT_EXECUTE can
* be a continuation if it has parameters but it doesn't provide the metadata for them.
*/
bool is_ps_continuation() const
{
return m_ps_continuation;
}
/**
* @brief Store and process a prepared statement
*
@ -251,12 +262,16 @@ public:
void ps_erase(GWBUF* buffer);
/**
* @brief Store a mapping from an external id to the corresponding internal id
* @brief Store a prepared statement response
*
* @param external_id The external id as seen by the client.
* @param internal_id The corresponding internal id.
* The response maps the internal ID to the external ID that is given to the client. It also collects
* the number of parameters in the prepared statement which are required in some cases in the routing
* process.
*
* @param internal_id The internal id (i.e. the session command number)
* @param buffer The buffer containing the OK response to a COM_STMT_PREPARE
*/
void ps_id_internal_put(uint32_t external_id, uint32_t internal_id);
void ps_store_response(uint32_t internal_id, GWBUF* buffer);
/**
* @brief Update the current RouteInfo.
@ -373,6 +388,8 @@ private:
uint8_t packet_type,
uint32_t* qtype);
bool query_continues_ps(uint8_t cmd, uint32_t stmt_id, GWBUF* buffer);
private:
class PSManager;
typedef std::shared_ptr<PSManager> SPSManager;
@ -397,5 +414,6 @@ private:
HandleMap m_ps_handles; /** External ID to internal ID */
RouteInfo m_route_info;
bool m_trx_is_read_only;
bool m_ps_continuation;
};
}