Add storing of statements to session

Statements can now be stored in the session object. This enables the
retrieval of these statements at a later time. These will be used by
readwritesplit to reroute failed reads to backup slaves.
This commit is contained in:
Markus Makela
2016-12-05 23:36:23 +02:00
parent 8f86a596fa
commit 6f7f8cae39
2 changed files with 88 additions and 0 deletions

View File

@ -105,6 +105,8 @@ session_alloc(SERVICE *service, DCB *client_dcb)
session->service = service;
session->client_dcb = client_dcb;
session->stats.connect = time(0);
session->stmt.buffer = NULL;
session->stmt.target = NULL;
/*<
* Associate the session to the client DCB and set the reference count on
* the session to indicate that there is a single reference to the
@ -395,6 +397,7 @@ static void session_free(SESSION *session)
static void
session_final_free(SESSION *session)
{
gwbuf_free(session->stmt.buffer);
MXS_FREE(session);
}
@ -939,3 +942,43 @@ void session_put_ref(SESSION *session)
}
}
}
bool session_store_stmt(SESSION *session, GWBUF *buf, const SERVER *server)
{
bool rval = false;
if (session->stmt.buffer)
{
/** This should not happen with proper use */
ss_dassert(false);
gwbuf_free(session->stmt.buffer);
}
if ((session->stmt.buffer = gwbuf_clone(buf)))
{
session->stmt.target = server;
/** No old statements were stored and we successfully cloned the buffer */
rval = true;
}
return rval;
}
GWBUF *session_fetch_stmt(SESSION *session)
{
GWBUF *rval = session->stmt.buffer;
session->stmt.buffer = NULL;
return rval;
}
const SERVER* session_fetch_stmt_target(const SESSION *session)
{
return session->stmt.target;
}
void session_clear_stmt(SESSION *session)
{
gwbuf_free(session->stmt.buffer);
session->stmt.buffer = NULL;
session->stmt.target = NULL;
}