From 98e233bb33b01d07a3d44a09a02bc3fe76f2bbcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Sun, 8 Jul 2018 00:28:16 +0300 Subject: [PATCH] Minor cleanup of route_single_stmt Moved transaction statistics calculations into a member function and placed all target type specific processing into their respective functions. Also inverted the connection keepalive check to also cover hinted queries. --- .../readwritesplit/rwsplit_route_stmt.cc | 31 ++++++------------- .../routing/readwritesplit/rwsplitsession.hh | 10 ++++++ 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc b/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc index cf6b315e1..709ac254c 100644 --- a/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc +++ b/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc @@ -238,12 +238,7 @@ bool RWSplitSession::route_single_stmt(GWBUF *querybuf) } else { - if (session_trx_is_ending(m_client->session)) - { - atomic_add_uint64(m_qc.is_trx_still_read_only() ? - &m_router->stats().n_ro_trx : - &m_router->stats().n_rw_trx, 1); - } + update_trx_statistics(); if (m_qc.is_trx_starting() && // A transaction is starting !session_trx_is_read_only(m_client->session) && // Not explicitly read-only @@ -281,11 +276,6 @@ bool RWSplitSession::route_single_stmt(GWBUF *querybuf) } else if (TARGET_IS_NAMED_SERVER(route_target) || TARGET_IS_RLAG_MAX(route_target)) { - /** - * There is a hint which either names the target backend or - * hint which sets maximum allowed replication lag for the - * backend. - */ if ((target = handle_hinted_target(querybuf, route_target))) { succp = true; @@ -308,14 +298,6 @@ bool RWSplitSession::route_single_stmt(GWBUF *querybuf) else if (TARGET_IS_MASTER(route_target)) { succp = handle_master_is_target(&target); - - if (!m_config->strict_multi_stmt && - !m_config->strict_sp_calls && - m_target_node == m_current_master) - { - /** Reset the forced node as we're in relaxed multi-statement mode */ - m_target_node.reset(); - } } if (succp && target) @@ -353,7 +335,6 @@ bool RWSplitSession::route_single_stmt(GWBUF *querybuf) { retry_query(gwbuf_clone(querybuf)); succp = true; - MXS_INFO("Delaying routing: %s", extract_sql(querybuf).c_str()); } else @@ -363,8 +344,7 @@ bool RWSplitSession::route_single_stmt(GWBUF *querybuf) } } - if (succp && m_config->connection_keepalive && - (TARGET_IS_SLAVE(route_target) || TARGET_IS_MASTER(route_target))) + if (succp && m_config->connection_keepalive && !TARGET_IS_ALL(route_target)) { handle_connection_keepalive(target); } @@ -963,6 +943,13 @@ bool RWSplitSession::handle_master_is_target(SRWBackend* dest) } } + if (!m_config->strict_multi_stmt && !m_config->strict_sp_calls && + m_target_node == m_current_master) + { + /** Reset the forced node as we're in relaxed multi-statement mode */ + m_target_node.reset(); + } + *dest = target; return succp; } diff --git a/server/modules/routing/readwritesplit/rwsplitsession.hh b/server/modules/routing/readwritesplit/rwsplitsession.hh index f93c673e3..9ea1f8ff9 100644 --- a/server/modules/routing/readwritesplit/rwsplitsession.hh +++ b/server/modules/routing/readwritesplit/rwsplitsession.hh @@ -270,6 +270,16 @@ private: return buflen == MYSQL_HEADER_LEN + GW_MYSQL_MAX_PACKET_LEN; } + + void update_trx_statistics() + { + if (session_trx_is_ending(m_client->session)) + { + atomic_add_uint64(m_qc.is_trx_still_read_only() ? + &m_router->stats().n_ro_trx : + &m_router->stats().n_rw_trx, 1); + } + } }; /**