MXS-1780 Store last statement as cloned GWBUF

The last statements of a session are now stored as a cloned
GWBUF instead of as a copy of the SQL.
This commit is contained in:
Johan Wikman 2018-11-05 16:12:10 +02:00
parent 3ccdb508de
commit fa13b8036a
2 changed files with 30 additions and 10 deletions

View File

@ -20,6 +20,7 @@
#include <unordered_set>
#include <vector>
#include <maxscale/buffer.hh>
#include <maxscale/session.h>
#include <maxscale/resultset.hh>
#include <maxscale/utils.hh>
@ -38,7 +39,7 @@ typedef struct SESSION_VARIABLE
} SESSION_VARIABLE;
typedef std::unordered_map<std::string, SESSION_VARIABLE> SessionVarsByName;
typedef std::deque<std::vector<uint8_t>> SessionStmtQueue;
typedef std::deque<std::shared_ptr<GWBUF>> SessionStmtQueue;
typedef std::unordered_set<DCB*> DCBSet;
// Class that holds the session specific filter data

View File

@ -26,19 +26,20 @@
#include <string>
#include <sstream>
#include <maxscale/alloc.h>
#include <maxbase/atomic.hh>
#include <maxscale/alloc.h>
#include <maxscale/clock.h>
#include <maxscale/dcb.h>
#include <maxscale/housekeeper.h>
#include <maxscale/json_api.h>
#include <maxscale/log.h>
#include <maxscale/modutil.h>
#include <maxscale/poll.h>
#include <maxscale/router.h>
#include <maxscale/routingworker.hh>
#include <maxscale/service.h>
#include <maxscale/utils.h>
#include <maxscale/json_api.h>
#include <maxscale/protocol/mysql.h>
#include <maxscale/routingworker.hh>
#include "internal/dcb.h"
#include "internal/filter.hh"
@ -1197,15 +1198,29 @@ void Session::dump_statements() const
if ((id != 0) && (id != ses_id))
{
MXS_WARNING("Current session is %" PRIu64 ", yet statements are dumped for %" PRIu64 ". "
"The session id in the subsequent dumped statements is the wrong one.",
"The session id in the subsequent dumped statements is the wrong one.",
id,
ses_id);
}
for (auto i = m_last_statements.rbegin(); i != m_last_statements.rend(); ++i)
{
int len = i->size();
const char* pStmt = (char*)&i->front();
std::shared_ptr<GWBUF> sBuffer = *i;
GWBUF* pBuffer = sBuffer.get();
mxb_assert(modutil_is_SQL(pBuffer));
char* pStmt;
int len;
if (GWBUF_IS_CONTIGUOUS(pBuffer))
{
modutil_extract_SQL(pBuffer, &pStmt, &len);
}
else
{
pStmt = modutil_get_SQL(pBuffer);
}
if (id != 0)
{
@ -1219,6 +1234,11 @@ void Session::dump_statements() const
MXS_NOTICE("(%" PRIu64 ") Stmt %d: %.*s", ses_id, n, len, pStmt);
}
if (!GWBUF_IS_CONTIGUOUS(pBuffer))
{
MXS_FREE(pStmt);
}
--n;
}
}
@ -1398,10 +1418,9 @@ void Session::retain_statement(GWBUF* pBuffer)
m_last_statements.pop_back();
}
std::vector<uint8_t> stmt(len - MYSQL_HEADER_LEN - 1);
gwbuf_copy_data(pBuffer, MYSQL_HEADER_LEN + 1, len - (MYSQL_HEADER_LEN + 1), &stmt.front());
std::shared_ptr<GWBUF> sBuffer(gwbuf_clone(pBuffer));
m_last_statements.push_front(stmt);
m_last_statements.push_front(sBuffer);
}
}
}