From e574af7e6e039244f10080936e21c70d33bafb03 Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Thu, 8 Dec 2016 23:48:13 +0200 Subject: [PATCH] Cache: Derived CacheFilterSession from maxscale::FilterSession --- server/modules/filter/cache/cachefilter.cc | 8 ++++-- .../filter/cache/cachefiltersession.cc | 24 +++++------------- .../filter/cache/cachefiltersession.hh | 25 +++---------------- 3 files changed, 15 insertions(+), 42 deletions(-) diff --git a/server/modules/filter/cache/cachefilter.cc b/server/modules/filter/cache/cachefilter.cc index 5f8be48bb..b55020f1e 100644 --- a/server/modules/filter/cache/cachefilter.cc +++ b/server/modules/filter/cache/cachefilter.cc @@ -272,7 +272,9 @@ static void setDownstream(FILTER* pInstance, void* pSessionData, DOWNSTREAM* pDo { CacheFilterSession* pCacheFilterSession = static_cast(pSessionData); - MXS_EXCEPTION_GUARD(pCacheFilterSession->setDownstream(pDownstream)); + CacheFilterSession::Downstream down(*pDownstream); + + MXS_EXCEPTION_GUARD(pCacheFilterSession->setDownstream(down)); } /** @@ -286,7 +288,9 @@ static void setUpstream(FILTER* pInstance, void* pSessionData, UPSTREAM* pUpstre { CacheFilterSession* pCacheFilterSession = static_cast(pSessionData); - MXS_EXCEPTION_GUARD(pCacheFilterSession->setUpstream(pUpstream)); + CacheFilterSession::Upstream up(*pUpstream); + + MXS_EXCEPTION_GUARD(pCacheFilterSession->setUpstream(up)); } /** diff --git a/server/modules/filter/cache/cachefiltersession.cc b/server/modules/filter/cache/cachefiltersession.cc index be058ef11..e8dd53229 100644 --- a/server/modules/filter/cache/cachefiltersession.cc +++ b/server/modules/filter/cache/cachefiltersession.cc @@ -19,16 +19,14 @@ #include #include "storage.h" -CacheFilterSession::CacheFilterSession(Cache* pCache, SESSION* pSession, char* zDefaultDb) - : m_state(CACHE_EXPECTING_NOTHING) +CacheFilterSession::CacheFilterSession(SESSION* pSession, Cache* pCache, char* zDefaultDb) + : maxscale::FilterSession(pSession) + , m_state(CACHE_EXPECTING_NOTHING) , m_pCache(pCache) - , m_pSession(pSession) , m_zDefaultDb(zDefaultDb) , m_zUseDb(NULL) , m_refreshing(false) { - memset(&m_down, 0, sizeof(m_down)); - memset(&m_up, 0, sizeof(m_up)); memset(m_key.data, 0, CACHE_KEY_MAXLEN); reset_response_state(); @@ -58,7 +56,7 @@ CacheFilterSession* CacheFilterSession::Create(Cache* pCache, SESSION* pSession) if ((pMysqlSession->db[0] == 0) || zDefaultDb) { - pCacheFilterSession = new (std::nothrow) CacheFilterSession(pCache, pSession, zDefaultDb); + pCacheFilterSession = new (std::nothrow) CacheFilterSession(pSession, pCache, zDefaultDb); if (!pCacheFilterSession) { @@ -73,16 +71,6 @@ void CacheFilterSession::close() { } -void CacheFilterSession::setDownstream(DOWNSTREAM* pDown) -{ - m_down = *pDown; -} - -void CacheFilterSession::setUpstream(UPSTREAM* pUp) -{ - m_up = *pUp; -} - int CacheFilterSession::routeQuery(GWBUF* pPacket) { uint8_t* pData = static_cast(GWBUF_DATA(pPacket)); @@ -231,7 +219,7 @@ int CacheFilterSession::routeQuery(GWBUF* pPacket) if (fetch_from_server) { - rv = m_down.routeQuery(m_down.instance, m_down.session, pPacket); + rv = m_down.routeQuery(pPacket); } return rv; @@ -584,7 +572,7 @@ int CacheFilterSession::send_upstream() { ss_dassert(m_res.pData != NULL); - int rv = m_up.clientReply(m_up.instance, m_up.session, m_res.pData); + int rv = m_up.clientReply(m_res.pData); m_res.pData = NULL; return rv; diff --git a/server/modules/filter/cache/cachefiltersession.hh b/server/modules/filter/cache/cachefiltersession.hh index b9385f877..3c874a1f2 100644 --- a/server/modules/filter/cache/cachefiltersession.hh +++ b/server/modules/filter/cache/cachefiltersession.hh @@ -14,14 +14,12 @@ #include #include -#include +#include #include "cache.h" #include "cachefilter.h" #include "cache_storage_api.h" -class Cache; - -class CacheFilterSession +class CacheFilterSession : public maxscale::FilterSession { public: enum cache_session_state_t @@ -67,20 +65,6 @@ public: */ void close(); - /** - * Set the downstream component for this session. - * - * @param pDown The downstream filter or router - */ - void setDownstream(DOWNSTREAM* pDownstream); - - /** - * Set the upstream component for this session. - * - * @param pUp The upstream filter or router - */ - void setUpstream(UPSTREAM* pUpstream); - /** * A request on its way to a backend is delivered to this function. * @@ -122,7 +106,7 @@ private: void store_result(); private: - CacheFilterSession(Cache* pCache, SESSION* pSession, char* zDefaultDb); + CacheFilterSession(SESSION* pSession, Cache* pCache, char* zDefaultDb); CacheFilterSession(const CacheFilterSession&); CacheFilterSession& operator = (const CacheFilterSession&); @@ -130,9 +114,6 @@ private: private: cache_session_state_t m_state; /**< What state is the session in, what data is expected. */ Cache* m_pCache; /**< The cache instance the session is associated with. */ - SESSION* m_pSession; /**< The session this data is associated with. */ - DOWNSTREAM m_down; /**< The previous filter or equivalent. */ - UPSTREAM m_up; /**< The next filter or equivalent. */ CACHE_RESPONSE_STATE m_res; /**< The response state. */ CACHE_KEY m_key; /**< Key storage. */ char* m_zDefaultDb; /**< The default database. */