From 0c8e68fd05ea982a0bfaaebe4bef6e18fa0435d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Fri, 16 Jun 2017 01:32:04 +0300 Subject: [PATCH] Rename and overload adding of session commands As the session commands are always appended to the end of the list, the name should reflect that action. For this reason, the function was renamed to append_session_command. Readwritesplit supports replacement of slave servers by storing all executed session commands in a list. To make the copying of this list a bit cleaner, an overload for a list of session commands was added. This will allow relatively smooth addition of server replacement to all router modules that use the Backend class. --- include/maxscale/backend.hh | 5 +++-- server/core/backend.cc | 9 +++++++-- .../readwritesplit/rwsplit_route_stmt.cc | 2 +- .../readwritesplit/rwsplit_select_backends.cc | 19 +++++++++++++++---- .../schemarouter/schemaroutersession.cc | 2 +- 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/include/maxscale/backend.hh b/include/maxscale/backend.hh index 8b0ce8c01..8f788b352 100644 --- a/include/maxscale/backend.hh +++ b/include/maxscale/backend.hh @@ -72,8 +72,9 @@ public: * @param sequence Sequence identifier of this session command, returned when * the session command is completed */ - void add_session_command(GWBUF* buffer, uint64_t sequence); - void add_session_command(const SSessionCommand& sescmd); + void append_session_command(GWBUF* buffer, uint64_t sequence); + void append_session_command(const SSessionCommand& sescmd); + void append_session_command(const SessionCommandList& sescmdlist); /** * @brief Mark the current session command as successfully executed diff --git a/server/core/backend.cc b/server/core/backend.cc index 8adc4c696..fee730c88 100644 --- a/server/core/backend.cc +++ b/server/core/backend.cc @@ -111,16 +111,21 @@ bool Backend::execute_session_command() return rval; } -void Backend::add_session_command(GWBUF* buffer, uint64_t sequence) +void Backend::append_session_command(GWBUF* buffer, uint64_t sequence) { m_session_commands.push_back(SSessionCommand(new SessionCommand(buffer, sequence))); } -void Backend::add_session_command(const SSessionCommand& sescmd) +void Backend::append_session_command(const SSessionCommand& sescmd) { m_session_commands.push_back(sescmd); } +void Backend::append_session_command(const SessionCommandList& sescmdlist) +{ + m_session_commands.insert(m_session_commands.end(), sescmdlist.begin(), sescmdlist.end()); +} + uint64_t Backend::complete_session_command() { uint64_t rval = m_session_commands.front()->get_position(); diff --git a/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc b/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc index ca2f7420f..fce558ce8 100644 --- a/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc +++ b/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc @@ -248,7 +248,7 @@ bool route_session_write(ROUTER_CLIENT_SES *rses, GWBUF *querybuf, uint8_t comma if (bref->in_use()) { - bref->add_session_command(sescmd); + bref->append_session_command(sescmd); uint64_t current_pos = bref->next_session_command()->get_position(); diff --git a/server/modules/routing/readwritesplit/rwsplit_select_backends.cc b/server/modules/routing/readwritesplit/rwsplit_select_backends.cc index c24084220..524f50184 100644 --- a/server/modules/routing/readwritesplit/rwsplit_select_backends.cc +++ b/server/modules/routing/readwritesplit/rwsplit_select_backends.cc @@ -214,11 +214,22 @@ bool select_connect_backend_servers(int router_nservers, bref && slaves_connected < max_nslaves; bref = get_slave_candidate(rses, master_host, cmpfun)) { - if (bref->connect(session) && - (bref->session_command_count() == 0 || - bref->execute_session_command())) + if (bref->can_connect() && bref->connect(session)) { - slaves_connected += 1; + if (rses->sescmd_list.size()) + { + bref->append_session_command(rses->sescmd_list); + + if (bref->execute_session_command()) + { + rses->expected_responses++; + slaves_connected++; + } + } + else + { + slaves_connected++; + } } } diff --git a/server/modules/routing/schemarouter/schemaroutersession.cc b/server/modules/routing/schemarouter/schemaroutersession.cc index 3247bdf58..03abf5295 100644 --- a/server/modules/routing/schemarouter/schemaroutersession.cc +++ b/server/modules/routing/schemarouter/schemaroutersession.cc @@ -726,7 +726,7 @@ bool SchemaRouterSession::route_session_write(GWBUF* querybuf, uint8_t command) { GWBUF *buffer = gwbuf_clone(querybuf); - (*it)->add_session_command(buffer, m_sent_sescmd); + (*it)->append_session_command(buffer, m_sent_sescmd); if (MXS_LOG_PRIORITY_IS_ENABLED(LOG_INFO)) {