Cache: Use StorageFactory for creating the cache key

Now the preparatory work is done using the storage factory and the
storage instance is created only when the actual testing is performed.
This commit is contained in:
Johan Wikman
2016-12-15 19:03:46 +02:00
parent 9e89fe9246
commit 883b82a26a
4 changed files with 35 additions and 32 deletions

View File

@ -15,7 +15,7 @@
#include <algorithm>
#include <iostream>
#include <set>
#include "storage.hh"
#include "storagefactory.hh"
// TODO: Move this to a common place.
#include "../../../../../query_classifier/test/testreader.hh"
@ -175,7 +175,9 @@ bool Tester::get_statements(std::istream& in, size_t n_statements, Statements* p
}
// static
bool Tester::get_cache_items(const Statements& statements, const Storage& storage, CacheItems* pItems)
bool Tester::get_cache_items(const Statements& statements,
const StorageFactory& factory,
CacheItems* pItems)
{
bool success = true;
@ -187,7 +189,7 @@ bool Tester::get_cache_items(const Statements& statements, const Storage& storag
if (pQuery)
{
CACHE_KEY key;
cache_result_t result = storage.get_key(NULL, pQuery, &key);
cache_result_t result = factory.get_key(NULL, pQuery, &key);
if (result == CACHE_RESULT_OK)
{
@ -214,7 +216,7 @@ bool Tester::get_cache_items(const Statements& statements, const Storage& storag
//static
bool Tester::get_cache_items(std::istream& in,
size_t n_items,
const Storage& storage,
const StorageFactory& factory,
CacheItems* pItems)
{
Statements statements;
@ -223,7 +225,7 @@ bool Tester::get_cache_items(std::istream& in,
if (rv)
{
rv = get_cache_items(statements, storage, pItems);
rv = get_cache_items(statements, factory, pItems);
}
return rv;

View File

@ -19,7 +19,7 @@
#include <pthread.h>
#include "cache_storage_api.hh"
class Storage;
class StorageFactory;
class Tester
{
@ -157,13 +157,13 @@ public:
* Converts a set of statements into cache items (i.e. key + statement).
*
* @param statements A number of statements.
* @param storage The storage using which the cache keys should be generated.
* @param factory The storage factory using which the cache keys should be generated.
* @param pItems Pointer to vector where the items will be back inserted.
*
* @return Whether the conversion was successful.
*/
static bool get_cache_items(const Statements& statements,
const Storage& storage,
const StorageFactory& factory,
CacheItems* pItems);
/**
@ -171,7 +171,7 @@ public:
*
* @param statements A number of statements.
* @param n_items How many items should be returned.
* @param storage The storage using which the cache keys should be generated.
* @param factory The storage factory using which the cache keys should be generated.
* @param pItems Pointer to vector where the items will be back inserted.
*
* @return Whether reading and conversion was successful, not whether @n_items
@ -179,7 +179,7 @@ public:
*/
static bool get_cache_items(std::istream& in,
size_t n_items,
const Storage& storage,
const StorageFactory& factory,
CacheItems* pItems);
/**

View File

@ -147,20 +147,13 @@ int TesterStorage::run(size_t n_threads, size_t n_seconds, std::istream& in)
{
int rv = EXIT_FAILURE;
Storage* pStorage = get_storage();
size_t n_items = get_n_items(n_threads, n_seconds);
if (pStorage)
CacheItems cache_items;
if (get_cache_items(in, n_items, m_factory, &cache_items))
{
size_t n_items = get_n_items(n_threads, n_seconds);
CacheItems cache_items;
if (get_cache_items(in, n_items, *pStorage, &cache_items))
{
rv = run(n_threads, n_seconds, cache_items, *pStorage);
}
delete pStorage;
rv = run(n_threads, n_seconds, cache_items);
}
return rv;
@ -168,10 +161,20 @@ int TesterStorage::run(size_t n_threads, size_t n_seconds, std::istream& in)
int TesterStorage::run(size_t n_threads,
size_t n_seconds,
const CacheItems& cache_items,
Storage& storage)
const CacheItems& cache_items)
{
return run_hit_task(n_threads, n_seconds, cache_items, storage);
int rv = EXIT_FAILURE;
Storage* pStorage = get_storage();
if (pStorage)
{
rv = run_hit_task(n_threads, n_seconds, cache_items, *pStorage);
delete pStorage;
}
return rv;
}
int TesterStorage::run_hit_task(size_t n_threads,

View File

@ -14,6 +14,7 @@
#include <maxscale/cppdefs.hh>
#include "tester.hh"
class Storage;
class StorageFactory;
class TesterStorage : public Tester
@ -85,13 +86,11 @@ public:
*
* @param n_threads How many threads to use.
* @param n_seconds For how many seconds to run the test.
* @param cache_items The cache items to use. Assumed to have been created using
* @c storage.
* @param storage The storage items to use.
* @param cache_items The cache items to use.
*
* @return EXIT_SUCCESS or EXIT_FAILURE.
*/
virtual int run(size_t n_threads, size_t n_seconds, const CacheItems& cache_items, Storage& storage);
virtual int run(size_t n_threads, size_t n_seconds, const CacheItems& cache_items);
/**
* Runs the HitTask using as many threads as specified, for the specified
@ -99,9 +98,8 @@ public:
*
* @param n_threads How many threads to use.
* @param n_seconds For how many seconds to run the test.
* @param cache_items The cache items to use. Assumed to have been created using
* @c storage.
* @param storage The storage items to use.
* @param cache_items The cache items to use.
* @param storage The storage to use.
*
* @return EXIT_SUCCESS or EXIT_FAILURE.
*/