Renamed old CachingBlockStore to ParallelAccessBlockStore

This commit is contained in:
Sebastian Messmer 2015-04-16 13:59:52 +02:00
parent 6413123838
commit 248fd0f5cc
11 changed files with 86 additions and 88 deletions

View File

@ -1 +0,0 @@
#include "CachedBlockRef.h"

View File

@ -1,44 +0,0 @@
#include "CachedBlockRef.h"
#include "CachingBlockStore.h"
#include <cassert>
#include <messmer/cpp-utils/pointer.h>
#include "CachingBlockStoreAdapter.h"
using std::unique_ptr;
using std::make_unique;
using std::string;
using std::mutex;
using std::lock_guard;
using std::promise;
using cpputils::dynamic_pointer_move;
namespace blockstore {
namespace caching {
CachingBlockStore::CachingBlockStore(unique_ptr<BlockStore> baseBlockStore)
: _baseBlockStore(std::move(baseBlockStore)), _cachingStore(make_unique<CachingBlockStoreAdapter>(_baseBlockStore.get())) {
}
unique_ptr<Block> CachingBlockStore::create(size_t size) {
auto block = _baseBlockStore->create(size);
Key key = block->key();
return _cachingStore.add(key, std::move(block));
}
unique_ptr<Block> CachingBlockStore::load(const Key &key) {
return _cachingStore.load(key);
}
void CachingBlockStore::remove(unique_ptr<Block> block) {
Key key = block->key();
return _cachingStore.remove(key, dynamic_pointer_move<CachedBlockRef>(block));
}
uint64_t CachingBlockStore::numBlocks() const {
return _baseBlockStore->numBlocks();
}
}
}

View File

@ -1 +0,0 @@
#include "CachingBlockStoreAdapter.h"

View File

@ -0,0 +1 @@
#include "BlockRef.h"

View File

