Cache: SessionCache renamed to CacheFilterSession

This commit is contained in:
Johan Wikman 2016-12-08 16:55:52 +02:00
parent fcd737a0c9
commit 528531f3b5
13 changed files with 84 additions and 84 deletions

View File

@ -2,6 +2,7 @@ if (JANSSON_FOUND)
add_library(cache SHARED
cache.cc
cachefilter.cc
cachefiltersession.cc
cachemt.cc
cachept.cc
cachesimple.cc
@ -10,7 +11,6 @@ if (JANSSON_FOUND)
lrustoragemt.cc
lrustoragest.cc
rules.cc
sessioncache.cc
storage.cc
storagefactory.cc
storagereal.cc

View File

@ -21,7 +21,7 @@
#include "cachefilter.h"
#include "cache_storage_api.h"
class SessionCache;
class CacheFilterSession;
class Cache
{
@ -67,20 +67,20 @@ public:
/**
* Specifies whether a particular SessioCache should refresh the data.
*
* @param key The hashed key for a query.
* @param pSessionCache The session cache asking.
* @param key The hashed key for a query.
* @param pSession The session cache asking.
*
* @return True, if the session cache should refresh the data.
*/
virtual bool must_refresh(const CACHE_KEY& key, const SessionCache* pSessionCache) = 0;
virtual bool must_refresh(const CACHE_KEY& key, const CacheFilterSession* pSession) = 0;
/**
* To inform the cache that a particular item has been updated upon request.
*
* @param key The hashed key for a query.
* @param pSessionCache The session cache informing.
* @param key The hashed key for a query.
* @param pSession The session cache informing.
*/
virtual void refreshed(const CACHE_KEY& key, const SessionCache* pSessionCache) = 0;
virtual void refreshed(const CACHE_KEY& key, const CacheFilterSession* pSession) = 0;
virtual cache_result_t get_key(const char* zDefaultDb, const GWBUF* pQuery, CACHE_KEY* pKey) = 0;

View File

@ -21,7 +21,7 @@
#include <maxscale/modulecmd.h>
#include "cachemt.h"
#include "cachept.h"
#include "sessioncache.h"
#include "cachefiltersession.hh"
using std::string;
@ -228,10 +228,10 @@ static void *newSession(FILTER* pInstance, SESSION* pSession)
CACHE_FILTER *pFilter = reinterpret_cast<CACHE_FILTER*>(pInstance);
Cache* pCache = pFilter->pCache;
SessionCache* pSessionCache = NULL;
CPP_GUARD(pSessionCache = SessionCache::Create(pCache, pSession));
CacheFilterSession* pCacheFilterSession = NULL;
CPP_GUARD(pCacheFilterSession = CacheFilterSession::Create(pCache, pSession));
return pSessionCache;
return pCacheFilterSession;
}
/**
@ -242,9 +242,9 @@ static void *newSession(FILTER* pInstance, SESSION* pSession)
*/
static void closeSession(FILTER* pInstance, void* pSessionData)
{
SessionCache* pSessionCache = static_cast<SessionCache*>(pSessionData);
CacheFilterSession* pCacheFilterSession = static_cast<CacheFilterSession*>(pSessionData);
CPP_GUARD(pSessionCache->close());
CPP_GUARD(pCacheFilterSession->close());
}
/**
@ -255,9 +255,9 @@ static void closeSession(FILTER* pInstance, void* pSessionData)
*/
static void freeSession(FILTER* pInstance, void* pSessionData)
{
SessionCache* pSessionCache = static_cast<SessionCache*>(pSessionData);
CacheFilterSession* pCacheFilterSession = static_cast<CacheFilterSession*>(pSessionData);
delete pSessionCache;
delete pCacheFilterSession;
}
/**
@ -269,9 +269,9 @@ static void freeSession(FILTER* pInstance, void* pSessionData)
*/
static void setDownstream(FILTER* pInstance, void* pSessionData, DOWNSTREAM* pDownstream)
{
SessionCache* pSessionCache = static_cast<SessionCache*>(pSessionData);
CacheFilterSession* pCacheFilterSession = static_cast<CacheFilterSession*>(pSessionData);
CPP_GUARD(pSessionCache->setDownstream(pDownstream));
CPP_GUARD(pCacheFilterSession->setDownstream(pDownstream));
}
/**
@ -283,9 +283,9 @@ static void setDownstream(FILTER* pInstance, void* pSessionData, DOWNSTREAM* pDo
*/
static void setUpstream(FILTER* pInstance, void* pSessionData, UPSTREAM* pUpstream)
{
SessionCache* pSessionCache = static_cast<SessionCache*>(pSessionData);
CacheFilterSession* pCacheFilterSession = static_cast<CacheFilterSession*>(pSessionData);
CPP_GUARD(pSessionCache->setUpstream(pUpstream));
CPP_GUARD(pCacheFilterSession->setUpstream(pUpstream));
}
/**
@ -297,10 +297,10 @@ static void setUpstream(FILTER* pInstance, void* pSessionData, UPSTREAM* pUpstre
*/
static int routeQuery(FILTER* pInstance, void* pSessionData, GWBUF* pPacket)
{
SessionCache* pSessionCache = static_cast<SessionCache*>(pSessionData);
CacheFilterSession* pCacheFilterSession = static_cast<CacheFilterSession*>(pSessionData);
int rv = 0;
CPP_GUARD(rv = pSessionCache->routeQuery(pPacket));
CPP_GUARD(rv = pCacheFilterSession->routeQuery(pPacket));
return rv;
}
@ -314,10 +314,10 @@ static int routeQuery(FILTER* pInstance, void* pSessionData, GWBUF* pPacket)
*/
static int clientReply(FILTER* pInstance, void* pSessionData, GWBUF* pPacket)
{
SessionCache* pSessionCache = static_cast<SessionCache*>(pSessionData);
CacheFilterSession* pCacheFilterSession = static_cast<CacheFilterSession*>(pSessionData);
int rv = 0;
CPP_GUARD(rv = pSessionCache->clientReply(pPacket));
CPP_GUARD(rv = pCacheFilterSession->clientReply(pPacket));
return rv;
}
@ -334,9 +334,9 @@ static int clientReply(FILTER* pInstance, void* pSessionData, GWBUF* pPacket)
*/
static void diagnostics(FILTER* pInstance, void* pSessionData, DCB* pDcb)
{
SessionCache* pSessionCache = static_cast<SessionCache*>(pSessionData);
CacheFilterSession* pCacheFilterSession = static_cast<CacheFilterSession*>(pSessionData);
CPP_GUARD(pSessionCache->diagnostics(pDcb));
CPP_GUARD(pCacheFilterSession->diagnostics(pDcb));
}
/**

View File

@ -12,14 +12,14 @@
*/
#define MXS_MODULE_NAME "cache"
#include "sessioncache.h"
#include "cachefiltersession.hh"
#include <new>
#include <maxscale/alloc.h>
#include <maxscale/query_classifier.h>
#include <maxscale/mysql_utils.h>
#include "storage.h"
SessionCache::SessionCache(Cache* pCache, SESSION* pSession, char* zDefaultDb)
CacheFilterSession::CacheFilterSession(Cache* pCache, SESSION* pSession, char* zDefaultDb)
: m_state(CACHE_EXPECTING_NOTHING)
, m_pCache(pCache)
, m_pSession(pSession)
@ -34,16 +34,16 @@ SessionCache::SessionCache(Cache* pCache, SESSION* pSession, char* zDefaultDb)
reset_response_state();
}
SessionCache::~SessionCache()
CacheFilterSession::~CacheFilterSession()
{
MXS_FREE(m_zUseDb);
MXS_FREE(m_zDefaultDb);
}
//static
SessionCache* SessionCache::Create(Cache* pCache, SESSION* pSession)
CacheFilterSession* CacheFilterSession::Create(Cache* pCache, SESSION* pSession)
{
SessionCache* pSessionCache = NULL;
CacheFilterSession* pCacheFilterSession = NULL;
ss_dassert(pSession->client_dcb);
ss_dassert(pSession->client_dcb->data);
@ -58,32 +58,32 @@ SessionCache* SessionCache::Create(Cache* pCache, SESSION* pSession)
if ((pMysqlSession->db[0] == 0) || zDefaultDb)
{
pSessionCache = new (std::nothrow) SessionCache(pCache, pSession, zDefaultDb);
pCacheFilterSession = new (std::nothrow) CacheFilterSession(pCache, pSession, zDefaultDb);
if (!pSessionCache)
if (!pCacheFilterSession)
{
MXS_FREE(zDefaultDb);
}
}
return pSessionCache;
return pCacheFilterSession;
}
void SessionCache::close()
void CacheFilterSession::close()
{
}
void SessionCache::setDownstream(DOWNSTREAM* pDown)
void CacheFilterSession::setDownstream(DOWNSTREAM* pDown)
{
m_down = *pDown;
}
void SessionCache::setUpstream(UPSTREAM* pUp)
void CacheFilterSession::setUpstream(UPSTREAM* pUp)
{
m_up = *pUp;
}
int SessionCache::routeQuery(GWBUF* pPacket)
int CacheFilterSession::routeQuery(GWBUF* pPacket)
{
uint8_t* pData = static_cast<uint8_t*>(GWBUF_DATA(pPacket));
@ -237,7 +237,7 @@ int SessionCache::routeQuery(GWBUF* pPacket)
return rv;
}
int SessionCache::clientReply(GWBUF* pData)
int CacheFilterSession::clientReply(GWBUF* pData)
{
int rv;
@ -303,7 +303,7 @@ int SessionCache::clientReply(GWBUF* pData)
return rv;
}
void SessionCache::diagnostics(DCB* pDcb)
void CacheFilterSession::diagnostics(DCB* pDcb)
{
// Not printing anything. Session of the same instance share the same cache, in
// which case the same information would be printed once per session, or all
@ -315,7 +315,7 @@ void SessionCache::diagnostics(DCB* pDcb)
/**
* Called when resultset field information is handled.
*/
int SessionCache::handle_expecting_fields()
int CacheFilterSession::handle_expecting_fields()
{
ss_dassert(m_state == CACHE_EXPECTING_FIELDS);
ss_dassert(m_res.pData);
@ -366,7 +366,7 @@ int SessionCache::handle_expecting_fields()
/**
* Called when data is received (even if nothing is expected) from the server.
*/
int SessionCache::handle_expecting_nothing()
int CacheFilterSession::handle_expecting_nothing()
{
ss_dassert(m_state == CACHE_EXPECTING_NOTHING);
ss_dassert(m_res.pData);
@ -379,7 +379,7 @@ int SessionCache::handle_expecting_nothing()
/**
* Called when a response is received from the server.
*/
int SessionCache::handle_expecting_response()
int CacheFilterSession::handle_expecting_response()
{
ss_dassert(m_state == CACHE_EXPECTING_RESPONSE);
ss_dassert(m_res.pData);
@ -451,7 +451,7 @@ int SessionCache::handle_expecting_response()
/**
* Called when resultset rows are handled.
*/
int SessionCache::handle_expecting_rows()
int CacheFilterSession::handle_expecting_rows()
{
ss_dassert(m_state == CACHE_EXPECTING_ROWS);
ss_dassert(m_res.pData);
@ -517,7 +517,7 @@ int SessionCache::handle_expecting_rows()
/**
* Called when a response to a "USE db" is received from the server.
*/
int SessionCache::handle_expecting_use_response()
int CacheFilterSession::handle_expecting_use_response()
{
ss_dassert(m_state == CACHE_EXPECTING_USE_RESPONSE);
ss_dassert(m_res.pData);
@ -567,7 +567,7 @@ int SessionCache::handle_expecting_use_response()
/**
* Called when all data from the server is ignored.
*/
int SessionCache::handle_ignoring_response()
int CacheFilterSession::handle_ignoring_response()
{
ss_dassert(m_state == CACHE_IGNORING_RESPONSE);
ss_dassert(m_res.pData);
@ -580,7 +580,7 @@ int SessionCache::handle_ignoring_response()
*
* @return Whatever the upstream returns.
*/
int SessionCache::send_upstream()
int CacheFilterSession::send_upstream()
{
ss_dassert(m_res.pData != NULL);
@ -593,7 +593,7 @@ int SessionCache::send_upstream()
/**
* Reset cache response state
*/
void SessionCache::reset_response_state()
void CacheFilterSession::reset_response_state()
{
m_res.pData = NULL;
m_res.nTotalFields = 0;
@ -609,7 +609,7 @@ void SessionCache::reset_response_state()
* @param value The result.
* @return True if the query was satisfied from the query.
*/
cache_result_t SessionCache::get_cached_response(const GWBUF *pQuery, GWBUF **ppResponse)
cache_result_t CacheFilterSession::get_cached_response(const GWBUF *pQuery, GWBUF **ppResponse)
{
cache_result_t result = m_pCache->get_key(m_zDefaultDb, pQuery, &m_key);
@ -632,7 +632,7 @@ cache_result_t SessionCache::get_cached_response(const GWBUF *pQuery, GWBUF **pp
*
* @param csdata Session data
*/
void SessionCache::store_result()
void CacheFilterSession::store_result()
{
ss_dassert(m_res.pData);

View File

@ -21,7 +21,7 @@
class Cache;
class SessionCache
class CacheFilterSession
{
public:
enum cache_session_state_t
@ -46,21 +46,21 @@ public:
/**
* Releases all resources held by the session cache.
*/
~SessionCache();
~CacheFilterSession();
/**
* Creates a SessionCache instance.
* Creates a CacheFilterSession instance.
*
* @param pCache Pointer to the cache instance to which this session cache
* belongs. Must remain valid for the lifetime of the SessionCache
* belongs. Must remain valid for the lifetime of the CacheFilterSession
* instance being created.
* @param pSession Pointer to the session this session cache instance is
* specific for. Must remain valid for the lifetime of the SessionCache
* specific for. Must remain valid for the lifetime of the CacheFilterSession
* instance being created.
*
* @return A new instance or NULL if memory allocation fails.
*/
static SessionCache* Create(Cache* pCache, SESSION* pSession);
static CacheFilterSession* Create(Cache* pCache, SESSION* pSession);
/**
* The session has been closed.
@ -122,10 +122,10 @@ private:
void store_result();
private:
SessionCache(Cache* pCache, SESSION* pSession, char* zDefaultDb);
CacheFilterSession(Cache* pCache, SESSION* pSession, char* zDefaultDb);
SessionCache(const SessionCache&);
SessionCache& operator = (const SessionCache&);
CacheFilterSession(const CacheFilterSession&);
CacheFilterSession& operator = (const CacheFilterSession&);
private:
cache_session_state_t m_state; /**< What state is the session in, what data is expected. */

View File

@ -61,18 +61,18 @@ json_t* CacheMT::get_info(uint32_t flags) const
return CacheSimple::do_get_info(flags);
}
bool CacheMT::must_refresh(const CACHE_KEY& key, const SessionCache* pSessionCache)
bool CacheMT::must_refresh(const CACHE_KEY& key, const CacheFilterSession* pSession)
{
LockGuard guard(&m_lockPending);
return do_must_refresh(key, pSessionCache);
return do_must_refresh(key, pSession);
}
void CacheMT::refreshed(const CACHE_KEY& key, const SessionCache* pSessionCache)
void CacheMT::refreshed(const CACHE_KEY& key, const CacheFilterSession* pSession)
{
LockGuard guard(&m_lockPending);
do_refreshed(key, pSessionCache);
do_refreshed(key, pSession);
}
// static

View File

@ -25,9 +25,9 @@ public:
json_t* get_info(uint32_t what) const;
bool must_refresh(const CACHE_KEY& key, const SessionCache* pSessionCache);
bool must_refresh(const CACHE_KEY& key, const CacheFilterSession* pSession);
void refreshed(const CACHE_KEY& key, const SessionCache* pSessionCache);
void refreshed(const CACHE_KEY& key, const CacheFilterSession* pSession);
private:
CacheMT(const std::string& name,

View File

@ -81,14 +81,14 @@ CachePT* CachePT::Create(const std::string& name, const CACHE_CONFIG* pConfig)
return pCache;
}
bool CachePT::must_refresh(const CACHE_KEY& key, const SessionCache* pSessionCache)
bool CachePT::must_refresh(const CACHE_KEY& key, const CacheFilterSession* pSession)
{
return thread_cache().must_refresh(key, pSessionCache);
return thread_cache().must_refresh(key, pSession);
}
void CachePT::refreshed(const CACHE_KEY& key, const SessionCache* pSessionCache)
void CachePT::refreshed(const CACHE_KEY& key, const CacheFilterSession* pSession)
{
thread_cache().refreshed(key, pSessionCache);
thread_cache().refreshed(key, pSession);
}
json_t* CachePT::get_info(uint32_t what) const

View File

@ -24,9 +24,9 @@ public:
static CachePT* Create(const std::string& name, const CACHE_CONFIG* pConfig);
bool must_refresh(const CACHE_KEY& key, const SessionCache* pSessionCache);
bool must_refresh(const CACHE_KEY& key, const CacheFilterSession* pSession);
void refreshed(const CACHE_KEY& key, const SessionCache* pSessionCache);
void refreshed(const CACHE_KEY& key, const CacheFilterSession* pSession);
json_t* get_info(uint32_t what) const;

View File

@ -100,7 +100,7 @@ json_t* CacheSimple::do_get_info(uint32_t what) const
}
// protected
bool CacheSimple::do_must_refresh(const CACHE_KEY& key, const SessionCache* pSessionCache)
bool CacheSimple::do_must_refresh(const CACHE_KEY& key, const CacheFilterSession* pSession)
{
bool rv = false;
Pending::iterator i = m_pending.find(key);
@ -109,7 +109,7 @@ bool CacheSimple::do_must_refresh(const CACHE_KEY& key, const SessionCache* pSes
{
try
{
m_pending.insert(std::make_pair(key, pSessionCache));
m_pending.insert(std::make_pair(key, pSession));
rv = true;
}
catch (const std::exception& x)
@ -122,10 +122,10 @@ bool CacheSimple::do_must_refresh(const CACHE_KEY& key, const SessionCache* pSes
}
// protected
void CacheSimple::do_refreshed(const CACHE_KEY& key, const SessionCache* pSessionCache)
void CacheSimple::do_refreshed(const CACHE_KEY& key, const CacheFilterSession* pSession)
{
Pending::iterator i = m_pending.find(key);
ss_dassert(i != m_pending.end());
ss_dassert(i->second == pSessionCache);
ss_dassert(i->second == pSession);
m_pending.erase(i);
}

View File

@ -46,16 +46,16 @@ protected:
json_t* do_get_info(uint32_t what) const;
bool do_must_refresh(const CACHE_KEY& key, const SessionCache* pSessionCache);
bool do_must_refresh(const CACHE_KEY& key, const CacheFilterSession* pSession);
void do_refreshed(const CACHE_KEY& key, const SessionCache* pSessionCache);
void do_refreshed(const CACHE_KEY& key, const CacheFilterSession* pSession);
private:
CacheSimple(const Cache&);
CacheSimple& operator = (const CacheSimple&);
protected:
typedef std::tr1::unordered_map<CACHE_KEY, const SessionCache*> Pending;
typedef std::tr1::unordered_map<CACHE_KEY, const CacheFilterSession*> Pending;
Pending m_pending; // Pending items; being fetched from the backend.
Storage* m_pStorage; // The storage instance to use.

View File

@ -70,14 +70,14 @@ json_t* CacheST::get_info(uint32_t flags) const
return CacheSimple::do_get_info(flags);
}
bool CacheST::must_refresh(const CACHE_KEY& key, const SessionCache* pSessionCache)
bool CacheST::must_refresh(const CACHE_KEY& key, const CacheFilterSession* pSession)
{
return CacheSimple::do_must_refresh(key, pSessionCache);
return CacheSimple::do_must_refresh(key, pSession);
}
void CacheST::refreshed(const CACHE_KEY& key, const SessionCache* pSessionCache)
void CacheST::refreshed(const CACHE_KEY& key, const CacheFilterSession* pSession)
{
CacheSimple::do_refreshed(key, pSessionCache);
CacheSimple::do_refreshed(key, pSession);
}
// static

View File

@ -28,9 +28,9 @@ public:
json_t* get_info(uint32_t what) const;
bool must_refresh(const CACHE_KEY& key, const SessionCache* pSessionCache);
bool must_refresh(const CACHE_KEY& key, const CacheFilterSession* pSession);
void refreshed(const CACHE_KEY& key, const SessionCache* pSessionCache);
void refreshed(const CACHE_KEY& key, const CacheFilterSession* pSession);
private:
CacheST(const std::string& name,