From b0d8535ead2ba227f6a917304d89ef2ba1ad8b9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Tue, 7 May 2019 12:43:58 +0300 Subject: [PATCH] Allow master changes at transaction start When a BEGIN statement is being executed without a master connection but when one can be created, the BEGIN statement would be treated as if a transaction was already open. Since the statement only starts the transaction, it is allowed to be routed to a "new" master regardless of the transaction statem. This fixes the failure to start a transaction when lazy_connect is enabled. --- .../modules/routing/readwritesplit/rwsplit_route_stmt.cc | 8 +++++++- server/modules/routing/readwritesplit/rwsplitsession.hh | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc b/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc index 2fc598259..0de872d95 100644 --- a/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc +++ b/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc @@ -928,13 +928,19 @@ void RWSplitSession::log_master_routing_failure(bool found, errmsg); } +bool RWSplitSession::trx_is_starting() +{ + return session_trx_is_active(m_client->session) + && qc_query_is_type(m_qc.current_route_info().type_mask(), QUERY_TYPE_BEGIN_TRX); +} + bool RWSplitSession::should_replace_master(RWBackend* target) { return m_config.master_reconnection && // We have a target server and it's not the current master target && target != m_current_master && // We are not inside a transaction (also checks for autocommit=1) - (!session_trx_is_active(m_client->session) || m_is_replay_active) + (!session_trx_is_active(m_client->session) || trx_is_starting() || m_is_replay_active) && // We are not locked to the old master !is_locked_to_master(); } diff --git a/server/modules/routing/readwritesplit/rwsplitsession.hh b/server/modules/routing/readwritesplit/rwsplitsession.hh index 1e8447eef..4db358f8f 100644 --- a/server/modules/routing/readwritesplit/rwsplitsession.hh +++ b/server/modules/routing/readwritesplit/rwsplitsession.hh @@ -166,6 +166,7 @@ private: bool create_one_connection(); void retry_query(GWBUF* querybuf, int delay = 1); + bool trx_is_starting(); bool should_replace_master(mxs::RWBackend* target); void replace_master(mxs::RWBackend* target); bool should_migrate_trx(mxs::RWBackend* target);