From dc8c20bf6a40e0d9ba35592760e9cf7c42877b5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Wed, 14 Jun 2017 10:18:01 +0300 Subject: [PATCH] Store session commands also as SessionCommand The session commands are now duplicated as SessionCommand objects This allows for an easier migration from the old session command implementation to the new one. --- .../routing/readwritesplit/readwritesplit.cc | 16 ++++++++++++++++ .../routing/readwritesplit/readwritesplit.hh | 8 +++++--- .../routing/readwritesplit/rwsplit_route_stmt.cc | 8 ++++++++ .../readwritesplit/rwsplit_session_cmd.cc | 2 +- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/server/modules/routing/readwritesplit/readwritesplit.cc b/server/modules/routing/readwritesplit/readwritesplit.cc index d606e7189..1725c48f6 100644 --- a/server/modules/routing/readwritesplit/readwritesplit.cc +++ b/server/modules/routing/readwritesplit/readwritesplit.cc @@ -1157,6 +1157,22 @@ static void closeSession(MXS_ROUTER *instance, MXS_ROUTER_SESSION *router_sessio } } } + + if (MXS_LOG_PRIORITY_IS_ENABLED(LOG_INFO) && + router_cli_ses->sescmd_list.size()) + { + std::string sescmdstr; + + for (mxs::SessionCommandList::iterator it = router_cli_ses->sescmd_list.begin(); + it != router_cli_ses->sescmd_list.end(); it++) + { + mxs::SSessionCommand& scmd = *it; + sescmdstr += scmd->to_string(); + sescmdstr += "\n"; + } + + MXS_INFO("Executed session commands:\n%s", sescmdstr.c_str()); + } } } diff --git a/server/modules/routing/readwritesplit/readwritesplit.hh b/server/modules/routing/readwritesplit/readwritesplit.hh index facba8e77..14a0672cb 100644 --- a/server/modules/routing/readwritesplit/readwritesplit.hh +++ b/server/modules/routing/readwritesplit/readwritesplit.hh @@ -27,6 +27,7 @@ #include #include #include +#include enum bref_state_t { @@ -151,7 +152,7 @@ struct mysql_sescmd_t unsigned char reply_cmd; /**< The reply command. One of OK, ERR, RESULTSET or * LOCAL_INFILE. Slave servers are compared to this * when they return session command replies.*/ - int position; /**< Position of this command */ + uint64_t position; /**< Position of this command */ skygw_chk_t my_sescmd_chk_tail; }; @@ -180,7 +181,7 @@ struct sescmd_cursor_t rses_property_t** scmd_cur_ptr_property; /**< address of pointer to owner property */ mysql_sescmd_t* scmd_cur_cmd; /**< pointer to current session command */ bool scmd_cur_active; /**< true if command is being executed */ - int position; /**< Position of this cursor */ + uint64_t position; /**< Position of this cursor */ skygw_chk_t scmd_cur_chk_tail; }; @@ -253,13 +254,14 @@ struct ROUTER_CLIENT_SES bool have_tmp_tables; uint64_t rses_load_data_sent; /**< How much data has been sent */ DCB* client_dcb; - int pos_generator; + uint64_t pos_generator; backend_ref_t *forced_node; /**< Current server where all queries should be sent */ int expected_responses; /**< Number of expected responses to the current query */ GWBUF* query_queue; /**< Queued commands waiting to be executed */ struct ROUTER_INSTANCE *router; /**< The router instance */ struct ROUTER_CLIENT_SES *next; TableSet temp_tables; /**< Set of temporary tables */ + mxs::SessionCommandList sescmd_list; /**< List of executed session commands */ skygw_chk_t rses_chk_tail; }; diff --git a/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc b/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc index 74c1e2209..a625e29d0 100644 --- a/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc +++ b/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc @@ -364,6 +364,14 @@ bool route_session_write(ROUTER_CLIENT_SES *router_cli_ses, return false; } + if (!router_cli_ses->rses_config.disable_sescmd_history) + { + /** The stored buffer points to the one in the session command + * which is freed in freeSession. */ + uint64_t id = prop->rses_prop_data.sescmd.position; + router_cli_ses->sescmd_list.push_front(mxs::SSessionCommand(new mxs::SessionCommand(querybuf, id))); + } + for (i = 0; i < router_cli_ses->rses_nbackends; i++) { if (BREF_IS_IN_USE((&backend_ref[i]))) diff --git a/server/modules/routing/readwritesplit/rwsplit_session_cmd.cc b/server/modules/routing/readwritesplit/rwsplit_session_cmd.cc index ffb5a8f51..7e837bbf2 100644 --- a/server/modules/routing/readwritesplit/rwsplit_session_cmd.cc +++ b/server/modules/routing/readwritesplit/rwsplit_session_cmd.cc @@ -80,7 +80,7 @@ mysql_sescmd_t *mysql_sescmd_init(rses_property_t *rses_prop, /** Set session command buffer */ sescmd->my_sescmd_buf = sescmd_buf; sescmd->my_sescmd_packet_type = packet_type; - sescmd->position = atomic_add(&rses->pos_generator, 1); + sescmd->position = atomic_add_uint64(&rses->pos_generator, 1); sescmd->my_sescmd_is_replied = false; sescmd->reply_cmd = 0;