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 <unordered_set>
#include <vector> #include <vector>
#include <maxscale/buffer.hh>
#include <maxscale/session.h> #include <maxscale/session.h>
#include <maxscale/resultset.hh> #include <maxscale/resultset.hh>
#include <maxscale/utils.hh> #include <maxscale/utils.hh>
@ -38,7 +39,7 @@ typedef struct SESSION_VARIABLE
} SESSION_VARIABLE; } SESSION_VARIABLE;
typedef std::unordered_map<std::string, SESSION_VARIABLE> SessionVarsByName; 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; typedef std::unordered_set<DCB*> DCBSet;
// Class that holds the session specific filter data // Class that holds the session specific filter data

View File

@ -26,19 +26,20 @@
#include <string> #include <string>
#include <sstream> #include <sstream>
#include <maxscale/alloc.h>
#include <maxbase/atomic.hh> #include <maxbase/atomic.hh>
#include <maxscale/alloc.h>
#include <maxscale/clock.h> #include <maxscale/clock.h>
#include <maxscale/dcb.h> #include <maxscale/dcb.h>
#include <maxscale/housekeeper.h> #include <maxscale/housekeeper.h>
#include <maxscale/json_api.h>
#include <maxscale/log.h> #include <maxscale/log.h>
#include <maxscale/modutil.h>
#include <maxscale/poll.h> #include <maxscale/poll.h>
#include <maxscale/router.h> #include <maxscale/router.h>
#include <maxscale/routingworker.hh>
#include <maxscale/service.h> #include <maxscale/service.h>
#include <maxscale/utils.h> #include <maxscale/utils.h>
#include <maxscale/json_api.h>
#include <maxscale/protocol/mysql.h> #include <maxscale/protocol/mysql.h>
#include <maxscale/routingworker.hh>
#include "internal/dcb.h" #include "internal/dcb.h"
#include "internal/filter.hh" #include "internal/filter.hh"
@ -1204,8 +1205,22 @@ void Session::dump_statements() const
for (auto i = m_last_statements.rbegin(); i != m_last_statements.rend(); ++i) for (auto i = m_last_statements.rbegin(); i != m_last_statements.rend(); ++i)
{ {
int len = i->size(); std::shared_ptr<GWBUF> sBuffer = *i;
const char* pStmt = (char*)&i->front(); 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) if (id != 0)
{ {
@ -1219,6 +1234,11 @@ void Session::dump_statements() const
MXS_NOTICE("(%" PRIu64 ") Stmt %d: %.*s", ses_id, n, len, pStmt); MXS_NOTICE("(%" PRIu64 ") Stmt %d: %.*s", ses_id, n, len, pStmt);
} }
if (!GWBUF_IS_CONTIGUOUS(pBuffer))
{
MXS_FREE(pStmt);
}
--n; --n;
} }
} }
@ -1398,10 +1418,9 @@ void Session::retain_statement(GWBUF* pBuffer)
m_last_statements.pop_back(); m_last_statements.pop_back();
} }
std::vector<uint8_t> stmt(len - MYSQL_HEADER_LEN - 1); std::shared_ptr<GWBUF> sBuffer(gwbuf_clone(pBuffer));
gwbuf_copy_data(pBuffer, MYSQL_HEADER_LEN + 1, len - (MYSQL_HEADER_LEN + 1), &stmt.front());
m_last_statements.push_front(stmt); m_last_statements.push_front(sBuffer);
} }
} }
} }