Cache: Make Storage abstract
Storage is now abstract with StorageReal (that uses an actual storage module) derived from it. This to prepare for a stackable case where LRU behaviour is implemented in front of the actual physcal storage.
This commit is contained in:
2
server/modules/filter/cache/CMakeLists.txt
vendored
2
server/modules/filter/cache/CMakeLists.txt
vendored
@ -1,5 +1,5 @@
|
||||
if (JANSSON_FOUND)
|
||||
add_library(cache SHARED cache.cc cachefilter.cc cachemt.cc cachept.cc cachesimple.cc cachest.cc rules.cc sessioncache.cc storage.cc storagefactory.cc)
|
||||
add_library(cache SHARED cache.cc cachefilter.cc cachemt.cc cachept.cc cachesimple.cc cachest.cc rules.cc sessioncache.cc storage.cc storagefactory.cc storagereal.cc)
|
||||
target_link_libraries(cache maxscale-common jansson)
|
||||
set_target_properties(cache PROPERTIES VERSION "1.0.0")
|
||||
set_target_properties(cache PROPERTIES LINK_FLAGS -Wl,-z,defs)
|
||||
|
||||
31
server/modules/filter/cache/storage.cc
vendored
31
server/modules/filter/cache/storage.cc
vendored
@ -15,39 +15,10 @@
|
||||
#include "storage.h"
|
||||
|
||||
|
||||
Storage::Storage(CACHE_STORAGE_API* pApi, CACHE_STORAGE* pStorage)
|
||||
: m_pApi(pApi)
|
||||
, m_pStorage(pStorage)
|
||||
Storage::Storage()
|
||||
{
|
||||
ss_dassert(m_pApi);
|
||||
ss_dassert(m_pStorage);
|
||||
}
|
||||
|
||||
Storage::~Storage()
|
||||
{
|
||||
}
|
||||
|
||||
cache_result_t Storage::get_key(const char* zDefaultDb,
|
||||
const GWBUF* pQuery,
|
||||
CACHE_KEY* pKey)
|
||||
{
|
||||
return m_pApi->getKey(m_pStorage, zDefaultDb, pQuery, pKey);
|
||||
}
|
||||
|
||||
cache_result_t Storage::get_value(const CACHE_KEY& key,
|
||||
uint32_t flags,
|
||||
GWBUF** ppValue)
|
||||
{
|
||||
return m_pApi->getValue(m_pStorage, &key, flags, ppValue);
|
||||
}
|
||||
|
||||
cache_result_t Storage::put_value(const CACHE_KEY& key,
|
||||
const GWBUF* pValue)
|
||||
{
|
||||
return m_pApi->putValue(m_pStorage, &key, pValue);
|
||||
}
|
||||
|
||||
cache_result_t Storage::del_value(const CACHE_KEY& key)
|
||||
{
|
||||
return m_pApi->delValue(m_pStorage, &key);
|
||||
}
|
||||
|
||||
34
server/modules/filter/cache/storage.h
vendored
34
server/modules/filter/cache/storage.h
vendored
@ -1,6 +1,4 @@
|
||||
#pragma once
|
||||
#ifndef _MAXSCALE_FILTER_CACHE_STORAGE_H
|
||||
#define _MAXSCALE_FILTER_CACHE_STORAGE_H
|
||||
/*
|
||||
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||
*
|
||||
@ -20,32 +18,24 @@
|
||||
class Storage
|
||||
{
|
||||
public:
|
||||
~Storage();
|
||||
virtual ~Storage();
|
||||
|
||||
cache_result_t get_key(const char* zDefaultDb,
|
||||
const GWBUF* pQuery,
|
||||
CACHE_KEY* pKey);
|
||||
virtual cache_result_t get_key(const char* zDefaultDb,
|
||||
const GWBUF* pQuery,
|
||||
CACHE_KEY* pKey) = 0;
|
||||
|
||||
cache_result_t get_value(const CACHE_KEY& key,
|
||||
uint32_t flags,
|
||||
GWBUF** ppValue);
|
||||
virtual cache_result_t get_value(const CACHE_KEY& key,
|
||||
uint32_t flags,
|
||||
GWBUF** ppValue) = 0;
|
||||
|
||||
cache_result_t put_value(const CACHE_KEY& key,
|
||||
const GWBUF* pValue);
|
||||
virtual cache_result_t put_value(const CACHE_KEY& key,
|
||||
const GWBUF* pValue) = 0;
|
||||
|
||||
cache_result_t del_value(const CACHE_KEY& key);
|
||||
virtual cache_result_t del_value(const CACHE_KEY& key) = 0;
|
||||
|
||||
private:
|
||||
friend class StorageFactory;
|
||||
|
||||
Storage(CACHE_STORAGE_API* pApi, CACHE_STORAGE* pStorage);
|
||||
protected:
|
||||
Storage();
|
||||
|
||||
Storage(const Storage&);
|
||||
Storage& operator = (const Storage&);
|
||||
|
||||
private:
|
||||
CACHE_STORAGE_API* m_pApi;
|
||||
CACHE_STORAGE* m_pStorage;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -19,7 +19,8 @@
|
||||
#include <maxscale/alloc.h>
|
||||
#include <maxscale/gwdirs.h>
|
||||
#include <maxscale/log_manager.h>
|
||||
#include "storage.h"
|
||||
#include "cachefilter.h"
|
||||
#include "storagereal.h"
|
||||
|
||||
|
||||
namespace
|
||||
@ -120,7 +121,7 @@ StorageFactory* StorageFactory::Open(const char* zName)
|
||||
|
||||
if (open_cache_storage(zName, &handle, &pApi))
|
||||
{
|
||||
pFactory = new (std::nothrow) StorageFactory(handle, pApi);
|
||||
CPP_GUARD(pFactory = new StorageFactory(handle, pApi));
|
||||
|
||||
if (!pFactory)
|
||||
{
|
||||
@ -144,7 +145,7 @@ Storage* StorageFactory::createStorage(cache_thread_model_t model,
|
||||
|
||||
if (pRawStorage)
|
||||
{
|
||||
pStorage = new (std::nothrow) Storage(m_pApi, pRawStorage);
|
||||
CPP_GUARD(pStorage = new StorageReal(m_pApi, pRawStorage));
|
||||
|
||||
if (!pStorage)
|
||||
{
|
||||
|
||||
53
server/modules/filter/cache/storagereal.cc
vendored
Normal file
53
server/modules/filter/cache/storagereal.cc
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||
*
|
||||
* Use of this software is governed by the Business Source License included
|
||||
* in the LICENSE.TXT file and at www.mariadb.com/bsl.
|
||||
*
|
||||
* Change Date: 2019-07-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source License, use
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
|
||||
#define MXS_MODULE_NAME "cache"
|
||||
#include "storagereal.h"
|
||||
|
||||
|
||||
StorageReal::StorageReal(CACHE_STORAGE_API* pApi, CACHE_STORAGE* pStorage)
|
||||
: m_pApi(pApi)
|
||||
, m_pStorage(pStorage)
|
||||
{
|
||||
ss_dassert(m_pApi);
|
||||
ss_dassert(m_pStorage);
|
||||
}
|
||||
|
||||
StorageReal::~StorageReal()
|
||||
{
|
||||
}
|
||||
|
||||
cache_result_t StorageReal::get_key(const char* zDefaultDb,
|
||||
const GWBUF* pQuery,
|
||||
CACHE_KEY* pKey)
|
||||
{
|
||||
return m_pApi->getKey(m_pStorage, zDefaultDb, pQuery, pKey);
|
||||
}
|
||||
|
||||
cache_result_t StorageReal::get_value(const CACHE_KEY& key,
|
||||
uint32_t flags,
|
||||
GWBUF** ppValue)
|
||||
{
|
||||
return m_pApi->getValue(m_pStorage, &key, flags, ppValue);
|
||||
}
|
||||
|
||||
cache_result_t StorageReal::put_value(const CACHE_KEY& key,
|
||||
const GWBUF* pValue)
|
||||
{
|
||||
return m_pApi->putValue(m_pStorage, &key, pValue);
|
||||
}
|
||||
|
||||
cache_result_t StorageReal::del_value(const CACHE_KEY& key)
|
||||
{
|
||||
return m_pApi->delValue(m_pStorage, &key);
|
||||
}
|
||||
47
server/modules/filter/cache/storagereal.h
vendored
Normal file
47
server/modules/filter/cache/storagereal.h
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
/*
|
||||
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||
*
|
||||
* Use of this software is governed by the Business Source License included
|
||||
* in the LICENSE.TXT file and at www.mariadb.com/bsl.
|
||||
*
|
||||
* Change Date: 2019-07-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source License, use
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
|
||||
#include <maxscale/cdefs.h>
|
||||
#include "storage.h"
|
||||
|
||||
class StorageReal : public Storage
|
||||
{
|
||||
public:
|
||||
~StorageReal();
|
||||
|
||||
cache_result_t get_key(const char* zDefaultDb,
|
||||
const GWBUF* pQuery,
|
||||
CACHE_KEY* pKey);
|
||||
|
||||
cache_result_t get_value(const CACHE_KEY& key,
|
||||
uint32_t flags,
|
||||
GWBUF** ppValue);
|
||||
|
||||
cache_result_t put_value(const CACHE_KEY& key,
|
||||
const GWBUF* pValue);
|
||||
|
||||
cache_result_t del_value(const CACHE_KEY& key);
|
||||
|
||||
private:
|
||||
friend class StorageFactory;
|
||||
|
||||
StorageReal(CACHE_STORAGE_API* pApi, CACHE_STORAGE* pStorage);
|
||||
|
||||
StorageReal(const StorageReal&);
|
||||
StorageReal& operator = (const StorageReal&);
|
||||
|
||||
private:
|
||||
CACHE_STORAGE_API* m_pApi;
|
||||
CACHE_STORAGE* m_pStorage;
|
||||
};
|
||||
Reference in New Issue
Block a user