From 248fd0f5cc68b2c698c60b1d899d197ece544104 Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Thu, 16 Apr 2015 13:59:52 +0200 Subject: [PATCH] Renamed old CachingBlockStore to ParallelAccessBlockStore --- implementations/caching/CachedBlockRef.cpp | 1 - implementations/caching/CachingBlockStore.cpp | 44 ------------------- .../caching/CachingBlockStoreAdapter.cpp | 1 - implementations/parallelaccess/BlockRef.cpp | 1 + .../BlockRef.h} | 10 ++--- .../ParallelAccessBlockStore.cpp | 44 +++++++++++++++++++ .../ParallelAccessBlockStore.h} | 12 ++--- .../ParallelAccessBlockStoreAdapter.cpp | 1 + .../ParallelAccessBlockStoreAdapter.h} | 12 ++--- .../caching/CachingBlockStoreTest.cpp | 25 ----------- .../ParallelAccessBlockStoreTest.cpp | 23 ++++++++++ 11 files changed, 86 insertions(+), 88 deletions(-) delete mode 100644 implementations/caching/CachedBlockRef.cpp delete mode 100644 implementations/caching/CachingBlockStore.cpp delete mode 100644 implementations/caching/CachingBlockStoreAdapter.cpp create mode 100644 implementations/parallelaccess/BlockRef.cpp rename implementations/{caching/CachedBlockRef.h => parallelaccess/BlockRef.h} (72%) create mode 100644 implementations/parallelaccess/ParallelAccessBlockStore.cpp rename implementations/{caching/CachingBlockStore.h => parallelaccess/ParallelAccessBlockStore.h} (69%) create mode 100644 implementations/parallelaccess/ParallelAccessBlockStoreAdapter.cpp rename implementations/{caching/CachingBlockStoreAdapter.h => parallelaccess/ParallelAccessBlockStoreAdapter.h} (54%) delete mode 100644 test/implementations/caching/CachingBlockStoreTest.cpp create mode 100644 test/implementations/parallelaccess/ParallelAccessBlockStoreTest.cpp diff --git a/implementations/caching/CachedBlockRef.cpp b/implementations/caching/CachedBlockRef.cpp deleted file mode 100644 index 66964318..00000000 --- a/implementations/caching/CachedBlockRef.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "CachedBlockRef.h" diff --git a/implementations/caching/CachingBlockStore.cpp b/implementations/caching/CachingBlockStore.cpp deleted file mode 100644 index 42b3151b..00000000 --- a/implementations/caching/CachingBlockStore.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "CachedBlockRef.h" -#include "CachingBlockStore.h" -#include -#include - -#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 baseBlockStore) - : _baseBlockStore(std::move(baseBlockStore)), _cachingStore(make_unique(_baseBlockStore.get())) { -} - -unique_ptr CachingBlockStore::create(size_t size) { - auto block = _baseBlockStore->create(size); - Key key = block->key(); - return _cachingStore.add(key, std::move(block)); -} - -unique_ptr CachingBlockStore::load(const Key &key) { - return _cachingStore.load(key); -} - - -void CachingBlockStore::remove(unique_ptr block) { - Key key = block->key(); - return _cachingStore.remove(key, dynamic_pointer_move(block)); -} - -uint64_t CachingBlockStore::numBlocks() const { - return _baseBlockStore->numBlocks(); -} - -} -} diff --git a/implementations/caching/CachingBlockStoreAdapter.cpp b/implementations/caching/CachingBlockStoreAdapter.cpp deleted file mode 100644 index b299922d..00000000 --- a/implementations/caching/CachingBlockStoreAdapter.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "CachingBlockStoreAdapter.h" diff --git a/implementations/parallelaccess/BlockRef.cpp b/implementations/parallelaccess/BlockRef.cpp new file mode 100644 index 00000000..f35230b4 --- /dev/null +++ b/implementations/parallelaccess/BlockRef.cpp @@ -0,0 +1 @@ +#include "BlockRef.h" diff --git a/implementations/caching/CachedBlockRef.h b/implementations/parallelaccess/BlockRef.h similarity index 72% rename from implementations/caching/CachedBlockRef.h rename to implementations/parallelaccess/BlockRef.h index 277bfbd6..685bfa1a 100644 --- a/implementations/caching/CachedBlockRef.h +++ b/implementations/parallelaccess/BlockRef.h @@ -9,13 +9,13 @@ #include namespace blockstore { -namespace caching { -class CachingBlockStore; +namespace parallelaccess { +class ParallelAccessBlockStore; -class CachedBlockRef: public Block, public cachingstore::CachingStore::CachedResource { +class BlockRef: public Block, public cachingstore::CachingStore::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); }; } diff --git a/implementations/parallelaccess/ParallelAccessBlockStore.cpp b/implementations/parallelaccess/ParallelAccessBlockStore.cpp new file mode 100644 index 00000000..2a62dec7 --- /dev/null +++ b/implementations/parallelaccess/ParallelAccessBlockStore.cpp @@ -0,0 +1,44 @@ +#include "BlockRef.h" +#include "ParallelAccessBlockStore.h" +#include "ParallelAccessBlockStoreAdapter.h" +#include +#include + + +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 baseBlockStore) + : _baseBlockStore(std::move(baseBlockStore)), _cachingStore(make_unique(_baseBlockStore.get())) { +} + +unique_ptr ParallelAccessBlockStore::create(size_t size) { + auto block = _baseBlockStore->create(size); + Key key = block->key(); + return _cachingStore.add(key, std::move(block)); +} + +unique_ptr ParallelAccessBlockStore::load(const Key &key) { + return _cachingStore.load(key); +} + + +void ParallelAccessBlockStore::remove(unique_ptr block) { + Key key = block->key(); + return _cachingStore.remove(key, dynamic_pointer_move(block)); +} + +uint64_t ParallelAccessBlockStore::numBlocks() const { + return _baseBlockStore->numBlocks(); +} + +} +} diff --git a/implementations/caching/CachingBlockStore.h b/implementations/parallelaccess/ParallelAccessBlockStore.h similarity index 69% rename from implementations/caching/CachingBlockStore.h rename to implementations/parallelaccess/ParallelAccessBlockStore.h index 7452557b..fee0475f 100644 --- a/implementations/caching/CachingBlockStore.h +++ b/implementations/parallelaccess/ParallelAccessBlockStore.h @@ -2,18 +2,18 @@ #ifndef BLOCKSTORE_IMPLEMENTATIONS_CACHING_CACHINGBLOCKSTORE_H_ #define BLOCKSTORE_IMPLEMENTATIONS_CACHING_CACHINGBLOCKSTORE_H_ +#include "BlockRef.h" #include #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 baseBlockStore); + ParallelAccessBlockStore(std::unique_ptr baseBlockStore); std::unique_ptr create(size_t size) override; std::unique_ptr load(const Key &key) override; @@ -22,9 +22,9 @@ public: private: std::unique_ptr _baseBlockStore; - cachingstore::CachingStore _cachingStore; + cachingstore::CachingStore _cachingStore; - DISALLOW_COPY_AND_ASSIGN(CachingBlockStore); + DISALLOW_COPY_AND_ASSIGN(ParallelAccessBlockStore); }; } diff --git a/implementations/parallelaccess/ParallelAccessBlockStoreAdapter.cpp b/implementations/parallelaccess/ParallelAccessBlockStoreAdapter.cpp new file mode 100644 index 00000000..49b896b0 --- /dev/null +++ b/implementations/parallelaccess/ParallelAccessBlockStoreAdapter.cpp @@ -0,0 +1 @@ +#include "ParallelAccessBlockStoreAdapter.h" diff --git a/implementations/caching/CachingBlockStoreAdapter.h b/implementations/parallelaccess/ParallelAccessBlockStoreAdapter.h similarity index 54% rename from implementations/caching/CachingBlockStoreAdapter.h rename to implementations/parallelaccess/ParallelAccessBlockStoreAdapter.h index 44fd4378..2314180e 100644 --- a/implementations/caching/CachingBlockStoreAdapter.h +++ b/implementations/parallelaccess/ParallelAccessBlockStoreAdapter.h @@ -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 #include #include "../../interface/BlockStore.h" namespace blockstore { -namespace caching { +namespace parallelaccess { -class CachingBlockStoreAdapter: public cachingstore::CachingBaseStore { +class ParallelAccessBlockStoreAdapter: public cachingstore::CachingBaseStore { 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); }; } diff --git a/test/implementations/caching/CachingBlockStoreTest.cpp b/test/implementations/caching/CachingBlockStoreTest.cpp deleted file mode 100644 index de5e418c..00000000 --- a/test/implementations/caching/CachingBlockStoreTest.cpp +++ /dev/null @@ -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 createBlockStore() override { - return make_unique(make_unique()); - } -}; - -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 diff --git a/test/implementations/parallelaccess/ParallelAccessBlockStoreTest.cpp b/test/implementations/parallelaccess/ParallelAccessBlockStoreTest.cpp new file mode 100644 index 00000000..2149d7a9 --- /dev/null +++ b/test/implementations/parallelaccess/ParallelAccessBlockStoreTest.cpp @@ -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 createBlockStore() override { + return make_unique(make_unique()); + } +}; + +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