From 7a0d6307fe9e6eb89b9b8f2953113d2c11c2e11b Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Fri, 25 Nov 2016 14:25:35 +0200 Subject: [PATCH] Cache: Make Cache abstract The methods that need to be different depending on the thread model are now pure virtual. --- server/modules/filter/cache/cache.cc | 30 --------------------------- server/modules/filter/cache/cache.h | 5 ++--- server/modules/filter/cache/cachemt.h | 1 + 3 files changed, 3 insertions(+), 33 deletions(-) diff --git a/server/modules/filter/cache/cache.cc b/server/modules/filter/cache/cache.cc index cefdde9a7..77bf1aadc 100644 --- a/server/modules/filter/cache/cache.cc +++ b/server/modules/filter/cache/cache.cc @@ -143,36 +143,6 @@ bool Cache::shouldUse(const SESSION* pSession) return cache_rules_should_use(m_pRules, pSession); } -bool Cache::mustRefresh(const char* pKey, const SessionCache* pSessionCache) -{ - long key = hash_of_key(pKey); - - spinlock_acquire(&m_lockPending); - // TODO: Remove the internal locking of hashtable. The internal - // TODO: locking is no good if you need transactional behaviour. - // TODO: Now we lock twice. - void *pValue = hashtable_fetch(m_pPending, (void*)pKey); - if (!pValue) - { - // It's not being fetched, so we make a note that we are. - hashtable_add(m_pPending, (void*)pKey, (void*)pSessionCache); - } - spinlock_release(&m_lockPending); - - return pValue == NULL; -} - -void Cache::refreshed(const char* pKey, const SessionCache* pSessionCache) -{ - long key = hash_of_key(pKey); - - spinlock_acquire(&m_lockPending); - ss_dassert(hashtable_fetch(m_pPending, (void*)pKey) == pSessionCache); - ss_debug(int n =) hashtable_delete(m_pPending, (void*)pKey); - ss_dassert(n == 1); - spinlock_release(&m_lockPending); -} - cache_result_t Cache::getKey(const char* zDefaultDb, const GWBUF* pQuery, char* pKey) diff --git a/server/modules/filter/cache/cache.h b/server/modules/filter/cache/cache.h index 8de701fa9..d9700862c 100644 --- a/server/modules/filter/cache/cache.h +++ b/server/modules/filter/cache/cache.h @@ -53,7 +53,7 @@ public: * * @return True, if the session cache should refresh the data. */ - virtual bool mustRefresh(const char* pKey, const SessionCache* pSessionCache); + virtual bool mustRefresh(const char* pKey, const SessionCache* pSessionCache) = 0; /** * To inform the cache that a particular item has been updated upon request. @@ -61,7 +61,7 @@ public: * @param pKey The hashed key for a query. * @param pSessionCache The session cache informing. */ - virtual void refreshed(const char* pKey, const SessionCache* pSessionCache); + virtual void refreshed(const char* pKey, const SessionCache* pSessionCache) = 0; const CACHE_CONFIG& config() const { return m_config; } @@ -103,5 +103,4 @@ protected: StorageFactory* m_pFactory; // The storage factory. Storage* m_pStorage; // The storage instance to use. HASHTABLE* m_pPending; // Pending items; being fetched from the backend. - SPINLOCK m_lockPending; // Lock used for protecting 'pending'. }; diff --git a/server/modules/filter/cache/cachemt.h b/server/modules/filter/cache/cachemt.h index 315224a9e..7153a9ac0 100644 --- a/server/modules/filter/cache/cachemt.h +++ b/server/modules/filter/cache/cachemt.h @@ -13,6 +13,7 @@ */ #include +#include #include "cache.h" class CacheMT : public Cache