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.
This commit is contained in:
Markus Mäkelä
2017-06-14 10:18:01 +03:00
parent 18993bc8ca
commit dc8c20bf6a
4 changed files with 30 additions and 4 deletions

View File

@ -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());
}
} }
} }

View File

@ -27,6 +27,7 @@
#include <maxscale/hashtable.h> #include <maxscale/hashtable.h>
#include <maxscale/router.h> #include <maxscale/router.h>
#include <maxscale/service.h> #include <maxscale/service.h>
#include <maxscale/session_command.hh>
enum bref_state_t 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 unsigned char reply_cmd; /**< The reply command. One of OK, ERR, RESULTSET or
* LOCAL_INFILE. Slave servers are compared to this * LOCAL_INFILE. Slave servers are compared to this
* when they return session command replies.*/ * 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; 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 */ rses_property_t** scmd_cur_ptr_property; /**< address of pointer to owner property */
mysql_sescmd_t* scmd_cur_cmd; /**< pointer to current session command */ mysql_sescmd_t* scmd_cur_cmd; /**< pointer to current session command */
bool scmd_cur_active; /**< true if command is being executed */ 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; skygw_chk_t scmd_cur_chk_tail;
}; };
@ -253,13 +254,14 @@ struct ROUTER_CLIENT_SES
bool have_tmp_tables; bool have_tmp_tables;
uint64_t rses_load_data_sent; /**< How much data has been sent */ uint64_t rses_load_data_sent; /**< How much data has been sent */
DCB* client_dcb; DCB* client_dcb;
int pos_generator; uint64_t pos_generator;
backend_ref_t *forced_node; /**< Current server where all queries should be sent */ backend_ref_t *forced_node; /**< Current server where all queries should be sent */
int expected_responses; /**< Number of expected responses to the current query */ int expected_responses; /**< Number of expected responses to the current query */
GWBUF* query_queue; /**< Queued commands waiting to be executed */ GWBUF* query_queue; /**< Queued commands waiting to be executed */
struct ROUTER_INSTANCE *router; /**< The router instance */ struct ROUTER_INSTANCE *router; /**< The router instance */
struct ROUTER_CLIENT_SES *next; struct ROUTER_CLIENT_SES *next;
TableSet temp_tables; /**< Set of temporary tables */ TableSet temp_tables; /**< Set of temporary tables */
mxs::SessionCommandList sescmd_list; /**< List of executed session commands */
skygw_chk_t rses_chk_tail; skygw_chk_t rses_chk_tail;
}; };

View File

@ -364,6 +364,14 @@ bool route_session_write(ROUTER_CLIENT_SES *router_cli_ses,
return false; 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++) for (i = 0; i < router_cli_ses->rses_nbackends; i++)
{ {
if (BREF_IS_IN_USE((&backend_ref[i]))) if (BREF_IS_IN_USE((&backend_ref[i])))

View File

@ -80,7 +80,7 @@ mysql_sescmd_t *mysql_sescmd_init(rses_property_t *rses_prop,
/** Set session command buffer */ /** Set session command buffer */
sescmd->my_sescmd_buf = sescmd_buf; sescmd->my_sescmd_buf = sescmd_buf;
sescmd->my_sescmd_packet_type = packet_type; 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->my_sescmd_is_replied = false;
sescmd->reply_cmd = 0; sescmd->reply_cmd = 0;