@ -9,13 +9,13 @@
#include <memory>
namespace blockstore {
namespace caching {
class CachingBlockStore;
namespace parallelaccess {
class ParallelAccessBlockStore;
class CachedBlockRef: public Block, public cachingstore::CachingStore<Block, CachedBlockRef, Key>::CachedResource {
class BlockRef: public Block, public cachingstore::CachingStore<Block, BlockRef, Key>::CachedResource {
public:
//TODO Unneccessarily storing Key twice here (in parent class and in _baseBlock).
CachedBlockRef(Block *baseBlock): Block(baseBlock->key()), _baseBlock(baseBlock) {}
BlockRef(Block *baseBlock): Block(baseBlock->key()), _baseBlock(baseBlock) {}
const void *data() const override {
return _baseBlock->data();
@ -36,7 +36,7 @@ public:
private:
Block *_baseBlock;
DISALLOW_COPY_AND_ASSIGN(CachedBlockRef);
DISALLOW_COPY_AND_ASSIGN(BlockRef);
};
}

View File

@ -0,0 +1,44 @@
#include "BlockRef.h"
#include "ParallelAccessBlockStore.h"
#include "ParallelAccessBlockStoreAdapter.h"
#include <cassert>
#include <messmer/cpp-utils/pointer.h>
using std::unique_ptr;
using std::make_unique;
using std::string;
using std::mutex;
using std::lock_guard;
using std::promise;
using cpputils::dynamic_pointer_move;
namespace blockstore {
namespace parallelaccess {
ParallelAccessBlockStore::ParallelAccessBlockStore(unique_ptr<BlockStore> baseBlockStore)
: _baseBlockStore(std::move(baseBlockStore)), _cachingStore(make_unique<ParallelAccessBlockStoreAdapter>(_baseBlockStore.get())) {
}
unique_ptr<Block> ParallelAccessBlockStore::create(size_t size) {
auto block = _baseBlockStore->create(size);
Key key = block->key();
return _cachingStore.add(key, std::move(block));
}
unique_ptr<Block> ParallelAccessBlockStore::load(const Key &key) {
return _cachingStore.load(key);
}
void ParallelAccessBlockStore::remove(unique_ptr<Block> block) {
Key key = block->key();
return _cachingStore.remove(key, dynamic_pointer_move<BlockRef>(block));
}
uint64_t ParallelAccessBlockStore::numBlocks() const {
return _baseBlockStore->numBlocks();
}
}
}

View File

@ -2,18 +2,18 @@
#ifndef BLOCKSTORE_IMPLEMENTATIONS_CACHING_CACHINGBLOCKSTORE_H_
#define BLOCKSTORE_IMPLEMENTATIONS_CACHING_CACHINGBLOCKSTORE_H_
#include "BlockRef.h"
#include <messmer/cachingstore/CachingStore.h>
#include "../../interface/BlockStore.h"
#include "CachedBlockRef.h"
namespace blockstore {
namespace caching {
namespace parallelaccess {
//TODO Check that this blockstore allows parallel destructing of blocks (otherwise we won't encrypt blocks in parallel)
class CachingBlockStore: public BlockStore {
class ParallelAccessBlockStore: public BlockStore {
public:
CachingBlockStore(std::unique_ptr<BlockStore> baseBlockStore);
ParallelAccessBlockStore(std::unique_ptr<BlockStore> baseBlockStore);
std::unique_ptr<Block> create(size_t size) override;
std::unique_ptr<Block> load(const Key &key) override;
@ -22,9 +22,9 @@ public:
private:
std::unique_ptr<BlockStore> _baseBlockStore;
cachingstore::CachingStore<Block, CachedBlockRef, Key> _cachingStore;
cachingstore::CachingStore<Block, BlockRef, Key> _cachingStore;
DISALLOW_COPY_AND_ASSIGN(CachingBlockStore);
DISALLOW_COPY_AND_ASSIGN(ParallelAccessBlockStore);
};
}

View File

@ -0,0 +1 @@
#include "ParallelAccessBlockStoreAdapter.h"

View File

@ -1,16 +1,16 @@
#ifndef MESSMER_BLOCKSTORE_IMPLEMENTATIONS_CACHING_CACHINGBLOCKSTOREADAPTER_H_
#define MESSMER_BLOCKSTORE_IMPLEMENTATIONS_CACHING_CACHINGBLOCKSTOREADAPTER_H_
#ifndef MESSMER_BLOCKSTORE_IMPLEMENTATIONS_PARALLELACCESS_PARALLELACCESSBLOCKSTOREADAPTER_H_
#define MESSMER_BLOCKSTORE_IMPLEMENTATIONS_PARALLELACCESS_PARALLELACCESSBLOCKSTOREADAPTER_H_
#include <messmer/cpp-utils/macros.h>
#include <messmer/cachingstore/CachingStore.h>
#include "../../interface/BlockStore.h"
namespace blockstore {
namespace caching {
namespace parallelaccess {
class CachingBlockStoreAdapter: public cachingstore::CachingBaseStore<Block, Key> {
class ParallelAccessBlockStoreAdapter: public cachingstore::CachingBaseStore<Block, Key> {
public:
CachingBlockStoreAdapter(BlockStore *baseBlockStore)
ParallelAccessBlockStoreAdapter(BlockStore *baseBlockStore)
:_baseBlockStore(std::move(baseBlockStore)) {
}
@ -25,7 +25,7 @@ public:
private:
BlockStore *_baseBlockStore;
DISALLOW_COPY_AND_ASSIGN(CachingBlockStoreAdapter);
DISALLOW_COPY_AND_ASSIGN(ParallelAccessBlockStoreAdapter);
};
}

View File

@ -1,25 +0,0 @@
#include "../../../implementations/caching/CachingBlockStore.h"
#include "../../../implementations/testfake/FakeBlockStore.h"
#include "../../testutils/BlockStoreTest.h"
#include "google/gtest/gtest.h"
using blockstore::BlockStore;
using blockstore::caching::CachingBlockStore;
using blockstore::testfake::FakeBlockStore;
using std::unique_ptr;
using std::make_unique;
class CachingBlockStoreTestFixture: public BlockStoreTestFixture {
public:
unique_ptr<BlockStore> createBlockStore() override {
return make_unique<CachingBlockStore>(make_unique<FakeBlockStore>());
}
};
INSTANTIATE_TYPED_TEST_CASE_P(Caching, BlockStoreTest, CachingBlockStoreTestFixture);
//TODO Add specific tests ensuring that
// (a) loading the same block twice doesn't load it twice from the underlying blockstore
// (b) ... cache tests

View File

@ -0,0 +1,23 @@
#include "../../../implementations/parallelaccess/ParallelAccessBlockStore.h"
#include "../../../implementations/testfake/FakeBlockStore.h"
#include "../../testutils/BlockStoreTest.h"
#include "google/gtest/gtest.h"
using blockstore::BlockStore;
using blockstore::parallelaccess::ParallelAccessBlockStore;
using blockstore::testfake::FakeBlockStore;
using std::unique_ptr;
using std::make_unique;
class ParallelAccessBlockStoreTestFixture: public BlockStoreTestFixture {
public:
unique_ptr<BlockStore> createBlockStore() override {
return make_unique<ParallelAccessBlockStore>(make_unique<FakeBlockStore>());
}
};
INSTANTIATE_TYPED_TEST_CASE_P(Caching, BlockStoreTest, ParallelAccessBlockStoreTestFixture);
//TODO Add specific tests ensuring that loading the same block twice doesn't load it twice from the underlying blockstore